Author: lslezak
Date: Mon Jan 7 16:50:47 2008
New Revision: 43311
URL: http://svn.opensuse.org/viewcvs/yast?rev=43311&view=rev
Log:
- added missing "log.h" file in Makefile.am
- added GPG key management functions (FATE 300754):
Pkg::GPGKeys() - get list of the known or trusted GPG keys
Pkg::DeleteGPGKey() - delete the GPG key from the known or
trusted keyring
- 2.16.9
Modified:
trunk/pkg-bindings/VERSION
trunk/pkg-bindings/package/yast2-pkg-bindings.changes
trunk/pkg-bindings/src/Keyring.cc
trunk/pkg-bindings/src/Makefile.am
trunk/pkg-bindings/src/PkgFunctions.h
Modified: trunk/pkg-bindings/VERSION
URL: http://svn.opensuse.org/viewcvs/yast/trunk/pkg-bindings/VERSION?rev=43311&r1=43310&r2=43311&view=diff
==============================================================================
--- trunk/pkg-bindings/VERSION (original)
+++ trunk/pkg-bindings/VERSION Mon Jan 7 16:50:47 2008
@@ -1 +1 @@
-2.16.8
+2.16.9
Modified: trunk/pkg-bindings/package/yast2-pkg-bindings.changes
URL: http://svn.opensuse.org/viewcvs/yast/trunk/pkg-bindings/package/yast2-pkg-bindings.changes?rev=43311&r1=43310&r2=43311&view=diff
==============================================================================
--- trunk/pkg-bindings/package/yast2-pkg-bindings.changes (original)
+++ trunk/pkg-bindings/package/yast2-pkg-bindings.changes Mon Jan 7 16:50:47 2008
@@ -1,4 +1,14 @@
-------------------------------------------------------------------
+Mon Jan 7 16:40:35 CET 2008 - lslezak@suse.cz
+
+- added missing "log.h" file in Makefile.am
+- added GPG key management functions (FATE 300754):
+ Pkg::GPGKeys() - get list of the known or trusted GPG keys
+ Pkg::DeleteGPGKey() - delete the GPG key from the known or
+ trusted keyring
+- 2.16.9
+
+-------------------------------------------------------------------
Fri Jan 4 11:35:08 CET 2008 - lslezak@suse.cz
- the functionality from PkgModuleFunctions has been moved to
Modified: trunk/pkg-bindings/src/Keyring.cc
URL: http://svn.opensuse.org/viewcvs/yast/trunk/pkg-bindings/src/Keyring.cc?rev=43311&r1=43310&r2=43311&view=diff
==============================================================================
--- trunk/pkg-bindings/src/Keyring.cc (original)
+++ trunk/pkg-bindings/src/Keyring.cc Mon Jan 7 16:50:47 2008
@@ -14,18 +14,25 @@
Summary: Access to the Package Manager
Namespace: Pkg
- Purpose: Access to the Package Manager - keyring related bindings
+ Purpose: Access to the Package Manager - GPG key management related functions
/-*/
+#include <list>
+#include <set>
+
#include "PkgFunctions.h"
#include "log.h"
#include
#include
#include
+#include
+#include
#include
+#include
+#include
/****************************************************************************************
* @builtin ImportGPGKey
@@ -40,8 +47,8 @@
YCPValue
PkgFunctions::ImportGPGKey(const YCPString& filename, const YCPBoolean& trusted)
{
- bool trusted_key = trusted->value();
- std::string file = filename->value();
+ const bool trusted_key = trusted->value();
+ const std::string file = filename->value();
y2milestone("importing %s key: %s", (trusted_key) ? "trusted" : "untrusted", file.c_str());
@@ -60,3 +67,105 @@
return YCPVoid();
}
+// A helper class
+// converts PublicKey to YCPMap and adds it to an YCPList
+class PublicKeyAdder : public std::unary_function
+{
+ public:
+
+ // where to add the public key maps, which keys are trusted
+ PublicKeyAdder(YCPList &lst, bool trusted_keyring)
+ : list(lst), trusted(trusted_keyring)
+ {
+ }
+
+ void operator() (const zypp::PublicKey &key)
+ {
+ YCPMap ret;
+
+ ret->add(YCPString("id"), YCPString(key.id()));
+ ret->add(YCPString("name"), YCPString(key.name()));
+ ret->add(YCPString("fingerprint"), YCPString(key.fingerprint()));
+
+ // is the key trusted?
+ ret->add(YCPString("trusted"), YCPBoolean(trusted));
+
+ return list->add(ret);
+ }
+
+ private:
+
+ // where to add the converted value
+ YCPList &list;
+ // processing trusted or known GPG keys
+ const bool trusted;
+};
+
+/****************************************************************************************
+ * @builtin GPGKeys
+ * @short Read the GPG keys in the package manager keyring
+ * @description
+ * Read known or trusted keys from the package manager
+ *
+ * @param boolean trusted If set to true trusted keys are returned,
+ * @return list List of maps $[ "id" : string , "name" : string, "fingerprint" : string, "trusted" : boolean ], nil when an error occurred
+ **/
+YCPValue PkgFunctions::GPGKeys(const YCPBoolean& trusted)
+{
+ try
+ {
+ YCPList ret;
+ const bool trusted_only = trusted->value();
+ const zypp::KeyRing_Ptr keyring(zypp_ptr()->keyRing());
+
+ // use the required keyring
+ std::listzypp::PublicKey key_list(
+ trusted_only ? keyring->trustedPublicKeys()
+ : keyring->publicKeys()
+ );
+
+ // convert std::list<PublicKey> to YCPList, pass the known/trusted flag
+ for_each(key_list.begin(), key_list.end(), PublicKeyAdder(ret, trusted_only));
+
+ return ret;
+ }
+ catch (const zypp::Exception& excpt)
+ {
+ y2error("Cannot read GPG keys: %s", excpt.asString().c_str());
+ _last_error.setLastError(ExceptionAsString(excpt));
+ return YCPVoid();
+ }
+}
+
+/****************************************************************************************
+ * @builtin DeleteGPGKey
+ * @short Remove the GPG key from the package manager keyring
+ * @description
+ * Remove the GPG key from the known or trusted keyring
+ *
+ * @param key_id GPG key ID of the key to remove
+ * @param trusted If set to true the key will be removed from the trusted keyring otherwise it's removed from the known keyring
+ * @return boolean true on success
+ **/
+YCPValue PkgFunctions::DeleteGPGKey(const YCPString& key_id, const YCPBoolean& trusted)
+{
+ bool ret;
+ try
+ {
+ zypp_ptr()->keyRing()->deleteKey(key_id->value(), trusted->value());
+ ret = true;
+ }
+ catch(const zypp::Exception &excpt)
+ {
+ y2error("Cannot delete GPG key %s from %s keying: %s",
+ key_id->value().c_str(),
+ trusted->value() ? "trusted" : "known",
+ excpt.asString().c_str()
+ );
+
+ _last_error.setLastError(ExceptionAsString(excpt));
+ ret = false;
+ }
+
+ return YCPBoolean(ret);
+}
Modified: trunk/pkg-bindings/src/Makefile.am
URL: http://svn.opensuse.org/viewcvs/yast/trunk/pkg-bindings/src/Makefile.am?rev=43311&r1=43310&r2=43311&view=diff
==============================================================================
--- trunk/pkg-bindings/src/Makefile.am (original)
+++ trunk/pkg-bindings/src/Makefile.am Mon Jan 7 16:50:47 2008
@@ -50,7 +50,7 @@
Callbacks.cc Callbacks_Register.cc \
Y2PkgFunction.cc Y2PkgFunction.h \
YRepo.h YRepo.cc \
- HelpTexts.h i18n.h
+ HelpTexts.h i18n.h log.h
libpy2Pkg_la_LDFLAGS = -version-info 2:0
Modified: trunk/pkg-bindings/src/PkgFunctions.h
URL: http://svn.opensuse.org/viewcvs/yast/trunk/pkg-bindings/src/PkgFunctions.h?rev=43311&r1=43310&r2=43311&view=diff
==============================================================================
--- trunk/pkg-bindings/src/PkgFunctions.h (original)
+++ trunk/pkg-bindings/src/PkgFunctions.h Mon Jan 7 16:50:47 2008
@@ -689,6 +689,10 @@
// keyring related
/* TYPEINFO: void(string,boolean)*/
YCPValue ImportGPGKey(const YCPString& filename, const YCPBoolean& trusted);
+ /* TYPEINFO: list