[svn] GnuPG - r5033 - in trunk: agent common g10

svn author wk cvs at cvs.gnupg.org
Wed Jun 3 19:24:26 CEST 2009


Author: wk
Date: 2009-06-03 19:24:24 +0200 (Wed, 03 Jun 2009)
New Revision: 5033

Modified:
   trunk/agent/ChangeLog
   trunk/agent/protect-tool.c
   trunk/agent/trustlist.c
   trunk/common/ChangeLog
   trunk/common/estream.c
   trunk/g10/card-util.c
Log:
Fixed an fopen problem on Windows Vista.


Modified: trunk/agent/ChangeLog
===================================================================
--- trunk/agent/ChangeLog	2009-06-02 15:46:59 UTC (rev 5032)
+++ trunk/agent/ChangeLog	2009-06-03 17:24:24 UTC (rev 5033)
@@ -1,3 +1,13 @@
+2009-06-03  Werner Koch  <wk at g10code.com>
+
+	* protect-tool.c: Include estream.h.
+	(store_private_key): Replace stdio streams by estream functions
+	for a portable use of the "x" mode.
+	* trustlist.c: Include estream.h.
+	(agent_marktrusted): Repalce stdio stream by estream functions.
+
+	* protect-tool.c (store_private_key): Use bin2hex.	
+
 2009-06-02  Werner Koch  <wk at g10code.com>
 
 	* gpg-agent.c (main): Run pth_kill after fork.  Fixes bug#1066.

Modified: trunk/common/ChangeLog
===================================================================
--- trunk/common/ChangeLog	2009-06-02 15:46:59 UTC (rev 5032)
+++ trunk/common/ChangeLog	2009-06-03 17:24:24 UTC (rev 5033)
@@ -1,3 +1,7 @@
+2009-06-03  Werner Koch  <wk at g10code.com>
+
+	* estream.c (es_convert_mode): Rewrite and support the "x" flag.
+
 2009-05-28  David Shaw  <dshaw at jabberwocky.com>
 
 	From 1.4:

Modified: trunk/agent/protect-tool.c
===================================================================
--- trunk/agent/protect-tool.c	2009-06-02 15:46:59 UTC (rev 5032)
+++ trunk/agent/protect-tool.c	2009-06-03 17:24:24 UTC (rev 5033)
@@ -44,6 +44,7 @@
 #include "i18n.h"
 #include "get-passphrase.h"
 #include "sysutils.h"
+#include "estream.h"
 
 
 enum cmd_and_opt_values 
@@ -1199,18 +1200,15 @@
 store_private_key (const unsigned char *grip,
                    const void *buffer, size_t length, int force)
 {
-  int i;
   char *fname;
-  FILE *fp;
+  estream_t fp;
   char hexgrip[40+4+1];
   
-  for (i=0; i < 20; i++)
-    sprintf (hexgrip+2*i, "%02X", grip[i]);
-  strcpy (hexgrip+40, ".key");
+  bin2hex (grip, 20, hexgrip);
 
   fname = make_filename (opt_homedir, GNUPG_PRIVATE_KEYS_DIR, hexgrip, NULL);
   if (force)
-    fp = fopen (fname, "wb");
+    fp = es_fopen (fname, "wb");
   else
     {
       if (!access (fname, F_OK))
@@ -1224,9 +1222,9 @@
         xfree (fname);
         return opt_no_fail_on_exist? 0 : -1;
       }
-      fp = fopen (fname, "wbx");  /* FIXME: the x is a GNU extension - let
-                                     configure check whether this actually
-                                     works */
+      /* FWIW: Under Windows Vista the standard fopen in the msvcrt
+         fails if the "x" GNU extension is used.  */
+      fp = es_fopen (fname, "wbx"); 
     }
 
   if (!fp) 
@@ -1236,15 +1234,15 @@
       return -1;
     }
 
-  if (fwrite (buffer, length, 1, fp) != 1)
+  if (es_fwrite (buffer, length, 1, fp) != 1)
     {
       log_error ("error writing `%s': %s\n", fname, strerror (errno));
-      fclose (fp);
+      es_fclose (fp);
       remove (fname);
       xfree (fname);
       return -1;
     }
-  if ( fclose (fp) )
+  if (es_fclose (fp))
     {
       log_error ("error closing `%s': %s\n", fname, strerror (errno));
       remove (fname);

Modified: trunk/agent/trustlist.c
===================================================================
--- trunk/agent/trustlist.c	2009-06-02 15:46:59 UTC (rev 5032)
+++ trunk/agent/trustlist.c	2009-06-03 17:24:24 UTC (rev 5033)
@@ -31,6 +31,7 @@
 #include "agent.h"
 #include <assuan.h> /* fixme: need a way to avoid assuan calls here */
 #include "i18n.h"
+#include "estream.h"
 
 
 /* A structure to store the information from the trust file. */
@@ -552,7 +553,7 @@
   gpg_error_t err = 0;
   char *desc;
   char *fname;
-  FILE *fp;
+  estream_t fp;
   char *fprformatted;
   char *nameformatted;
   int is_disabled;
@@ -691,7 +692,7 @@
   fname = make_filename (opt.homedir, "trustlist.txt", NULL);
   if ( access (fname, F_OK) && errno == ENOENT)
     {
-      fp = fopen (fname, "wx"); /* Warning: "x" is a GNU extension. */
+      fp = es_fopen (fname, "wx");
       if (!fp)
         {
           err = gpg_error_from_syserror ();
@@ -702,10 +703,10 @@
           xfree (nameformatted);
           return err;
         }
-      fputs (headerblurb, fp);
-      fclose (fp);
+      es_fputs (headerblurb, fp);
+      es_fclose (fp);
     }
-  fp = fopen (fname, "a+");
+  fp = es_fopen (fname, "a+");
   if (!fp)
     {
       err = gpg_error_from_syserror ();
@@ -718,22 +719,22 @@
     }
 
   /* Append the key. */
-  fputs ("\n# ", fp);
+  es_fputs ("\n# ", fp);
   xfree (nameformatted);
   nameformatted = reformat_name (name, "\n# ");
   if (!nameformatted || strchr (name, '\n'))
     {
       /* Note that there should never be a LF in NAME but we better
          play safe and print a sanitized version in this case.  */
-      print_sanitized_string (fp, name, 0);
+      es_write_sanitized (fp, name, strlen (name), NULL, NULL);
     }
   else
-    fputs (nameformatted, fp);
-  fprintf (fp, "\n%s%s %c\n", yes_i_trust?"":"!", fprformatted, flag);
-  if (ferror (fp))
+    es_fputs (nameformatted, fp);
+  es_fprintf (fp, "\n%s%s %c\n", yes_i_trust?"":"!", fprformatted, flag);
+  if (es_ferror (fp))
     err = gpg_error_from_syserror ();
   
-  if (fclose (fp))
+  if (es_fclose (fp))
     err = gpg_error_from_syserror ();
 
   agent_reload_trustlist ();

Modified: trunk/common/estream.c
===================================================================
--- trunk/common/estream.c	2009-06-02 15:46:59 UTC (rev 5032)
+++ trunk/common/estream.c	2009-06-03 17:24:24 UTC (rev 5033)
@@ -897,67 +897,49 @@
   };
 
 
-
-/* Stream primitives.  */
-
 static int
 es_convert_mode (const char *mode, unsigned int *modeflags)
 {
+  unsigned int omode, oflags;
 
-  /* FIXME: We need to allow all mode flags permutations.  */
-  struct
-  {
-    const char *mode;
-    unsigned int flags;
-  } mode_flags[] = { { "r",
-		       O_RDONLY },
-		     { "rb",
-		       O_RDONLY | O_BINARY },
-		     { "w",
-		       O_WRONLY | O_TRUNC | O_CREAT },
-		     { "wb",
-		       O_WRONLY | O_TRUNC | O_CREAT | O_BINARY },
-		     { "a",
-		       O_WRONLY | O_APPEND | O_CREAT },
-		     { "ab",
-		       O_WRONLY | O_APPEND | O_CREAT | O_BINARY },
-		     { "r+",
-		       O_RDWR },
-		     { "rb+",
-		       O_RDWR | O_BINARY },
-		     { "r+b",
-		       O_RDONLY | O_WRONLY | O_BINARY },
-		     { "w+",
-		       O_RDWR | O_TRUNC | O_CREAT },
-		     { "wb+",
-		       O_RDWR | O_TRUNC | O_CREAT | O_BINARY },
-		     { "w+b",
-		       O_RDWR | O_TRUNC | O_CREAT | O_BINARY },
-		     { "a+",
-		       O_RDWR | O_CREAT | O_APPEND },
-		     { "ab+",
-		       O_RDWR | O_CREAT | O_APPEND | O_BINARY },
-		     { "a+b",
-		       O_RDWR | O_CREAT | O_APPEND | O_BINARY }
-  };
-  unsigned int i;
-  int err; 
-
-  for (i = 0; i < DIM (mode_flags); i++)
-    if (! strcmp (mode_flags[i].mode, mode))
-      break;
-  if (i == DIM (mode_flags))
+  switch (*mode)
     {
+    case 'r':
+      omode = O_RDONLY;
+      oflags = 0;
+      break;
+    case 'w':
+      omode = O_WRONLY;
+      oflags = O_TRUNC | O_CREAT;
+      break;
+    case 'a':
+      omode = O_WRONLY;
+      oflags = O_APPEND | O_CREAT;
+      break;
+    default:
       errno = EINVAL;
-      err = -1;
+      return -1;
     }
-  else
+  for (mode++; *mode; mode++)
     {
-      err = 0;
-      *modeflags = mode_flags[i].flags;
+      switch (*mode)
+        {
+        case '+':
+          omode = O_RDWR;
+          break;
+        case 'b':
+          oflags |= O_BINARY;
+          break;
+        case 'x':
+          oflags |= O_EXCL;
+          break;
+        default: /* Ignore unknown flags.  */
+          break; 
+        }
     }
 
-  return err;
+  *modeflags = (omode | oflags);
+  return 0;
 }
 
 

Modified: trunk/g10/card-util.c
===================================================================
--- trunk/g10/card-util.c	2009-06-02 15:46:59 UTC (rev 5032)
+++ trunk/g10/card-util.c	2009-06-03 17:24:24 UTC (rev 5033)
@@ -195,6 +195,7 @@
     case 0x0004: return "Wewid AB";
     case 0x0005: return "ZeitControl";
 
+    case 0x002A: return "Magrathea";
       /* 0x00000 and 0xFFFF are defined as test cards per spec,
          0xFFF00 to 0xFFFE are assigned for use with randomly created
          serial numbers.  */




More information about the Gnupg-commits mailing list