[svn] gpgme - r1392 - in trunk: src tests

svn author wk cvs at cvs.gnupg.org
Tue Jul 7 16:33:11 CEST 2009


Author: wk
Date: 2009-07-07 16:33:10 +0200 (Tue, 07 Jul 2009)
New Revision: 1392

Modified:
   trunk/src/ChangeLog
   trunk/src/engine-gpg.c
   trunk/src/engine-gpgsm.c
   trunk/tests/ChangeLog
   trunk/tests/run-keylist.c
Log:
Inmplement import from keys for GPGSM.
Add option --cms to run-keylist test program.


Modified: trunk/src/ChangeLog
===================================================================
--- trunk/src/ChangeLog	2009-07-07 14:17:39 UTC (rev 1391)
+++ trunk/src/ChangeLog	2009-07-07 14:33:10 UTC (rev 1392)
@@ -1,5 +1,12 @@
 2009-07-07  Werner Koch  <wk at g10code.com>
 
+	* engine-gpgsm.c (struct engine_gpgsm): Add fields
+	input_helper_data and input_helper_memory.
+	(close_notify_handler): Release these new fields.
+	(gpgsm_import): Implement the keyarray feature.
+
+	* engine-gpg.c (gpg_import): Actually return GPG_ERR_INV_VALUE.
+
 	* engine-gpgsm.c (gpgsm_import): Return an error for unknown data
 	encodings.
 

Modified: trunk/tests/ChangeLog
===================================================================
--- trunk/tests/ChangeLog	2009-07-07 14:17:39 UTC (rev 1391)
+++ trunk/tests/ChangeLog	2009-07-07 14:33:10 UTC (rev 1392)
@@ -1,5 +1,7 @@
 2009-07-07  Werner Koch  <wk at g10code.com>
 
+	* run-keylist.c (main):  Add options --cms and --openpgp.  
+	
 	* gpg/pgp-keylist.c: Rename to ...
 	* run-keylist.c: ... this.
 	* gpg/pgp-import.c: Rename to ...

Modified: trunk/src/engine-gpg.c
===================================================================
--- trunk/src/engine-gpg.c	2009-07-07 14:17:39 UTC (rev 1391)
+++ trunk/src/engine-gpg.c	2009-07-07 14:33:10 UTC (rev 1392)
@@ -1914,7 +1914,7 @@
   gpgme_data_encoding_t dataenc;
 
   if (keydata && keyarray)
-    gpg_error (GPG_ERR_INV_VALUE); /* Only one is allowed.  */
+    return gpg_error (GPG_ERR_INV_VALUE); /* Only one is allowed.  */
 
   dataenc = gpgme_data_get_encoding (keydata);
 

Modified: trunk/src/engine-gpgsm.c
===================================================================
--- trunk/src/engine-gpgsm.c	2009-07-07 14:17:39 UTC (rev 1391)
+++ trunk/src/engine-gpgsm.c	2009-07-07 14:33:10 UTC (rev 1392)
@@ -70,6 +70,8 @@
 
   /* Input, output etc are from the servers perspective.  */
   iocb_data_t input_cb;
+  gpgme_data_t input_helper_data;  /* Input helper data object.  */
+  void *input_helper_memory;       /* Input helper memory block.  */
 
   iocb_data_t output_cb;
 
@@ -141,6 +143,16 @@
 	(*gpgsm->io_cbs.remove) (gpgsm->input_cb.tag);
       gpgsm->input_cb.fd = -1;
       gpgsm->input_cb.tag = NULL;
+      if (gpgsm->input_helper_data)
+        {
+          gpgme_data_release (gpgsm->input_helper_data);
+          gpgsm->input_helper_data = NULL;
+        }
+      if (gpgsm->input_helper_memory)
+        {
+          free (gpgsm->input_helper_memory);
+          gpgsm->input_helper_memory = NULL;
+        }
     }
   else if (gpgsm->output_cb.fd == fd)
     {
@@ -1545,18 +1557,79 @@
   engine_gpgsm_t gpgsm = engine;
   gpgme_error_t err;
   gpgme_data_encoding_t dataenc;
+  int idx;
 
   if (!gpgsm)
     return gpg_error (GPG_ERR_INV_VALUE);
 
   if (keydata && keyarray)
-    gpg_error (GPG_ERR_INV_VALUE); /* Only one is allowed.  */
+    return gpg_error (GPG_ERR_INV_VALUE); /* Only one is allowed.  */
 
   dataenc = gpgme_data_get_encoding (keydata);
 
   if (keyarray)
     {
-      return gpg_error (GPG_ERR_NOT_IMPLEMENTED);
+      size_t buflen;
+      char *buffer, *p;
+
+      /* Fist check whether the engine already features the
+         --re-import option.  */
+      err = gpgsm_assuan_simple_command 
+        (gpgsm->assuan_ctx, 
+         "GETINFO cmd_has_option IMPORT re-import", NULL, NULL);
+      if (err)
+	return gpg_error (GPG_ERR_NOT_SUPPORTED);
+
+      /* Create an internal data object with a list of all
+         fingerprints.  The data object and its memory (to avoid an
+         extra copy by gpgme_data_new_from_mem) are stored in two
+         variables which are released by the close_notify_handler.  */
+      for (idx=0, buflen=0; keyarray[idx]; idx++)
+        {
+          if (keyarray[idx]->protocol == GPGME_PROTOCOL_CMS
+              && keyarray[idx]->subkeys
+              && keyarray[idx]->subkeys->fpr 
+              && *keyarray[idx]->subkeys->fpr)
+            buflen += strlen (keyarray[idx]->subkeys->fpr) + 1;
+        }
+      /* Allocate a bufer with extra space for the trailing Nul
+         introduced by the use of stpcpy.  */
+      buffer = malloc (buflen+1);
+      if (!buffer)
+        return gpg_error_from_syserror ();
+      for (idx=0, p = buffer; keyarray[idx]; idx++)
+        {
+          if (keyarray[idx]->protocol == GPGME_PROTOCOL_CMS
+              && keyarray[idx]->subkeys
+              && keyarray[idx]->subkeys->fpr 
+              && *keyarray[idx]->subkeys->fpr)
+            p = stpcpy (stpcpy (p, keyarray[idx]->subkeys->fpr), "\n");
+        }
+      
+      err = gpgme_data_new_from_mem (&gpgsm->input_helper_data,
+                                     buffer, buflen, 0);
+      if (err)
+        {
+          free (buffer);
+          return err;
+        }
+      gpgsm->input_helper_memory = buffer;
+
+      gpgsm->input_cb.data = gpgsm->input_helper_data;
+      err = gpgsm_set_fd (gpgsm, INPUT_FD, map_data_enc (gpgsm->input_cb.data));
+      if (err)
+        {
+          gpgme_data_release (gpgsm->input_helper_data);
+          gpgsm->input_helper_data = NULL;
+          free (gpgsm->input_helper_memory);
+          gpgsm->input_helper_memory = NULL;
+          return err;
+        }
+      gpgsm_clear_fd (gpgsm, OUTPUT_FD);
+      gpgsm_clear_fd (gpgsm, MESSAGE_FD);
+      gpgsm->inline_data = NULL;
+
+      return start (gpgsm, "IMPORT --re-import");
     }
   else if (dataenc == GPGME_DATA_ENCODING_URL
            || dataenc == GPGME_DATA_ENCODING_URL0
@@ -1573,10 +1646,9 @@
       gpgsm_clear_fd (gpgsm, OUTPUT_FD);
       gpgsm_clear_fd (gpgsm, MESSAGE_FD);
       gpgsm->inline_data = NULL;
+
+      return start (gpgsm, "IMPORT");
     }
-
-  err = start (gpgsm, "IMPORT");
-  return err;
 }
 
 

Modified: trunk/tests/run-keylist.c
===================================================================
--- trunk/tests/run-keylist.c	2009-07-07 14:17:39 UTC (rev 1391)
+++ trunk/tests/run-keylist.c	2009-07-07 14:33:10 UTC (rev 1392)
@@ -43,6 +43,8 @@
   fputs ("usage: " PGM " [options] [USERID]\n\n"
          "Options:\n"
          "  --verbose        run in verbose mode\n"
+         "  --openpgp        use the OpenPGP protocol (default)\n"
+         "  --cms            use the CMS protocol\n"
          "  --local          use GPGME_KEYLIST_MODE_LOCAL\n"
          "  --extern         use GPGME_KEYLIST_MODE_EXTERN\n"
          "  --sigs           use GPGME_KEYLIST_MODE_SIGS\n"
@@ -54,6 +56,7 @@
   exit (ex);
 }
 
+
 int 
 main (int argc, char **argv)
 {
@@ -66,6 +69,7 @@
   int import = 0;
   gpgme_key_t keyarray[100];
   int keyidx = 0;
+  gpgme_protocol_t protocol = GPGME_PROTOCOL_OpenPGP;
 
   if (argc)
     { argc--; argv++; }
@@ -85,6 +89,16 @@
           verbose = 1;
           argc--; argv++;
         }
+      else if (!strcmp (*argv, "--openpgp"))
+        {
+          protocol = GPGME_PROTOCOL_OpenPGP;
+          argc--; argv++;
+        }
+      else if (!strcmp (*argv, "--cms"))
+        {
+          protocol = GPGME_PROTOCOL_CMS;
+          argc--; argv++;
+        }
       else if (!strcmp (*argv, "--local"))
         {
           mode |= GPGME_KEYLIST_MODE_LOCAL;
@@ -128,11 +142,11 @@
   if (argc > 1)
     show_usage (1);
 
-  init_gpgme (GPGME_PROTOCOL_OpenPGP);
+  init_gpgme (protocol);
 
   err = gpgme_new (&ctx);
   fail_if_err (err);
-  gpgme_set_protocol (ctx, GPGME_PROTOCOL_OpenPGP);
+  gpgme_set_protocol (ctx, protocol);
 
   gpgme_set_keylist_mode (ctx, mode);
 




More information about the Gnupg-commits mailing list