- adapt to libzypp's keyring changes (bnc #366467)
authorJan Kupec <jkupec@suse.cz>
Wed, 24 Sep 2008 22:17:27 +0000 (22:17 +0000)
committerJan Kupec <jkupec@suse.cz>
Wed, 24 Sep 2008 22:17:27 +0000 (22:17 +0000)
src/callbacks/keyring.h
src/zypp-refresh.cc
zypper.spec.cmake

index 6e4f317..107ff41 100644 (file)
@@ -31,7 +31,8 @@ namespace zypp {
     {
       KeyRingReceive() : _gopts(Zypper::instance()->globalOpts()) {}
 
-      virtual bool askUserToAcceptUnsignedFile( const std::string &file )
+      virtual bool askUserToAcceptUnsignedFile(
+          const std::string & file, const KeyContext & context)
       {
         if (_gopts.no_gpg_checks)
         {
@@ -48,7 +49,8 @@ namespace zypp {
         return read_bool_answer(PROMPT_YN_GPG_UNSIGNED_FILE_ACCEPT, question, false);
       }
 
-      virtual bool askUserToImportKey( const PublicKey &key )
+/*      virtual bool askUserToImportKey(
+          const PublicKey &key, const KeyContext & context)
       {
         //this is because only root have access to rpm db where is keys stored
         if ( geteuid() != 0 && !_gopts.changedRoot)
@@ -58,8 +60,11 @@ namespace zypp {
             _("Import key %s to trusted keyring?")) % key.id());
         return read_bool_answer(PROMPT_YN_GPG_KEY_IMPORT_TRUSTED, question, false);
       }
-
-      virtual bool askUserToAcceptUnknownKey( const std::string &file, const std::string &id )
+*/
+      virtual bool askUserToAcceptUnknownKey(
+          const std::string & file,
+          const std::string & id,
+          const zypp::KeyContext & context)
       {
         if (_gopts.no_gpg_checks)
         {
@@ -76,28 +81,53 @@ namespace zypp {
         return read_bool_answer(PROMPT_YN_GPG_UNKNOWN_KEY_ACCEPT, question, false);
       }
 
-      virtual bool askUserToTrustKey( const PublicKey &key )
+      virtual KeyRingReport::KeyTrust askUserToAcceptKey(
+          const PublicKey &key, const zypp::KeyContext & context)
       {
-       const std::string& keyid = key.id(), keyname = key.name(),
+        Zypper & zypper = *Zypper::instance();
+
+       const std::string & keyid = key.id(), keyname = key.name(),
          fingerprint = key.fingerprint();
 
         if (_gopts.no_gpg_checks)
         {
           MIL << boost::format("Automatically trusting key id %s, %s, fingerprint %s")
               % keyid % keyname % fingerprint << std::endl;
-          Zypper::instance()->out().info(boost::str(boost::format(
+          zypper.out().info(boost::str(boost::format(
               _("Automatically trusting key id %s, %s, fingerprint %s"))
               % keyid % keyname % fingerprint));
-          return true;
+          return KeyRingReport::KEY_TRUST_TEMPORARILY;
         }
 
         std::string question = boost::str(boost::format(
            _("Do you want to trust key id %s, %s, fingerprint %s"))
            % keyid % keyname % fingerprint);
-        return read_bool_answer(PROMPT_YN_GPG_KEY_TRUST, question, false);
+
+        PromptOptions popts;
+        popts.setOptions(_("t/i/n"), 2);
+        popts.setOptionHelp(0, _("Trust the key temporarily, do not import it."));
+        popts.setOptionHelp(1, _("Trust the key and import it into RPM keyring."));
+        popts.setOptionHelp(2, _("Don't trust the key."));
+
+        zypper.out().prompt(PROMPT_YN_GPG_KEY_TRUST, question, popts);
+        unsigned prep =
+          get_prompt_reply(zypper, PROMPT_YN_GPG_KEY_TRUST, popts);
+        switch (prep)
+        {
+        case 0:
+          return KeyRingReport::KEY_TRUST_TEMPORARILY;
+        case 1:
+          return KeyRingReport::KEY_TRUST_AND_IMPORT;
+        default:
+          return KeyRingReport::KEY_DONT_TRUST;
+        }
+        return KeyRingReport::KEY_DONT_TRUST;
       }
 
-      virtual bool askUserToAcceptVerificationFailed( const std::string &file,const PublicKey &key )
+      virtual bool askUserToAcceptVerificationFailed(
+          const std::string & file,
+          const PublicKey & key,
+          const zypp::KeyContext & context )
       {
        const std::string& keyid = key.id(), keyname = key.name(),
          fingerprint = key.fingerprint();
index ccb9dea..5c45deb 100644 (file)
@@ -46,13 +46,13 @@ namespace zypp {
   ///////////////////////////////////////////////////////////////////
   struct KeyRingReceive : public zypp::callback::ReceiveReport<zypp::KeyRingReport>
   {
-    virtual bool askUserToAcceptUnsignedFile( const std::string &file )
+    virtual bool askUserToAcceptUnsignedFile( const std::string &file, const KeyContext & context )
     { cerr << ". Error:" << endl << "refusing unsigned file " << file << endl;  return readCallbackAnswer(); }
-    virtual bool askUserToAcceptUnknownKey( const std::string &file, const std::string &id )
+    virtual bool askUserToAcceptUnknownKey( const std::string &file, const std::string &id, const KeyContext & context )
     { cerr << ". Error:" << endl << "refusing unknown key, id: '" << id << "' from file '" << file << "'" << endl; return readCallbackAnswer(); }
-    virtual bool askUserToTrustKey( const PublicKey &key )
-    { cerr << ". Error:" << endl << "not trusting key '" << key << "'" << endl;return readCallbackAnswer(); }
-    virtual bool askUserToAcceptVerificationFailed( const std::string &file, const PublicKey &key )
+    virtual KeyRingReport::KeyTrust askUserToAcceptKey( const PublicKey &key, const KeyContext & context )
+    { cerr << ". Error:" << endl << "not trusting key '" << key << "'" << endl; return KeyRingReport::KEY_DONT_TRUST; }
+    virtual bool askUserToAcceptVerificationFailed( const std::string &file, const PublicKey &key, const KeyContext & context )
     { cerr << ". Error:" << endl << "verification of '" << file << "' with key '" << key << "' failed" << endl; return readCallbackAnswer(); }
   };
 
index e441db1..a0228d1 100644 (file)
@@ -11,7 +11,7 @@
 # norootforbuild
 
 Name:           @PACKAGE@
-BuildRequires:  libzypp-devel >= 5.10.0 boost-devel >= 1.33.1 gettext-devel >= 0.15 readline-devel >= 5.1
+BuildRequires:  libzypp-devel >= 5.12.0 boost-devel >= 1.33.1 gettext-devel >= 0.15 readline-devel >= 5.1
 BuildRequires:  gcc-c++ >= 4.1 cmake >= 2.4.6
 Requires:      procps
 Recommends:     logrotate cron