[git] GnuPG - branch, master, updated. gnupg-2.1.14-33-g48a2c93

by Werner Koch cvs at cvs.gnupg.org
Wed Aug 3 15:42:01 CEST 2016


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  48a2c93a1886589d1a0e2a4a2173e0e81311200b (commit)
       via  3a2421c94015432caa49e166bc5bf5c4f80ab7c7 (commit)
      from  40365b28c3fdf087fd58401f5a6f42f9d7d29d20 (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 48a2c93a1886589d1a0e2a4a2173e0e81311200b
Author: Werner Koch <wk at gnupg.org>
Date:   Wed Aug 3 15:31:27 2016 +0200

    gpg,gpgsm: Block signals during keyring/keybox update.
    
    * kbx/keybox-util.c (keybox_file_rename): Add arg BLOCK_SIGNALS.
    * kbx/keybox-update.c (rename_tmp_file): Block all signals when doing
    a double rename.
    * g10/keyring.c (rename_tmp_file): Block all signals during the double
    rename.
    --
    
    This might fix
    Debian-bug-id: 831510
    
    Signed-off-by: Werner Koch <wk at gnupg.org>

diff --git a/g10/keyring.c b/g10/keyring.c
index 0611b2e..aa73290 100644
--- a/g10/keyring.c
+++ b/g10/keyring.c
@@ -1338,6 +1338,7 @@ static int
 rename_tmp_file (const char *bakfname, const char *tmpfname, const char *fname)
 {
   int rc = 0;
+  int block = 0;
 
   /* Invalidate close caches.  */
   if (iobuf_ioctl (NULL, IOBUF_IOCTL_INVALIDATE_CACHE, 0, (char*)tmpfname ))
@@ -1349,12 +1350,18 @@ rename_tmp_file (const char *bakfname, const char *tmpfname, const char *fname)
   iobuf_ioctl (NULL, IOBUF_IOCTL_INVALIDATE_CACHE, 0, (char*)fname );
 
   /* First make a backup file. */
-  rc = keybox_file_rename (fname, bakfname);
+  block = 1;
+  rc = keybox_file_rename (fname, bakfname, &block);
   if (rc)
     goto fail;
 
   /* then rename the file */
-  rc = keybox_file_rename (tmpfname, fname);
+  rc = keybox_file_rename (tmpfname, fname, NULL);
+  if (block)
+    {
+      gnupg_unblock_all_signals ();
+      block = 0;
+    }
   if (rc)
     {
       register_secured_file (fname);
@@ -1379,6 +1386,8 @@ rename_tmp_file (const char *bakfname, const char *tmpfname, const char *fname)
   return 0;
 
  fail:
+  if (block)
+    gnupg_unblock_all_signals ();
   return rc;
 }
 
diff --git a/kbx/keybox-update.c b/kbx/keybox-update.c
index ff65904..ec28b4c 100644
--- a/kbx/keybox-update.c
+++ b/kbx/keybox-update.c
@@ -97,6 +97,7 @@ rename_tmp_file (const char *bakfname, const char *tmpfname,
                  const char *fname, int secret )
 {
   int rc=0;
+  int block = 0;
 
   /* restrict the permissions for secret keyboxs */
 #ifndef HAVE_DOSISH_SYSTEM
@@ -119,27 +120,35 @@ rename_tmp_file (const char *bakfname, const char *tmpfname,
   /* First make a backup file except for secret keyboxes. */
   if (!secret)
     {
-      rc = keybox_file_rename (fname, bakfname);
+      block = 1;
+      rc = keybox_file_rename (fname, bakfname, &block);
       if (rc)
-        return rc;
+        goto leave;
     }
 
   /* Then rename the file. */
-  rc = keybox_file_rename (tmpfname, fname);
-  if (rc)
+  rc = keybox_file_rename (tmpfname, fname, NULL);
+  if (block)
     {
-      if (secret)
-        {
-/*            log_info ("WARNING: 2 files with confidential" */
-/*                       " information exists.\n"); */
-/*            log_info ("%s is the unchanged one\n", fname ); */
-/*            log_info ("%s is the new one\n", tmpfname ); */
-/*            log_info ("Please fix this possible security flaw\n"); */
-	}
-      return rc;
+      gnupg_unblock_all_signals ();
+      block = 0;
     }
+  /* if (rc) */
+  /*   { */
+  /*     if (secret) */
+  /*       { */
+  /*         log_info ("WARNING: 2 files with confidential" */
+  /*                   " information exists.\n"); */
+  /*         log_info ("%s is the unchanged one\n", fname ); */
+  /*         log_info ("%s is the new one\n", tmpfname ); */
+  /*         log_info ("Please fix this possible security flaw\n"); */
+  /*       } */
+  /*   } */
 
-  return 0;
+ leave:
+  if (block)
+    gnupg_unblock_all_signals ();
+  return rc;
 }
 
 
diff --git a/kbx/keybox-util.c b/kbx/keybox-util.c
index 13fedb3..a2ca3f0 100644
--- a/kbx/keybox-util.c
+++ b/kbx/keybox-util.c
@@ -27,6 +27,7 @@
 #endif
 
 #include "keybox-defs.h"
+#include "utilproto.h"
 
 
 static void *(*alloc_func)(size_t n) = malloc;
@@ -147,55 +148,70 @@ keybox_tmp_names (const char *filename, int for_keyring,
 }
 
 
-/* Wrapper for rename(2) to handle Windows peculiarities.  */
+/* Wrapper for rename(2) to handle Windows peculiarities.  If
+ * BLOCK_SIGNALS is not NULL and points to a variable set to true, all
+ * signals will be blocked by calling gnupg_block_all_signals; the
+ * caller needs to call gnupg_unblock_all_signals if that variable is
+ * still set to true on return. */
 gpg_error_t
-keybox_file_rename (const char *oldname, const char *newname)
+keybox_file_rename (const char *oldname, const char *newname,
+                    int *block_signals)
 {
   gpg_error_t err = 0;
 
-#ifdef HAVE_DOSISH_SYSTEM
-  int wtime = 0;
+  if (block_signals && *block_signals)
+    gnupg_block_all_signals ();
 
-  gnupg_remove (newname);
- again:
-  if (rename (oldname, newname))
-    {
-      if (GetLastError () == ERROR_SHARING_VIOLATION)
-        {
-          /* Another process has the file open.  We do not use a lock
-           * for read but instead we wait until the other process has
-           * closed the file.  This may take long but that would also
-           * be the case with a dotlock approach for read and write.
-           * Note that we don't need this on Unix due to the inode
-           * concept.
-           *
-           * So let's wait until the rename has worked.  The retry
-           * intervals are 50, 100, 200, 400, 800, 50ms, ...  */
-          if (!wtime || wtime >= 800)
-            wtime = 50;
-          else
-            wtime *= 2;
-
-          if (wtime >= 800)
-            log_info ("waiting for file '%s' to become accessible ...\n",
-                      oldname);
-
-          Sleep (wtime);
-          goto again;
-        }
-      err = gpg_error_from_syserror ();
-    }
+#ifdef HAVE_DOSISH_SYSTEM
+  {
+    int wtime = 0;
 
+    gnupg_remove (newname);
+  again:
+    if (rename (oldname, newname))
+      {
+        if (GetLastError () == ERROR_SHARING_VIOLATION)
+          {
+            /* Another process has the file open.  We do not use a
+             * lock for read but instead we wait until the other
+             * process has closed the file.  This may take long but
+             * that would also be the case with a dotlock approach for
+             * read and write.  Note that we don't need this on Unix
+             * due to the inode concept.
+             *
+             * So let's wait until the rename has worked.  The retry
+             * intervals are 50, 100, 200, 400, 800, 50ms, ...  */
+            if (!wtime || wtime >= 800)
+              wtime = 50;
+            else
+              wtime *= 2;
+
+            if (wtime >= 800)
+              log_info ("waiting for file '%s' to become accessible ...\n",
+                        oldname);
+
+            Sleep (wtime);
+            goto again;
+          }
+        err = gpg_error_from_syserror ();
+      }
+  }
 #else /* Unix */
-
+  {
 #ifdef __riscos__
-  gnupg_remove (newname);
+    gnupg_remove (newname);
 #endif
-  if (rename (oldname, newname) )
-    err = gpg_error_from_syserror ();
-
+    if (rename (oldname, newname) )
+      err = gpg_error_from_syserror ();
+  }
 #endif /* Unix */
 
+  if (block_signals && *block_signals && err)
+    {
+      gnupg_unblock_all_signals ();
+      *block_signals = 0;
+    }
+
   if (err)
     log_error ("renaming '%s' to '%s' failed: %s\n",
                oldname, newname, gpg_strerror (err));
diff --git a/kbx/keybox.h b/kbx/keybox.h
index bfc3586..6180a2f 100644
--- a/kbx/keybox.h
+++ b/kbx/keybox.h
@@ -134,7 +134,8 @@ void keybox_set_malloc_hooks ( void *(*new_alloc_func)(size_t n),
 
 gpg_error_t keybox_tmp_names (const char *filename, int for_keyring,
                               char **r_bakname, char **r_tmpname);
-gpg_error_t keybox_file_rename (const char *oldname, const char *newname);
+gpg_error_t keybox_file_rename (const char *oldname, const char *newname,
+                                int *block_signals);
 
 
 #ifdef __cplusplus

commit 3a2421c94015432caa49e166bc5bf5c4f80ab7c7
Author: Werner Koch <wk at gnupg.org>
Date:   Wed Aug 3 15:27:03 2016 +0200

    common: New file utilproto.c
    
    * common/util.h: Factor prototypes from signal.c out to ...
    * common/utilproto.h: new.
    * common/Makefile.am (common_sources): Add new file.
    
    Signed-off-by: Werner Koch <wk at gnupg.org>

diff --git a/common/Makefile.am b/common/Makefile.am
index 759800b..2a24c57 100644
--- a/common/Makefile.am
+++ b/common/Makefile.am
@@ -42,7 +42,7 @@ include $(top_srcdir)/am/cmacros.am
 
 common_sources = \
 	common-defs.h \
-	util.h fwddecl.h i18n.c i18n.h \
+	util.h utilproto.h fwddecl.h i18n.c i18n.h \
 	types.h host2net.h dynload.h w32help.h \
 	mapstrings.c stringhelp.c stringhelp.h \
 	strlist.c strlist.h \
diff --git a/common/fwddecl.h b/common/fwddecl.h
index 92f0453..f9d7536 100644
--- a/common/fwddecl.h
+++ b/common/fwddecl.h
@@ -1,4 +1,4 @@
-/* fwddecl.h - Formward declarations
+/* fwddecl.h - Forward declarations
  * Copyright (C) 2015 Werner Koch
  *
  * This file is part of GnuPG.
diff --git a/common/util.h b/common/util.h
index eb7a3fd..29e0ec9 100644
--- a/common/util.h
+++ b/common/util.h
@@ -54,6 +54,7 @@
 #include "../common/utf8conv.h"
 #include "../common/dynload.h"
 #include "../common/fwddecl.h"
+#include "../common/utilproto.h"
 
 #include "gettime.h"
 
@@ -114,11 +115,6 @@ out_of_core (void)
 }
 
 
-/*-- signal.c --*/
-void gnupg_init_signals (int mode, void (*fast_cleanup)(void));
-void gnupg_block_all_signals (void);
-void gnupg_unblock_all_signals (void);
-
 /*-- yesno.c --*/
 int answer_is_yes (const char *s);
 int answer_is_yes_no_default (const char *s, int def_answer);
diff --git a/common/fwddecl.h b/common/utilproto.h
similarity index 64%
copy from common/fwddecl.h
copy to common/utilproto.h
index 92f0453..5bb9dd1 100644
--- a/common/fwddecl.h
+++ b/common/utilproto.h
@@ -1,5 +1,5 @@
-/* fwddecl.h - Formward declarations
- * Copyright (C) 2015 Werner Koch
+/* utilproto.h - Some prototypes for inclusion by util.h
+ * Copyright (C) 2016 Werner Koch
  *
  * This file is part of GnuPG.
  *
@@ -27,13 +27,18 @@
  * along with this program; if not, see <http://www.gnu.org/licenses/>.
  */
 
-#ifndef GNUPG_COMMON_FWDDECL_H
-#define GNUPG_COMMON_FWDDECL_H
+/* This file is in general included via util.h but sometimes we do not
+ * want all stuff from util.h and instead use this file with its
+ * simple prototypes.  */
 
+#ifndef GNUPG_COMMON_UTILPROTO_H
+#define GNUPG_COMMON_UTILPROTO_H
 
-/*-- Forward declaration of the commonly used server control structure.  */
-struct server_control_s;
-typedef struct server_control_s *ctrl_t;
+/*-- signal.c --*/
+void gnupg_init_signals (int mode, void (*fast_cleanup)(void));
+void gnupg_block_all_signals (void);
+void gnupg_unblock_all_signals (void);
 
 
-#endif /*GNUPG_COMMON_FWDDECL_H*/
+
+#endif /*GNUPG_COMMON_UTILPROTO_H*/

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

Summary of changes:
 common/Makefile.am               |  2 +-
 common/fwddecl.h                 |  2 +-
 common/util.h                    |  6 +--
 common/{recsel.h => utilproto.h} | 25 +++++------
 g10/keyring.c                    | 13 +++++-
 kbx/keybox-update.c              | 37 ++++++++++------
 kbx/keybox-util.c                | 92 +++++++++++++++++++++++-----------------
 kbx/keybox.h                     |  3 +-
 8 files changed, 106 insertions(+), 74 deletions(-)
 copy common/{recsel.h => utilproto.h} (65%)


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




More information about the Gnupg-commits mailing list