[svn] GnuPG - r4587 - in trunk: . agent common g10 jnlib po scd tools

svn author wk cvs at cvs.gnupg.org
Mon Oct 1 16:49:06 CEST 2007


Author: wk
Date: 2007-10-01 16:48:39 +0200 (Mon, 01 Oct 2007)
New Revision: 4587

Modified:
   trunk/ChangeLog
   trunk/NEWS
   trunk/agent/ChangeLog
   trunk/agent/agent.h
   trunk/agent/command-ssh.c
   trunk/agent/command.c
   trunk/agent/gpg-agent.c
   trunk/common/ChangeLog
   trunk/common/homedir.c
   trunk/common/sysutils.h
   trunk/configure.ac
   trunk/g10/server.c
   trunk/jnlib/ChangeLog
   trunk/jnlib/w32-afunix.c
   trunk/jnlib/w32-afunix.h
   trunk/po/be.po
   trunk/po/ca.po
   trunk/po/cs.po
   trunk/po/da.po
   trunk/po/el.po
   trunk/po/eo.po
   trunk/po/es.po
   trunk/po/et.po
   trunk/po/fi.po
   trunk/po/fr.po
   trunk/po/gl.po
   trunk/po/hu.po
   trunk/po/id.po
   trunk/po/it.po
   trunk/po/ja.po
   trunk/po/nb.po
   trunk/po/pl.po
   trunk/po/pt.po
   trunk/po/pt_BR.po
   trunk/po/ro.po
   trunk/po/ru.po
   trunk/po/sk.po
   trunk/po/sv.po
   trunk/po/tr.po
   trunk/po/zh_CN.po
   trunk/po/zh_TW.po
   trunk/scd/ChangeLog
   trunk/scd/scdaemon.c
   trunk/scd/scdaemon.h
   trunk/tools/ChangeLog
   trunk/tools/gpg-connect-agent.c
Log:
Use Assuan socket wrapper calls.
Made socket servers secure under Windows.


Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog	2007-09-18 11:40:09 UTC (rev 4586)
+++ trunk/ChangeLog	2007-10-01 14:48:39 UTC (rev 4587)
@@ -1,3 +1,7 @@
+2007-10-01  Werner Koch  <wk at g10code.com>
+
+	* configure.ac: Require assuan 1.0.4.
+
 2007-09-14  Werner Koch  <wk at g10code.com>
 
 	* configure.ac (GNUPG_LIBASSUAN_VERSION): New.

Modified: trunk/NEWS
===================================================================
--- trunk/NEWS	2007-09-18 11:40:09 UTC (rev 4586)
+++ trunk/NEWS	2007-10-01 14:48:39 UTC (rev 4587)
@@ -1,7 +1,11 @@
 Noteworthy changes in version 2.0.8
 ------------------------------------------------
 
+ * Make sure that under Windows the file permissions of the socket are
+   taken into account.  This required a change of our the socket
+   emulation code; thus old GnuPG modules can't be used anymore.
 
+
 Noteworthy changes in version 2.0.7 (2007-09-10)
 ------------------------------------------------
 

Modified: trunk/agent/ChangeLog
===================================================================
--- trunk/agent/ChangeLog	2007-09-18 11:40:09 UTC (rev 4586)
+++ trunk/agent/ChangeLog	2007-10-01 14:48:39 UTC (rev 4587)
@@ -1,3 +1,17 @@
+2007-10-01  Werner Koch  <wk at g10code.com>
+
+	* agent.h (struct server_control_s): Remove unused CONNECTION_FD.
+
+	* gpg-agent.c: Remove w32-afunix.h.  Include mkdtemp.h.
+	(socket_nonce, socket_nonce_ssh): New.
+	(create_server_socket): Use assuan socket wrappers.  Remove W32
+	specific stuff.  Save the server nonce.
+	(check_nonce): New.
+	(start_connection_thread, start_connection_thread_ssh): Call it.
+	(handle_connections): Change args to gnupg_fd_t.
+	* command.c (start_command_handler): Change LISTEN_FD to gnupg_fd_t.
+	* command-ssh.c (start_command_handler_ssh): Ditto.
+
 2007-09-18  Werner Koch  <wk at g10code.com>
 
 	* agent.h (struct pin_entry_info_s): Add element WITH_QUALITYBAR.

Modified: trunk/agent/agent.h
===================================================================
--- trunk/agent/agent.h	2007-09-18 11:40:09 UTC (rev 4586)
+++ trunk/agent/agent.h	2007-10-01 14:48:39 UTC (rev 4587)
@@ -32,7 +32,8 @@
 #include <gcrypt.h>
 #include "../common/util.h"
 #include "../common/errors.h"
-#include "membuf.h"
+#include "../common/membuf.h"
+#include "../common/sysutils.h" /* (gnupg_fd_t) */
 
 /* To convey some special hash algorithms we use algorithm numbers
    reserved for application use. */
@@ -131,7 +132,7 @@
   /* Private data used to fire up the connection thread.  We use this
      structure do avoid an extra allocation for just a few bytes. */
   struct {
-    int fd;
+    gnupg_fd_t fd;
   } thread_startup;
   
   /* Private data of the server (command.c). */
@@ -140,8 +141,6 @@
   /* Private data of the SCdaemon (call-scd.c). */
   struct scd_local_s *scd_local;
 
-  int   connection_fd; /* -1 or an identifier for the current connection. */
-
   char *display;
   char *ttyname;
   char *ttytype;
@@ -209,10 +208,10 @@
 gpg_error_t agent_write_status (ctrl_t ctrl, const char *keyword, ...);
 void bump_key_eventcounter (void);
 void bump_card_eventcounter (void);
-void start_command_handler (ctrl_t, int, int);
+void start_command_handler (ctrl_t, gnupg_fd_t, gnupg_fd_t);
 
 /*-- command-ssh.c --*/
-void start_command_handler_ssh (ctrl_t, int);
+void start_command_handler_ssh (ctrl_t, gnupg_fd_t);
 
 /*-- findkey.c --*/
 int agent_write_private_key (const unsigned char *grip,

Modified: trunk/agent/command-ssh.c
===================================================================
--- trunk/agent/command-ssh.c	2007-09-18 11:40:09 UTC (rev 4586)
+++ trunk/agent/command-ssh.c	2007-10-01 14:48:39 UTC (rev 4587)
@@ -2818,15 +2818,12 @@
 
 /* Start serving client on SOCK_CLIENT.  */
 void
-start_command_handler_ssh (ctrl_t ctrl, int sock_client)
+start_command_handler_ssh (ctrl_t ctrl, gnupg_fd_t sock_client)
 {
   estream_t stream_sock;
   gpg_error_t err;
   int ret;
 
-  /* Setup control structure.  */
-  ctrl->connection_fd = sock_client;
-
   /* Because the ssh protocol does not send us information about the
      the current TTY setting, we resort here to use those from startup
      or those explictly set.  */
@@ -2843,7 +2840,7 @@
 
 
   /* Create stream from socket.  */
-  stream_sock = es_fdopen (sock_client, "r+");
+  stream_sock = es_fdopen (FD2INT(sock_client), "r+");
   if (!stream_sock)
     {
       err = gpg_error_from_syserror ();

Modified: trunk/agent/command.c
===================================================================
--- trunk/agent/command.c	2007-09-18 11:40:09 UTC (rev 4586)
+++ trunk/agent/command.c	2007-10-01 14:48:39 UTC (rev 4587)
@@ -1544,12 +1544,12 @@
    control structure for this connection; it has only the basic
    intialization. */
 void
-start_command_handler (ctrl_t ctrl, int listen_fd, int fd)
+start_command_handler (ctrl_t ctrl, gnupg_fd_t listen_fd, gnupg_fd_t fd)
 {
   int rc;
   assuan_context_t ctx;
 
-  if (listen_fd == -1 && fd == -1)
+  if (listen_fd == GNUPG_INVALID_FD && fd == GNUPG_INVALID_FD)
     {
       int filedes[2];
 
@@ -1557,14 +1557,13 @@
       filedes[1] = 1;
       rc = assuan_init_pipe_server (&ctx, filedes);
     }
-  else if (listen_fd != -1)
+  else if (listen_fd != GNUPG_INVALID_FD)
     {
       rc = assuan_init_socket_server_ext (&ctx, listen_fd, 0);
     }
   else 
     {
       rc = assuan_init_socket_server_ext (&ctx, fd, 2);
-      ctrl->connection_fd = fd;
     }
   if (rc)
     {

Modified: trunk/agent/gpg-agent.c
===================================================================
--- trunk/agent/gpg-agent.c	2007-09-18 11:40:09 UTC (rev 4586)
+++ trunk/agent/gpg-agent.c	2007-10-01 14:48:39 UTC (rev 4587)
@@ -40,13 +40,11 @@
 
 #define JNLIB_NEED_LOG_LOGV
 #include "agent.h"
-#include <assuan.h> /* Malloc hooks */
+#include <assuan.h> /* Malloc hooks  and socket wrappers. */
 
 #include "i18n.h"
+#include "mkdtemp.h" /* Gnulib replacement. */
 #include "sysutils.h"
-#ifdef HAVE_W32_SYSTEM
-# include "../jnlib/w32-afunix.h"
-#endif
 #include "setenv.h"
 #include "gc-opt-flags.h"
 
@@ -207,6 +205,12 @@
 /* Name of the communication socket used for ssh-agent-emulation.  */
 static char *socket_name_ssh;
 
+/* We need to keep track of the server's nonces (these are dummies for
+   POSIX systems). */
+static assuan_sock_nonce_t socket_nonce;
+static assuan_sock_nonce_t socket_nonce_ssh;
+
+
 /* Default values for options passed to the pinentry. */
 static char *default_display;
 static char *default_ttyname;
@@ -236,13 +240,15 @@
 
 static char *create_socket_name (int use_standard_socket,
                                  char *standard_name, char *template);
-static int create_server_socket (int is_standard_name, char *name);
+static gnupg_fd_t create_server_socket (int is_standard_name, char *name, 
+                                        assuan_sock_nonce_t *nonce);
 static void create_directories (void);
 
 static void agent_init_default_ctrl (ctrl_t ctrl);
 static void agent_deinit_default_ctrl (ctrl_t ctrl);
 
-static void handle_connections (int listen_fd, int listen_fd_ssh);
+static void handle_connections (gnupg_fd_t listen_fd,
+                                gnupg_fd_t listen_fd_ssh);
 static int check_for_running_agent (int silent, int mode);
 
 /* Pth wrapper function definitions. */
@@ -845,7 +851,7 @@
           agent_exit (1);
         }
       agent_init_default_ctrl (ctrl);
-      start_command_handler (ctrl, -1, -1);
+      start_command_handler (ctrl, GNUPG_INVALID_FD, GNUPG_INVALID_FD);
       agent_deinit_default_ctrl (ctrl);
       xfree (ctrl);
     }
@@ -853,8 +859,8 @@
     ; /* NOTREACHED */
   else
     { /* Regular server mode */
-      int fd;
-      int fd_ssh;
+      gnupg_fd_t fd;
+      gnupg_fd_t fd_ssh;
       pid_t pid;
 
       /* Remove the DISPLAY variable so that a pinentry does not
@@ -878,11 +884,13 @@
                                             "S.gpg-agent.ssh",
                                             "/tmp/gpg-XXXXXX/S.gpg-agent.ssh");
 
-      fd = create_server_socket (standard_socket, socket_name);
+      fd = create_server_socket (standard_socket, socket_name,
+                                 &socket_nonce);
       if (opt.ssh_support)
-	fd_ssh = create_server_socket (standard_socket, socket_name_ssh);
+	fd_ssh = create_server_socket (standard_socket, socket_name_ssh,
+                                       &socket_nonce_ssh);
       else
-	fd_ssh = -1;
+	fd_ssh = GNUPG_INVALID_FD;
 
       /* If we are going to exec a program in the parent, we record
          the PID, so that the child may check whether the program is
@@ -1079,8 +1087,8 @@
       }
 #endif /*!HAVE_W32_SYSTEM*/
 
-      handle_connections (fd, opt.ssh_support ? fd_ssh : -1);
-      close (fd);
+      handle_connections (fd, opt.ssh_support ? fd_ssh : GNUPG_INVALID_FD);
+      assuan_sock_close (fd);
     }
   
   return 0;
@@ -1109,8 +1117,6 @@
 static void
 agent_init_default_ctrl (ctrl_t ctrl)
 {
-  ctrl->connection_fd = -1;
-
   /* Note we ignore malloc errors because we can't do much about it
      and the request will fail anyway shortly after this
      initialization. */
@@ -1269,20 +1275,17 @@
 /* Create a Unix domain socket with NAME.  IS_STANDARD_NAME indicates
    whether a non-random socket is used.  Returns the file descriptor or
    terminates the process in case of an error. */
-static int
-create_server_socket (int is_standard_name, char *name)
+static gnupg_fd_t
+create_server_socket (int is_standard_name, char *name,
+                      assuan_sock_nonce_t *nonce)
 {
   struct sockaddr_un *serv_addr;
   socklen_t len;
-  int fd;
+  gnupg_fd_t fd;
   int rc;
 
-#ifdef HAVE_W32_SYSTEM
-  fd = _w32_sock_new (AF_UNIX, SOCK_STREAM, 0);
-#else
-  fd = socket (AF_UNIX, SOCK_STREAM, 0);
-#endif
-  if (fd == -1)
+  fd = assuan_sock_new (AF_UNIX, SOCK_STREAM, 0);
+  if (fd == ASSUAN_INVALID_FD)
     {
       log_error (_("can't create socket: %s\n"), strerror (errno));
       agent_exit (2);
@@ -1291,43 +1294,32 @@
   serv_addr = xmalloc (sizeof (*serv_addr)); 
   memset (serv_addr, 0, sizeof *serv_addr);
   serv_addr->sun_family = AF_UNIX;
-  assert (strlen (name) + 1 < sizeof (serv_addr->sun_path));
+  if (strlen (name) + 1 >= sizeof (serv_addr->sun_path))
+    {
+      log_error (_("socket name `%s' is too long\n"), name);
+      agent_exit (2);
+    }
   strcpy (serv_addr->sun_path, name);
   len = (offsetof (struct sockaddr_un, sun_path)
 	 + strlen (serv_addr->sun_path) + 1);
 
-#ifdef HAVE_W32_SYSTEM
-  rc = _w32_sock_bind (fd, (struct sockaddr*) serv_addr, len);
-  if (is_standard_name && rc == -1 && errno == WSAEADDRINUSE)
-    {
-      if (!check_for_running_agent (1, 1))
-        {
-          log_error (_("a gpg-agent is already running - "
-                      "not starting a new one\n"));
-          *name = 0; /* Inhibit removal of the socket by cleanup(). */
-          close (fd);
-          agent_exit (2);
-        }
-
-      remove (name);
-      rc = _w32_sock_bind (fd, (struct sockaddr*) serv_addr, len);
-    }
-#else
-  rc = bind (fd, (struct sockaddr*) serv_addr, len);
+  rc = assuan_sock_bind (fd, (struct sockaddr*) serv_addr, len);
   if (is_standard_name && rc == -1 && errno == EADDRINUSE)
     {
       if (!check_for_running_agent (1, 1))
         {
           log_error (_("a gpg-agent is already running - "
-                      "not starting a new one\n"));
+                       "not starting a new one\n"));
           *name = 0; /* Inhibit removal of the socket by cleanup(). */
-          close (fd);
+          assuan_sock_close (fd);
           agent_exit (2);
         }
       remove (name);
-      rc = bind (fd, (struct sockaddr*) serv_addr, len);
+      rc = assuan_sock_bind (fd, (struct sockaddr*) serv_addr, len);
     }
-#endif
+  if (rc != -1 
+      && (rc=assuan_sock_get_nonce ((struct sockaddr*)serv_addr, len, nonce)))
+    log_error (_("error getting nonce for the socket\n"));
   if (rc == -1)
     {
       /* We use gpg_strerror here because it allows us to get strings
@@ -1336,16 +1328,16 @@
 		 serv_addr->sun_path, 
                  gpg_strerror (gpg_error_from_errno (errno)));
       
-      close (fd);
+      assuan_sock_close (fd);
       if (is_standard_name)
         *name = 0; /* Inhibit removal of the socket by cleanup(). */
       agent_exit (2);
     }
 
-  if (listen (fd, 5 ) == -1)
+  if (listen (FD2INT(fd), 5 ) == -1)
     {
       log_error (_("listen() failed: %s\n"), strerror (errno));
-      close (fd);
+      assuan_sock_close (fd);
       agent_exit (2);
     }
           
@@ -1538,21 +1530,42 @@
 }
 
 
+/* Check the nonce on a new connection.  This is a NOP unless we we
+   are using our Unix domain socket emulation under Windows.  */
+static int 
+check_nonce (ctrl_t ctrl, assuan_sock_nonce_t *nonce)
+{
+  if (assuan_sock_check_nonce (ctrl->thread_startup.fd, nonce))
+    {
+      log_info (_("error reading nonce on fd %d: %s\n"), 
+                FD2INT(ctrl->thread_startup.fd), strerror (errno));
+      assuan_sock_close (ctrl->thread_startup.fd);
+      xfree (ctrl);
+      return -1;
+    }
+  else
+    return 0;
+}
+
+
 /* This is the standard connection thread's main function.  */
 static void *
 start_connection_thread (void *arg)
 {
   ctrl_t ctrl = arg;
 
+  if (check_nonce (ctrl, &socket_nonce))
+    return NULL;
+
   agent_init_default_ctrl (ctrl);
   if (opt.verbose)
     log_info (_("handler 0x%lx for fd %d started\n"), 
-              (long)pth_self (), ctrl->thread_startup.fd);
+              (long)pth_self (), FD2INT(ctrl->thread_startup.fd));
 
-  start_command_handler (ctrl, -1, ctrl->thread_startup.fd);
+  start_command_handler (ctrl, GNUPG_INVALID_FD, ctrl->thread_startup.fd);
   if (opt.verbose)
     log_info (_("handler 0x%lx for fd %d terminated\n"), 
-              (long)pth_self (), ctrl->thread_startup.fd);
+              (long)pth_self (), FD2INT(ctrl->thread_startup.fd));
   
   agent_deinit_default_ctrl (ctrl);
   xfree (ctrl);
@@ -1566,15 +1579,18 @@
 {
   ctrl_t ctrl = arg;
 
+  if (check_nonce (ctrl, &socket_nonce_ssh))
+    return NULL;
+
   agent_init_default_ctrl (ctrl);
   if (opt.verbose)
     log_info (_("ssh handler 0x%lx for fd %d started\n"),
-              (long)pth_self (), ctrl->thread_startup.fd);
+              (long)pth_self (), FD2INT(ctrl->thread_startup.fd));
 
   start_command_handler_ssh (ctrl, ctrl->thread_startup.fd);
   if (opt.verbose)
     log_info (_("ssh handler 0x%lx for fd %d terminated\n"),
-              (long)pth_self (), ctrl->thread_startup.fd);
+              (long)pth_self (), FD2INT(ctrl->thread_startup.fd));
   
   agent_deinit_default_ctrl (ctrl);
   xfree (ctrl);
@@ -1585,7 +1601,7 @@
 /* Connection handler loop.  Wait for connection requests and spawn a
    thread after accepting a connection.  */
 static void
-handle_connections (int listen_fd, int listen_fd_ssh)
+handle_connections (gnupg_fd_t listen_fd, gnupg_fd_t listen_fd_ssh)
 {
   pth_attr_t tattr;
   pth_event_t ev, time_ev;
@@ -1595,7 +1611,7 @@
   socklen_t plen;
   fd_set fdset, read_fdset;
   int ret;
-  int fd;
+  gnupg_fd_t fd;
   int nfd;
 
   tattr = pth_attr_new();
@@ -1620,13 +1636,13 @@
   time_ev = NULL;
 
   FD_ZERO (&fdset);
-  FD_SET (listen_fd, &fdset);
-  nfd = listen_fd;
-  if (listen_fd_ssh != -1)
+  FD_SET (FD2INT (listen_fd), &fdset);
+  nfd = FD2INT (listen_fd);
+  if (listen_fd_ssh != GNUPG_INVALID_FD)
     {
-      FD_SET (listen_fd_ssh, &fdset);
-      if (listen_fd_ssh > nfd)
-        nfd = listen_fd_ssh;
+      FD_SET ( FD2INT(listen_fd_ssh), &fdset);
+      if (FD2INT (listen_fd_ssh) > nfd)
+        nfd = FD2INT (listen_fd_ssh);
     }
 
   for (;;)
@@ -1701,13 +1717,14 @@
          new thread.  Thus we need to block those signals. */
       pth_sigmask (SIG_BLOCK, &sigs, &oldsigs);
 
-      if (FD_ISSET (listen_fd, &read_fdset))
+      if (FD_ISSET (FD2INT (listen_fd), &read_fdset))
 	{
           ctrl_t ctrl;
 
           plen = sizeof paddr;
-	  fd = pth_accept (listen_fd, (struct sockaddr *)&paddr, &plen);
-	  if (fd == -1)
+	  fd = INT2FD (pth_accept (FD2INT(listen_fd),
+                                   (struct sockaddr *)&paddr, &plen));
+	  if (fd == GNUPG_INVALID_FD)
 	    {
 	      log_error ("accept failed: %s\n", strerror (errno));
 	    }
@@ -1715,14 +1732,14 @@
             {
               log_error ("error allocating connection control data: %s\n",
                          strerror (errno) );
-              close (fd);
+              assuan_sock_close (fd);
             }
           else 
             {
               char threadname[50];
 
               snprintf (threadname, sizeof threadname-1,
-                        "conn fd=%d (gpg)", fd);
+                        "conn fd=%d (gpg)", FD2INT(fd));
               threadname[sizeof threadname -1] = 0;
               pth_attr_set (tattr, PTH_ATTR_NAME, threadname);
               ctrl->thread_startup.fd = fd;
@@ -1730,20 +1747,22 @@
                 {
                   log_error ("error spawning connection handler: %s\n",
                              strerror (errno) );
-                  close (fd);
+                  assuan_sock_close (fd);
                   xfree (ctrl);
                 }
             }
-          fd = -1;
+          fd = GNUPG_INVALID_FD;
 	}
 
-      if (listen_fd_ssh != -1 && FD_ISSET (listen_fd_ssh, &read_fdset))
+      if (listen_fd_ssh != GNUPG_INVALID_FD 
+          && FD_ISSET ( FD2INT (listen_fd_ssh), &read_fdset))
 	{
           ctrl_t ctrl;
 
           plen = sizeof paddr;
-	  fd = pth_accept (listen_fd_ssh, (struct sockaddr *)&paddr, &plen);
-	  if (fd == -1)
+	  fd = INT2FD(pth_accept (FD2INT(listen_fd_ssh),
+                                  (struct sockaddr *)&paddr, &plen));
+	  if (fd == GNUPG_INVALID_FD)
 	    {
 	      log_error ("accept failed for ssh: %s\n", strerror (errno));
 	    }
@@ -1751,7 +1770,7 @@
             {
               log_error ("error allocating connection control data: %s\n",
                          strerror (errno) );
-              close (fd);
+              assuan_sock_close (fd);
             }
           else
             {
@@ -1759,7 +1778,7 @@
 
               agent_init_default_ctrl (ctrl);
               snprintf (threadname, sizeof threadname-1,
-                        "conn fd=%d (ssh)", fd);
+                        "conn fd=%d (ssh)", FD2INT(fd));
               threadname[sizeof threadname -1] = 0;
               pth_attr_set (tattr, PTH_ATTR_NAME, threadname);
               ctrl->thread_startup.fd = fd;
@@ -1767,11 +1786,11 @@
                 {
                   log_error ("error spawning ssh connection handler: %s\n",
                              strerror (errno) );
-                  close (fd);
+                  assuan_sock_close (fd);
                   xfree (ctrl);
                 }
             }
-          fd = -1;
+          fd = GNUPG_INVALID_FD;
 	}
 
       /* Restore the signal mask. */

Modified: trunk/common/ChangeLog
===================================================================
--- trunk/common/ChangeLog	2007-09-18 11:40:09 UTC (rev 4586)
+++ trunk/common/ChangeLog	2007-10-01 14:48:39 UTC (rev 4587)
@@ -1,3 +1,12 @@
+2007-10-01  Werner Koch  <wk at g10code.com>
+
+	* sysutils.h (FD2INT, INT2FD): New.
+
+2007-09-21  Werner Koch  <wk at g10code.com>
+
+	* homedir.c (default_homedir): Make registry work.  Reported by
+	Marc Mutz.
+
 2007-08-29  Werner Koch  <wk at g10code.com>
 
 	* exechelp.c (gnupg_wait_process): Add arg EXITCODE.  Changed all

Modified: trunk/common/homedir.c
===================================================================
--- trunk/common/homedir.c	2007-09-18 11:40:09 UTC (rev 4586)
+++ trunk/common/homedir.c	2007-10-01 14:48:39 UTC (rev 4587)
@@ -143,7 +143,7 @@
 
               tmp = read_w32_registry_string (NULL, "Software\\GNU\\GnuPG",
                                               "HomeDir");
-              if (tmp && *tmp)
+              if (tmp && !*tmp)
                 {
                   xfree (tmp);
                   tmp = NULL;

Modified: trunk/common/sysutils.h
===================================================================
--- trunk/common/sysutils.h	2007-09-18 11:40:09 UTC (rev 4586)
+++ trunk/common/sysutils.h	2007-10-01 14:48:39 UTC (rev 4587)
@@ -27,9 +27,13 @@
 #ifdef HAVE_W32_SYSTEM
 typedef void *gnupg_fd_t;
 #define GNUPG_INVALID_FD ((void*)(-1))
+#define INT2FD(s) ((void *)(s))
+#define FD2INT(h) ((unsigned int)(h))
 #else
 typedef int gnupg_fd_t;
 #define GNUPG_INVALID_FD (-1)
+#define INT2FD(s) (s)
+#define FD2INT(h) (h)
 #endif
 
 

Modified: trunk/configure.ac
===================================================================
--- trunk/configure.ac	2007-09-18 11:40:09 UTC (rev 4586)
+++ trunk/configure.ac	2007-10-01 14:48:39 UTC (rev 4587)
@@ -43,7 +43,7 @@
 NEED_LIBGCRYPT_VERSION=1.2.2
 
 NEED_LIBASSUAN_API=1
-NEED_LIBASSUAN_VERSION=1.0.2
+NEED_LIBASSUAN_VERSION=1.0.4
 
 NEED_KSBA_API=1
 NEED_KSBA_VERSION=1.0.2

Modified: trunk/g10/server.c
===================================================================
--- trunk/g10/server.c	2007-09-18 11:40:09 UTC (rev 4586)
+++ trunk/g10/server.c	2007-10-01 14:48:39 UTC (rev 4587)
@@ -32,9 +32,9 @@
 #include "util.h"
 #include "i18n.h"
 #include "options.h"
+#include "../common/sysutils.h"
 
 
-
 #define set_error(e,t) assuan_set_error (ctx, gpg_error (e), (t))
 
 
@@ -44,7 +44,7 @@
   /* Our current Assuan context. */
   assuan_context_t assuan_ctx;  
   /* File descriptor as set by the MESSAGE command. */
-  int message_fd;               
+  gnupg_fd_t message_fd;               
 };
 
 
@@ -53,10 +53,10 @@
 static void 
 close_message_fd (ctrl_t ctrl)
 {
-  if (ctrl->server_local->message_fd != -1)
+  if (ctrl->server_local->message_fd != GNUPG_INVALID_FD)
     {
-      close (ctrl->server_local->message_fd);
-      ctrl->server_local->message_fd = -1;
+      assuan_sock_close (ctrl->server_local->message_fd);
+      ctrl->server_local->message_fd = GNUPG_INVALID_FD;
     } 
 }
 
@@ -229,27 +229,28 @@
 {
   int rc;
   ctrl_t ctrl = assuan_get_pointer (ctx);
-  int fd = assuan_get_input_fd (ctx);
-  int out_fd = assuan_get_output_fd (ctx);
+  gnupg_fd_t fd = assuan_get_input_fd (ctx);
+  gnupg_fd_t out_fd = assuan_get_output_fd (ctx);
   FILE *out_fp = NULL;
 
-  if (fd == -1)
+  if (fd == GNUPG_INVALID_FD)
     return gpg_error (GPG_ERR_ASS_NO_INPUT);
 
-  if (out_fd != -1)
+  if (out_fd != GNUPG_INVALID_FD)
     {
-      out_fp = fdopen ( dup(out_fd), "w");
+      out_fp = fdopen ( dup (FD2INT (out_fd)), "w");
       if (!out_fp)
         return set_error (GPG_ERR_ASS_GENERAL, "fdopen() failed");
     }
 
-  log_debug ("WARNING: The server mode work in progress and not ready for use\n");
+  log_debug ("WARNING: The server mode work "
+             "in progress and not ready for use\n");
 
   /* Need to dup it because it might get closed and libassuan won't
      know about it then. */
   rc = gpg_verify (ctrl,
-                   dup (fd), 
-                   dup (ctrl->server_local->message_fd),
+                   dup ( FD2INT (fd)), 
+                   dup ( FD2INT (ctrl->server_local->message_fd)),
                    out_fp);
 
   if (out_fp)
@@ -326,13 +327,13 @@
 cmd_message (assuan_context_t ctx, char *line)
 {
   int rc;
-  int fd;
+  gnupg_fd_t fd;
   ctrl_t ctrl = assuan_get_pointer (ctx);
 
   rc = assuan_command_parse_fd (ctx, line, &fd);
   if (rc)
     return rc;
-  if (fd == -1)
+  if (fd == GNUPG_INVALID_FD)
     return gpg_error (GPG_ERR_ASS_NO_INPUT);
   ctrl->server_local->message_fd = fd;
   return 0;
@@ -488,7 +489,7 @@
       goto leave;
     }
   ctrl->server_local->assuan_ctx = ctx;
-  ctrl->server_local->message_fd = -1;
+  ctrl->server_local->message_fd = GNUPG_INVALID_FD;
 
   if (DBG_ASSUAN)
     assuan_set_log_stream (ctx, log_get_stream ());

Modified: trunk/jnlib/ChangeLog
===================================================================
--- trunk/jnlib/ChangeLog	2007-09-18 11:40:09 UTC (rev 4586)
+++ trunk/jnlib/ChangeLog	2007-10-01 14:48:39 UTC (rev 4587)
@@ -1,3 +1,9 @@
+2007-10-01  Werner Koch  <wk at g10code.com>
+
+	* w32-afunix.c: Only keep the client related code.
+	(read_port_and_nonce): New.  Taken from Assuan.
+	(_w32_sock_connect): Rewritten.
+
 2007-08-29  Werner Koch  <wk at g10code.com>
 
 	* argparse.c (initialize): Make strings translatable and remove

Modified: trunk/jnlib/w32-afunix.c
===================================================================
--- trunk/jnlib/w32-afunix.c	2007-09-18 11:40:09 UTC (rev 4586)
+++ trunk/jnlib/w32-afunix.c	2007-10-01 14:48:39 UTC (rev 4587)
@@ -1,4 +1,4 @@
-/* w32-afunix.c - AF_UNIX emulation for Windows.
+/* w32-afunix.c - AF_UNIX emulation for Windows (Client only).
  * Copyright (C) 2004, 2006 g10 Code GmbH
  *
  * This file is part of JNLIB.
@@ -17,8 +17,13 @@
  * License along with this program; if not, see <http://www.gnu.org/licenses/>.
  */
 
+/* Use of this code is preprecated - you better use the sockt wrappers
+   from libassuan. */
+
 #ifdef _WIN32
 #include <stdio.h>
+#include <stdlib.h>
+#define WIN32_LEAN_AND_MEAN
 #include <windows.h>
 #include <fcntl.h>
 #include <sys/stat.h>
@@ -27,12 +32,50 @@
 
 #include "w32-afunix.h"
 
-#ifndef S_IRGRP
-# define S_IRGRP 0
-# define S_IWGRP 0
-#endif
 
 
+/* The buffer for NONCE needs to be at least 16 bytes.  Returns 0 on
+   success. */
+static int
+read_port_and_nonce (const char *fname, unsigned short *port, char *nonce)
+{
+  FILE *fp;
+  char buffer[50], *p;
+  size_t nread;
+  int aval;
+
+  fp = fopen (fname, "rb");
+  if (!fp)
+    return -1;
+  nread = fread (buffer, 1, sizeof buffer - 1, fp);
+  fclose (fp);
+  if (!nread)
+    {
+      errno = ENOFILE;
+      return -1;
+    }
+  buffer[nread] = 0;
+  aval = atoi (buffer);
+  if (aval < 1 || aval > 65535)
+    {
+      errno = EINVAL;
+      return -1;
+    }
+  *port = (unsigned int)aval;
+  for (p=buffer; nread && *p != '\n'; p++, nread--)
+    ;
+  if (*p != '\n' || nread != 17)
+    {
+      errno = EINVAL;
+      return -1;
+    }
+  p++; nread--;
+  memcpy (nonce, p, 16);
+  return 0;
+}
+
+
+
 int
 _w32_close (int fd)
 {
@@ -53,97 +96,40 @@
 
 
 int
-_w32_sock_connect (int sockfd, struct sockaddr * addr, int addrlen)
+_w32_sock_connect (int sockfd, struct sockaddr *addr, int addrlen)
 {
   struct sockaddr_in myaddr;
-  struct sockaddr_un * unaddr;
-  FILE * fp;
-  int port;
-  
+  struct sockaddr_un *unaddr;
+  unsigned short port;
+  char nonce[16];
+  int ret;
+      
   unaddr = (struct sockaddr_un *)addr;
-  fp = fopen (unaddr->sun_path, "rb");
-  if (!fp)
+  if (read_port_and_nonce (unaddr->sun_path, &port, nonce))
     return -1;
-  fscanf (fp, "%d", &port);
-  fclose (fp);
-
-  if (port < 0 || port > 65535)
-    {
-      errno = EINVAL;
-      return -1;
-    }
-  
+      
   myaddr.sin_family = AF_INET;
-  myaddr.sin_port = port; 
+  myaddr.sin_port = htons (port); 
   myaddr.sin_addr.s_addr = htonl (INADDR_LOOPBACK);
-
-  /* we need this later. */
+  
+  /* Set return values.  */
   unaddr->sun_family = myaddr.sin_family;
   unaddr->sun_port = myaddr.sin_port;
   unaddr->sun_addr.s_addr = myaddr.sin_addr.s_addr;
   
-  return connect (sockfd, (struct sockaddr *)&myaddr, sizeof myaddr);
-}
-
-
-int
-_w32_sock_bind (int sockfd, struct sockaddr *addr, int addrlen)
-{
-  if (addr->sa_family == AF_LOCAL || addr->sa_family == AF_UNIX)
+  ret = connect (sockfd, (struct sockaddr *)&myaddr, sizeof myaddr);
+  if (!ret)
     {
-      struct sockaddr_in myaddr;
-      struct sockaddr_un *unaddr;
-      int filefd;
-      FILE *fp;
-      int len = sizeof myaddr;
-      int rc;
-
-      unaddr = (struct sockaddr_un *)addr;
-
-      myaddr.sin_port = 0;
-      myaddr.sin_family = AF_INET;
-      myaddr.sin_addr.s_addr = htonl (INADDR_LOOPBACK);
-
-      filefd = open (unaddr->sun_path, 
-                     (O_WRONLY|O_CREAT|O_EXCL|O_BINARY), 
-                     (S_IRUSR|S_IWUSR|S_IRGRP|S_IWGRP));
-      if (filefd == -1)
+      /* Send the nonce. */
+      ret = send (sockfd, nonce, 16, 0);
+      if (ret >= 0 && ret != 16)
         {
-          if (errno == EEXIST)
-            errno = WSAEADDRINUSE;
-          return -1;
+          errno = EIO;
+          ret = -1;
         }
-      fp = fdopen (filefd, "wb");
-      if (!fp)
-        { 
-          int save_e = errno;
-          close (filefd);
-          errno = save_e;
-          return -1;
-        }
-
-      rc = bind (sockfd, (struct sockaddr *)&myaddr, len);
-      if (!rc)
-        rc = getsockname (sockfd, (struct sockaddr *)&myaddr, &len);
-      if (rc)
-        {
-          int save_e = errno;
-          fclose (fp);
-          remove (unaddr->sun_path);
-          errno = save_e;
-          return rc;
-        }
-      fprintf (fp, "%d", myaddr.sin_port);
-      fclose (fp);
-
-      /* The caller expects these values. */
-      unaddr->sun_family = myaddr.sin_family;
-      unaddr->sun_port = myaddr.sin_port;
-      unaddr->sun_addr.s_addr = myaddr.sin_addr.s_addr;
-      
-      return 0;
     }
-  return bind (sockfd, addr, addrlen);
+  return ret;
 }
 
+
 #endif /*_WIN32*/

Modified: trunk/jnlib/w32-afunix.h
===================================================================
--- trunk/jnlib/w32-afunix.h	2007-09-18 11:40:09 UTC (rev 4586)
+++ trunk/jnlib/w32-afunix.h	2007-10-01 14:48:39 UTC (rev 4587)
@@ -39,10 +39,11 @@
   char           sun_path[108-2-4]; /* Path name.  */
 };
 
+
 int _w32_close (int fd);
 int _w32_sock_new (int domain, int type, int proto);
-int _w32_sock_bind (int sockfd, struct sockaddr *addr, int addrlen);
 int _w32_sock_connect (int sockfd, struct sockaddr *addr, int addrlen);
 
+
 #endif /*W32AFUNIX_DEFS_H*/
 #endif /*_WIN32*/

Modified: trunk/po/be.po
===================================================================
--- trunk/po/be.po	2007-09-18 11:40:09 UTC (rev 4586)
+++ trunk/po/be.po	2007-10-01 14:48:39 UTC (rev 4587)
@@ -6,7 +6,7 @@
 msgstr ""
 "Project-Id-Version: gnupg 1.2.2\n"
 "Report-Msgid-Bugs-To: translations at gnupg.org\n"
-"POT-Creation-Date: 2007-09-10 17:28+0200\n"
+"POT-Creation-Date: 2007-09-14 13:27+0200\n"
 "PO-Revision-Date: 2003-10-30 16:35+0200\n"
 "Last-Translator: Ales Nyakhaychyk <nab at mail.by>\n"
 "Language-Team: Belarusian <i18n at mova.org>\n"
@@ -7509,6 +7509,10 @@
 msgid "Configuration for Keyservers"
 msgstr ""
 
+#: tools/gpgconf-comp.c:673
+msgid "|URL|use keyserver at URL"
+msgstr ""
+
 #: tools/gpgconf-comp.c:676
 msgid "allow PKA lookups (DNS requests)"
 msgstr ""

Modified: trunk/po/ca.po
===================================================================
--- trunk/po/ca.po	2007-09-18 11:40:09 UTC (rev 4586)
+++ trunk/po/ca.po	2007-10-01 14:48:39 UTC (rev 4587)
@@ -27,7 +27,7 @@
 msgstr ""
 "Project-Id-Version: gnupg 1.4.0\n"
 "Report-Msgid-Bugs-To: translations at gnupg.org\n"
-"POT-Creation-Date: 2007-09-10 17:28+0200\n"
+"POT-Creation-Date: 2007-09-14 13:27+0200\n"
 "PO-Revision-Date: 2005-02-04 02:04+0100\n"
 "Last-Translator: Jordi Mallach <jordi at gnu.org>\n"
 "Language-Team: Catalan <ca at dodds.net>\n"
@@ -8097,6 +8097,11 @@
 msgid "Configuration for Keyservers"
 msgstr ""
 
+#: tools/gpgconf-comp.c:673
+#, fuzzy
+msgid "|URL|use keyserver at URL"
+msgstr "no s'ha pogut analitzar sintàcticament la URI del servidor de claus\n"
+
 #: tools/gpgconf-comp.c:676
 msgid "allow PKA lookups (DNS requests)"
 msgstr ""

Modified: trunk/po/cs.po
===================================================================
--- trunk/po/cs.po	2007-09-18 11:40:09 UTC (rev 4586)
+++ trunk/po/cs.po	2007-10-01 14:48:39 UTC (rev 4587)
@@ -7,7 +7,7 @@
 msgstr ""
 "Project-Id-Version: gnupg-1.3.92\n"
 "Report-Msgid-Bugs-To: translations at gnupg.org\n"
-"POT-Creation-Date: 2007-09-10 17:28+0200\n"
+"POT-Creation-Date: 2007-09-14 13:27+0200\n"
 "PO-Revision-Date: 2004-11-26 09:12+0200\n"
 "Last-Translator: Roman Pavlik <rp at tns.cz>\n"
 "Language-Team: Czech <translations.cs at gnupg.cz>\n"
@@ -7779,6 +7779,11 @@
 msgid "Configuration for Keyservers"
 msgstr ""
 
+#: tools/gpgconf-comp.c:673
+#, fuzzy
+msgid "|URL|use keyserver at URL"
+msgstr "nelze zpracovat URL serveru klíèù\n"
+
 #: tools/gpgconf-comp.c:676
 msgid "allow PKA lookups (DNS requests)"
 msgstr ""

Modified: trunk/po/da.po
===================================================================
--- trunk/po/da.po	2007-09-18 11:40:09 UTC (rev 4586)
+++ trunk/po/da.po	2007-10-01 14:48:39 UTC (rev 4587)
@@ -8,7 +8,7 @@
 msgstr ""
 "Project-Id-Version: gnupg 1.0.0h\n"
 "Report-Msgid-Bugs-To: translations at gnupg.org\n"
-"POT-Creation-Date: 2007-09-10 17:28+0200\n"
+"POT-Creation-Date: 2007-09-14 13:27+0200\n"
 "PO-Revision-Date: 2003-12-03 16:11+0100\n"
 "Last-Translator: Birger Langkjer <birger.langkjer at image.dk>\n"
 "Language-Team: Danish <dansk at klid.dk>\n"
@@ -7663,6 +7663,11 @@
 msgid "Configuration for Keyservers"
 msgstr ""
 
+#: tools/gpgconf-comp.c:673
+#, fuzzy
+msgid "|URL|use keyserver at URL"
+msgstr "importér nøgler fra en nøgleserver: %s\n"
+
 #: tools/gpgconf-comp.c:676
 msgid "allow PKA lookups (DNS requests)"
 msgstr ""

Modified: trunk/po/el.po
===================================================================
--- trunk/po/el.po	2007-09-18 11:40:09 UTC (rev 4586)
+++ trunk/po/el.po	2007-10-01 14:48:39 UTC (rev 4587)
@@ -6,7 +6,7 @@
 msgstr ""
 "Project-Id-Version: gnupg-1.1.92\n"
 "Report-Msgid-Bugs-To: translations at gnupg.org\n"
-"POT-Creation-Date: 2007-09-10 17:28+0200\n"
+"POT-Creation-Date: 2007-09-14 13:27+0200\n"
 "PO-Revision-Date: 2003-06-27 12:00+0200\n"
 "Last-Translator: Dokianakis Theofanis <madf at hellug.gr>\n"
 "Language-Team: Greek <nls at tux.hellug.gr>\n"
@@ -7951,6 +7951,11 @@
 msgid "Configuration for Keyservers"
 msgstr ""
 
+#: tools/gpgconf-comp.c:673
+#, fuzzy
+msgid "|URL|use keyserver at URL"
+msgstr "áäõíáìßá åðåîåñãáóßáò ôïõ URI ôïõ äéáêïìéóç êëåéäéþí\n"
+
 #: tools/gpgconf-comp.c:676
 msgid "allow PKA lookups (DNS requests)"
 msgstr ""

Modified: trunk/po/eo.po
===================================================================
--- trunk/po/eo.po	2007-09-18 11:40:09 UTC (rev 4586)
+++ trunk/po/eo.po	2007-10-01 14:48:39 UTC (rev 4587)
@@ -6,7 +6,7 @@
 msgstr ""
 "Project-Id-Version: gnupg 1.0.6d\n"
 "Report-Msgid-Bugs-To: translations at gnupg.org\n"
-"POT-Creation-Date: 2007-09-10 17:28+0200\n"
+"POT-Creation-Date: 2007-09-14 13:27+0200\n"
 "PO-Revision-Date: 2002-04-14 14:33+0100\n"
 "Last-Translator: Edmund GRIMLEY EVANS <edmundo at rano.org>\n"
 "Language-Team: Esperanto <translation-team-eo at lists.sourceforge.net>\n"
@@ -7897,6 +7897,11 @@
 msgid "Configuration for Keyservers"
 msgstr ""
 
+#: tools/gpgconf-comp.c:673
+#, fuzzy
+msgid "|URL|use keyserver at URL"
+msgstr "ne povis analizi URI de þlosilservilo\n"
+
 #: tools/gpgconf-comp.c:676
 msgid "allow PKA lookups (DNS requests)"
 msgstr ""

Modified: trunk/po/es.po
===================================================================
--- trunk/po/es.po	2007-09-18 11:40:09 UTC (rev 4586)
+++ trunk/po/es.po	2007-10-01 14:48:39 UTC (rev 4587)
@@ -10,7 +10,7 @@
 msgstr ""
 "Project-Id-Version: gnupg 1.4.1\n"
 "Report-Msgid-Bugs-To: translations at gnupg.org\n"
-"POT-Creation-Date: 2007-09-10 17:28+0200\n"
+"POT-Creation-Date: 2007-09-14 13:27+0200\n"
 "PO-Revision-Date: 2007-08-16 11:35+0200\n"
 "Last-Translator: Jaime Suárez <jsuarez at ono.com>\n"
 "Language-Team: Spanish <es at li.org>\n"
@@ -7825,6 +7825,11 @@
 msgid "Configuration for Keyservers"
 msgstr ""
 
+#: tools/gpgconf-comp.c:673
+#, fuzzy
+msgid "|URL|use keyserver at URL"
+msgstr "no se puede interpretar la URL del servidor de claves\n"
+
 #: tools/gpgconf-comp.c:676
 msgid "allow PKA lookups (DNS requests)"
 msgstr ""

Modified: trunk/po/et.po
===================================================================
--- trunk/po/et.po	2007-09-18 11:40:09 UTC (rev 4586)
+++ trunk/po/et.po	2007-10-01 14:48:39 UTC (rev 4587)
@@ -6,7 +6,7 @@
 msgstr ""
 "Project-Id-Version: gnupg 1.2.2\n"
 "Report-Msgid-Bugs-To: translations at gnupg.org\n"
-"POT-Creation-Date: 2007-09-10 17:28+0200\n"
+"POT-Creation-Date: 2007-09-14 13:27+0200\n"
 "PO-Revision-Date: 2004-06-17 11:04+0300\n"
 "Last-Translator: Toomas Soome <Toomas.Soome at microlink.ee>\n"
 "Language-Team: Estonian <et at li.org>\n"
@@ -7856,6 +7856,11 @@
 msgid "Configuration for Keyservers"
 msgstr ""
 
+#: tools/gpgconf-comp.c:673
+#, fuzzy
+msgid "|URL|use keyserver at URL"
+msgstr "ei saa parsida võtmeserveri URI\n"
+
 #: tools/gpgconf-comp.c:676
 msgid "allow PKA lookups (DNS requests)"
 msgstr ""

Modified: trunk/po/fi.po
===================================================================
--- trunk/po/fi.po	2007-09-18 11:40:09 UTC (rev 4586)
+++ trunk/po/fi.po	2007-10-01 14:48:39 UTC (rev 4587)
@@ -22,7 +22,7 @@
 msgstr ""
 "Project-Id-Version: gnupg 1.2.2\n"
 "Report-Msgid-Bugs-To: translations at gnupg.org\n"
-"POT-Creation-Date: 2007-09-10 17:28+0200\n"
+"POT-Creation-Date: 2007-09-14 13:27+0200\n"
 "PO-Revision-Date: 2004-06-16 22:40+0300\n"
 "Last-Translator: Tommi Vainikainen <Tommi.Vainikainen at iki.fi>\n"
 "Language-Team: Finnish <translation-team-fi at lists.sourceforge.net>\n"
@@ -7935,6 +7935,11 @@
 msgid "Configuration for Keyservers"
 msgstr ""
 
+#: tools/gpgconf-comp.c:673
+#, fuzzy
+msgid "|URL|use keyserver at URL"
+msgstr "avainpalvelimen URI:iä ei voi jäsentää\n"
+
 #: tools/gpgconf-comp.c:676
 msgid "allow PKA lookups (DNS requests)"
 msgstr ""

Modified: trunk/po/fr.po
===================================================================
--- trunk/po/fr.po	2007-09-18 11:40:09 UTC (rev 4586)
+++ trunk/po/fr.po	2007-10-01 14:48:39 UTC (rev 4587)
@@ -11,7 +11,7 @@
 msgstr ""
 "Project-Id-Version: gnupg 1.4.2rc2\n"
 "Report-Msgid-Bugs-To: translations at gnupg.org\n"
-"POT-Creation-Date: 2007-09-10 17:28+0200\n"
+"POT-Creation-Date: 2007-09-14 13:27+0200\n"
 "PO-Revision-Date: 2005-06-28 00:24+0200\n"
 "Last-Translator: Gaël Quéri <gael at lautre.net>\n"
 "Language-Team: French <traduc at traduc.org>\n"
@@ -7983,6 +7983,11 @@
 msgid "Configuration for Keyservers"
 msgstr ""
 
+#: tools/gpgconf-comp.c:673
+#, fuzzy
+msgid "|URL|use keyserver at URL"
+msgstr "impossible d'interpréter l'URL du serveur de clés\n"
+
 #: tools/gpgconf-comp.c:676
 msgid "allow PKA lookups (DNS requests)"
 msgstr ""

Modified: trunk/po/gl.po
===================================================================
--- trunk/po/gl.po	2007-09-18 11:40:09 UTC (rev 4586)
+++ trunk/po/gl.po	2007-10-01 14:48:39 UTC (rev 4587)
@@ -6,7 +6,7 @@
 msgstr ""
 "Project-Id-Version: gnupg 1.2.4\n"
 "Report-Msgid-Bugs-To: translations at gnupg.org\n"
-"POT-Creation-Date: 2007-09-10 17:28+0200\n"
+"POT-Creation-Date: 2007-09-14 13:27+0200\n"
 "PO-Revision-Date: 2003-12-04 11:39+0100\n"
 "Last-Translator: Jacobo Tarrio <jtarrio at trasno.net>\n"
 "Language-Team: Galician <gpul-traduccion at ceu.fi.udc.es>\n"
@@ -7946,6 +7946,11 @@
 msgid "Configuration for Keyservers"
 msgstr ""
 
+#: tools/gpgconf-comp.c:673
+#, fuzzy
+msgid "|URL|use keyserver at URL"
+msgstr "non se puido analisa-lo URI do servidor de chaves\n"
+
 #: tools/gpgconf-comp.c:676
 msgid "allow PKA lookups (DNS requests)"
 msgstr ""

Modified: trunk/po/hu.po
===================================================================
--- trunk/po/hu.po	2007-09-18 11:40:09 UTC (rev 4586)
+++ trunk/po/hu.po	2007-10-01 14:48:39 UTC (rev 4587)
@@ -6,7 +6,7 @@
 msgstr ""
 "Project-Id-Version: gnupg 1.2.5\n"
 "Report-Msgid-Bugs-To: translations at gnupg.org\n"
-"POT-Creation-Date: 2007-09-10 17:28+0200\n"
+"POT-Creation-Date: 2007-09-14 13:27+0200\n"
 "PO-Revision-Date: 2004-06-19 21:53+0200\n"
 "Last-Translator: Nagy Ferenc László <nfl at nfllab.com>\n"
 "Language-Team: Hungarian <translation-team-hu at lists.sourceforge.net>\n"
@@ -7897,6 +7897,11 @@
 msgid "Configuration for Keyservers"
 msgstr ""
 
+#: tools/gpgconf-comp.c:673
+#, fuzzy
+msgid "|URL|use keyserver at URL"
+msgstr "Értelmezhetetlen a kulcsszerver URI-ja!\n"
+
 #: tools/gpgconf-comp.c:676
 msgid "allow PKA lookups (DNS requests)"
 msgstr ""

Modified: trunk/po/id.po
===================================================================
--- trunk/po/id.po	2007-09-18 11:40:09 UTC (rev 4586)
+++ trunk/po/id.po	2007-10-01 14:48:39 UTC (rev 4587)
@@ -7,7 +7,7 @@
 msgstr ""
 "Project-Id-Version: gnupg-id\n"
 "Report-Msgid-Bugs-To: translations at gnupg.org\n"
-"POT-Creation-Date: 2007-09-10 17:28+0200\n"
+"POT-Creation-Date: 2007-09-14 13:27+0200\n"
 "PO-Revision-Date: 2004-06-17 16:32+0700\n"
 "Last-Translator: Tedi Heriyanto <tedi_h at gmx.net>\n"
 "Language-Team: Indonesian <translation-team-id at lists.sourceforge.net>\n"
@@ -7899,6 +7899,11 @@
 msgid "Configuration for Keyservers"
 msgstr ""
 
+#: tools/gpgconf-comp.c:673
+#, fuzzy
+msgid "|URL|use keyserver at URL"
+msgstr "tidak dapat memparsing URI keyserver\n"
+
 #: tools/gpgconf-comp.c:676
 msgid "allow PKA lookups (DNS requests)"
 msgstr ""

Modified: trunk/po/it.po
===================================================================
--- trunk/po/it.po	2007-09-18 11:40:09 UTC (rev 4586)
+++ trunk/po/it.po	2007-10-01 14:48:39 UTC (rev 4587)
@@ -6,7 +6,7 @@
 msgstr ""
 "Project-Id-Version: gnupg 1.1.92\n"
 "Report-Msgid-Bugs-To: translations at gnupg.org\n"
-"POT-Creation-Date: 2007-09-10 17:28+0200\n"
+"POT-Creation-Date: 2007-09-14 13:27+0200\n"
 "PO-Revision-Date: 2004-06-16 17:01+0200\n"
 "Last-Translator: Marco d'Itri <md at linux.it>\n"
 "Language-Team: Italian <tp at lists.linux.it>\n"
@@ -7945,6 +7945,11 @@
 msgid "Configuration for Keyservers"
 msgstr ""
 
+#: tools/gpgconf-comp.c:673
+#, fuzzy
+msgid "|URL|use keyserver at URL"
+msgstr "impossibile fare il parsing dell'URI del keyserver\n"
+
 #: tools/gpgconf-comp.c:676
 msgid "allow PKA lookups (DNS requests)"
 msgstr ""

Modified: trunk/po/ja.po
===================================================================
--- trunk/po/ja.po	2007-09-18 11:40:09 UTC (rev 4586)
+++ trunk/po/ja.po	2007-10-01 14:48:39 UTC (rev 4587)
@@ -9,7 +9,7 @@
 msgstr ""
 "Project-Id-Version: gnupg 1.3.92\n"
 "Report-Msgid-Bugs-To: translations at gnupg.org\n"
-"POT-Creation-Date: 2007-09-10 17:28+0200\n"
+"POT-Creation-Date: 2007-09-14 13:27+0200\n"
 "PO-Revision-Date: 2004-11-23 11:14+0900\n"
 "Last-Translator: IIDA Yosiaki <iida at gnu.org>\n"
 "Language-Team: Japanese <translation-team-ja at lists.sourceforge.net>\n"
@@ -7713,6 +7713,11 @@
 msgid "Configuration for Keyservers"
 msgstr ""
 
+#: tools/gpgconf-comp.c:673
+#, fuzzy
+msgid "|URL|use keyserver at URL"
+msgstr "¸°¥µ¡¼¥Ð¡¼¤ÎURL¤ò²òÀÏÉÔǽ\n"
+
 #: tools/gpgconf-comp.c:676
 msgid "allow PKA lookups (DNS requests)"
 msgstr ""

Modified: trunk/po/nb.po
===================================================================
--- trunk/po/nb.po	2007-09-18 11:40:09 UTC (rev 4586)
+++ trunk/po/nb.po	2007-10-01 14:48:39 UTC (rev 4587)
@@ -10,7 +10,7 @@
 msgstr ""
 "Project-Id-Version: gnupg 1.4.3\n"
 "Report-Msgid-Bugs-To: translations at gnupg.org\n"
-"POT-Creation-Date: 2007-09-10 17:28+0200\n"
+"POT-Creation-Date: 2007-09-14 13:27+0200\n"
 "PO-Revision-Date: 2006-06-13 20:31+0200\n"
 "Last-Translator: Trond Endrestøl <Trond.Endrestol at fagskolen.gjovik.no>\n"
 "Language-Team: Norwegian Bokmål <i18n-nb at lister.ping.uio.no>\n"
@@ -7582,6 +7582,11 @@
 msgid "Configuration for Keyservers"
 msgstr ""
 
+#: tools/gpgconf-comp.c:673
+#, fuzzy
+msgid "|URL|use keyserver at URL"
+msgstr "kunne ikke parse nøkkelserverens URL\n"
+
 #: tools/gpgconf-comp.c:676
 msgid "allow PKA lookups (DNS requests)"
 msgstr ""

Modified: trunk/po/pl.po
===================================================================
--- trunk/po/pl.po	2007-09-18 11:40:09 UTC (rev 4586)
+++ trunk/po/pl.po	2007-10-01 14:48:39 UTC (rev 4587)
@@ -8,7 +8,7 @@
 msgstr ""
 "Project-Id-Version: gnupg-1.2.2\n"
 "Report-Msgid-Bugs-To: translations at gnupg.org\n"
-"POT-Creation-Date: 2007-09-10 17:28+0200\n"
+"POT-Creation-Date: 2007-09-14 13:27+0200\n"
 "PO-Revision-Date: 2004-06-23 15:54+0200\n"
 "Last-Translator: Janusz A. Urbanowicz <alex at bofh.net.pl>\n"
 "Language-Team: Polish <pl at li.org>\n"
@@ -7942,6 +7942,11 @@
 msgid "Configuration for Keyservers"
 msgstr ""
 
+#: tools/gpgconf-comp.c:673
+#, fuzzy
+msgid "|URL|use keyserver at URL"
+msgstr "niezrozuma³y URI serwera kluczy\n"
+
 #: tools/gpgconf-comp.c:676
 msgid "allow PKA lookups (DNS requests)"
 msgstr ""

Modified: trunk/po/pt.po
===================================================================
--- trunk/po/pt.po	2007-09-18 11:40:09 UTC (rev 4586)
+++ trunk/po/pt.po	2007-10-01 14:48:39 UTC (rev 4587)
@@ -9,7 +9,7 @@
 msgstr ""
 "Project-Id-Version: gnupg\n"
 "Report-Msgid-Bugs-To: translations at gnupg.org\n"
-"POT-Creation-Date: 2007-09-10 17:28+0200\n"
+"POT-Creation-Date: 2007-09-14 13:27+0200\n"
 "PO-Revision-Date: 2002-09-13 18:26+0100\n"
 "Last-Translator: Pedro Morais <morais at kde.org>\n"
 "Language-Team: pt <morais at kde.org>\n"
@@ -7911,6 +7911,11 @@
 msgid "Configuration for Keyservers"
 msgstr ""
 
+#: tools/gpgconf-comp.c:673
+#, fuzzy
+msgid "|URL|use keyserver at URL"
+msgstr "não consegui processar a URI do servidor de chaves\n"
+
 #: tools/gpgconf-comp.c:676
 msgid "allow PKA lookups (DNS requests)"
 msgstr ""

Modified: trunk/po/pt_BR.po
===================================================================
--- trunk/po/pt_BR.po	2007-09-18 11:40:09 UTC (rev 4586)
+++ trunk/po/pt_BR.po	2007-10-01 14:48:39 UTC (rev 4587)
@@ -13,7 +13,7 @@
 msgstr ""
 "Project-Id-Version: gnupg 1.0\n"
 "Report-Msgid-Bugs-To: translations at gnupg.org\n"
-"POT-Creation-Date: 2007-09-10 17:28+0200\n"
+"POT-Creation-Date: 2007-09-14 13:27+0200\n"
 "PO-Revision-Date: 2007-08-16 11:35+0200\n"
 "Last-Translator:\n"
 "Language-Team: ?\n"
@@ -7863,6 +7863,11 @@
 msgid "Configuration for Keyservers"
 msgstr ""
 
+#: tools/gpgconf-comp.c:673
+#, fuzzy
+msgid "|URL|use keyserver at URL"
+msgstr "impossível escrever para o chaveiro: %s\n"
+
 #: tools/gpgconf-comp.c:676
 msgid "allow PKA lookups (DNS requests)"
 msgstr ""

Modified: trunk/po/ro.po
===================================================================
--- trunk/po/ro.po	2007-09-18 11:40:09 UTC (rev 4586)
+++ trunk/po/ro.po	2007-10-01 14:48:39 UTC (rev 4587)
@@ -9,7 +9,7 @@
 msgstr ""
 "Project-Id-Version: gnupg 1.4.2rc1\n"
 "Report-Msgid-Bugs-To: translations at gnupg.org\n"
-"POT-Creation-Date: 2007-09-10 17:28+0200\n"
+"POT-Creation-Date: 2007-09-14 13:27+0200\n"
 "PO-Revision-Date: 2005-05-31 22:00-0500\n"
 "Last-Translator: Laurentiu Buzdugan <lbuz at rolix.org>\n"
 "Language-Team: Romanian <translation-team-ro at lists.sourceforge.net>\n"
@@ -7806,6 +7806,12 @@
 msgid "Configuration for Keyservers"
 msgstr ""
 
+#
+#: tools/gpgconf-comp.c:673
+#, fuzzy
+msgid "|URL|use keyserver at URL"
+msgstr "nu am putut interpreta URL-ul serverului de chei\n"
+
 #: tools/gpgconf-comp.c:676
 msgid "allow PKA lookups (DNS requests)"
 msgstr ""

Modified: trunk/po/ru.po
===================================================================
--- trunk/po/ru.po	2007-09-18 11:40:09 UTC (rev 4586)
+++ trunk/po/ru.po	2007-10-01 14:48:39 UTC (rev 4587)
@@ -8,7 +8,7 @@
 msgstr ""
 "Project-Id-Version: GnuPG 2.0.0\n"
 "Report-Msgid-Bugs-To: translations at gnupg.org\n"
-"POT-Creation-Date: 2007-09-10 17:28+0200\n"
+"POT-Creation-Date: 2007-09-14 13:27+0200\n"
 "PO-Revision-Date: 2006-11-07 19:31+0300\n"
 "Last-Translator: Maxim Britov <maxim.britov at gmail.com>\n"
 "Language-Team: Russian <gnupg-ru at gnupg.org>\n"
@@ -7667,6 +7667,11 @@
 msgid "Configuration for Keyservers"
 msgstr "Конфигурация серверов ключей"
 
+#: tools/gpgconf-comp.c:673
+#, fuzzy
+msgid "|URL|use keyserver at URL"
+msgstr "не могу проанализировать URL сервера ключей\n"
+
 #: tools/gpgconf-comp.c:676
 msgid "allow PKA lookups (DNS requests)"
 msgstr ""

Modified: trunk/po/sk.po
===================================================================
--- trunk/po/sk.po	2007-09-18 11:40:09 UTC (rev 4586)
+++ trunk/po/sk.po	2007-10-01 14:48:39 UTC (rev 4587)
@@ -5,7 +5,7 @@
 msgstr ""
 "Project-Id-Version: gnupg 1.2.5\n"
 "Report-Msgid-Bugs-To: translations at gnupg.org\n"
-"POT-Creation-Date: 2007-09-10 17:28+0200\n"
+"POT-Creation-Date: 2007-09-14 13:27+0200\n"
 "PO-Revision-Date: 2004-07-20 15:52+0200\n"
 "Last-Translator: Michal Majer <mmajer at econ.umb.sk>\n"
 "Language-Team: Slovak <sk-i18n at lists.linux.sk>\n"
@@ -7917,6 +7917,11 @@
 msgid "Configuration for Keyservers"
 msgstr ""
 
+#: tools/gpgconf-comp.c:673
+#, fuzzy
+msgid "|URL|use keyserver at URL"
+msgstr "nemo¾no pou¾i» URI servera kµúèov - chyba analýzy URI\n"
+
 #: tools/gpgconf-comp.c:676
 msgid "allow PKA lookups (DNS requests)"
 msgstr ""

Modified: trunk/po/sv.po
===================================================================
--- trunk/po/sv.po	2007-09-18 11:40:09 UTC (rev 4586)
+++ trunk/po/sv.po	2007-10-01 14:48:39 UTC (rev 4587)
@@ -24,7 +24,7 @@
 msgstr ""
 "Project-Id-Version: gnupg 2.0\n"
 "Report-Msgid-Bugs-To: translations at gnupg.org\n"
-"POT-Creation-Date: 2007-09-10 17:28+0200\n"
+"POT-Creation-Date: 2007-09-14 13:27+0200\n"
 "PO-Revision-Date: 2007-02-17 13:13+0100\n"
 "Last-Translator: Daniel Nylander <po at danielnylander.se>\n"
 "Language-Team: Swedish <tp-sv at listor.tp-sv.se>\n"
@@ -7880,6 +7880,11 @@
 msgid "Configuration for Keyservers"
 msgstr "Konfiguration för nyckelservrar"
 
+#: tools/gpgconf-comp.c:673
+#, fuzzy
+msgid "|URL|use keyserver at URL"
+msgstr "kunde inte tolka url till nyckelserver\n"
+
 #: tools/gpgconf-comp.c:676
 msgid "allow PKA lookups (DNS requests)"
 msgstr "tillåt PKA-uppslag (DNS-förfrågningar)"

Modified: trunk/po/tr.po
===================================================================
--- trunk/po/tr.po	2007-09-18 11:40:09 UTC (rev 4586)
+++ trunk/po/tr.po	2007-10-01 14:48:39 UTC (rev 4587)
@@ -6,7 +6,7 @@
 msgstr ""
 "Project-Id-Version: gnupg 1.9.94\n"
 "Report-Msgid-Bugs-To: translations at gnupg.org\n"
-"POT-Creation-Date: 2007-09-10 17:28+0200\n"
+"POT-Creation-Date: 2007-09-14 13:27+0200\n"
 "PO-Revision-Date: 2006-11-04 03:45+0200\n"
 "Last-Translator: Nilgün Belma Bugüner <nilgun at belgeler.gen.tr>\n"
 "Language-Team: Turkish <gnu-tr-u12a at lists.sourceforge.net>\n"
@@ -7755,6 +7755,11 @@
 msgid "Configuration for Keyservers"
 msgstr "Anahtar sunucular için yapılandırma"
 
+#: tools/gpgconf-comp.c:673
+#, fuzzy
+msgid "|URL|use keyserver at URL"
+msgstr "anahtar sunucusunun adresi çözümlenemedi\n"
+
 #: tools/gpgconf-comp.c:676
 msgid "allow PKA lookups (DNS requests)"
 msgstr "PKA aramalarına izin verilir (DNS istekleri)"

Modified: trunk/po/zh_CN.po
===================================================================
--- trunk/po/zh_CN.po	2007-09-18 11:40:09 UTC (rev 4586)
+++ trunk/po/zh_CN.po	2007-10-01 14:48:39 UTC (rev 4587)
@@ -7,7 +7,7 @@
 msgstr ""
 "Project-Id-Version: gnupg 1.4.4\n"
 "Report-Msgid-Bugs-To: translations at gnupg.org\n"
-"POT-Creation-Date: 2007-09-10 17:28+0200\n"
+"POT-Creation-Date: 2007-09-14 13:27+0200\n"
 "PO-Revision-Date: 2006-07-02 10:58+0800\n"
 "Last-Translator: Meng Jie <zuxyhere at eastday.com>\n"
 "Language-Team: Chinese (simplified) <i18n-translation at lists.linux.net.cn>\n"
@@ -7615,6 +7615,11 @@
 msgid "Configuration for Keyservers"
 msgstr ""
 
+#: tools/gpgconf-comp.c:673
+#, fuzzy
+msgid "|URL|use keyserver at URL"
+msgstr "无法解析公钥服务器 URL\n"
+
 #: tools/gpgconf-comp.c:676
 msgid "allow PKA lookups (DNS requests)"
 msgstr ""

Modified: trunk/po/zh_TW.po
===================================================================
--- trunk/po/zh_TW.po	2007-09-18 11:40:09 UTC (rev 4586)
+++ trunk/po/zh_TW.po	2007-10-01 14:48:39 UTC (rev 4587)
@@ -9,7 +9,7 @@
 msgstr ""
 "Project-Id-Version: gnupg 1.4.2\n"
 "Report-Msgid-Bugs-To: translations at gnupg.org\n"
-"POT-Creation-Date: 2007-09-10 17:28+0200\n"
+"POT-Creation-Date: 2007-09-14 13:27+0200\n"
 "PO-Revision-Date: 2005-07-29 09:49+0800\n"
 "Last-Translator: Jedi <Jedi at Jedi.org>\n"
 "Language-Team: Chinese (traditional) <zh-l10n at linux.org.tw>\n"
@@ -7655,6 +7655,11 @@
 msgid "Configuration for Keyservers"
 msgstr ""
 
+#: tools/gpgconf-comp.c:673
+#, fuzzy
+msgid "|URL|use keyserver at URL"
+msgstr "無法剖析金鑰伺服器 URI\n"
+
 #: tools/gpgconf-comp.c:676
 msgid "allow PKA lookups (DNS requests)"
 msgstr ""

Modified: trunk/scd/ChangeLog
===================================================================
--- trunk/scd/ChangeLog	2007-09-18 11:40:09 UTC (rev 4586)
+++ trunk/scd/ChangeLog	2007-10-01 14:48:39 UTC (rev 4587)
@@ -1,3 +1,10 @@
+2007-10-01  Werner Koch  <wk at g10code.com>
+
+	* scdaemon.c (create_server_socket): Use Assuan socket wrappers
+	and remove Windows specific code.
+	(socket_nonce): New.
+	(start_connection_thread): Check nonce.
+
 2007-09-14  Marcus Brinkmann  <marcus at g10code.de>
 
 	* scdaemon.c (main): New variable STANDARD_SOCKET, which is 1 for

Modified: trunk/scd/scdaemon.c
===================================================================
--- trunk/scd/scdaemon.c	2007-09-18 11:40:09 UTC (rev 4586)
+++ trunk/scd/scdaemon.c	2007-10-01 14:48:39 UTC (rev 4587)
@@ -47,9 +47,6 @@
 #include "i18n.h"
 #include "sysutils.h"
 #include "app-common.h"
-#ifdef HAVE_W32_SYSTEM
-#include "../jnlib/w32-afunix.h"
-#endif
 #include "ccid-driver.h"
 #include "mkdtemp.h"
 #include "gc-opt-flags.h"
@@ -170,6 +167,9 @@
 /* Name of the communication socket */
 static char *socket_name;
 
+/* We need to keep track of the server's nonces (these are dummies for
+   POSIX systems). */
+static assuan_sock_nonce_t socket_nonce;
 
 /* Debug flag to disable the ticker.  The ticker is in fact not
    disabled but it won't perform any ticker specific actions. */
@@ -179,7 +179,8 @@
 
 static char *create_socket_name (int use_standard_socket,
                                  char *standard_name, char *template);
-static int create_server_socket (int is_standard_name, const char *name);
+static gnupg_fd_t create_server_socket (int is_standard_name, const char *name,
+                                        assuan_sock_nonce_t *nonce);
 
 static void *start_connection_thread (void *arg);
 static void handle_connections (int listen_fd);
@@ -631,7 +632,7 @@
                                             "S.scdaemon",
                                             "/tmp/gpg-XXXXXX/S.scdaemon");
           
-          fd = create_server_socket (0, socket_name);
+          fd = FD2INT(create_server_socket (0, socket_name, &socket_nonce));
         }
 
       tattr = pth_attr_new();
@@ -646,7 +647,7 @@
                      strerror (errno) );
           scd_exit (2);
         }
-      ctrl->thread_startup.fd = -1;
+      ctrl->thread_startup.fd = GNUPG_INVALID_FD;
       if ( !pth_spawn (tattr, start_connection_thread, ctrl) )
         {
           log_error ("error spawning pipe connection handler: %s\n",
@@ -667,15 +668,17 @@
   else
     { /* Regular server mode */
       int fd;
+#ifndef HAVE_W32_SYSTEM
       pid_t pid;
       int i;
+#endif
 
       /* Create the socket.  */
       socket_name = create_socket_name (standard_socket,
                                         "S.scdaemon",
                                         "/tmp/gpg-XXXXXX/S.scdaemon");
 
-      fd = create_server_socket (0, socket_name);
+      fd = FD2INT (create_server_socket (0, socket_name, &socket_nonce));
 
 
       fflush (NULL);
@@ -936,20 +939,17 @@
 /* Create a Unix domain socket with NAME.  IS_STANDARD_NAME indicates
    whether a non-random socket is used.  Returns the file descriptor
    or terminates the process in case of an error. */
-static int
-create_server_socket (int is_standard_name, const char *name)
+static gnupg_fd_t
+create_server_socket (int is_standard_name, const char *name,
+                      assuan_sock_nonce_t *nonce)
 {
   struct sockaddr_un *serv_addr;
   socklen_t len;
-  int fd;
+  gnupg_fd_t fd;
   int rc;
 
-#ifdef HAVE_W32_SYSTEM
-  fd = _w32_sock_new (AF_UNIX, SOCK_STREAM, 0);
-#else
-  fd = socket (AF_UNIX, SOCK_STREAM, 0);
-#endif
-  if (fd == -1)
+  fd = assuan_sock_new (AF_UNIX, SOCK_STREAM, 0);
+  if (fd == GNUPG_INVALID_FD)
     {
       log_error (_("can't create socket: %s\n"), strerror (errno));
       scd_exit (2);
@@ -963,33 +963,27 @@
   len = (offsetof (struct sockaddr_un, sun_path)
 	 + strlen (serv_addr->sun_path) + 1);
 
-#ifdef HAVE_W32_SYSTEM
-  rc = _w32_sock_bind (fd, (struct sockaddr*) serv_addr, len);
-  if (is_standard_name && rc == -1 )
-    {
-      remove (name);
-      rc = bind (fd, (struct sockaddr*) serv_addr, len);
-    }
-#else
-  rc = bind (fd, (struct sockaddr*) serv_addr, len);
+  rc = assuan_sock_bind (fd, (struct sockaddr*) serv_addr, len);
   if (is_standard_name && rc == -1 && errno == EADDRINUSE)
     {
       remove (name);
-      rc = bind (fd, (struct sockaddr*) serv_addr, len);
+      rc = assuan_sock_bind (fd, (struct sockaddr*) serv_addr, len);
     }
-#endif
-  if (rc == -1)
+  if (rc != -1 
+      && (rc=assuan_sock_get_nonce ((struct sockaddr*)serv_addr, len, nonce)))
+    log_error (_("error getting nonce for the socket\n"));
+ if (rc == -1)
     {
       log_error (_("error binding socket to `%s': %s\n"),
 		 serv_addr->sun_path, strerror (errno));
-      close (fd);
+      assuan_sock_close (fd);
       scd_exit (2);
     }
 
-  if (listen (fd, 5 ) == -1)
+  if (listen (FD2INT(fd), 5 ) == -1)
     {
       log_error (_("listen() failed: %s\n"), strerror (errno));
-      close (fd);
+      assuan_sock_close (fd);
       scd_exit (2);
     }
           
@@ -1007,20 +1001,31 @@
 {
   ctrl_t ctrl = arg;
 
+  if (assuan_sock_check_nonce (ctrl->thread_startup.fd, &socket_nonce))
+    {
+      log_info (_("error reading nonce on fd %d: %s\n"), 
+                FD2INT(ctrl->thread_startup.fd), strerror (errno));
+      assuan_sock_close (ctrl->thread_startup.fd);
+      xfree (ctrl);
+      return NULL;
+    }
+
   scd_init_default_ctrl (ctrl);
   if (opt.verbose)
-    log_info (_("handler for fd %d started\n"), ctrl->thread_startup.fd);
+    log_info (_("handler for fd %d started\n"),
+              FD2INT(ctrl->thread_startup.fd));
 
-  scd_command_handler (ctrl, ctrl->thread_startup.fd);
+  scd_command_handler (ctrl, FD2INT(ctrl->thread_startup.fd));
 
   if (opt.verbose)
-    log_info (_("handler for fd %d terminated\n"), ctrl->thread_startup.fd);
+    log_info (_("handler for fd %d terminated\n"),
+              FD2INT (ctrl->thread_startup.fd));
 
   /* If this thread is the pipe connection thread, flag that a
      shutdown is required.  With the next ticker event and given that
      no other connections are running the shutdown will then
      happen. */
-  if (ctrl->thread_startup.fd == -1)
+  if (ctrl->thread_startup.fd == GNUPG_INVALID_FD)
     shutdown_pending = 1;
   
   scd_deinit_default_ctrl (ctrl);
@@ -1166,7 +1171,7 @@
               snprintf (threadname, sizeof threadname-1, "conn fd=%d", fd);
               threadname[sizeof threadname -1] = 0;
               pth_attr_set (tattr, PTH_ATTR_NAME, threadname);
-              ctrl->thread_startup.fd = fd;
+              ctrl->thread_startup.fd = INT2FD (fd);
               if (!pth_spawn (tattr, start_connection_thread, ctrl))
                 {
                   log_error ("error spawning connection handler: %s\n",

Modified: trunk/scd/scdaemon.h
===================================================================
--- trunk/scd/scdaemon.h	2007-09-18 11:40:09 UTC (rev 4586)
+++ trunk/scd/scdaemon.h	2007-10-01 14:48:39 UTC (rev 4587)
@@ -30,8 +30,8 @@
 #include <gcrypt.h>
 #include "../common/util.h"
 #include "../common/errors.h"
+#include "../common/sysutils.h"
 
-
 /* To convey some special hash algorithms we use algorithm numbers
    reserved for application use. */
 #ifndef GCRY_MD_USER
@@ -91,7 +91,7 @@
   /* Private data used to fire up the connection thread.  We use this
      structure do avoid an extra allocation for just a few bytes. */
   struct {
-    int fd;
+    gnupg_fd_t fd;
   } thread_startup;
   
   /* Local data of the server; used only in command.c. */

Modified: trunk/tools/ChangeLog
===================================================================
--- trunk/tools/ChangeLog	2007-09-18 11:40:09 UTC (rev 4586)
+++ trunk/tools/ChangeLog	2007-10-01 14:48:39 UTC (rev 4587)
@@ -1,3 +1,12 @@
+2007-10-01  Werner Koch  <wk at g10code.com>
+
+	* gpg-connect-agent.c (do_sendfd): Use INT2FD for assuan_sendfd.
+
+2007-09-26  Werner Koch  <wk at g10code.com>
+
+	* gpg-connect-agent.c (main): Print the first response from the
+	server.
+
 2007-09-14  Werner Koch  <wk at g10code.com>
 
 	* gpgconf-comp.c: Make a string translatable.

Modified: trunk/tools/gpg-connect-agent.c
===================================================================
--- trunk/tools/gpg-connect-agent.c	2007-09-18 11:40:09 UTC (rev 4586)
+++ trunk/tools/gpg-connect-agent.c	2007-10-01 14:48:39 UTC (rev 4587)
@@ -29,9 +29,9 @@
 #include "i18n.h"
 #include "../common/util.h"
 #include "../common/asshelp.h"
+#include "../common/sysutils.h"
 
 
-
 /* Constants to identify the commands and options. */
 enum cmd_and_opt_values
   {
@@ -244,7 +244,7 @@
     log_error ("file `%s' opened in \"%s\" mode, fd=%d\n",
                name, mode, fd);
 
-  rc = assuan_sendfd (ctx, fd);
+  rc = assuan_sendfd (ctx, INT2FD (fd) );
   if (rc)
     log_error ("sednig  descriptor %d failed: %s\n", fd, gpg_strerror (rc));
   fclose (fp);
@@ -360,6 +360,16 @@
     }
   else
     ctx = start_agent ();
+
+  /* See whether there is a line pending from the server (in case
+     assuan did not run the initial handshaking).  */
+  if (assuan_pending_line (ctx))
+    {
+      rc = read_and_print_response (ctx);
+      if (rc)
+        log_info (_("receiving line failed: %s\n"), gpg_strerror (rc) );
+    }
+
   line = NULL;
   linesize = 0;
   for (;;)




More information about the Gnupg-commits mailing list