[svn] GnuPG - r4541 - in trunk: common g10 sm

svn author wk cvs at cvs.gnupg.org
Thu Jul 12 17:29:02 CEST 2007


Author: wk
Date: 2007-07-12 17:28:30 +0200 (Thu, 12 Jul 2007)
New Revision: 4541

Modified:
   trunk/common/ChangeLog
   trunk/common/sysutils.c
   trunk/common/sysutils.h
   trunk/g10/ChangeLog
   trunk/g10/gpg.c
   trunk/g10/gpgv.c
   trunk/sm/ChangeLog
   trunk/sm/gpgsm.c
   trunk/sm/server.c
Log:
Translate all file descriptors received from assuan.


Modified: trunk/common/ChangeLog
===================================================================
--- trunk/common/ChangeLog	2007-07-10 09:24:29 UTC (rev 4540)
+++ trunk/common/ChangeLog	2007-07-12 15:28:30 UTC (rev 4541)
@@ -1,3 +1,9 @@
+2007-07-12  Werner Koch  <wk at g10code.com>
+
+	* sysutils.h (gnupg_fd_t): New.
+	* sysutils.c (translate_sys2libc_fd): Use that type instead of int.
+	(translate_sys2libc_fd_int): New.
+
 2007-07-09  Werner Koch  <wk at g10code.com>
 
 	* t-gettime.c (test_isotime2epoch): Use time_t and not u32.

Modified: trunk/common/sysutils.c
===================================================================
--- trunk/common/sysutils.c	2007-07-10 09:24:29 UTC (rev 4540)
+++ trunk/common/sysutils.c	2007-07-12 15:28:30 UTC (rev 4541)
@@ -278,24 +278,36 @@
    translates system file handles to libc file handles.  FOR_WRITE
    gives the direction of the handle.  */
 int
-translate_sys2libc_fd (int fd, int for_write)
+translate_sys2libc_fd (gnupg_fd_t fd, int for_write)
 {
 #ifdef HAVE_W32_SYSTEM
   int x;
+
+  if (fd == GNUPG_INVALID_FD)
+    return -1;
   
-  if (fd <= 2)
-    return fd;	/* Do not do this for error, stdin, stdout, stderr.
-                   (This also ignores an fd of -1.) */
-
-  x = _open_osfhandle (fd, for_write ? 1 : 0);
+  /* Note that _open_osfhandle is currently defined to take and return
+     a long.  */
+  x = _open_osfhandle ((long)fd, for_write ? 1 : 0);
   if (x == -1)
     log_error ("failed to translate osfhandle %p\n", (void *) fd);
-  else
-    {
-/*       log_info ("_open_osfhandle %p yields %d%s\n", */
-/*                 (void*)fd, x, for_write? " for writing":"" ); */
-      fd = x;
-    }
-#endif /* HAVE_W32_SYSTEM */
+  return x;
+#else /*!HAVE_W32_SYSTEM */
   return fd;
+#endif
 }
+
+/* This is the same as translate_sys2libc_fd but takes an integer
+   which is assumet to be such an system handle.  */
+int
+translate_sys2libc_fd_int (int fd, int for_write)
+{
+#ifdef HAVE_W32_SYSTEM
+  if (fd <= 2)
+    return fd;	/* Do not do this for error, stdin, stdout, stderr. */
+
+  return translate_sys2libc_fd ((void*)fd, for_write);
+#else
+  return fd;
+#endif
+}

Modified: trunk/common/sysutils.h
===================================================================
--- trunk/common/sysutils.h	2007-07-10 09:24:29 UTC (rev 4540)
+++ trunk/common/sysutils.h	2007-07-12 15:28:30 UTC (rev 4541)
@@ -20,14 +20,29 @@
 #ifndef GNUPG_COMMON_SYSUTILS_H
 #define GNUPG_COMMON_SYSUTILS_H
 
+/* Because we use system handles and not libc low level file
+   descriptors on W32, we need to declare them as HANDLE (which
+   actually is a plain pointer).  This is required to eventually
+   support 64 bits Windows systems.  */
+#ifdef HAVE_W32_SYSTEM
+typedef void *gnupg_fd_t;
+#define GNUPG_INVALID_FD ((void*)(-1))
+#else
+typedef int gnupg_fd_t;
+#define GNUPG_INVALID_FD (-1)
+#endif
+
+
 void trap_unaligned (void);
 int  disable_core_dumps (void);
 int  enable_core_dumps (void);
 const unsigned char *get_session_marker (size_t *rlen);
 /*int check_permissions (const char *path,int extension,int checkonly);*/
 void gnupg_sleep (unsigned int seconds);
-int translate_sys2libc_fd (int fd, int for_write);
+int translate_sys2libc_fd (gnupg_fd_t fd, int for_write);
+int translate_sys2libc_fd_int (int fd, int for_write);
 
+
 #ifdef HAVE_W32_SYSTEM
 
 #include "../jnlib/w32help.h"

Modified: trunk/g10/ChangeLog
===================================================================
--- trunk/g10/ChangeLog	2007-07-10 09:24:29 UTC (rev 4540)
+++ trunk/g10/ChangeLog	2007-07-12 15:28:30 UTC (rev 4541)
@@ -1,3 +1,9 @@
+2007-07-12  Werner Koch  <wk at g10code.com>
+
+	* gpg.c (main): Use translate_sys2libc_fd_int when passing an int
+	value.
+	* gpgv.c (main): Ditto.
+
 2007-07-05  Werner Koch  <wk at g10code.com>
 
 	* card-util.c (card_generate_subkey, card_store_subkey): Enable

Modified: trunk/g10/gpg.c
===================================================================
--- trunk/g10/gpg.c	2007-07-10 09:24:29 UTC (rev 4540)
+++ trunk/g10/gpg.c	2007-07-12 15:28:30 UTC (rev 4541)
@@ -2160,19 +2160,19 @@
           case oDebugLevel: debug_level = pargs.r.ret_str; break;
 
 	  case oStatusFD:
-            set_status_fd( translate_sys2libc_fd (pargs.r.ret_int, 1) );
+            set_status_fd( translate_sys2libc_fd_int (pargs.r.ret_int, 1) );
             break;
 	  case oStatusFile:
             set_status_fd ( open_info_file (pargs.r.ret_str, 1) );
             break;
 	  case oAttributeFD:
-            set_attrib_fd(translate_sys2libc_fd (pargs.r.ret_int, 1));
+            set_attrib_fd(translate_sys2libc_fd_int (pargs.r.ret_int, 1));
             break;
 	  case oAttributeFile:
             set_attrib_fd ( open_info_file (pargs.r.ret_str, 1) );
             break;
 	  case oLoggerFD:
-            log_set_fd (translate_sys2libc_fd (pargs.r.ret_int, 1));
+            log_set_fd (translate_sys2libc_fd_int (pargs.r.ret_int, 1));
             break;
           case oLoggerFile:
             logfile = pargs.r.ret_str;
@@ -2436,14 +2436,14 @@
 	    set_passphrase_from_string(pargs.r.ret_str);
 	    break;
 	  case oPasswdFD:
-            pwfd = translate_sys2libc_fd (pargs.r.ret_int, 0);
+            pwfd = translate_sys2libc_fd_int (pargs.r.ret_int, 0);
             break;
 	  case oPasswdFile:
             pwfd = open_info_file (pargs.r.ret_str, 0);
             break;
 	  case oPasswdRepeat: opt.passwd_repeat=pargs.r.ret_int; break;
 	  case oCommandFD:
-            opt.command_fd = translate_sys2libc_fd (pargs.r.ret_int, 0);
+            opt.command_fd = translate_sys2libc_fd_int (pargs.r.ret_int, 0);
             break;
 	  case oCommandFile:
             opt.command_fd = open_info_file (pargs.r.ret_str, 0);

Modified: trunk/g10/gpgv.c
===================================================================
--- trunk/g10/gpgv.c	2007-07-10 09:24:29 UTC (rev 4540)
+++ trunk/g10/gpgv.c	2007-07-12 15:28:30 UTC (rev 4541)
@@ -154,7 +154,7 @@
           case oKeyring: append_to_strlist( &nrings, pargs.r.ret_str); break;
 	  case oStatusFD: set_status_fd( pargs.r.ret_int ); break;
 	  case oLoggerFD: 
-            log_set_fd (translate_sys2libc_fd (pargs.r.ret_int, 1));
+            log_set_fd (translate_sys2libc_fd_int (pargs.r.ret_int, 1));
             break;
 	  case oHomedir: opt.homedir = pargs.r.ret_str; break;
 	  case oIgnoreTimeConflict: opt.ignore_time_conflict = 1; break;

Modified: trunk/sm/ChangeLog
===================================================================
--- trunk/sm/ChangeLog	2007-07-10 09:24:29 UTC (rev 4540)
+++ trunk/sm/ChangeLog	2007-07-12 15:28:30 UTC (rev 4541)
@@ -1,3 +1,10 @@
+2007-07-12  Werner Koch  <wk at g10code.com>
+
+	* gpgsm.c (check_special_filename): Use translate_sys2libc_fd_int
+	when passing an int value.
+	* server.c (cmd_encrypt, cmd_decrypt, cmd_verify, cmd_import)
+	(cmd_export, cmd_message, cmd_genkey): 	Translate file descriptors.
+	
 2007-07-05  Werner Koch  <wk at g10code.com>
 
 	* Makefile.am (common_libs): Changed order of libs.

Modified: trunk/sm/gpgsm.c
===================================================================
--- trunk/sm/gpgsm.c	2007-07-10 09:24:29 UTC (rev 4540)
+++ trunk/sm/gpgsm.c	2007-07-12 15:28:30 UTC (rev 4541)
@@ -1741,7 +1741,7 @@
     for (i=0; isdigit (fname[i]); i++ )
       ;
     if ( !fname[i] ) 
-      return translate_sys2libc_fd (atoi (fname), for_write);
+      return translate_sys2libc_fd_int (atoi (fname), for_write);
   }
   return -1;
 }

Modified: trunk/sm/server.c
===================================================================
--- trunk/sm/server.c	2007-07-10 09:24:29 UTC (rev 4540)
+++ trunk/sm/server.c	2007-07-12 15:28:30 UTC (rev 4541)
@@ -29,6 +29,7 @@
 #include <assuan.h>
 
 #include "gpgsm.h"
+#include "sysutils.h"
 
 #define set_error(e,t) assuan_set_error (ctx, gpg_error (e), (t))
 
@@ -409,14 +410,14 @@
   FILE *out_fp;
   int rc;
 
-  inp_fd = assuan_get_input_fd (ctx);
+  inp_fd = translate_sys2libc_fd (assuan_get_input_fd (ctx), 0);
   if (inp_fd == -1)
     return set_error (GPG_ERR_ASS_NO_INPUT, NULL);
-  out_fd = assuan_get_output_fd (ctx);
+  out_fd = translate_sys2libc_fd (assuan_get_output_fd (ctx), 1);
   if (out_fd == -1)
     return set_error (GPG_ERR_ASS_NO_OUTPUT, NULL);
 
-  out_fp = fdopen ( dup(out_fd), "w");
+  out_fp = fdopen (dup (out_fd), "w");
   if (!out_fp)
     return set_error (GPG_ERR_ASS_GENERAL, "fdopen() failed");
   
@@ -460,14 +461,14 @@
   FILE *out_fp;
   int rc;
 
-  inp_fd = assuan_get_input_fd (ctx);
+  inp_fd = translate_sys2libc_fd (assuan_get_input_fd (ctx), 0);
   if (inp_fd == -1)
     return set_error (GPG_ERR_ASS_NO_INPUT, NULL);
-  out_fd = assuan_get_output_fd (ctx);
+  out_fd = translate_sys2libc_fd (assuan_get_output_fd (ctx), 1);
   if (out_fd == -1)
     return set_error (GPG_ERR_ASS_NO_OUTPUT, NULL);
 
-  out_fp = fdopen ( dup(out_fd), "w");
+  out_fp = fdopen (dup(out_fd), "w");
   if (!out_fp)
     return set_error (GPG_ERR_ASS_GENERAL, "fdopen() failed");
   rc = gpgsm_decrypt (ctrl, inp_fd, out_fp); 
@@ -496,8 +497,8 @@
 {
   int rc;
   ctrl_t ctrl = assuan_get_pointer (ctx);
-  int fd = assuan_get_input_fd (ctx);
-  int out_fd = assuan_get_output_fd (ctx);
+  int fd = translate_sys2libc_fd (assuan_get_input_fd (ctx), 0);
+  int out_fd = translate_sys2libc_fd (assuan_get_output_fd (ctx), 1);
   FILE *out_fp = NULL;
 
   if (fd == -1)
@@ -538,10 +539,10 @@
   int detached;
   int rc;
 
-  inp_fd = assuan_get_input_fd (ctx);
+  inp_fd = translate_sys2libc_fd (assuan_get_input_fd (ctx), 0);
   if (inp_fd == -1)
     return set_error (GPG_ERR_ASS_NO_INPUT, NULL);
-  out_fd = assuan_get_output_fd (ctx);
+  out_fd = translate_sys2libc_fd (assuan_get_output_fd (ctx), 1);
   if (out_fd == -1)
     return set_error (GPG_ERR_ASS_NO_OUTPUT, NULL);
 
@@ -575,7 +576,7 @@
 {
   ctrl_t ctrl = assuan_get_pointer (ctx);
   int rc;
-  int fd = assuan_get_input_fd (ctx);
+  int fd = translate_sys2libc_fd (assuan_get_input_fd (ctx), 0);
 
   if (fd == -1)
     return set_error (GPG_ERR_ASS_NO_INPUT, NULL);
@@ -653,7 +654,7 @@
     }
   else
     {
-      int fd = assuan_get_output_fd (ctx);
+      int fd = translate_sys2libc_fd (assuan_get_output_fd (ctx), 1);
       FILE *out_fp;
 
       if (fd == -1)
@@ -733,12 +734,14 @@
 cmd_message (assuan_context_t ctx, char *line)
 {
   int rc;
+  assuan_fd_t sysfd;
   int fd;
   ctrl_t ctrl = assuan_get_pointer (ctx);
 
-  rc = assuan_command_parse_fd (ctx, line, &fd);
+  rc = assuan_command_parse_fd (ctx, line, &sysfd);
   if (rc)
     return rc;
+  fd = translate_sys2libc_fd (sysfd, 0);
   if (fd == -1)
     return set_error (GPG_ERR_ASS_NO_INPUT, NULL);
   ctrl->server_local->message_fd = fd;
@@ -785,7 +788,7 @@
 
   if (ctrl->server_local->list_to_output)
     {
-      int outfd = assuan_get_output_fd (ctx);
+      int outfd = translate_sys2libc_fd (assuan_get_output_fd (ctx), 1);
 
       if ( outfd == -1 )
         return set_error (GPG_ERR_ASS_NO_OUTPUT, NULL);
@@ -853,10 +856,10 @@
   FILE *out_fp;
   int rc;
 
-  inp_fd = assuan_get_input_fd (ctx);
+  inp_fd = translate_sys2libc_fd (assuan_get_input_fd (ctx), 0);
   if (inp_fd == -1)
     return set_error (GPG_ERR_ASS_NO_INPUT, NULL);
-  out_fd = assuan_get_output_fd (ctx);
+  out_fd = translate_sys2libc_fd (assuan_get_output_fd (ctx), 1);
   if (out_fd == -1)
     return set_error (GPG_ERR_ASS_NO_OUTPUT, NULL);
 




More information about the Gnupg-commits mailing list