[git] GnuPG - branch, master, updated. gnupg-2.1.18-11-g73d6572

by Justus Winter cvs at cvs.gnupg.org
Tue Jan 24 15:47:37 CET 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  73d6572bd0f260c5aa1e191a1ba4859ec6fa262c (commit)
       via  77b8aff4e1bb641f497e63230a5006ab70e6c3a8 (commit)
       via  bfd75e9492fc4edd86f4049a62304943a7b2a29a (commit)
       via  82e309ad06884e54693f4856412984331febdda0 (commit)
       via  b0348fdb26637b0bcbd68a96c1746a1613b309af (commit)
       via  5b28f025085b386e0ec49535d4cd3f875a414eb0 (commit)
      from  5aafa56dffefe3fac55b9d0555c7c86e8a07f072 (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 73d6572bd0f260c5aa1e191a1ba4859ec6fa262c
Author: Justus Winter <justus at g10code.com>
Date:   Tue Jan 24 15:36:59 2017 +0100

    tools: Use platform abstraction for I/O.
    
    * tools/gpg-connect-agent.c (main): Use a gpgrt_stream_t for
    'script_fp'.  Adapt accordingly.
    --
    Werner asked me to make gpgconf use the platform abstractions that
    were introduced after gpgconf's inception.  After doing that, I
    realized that 'read_line' is only used in two more places, one of
    which this patch takes care of.
    
    Signed-off-by: Justus Winter <justus at g10code.com>

diff --git a/tools/gpg-connect-agent.c b/tools/gpg-connect-agent.c
index a5413cf..2d054f4 100644
--- a/tools/gpg-connect-agent.c
+++ b/tools/gpg-connect-agent.c
@@ -1155,7 +1155,7 @@ main (int argc, char **argv)
   int rc;
   int cmderr;
   const char *opt_run = NULL;
-  FILE *script_fp = NULL;
+  gpgrt_stream_t script_fp = NULL;
   int use_tty, keep_line;
   struct {
     int collecting;
@@ -1271,7 +1271,7 @@ main (int argc, char **argv)
                 "--tcp-socket", "--raw-socket");
     }
 
-  if (opt_run && !(script_fp = fopen (opt_run, "r")))
+  if (opt_run && !(script_fp = gpgrt_fopen (opt_run, "r")))
     {
       log_error ("cannot open run file '%s': %s\n",
                  opt_run, strerror (errno));
@@ -1425,15 +1425,15 @@ main (int argc, char **argv)
               linesize = 0;
               keep_line = 1;
             }
-          n = read_line (script_fp? script_fp:stdin,
-                         &line, &linesize, &maxlength);
+          n = gpgrt_read_line (script_fp ? script_fp : gpgrt_stdin,
+                               &line, &linesize, &maxlength);
         }
       if (n < 0)
         {
           log_error (_("error reading input: %s\n"), strerror (errno));
           if (script_fp)
             {
-              fclose (script_fp);
+              gpgrt_fclose (script_fp);
               script_fp = NULL;
               log_error ("stopping script execution\n");
               continue;
@@ -1445,7 +1445,7 @@ main (int argc, char **argv)
           /* EOF */
           if (script_fp)
             {
-              fclose (script_fp);
+              gpgrt_fclose (script_fp);
               script_fp = NULL;
               if (opt.verbose)
                 log_info ("end of script\n");
@@ -1683,17 +1683,17 @@ main (int argc, char **argv)
                   log_error ("syntax error in run command\n");
                   if (script_fp)
                     {
-                      fclose (script_fp);
+                      gpgrt_fclose (script_fp);
                       script_fp = NULL;
                     }
                 }
               else if (script_fp)
                 {
                   log_error ("cannot nest run commands - stop\n");
-                  fclose (script_fp);
+                  gpgrt_fclose (script_fp);
                   script_fp = NULL;
                 }
-              else if (!(script_fp = fopen (p, "r")))
+              else if (!(script_fp = gpgrt_fopen (p, "r")))
                 {
                   log_error ("cannot open run file '%s': %s\n",
                              p, strerror (errno));
@@ -1864,7 +1864,7 @@ main (int argc, char **argv)
       if ((rc || cmderr) && script_fp)
         {
           log_error ("stopping script execution\n");
-          fclose (script_fp);
+          gpgrt_fclose (script_fp);
           script_fp = NULL;
         }
 

commit 77b8aff4e1bb641f497e63230a5006ab70e6c3a8
Author: Justus Winter <justus at g10code.com>
Date:   Tue Jan 24 15:06:43 2017 +0100

    tools: Use platform abstraction for I/O.
    
    * tools/gpgconf-comp.c (retrieve_options_from_file): Use a
    gpgrt_stream_t for 'list_file'.  Adapt accordingly.
    (copy_file): Likewise for 'src' and 'dst'.
    (change_options_file): Likewise for 'src_file' and 'dest_file'.
    (change_options_program): Likewise for 'src_file' and 'dest_file'.
    (gc_process_gpgconf_conf): Likewise for 'config'.
    --
    Werner asked me to make gpgconf use the platform abstractions that
    were introduced after gpgconf's inception.
    
    Signed-off-by: Justus Winter <justus at g10code.com>

diff --git a/tools/gpgconf-comp.c b/tools/gpgconf-comp.c
index 4b0366d..20e8411 100644
--- a/tools/gpgconf-comp.c
+++ b/tools/gpgconf-comp.c
@@ -2266,7 +2266,7 @@ retrieve_options_from_file (gc_component_t component, gc_backend_t backend)
   gc_option_t *list_option;
   gc_option_t *config_option;
   char *list_filename;
-  FILE *list_file;
+  gpgrt_stream_t list_file;
   char *line = NULL;
   size_t line_len = 0;
   ssize_t length;
@@ -2278,13 +2278,13 @@ retrieve_options_from_file (gc_component_t component, gc_backend_t backend)
   assert (!list_option->active);
 
   list_filename = get_config_filename (component, backend);
-  list_file = fopen (list_filename, "r");
+  list_file = gpgrt_fopen (list_filename, "r");
   if (!list_file)
     gc_error (0, errno, "warning: can not open list file %s", list_filename);
   else
     {
 
-      while ((length = read_line (list_file, &line, &line_len, NULL)) > 0)
+      while ((length = gpgrt_read_line (list_file, &line, &line_len, NULL)) > 0)
 	{
 	  char *start;
 	  char *end;
@@ -2317,7 +2317,7 @@ retrieve_options_from_file (gc_component_t component, gc_backend_t backend)
 	  else
 	    list = xasprintf ("\"%s", gc_percent_escape (start));
 	}
-      if (length < 0 || ferror (list_file))
+      if (length < 0 || gpgrt_ferror (list_file))
 	gc_error (1, errno, "can not read list file %s", list_filename);
     }
 
@@ -2330,7 +2330,7 @@ retrieve_options_from_file (gc_component_t component, gc_backend_t backend)
   if (config_option->flags & GC_OPT_FLAG_NO_CHANGE)
     list_option->flags |= GC_OPT_FLAG_NO_CHANGE;
 
-  if (list_file && fclose (list_file))
+  if (list_file && gpgrt_fclose (list_file))
     gc_error (1, errno, "error closing %s", list_filename);
   xfree (line);
 }
@@ -2516,7 +2516,6 @@ option_check_validity (gc_option_t *option, unsigned long flags,
   while (arg && *arg);
 }
 
-
 #ifdef HAVE_W32_SYSTEM
 int
 copy_file (const char *src_name, const char *dst_name)
@@ -2524,18 +2523,18 @@ copy_file (const char *src_name, const char *dst_name)
 #define BUF_LEN 4096
   char buffer[BUF_LEN];
   int len;
-  FILE *src;
-  FILE *dst;
+  gpgrt_stream_t src;
+  gpgrt_stream_t dst;
 
-  src = fopen (src_name, "r");
+  src = gpgrt_fopen (src_name, "r");
   if (src == NULL)
     return -1;
 
-  dst = fopen (dst_name, "w");
+  dst = gpgrt_fopen (dst_name, "w");
   if (dst == NULL)
     {
       int saved_err = errno;
-      fclose (src);
+      gpgrt_fclose (src);
       gpg_err_set_errno (saved_err);
       return -1;
     }
@@ -2544,28 +2543,28 @@ copy_file (const char *src_name, const char *dst_name)
     {
       int written;
 
-      len = fread (buffer, 1, BUF_LEN, src);
+      len = gpgrt_fread (buffer, 1, BUF_LEN, src);
       if (len == 0)
 	break;
-      written = fwrite (buffer, 1, len, dst);
+      written = gpgrt_fwrite (buffer, 1, len, dst);
       if (written != len)
 	break;
     }
-  while (!feof (src) && !ferror (src) && !ferror (dst));
+  while (! gpgrt_feof (src) && ! gpgrt_ferror (src) && ! gpgrt_ferror (dst));
 
-  if (ferror (src) || ferror (dst) || !feof (src))
+  if (gpgrt_ferror (src) || gpgrt_ferror (dst) || ! gpgrt_feof (src))
     {
       int saved_errno = errno;
-      fclose (src);
-      fclose (dst);
+      gpgrt_fclose (src);
+      gpgrt_fclose (dst);
       unlink (dst_name);
       gpg_err_set_errno (saved_errno);
       return -1;
     }
 
-  if (fclose (dst))
+  if (gpgrt_fclose (dst))
     gc_error (1, errno, "error closing %s", dst_name);
-  if (fclose (src))
+  if (gpgrt_fclose (src))
     gc_error (1, errno, "error closing %s", src_name);
 
   return 0;
@@ -2602,8 +2601,8 @@ change_options_file (gc_component_t component, gc_backend_t backend,
   ssize_t length;
   int res;
   int fd;
-  FILE *src_file = NULL;
-  FILE *dest_file = NULL;
+  gpgrt_stream_t src_file = NULL;
+  gpgrt_stream_t dest_file = NULL;
   char *src_filename;
   char *dest_filename;
   char *orig_filename;
@@ -2675,7 +2674,7 @@ change_options_file (gc_component_t component, gc_backend_t backend,
   fd = open (src_filename, O_CREAT | O_EXCL | O_WRONLY, 0644);
   if (fd < 0)
     return -1;
-  src_file = fdopen (fd, "w");
+  src_file = gpgrt_fdopen (fd, "w");
   res = errno;
   if (!src_file)
     {
@@ -2689,11 +2688,11 @@ change_options_file (gc_component_t component, gc_backend_t backend,
      process.  */
   if (orig_filename)
     {
-      dest_file = fopen (dest_filename, "r");
+      dest_file = gpgrt_fopen (dest_filename, "r");
       if (!dest_file)
 	goto change_file_one_err;
 
-      while ((length = read_line (dest_file, &line, &line_len, NULL)) > 0)
+      while ((length = gpgrt_read_line (dest_file, &line, &line_len, NULL)) > 0)
 	{
 	  int disable = 0;
 	  char *start;
@@ -2764,24 +2763,24 @@ change_options_file (gc_component_t component, gc_backend_t backend,
 	    {
 	      if (!in_marker)
 		{
-		  fprintf (src_file,
+		  gpgrt_fprintf (src_file,
 			   "# %s disabled this option here at %s\n",
 			   GPGCONF_DISP_NAME, asctimestamp (gnupg_get_time ()));
-		  if (ferror (src_file))
+		  if (gpgrt_ferror (src_file))
 		    goto change_file_one_err;
-		  fprintf (src_file, "# %s", line);
-		  if (ferror (src_file))
+		  gpgrt_fprintf (src_file, "# %s", line);
+		  if (gpgrt_ferror (src_file))
 		    goto change_file_one_err;
 		}
 	    }
 	  else
 	    {
-	      fprintf (src_file, "%s", line);
-	      if (ferror (src_file))
+	      gpgrt_fprintf (src_file, "%s", line);
+	      if (gpgrt_ferror (src_file))
 		goto change_file_one_err;
 	    }
 	}
-      if (length < 0 || ferror (dest_file))
+      if (length < 0 || gpgrt_ferror (dest_file))
 	goto change_file_one_err;
     }
 
@@ -2792,8 +2791,8 @@ change_options_file (gc_component_t component, gc_backend_t backend,
 	 proceed.  Note that we first write a newline, this guards us
 	 against files which lack the newline at the end of the last
 	 line, while it doesn't hurt us in all other cases.  */
-      fprintf (src_file, "\n%s\n", marker);
-      if (ferror (src_file))
+      gpgrt_fprintf (src_file, "\n%s\n", marker);
+      if (gpgrt_ferror (src_file))
 	goto change_file_one_err;
     }
 
@@ -2803,7 +2802,7 @@ change_options_file (gc_component_t component, gc_backend_t backend,
      followed by the rest of the original file.  */
   while (cur_arg)
     {
-      fprintf (src_file, "%s\n", cur_arg);
+      gpgrt_fprintf (src_file, "%s\n", cur_arg);
 
       /* Find next argument.  */
       if (arg)
@@ -2828,52 +2827,52 @@ change_options_file (gc_component_t component, gc_backend_t backend,
 	cur_arg = NULL;
     }
 
-  fprintf (src_file, "%s %s\n", marker, asctimestamp (gnupg_get_time ()));
-  if (ferror (src_file))
+  gpgrt_fprintf (src_file, "%s %s\n", marker, asctimestamp (gnupg_get_time ()));
+  if (gpgrt_ferror (src_file))
     goto change_file_one_err;
 
   if (!in_marker)
     {
-      fprintf (src_file, "# %s edited this configuration file.\n",
+      gpgrt_fprintf (src_file, "# %s edited this configuration file.\n",
                GPGCONF_DISP_NAME);
-      if (ferror (src_file))
+      if (gpgrt_ferror (src_file))
 	goto change_file_one_err;
-      fprintf (src_file, "# It will disable options before this marked "
+      gpgrt_fprintf (src_file, "# It will disable options before this marked "
 	       "block, but it will\n");
-      if (ferror (src_file))
+      if (gpgrt_ferror (src_file))
 	goto change_file_one_err;
-      fprintf (src_file, "# never change anything below these lines.\n");
-      if (ferror (src_file))
+      gpgrt_fprintf (src_file, "# never change anything below these lines.\n");
+      if (gpgrt_ferror (src_file))
 	goto change_file_one_err;
     }
   if (dest_file)
     {
-      while ((length = read_line (dest_file, &line, &line_len, NULL)) > 0)
+      while ((length = gpgrt_read_line (dest_file, &line, &line_len, NULL)) > 0)
 	{
-	  fprintf (src_file, "%s", line);
-	  if (ferror (src_file))
+	  gpgrt_fprintf (src_file, "%s", line);
+	  if (gpgrt_ferror (src_file))
 	    goto change_file_one_err;
 	}
-      if (length < 0 || ferror (dest_file))
+      if (length < 0 || gpgrt_ferror (dest_file))
 	goto change_file_one_err;
     }
   xfree (line);
   line = NULL;
 
-  res = fclose (src_file);
+  res = gpgrt_fclose (src_file);
   if (res)
     {
       res = errno;
       close (fd);
       if (dest_file)
-	fclose (dest_file);
+	gpgrt_fclose (dest_file);
       gpg_err_set_errno (res);
       return -1;
     }
   close (fd);
   if (dest_file)
     {
-      res = fclose (dest_file);
+      res = gpgrt_fclose (dest_file);
       if (res)
 	return -1;
     }
@@ -2884,11 +2883,11 @@ change_options_file (gc_component_t component, gc_backend_t backend,
   res = errno;
   if (src_file)
     {
-      fclose (src_file);
+      gpgrt_fclose (src_file);
       close (fd);
     }
   if (dest_file)
-    fclose (dest_file);
+    gpgrt_fclose (dest_file);
   gpg_err_set_errno (res);
   return -1;
 }
@@ -2924,8 +2923,8 @@ change_options_program (gc_component_t component, gc_backend_t backend,
   ssize_t length;
   int res;
   int fd;
-  FILE *src_file = NULL;
-  FILE *dest_file = NULL;
+  gpgrt_stream_t src_file = NULL;
+  gpgrt_stream_t dest_file = NULL;
   char *src_filename;
   char *dest_filename;
   char *orig_filename;
@@ -2967,7 +2966,7 @@ change_options_program (gc_component_t component, gc_backend_t backend,
   fd = open (src_filename, O_CREAT | O_EXCL | O_WRONLY, 0644);
   if (fd < 0)
     return -1;
-  src_file = fdopen (fd, "w");
+  src_file = gpgrt_fdopen (fd, "w");
   res = errno;
   if (!src_file)
     {
@@ -2981,11 +2980,11 @@ change_options_program (gc_component_t component, gc_backend_t backend,
      process.  */
   if (orig_filename)
     {
-      dest_file = fopen (dest_filename, "r");
+      dest_file = gpgrt_fopen (dest_filename, "r");
       if (!dest_file)
 	goto change_one_err;
 
-      while ((length = read_line (dest_file, &line, &line_len, NULL)) > 0)
+      while ((length = gpgrt_read_line (dest_file, &line, &line_len, NULL)) > 0)
 	{
 	  int disable = 0;
 	  char *start;
@@ -3032,24 +3031,24 @@ change_options_program (gc_component_t component, gc_backend_t backend,
 	    {
 	      if (!in_marker)
 		{
-		  fprintf (src_file,
+		  gpgrt_fprintf (src_file,
 			   "# %s disabled this option here at %s\n",
 			   GPGCONF_DISP_NAME, asctimestamp (gnupg_get_time ()));
-		  if (ferror (src_file))
+		  if (gpgrt_ferror (src_file))
 		    goto change_one_err;
-		  fprintf (src_file, "# %s", line);
-		  if (ferror (src_file))
+		  gpgrt_fprintf (src_file, "# %s", line);
+		  if (gpgrt_ferror (src_file))
 		    goto change_one_err;
 		}
 	    }
 	  else
 	    {
-	      fprintf (src_file, "%s", line);
-	      if (ferror (src_file))
+	      gpgrt_fprintf (src_file, "%s", line);
+	      if (gpgrt_ferror (src_file))
 		goto change_one_err;
 	    }
 	}
-      if (length < 0 || ferror (dest_file))
+      if (length < 0 || gpgrt_ferror (dest_file))
 	goto change_one_err;
     }
 
@@ -3060,8 +3059,8 @@ change_options_program (gc_component_t component, gc_backend_t backend,
 	 proceed.  Note that we first write a newline, this guards us
 	 against files which lack the newline at the end of the last
 	 line, while it doesn't hurt us in all other cases.  */
-      fprintf (src_file, "\n%s\n", marker);
-      if (ferror (src_file))
+      gpgrt_fprintf (src_file, "\n%s\n", marker);
+      if (gpgrt_ferror (src_file))
 	goto change_one_err;
     }
   /* At this point, we have copied everything up to the end marker
@@ -3072,7 +3071,7 @@ change_options_program (gc_component_t component, gc_backend_t backend,
 
   /* We have to turn on UTF8 strings for GnuPG.  */
   if (backend == GC_BACKEND_GPG && ! utf8strings_seen)
-    fprintf (src_file, "utf8-strings\n");
+    gpgrt_fprintf (src_file, "utf8-strings\n");
 
   option = gc_component[component].options;
   while (option->name)
@@ -3087,16 +3086,16 @@ change_options_program (gc_component_t component, gc_backend_t backend,
 	    {
 	      if (*arg == '\0' || *arg == ',')
 		{
-		  fprintf (src_file, "%s\n", option->name);
-		  if (ferror (src_file))
+		  gpgrt_fprintf (src_file, "%s\n", option->name);
+		  if (gpgrt_ferror (src_file))
 		    goto change_one_err;
 		}
 	      else if (gc_arg_type[option->arg_type].fallback
 		       == GC_ARG_TYPE_NONE)
 		{
 		  assert (*arg == '1');
-		  fprintf (src_file, "%s\n", option->name);
-		  if (ferror (src_file))
+		  gpgrt_fprintf (src_file, "%s\n", option->name);
+		  if (gpgrt_ferror (src_file))
 		    goto change_one_err;
 
 		  arg++;
@@ -3118,9 +3117,9 @@ change_options_program (gc_component_t component, gc_backend_t backend,
                   else
                     end = NULL;
 
-		  fprintf (src_file, "%s %s\n", option->name,
+		  gpgrt_fprintf (src_file, "%s %s\n", option->name,
 			   verbatim? arg : percent_deescape (arg));
-		  if (ferror (src_file))
+		  if (gpgrt_ferror (src_file))
 		    goto change_one_err;
 
 		  if (end)
@@ -3135,8 +3134,8 @@ change_options_program (gc_component_t component, gc_backend_t backend,
 		  if (end)
 		    *end = '\0';
 
-		  fprintf (src_file, "%s %s\n", option->name, arg);
-		  if (ferror (src_file))
+		  gpgrt_fprintf (src_file, "%s %s\n", option->name, arg);
+		  if (gpgrt_ferror (src_file))
 		    goto change_one_err;
 
 		  if (end)
@@ -3153,52 +3152,52 @@ change_options_program (gc_component_t component, gc_backend_t backend,
       option++;
     }
 
-  fprintf (src_file, "%s %s\n", marker, asctimestamp (gnupg_get_time ()));
-  if (ferror (src_file))
+  gpgrt_fprintf (src_file, "%s %s\n", marker, asctimestamp (gnupg_get_time ()));
+  if (gpgrt_ferror (src_file))
     goto change_one_err;
 
   if (!in_marker)
     {
-      fprintf (src_file, "# %s edited this configuration file.\n",
+      gpgrt_fprintf (src_file, "# %s edited this configuration file.\n",
                GPGCONF_DISP_NAME);
-      if (ferror (src_file))
+      if (gpgrt_ferror (src_file))
 	goto change_one_err;
-      fprintf (src_file, "# It will disable options before this marked "
+      gpgrt_fprintf (src_file, "# It will disable options before this marked "
 	       "block, but it will\n");
-      if (ferror (src_file))
+      if (gpgrt_ferror (src_file))
 	goto change_one_err;
-      fprintf (src_file, "# never change anything below these lines.\n");
-      if (ferror (src_file))
+      gpgrt_fprintf (src_file, "# never change anything below these lines.\n");
+      if (gpgrt_ferror (src_file))
 	goto change_one_err;
     }
   if (dest_file)
     {
-      while ((length = read_line (dest_file, &line, &line_len, NULL)) > 0)
+      while ((length = gpgrt_read_line (dest_file, &line, &line_len, NULL)) > 0)
 	{
-	  fprintf (src_file, "%s", line);
-	  if (ferror (src_file))
+	  gpgrt_fprintf (src_file, "%s", line);
+	  if (gpgrt_ferror (src_file))
 	    goto change_one_err;
 	}
-      if (length < 0 || ferror (dest_file))
+      if (length < 0 || gpgrt_ferror (dest_file))
 	goto change_one_err;
     }
   xfree (line);
   line = NULL;
 
-  res = fclose (src_file);
+  res = gpgrt_fclose (src_file);
   if (res)
     {
       res = errno;
       close (fd);
       if (dest_file)
-	fclose (dest_file);
+	gpgrt_fclose (dest_file);
       gpg_err_set_errno (res);
       return -1;
     }
   close (fd);
   if (dest_file)
     {
-      res = fclose (dest_file);
+      res = gpgrt_fclose (dest_file);
       if (res)
 	return -1;
     }
@@ -3209,11 +3208,11 @@ change_options_program (gc_component_t component, gc_backend_t backend,
   res = errno;
   if (src_file)
     {
-      fclose (src_file);
+      gpgrt_fclose (src_file);
       close (fd);
     }
   if (dest_file)
-    fclose (dest_file);
+    gpgrt_fclose (dest_file);
   gpg_err_set_errno (res);
   return -1;
 }
@@ -3646,7 +3645,7 @@ gc_process_gpgconf_conf (const char *fname_arg, int update, int defaults,
   char *line = NULL;
   size_t line_len = 0;
   ssize_t length;
-  FILE *config;
+  gpgrt_stream_t config;
   int lineno = 0;
   int in_rule = 0;
   int got_match = 0;
@@ -3663,7 +3662,7 @@ gc_process_gpgconf_conf (const char *fname_arg, int update, int defaults,
   for (backend_id = 0; backend_id < GC_BACKEND_NR; backend_id++)
     runtime[backend_id] = 0;
 
-  config = fopen (fname, "r");
+  config = gpgrt_fopen (fname, "r");
   if (!config)
     {
       /* Do not print an error if the file is not available, except
@@ -3677,7 +3676,7 @@ gc_process_gpgconf_conf (const char *fname_arg, int update, int defaults,
       return result;
     }
 
-  while ((length = read_line (config, &line, &line_len, NULL)) > 0)
+  while ((length = gpgrt_read_line (config, &line, &line_len, NULL)) > 0)
     {
       char *key, *component, *option, *flags, *value;
       char *empty;
@@ -3903,12 +3902,12 @@ gc_process_gpgconf_conf (const char *fname_arg, int update, int defaults,
         }
     }
 
-  if (length < 0 || ferror (config))
+  if (length < 0 || gpgrt_ferror (config))
     {
       gc_error (0, errno, "error reading from '%s'", fname);
       result = -1;
     }
-  if (fclose (config))
+  if (gpgrt_fclose (config))
     gc_error (0, errno, "error closing '%s'", fname);
 
   xfree (line);

commit bfd75e9492fc4edd86f4049a62304943a7b2a29a
Author: Justus Winter <justus at g10code.com>
Date:   Mon Jan 23 14:26:00 2017 +0100

    tools: Use platform abstraction for renaming files.
    
    * tools/gpgconf-comp.c (gc_component_change_options): Use
    'gnupg_rename_file'.  Also, block signals across all renames in an
    attempt to make the whole process atomic.
    --
    Werner asked me to make gpgconf use the platform abstractions that
    were introduced after gpgconf's inception.
    
    Signed-off-by: Justus Winter <justus at g10code.com>

diff --git a/tools/gpgconf-comp.c b/tools/gpgconf-comp.c
index 641738e..4b0366d 100644
--- a/tools/gpgconf-comp.c
+++ b/tools/gpgconf-comp.c
@@ -47,6 +47,7 @@
 #include "util.h"
 #include "i18n.h"
 #include "exechelp.h"
+#include "sysutils.h"
 
 #include "gc-opt-flags.h"
 #include "gpgconf.h"
@@ -3267,6 +3268,7 @@ gc_component_change_options (int component, estream_t in, estream_t out,
                              int verbatim)
 {
   int err = 0;
+  int block = 0;
   int runtime[GC_BACKEND_NR];
   char *src_filename[GC_BACKEND_NR];
   char *dest_filename[GC_BACKEND_NR];
@@ -3406,6 +3408,14 @@ gc_component_change_options (int component, estream_t in, estream_t out,
       option++;
     }
 
+  /* We are trying to atomically commit all changes.  Unfortunately,
+     we cannot rely on gnupg_rename_file to manage the signals for us,
+     doing so would require us to pass NULL as BLOCK to any subsequent
+     call to it.  Instead, we just manage the signal handling
+     manually.  */
+  block = 1;
+  gnupg_block_all_signals ();
+
   if (! err && ! opt.dry_run)
     {
       int i;
@@ -3419,20 +3429,13 @@ gc_component_change_options (int component, estream_t in, estream_t out,
 	      assert (dest_filename[i]);
 
 	      if (orig_filename[i])
-		{
-#ifdef HAVE_W32_SYSTEM
-		  /* There is no atomic update on W32.  */
-		  err = unlink (dest_filename[i]);
-#endif /* HAVE_W32_SYSTEM */
-		  if (!err)
-		    err = rename (src_filename[i], dest_filename[i]);
-		}
+		err = gnupg_rename_file (src_filename[i], dest_filename[i], NULL);
 	      else
 		{
 #ifdef HAVE_W32_SYSTEM
 		  /* We skip the unlink if we expect the file not to
 		     be there.  */
-                  err = rename (src_filename[i], dest_filename[i]);
+                  err = gnupg_rename_file (src_filename[i], dest_filename[i], NULL);
 #else /* HAVE_W32_SYSTEM */
 		  /* This is a bit safer than rename() because we
 		     expect DEST_FILENAME not to be there.  If it
@@ -3472,13 +3475,7 @@ gc_component_change_options (int component, estream_t in, estream_t out,
 		 a version of the file that is even newer than the one
 		 we just installed.  */
 	      if (orig_filename[i])
-		{
-#ifdef HAVE_W32_SYSTEM
-		  /* There is no atomic update on W32.  */
-		  unlink (dest_filename[i]);
-#endif /* HAVE_W32_SYSTEM */
-		  rename (orig_filename[i], dest_filename[i]);
-		}
+		gnupg_rename_file (orig_filename[i], dest_filename[i], NULL);
 	      else
 		unlink (dest_filename[i]);
 	    }
@@ -3508,16 +3505,13 @@ gc_component_change_options (int component, estream_t in, estream_t out,
 
 	backup_filename = xasprintf ("%s.%s.bak",
                                      dest_filename[backend], GPGCONF_NAME);
-
-#ifdef HAVE_W32_SYSTEM
-	/* There is no atomic update on W32.  */
-	unlink (backup_filename);
-#endif /* HAVE_W32_SYSTEM */
-	rename (orig_filename[backend], backup_filename);
+	gnupg_rename_file (orig_filename[backend], backup_filename, NULL);
 	xfree (backup_filename);
       }
 
  leave:
+  if (block)
+    gnupg_unblock_all_signals ();
   xfree (line);
   for (backend = 0; backend < GC_BACKEND_NR; backend++)
     {

commit 82e309ad06884e54693f4856412984331febdda0
Author: Justus Winter <justus at g10code.com>
Date:   Tue Jan 24 12:57:43 2017 +0100

    tools: Add comments explaining the functions parameters.
    
    * tools/gpgconf-comp.c (change_options_file): Add comments explaining
    the functions parameters.
    (change_options_program): Likewise.
    --
    From reading those two functions it is not clear why we write the new
    configuration to the source file, and read the current configuration
    from the destination file.  The identifiers are named for the benefit
    of the callee.
    
    Note that identifiers that require that much explanation are poorly
    chosen.
    
    Signed-off-by: Justus Winter <justus at g10code.com>

diff --git a/tools/gpgconf-comp.c b/tools/gpgconf-comp.c
index 180fd65..641738e 100644
--- a/tools/gpgconf-comp.c
+++ b/tools/gpgconf-comp.c
@@ -2573,7 +2573,20 @@ copy_file (const char *src_name, const char *dst_name)
 
 
 /* Create and verify the new configuration file for the specified
-   backend and component.  Returns 0 on success and -1 on error.  */
+ * backend and component.  Returns 0 on success and -1 on error.  This
+ * function may store pointers to malloced strings in SRC_FILENAMEP,
+ * DEST_FILENAMEP, and ORIG_FILENAMEP.  Those must be freed by the
+ * caller.  The strings refer to three versions of the configuration
+ * file:
+ *
+ * SRC_FILENAME:  The updated configuration is written to this file.
+ * DEST_FILENAME: Name of the configuration file read by the
+ *                component.
+ * ORIG_FILENAME: A backup of the previous configuration file.
+ *
+ * To apply the configuration change, rename SRC_FILENAME to
+ * DEST_FILENAME.  To revert to the previous configuration, rename
+ * ORIG_FILENAME to DEST_FILENAME.  */
 static int
 change_options_file (gc_component_t component, gc_backend_t backend,
 		     char **src_filenamep, char **dest_filenamep,
@@ -2882,7 +2895,19 @@ change_options_file (gc_component_t component, gc_backend_t backend,
 
 /* Create and verify the new configuration file for the specified
  * backend and component.  Returns 0 on success and -1 on error.  If
- * VERBATIM is set the profile mode is used. */
+ * VERBATIM is set the profile mode is used.  This function may store
+ * pointers to malloced strings in SRC_FILENAMEP, DEST_FILENAMEP, and
+ * ORIG_FILENAMEP.  Those must be freed by the caller.  The strings
+ * refer to three versions of the configuration file:
+ *
+ * SRC_FILENAME:  The updated configuration is written to this file.
+ * DEST_FILENAME: Name of the configuration file read by the
+ *                component.
+ * ORIG_FILENAME: A backup of the previous configuration file.
+ *
+ * To apply the configuration change, rename SRC_FILENAME to
+ * DEST_FILENAME.  To revert to the previous configuration, rename
+ * ORIG_FILENAME to DEST_FILENAME.  */
 static int
 change_options_program (gc_component_t component, gc_backend_t backend,
 			char **src_filenamep, char **dest_filenamep,

commit b0348fdb26637b0bcbd68a96c1746a1613b309af
Author: Justus Winter <justus at g10code.com>
Date:   Mon Jan 23 14:24:22 2017 +0100

    tools: Improve error handling.
    
    * tools/gpgconf-comp.c (gp_component_change_options): Improve error
    handling when reading from stdin.
    --
    Previously, errors encountered while reading the configuration changes
    were ignored.
    
    Signed-off-by: Justus Winter <justus at g10code.com>

diff --git a/tools/gpgconf-comp.c b/tools/gpgconf-comp.c
index 85eb80a..180fd65 100644
--- a/tools/gpgconf-comp.c
+++ b/tools/gpgconf-comp.c
@@ -3328,6 +3328,8 @@ gc_component_change_options (int component, estream_t in, estream_t out,
 
           change_one_value (option, runtime, flags, new_value, 0);
         }
+      if (length < 0 || gpgrt_ferror (in))
+	gc_error (1, errno, "error reading stream 'in'");
     }
 
   /* Now that we have collected and locally verified the changes,

commit 5b28f025085b386e0ec49535d4cd3f875a414eb0
Author: Justus Winter <justus at g10code.com>
Date:   Mon Jan 23 11:52:30 2017 +0100

    tools: Fix memory leak.
    
    * tools/gpgconf-comp.c (change_options_file): Fix leak.
    --
    Previously, 'src_filename' and 'orig_filename' leaked if creating the
    backup file failed.
    
    Signed-off-by: Justus Winter <justus at g10code.com>

diff --git a/tools/gpgconf-comp.c b/tools/gpgconf-comp.c
index a25b513..85eb80a 100644
--- a/tools/gpgconf-comp.c
+++ b/tools/gpgconf-comp.c
@@ -2641,6 +2641,8 @@ change_options_file (gc_component_t component, gc_backend_t backend,
   if (res < 0 && errno != ENOENT)
     {
       xfree (dest_filename);
+      xfree (src_filename);
+      xfree (orig_filename);
       return -1;
     }
   if (res < 0)

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

Summary of changes:
 tools/gpg-connect-agent.c |  20 ++--
 tools/gpgconf-comp.c      | 262 +++++++++++++++++++++++++---------------------
 2 files changed, 152 insertions(+), 130 deletions(-)


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




More information about the Gnupg-commits mailing list