Author: lslezak Date: Tue Jan 15 15:04:19 2008 New Revision: 8288 URL: http://svn.opensuse.org/viewcvs/zypp?rev=8288&view=rev Log: - added RpmDb::removePubkey(), call it from KeyRing::Impl::deleteKey() - remove the GPG key from RPM when it is removed from the trusted keyring - revision 8288 Modified: trunk/libzypp/package/libzypp.changes trunk/libzypp/zypp/KeyRing.cc trunk/libzypp/zypp/target/rpm/RpmDb.cc trunk/libzypp/zypp/target/rpm/RpmDb.h Modified: trunk/libzypp/package/libzypp.changes URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/package/libzypp.changes?rev=8288&r1=8287&r2=8288&view=diff ============================================================================== --- trunk/libzypp/package/libzypp.changes (original) +++ trunk/libzypp/package/libzypp.changes Tue Jan 15 15:04:19 2008 @@ -1,4 +1,12 @@ ------------------------------------------------------------------- +Tue Jan 15 14:56:21 CET 2008 - lslezak@suse.cz + +- added RpmDb::removePubkey(), call it from + KeyRing::Impl::deleteKey() - remove the GPG key from RPM when it + is removed from the trusted keyring +- revision 8288 + +------------------------------------------------------------------- Mon Jan 14 17:11:15 CET 2008 - schubi@suse.de - Textchanges Modified: trunk/libzypp/zypp/KeyRing.cc URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/zypp/KeyRing.cc?rev=8288&r1=8287&r2=8288&view=diff ============================================================================== --- trunk/libzypp/zypp/KeyRing.cc (original) +++ trunk/libzypp/zypp/KeyRing.cc Tue Jan 15 15:04:19 2008 @@ -176,7 +176,23 @@ void KeyRing::Impl::deleteKey( const string &id, bool trusted) { + PublicKey key; + + if (trusted) + { + key = exportKey(id, trustedKeyRing()); + } + deleteKey( id, trusted ? trustedKeyRing() : generalKeyRing() ); + + if ( trusted ) + { + callback::SendReporttarget::rpm::KeyRingSignals rpmdbEmitSignal; + callback::SendReport<KeyRingSignals> emitSignal; + + rpmdbEmitSignal->trustedKeyRemoved( key ); + emitSignal->trustedKeyRemoved( key ); + } } list<PublicKey> KeyRing::Impl::publicKeys() Modified: trunk/libzypp/zypp/target/rpm/RpmDb.cc URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/zypp/target/rpm/RpmDb.cc?rev=8288&r1=8287&r2=8288&view=diff ============================================================================== --- trunk/libzypp/zypp/target/rpm/RpmDb.cc (original) +++ trunk/libzypp/zypp/target/rpm/RpmDb.cc Tue Jan 15 15:04:19 2008 @@ -103,7 +103,19 @@ } virtual void trustedKeyRemoved( const PublicKey &key ) - {} + { + MIL << "Trusted key removed from zypp Keyring. Removing..." << endl; + + // remove the key from rpm + try + { + _rpmdb.removePubkey( key ); + } + catch (RpmException &e) + { + ERR << "Could not remove key " << key.id() << " (" << key.name() << ") from rpm database" << endl; + } + } RpmDb &_rpmdb; }; @@ -1043,6 +1055,80 @@ /////////////////////////////////////////////////////////////////// // // +// METHOD NAME : RpmDb::removePubkey +// METHOD TYPE : PMError +// +void RpmDb::removePubkey( const PublicKey & pubkey_r ) +{ + FAILIFNOTINITIALIZED; + + // check if the key is in the rpm database and just + // return if it does not. + set<Edition> rpm_keys = pubkeyEditions(); + + // search the key + set<Edition>::const_iterator found_edition = rpm_keys.end(); + + for ( set<Edition>::const_iterator it = rpm_keys.begin(); it != rpm_keys.end(); ++it) + { + string id = str::toUpper( (*it).version() ); + string keyshortid = pubkey_r.id().substr(8,8); + MIL << "Comparing '" << id << "' to '" << keyshortid << "'" << endl; + if ( id == keyshortid ) + { + found_edition = it; + break; + } + } + + // the key does not exist, cannot be removed + if (found_edition == rpm_keys.end()) + { + WAR << "Key " << pubkey_r.id() << " is not in rpm db" << endl; + return; + } + + string rpm_name("gpg-pubkey-" + found_edition->asString()); + + RpmArgVec opts; + opts.push_back ( "-e" ); + opts.push_back ( "--" ); + opts.push_back ( rpm_name.c_str() ); + + // don't call modifyDatabase because it would remove the old + // rpm3 database, if the current database is a temporary one. + // But do invalidate packages list. + _packages._valid = false; + run_rpm( opts, ExternalProgram::Stderr_To_Stdout ); + + string line; + while ( systemReadLine( line ) ) + { + if ( line.substr( 0, 6 ) == "error:" ) + { + WAR << line << endl; + } + else + { + DBG << line << endl; + } + } + + int rpm_status = systemStatus(); + + if ( rpm_status != 0 ) + { + ZYPP_THROW(RpmSubprocessException(string("Failed to remove public key ") + pubkey_r.asString() + string(": rpm returned ") + str::numstring(rpm_status))); + } + else + { + MIL << "Key " << pubkey_r << " has been removed from RPM trusted keyring" << endl; + } +} + +/////////////////////////////////////////////////////////////////// +// +// // METHOD NAME : RpmDb::pubkeys // METHOD TYPE : set<Edition> // Modified: trunk/libzypp/zypp/target/rpm/RpmDb.h URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/zypp/target/rpm/RpmDb.h?rev=8288&r1=8287&r2=8288&view=diff ============================================================================== --- trunk/libzypp/zypp/target/rpm/RpmDb.h (original) +++ trunk/libzypp/zypp/target/rpm/RpmDb.h Tue Jan 15 15:04:19 2008 @@ -220,6 +220,14 @@ void importPubkey( const PublicKey & pubkey_r ); /** + * Remove a public key from the rpm database + * + * \throws RpmException + * + **/ + void removePubkey( const PublicKey & pubkey_r ); + + /** * Return the long ids of all installed public keys. **/ std::list<PublicKey> pubkeys() const; -- To unsubscribe, e-mail: zypp-commit+unsubscribe@opensuse.org For additional commands, e-mail: zypp-commit+help@opensuse.org