[svn] dirmngr - r325 - in trunk: . src tests

svn author marcus cvs at cvs.gnupg.org
Wed Sep 23 01:14:12 CEST 2009


Author: marcus
Date: 2009-09-23 01:14:11 +0200 (Wed, 23 Sep 2009)
New Revision: 325

Modified:
   trunk/configure.ac
   trunk/src/ChangeLog
   trunk/src/dirmngr-client.c
   trunk/src/dirmngr.c
   trunk/src/server.c
   trunk/tests/test-dirmngr.c
Log:
2009-09-22  Marcus Brinkmann  <marcus at g10code.de>

	* configure.ac (NEED_LIBASSUAN_API, NEED_LIBASSUAN_VERSION): Bump
	to new Assuan interface (2, 1.1.0).
	* tests/test-dirmngr.c: Update to new Assuan interface.
	(print_assuan_error): Use gpg_strerror
	instead of assuan_strerror.
	(start_dirmngr): Allocate context with assuan_new before
	connecting to server.  Release on error.
	(sendcert): Return gpg_error_t instead of int.

src/
2009-09-22  Marcus Brinkmann  <marcus at g10code.de>

	* dirmngr.c (main): Update to new Assuan interface.
	* server.c (option_handler, cmd_ldapserver, cmd_isvalid)
	(cmd_checkcrl, cmd_checkocsp, cmd_lookup, cmd_loadcrl)
	(cmd_listcrls, cmd_cachecert, cmd_validate): Return gpg_error_t
	instead int.
	(register_commands): Likewise for member HANDLER.
	(start_command_handler): Allocate context with assuan_new before
	starting server.  Release on error.
	* dirmngr-client.c (main): Update to new Assuan interface.
	(start_dirmngr): Allocate context with assuan_new before
	connecting to server.  Release on error.


Modified: trunk/src/ChangeLog
===================================================================
--- trunk/src/ChangeLog	2009-08-12 19:29:31 UTC (rev 324)
+++ trunk/src/ChangeLog	2009-09-22 23:14:11 UTC (rev 325)
@@ -1,3 +1,17 @@
+2009-09-22  Marcus Brinkmann  <marcus at g10code.de>
+
+	* dirmngr.c (main): Update to new Assuan interface.
+	* server.c (option_handler, cmd_ldapserver, cmd_isvalid)
+	(cmd_checkcrl, cmd_checkocsp, cmd_lookup, cmd_loadcrl)
+	(cmd_listcrls, cmd_cachecert, cmd_validate): Return gpg_error_t
+	instead int.
+	(register_commands): Likewise for member HANDLER.
+	(start_command_handler): Allocate context with assuan_new before
+	starting server.  Release on error.
+	* dirmngr-client.c (main): Update to new Assuan interface.
+	(start_dirmngr): Allocate context with assuan_new before
+	connecting to server.  Release on error.
+
 2009-08-12  Werner Koch  <wk at g10code.com>
 
 	* dirmngr-client.c (squid_loop_body): Flush stdout.  Suggested by

Modified: trunk/configure.ac
===================================================================
--- trunk/configure.ac	2009-08-12 19:29:31 UTC (rev 324)
+++ trunk/configure.ac	2009-09-22 23:14:11 UTC (rev 325)
@@ -41,8 +41,8 @@
 NEED_LIBGCRYPT_API=1
 NEED_LIBGCRYPT_VERSION=1.4.0
 
-NEED_LIBASSUAN_API=1
-NEED_LIBASSUAN_VERSION=1.0.4
+NEED_LIBASSUAN_API=2
+NEED_LIBASSUAN_VERSION=1.1.0
 
 NEED_KSBA_API=1
 NEED_KSBA_VERSION=1.0.2

Modified: trunk/src/dirmngr-client.c
===================================================================
--- trunk/src/dirmngr-client.c	2009-08-12 19:29:31 UTC (rev 324)
+++ trunk/src/dirmngr-client.c	2009-09-22 23:14:11 UTC (rev 325)
@@ -211,9 +211,8 @@
 #endif /*HAVE_W32_SYSTEM*/
   
   /* Init Assuan.  */
-  assuan_set_assuan_log_stream (log_get_stream ());
   assuan_set_assuan_log_prefix (log_get_prefix (NULL));
-  assuan_set_assuan_err_source (GPG_ERR_SOURCE_DEFAULT);
+  assuan_set_gpg_err_source (GPG_ERR_SOURCE_DEFAULT);
 
   /* Setup I18N. */
   i18n_init();
@@ -367,7 +366,7 @@
       xfree (certbuf);
     }
 
-  assuan_disconnect (ctx);
+  assuan_release (ctx);
 
   if (cmd_ping)
     {
@@ -463,6 +462,14 @@
       infostr = xstrdup (default_socket_name ());
       try_default = 1;
     }
+
+  rc = assuan_new (&ctx);
+  if (rc)
+    {
+      log_error (_("can't create assuan context: %s\n"), gpg_strerror (rc));
+      return NULL;
+    }
+
   if (!infostr || !*infostr)
     {
       const char *pgmname;
@@ -497,7 +504,7 @@
       no_close_list[i] = -1;
 
       /* Connect to the agent and perform initial handshaking.  */
-      rc = assuan_pipe_connect (&ctx, opt.dirmngr_program, argv,
+      rc = assuan_pipe_connect (ctx, opt.dirmngr_program, argv,
                                 no_close_list);
     }
   else /* Connect to a daemon.  */
@@ -537,7 +544,7 @@
       else
         pid = -1;
 
-      rc = assuan_socket_connect (&ctx, infostr, pid);
+      rc = assuan_socket_connect (ctx, infostr, pid);
       xfree (infostr);
       if (gpg_err_code(rc) == GPG_ERR_ASS_CONNECT_FAILED && !only_daemon)
         {
@@ -549,6 +556,7 @@
 
   if (rc)
     {
+      assuan_release (ctx);
       log_error (_("can't connect to the dirmngr: %s\n"),
                  gpg_strerror (rc));
       return NULL;

Modified: trunk/src/dirmngr.c
===================================================================
--- trunk/src/dirmngr.c	2009-08-12 19:29:31 UTC (rev 324)
+++ trunk/src/dirmngr.c	2009-09-22 23:14:11 UTC (rev 325)
@@ -592,6 +592,7 @@
   int debug_wait = 0;
   int rc;
   int homedir_seen = 0;
+  struct assuan_malloc_hooks malloc_hooks;
 
 #ifdef HAVE_W32_SYSTEM
   /* The option will be set by main() below if we should run as a
@@ -654,10 +655,12 @@
 
 
   /* Init Assuan. */
-  assuan_set_malloc_hooks (gcry_malloc, gcry_realloc, gcry_free);
-  assuan_set_assuan_log_stream (log_get_stream ());
+  malloc_hooks.malloc = gcry_malloc;
+  malloc_hooks.realloc = gcry_realloc;
+  malloc_hooks.free = gcry_free;
+  assuan_set_malloc_hooks (&malloc_hooks);
   assuan_set_assuan_log_prefix (log_get_prefix (NULL));
-  assuan_set_assuan_err_source (GPG_ERR_SOURCE_DEFAULT);
+  assuan_set_gpg_err_source (GPG_ERR_SOURCE_DEFAULT);
 
   /* Setup I18N. */
   i18n_init();
@@ -914,7 +917,6 @@
         {
           log_set_file (logfile);
           log_set_prefix (NULL, 2|4);
-	  assuan_set_assuan_log_stream (log_get_stream ());
         }
        
       if (debug_wait)
@@ -949,7 +951,6 @@
                                  |JNLIB_LOG_WITH_TIME
                                  |JNLIB_LOG_WITH_PID));
           current_logfile = xstrdup (logfile);
-	  assuan_set_assuan_log_stream (log_get_stream ());
         }
 
 #ifndef HAVE_W32_SYSTEM

Modified: trunk/src/server.c
===================================================================
--- trunk/src/server.c	2009-08-12 19:29:31 UTC (rev 324)
+++ trunk/src/server.c	2009-09-22 23:14:11 UTC (rev 325)
@@ -416,7 +416,7 @@
 
 
 /* Handle OPTION commands. */
-static int
+static gpg_error_t
 option_handler (assuan_context_t ctx, const char *key, const char *value)
 {
   ctrl_t ctrl = assuan_get_pointer (ctx);
@@ -438,7 +438,7 @@
 }
 
 
-static int
+static gpg_error_t
 cmd_ldapserver (assuan_context_t ctx, char *line)
 {
   ctrl_t ctrl = assuan_get_pointer (ctx);
@@ -486,7 +486,7 @@
    OCSP responder URL won't be used.
  */
 
-static int
+static gpg_error_t
 cmd_isvalid (assuan_context_t ctx, char *line)
 {
   ctrl_t ctrl = assuan_get_pointer (ctx);
@@ -635,7 +635,7 @@
    The return value is the usual gpg-error code or 0 for ducesss;
    i.e. the certificate validity has been confirmed by a valid CRL.
 */
-static int
+static gpg_error_t
 cmd_checkcrl (assuan_context_t ctx, char *line)
 {
   ctrl_t ctrl = assuan_get_pointer (ctx);
@@ -719,7 +719,7 @@
    The return value is the usual gpg-error code or 0 for ducesss;
    i.e. the certificate validity has been confirmed by a valid CRL.
 */
-static int
+static gpg_error_t
 cmd_checkocsp (assuan_context_t ctx, char *line)
 {
   ctrl_t ctrl = assuan_get_pointer (ctx);
@@ -1045,7 +1045,7 @@
    certificates from the cache may get returned.
 */
 
-static int
+static gpg_error_t
 cmd_lookup (assuan_context_t ctx, char *line)
 {
   gpg_error_t err;
@@ -1084,7 +1084,7 @@
    is not useful because gpgsm might need to callback gpgsm to ask for
    the CA's certificate.  */
 
-static int
+static gpg_error_t
 cmd_loadcrl (assuan_context_t ctx, char *line)
 {
   ctrl_t ctrl = assuan_get_pointer (ctx);
@@ -1139,7 +1139,7 @@
    --list-crls".
 */
 
-static int
+static gpg_error_t
 cmd_listcrls (assuan_context_t ctx, char *line)
 {
   gpg_error_t err;
@@ -1170,7 +1170,7 @@
    and the caller is expected to return the certificate for the
    request as a binary blob.
 */
-static int
+static gpg_error_t
 cmd_cachecert (assuan_context_t ctx, char *line)
 {
   ctrl_t ctrl = assuan_get_pointer (ctx);
@@ -1223,7 +1223,7 @@
    and the caller is expected to return the certificate for the
    request as a binary blob.
 */
-static int
+static gpg_error_t
 cmd_validate (assuan_context_t ctx, char *line)
 {
   ctrl_t ctrl = assuan_get_pointer (ctx);
@@ -1287,7 +1287,7 @@
 {
   static struct {
     const char *name;
-    int (*handler)(assuan_context_t, char *line);
+    gpg_error_t (*handler)(assuan_context_t, char *line);
   } table[] = {
     { "LDAPSERVER", cmd_ldapserver },
     { "ISVALID",    cmd_isvalid },
@@ -1348,21 +1348,30 @@
     
   dirmngr_init_default_ctrl (ctrl);
 
+  rc = assuan_new (&ctx);
+  if (rc)
+    {
+      log_error (_("failed to allocate assuan context: %s\n"),
+		 gpg_strerror (rc));
+      dirmngr_exit (2);
+    }
+
   if (fd == ASSUAN_INVALID_FD)
     {
       int filedes[2];
-
+      
       filedes[0] = 0;
       filedes[1] = 1;
-      rc = assuan_init_pipe_server (&ctx, filedes);
+      rc = assuan_init_pipe_server (ctx, filedes);
     }
   else
     {
-      rc = assuan_init_socket_server_ext (&ctx, fd, 2);
+      rc = assuan_init_socket_server_ext (ctx, fd, 2);
     }
 
   if (rc)
     {
+      assuan_release (ctx);
       log_error (_("failed to initialize the server: %s\n"),
                  gpg_strerror(rc));
       dirmngr_exit (2);
@@ -1445,7 +1454,7 @@
   ctrl->server_local->ldapservers = NULL;
 
   ctrl->server_local->assuan_ctx = NULL;
-  assuan_deinit_server (ctx);
+  assuan_release (ctx);
 
   if (ctrl->refcount)
     log_error ("oops: connection control structure still referenced (%d)\n",

Modified: trunk/tests/test-dirmngr.c
===================================================================
--- trunk/tests/test-dirmngr.c	2009-08-12 19:29:31 UTC (rev 324)
+++ trunk/tests/test-dirmngr.c	2009-09-22 23:14:11 UTC (rev 325)
@@ -15,7 +15,7 @@
 
 assuan_context_t entry_ctx;
 
-#define print_assuan_error( rc ) fprintf(stderr, "Error: %s", assuan_strerror( rc ) )
+#define print_assuan_error( rc ) fprintf(stderr, "Error: %s", gpg_strerror (rc))
 
 #define fail_if_err(a) do { if(a) {                                       \
                               fprintf (stderr, "%s:%d: KSBA error: %s\n", \
@@ -55,11 +55,19 @@
   argv[0] = pgmname;
   argv[1] = NULL;
 
-  rc = assuan_pipe_connect (&ctx, pgmname, argv, 0);
+  rc = assuan_new (&ctx);
   if (rc)
     {
+      log_error ("can't allocate assuan context: %s\n", gpg_strerror (rc));
+      return -1;
+    }
+
+  rc = assuan_pipe_connect (ctx, pgmname, argv, 0);
+  if (rc)
+    {
+      assuan_release (ctx);
       log_error ("can't connect to the DirMngr module: %s\n",
-                 assuan_strerror (rc));
+		 gpg_strerror (rc));
       return -1;
     }
   entry_ctx = ctx;
@@ -131,31 +139,31 @@
 
 static int inquire_done = 0;
 
-static int 
-sendcert( void* ctx, const char* line)
+static gpg_error_t
+sendcert (void* ctx, const char* line)
 {
   FILE* infp;
   char buf[4096];
   int len = 0;
   fprintf(stderr, "######## Got inquiry \"%s\"\n", line );
 
-/*   This hack is because we only want to send */
-/*   the cert. Dirmngr will ask a second time  */
-/*   -- this time for the issuer cert. */
-/*    We dont know that, so we return nothing */
-  if( inquire_done ) return ASSUAN_No_Error;
+  /* This hack is because we only want to send the cert. Dirmngr will
+     ask a second time -- this time for the issuer cert.  We dont know
+     that, so we return nothing.  */
+  if (inquire_done)
+    return 0;
   inquire_done = 1;
   infp = fopen( fname, "r" );
   if( infp == NULL ) {
     perror("Error opening cert file");
-    return ASSUAN_General_Error;
+    return gpg_error (GPG_ERR_GENERAL);
   }
   while( !feof( infp ) ) {
     len += fread( buf+len, 1, sizeof(buf)-len, infp );
   }
   assuan_send_data( ctx, buf, len);
   fclose( infp );
-  return ASSUAN_No_Error;
+  return 0;
 }
 
 
@@ -231,7 +239,8 @@
 
   fprintf(stderr, "sending \"%s\"\n", line );
 
-  rc = assuan_transact (entry_ctx, line, NULL, NULL, sendcert, entry_ctx, NULL, NULL);
+  rc = assuan_transact (entry_ctx, line, NULL, NULL,
+			sendcert, entry_ctx, NULL, NULL);
   if( rc ) {
     fprintf(stderr,"\n#######");
     print_assuan_error(rc);




More information about the Gnupg-commits mailing list