[svn] assuan - r268 - in trunk: doc src

svn author wk cvs at cvs.gnupg.org
Tue Oct 2 10:44:30 CEST 2007


Author: wk
Date: 2007-10-02 10:44:21 +0200 (Tue, 02 Oct 2007)
New Revision: 268

Modified:
   trunk/doc/assuan.texi
   trunk/src/ChangeLog
   trunk/src/assuan-defs.h
   trunk/src/assuan-io.c
   trunk/src/assuan-socket-server.c
   trunk/src/assuan-socket.c
   trunk/src/assuan.h
Log:
Add new API assuan_set_sock_nonce.
Fixed a blocking problem on Windows.


Modified: trunk/doc/assuan.texi
===================================================================
--- trunk/doc/assuan.texi	2007-10-01 14:44:46 UTC (rev 267)
+++ trunk/doc/assuan.texi	2007-10-02 08:44:21 UTC (rev 268)
@@ -920,6 +920,21 @@
 @end deftypefun
 
 @noindent
+On the Windows platform the following function needs to be called after
+assuan_init_socket_server_ext:
+
+ at deftypefun void assuan_set_sock_nonce ( @
+        @w{assuan_context_t @var{ctx}}, @
+        @w{assuan_sock_nonce_t *@var{nonce}})
+
+Save a copy of @var{nonce} in context @var{ctx}.  This should be used to
+register the server's nonce with a context established by
+assuan_init_socket_server.  It is actually only needed for Windows but
+it does not harm to use it on other systems as well.
+ at end deftypefun
+
+
+ at noindent
 After error checking, the implemented assuan commands are registered with
 the server.  
 
@@ -938,6 +953,7 @@
     @} 
 @end example
 
+
 @deftypefun assuan_error_t assuan_register_command (@w{assuan_context_t @var{ctx}}, @w{const char *@var{cmd_string}}, @w{int (*@var{handler}) (assuan_context_t, char *)})
 
 This registers the command named @var{cmd_string} with the Assuan
@@ -1642,7 +1658,7 @@
 from the client and compare it with the saved @var{nonce}.  If this
 function fails the server should immediatly drop the connection.  To
 keep the code readable this may also be used on POSIX system; it is a
-dummy function then.
+dummy function then.  See also @code{assuan_set_sock_nonce}.
 @end deftypefun
 
 

Modified: trunk/src/ChangeLog
===================================================================
--- trunk/src/ChangeLog	2007-10-01 14:44:46 UTC (rev 267)
+++ trunk/src/ChangeLog	2007-10-02 08:44:21 UTC (rev 268)
@@ -1,5 +1,16 @@
+2007-10-02  Werner Koch  <wk at g10code.com>
+
+	* assuan-io.c (_assuan_io_read) [W32]: Map WSAEWOULDBLOCK to EAGAIN.
+	* assuan-socket.c (_assuan_sock_check_nonce): N needs to be signed.
+
+	* assuan-defs.h (struct assuan_context_s): Add LISTEN_NONCE.
+	* assuan-socket-server.c (assuan_set_sock_nonce): New.
+	(accept_connection): Check the nonce.
+
 2007-10-01  Werner Koch  <wk at g10code.com>
 
+	* assuan.h (ASSUAN_INT2FD, ASSUAN_FD2INT): New.
+
 	* assuan-socket.c: Rewritten.
 	(assuan_sock_new, assuan_sock_connect, assuan_sock_bind) 
 	(assuan_sock_get_nonce, assuan_sock_check_nonce): New APIs.

Modified: trunk/src/assuan-defs.h
===================================================================
--- trunk/src/assuan-defs.h	2007-10-01 14:44:46 UTC (rev 267)
+++ trunk/src/assuan-defs.h	2007-10-02 08:44:21 UTC (rev 268)
@@ -136,6 +136,7 @@
   pid_t pid;	  /* The pid of the peer. */
   assuan_fd_t listen_fd;  /* The fd we are listening on (used by
                              socket servers) */
+  assuan_sock_nonce_t listen_nonce; /* Used with LISTEN_FD.  */
   assuan_fd_t connected_fd; /* helper */
 
   struct {
@@ -186,8 +187,8 @@
   /* If set, this is called right before logging an I/O line.  With
      DIRECTION set to 1 it is called for an output oeration; 0 means
      an input operation. If bit 0 is set in the return value, the
-     logging of the will be suppressed.  With bit 1 set, the entire
-     line will be ignored. */
+     logging of the line will be suppressed.  With bit 1 set, the
+     entire line will be ignored. */
   unsigned int (*io_monitor)(assuan_context_t ctx,
                              int direction,
                              const char *line,

Modified: trunk/src/assuan-io.c
===================================================================
--- trunk/src/assuan-io.c	2007-10-01 14:44:46 UTC (rev 267)
+++ trunk/src/assuan-io.c	2007-10-02 08:44:21 UTC (rev 268)
@@ -56,22 +56,33 @@
   int n;
 
   n = recv (HANDLE2SOCKET(fd), buffer, size, 0);
-  if (n == -1 && WSAGetLastError () == WSAENOTSOCK)
+  if (n == -1)
     {
-      DWORD nread = 0;
-
-      n = ReadFile (fd, buffer, size, &nread, NULL);
-      if (!n)
+      switch (WSAGetLastError ())
         {
-          switch (GetLastError())
-            {
-            case ERROR_BROKEN_PIPE: errno = EPIPE; break;
-            default: errno = EIO; 
-            }
-          n = -1;
+        case WSAENOTSOCK:
+          {
+            DWORD nread = 0;
+            
+            n = ReadFile (fd, buffer, size, &nread, NULL);
+            if (!n)
+              {
+                switch (GetLastError())
+                  {
+                  case ERROR_BROKEN_PIPE: errno = EPIPE; break;
+                  default: errno = EIO; 
+                  }
+                n = -1;
+              }
+            else
+              n = (int)nread;
+          }
+          break;
+          
+        case WSAEWOULDBLOCK: errno = EAGAIN; break;
+        case ERROR_BROKEN_PIPE: errno = EPIPE; break;
+        default: errno = EIO; break;
         }
-      else
-        n = (int)nread;
     }
   return n;
 #else /*!HAVE_W32_SYSTEM*/

Modified: trunk/src/assuan-socket-server.c
===================================================================
--- trunk/src/assuan-socket-server.c	2007-10-01 14:44:46 UTC (rev 267)
+++ trunk/src/assuan-socket-server.c	2007-10-02 08:44:21 UTC (rev 268)
@@ -1,5 +1,5 @@
 /* assuan-socket-server.c - Assuan socket based server
- *	Copyright (C) 2002 Free Software Foundation, Inc.
+ *	Copyright (C) 2002, 2007 Free Software Foundation, Inc.
  *
  * This file is part of Assuan.
  *
@@ -98,6 +98,12 @@
       ctx->os_errno = errno;
       return _assuan_error (ASSUAN_Accept_Failed);
     }
+  if (_assuan_sock_check_nonce (fd, &ctx->listen_nonce))
+    {
+      _assuan_close (fd);
+      ctx->os_errno = EACCES;
+      return _assuan_error (ASSUAN_Accept_Failed);
+    }
 
   ctx->connected_fd = fd;
   return accept_connection_bottom (ctx);
@@ -190,3 +196,14 @@
     *r_ctx = ctx;
   return rc;
 }
+
+
+/* Save a copy of NONCE in context CTX.  This should be used to
+   register the server's nonce with an context established by
+   assuan_init_socket_server.  */
+void
+assuan_set_sock_nonce (assuan_context_t ctx, assuan_sock_nonce_t *nonce)
+{
+  if (ctx && nonce)
+    ctx->listen_nonce = *nonce;
+}

Modified: trunk/src/assuan-socket.c
===================================================================
--- trunk/src/assuan-socket.c	2007-10-01 14:44:46 UTC (rev 267)
+++ trunk/src/assuan-socket.c	2007-10-02 08:44:21 UTC (rev 268)
@@ -32,6 +32,8 @@
 #include <errno.h>
 #include <sys/stat.h>
 #include <fcntl.h>
+#include <assert.h>
+
 #include "assuan-defs.h"
 
 /* Hacks for Slowaris.  */
@@ -306,7 +308,8 @@
 {
 #ifdef HAVE_W32_SYSTEM
   char buffer[16], *p;
-  size_t nleft, n;
+  size_t nleft;
+  int n;
 
   if (sizeof nonce->nonce != 16)
     {

Modified: trunk/src/assuan.h
===================================================================
--- trunk/src/assuan.h	2007-10-01 14:44:46 UTC (rev 267)
+++ trunk/src/assuan.h	2007-10-02 08:44:21 UTC (rev 268)
@@ -377,9 +377,13 @@
 #ifdef _WIN32
 typedef void *assuan_fd_t;
 #define ASSUAN_INVALID_FD ((void*)(-1))
+#define ASSUAN_INT2FD(s)  ((void *)(s))
+#define ASSUAN_FD2INT(h)  ((unsigned int)(h))
 #else
 typedef int assuan_fd_t;
 #define ASSUAN_INVALID_FD (-1)
+#define ASSUAN_INT2FD(s)  ((s))
+#define ASSUAN_FD2INT(h)  ((h))
 #endif
 
 
@@ -475,6 +479,7 @@
                                          assuan_fd_t fd) _ASSUAN_DEPRECATED;
 int assuan_init_socket_server_ext (assuan_context_t *r_ctx, assuan_fd_t fd,
                                    unsigned int flags);
+void assuan_set_sock_nonce (assuan_context_t ctx, assuan_sock_nonce_t *nonce);
 
 /*-- assuan-pipe-connect.c --*/
 assuan_error_t assuan_pipe_connect (assuan_context_t *ctx,




More information about the Gnupg-commits mailing list