[git] GnuPG - branch, master, updated. gnupg-2.1.21-154-g0ef5034

by Werner Koch cvs at cvs.gnupg.org
Tue Jul 25 13:09:41 CEST 2017


This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "The GNU Privacy Guard".

The branch, master has been updated
       via  0ef50340ef68b2541d9a1aafa71f5400aef4dc7e (commit)
       via  226f143ca01cf335c7c4e3e94c96fb9d271eccc9 (commit)
       via  f2d2648a4deb205c26ac869c857c000a95d3ff0c (commit)
      from  166d0d7a2439f30c0a250faadc16ce3453447d71 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit 0ef50340ef68b2541d9a1aafa71f5400aef4dc7e
Author: Werner Koch <wk at gnupg.org>
Date:   Tue Jul 25 12:52:33 2017 +0200

    w32: Also change the directory on daemon startup.
    
    * agent/gpg-agent.c (main): Always to the chdir.
    * dirmngr/dirmngr.c (main): Ditto.
    * scd/scdaemon.c (main): Ditto.
    --
    
    Note that only dirmngr did not call the chdir with --no-detach.  thus
    we kept it this way.
    
    Tested gpg-agent by checking the properties shown by procexp.
    
    Gnupg-bug-id: 2670
    Signed-off-by: Werner Koch <wk at gnupg.org>

diff --git a/agent/gpg-agent.c b/agent/gpg-agent.c
index ef35174..36c05bc 100644
--- a/agent/gpg-agent.c
+++ b/agent/gpg-agent.c
@@ -1708,13 +1708,6 @@ main (int argc, char **argv )
           opt.running_detached = 1;
         }
 
-      if (gnupg_chdir (gnupg_daemon_rootdir ()))
-        {
-          log_error ("chdir to '%s' failed: %s\n",
-                     gnupg_daemon_rootdir (), strerror (errno));
-          exit (1);
-        }
-
       {
         struct sigaction sa;
 
@@ -1725,6 +1718,13 @@ main (int argc, char **argv )
       }
 #endif /*!HAVE_W32_SYSTEM*/
 
+      if (gnupg_chdir (gnupg_daemon_rootdir ()))
+        {
+          log_error ("chdir to '%s' failed: %s\n",
+                     gnupg_daemon_rootdir (), strerror (errno));
+          exit (1);
+        }
+
       log_info ("%s %s started\n", strusage(11), strusage(13) );
       handle_connections (fd, fd_extra, fd_browser, fd_ssh);
       assuan_sock_close (fd);
diff --git a/dirmngr/dirmngr.c b/dirmngr/dirmngr.c
index 436c808..5f3a4cd 100644
--- a/dirmngr/dirmngr.c
+++ b/dirmngr/dirmngr.c
@@ -1351,15 +1351,18 @@ main (int argc, char **argv)
           log_set_prefix (NULL, oldflags | GPGRT_LOG_RUN_DETACHED);
           opt.running_detached = 1;
 
+        }
+#endif
+
+      if (!nodetach )
+        {
           if (gnupg_chdir (gnupg_daemon_rootdir ()))
             {
               log_error ("chdir to '%s' failed: %s\n",
                          gnupg_daemon_rootdir (), strerror (errno));
               dirmngr_exit (1);
             }
-
         }
-#endif
 
       thread_init ();
       cert_cache_init (hkp_cacert_filenames);
diff --git a/scd/scdaemon.c b/scd/scdaemon.c
index bf3f42a..60d539d 100644
--- a/scd/scdaemon.c
+++ b/scd/scdaemon.c
@@ -908,6 +908,8 @@ main (int argc, char **argv )
         sigaction (SIGPIPE, &sa, NULL);
       }
 
+#endif /*!HAVE_W32_SYSTEM*/
+
       if (gnupg_chdir (gnupg_daemon_rootdir ()))
         {
           log_error ("chdir to '%s' failed: %s\n",
@@ -915,8 +917,6 @@ main (int argc, char **argv )
           exit (1);
         }
 
-#endif /*!HAVE_W32_SYSTEM*/
-
       handle_connections (fd);
 
       close (fd);

commit 226f143ca01cf335c7c4e3e94c96fb9d271eccc9
Author: Werner Koch <wk at gnupg.org>
Date:   Tue Jul 25 12:24:01 2017 +0200

    common: New functions gnupg_daemon_rootdir and gnupg_chdir.
    
    * common/sysutils.c (gnupg_chdir): New.
    * common/homedir.c (gnupg_daemon_rootdir): New.
    * agent/gpg-agent.c (main): Use these functions instead chdir("/").
    * dirmngr/dirmngr.c (main): Ditto.
    * scd/scdaemon.c (main): Ditto.
    --
    
    Signed-off-by: Werner Koch <wk at gnupg.org>

diff --git a/agent/gpg-agent.c b/agent/gpg-agent.c
index efaebfd..ef35174 100644
--- a/agent/gpg-agent.c
+++ b/agent/gpg-agent.c
@@ -1708,9 +1708,10 @@ main (int argc, char **argv )
           opt.running_detached = 1;
         }
 
-      if (chdir("/"))
+      if (gnupg_chdir (gnupg_daemon_rootdir ()))
         {
-          log_error ("chdir to / failed: %s\n", strerror (errno));
+          log_error ("chdir to '%s' failed: %s\n",
+                     gnupg_daemon_rootdir (), strerror (errno));
           exit (1);
         }
 
diff --git a/common/homedir.c b/common/homedir.c
index fce6d44..a30e8dc 100644
--- a/common/homedir.c
+++ b/common/homedir.c
@@ -433,6 +433,34 @@ gnupg_default_homedir_p (void)
 }
 
 
+/* Return the directory name used by daemons for their current working
+ * directory.  */
+const char *
+gnupg_daemon_rootdir (void)
+{
+#ifdef HAVE_W32_SYSTEM
+  static char *name;
+
+  if (!name)
+    {
+      char path[MAX_PATH];
+      size_t n;
+
+      n = GetSystemDirectoryA (path, sizeof path);
+      if (!n || n >= sizeof path)
+        name = xstrdup ("/"); /* Error - use the curret top dir instead.  */
+      else
+        name = xstrdup (path);
+    }
+
+  return name;
+
+#else /*!HAVE_W32_SYSTEM*/
+  return "/";
+#endif /*!HAVE_W32_SYSTEM*/
+}
+
+
 /* Helper for gnupg-socketdir.  This is a global function, so that
  * gpgconf can use it for its --create-socketdir command.  If
  * SKIP_CHECKS is set permission checks etc. are not done.  The
diff --git a/common/sysutils.c b/common/sysutils.c
index 1aa2e53..e90010c 100644
--- a/common/sysutils.c
+++ b/common/sysutils.c
@@ -796,6 +796,15 @@ gnupg_mkdir (const char *name, const char *modestr)
 }
 
 
+/* A simple wrapper around chdir.  NAME is expected to be utf8
+ * encoded.  */
+int
+gnupg_chdir (const char *name)
+{
+  return chdir (name);
+}
+
+
 /* A wrapper around chmod which takes a string for the mode argument.
    This makes it easier to handle the mode argument which is not
    defined on all systems.  The format of the modestring is the same
diff --git a/common/sysutils.h b/common/sysutils.h
index e93ea2b..009b14b 100644
--- a/common/sysutils.h
+++ b/common/sysutils.h
@@ -65,7 +65,8 @@ void gnupg_allow_set_foregound_window (pid_t pid);
 int  gnupg_remove (const char *fname);
 gpg_error_t gnupg_rename_file (const char *oldname, const char *newname,
                                int *block_signals);
-int  gnupg_mkdir (const char *name, const char *modestr);
+int gnupg_mkdir (const char *name, const char *modestr);
+int gnupg_chdir (const char *name);
 int gnupg_chmod (const char *name, const char *modestr);
 char *gnupg_mkdtemp (char *template);
 int  gnupg_setenv (const char *name, const char *value, int overwrite);
diff --git a/common/util.h b/common/util.h
index 5b712d3..c6d19c6 100644
--- a/common/util.h
+++ b/common/util.h
@@ -235,6 +235,7 @@ const char *default_homedir (void);
 void gnupg_set_homedir (const char *newdir);
 const char *gnupg_homedir (void);
 int gnupg_default_homedir_p (void);
+const char *gnupg_daemon_rootdir (void);
 const char *gnupg_socketdir (void);
 const char *gnupg_sysconfdir (void);
 const char *gnupg_bindir (void);
diff --git a/dirmngr/dirmngr.c b/dirmngr/dirmngr.c
index 6eabca9..436c808 100644
--- a/dirmngr/dirmngr.c
+++ b/dirmngr/dirmngr.c
@@ -1351,11 +1351,13 @@ main (int argc, char **argv)
           log_set_prefix (NULL, oldflags | GPGRT_LOG_RUN_DETACHED);
           opt.running_detached = 1;
 
-          if (chdir("/"))
+          if (gnupg_chdir (gnupg_daemon_rootdir ()))
             {
-              log_error ("chdir to / failed: %s\n", strerror (errno));
+              log_error ("chdir to '%s' failed: %s\n",
+                         gnupg_daemon_rootdir (), strerror (errno));
               dirmngr_exit (1);
             }
+
         }
 #endif
 
diff --git a/scd/scdaemon.c b/scd/scdaemon.c
index 26e89dd..bf3f42a 100644
--- a/scd/scdaemon.c
+++ b/scd/scdaemon.c
@@ -908,9 +908,10 @@ main (int argc, char **argv )
         sigaction (SIGPIPE, &sa, NULL);
       }
 
-      if (chdir("/"))
+      if (gnupg_chdir (gnupg_daemon_rootdir ()))
         {
-          log_error ("chdir to / failed: %s\n", strerror (errno));
+          log_error ("chdir to '%s' failed: %s\n",
+                     gnupg_daemon_rootdir (), strerror (errno));
           exit (1);
         }
 

commit f2d2648a4deb205c26ac869c857c000a95d3ff0c
Author: Werner Koch <wk at gnupg.org>
Date:   Tue Jul 25 12:19:08 2017 +0200

    Revert "w32: Change directory on daemon startup."
    
    --
    This reverts commit 78ebc62604d77600b9865950610717d28c6027a2.
    Gnupg-bug-id: 2670

diff --git a/agent/gpg-agent.c b/agent/gpg-agent.c
index 90e8a26..efaebfd 100644
--- a/agent/gpg-agent.c
+++ b/agent/gpg-agent.c
@@ -39,7 +39,6 @@
 # endif
 # include <aclapi.h>
 # include <sddl.h>
-# include <direct.h>
 #else /*!HAVE_W32_SYSTEM*/
 # include <sys/socket.h>
 # include <sys/un.h>
@@ -1559,11 +1558,6 @@ main (int argc, char **argv )
       (void)csh_style;
       (void)nodetach;
       initialize_modules ();
-      if (_chdir("\\"))
-        {
-          log_error ("chdir to / failed: %s\n", strerror (errno));
-          exit (1);
-        }
 
 #else /*!HAVE_W32_SYSTEM*/
 
diff --git a/dirmngr/dirmngr.c b/dirmngr/dirmngr.c
index b19b418..6eabca9 100644
--- a/dirmngr/dirmngr.c
+++ b/dirmngr/dirmngr.c
@@ -30,11 +30,9 @@
 #include <assert.h>
 #include <time.h>
 #include <fcntl.h>
-#ifdef HAVE_W32_SYSTEM
-# include <direct.h>
-#else
-# include <sys/socket.h>
-# include <sys/un.h>
+#ifndef HAVE_W32_SYSTEM
+#include <sys/socket.h>
+#include <sys/un.h>
 #endif
 #include <sys/stat.h>
 #include <unistd.h>
@@ -1270,11 +1268,6 @@ main (int argc, char **argv)
 #ifdef HAVE_W32_SYSTEM
       (void)csh_style;
       (void)nodetach;
-      if (_chdir("\\"))
-        {
-          log_error ("chdir to / failed: %s\n", strerror (errno));
-          exit (1);
-        }
 
       pid = getpid ();
       es_printf ("set %s=%s;%lu;1\n",
diff --git a/scd/scdaemon.c b/scd/scdaemon.c
index bbb0433..26e89dd 100644
--- a/scd/scdaemon.c
+++ b/scd/scdaemon.c
@@ -29,11 +29,9 @@
 #include <assert.h>
 #include <time.h>
 #include <fcntl.h>
-#ifdef HAVE_W32_SYSTEM
-# include <direct.h>
-#else
-# include <sys/socket.h>
-# include <sys/un.h>
+#ifndef HAVE_W32_SYSTEM
+#include <sys/socket.h>
+#include <sys/un.h>
 #endif /*HAVE_W32_SYSTEM*/
 #include <unistd.h>
 #include <signal.h>
@@ -813,11 +811,6 @@ main (int argc, char **argv )
 #ifdef HAVE_W32_SYSTEM
       (void)csh_style;
       (void)nodetach;
-      if (_chdir("\\"))
-        {
-          log_error ("chdir to / failed: %s\n", strerror (errno));
-          exit (1);
-        }
 #else
       pid = fork ();
       if (pid == (pid_t)-1)

-----------------------------------------------------------------------

Summary of changes:
 agent/gpg-agent.c | 19 +++++++------------
 common/homedir.c  | 28 ++++++++++++++++++++++++++++
 common/sysutils.c |  9 +++++++++
 common/sysutils.h |  3 ++-
 common/util.h     |  1 +
 dirmngr/dirmngr.c | 24 +++++++++++-------------
 scd/scdaemon.c    | 22 ++++++++--------------
 7 files changed, 66 insertions(+), 40 deletions(-)


hooks/post-receive
-- 
The GNU Privacy Guard
http://git.gnupg.org




More information about the Gnupg-commits mailing list