[svn] GnuPG - r5305 - in trunk: . agent common g10 gl sm tools

svn author wk cvs at cvs.gnupg.org
Wed Apr 14 13:24:03 CEST 2010


Author: wk
Date: 2010-04-14 13:24:02 +0200 (Wed, 14 Apr 2010)
New Revision: 5305

Modified:
   trunk/ChangeLog
   trunk/agent/ChangeLog
   trunk/agent/call-pinentry.c
   trunk/agent/call-scd.c
   trunk/agent/command-ssh.c
   trunk/agent/findkey.c
   trunk/agent/genkey.c
   trunk/agent/gpg-agent.c
   trunk/agent/protect-tool.c
   trunk/agent/protect.c
   trunk/agent/trustlist.c
   trunk/autogen.sh
   trunk/common/ChangeLog
   trunk/common/asshelp.c
   trunk/common/estream.c
   trunk/common/mischelp.c
   trunk/common/sysutils.c
   trunk/common/sysutils.h
   trunk/common/util.h
   trunk/common/w32help.h
   trunk/g10/ChangeLog
   trunk/g10/openfile.c
   trunk/gl/mkdtemp.c
   trunk/sm/ChangeLog
   trunk/sm/gpgsm.c
   trunk/sm/misc.c
   trunk/sm/sign.c
   trunk/tools/gpg-connect-agent.c
Log:
Whole lot of changes to support CE.


Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog	2010-04-13 01:06:18 UTC (rev 5304)
+++ trunk/ChangeLog	2010-04-14 11:24:02 UTC (rev 5305)
@@ -1,3 +1,9 @@
+2010-04-07  Werner Koch  <wk at g10code.com>
+
+	* autogen.sh: Take a .gnupg-autogen.rc file in account.
+
+	* gl/mkdtemp.c (getpid) [W32CE]: New macro.
+
 2010-03-24  Werner Koch  <wk at g10code.com>
 
 	* configure.ac (AH_BOTTOM): Use /gnupg as the default homedir on

Modified: trunk/agent/ChangeLog
===================================================================
--- trunk/agent/ChangeLog	2010-04-13 01:06:18 UTC (rev 5304)
+++ trunk/agent/ChangeLog	2010-04-14 11:24:02 UTC (rev 5305)
@@ -1,3 +1,40 @@
+2010-04-14  Werner Koch  <wk at g10code.com>
+
+	* trustlist.c (read_one_trustfile): Use estream.
+
+2010-04-13  Werner Koch  <wk at g10code.com>
+
+	* findkey.c (read_key_file): Use estream.
+	(agent_write_private_key): Ditto.
+
+2010-04-07  Werner Koch  <wk at g10code.com>
+
+	* gpg-agent.c (handle_connections) [W32]: Assume that PTh support
+	the handle event.  Use a dummy event for W32CE.
+	(get_agent_scd_notify_event) [W32CE]: Do not build.
+
+	* call-pinentry.c: Remove setenv.h.  Include sysutils.h.
+	(atfork_cb): s/setenv/gnupg_setenv/.
+
+	* gpg-agent.c: Do not include setenv.h.
+	(main): s/unsetenv/gnupg_unsetenv/.
+
+	* protect.c (calibrate_get_time) [W32CE]: Use GetThreadTimes.
+
+2010-04-06  Werner Koch  <wk at g10code.com>
+
+	* call-scd.c [!HAVE_SIGNAL_H]: Do not include signal.h.
+
+	* findkey.c (agent_write_private_key): s/remove/gnupg_remove/.
+
+	* command-ssh.c (search_control_file): Replace rewind by fseek and
+	clearerr.
+	* genkey.c (check_passphrase_pattern): Ditto.
+
+	* gpg-agent.c [!HAVE_SIGNAL_H]: Do not include signal.h.
+	(remove_socket): s/remove/gnupg_remove/.
+	(create_private_keys_directory): Use gnupg_mkdir.
+
 2010-03-11  Werner Koch  <wk at g10code.com>
 
 	* gpg-agent.c: Include "asshelp.h".

Modified: trunk/common/ChangeLog
===================================================================
--- trunk/common/ChangeLog	2010-04-13 01:06:18 UTC (rev 5304)
+++ trunk/common/ChangeLog	2010-04-14 11:24:02 UTC (rev 5305)
@@ -1,3 +1,26 @@
+2010-04-14  Werner Koch  <wk at g10code.com>
+
+	* asshelp.c (setup_libassuan_logging): Read ASSUAN_DEBUG envvar.
+	(my_libassuan_log_handler): Use it.
+	* sysutils.c (_gnupg_getenv): Implement ASSUAN_DEBUG.
+
+2010-04-08  Werner Koch  <wk at g10code.com>
+
+	* w32help.h (_setmode, setmode) [W32CE]: Provide prototype and
+	macro.
+
+2010-04-07  Werner Koch  <wk at g10code.com>
+
+	* mischelp.c (timegm): Replace unsetenv/putenv by gnupg_unsetenv.
+
+	* sysutils.c: Include setenv.h.
+	(gnupg_setenv, gnupg_unsetenv): New.
+
+
+2010-04-06  Werner Koch  <wk at g10code.com>
+
+	* sysutils.c (gnupg_mkdir): New.
+
 2010-03-29  Werner Koch  <wk at g10code.com>
 
 	* init.c (sleep_on_exit): Change to 400ms.

Modified: trunk/g10/ChangeLog
===================================================================
--- trunk/g10/ChangeLog	2010-04-13 01:06:18 UTC (rev 5304)
+++ trunk/g10/ChangeLog	2010-04-14 11:24:02 UTC (rev 5305)
@@ -1,3 +1,8 @@
+2010-04-06  Werner Koch  <wk at g10code.com>
+
+	* openfile.c (mkdir): Remove.
+	(try_make_homedir): Use gnupg_mkdir.
+
 2010-04-01  Werner Koch  <wk at g10code.com>
 
 	Use gpg_err_set_errno to set ERRNO.

Modified: trunk/sm/ChangeLog
===================================================================
--- trunk/sm/ChangeLog	2010-04-13 01:06:18 UTC (rev 5304)
+++ trunk/sm/ChangeLog	2010-04-14 11:24:02 UTC (rev 5305)
@@ -1,3 +1,22 @@
+2010-04-14  Werner Koch  <wk at g10code.com>
+
+	* gpgsm.c (main) [W32CE]: Disable dirmngr for now.
+
+2010-04-13  Werner Koch  <wk at g10code.com>
+
+	* sign.c (gpgsm_sign): Do not check qualified status in
+	no-chain-validation mode.
+
+2010-04-08  Werner Koch  <wk at g10code.com>
+
+	* gpgsm.c (open_es_fread): Add arg mode.
+	(main) <aKeygen>: Call with mode "r" instead of "rb".
+
+2010-04-07  Werner Koch  <wk at g10code.com>
+
+	* misc.c: Remove setenv.h.  Include sysutils.h.
+	(setup_pinentry_env): s/setenv/gnupg_setenv/
+
 2010-03-24  Werner Koch  <wk at g10code.com>
 
 	* Makefile.am (gpgsm_LDADD): Add extra_sys_libs.

Modified: trunk/agent/call-pinentry.c
===================================================================
--- trunk/agent/call-pinentry.c	2010-04-13 01:06:18 UTC (rev 5304)
+++ trunk/agent/call-pinentry.c	2010-04-14 11:24:02 UTC (rev 5305)
@@ -36,7 +36,7 @@
 
 #include "agent.h"
 #include <assuan.h>
-#include "setenv.h"
+#include "sysutils.h"
 #include "i18n.h"
 
 #ifdef _POSIX_OPEN_MAX
@@ -190,7 +190,7 @@
             {
               value = session_env_getenv (ctrl->session_env, name);
               if (value)
-                setenv (name, value, 1);
+                gnupg_setenv (name, value, 1);
             }
         }
     }
@@ -276,7 +276,7 @@
 
   if (!opt.pinentry_program || !*opt.pinentry_program)
     opt.pinentry_program = gnupg_module_name (GNUPG_MODULE_NAME_PINENTRY);
-    pgmname = opt.pinentry_program;
+  pgmname = opt.pinentry_program;
   if ( !(pgmname = strrchr (opt.pinentry_program, '/')))
     pgmname = opt.pinentry_program;
   else

Modified: trunk/agent/call-scd.c
===================================================================
--- trunk/agent/call-scd.c	2010-04-13 01:06:18 UTC (rev 5304)
+++ trunk/agent/call-scd.c	2010-04-14 11:24:02 UTC (rev 5305)
@@ -25,7 +25,9 @@
 #include <ctype.h>
 #include <assert.h>
 #include <unistd.h>
-#include <signal.h>
+#ifdef HAVE_SIGNAL_H
+# include <signal.h>
+#endif
 #include <sys/stat.h>
 #include <sys/types.h>
 #ifndef HAVE_W32_SYSTEM
@@ -385,7 +387,9 @@
     xfree (databuf);
   }
 
-  /* Tell the scdaemon we want him to send us an event signal. */
+  /* Tell the scdaemon we want him to send us an event signal.  We
+     don't support this for W32CE.  */
+#ifndef HAVE_W32CE_SYSTEM
   {
     char buf[100];
 
@@ -397,6 +401,7 @@
 #endif
     assuan_transact (ctx, buf, NULL, NULL, NULL, NULL, NULL, NULL);
   }
+#endif /*HAVE_W32CE_SYSTEM*/
 
   primary_scd_ctx = ctx;
   primary_scd_ctx_reusable = 0;

Modified: trunk/agent/command-ssh.c
===================================================================
--- trunk/agent/command-ssh.c	2010-04-13 01:06:18 UTC (rev 5304)
+++ trunk/agent/command-ssh.c	2010-04-14 11:24:02 UTC (rev 5305)
@@ -721,7 +721,8 @@
 
   assert (strlen (hexgrip) == 40 );
 
-  rewind (fp);
+  fseek (fp, 0, SEEK_SET);
+  clearerr (fp);
   *r_disabled = 0;
  next_line:
   do

Modified: trunk/agent/findkey.c
===================================================================
--- trunk/agent/findkey.c	2010-04-13 01:06:18 UTC (rev 5304)
+++ trunk/agent/findkey.c	2010-04-14 11:24:02 UTC (rev 5305)
@@ -57,9 +57,8 @@
                          const void *buffer, size_t length, int force)
 {
   char *fname;
-  FILE *fp;
+  estream_t fp;
   char hexgrip[40+4+1];
-  int fd;
   
   bin2hex (grip, 20, hexgrip);
   strcpy (hexgrip+40, ".key");
@@ -73,53 +72,30 @@
       return gpg_error (GPG_ERR_GENERAL);
     }
 
-  /* In FORCE mode we would like to create FNAME but only if it does
-     not already exist.  We cannot make this guarantee just using
-     POSIX (GNU provides the "x" opentype for fopen, however, this is
-     not portable).  Thus, we use the more flexible open function and
-     then use fdopen to obtain a stream. */
-  fd = open (fname, force? (O_CREAT | O_TRUNC | O_WRONLY | O_BINARY)
-                         : (O_CREAT | O_EXCL | O_WRONLY | O_BINARY),
-             S_IRUSR | S_IWUSR 
-#ifndef HAVE_W32_SYSTEM
-                 | S_IRGRP 
-#endif
-                 );
-  if (fd < 0)
-    fp = NULL;
-  else
-    {
-      fp = fdopen (fd, "wb");
-      if (!fp)
-        { 
-          int save_e = errno;
-          close (fd);
-          errno = save_e;
-        }
-    }
-
+  /* FIXME: On POSIX systems we used include S_IRGRP as well.  */
+  fp = es_fopen (fname, force? "wb" : "wbx");
   if (!fp) 
     { 
-      gpg_error_t tmperr = gpg_error (gpg_err_code_from_errno (errno));
-      log_error ("can't create `%s': %s\n", fname, strerror (errno));
+      gpg_error_t tmperr = gpg_error_from_syserror ();
+      log_error ("can't create `%s': %s\n", fname, gpg_strerror (tmperr));
       xfree (fname);
       return tmperr;
     }
 
-  if (fwrite (buffer, length, 1, fp) != 1)
+  if (es_fwrite (buffer, length, 1, fp) != 1)
     {
-      gpg_error_t tmperr = gpg_error (gpg_err_code_from_errno (errno));
-      log_error ("error writing `%s': %s\n", fname, strerror (errno));
-      fclose (fp);
-      remove (fname);
+      gpg_error_t tmperr = gpg_error_from_syserror ();
+      log_error ("error writing `%s': %s\n", fname, gpg_strerror (tmperr));
+      es_fclose (fp);
+      gnupg_remove (fname);
       xfree (fname);
       return tmperr;
     }
-  if ( fclose (fp) )
+  if (es_fclose (fp))
     {
-      gpg_error_t tmperr = gpg_error (gpg_err_code_from_errno (errno));
-      log_error ("error closing `%s': %s\n", fname, strerror (errno));
-      remove (fname);
+      gpg_error_t tmperr = gpg_error_from_syserror ();
+      log_error ("error closing `%s': %s\n", fname, gpg_strerror (tmperr));
+      gnupg_remove (fname);
       xfree (fname);
       return tmperr;
     }
@@ -425,7 +401,7 @@
 {
   int rc;
   char *fname;
-  FILE *fp;
+  estream_t fp;
   struct stat st;
   unsigned char *buf;
   size_t buflen, erroff;
@@ -438,7 +414,7 @@
   strcpy (hexgrip+40, ".key");
 
   fname = make_filename (opt.homedir, GNUPG_PRIVATE_KEYS_DIR, hexgrip, NULL);
-  fp = fopen (fname, "rb");
+  fp = es_fopen (fname, "rb");
   if (!fp)
     {
       rc = gpg_error_from_syserror ();
@@ -448,31 +424,44 @@
       return rc;
     }
   
-  if (fstat (fileno(fp), &st))
+  if (fstat (es_fileno (fp), &st))
     {
       rc = gpg_error_from_syserror ();
       log_error ("can't stat `%s': %s\n", fname, strerror (errno));
       xfree (fname);
-      fclose (fp);
+      es_fclose (fp);
       return rc;
     }
 
   buflen = st.st_size;
   buf = xtrymalloc (buflen+1);
-  if (!buf || fread (buf, buflen, 1, fp) != 1)
+  if (!buf)
     {
       rc = gpg_error_from_syserror ();
-      log_error ("error reading `%s': %s\n", fname, strerror (errno));
+      log_error ("error allocating %zu bytes for `%s': %s\n",
+                 buflen, fname, strerror (errno));
       xfree (fname);
-      fclose (fp);
+      es_fclose (fp);
       xfree (buf);
       return rc;
+
     }
 
+  if (es_fread (buf, buflen, 1, fp) != 1)
+    {
+      rc = gpg_error_from_syserror ();
+      log_error ("error reading %zu bytes from `%s': %s\n", 
+                 buflen, fname, strerror (errno));
+      xfree (fname);
+      es_fclose (fp);
+      xfree (buf);
+      return rc;
+    }
+
   /* Convert the file into a gcrypt S-expression object.  */
   rc = gcry_sexp_sscan (&s_skey, &erroff, (char*)buf, buflen);
   xfree (fname);
-  fclose (fp);
+  es_fclose (fp);
   xfree (buf);
   if (rc)
     {

Modified: trunk/agent/genkey.c
===================================================================
--- trunk/agent/genkey.c	2010-04-13 01:06:18 UTC (rev 5304)
+++ trunk/agent/genkey.c	2010-04-14 11:24:02 UTC (rev 5305)
@@ -117,7 +117,8 @@
       fclose (infp);
       return 1; /* Error - assume password should not be used.  */
     }
-  rewind (infp);
+  fseek (infp, 0, SEEK_SET);
+  clearerr (infp);
 
   i = 0;
   argv[i++] = "--null";
@@ -134,7 +135,8 @@
     result = 0; /* Success; i.e. no match.  */
 
   /* Overwrite our temporary file. */
-  rewind (infp);
+  fseek (infp, 0, SEEK_SET);
+  clearerr (infp);
   for (i=((strlen (pw)+99)/100)*100; i > 0; i--)
     putc ('\xff', infp);
   fflush (infp);

Modified: trunk/agent/gpg-agent.c
===================================================================
--- trunk/agent/gpg-agent.c	2010-04-13 01:06:18 UTC (rev 5304)
+++ trunk/agent/gpg-agent.c	2010-04-14 11:24:02 UTC (rev 5305)
@@ -1,6 +1,6 @@
 /* gpg-agent.c  -  The GnuPG Agent
- * Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005,
- *               2006, 2007, 2009 Free Software Foundation, Inc.
+ * Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2009,
+ *               2010 Free Software Foundation, Inc.
  *
  * This file is part of GnuPG.
  *
@@ -35,7 +35,9 @@
 # include <sys/un.h>
 #endif /*!HAVE_W32_SYSTEM*/
 #include <unistd.h>
-#include <signal.h>
+#ifdef HAVE_SIGNAL_H
+# include <signal.h>
+#endif
 #include <pth.h>
 
 #define JNLIB_NEED_LOG_LOGV
@@ -46,7 +48,6 @@
 #include "i18n.h"
 #include "mkdtemp.h" /* Gnulib replacement. */
 #include "sysutils.h"
-#include "setenv.h"
 #include "gc-opt-flags.h"
 #include "exechelp.h"
 #include "asshelp.h"
@@ -425,7 +426,7 @@
     {
       char *p;
 
-      remove (name);
+      gnupg_remove (name);
       p = strrchr (name, '/');
       if (p)
 	{
@@ -615,7 +616,7 @@
   malloc_hooks.realloc = gcry_realloc;
   malloc_hooks.free = gcry_free;
   assuan_set_malloc_hooks (&malloc_hooks);
-    assuan_set_gpg_err_source (GPG_ERR_SOURCE_DEFAULT);
+  assuan_set_gpg_err_source (GPG_ERR_SOURCE_DEFAULT);
   assuan_set_system_hooks (ASSUAN_SYSTEM_PTH);
   assuan_sock_init ();
   setup_libassuan_logging (&opt.debug);
@@ -994,7 +995,7 @@
          exec the program given as arguments). */
 #ifndef HAVE_W32_SYSTEM
       if (!opt.keep_display && !argc)
-        unsetenv ("DISPLAY");
+        gnupg_unsetenv ("DISPLAY");
 #endif
 
 
@@ -1374,7 +1375,7 @@
 /* Under W32, this function returns the handle of the scdaemon
    notification event.  Calling it the first time creates that
    event.  */
-#ifdef HAVE_W32_SYSTEM
+#if defined(HAVE_W32_SYSTEM) && !defined(HAVE_W32CE_SYSTEM)
 void *
 get_agent_scd_notify_event (void)
 {
@@ -1412,7 +1413,7 @@
   log_debug  ("returning notify handle %p\n", the_event);
   return the_event;
 }
-#endif /*HAVE_W32_SYSTEM*/
+#endif /*HAVE_W32_SYSTEM && !HAVE_W32CE_SYSTEM*/
 
 
 
@@ -1510,7 +1511,7 @@
           assuan_sock_close (fd);
           agent_exit (2);
         }
-      remove (name);
+      gnupg_remove (name);
       rc = assuan_sock_bind (fd, (struct sockaddr*) serv_addr, len);
     }
   if (rc != -1 
@@ -1556,15 +1557,9 @@
   fname = make_filename (home, GNUPG_PRIVATE_KEYS_DIR, NULL);
   if (stat (fname, &statbuf) && errno == ENOENT)
     {
-#ifdef HAVE_W32_SYSTEM  /*FIXME: Setup proper permissions.  */
-      if (!CreateDirectory (fname, NULL))
+      if (gnupg_mkdir (fname, "-rwx"))
         log_error (_("can't create directory `%s': %s\n"),
-                   fname, w32_strerror (-1) );
-#else
-      if (mkdir (fname, S_IRUSR|S_IWUSR|S_IXUSR ))
-        log_error (_("can't create directory `%s': %s\n"),
                    fname, strerror (errno) );
-#endif
       else if (!opt.quiet)
         log_info (_("directory `%s' created\n"), fname);
     }
@@ -1601,15 +1596,9 @@
 #endif
                )
             {
-#ifdef HAVE_W32_SYSTEM
-              if (!CreateDirectory (home, NULL))
+              if (gnupg_mkdir (home, "-rwx"))
                 log_error (_("can't create directory `%s': %s\n"),
-                           home, w32_strerror (-1) );
-#else
-              if (mkdir (home, S_IRUSR|S_IWUSR|S_IXUSR ))
-                log_error (_("can't create directory `%s': %s\n"),
                            home, strerror (errno) );
-#endif
               else 
                 {
                   if (!opt.quiet)
@@ -1863,14 +1852,14 @@
   pth_sigmask (SIG_UNBLOCK, &sigs, NULL);
   ev = pth_event (PTH_EVENT_SIGS, &sigs, &signo);
 #else
-# ifdef PTH_EVENT_HANDLE
-  sigs = 0;
-  ev = pth_event (PTH_EVENT_HANDLE, get_agent_scd_notify_event ());
-  signo = 0;
-# else
+# ifdef HAVE_W32CE_SYSTEM
   /* Use a dummy event. */
   sigs = 0;
   ev = pth_event (PTH_EVENT_SIGS, &sigs, &signo);
+# else
+  sigs = 0;
+  ev = pth_event (PTH_EVENT_HANDLE, get_agent_scd_notify_event ());
+  signo = 0;
 # endif
 #endif
   time_ev = NULL;

Modified: trunk/agent/protect-tool.c
===================================================================
--- trunk/agent/protect-tool.c	2010-04-13 01:06:18 UTC (rev 5304)
+++ trunk/agent/protect-tool.c	2010-04-14 11:24:02 UTC (rev 5305)
@@ -1249,14 +1249,14 @@
     {
       log_error ("error writing `%s': %s\n", fname, strerror (errno));
       es_fclose (fp);
-      remove (fname);
+      gnupg_remove (fname);
       xfree (fname);
       return -1;
     }
   if (es_fclose (fp))
     {
       log_error ("error closing `%s': %s\n", fname, strerror (errno));
-      remove (fname);
+      gnupg_remove (fname);
       xfree (fname);
       return -1;
     }

Modified: trunk/agent/protect.c
===================================================================
--- trunk/agent/protect.c	2010-04-13 01:06:18 UTC (rev 5304)
+++ trunk/agent/protect.c	2010-04-14 11:24:02 UTC (rev 5305)
@@ -78,7 +78,11 @@
 calibrate_get_time (struct calibrate_time_s *data)
 {
 #ifdef HAVE_W32_SYSTEM
+# ifdef HAVE_W32CE_SYSTEM
+  GetThreadTimes (GetCurrentThread (),
+# else 
   GetProcessTimes (GetCurrentProcess (),
+# endif
                    &data->creation_time, &data->exit_time,
                    &data->kernel_time, &data->user_time);
 #else

Modified: trunk/agent/trustlist.c
===================================================================
--- trunk/agent/trustlist.c	2010-04-13 01:06:18 UTC (rev 5304)
+++ trunk/agent/trustlist.c	2010-04-14 11:24:02 UTC (rev 5305)
@@ -116,7 +116,7 @@
                     int *addr_of_tableidx)
 {
   gpg_error_t err = 0;
-  FILE *fp;
+  estream_t fp;
   int n, c;
   char *p, line[256];
   trustitem_t *table, *ti;
@@ -128,7 +128,7 @@
   tablesize = *addr_of_tablesize;
   tableidx = *addr_of_tableidx;
 
-  fp = fopen (fname, "r");
+  fp = es_fopen (fname, "r");
   if (!fp)
     {
       err = gpg_error_from_syserror ();
@@ -136,14 +136,14 @@
       goto leave;
     }
 
-  while (fgets (line, DIM(line)-1, fp))
+  while (es_fgets (line, DIM(line)-1, fp))
     {
       lnr++;
       
       if (!*line || line[strlen(line)-1] != '\n')
         {
           /* Eat until end of line. */
-          while ( (c=getc (fp)) != EOF && c != '\n')
+          while ( (c=es_getc (fp)) != EOF && c != '\n')
             ;
           err = gpg_error (*line? GPG_ERR_LINE_TOO_LONG
                            : GPG_ERR_INCOMPLETE_LINE);
@@ -288,7 +288,7 @@
         }
       tableidx++;
     }
-  if ( !err && !feof (fp) )
+  if ( !err && !es_feof (fp) )
     {
       err = gpg_error_from_syserror ();
       log_error (_("error reading `%s', line %d: %s\n"),
@@ -296,8 +296,7 @@
     }
 
  leave:
-  if (fp)
-    fclose (fp);
+  es_fclose (fp);
   *addr_of_table = table;
   *addr_of_tablesize = tablesize;
   *addr_of_tableidx = tableidx;

Modified: trunk/autogen.sh
===================================================================
--- trunk/autogen.sh	2010-04-13 01:06:18 UTC (rev 5304)
+++ trunk/autogen.sh	2010-04-14 11:24:02 UTC (rev 5305)
@@ -18,7 +18,7 @@
 }
 
 check_version () {
-    if [ `("$1" --version || echo "0") | cvtver` -ge "$2" ]; then
+    if [ $(( `("$1" --version || echo "0") | cvtver` >= $2 )) = 1 ]; then
        return 0
     fi
     echo "**Error**: "\`$1\'" not installed or too old." >&2
@@ -45,6 +45,24 @@
   shift
 fi
 
+# Begin list of optional variables sourced from ~/.gnupg-autogen.rc
+w32_toolprefixes=
+w32_extraoptions=
+w32ce_toolprefixes=
+w32ce_extraoptions=
+amd64_toolprefixes=
+# End list of optional variables sourced from ~/.gnupg-autogen.rc
+# What follows are variables which are sourced but default to 
+# environment variables or lacking them hardcoded values.
+#w32root=
+#w32ce_root=
+#amd64root=
+
+if [ -f "$HOME/.gnupg-autogen.rc" ]; then
+    echo "sourcing extra definitions from $HOME/.gnupg-autogen.rc"
+    . "$HOME/.gnupg-autogen.rc"
+fi
+
 # Convenience option to use certain configure options for some hosts.
 myhost="" 
 myhostsub=""
@@ -59,6 +77,10 @@
     --build-amd64)
         myhost="amd64"
         ;;
+    --build*)
+        echo "**Error**: invalid build option $1" >&2
+        exit 1
+        ;;
     *)
      ;;
 esac
@@ -76,16 +98,17 @@
     fi
     build=`$tsdir/scripts/config.guess`
 
-    extraoptions=""
     case $myhostsub in
         ce)
-          [ -z "$w32root" ] && w32root="$HOME/w32ce_root"
-          toolprefixes="arm-mingw32ce"
-          extraoptions="--disable-scdaemon"
+          [ -z "$w32ce_root" ] && w32root="$HOME/w32ce_root"
+          toolprefixes="$w32ce_toolprefixes arm-mingw32ce"
+          extraoptions="--disable-scdaemon $w32ce_extraoptions"
           ;;
         *)
           [ -z "$w32root" ] && w32root="$HOME/w32root"
-          toolprefixes="i586-mingw32msvc i386-mingw32msvc mingw32"
+          toolprefixes="$w32_toolprefixes i586-mingw32msvc"
+          toolprefixes="$toolprefixes i386-mingw32msvc mingw32"
+          extraoptions="$w32_extraoptions"
           ;;
     esac
     echo "Using $w32root as standard install directory" >&2
@@ -146,10 +169,12 @@
 
     [ -z "$amd64root" ] && amd64root="$HOME/amd64root"
     echo "Using $amd64root as standard install directory" >&2
+
+    toolprefixes="$amd64_toolprefixes x86_64-linux-gnu amd64-linux-gnu"
     
     # Locate the cross compiler
     crossbindir=
-    for host in x86_64-linux-gnu amd64-linux-gnu; do
+    for host in $toolprefixes ; do
         if ${host}-gcc --version >/dev/null 2>&1 ; then
             crossbindir=/usr/${host}/bin
             conf_CC="CC=${host}-gcc"
@@ -224,7 +249,7 @@
     cat <<EOF
 
 Note that you may use alternative versions of the tools by setting 
-the corresponding environment variables; see README.CVS for details.
+the corresponding environment variables; see README.SVN for details.
                    
 EOF
     exit 1

Modified: trunk/common/asshelp.c
===================================================================
--- trunk/common/asshelp.c	2010-04-13 01:06:18 UTC (rev 5304)
+++ trunk/common/asshelp.c	2010-04-14 11:24:02 UTC (rev 5305)
@@ -36,6 +36,14 @@
 #include "asshelp.h"
 
 
+/* A bitfield that specifies the assuan categories to log.  This is
+   identical to the default log handler of libassuan.  We need to do
+   it ourselves because we use a custom log handler and want to use
+   the same assuan variables to select the categories to log. */
+static int log_cats;
+#define TEST_LOG_CAT(x) (!! (log_cats & (1 << (x - 1))))
+
+
 static int
 my_libassuan_log_handler (assuan_context_t ctx, void *hook,
                           unsigned int cat, const char *msg)
@@ -44,8 +52,9 @@
 
   (void)ctx;
 
-  if (cat != ASSUAN_LOG_CONTROL)
-    return 0; /* We only want the control channel messages.  */
+  if (! TEST_LOG_CAT (cat))
+    return 0;
+
   dbgval = hook? *(unsigned int*)hook : 0;
   if (!(dbgval & 1024))
     return 0; /* Assuan debugging is not enabled.  */
@@ -62,6 +71,13 @@
 void
 setup_libassuan_logging (unsigned int *debug_var_address)
 {
+  char *flagstr;
+
+  flagstr = getenv ("ASSUAN_DEBUG");
+  if (flagstr)
+    log_cats = atoi (flagstr);
+  else /* Default to log the control channel.  */
+    log_cats = (1 << (ASSUAN_LOG_CONTROL - 1));
   assuan_set_log_cb (my_libassuan_log_handler, debug_var_address);
 }
 

Modified: trunk/common/estream.c
===================================================================
--- trunk/common/estream.c	2010-04-13 01:06:18 UTC (rev 5304)
+++ trunk/common/estream.c	2010-04-14 11:24:02 UTC (rev 5305)
@@ -118,6 +118,9 @@
 
 #ifdef HAVE_W32CE_SYSTEM
 # define _set_errno(a)  gpg_err_set_errno ((a))
+/* Setmode is missing in cegcc but available since CE 5.0.  */
+int _setmode (int handle, int mode);
+# define setmode(a,b)   _setmode ((a),(b))
 #else
 # define _set_errno(a)  do { errno = (a); } while (0)
 #endif

Modified: trunk/common/mischelp.c
===================================================================
--- trunk/common/mischelp.c	2010-04-13 01:06:18 UTC (rev 5304)
+++ trunk/common/mischelp.c	2010-04-14 11:24:02 UTC (rev 5305)
@@ -183,11 +183,7 @@
         putenv (old_zone);	
     }
   else
-#ifdef HAVE_UNSETENV
-    unsetenv("TZ");
-#else
-    putenv("TZ");
-#endif
+    gnupg_unsetenv("TZ");
 
   tzset();
   return answer;

Modified: trunk/common/sysutils.c
===================================================================
--- trunk/common/sysutils.c	2010-04-13 01:06:18 UTC (rev 5304)
+++ trunk/common/sysutils.c	2010-04-14 11:24:02 UTC (rev 5305)
@@ -51,6 +51,8 @@
 #endif
 #include <fcntl.h>
 
+#include "setenv.h"   /* Gnulib replacement.  */
+
 #include "util.h"
 #include "i18n.h"
 
@@ -529,17 +531,122 @@
 }
 
 
+/* A wrapper around mkdir which takes a string for the mode argument.
+   This makes it easier to handle the mode argument which is not
+   defined on all systems.  The format of the modestring is
 
+      "-rwxrwxrwx"
+      
+   '-' is a don't care or not set.  'r', 'w', 'x' are read allowed,
+   write allowed, execution allowed with the first group for the user,
+   the second for the group and the third for all others.  If the
+   string is shorter than above the missing mode characters are meant
+   to be not set.  */
+int
+gnupg_mkdir (const char *name, const char *modestr)
+{
+#ifdef HAVE_W32CE_SYSTEM
+  wchar_t *wname;
+  (void)modestr;
+  
+  wname = utf8_to_wchar (name);
+  if (!wname)
+    return -1;
+  if (!CreateDirectoryW (wname, NULL))
+    {
+      xfree (wname);
+      return -1;  /* ERRNO is automagically provided by gpg-error.h.  */
+    }
+  xfree (wname);
+  return 0;
+#elif MKDIR_TAKES_ONE_ARG
+  (void)modestr;
+  /* Note: In the case of W32 we better use CreateDirectory and try to
+     set appropriate permissions.  However using mkdir is easier
+     because this sets ERRNO.  */
+  return mkdir (name);
+#else
+  mode_t mode = 0;
 
+  if (modestr && *modestr)
+    {
+      modestr++;
+      if (*modestr && *modestr++ == 'r')
+        mode |= S_IRUSR;
+      if (*modestr && *modestr++ == 'w')
+        mode |= S_IWUSR;
+      if (*modestr && *modestr++ == 'x')
+        mode |= S_IXUSR;
+      if (*modestr && *modestr++ == 'r')
+        mode |= S_IRGRP;
+      if (*modestr && *modestr++ == 'w')
+        mode |= S_IWGRP;
+      if (*modestr && *modestr++ == 'x')
+        mode |= S_IXGRP;
+      if (*modestr && *modestr++ == 'r')
+        mode |= S_IROTH;
+      if (*modestr && *modestr++ == 'w')
+        mode |= S_IWOTH;
+      if (*modestr && *modestr++ == 'x')
+        mode |= S_IXOTH;
+    }
+  return mkdir (home, mode)
+#endif
+}
+
+
+int
+gnupg_setenv (const char *name, const char *value, int overwrite)
+{
 #ifdef HAVE_W32CE_SYSTEM
+  (void)name;
+  (void)value;
+  (void)overwrite;
+  return 0;
+#else
+  setenv (name, value, overwrite);
+#endif
+}
+
+int 
+gnupg_unsetenv (const char *name)
+{
+#ifdef HAVE_W32CE_SYSTEM
+  (void)name;
+  return 0;
+#else
+# ifdef HAVE_UNSETENV
+  unsetenv (name);
+# else
+  putenv (name);
+# endif
+#endif
+}
+
+
+#ifdef HAVE_W32CE_SYSTEM
 /* Replacement for getenv which takes care of the our use of getenv.
    The code is not thread safe but we expect it to work in all cases
    because it is called for the first time early enough.  */
 char *
 _gnupg_getenv (const char *name)
 {
-  (void)name;
-  return NULL;
+  static int initialized;
+  static char *assuan_debug;
+  
+  if (!initialized)
+    {
+      assuan_debug = read_w32_registry_string (NULL, 
+                                               "\\Software\\GNU\\libassuan",
+                                               "debug");
+      initialized = 1;
+    }
+
+  if (!strcmp (name, "ASSUAN_DEBUG"))
+    return assuan_debug;
+  else
+    return NULL;
 }
+
 #endif /*HAVE_W32CE_SYSTEM*/
 

Modified: trunk/common/sysutils.h
===================================================================
--- trunk/common/sysutils.h	2010-04-13 01:06:18 UTC (rev 5304)
+++ trunk/common/sysutils.h	2010-04-14 11:24:02 UTC (rev 5305)
@@ -49,6 +49,9 @@
 void gnupg_reopen_std (const char *pgmname);
 void gnupg_allow_set_foregound_window (pid_t pid);
 int  gnupg_remove (const char *fname);
+int  gnupg_mkdir (const char *name, const char *modestr);
+int  gnupg_setenv (const char *name, const char *value, int overwrite);
+int  gnupg_unsetenv (const char *name);
 
 #ifdef HAVE_W32_SYSTEM
 

Modified: trunk/common/util.h
===================================================================
--- trunk/common/util.h	2010-04-13 01:06:18 UTC (rev 5304)
+++ trunk/common/util.h	2010-04-14 11:24:02 UTC (rev 5305)
@@ -298,6 +298,8 @@
 #define getpid() GetCurrentProcessId ()
 char *_gnupg_getenv (const char *name); /* See sysutils.c */
 #define getenv(a)  _gnupg_getenv ((a))
+char *_gnupg_setenv (const char *name); /* See sysutils.c */
+#define setenv(a,b,c)  _gnupg_setenv ((a),(b),(c))
 #endif
 
 

Modified: trunk/common/w32help.h
===================================================================
--- trunk/common/w32help.h	2010-04-13 01:06:18 UTC (rev 5304)
+++ trunk/common/w32help.h	2010-04-14 11:24:02 UTC (rev 5305)
@@ -28,5 +28,12 @@
                                const char *name, const char *value);
 
 
+/* Other stuff.  */
+#ifdef HAVE_W32CE_SYSTEM
+/* Setmode is missing in cegcc but available since CE 5.0.  */
+int _setmode (int handle, int mode);
+# define setmode(a,b)   _setmode ((a),(b))
+#endif /*HAVE_W32CE_SYSTEM*/
+
 #endif /*HAVE_W32_SYSTEM*/
 #endif /*LIBJNLIB_MISCHELP_H*/

Modified: trunk/g10/openfile.c
===================================================================
--- trunk/g10/openfile.c	2010-04-13 01:06:18 UTC (rev 5304)
+++ trunk/g10/openfile.c	2010-04-14 11:24:02 UTC (rev 5305)
@@ -56,10 +56,6 @@
 #define CMP_FILENAME(a,b) strcmp( (a), (b) )
 #endif
 
-#ifdef MKDIR_TAKES_ONE_ARG
-#undef mkdir
-#define mkdir(a,b) mkdir(a)
-#endif
 
 /* FIXME:  Implement opt.interactive. */
 
@@ -444,12 +440,11 @@
 #endif
       )
     {
-      if ( mkdir (fname, S_IRUSR|S_IWUSR|S_IXUSR) )
+      if (gnupg_mkdir (fname, "-rwx"))
         log_fatal ( _("can't create directory `%s': %s\n"),
                     fname, strerror(errno) );
       else if (!opt.quiet )
         log_info ( _("directory `%s' created\n"), fname );
       copy_options_file( fname );
-      
     }
 }

Modified: trunk/gl/mkdtemp.c
===================================================================
--- trunk/gl/mkdtemp.c	2010-04-13 01:06:18 UTC (rev 5304)
+++ trunk/gl/mkdtemp.c	2010-04-14 11:24:02 UTC (rev 5305)
@@ -80,6 +80,11 @@
 # include <io.h>
 #endif
 
+#ifdef HAVE_W32CE_SYSTEM
+#include <windows.h>
+#define getpid() GetCurrentProcessId ()
+#endif
+
 #if !_LIBC
 # define __getpid getpid
 # define __gettimeofday gettimeofday

Modified: trunk/sm/gpgsm.c
===================================================================
--- trunk/sm/gpgsm.c	2010-04-13 01:06:18 UTC (rev 5304)
+++ trunk/sm/gpgsm.c	2010-04-14 11:24:02 UTC (rev 5305)
@@ -434,7 +434,7 @@
 static void emergency_cleanup (void);
 static int check_special_filename (const char *fname, int for_write);
 static int open_read (const char *filename);
-static estream_t open_es_fread (const char *filename);
+static estream_t open_es_fread (const char *filename, const char *mode);
 static FILE *open_fwrite (const char *filename);
 static estream_t open_es_fwrite (const char *filename);
 static void run_protect_tool (int argc, char **argv);
@@ -942,6 +942,11 @@
 
   opt.homedir = default_homedir ();
 
+#ifdef HAVE_W32CE_SYSTEM
+  opt.disable_dirmngr = 1;
+  opt.no_crl_check = 1;
+#endif
+ 
   /* First check whether we have a config file on the commandline */
   orig_argc = argc;
   orig_argv = argv;
@@ -1834,9 +1839,9 @@
         if (opt.batch)
           {
             if (!argc) /* Create from stdin. */
-              fpin = open_es_fread ("-"); 
+              fpin = open_es_fread ("-", "r"); 
             else if (argc == 1) /* From file. */
-              fpin = open_es_fread (*argv); 
+              fpin = open_es_fread (*argv, "r"); 
             else
               wrong_args ("--gen-key --batch [parmfile]");
           }
@@ -2057,7 +2062,7 @@
 
 /* Same as open_read but return an estream_t.  */
 static estream_t
-open_es_fread (const char *filename)
+open_es_fread (const char *filename, const char *mode)
 {
   int fd;
   estream_t fp;
@@ -2068,7 +2073,7 @@
     fd = check_special_filename (filename, 0);
   if (fd != -1)
     {
-      fp = es_fdopen_nc (fd, "rb");
+      fp = es_fdopen_nc (fd, mode);
       if (!fp)
         {
           log_error ("es_fdopen(%d) failed: %s\n", fd, strerror (errno));
@@ -2076,7 +2081,7 @@
         }
       return fp;
     }
-  fp = es_fopen (filename, "rb");
+  fp = es_fopen (filename, mode);
   if (!fp)
     {
       log_error (_("can't open `%s': %s\n"), filename, strerror (errno));

Modified: trunk/sm/misc.c
===================================================================
--- trunk/sm/misc.c	2010-04-13 01:06:18 UTC (rev 5304)
+++ trunk/sm/misc.c	2010-04-14 11:24:02 UTC (rev 5305)
@@ -30,7 +30,7 @@
 
 #include "gpgsm.h"
 #include "i18n.h"
-#include "setenv.h"
+#include "sysutils.h"
 
 /* Setup the environment so that the pinentry is able to get all
    required information.  This is used prior to an exec of the
@@ -49,7 +49,7 @@
      but print a warning.  */
   value = session_env_getenv (opt.session_env, "GPG_TTY");
   if (value)
-    setenv ("GPG_TTY", value, 1);
+    gnupg_setenv ("GPG_TTY", value, 1);
   else if (!(lc=getenv ("GPG_TTY")) || !*lc)
     {
       log_error (_("GPG_TTY has not been set - "
@@ -57,21 +57,21 @@
       lc = ttyname (0);
       if (!lc)
         lc = "/dev/tty";
-      setenv ("GPG_TTY", lc, 1);
+      gnupg_setenv ("GPG_TTY", lc, 1);
     }
 
   if (opt.lc_ctype)
-    setenv ("LC_CTYPE", opt.lc_ctype, 1);
+    gnupg_setenv ("LC_CTYPE", opt.lc_ctype, 1);
 #if defined(HAVE_SETLOCALE) && defined(LC_CTYPE)
   else if ( (lc = setlocale (LC_CTYPE, "")) )
-    setenv ("LC_CTYPE", lc, 1);
+    gnupg_setenv ("LC_CTYPE", lc, 1);
 #endif
 
   if (opt.lc_messages)
-    setenv ("LC_MESSAGES", opt.lc_messages, 1);
+    gnupg_setenv ("LC_MESSAGES", opt.lc_messages, 1);
 #if defined(HAVE_SETLOCALE) && defined(LC_MESSAGES)
   else if ( (lc = setlocale (LC_MESSAGES, "")) )
-    setenv ("LC_MESSAGES", lc, 1);
+    gnupg_setenv ("LC_MESSAGES", lc, 1);
 #endif
 
   iterator = 0;
@@ -81,7 +81,7 @@
         continue;  /* Already set.  */
       value = session_env_getenv (opt.session_env, name);
       if (value)
-        setenv (name, value, 1);
+        gnupg_setenv (name, value, 1);
     }
 
 #endif /*!HAVE_W32_SYSTEM*/

Modified: trunk/sm/sign.c
===================================================================
--- trunk/sm/sign.c	2010-04-13 01:06:18 UTC (rev 5304)
+++ trunk/sm/sign.c	2010-04-14 11:24:02 UTC (rev 5305)
@@ -503,31 +503,34 @@
   /* Check whether one of the certificates is qualified.  Note that we
      already validated the certificate and thus the user data stored
      flag must be available. */
-  for (cl=signerlist; cl; cl = cl->next)
+  if (!opt.no_chain_validation)
     {
-      size_t buflen;
-      char buffer[1];
-      
-      err = ksba_cert_get_user_data (cl->cert, "is_qualified", 
-                                     &buffer, sizeof (buffer), &buflen);
-      if (err || !buflen)
+      for (cl=signerlist; cl; cl = cl->next)
         {
-          log_error (_("checking for qualified certificate failed: %s\n"),
-                     gpg_strerror (err)); 
-          rc = err;
-          goto leave;
+          size_t buflen;
+          char buffer[1];
+          
+          err = ksba_cert_get_user_data (cl->cert, "is_qualified", 
+                                         &buffer, sizeof (buffer), &buflen);
+          if (err || !buflen)
+            {
+              log_error (_("checking for qualified certificate failed: %s\n"),
+                         gpg_strerror (err)); 
+              rc = err;
+              goto leave;
+            }
+          if (*buffer)
+            err = gpgsm_qualified_consent (ctrl, cl->cert);
+          else
+            err = gpgsm_not_qualified_warning (ctrl, cl->cert);
+          if (err)
+            {
+              rc = err;
+              goto leave;
+            }
         }
-      if (*buffer)
-        err = gpgsm_qualified_consent (ctrl, cl->cert);
-      else
-        err = gpgsm_not_qualified_warning (ctrl, cl->cert);
-      if (err)
-        {
-          rc = err;
-          goto leave;
-        }
     }
-  
+
   /* Prepare hashing (actually we are figuring out what we have set
      above). */
   rc = gcry_md_open (&data_md, 0, 0);

Modified: trunk/tools/gpg-connect-agent.c
===================================================================
--- trunk/tools/gpg-connect-agent.c	2010-04-13 01:06:18 UTC (rev 5304)
+++ trunk/tools/gpg-connect-agent.c	2010-04-14 11:24:02 UTC (rev 5305)
@@ -210,12 +210,17 @@
   for (;;)
     {
       buffer = xmalloc (size+1);
+#ifdef HAVE_W32CE_SYSTEM
+      strcpy (buffer, "/");
+      return buffer;
+#else      
       if (getcwd (buffer, size) == buffer)
         return buffer;
       xfree (buffer);
       if (errno != ERANGE)
         return NULL;
       size *= 2;
+#endif
     }
 }
 
@@ -989,7 +994,8 @@
   if (fd >= 0 && fd < DIM (open_fd_table))
     {
       open_fd_table[fd].inuse = 1;
-#ifdef HAVE_W32_SYSTEM
+#warning fixme: implement our pipe emulation.
+#if defined(HAVE_W32_SYSTEM) && !defined(HAVE_W32CE_SYSTEM)
       {
         HANDLE prochandle, handle, newhandle;
 
@@ -1197,7 +1203,11 @@
   if (log_get_errorcount (0))
     exit (2);
 
+#ifdef HAVE_W32CE_SYSTEM
+  use_tty = 0;
+#else
   use_tty = (isatty ( fileno (stdin)) && isatty (fileno (stdout)));
+#endif
 
   if (opt.exec)
     {
@@ -1890,7 +1900,11 @@
     {
       if (d->is_prog)
         {
+#ifdef HAVE_W32CE_SYSTEM
+          fp = NULL;
+#else
           fp = popen (d->file, "r");
+#endif
           if (!fp)
             log_error ("error executing `%s': %s\n",
                        d->file, strerror (errno));
@@ -1931,8 +1945,10 @@
     ;
   else if (d->is_prog)
     {
+#ifndef HAVE_W32CE_SYSTEM
       if (pclose (fp))
         log_error ("error running `%s': %s\n", d->file, strerror (errno));
+#endif
     }
   else
     fclose (fp);




More information about the Gnupg-commits mailing list