[git] GnuPG - branch, STABLE-BRANCH-2-0, updated. gnupg-2.0.29-21-geb7806d

by NIIBE Yutaka cvs at cvs.gnupg.org
Fri Feb 12 02:38:02 CET 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, STABLE-BRANCH-2-0 has been updated
       via  eb7806d63df63663170ba86f0673caa34b944c28 (commit)
      from  776bee6d370602ff95e93a4aea6a70005dff9ae6 (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 eb7806d63df63663170ba86f0673caa34b944c28
Author: NIIBE Yutaka <gniibe at fsij.org>
Date:   Fri Feb 12 10:15:52 2016 +0900

    g10: Make sure to have the directory for trustdb.
    
    * g10/tdbio.c (tdbio_set_dbname): Return earlier if !CREATE.  Check
    the directory and create it if none before calling take_write_lock.
    
    --
    
    Thanks to Marc Deslauriers for the bug report and his patch.
    
    GnuPG-bug-id: 2246
    
    Signed-off-by: NIIBE Yutaka <gniibe at fsij.org>
    
    (backport from master
     commit 2f3e42047d17313eeb38d354048f343158402a8d)

diff --git a/g10/tdbio.c b/g10/tdbio.c
index 84a0ba6..5c2fdd1 100644
--- a/g10/tdbio.c
+++ b/g10/tdbio.c
@@ -479,9 +479,10 @@ create_version_record (void)
 int
 tdbio_set_dbname( const char *new_dbname, int create, int *r_nofile)
 {
-    char *fname;
+    char *fname, *p;
     struct stat statbuf;
     static int initialized = 0;
+    int save_slash;
 
     if( !initialized ) {
 	atexit( cleanup );
@@ -514,68 +515,75 @@ tdbio_set_dbname( const char *new_dbname, int create, int *r_nofile)
     if (stat (fname, &statbuf) == 0 && statbuf.st_size > 0)
       /* OK, we have the valid trustdb.gpg already.  */
       return 0;
+    else if (!create)
+      {
+        *r_nofile = 1;
+        return 0;
+      }
+
+  /* Here comes: No valid trustdb.gpg AND CREATE==1 */
+
+    /*
+     * Make sure the directory exists.  This should be done before
+     * acquiring the lock, which assumes the existence of the directory.
+     */
+    p = strrchr( fname, DIRSEP_C );
+#if HAVE_W32_SYSTEM
+    {
+      /* Windows may either have a slash or a backslash.  Take
+         care of it.  */
+      char *pp = strrchr (fname, '/');
+      if (!p || pp > p)
+        p = pp;
+    }
+#endif /*HAVE_W32_SYSTEM*/
+    assert (p);
+    save_slash = *p;
+    *p = 0;
+    if ( access( fname, F_OK ) ) {
+        try_make_homedir( fname );
+        if (access (fname, F_OK ))
+          log_fatal (_("%s: directory does not exist!\n"), fname);
+    }
+    *p = save_slash;
 
     take_write_lock ();
 
     if( access( fname, R_OK ) ) {
+        FILE *fp;
+        TRUSTREC rec;
+        int rc;
+        mode_t oldmask;
+
         if( errno != ENOENT )
             log_fatal( _("can't access `%s': %s\n"), fname, strerror(errno) );
 
-	if (!create)
-          *r_nofile = 1;
-        else {
-	    FILE *fp;
-	    TRUSTREC rec;
-	    int rc;
-	    char *p = strrchr( fname, DIRSEP_C );
-	    mode_t oldmask;
-            int save_slash;
 
-#if HAVE_W32_SYSTEM
-            {
-              /* Windows may either have a slash or a backslash.  Take
-                 care of it.  */
-              char *pp = strrchr (fname, '/');
-              if (!p || pp > p)
-                p = pp;
-            }
-#endif /*HAVE_W32_SYSTEM*/
-	    assert (p);
-            save_slash = *p;
-	    *p = 0;
-	    if( access( fname, F_OK ) ) {
-		try_make_homedir( fname );
-                if (access (fname, F_OK ))
-                  log_fatal (_("%s: directory does not exist!\n"), fname);
-	    }
-	    *p = save_slash;
-
-	    oldmask=umask(077);
-            if (is_secured_filename (fname)) {
-                fp = NULL;
-                errno = EPERM;
-            }
-            else
-                fp =fopen( fname, "wb" );
-	    umask(oldmask);
-	    if( !fp )
-		log_fatal( _("can't create `%s': %s\n"), fname, strerror(errno) );
-	    fclose(fp);
-	    db_fd = open( db_name, O_RDWR | MY_O_BINARY );
-	    if( db_fd == -1 )
-		log_fatal( _("can't open `%s': %s\n"), db_name, strerror(errno) );
-
-            rc = create_version_record ();
-	    if( rc )
-		log_fatal( _("%s: failed to create version record: %s"),
-						   fname, g10_errstr(rc));
-	    /* and read again to check that we are okay */
-	    if( tdbio_read_record( 0, &rec, RECTYPE_VER ) )
-		log_fatal( _("%s: invalid trustdb created\n"), db_name );
-
-	    if( !opt.quiet )
-		log_info(_("%s: trustdb created\n"), db_name);
-	}
+        oldmask=umask(077);
+        if (is_secured_filename (fname)) {
+            fp = NULL;
+            errno = EPERM;
+        }
+        else
+            fp =fopen( fname, "wb" );
+        umask(oldmask);
+        if( !fp )
+            log_fatal( _("can't create `%s': %s\n"), fname, strerror(errno) );
+        fclose(fp);
+        db_fd = open( db_name, O_RDWR | MY_O_BINARY );
+        if( db_fd == -1 )
+            log_fatal( _("can't open `%s': %s\n"), db_name, strerror(errno) );
+
+        rc = create_version_record ();
+        if( rc )
+            log_fatal( _("%s: failed to create version record: %s"),
+                     fname, g10_errstr(rc));
+        /* and read again to check that we are okay */
+        if( tdbio_read_record( 0, &rec, RECTYPE_VER ) )
+            log_fatal( _("%s: invalid trustdb created\n"), db_name );
+
+        if( !opt.quiet )
+            log_info(_("%s: trustdb created\n"), db_name);
     }
 
     release_write_lock ();

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

Summary of changes:
 g10/tdbio.c | 118 ++++++++++++++++++++++++++++++++----------------------------
 1 file changed, 63 insertions(+), 55 deletions(-)


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




More information about the Gnupg-commits mailing list