Merge branch 'switch-to-gpgk' into master
authorWerner Koch <wk@gnupg.org>
Fri, 27 Sep 2019 13:44:23 +0000 (15:44 +0200)
committerWerner Koch <wk@gnupg.org>
Fri, 27 Sep 2019 13:44:23 +0000 (15:44 +0200)
--
Resolved Conflicts:

* common/asshelp.c: Keep the new code in master for spawing under
Windows.
* g10/Makefile.am: Keep all new file.
* g10/photoid.c: Pass CTRL to pct_expando.

Signed-off-by: Werner Koch <wk@gnupg.org>
22 files changed:
1  2 
common/asshelp.c
configure.ac
doc/DETAILS
g10/Makefile.am
g10/export.c
g10/getkey.c
g10/gpg.c
g10/import.c
g10/keydb.c
g10/keydb.h
g10/keyedit.c
g10/keygen.c
g10/keylist.c
g10/keyserver.c
g10/options.h
g10/photoid.c
g10/sign.c
g10/trustdb.c
kbx/keybox-blob.c
kbx/keybox-dump.c
kbx/keybox-update.c
sm/keydb.c

@@@ -489,30 -524,22 +524,32 @@@ start_new_service (assuan_context_t *r_
        argv[i++] = "--daemon";
        argv[i++] = NULL;
  
-       if (!(err = lock_spawning (&lock, gnupg_homedir (), "agent", verbose))
-           && assuan_socket_connect (ctx, sockname, 0, 0))
+       if (!(err = lock_spawning (&lock, gnupg_homedir (), lock_name, verbose))
+           && assuan_socket_connect (ctx, sockname, 0, connect_flags))
          {
-           err = gnupg_spawn_process_detached (program? program : agent_program,
 +#ifdef HAVE_W32_SYSTEM
+           err = gnupg_spawn_process_detached (program? program : program_name,
                                                argv, NULL);
- #else
++#else /*!W32*/
 +          pid_t pid;
 +
-           err = gnupg_spawn_process_fd (program? program : agent_program,
++          err = gnupg_spawn_process_fd (program? program : program_name,
 +                                        argv, -1, -1, -1, &pid);
 +          if (!err)
-             err = gnupg_wait_process (program? program : agent_program,
++            err = gnupg_wait_process (program? program : program_name,
 +                                      pid, 1, NULL);
- #endif
++#endif /*!W32*/
            if (err)
-             log_error ("failed to start agent '%s': %s\n",
-                        agent_program, gpg_strerror (err));
+             log_error ("failed to start %s '%s': %s\n",
+                        printed_name, program? program : program_name,
+                        gpg_strerror (err));
            else
-             err = wait_for_sock (SECS_TO_WAIT_FOR_AGENT, 0,
-                                  sockname, verbose, ctx, &did_success_msg);
+             err = wait_for_sock (seconds_to_wait, module_name_id,
+                                  sockname, connect_flags,
+                                  verbose, ctx, &did_success_msg);
          }
  
-       unlock_spawning (&lock, "agent");
+       unlock_spawning (&lock, lock_name);
        xfree (abs_homedir);
        xfree (program);
      }
@@@ -571,114 -621,33 +631,33 @@@ start_new_keyboxd (assuan_context_t *r_
                     gpg_error_t (*status_cb)(ctrl_t, int, ...),
                     ctrl_t status_cb_arg)
  {
-   gpg_error_t err;
-   assuan_context_t ctx;
-   const char *sockname;
-   int did_success_msg = 0;
-   *r_ctx = NULL;
-   err = assuan_new (&ctx);
-   if (err)
-     {
-       log_error ("error allocating assuan context: %s\n", gpg_strerror (err));
-       return err;
-     }
-   sockname = dirmngr_socket_name ();
-   err = assuan_socket_connect (ctx, sockname, 0, 0);
- #ifdef USE_DIRMNGR_AUTO_START
-   if (err && autostart)
-     {
-       lock_spawn_t lock;
-       const char *argv[4];
-       char *abs_homedir;
-       /* No connection: Try start a new Dirmngr.  */
-       if (!dirmngr_program || !*dirmngr_program)
-         dirmngr_program = gnupg_module_name (GNUPG_MODULE_NAME_DIRMNGR);
-       if (verbose)
-         log_info (_("no running dirmngr - starting '%s'\n"),
-                   dirmngr_program);
-       if (status_cb)
-         status_cb (status_cb_arg, STATUS_PROGRESS,
-                    "starting_dirmngr ? 0 0", NULL);
-       abs_homedir = make_absfilename (gnupg_homedir (), NULL);
-       if (!abs_homedir)
-         {
-           gpg_error_t tmperr = gpg_err_make (errsource,
-                                              gpg_err_code_from_syserror ());
-           log_error ("error building filename: %s\n",gpg_strerror (tmperr));
-           assuan_release (ctx);
-           return tmperr;
-         }
-       if (fflush (NULL))
-         {
-           gpg_error_t tmperr = gpg_err_make (errsource,
-                                              gpg_err_code_from_syserror ());
-           log_error ("error flushing pending output: %s\n",
-                      strerror (errno));
-           assuan_release (ctx);
-           return tmperr;
-         }
+   return start_new_service (r_ctx, GNUPG_MODULE_NAME_KEYBOXD,
+                             errsource, keyboxd_program,
+                             NULL, NULL, NULL,
+                             autostart, verbose, debug,
+                             status_cb, status_cb_arg);
+ }
  
-       argv[0] = "--daemon";
-       /* Try starting the daemon.  Versions of dirmngr < 2.1.15 do
-        * this only if the home directory is given on the command line.  */
-       argv[1] = "--homedir";
-       argv[2] = abs_homedir;
-       argv[3] = NULL;
  
-       if (!(err = lock_spawning (&lock, gnupg_homedir (), "dirmngr", verbose))
-           && assuan_socket_connect (ctx, sockname, 0, 0))
-         {
- #ifdef HAVE_W32_SYSTEM
-           err = gnupg_spawn_process_detached (dirmngr_program, argv, NULL);
- #else
-           pid_t pid;
-           err = gnupg_spawn_process_fd (dirmngr_program, argv,
-                                         -1, -1, -1, &pid);
-           if (!err)
-             err = gnupg_wait_process (dirmngr_program, pid, 1, NULL);
+ /* Try to connect to the dirmngr via a socket.  On platforms
+    supporting it, start it up if needed and if AUTOSTART is true.
+    Returns a new assuan context at R_CTX or an error code. */
+ gpg_error_t
+ start_new_dirmngr (assuan_context_t *r_ctx,
+                    gpg_err_source_t errsource,
+                    const char *dirmngr_program,
+                    int autostart, int verbose, int debug,
+                    gpg_error_t (*status_cb)(ctrl_t, int, ...),
+                    ctrl_t status_cb_arg)
+ {
 -#ifdef USE_DIRMNGR_AUTO_START
++#ifndef USE_DIRMNGR_AUTO_START
+   autostart = 0;
  #endif
-           if (err)
-             log_error ("failed to start the dirmngr '%s': %s\n",
-                        dirmngr_program, gpg_strerror (err));
-           else
-             err = wait_for_sock (SECS_TO_WAIT_FOR_DIRMNGR, 1,
-                                  sockname, verbose, ctx, &did_success_msg);
-         }
-       unlock_spawning (&lock, "dirmngr");
-       xfree (abs_homedir);
-     }
- #else
-   (void)dirmngr_program;
-   (void)verbose;
-   (void)status_cb;
-   (void)status_cb_arg;
- #endif /*USE_DIRMNGR_AUTO_START*/
-   if (err)
-     {
-       if (autostart || gpg_err_code (err) != GPG_ERR_ASS_CONNECT_FAILED)
-         log_error ("connecting dirmngr at '%s' failed: %s\n",
-                    sockname, gpg_strerror (err));
-       assuan_release (ctx);
-       return gpg_err_make (errsource, GPG_ERR_NO_DIRMNGR);
-     }
-   if (debug && !did_success_msg)
-     log_debug ("connection to the dirmngr established\n");
-   *r_ctx = ctx;
-   return 0;
+   return start_new_service (r_ctx, GNUPG_MODULE_NAME_DIRMNGR,
+                             errsource, dirmngr_program,
+                             NULL, NULL, NULL,
+                             autostart, verbose, debug,
+                             status_cb, status_cb_arg);
  }
  
  
diff --cc configure.ac
Simple merge
diff --cc doc/DETAILS
Simple merge
diff --cc g10/Makefile.am
@@@ -99,8 -99,10 +99,11 @@@ common_source =  
              filter.h          \
              free-packet.c     \
              getkey.c          \
-             keydb.c keydb.h    \
 +            expand-group.c    \
+             keydb.h           \
+             keydb-private.h   \
+               call-keyboxd.c    \
+             keydb.c           \
              keyring.c keyring.h \
              seskey.c          \
              kbnode.c          \
diff --cc g10/export.c
Simple merge
diff --cc g10/getkey.c
Simple merge
diff --cc g10/gpg.c
+++ b/g10/gpg.c
@@@ -896,11 -899,8 +900,12 @@@ static ARGPARSE_OPTS opts[] = 
    ARGPARSE_s_n (oNoAutoKeyLocate, "no-auto-key-locate", "@"),
    ARGPARSE_s_n (oNoAutostart, "no-autostart", "@"),
    ARGPARSE_s_n (oNoSymkeyCache, "no-symkey-cache", "@"),
+   ARGPARSE_s_n (oUseKeyboxd,    "use-keyboxd", "@"),
  
 +  /* Options which can be used in special circumstances. They are not
 +   * published and we hope they are never required.  */
 +  ARGPARSE_s_n (oUseOnlyOpenPGPCard, "use-only-openpgp-card", "@"),
 +
    /* Dummy options with warnings.  */
    ARGPARSE_s_n (oUseAgent,      "use-agent", "@"),
    ARGPARSE_s_n (oNoUseAgent, "no-use-agent", "@"),
diff --cc g10/import.c
Simple merge
diff --cc g10/keydb.c
Simple merge
diff --cc g10/keydb.h
Simple merge
diff --cc g10/keyedit.c
Simple merge
diff --cc g10/keygen.c
Simple merge
diff --cc g10/keylist.c
Simple merge
diff --cc g10/keyserver.c
Simple merge
diff --cc g10/options.h
Simple merge
diff --cc g10/photoid.c
@@@ -652,33 -322,28 +652,33 @@@ show_photos (ctrl_t ctrl, const struct 
  
    es_fflush (es_stdout);
  
 -  for(i=0;i<count;i++)
 -    if(attrs[i].type==ATTRIB_IMAGE &&
 -       parse_image_header(&attrs[i],&args.imagetype,&len))
 -      {
 -      char *command,*name;
 -      struct exec_info *spawn;
 -      int offset=attrs[i].len-len;
 -
  #ifdef FIXED_PHOTO_VIEWER
 -      opt.photo_viewer=FIXED_PHOTO_VIEWER;
 +  opt.photo_viewer = FIXED_PHOTO_VIEWER;
  #else
 -      if(!opt.photo_viewer)
 -        opt.photo_viewer=get_default_photo_command();
 +  if (!opt.photo_viewer)
 +    opt.photo_viewer = get_default_photo_command ();
  #endif
  
 +  for (i=0; i<count; i++)
 +    if (attrs[i].type == ATTRIB_IMAGE
 +        && parse_image_header (&attrs[i], &args.imagetype, &len))
 +      {
 +        char *command, *name;
 +        int offset = attrs[i].len-len;
 +
        /* make command grow */
-       command = pct_expando (opt.photo_viewer, &args);
-       if (!command)
 -      command=pct_expando (ctrl, opt.photo_viewer,&args);
++      command = pct_expando (ctrl, opt.photo_viewer,&args);
+       if(!command)
          goto fail;
  
 -      name=xmalloc(16+strlen(EXTSEP_S)+
 -                   strlen(image_type_to_string(args.imagetype,0))+1);
 +      name = xmalloc (1 + 16 + strlen(EXTSEP_S)
 +                        + strlen (image_type_to_string (args.imagetype, 0)));
 +
 +      if (!name)
 +          {
 +            xfree (command);
 +            goto fail;
 +          }
  
        /* Make the filename.  Notice we are not using the image
             encoding type for more than cosmetics.  Most external image
diff --cc g10/sign.c
Simple merge
diff --cc g10/trustdb.c
Simple merge
Simple merge
Simple merge
Simple merge
diff --cc sm/keydb.c
Simple merge