remote pool_handle_t
authorHenri Manson <hfmanson@gmail.com>
Thu, 18 Apr 2019 18:47:07 +0000 (20:47 +0200)
committerHenri Manson <hfmanson@gmail.com>
Thu, 18 Apr 2019 18:47:07 +0000 (20:47 +0200)
17 files changed:
include/tlspool/async.h
include/tlspool/commands.h
include/tlspool/internal.h
include/tlspool/starttls.h
lib/go/tlspool.c
lib/libtlspool.c
lib/libtlspool_async.c
lib/libtlspool_posix.c
lib/python/tlspool.c
lib/swig-tlspool.i
src/ctlkey.c
src/gnutls.c
src/lidentry.c
src/pinentry.c
src/service.c
src/service_posix.c
tool/tlstunnel.c

index 6d3913a..c1164bd 100644 (file)
@@ -6,27 +6,7 @@
 
 #include <tlspool/uthash.h>
 //LIST_STYLE// #include <tlspool/utlist.h>
-#include <tlspool/commands.h>
-
-
-#ifdef WINDOWS_PORT
-/* Our main purpose with the asynchronous API is simplicity.
- * You can say a lot about the Windows platform, but not
- * that it is simple.  We may not be able to support it.
- *
- * Instead, what we could do is simulate the API on top of
- * the synchronous default API for Windows.  If we do this,
- * we should do it in such a manner that tools like libev
- * continue to work.
- */
-#error "The asynchronous API is not available on Windows"
-#endif
-
-
-/* POSIX pool handle type.
- */
-typedef int pool_handle_t;
-
+#include <tlspool/starttls.h>
 
 /* The tlspool_async_request structure manages
  * a single pending request.  Once a response arrives,
@@ -63,7 +43,7 @@ struct tlspool_async_request {
  * with its output.
  */
 struct tlspool_async_pool {
-       pool_handle_t handle;
+       int handle;
        size_t cmdsize;
        struct tlspool_async_request *requests;
        struct pioc_ping pingdata;
@@ -147,5 +127,5 @@ bool tlspool_async_close (struct tlspool_async_pool *pool,
                                bool close_socket);
 
 
-//TODO// How to register with an event loop?  The pool_handle_t is strange on Windows...
+//TODO// How to register with an event loop?  The int is strange on Windows...
 
index c19b40d..7831006 100644 (file)
@@ -15,8 +15,10 @@ extern "C"
 #define _usleep(usec) (Sleep((usec) / 1000))
 #define poll(fds, nfds, timeout) WSAPoll(fds, nfds, timeout)
 #include <winsock2.h>
+#define DPRINTF(...) tlog (TLOG_UNIXSOCK, LOG_DEBUG, __VA_ARGS__)
 #else /* WINDOWS_PORT */
 #define _usleep(usec) usleep(usec)
+#define DPRINTF(...) fprintf (stderr, __VA_ARGS__)
 #endif /* WINDOWS_PORT */
 
 
index c533fc3..8387a86 100644 (file)
@@ -35,7 +35,7 @@ typedef struct pool_datum {
  * information for local administrative purposes.
  */
 struct command {
-       pool_handle_t clientfd;
+       int clientfd;
        int passfd;
        int claimed;
        pthread_t handler;
@@ -91,7 +91,7 @@ struct soxinfo {
  */
 struct callback {
        struct callback *next;          /* Lists, e.g. free list or cbq list */
-       pool_handle_t fd;           /* client socket receiving callback */
+       int fd;           /* client socket receiving callback */
        pthread_cond_t semaphore;       /* Dependent is waiting for signal */
        struct command *followup;       /* Link to the callback returned cmd */
        int timedout;                   /* Callback will be ignored, timeout */
@@ -122,7 +122,7 @@ void send_error (struct command *cmd, int tlserrno, char *msg);
 void send_success (struct command *cmd);
 int send_command (struct command *cmd, int passfd);
 struct command *send_callback_and_await_response (struct command *cmdresp, time_t opt_timeout);
-void register_server_socket (pool_handle_t srvsox);
+void register_server_socket (int srvsox);
 
 /* pinentry.c */
 void setup_pinentry (void);
@@ -130,7 +130,7 @@ void cleanup_pinentry (void);
 void register_pinentry_command (struct command *cmd);
 success_t token_callback (const char *const label, unsigned retry);
 success_t pin_callback (int attempt, const char *token_url, const char *opt_prompt, char *pin, size_t pin_max);
-void pinentry_forget_clientfd (pool_handle_t fd);
+void pinentry_forget_clientfd (int fd);
 
 /* starttls.c */
 struct ctlkeynode;
@@ -274,7 +274,7 @@ enum security_layer {
 struct ctlkeynode {
        uint8_t ctlkey [TLSPOOL_CTLKEYLEN];
        struct ctlkeynode *lessnode, *morenode;
-       pool_handle_t ctlfd;
+       int ctlfd;
        int forked;
        enum security_layer security;
 };
@@ -295,7 +295,7 @@ struct ctlkeynode {
  * be -1 to signal it is detached.  The forked flag should be non-zero
  * to indicate that this is a forked connection.
  */
-int ctlkey_register (uint8_t *ctlkey, struct ctlkeynode *ckn, enum security_layer sec, pool_handle_t ctlfd, int forked);
+int ctlkey_register (uint8_t *ctlkey, struct ctlkeynode *ckn, enum security_layer sec, int ctlfd, int forked);
 
 /* Remove a registered cltkey value from th registry.  This is the most
  * complex operation, as it needs to merge the subtrees.
@@ -323,7 +323,7 @@ int ctlkey_unregister (uint8_t *ctlkey);
  * be cleaned up.  Note that detaching is not done before the TLS handshake
  * is complete.
  */
-void ctlkey_close_ctlfd (pool_handle_t clisox);
+void ctlkey_close_ctlfd (int clisox);
 
 /* Find a ctlkeynode based on a ctlkey.  Returns NULL if not found.
  * 
@@ -334,7 +334,7 @@ void ctlkey_close_ctlfd (pool_handle_t clisox);
  * which means that a non-NULL return value must later be passed to a function
  * that unlocks the resource, ctlkey_unfind().
  */
-struct ctlkeynode *ctlkey_find (uint8_t *ctlkey, enum security_layer sec, pool_handle_t ctlfd);
+struct ctlkeynode *ctlkey_find (uint8_t *ctlkey, enum security_layer sec, int ctlfd);
 
 /* Free a ctlkeynode that was returned by ctlkey_find().  This function also
  * accepts a NULL argument, though those need not be passed through this
@@ -375,7 +375,7 @@ void register_lidentry_command (struct command *cmd);
  * being closed.  The LIDENTRY facility is freed up immediately for the next
  * requestor.
  */
-void lidentry_forget_clientfd (pool_handle_t fd);
+void lidentry_forget_clientfd (int fd);
 
 /* Check if the localid registration permits skipping of the given database
  * entry.  Such skips mean that the database entry on its own may fulfill the
index 12271de..215f671 100644 (file)
@@ -28,10 +28,10 @@ extern "C"
 
 #ifdef WINDOWS_PORT
 #include <windows.h>
-#else
-#include <unistd.h>
+#include <io.h>
 #endif /* WINDOWS_PORT */
 
+#include <unistd.h>
 
 /*
  * These functions are used by application software to turn an existing
@@ -63,11 +63,6 @@ typedef struct {
        DWORD dwState;
        BOOL fPendingIO;
 } PIPEINST, *LPPIPEINST;
-typedef LPPIPEINST pool_handle_t;
-#define INVALID_POOL_HANDLE NULL
-#else /* WINDOWS_PORT */
-typedef int pool_handle_t;
-#define INVALID_POOL_HANDLE -1
 #endif /* WINDOWS_PORT */ 
 
 /* Setup the TLS pool socket to use, if it is not the default path name
@@ -77,19 +72,13 @@ typedef int pool_handle_t;
  * be called with NULL in the first call, in which case the default location
  * is used.
  */
-pool_handle_t tlspool_open_poolhandle (char *path);
+int tlspool_open_poolhandle (char *path);
 
 /* Close a pool handle
  */
-#ifdef WINDOWS_PORT
-static inline void tlspool_close_poolhandle (pool_handle_t poolh) {
-       CloseHandle (poolh);
-}
-#else /* WINDOWS_PORT */
-static inline void tlspool_close_poolhandle (pool_handle_t poolh) {
+static inline void tlspool_close_poolhandle (int poolh) {
        close (poolh);
 }
-#endif /* WINDOWS_PORT */
 
 
 /* The library function for ping, which is called to establish the API
index a9b8b58..e7480cf 100644 (file)
@@ -238,7 +238,7 @@ static void* Swig_malloc(int c) {
 
        typedef char service_t [16];
 
-       typedef int pool_handle_t;
+       typedef int int;
 
        typedef struct {
                int tlserrno;
@@ -1060,7 +1060,7 @@ intgo _wrap_Internal_pid_tlspool_03ad2d7a43d805c7(_gostring_ _swig_go_0) {
 
 intgo _wrap_Internal_open_poolhandle_tlspool_03ad2d7a43d805c7(_gostring_ _swig_go_0) {
   char *arg1 = (char *) 0 ;
-  pool_handle_t result;
+  int result;
   intgo _swig_go_result;
   
   
@@ -1069,7 +1069,7 @@ intgo _wrap_Internal_open_poolhandle_tlspool_03ad2d7a43d805c7(_gostring_ _swig_g
   arg1[_swig_go_0.n] = '\0';
   
   
-  result = (pool_handle_t)tlspool_open_poolhandle(arg1);
+  result = (int)tlspool_open_poolhandle(arg1);
   _swig_go_result = result; 
   free(arg1); 
   return _swig_go_result;
index 3fc9c8e..65a8cbc 100644 (file)
@@ -61,7 +61,7 @@ static pthread_mutex_t have_master_lock = PTHREAD_MUTEX_INITIALIZER;
 
 static void *master_thread (void *path);
 
-static pool_handle_t poolfd = INVALID_POOL_HANDLE;             /* Blocked retrieval with tlspool_socket() */
+static int poolfd = -1;                /* Blocked retrieval with tlspool_socket() */
 
 static pthread_cond_t updated_poolfd = PTHREAD_COND_INITIALIZER;
 
@@ -108,9 +108,9 @@ int tlspool_pid (char *opt_pidfile) {
  * on the poolfd.  This is the process that actually contacts the TLS Pool
  * and sets up the poolfd socket.
  */
-pool_handle_t tlspool_open_poolhandle (char *path) {
-       pool_handle_t poolfdsample = poolfd;
-       if (poolfdsample == INVALID_POOL_HANDLE) {
+int tlspool_open_poolhandle (char *path) {
+       int poolfdsample = poolfd;
+       if (poolfdsample < 0) {
                pthread_mutex_t local_cond_wait = PTHREAD_MUTEX_INITIALIZER;
                //
                // Now that we have established a (first) poolfd, start up
@@ -137,8 +137,8 @@ pool_handle_t tlspool_open_poolhandle (char *path) {
                                syslog(LOG_NOTICE, "Failed to create TLS Pool client master thread");
                                pthread_mutex_unlock(&have_master_lock);
                                tlspool_close_poolhandle(poolfd);
-                               poolfd = INVALID_POOL_HANDLE;
-                               return INVALID_POOL_HANDLE;
+                               poolfd = -1;
+                               return -1;
                        }
                        pthread_detach (thr);
                        //
@@ -158,7 +158,7 @@ pool_handle_t tlspool_open_poolhandle (char *path) {
                // shared mutex -- which is why we use a local mutex per
                // thread: we don't need to wait for unique access.
                assert (pthread_mutex_lock (&local_cond_wait) == 0);
-               while (poolfdsample = poolfd, poolfdsample == INVALID_POOL_HANDLE) {
+               while (poolfdsample = poolfd, poolfdsample < 0) {
                        pthread_cond_wait (&updated_poolfd, &local_cond_wait);
                }
                pthread_mutex_unlock (&local_cond_wait);
@@ -175,7 +175,7 @@ pool_handle_t tlspool_open_poolhandle (char *path) {
 struct registry_entry {
        pthread_mutex_t *sig;           /* Wait for master thread's recvmsg() */
        struct tlspool_command *buf;    /* Buffer to hold received command */
-       pool_handle_t pfd;                      /* Client thread's assumed poolfd */
+       int pfd;                        /* Client thread's assumed poolfd */
 };
 
 static struct registry_entry **registry;
@@ -245,7 +245,7 @@ static int registry_update (int *reqid, struct registry_entry *entry) {
  * Any outstanding registry entries will be sent an ERROR value at this
  * time.
  */
-static void registry_flush (pool_handle_t poolfd) {
+static void registry_flush (int poolfd) {
        int regid = tlspool_simultaneous_starttls ();
        assert (pthread_mutex_lock (&registry_lock) == 0);
        while (regid-- > 0) {
@@ -294,20 +294,20 @@ static void *master_thread (void *path) {
                //
                // If any old socket clients persist, tell them that the
                // TLS Pool has been disconnected.
-               if (poolfd != INVALID_POOL_HANDLE) {
-                       pool_handle_t poolfdcopy = poolfd;
+               if (poolfd >= 0) {
+                       int poolfdcopy = poolfd;
 // printf ("DEBUG: Removing old poolfd %d\n", poolfd);
-                       poolfd = INVALID_POOL_HANDLE;
-                       registry_flush (INVALID_POOL_HANDLE);
+                       poolfd = -1;
+                       registry_flush (-1);
                        tlspool_close_poolhandle (poolfdcopy);
                }
                //
                // First, connect to the TLS Pool; upon failure, retry
                // with 1s, 2s, 4s, 8s, 16s, 32s, 32s, 32s, ... intervals.
                usec = 1000000;
-               while (poolfd == INVALID_POOL_HANDLE) {
-                       pool_handle_t newpoolfd = open_pool (path);                     
-                       if (newpoolfd != INVALID_POOL_HANDLE) {
+               while (poolfd < 0) {
+                       int newpoolfd = open_pool (path);                       
+                       if (newpoolfd >= 0) {
                                poolfd = newpoolfd;
                        }
                        //
@@ -323,7 +323,7 @@ static void *master_thread (void *path) {
 // printf ("DEBUG: Signalled slave threads with poolfd %d\n", poolfd);
                        //
                        // Wait before repeating, with exponential back-off
-                       if (poolfd == INVALID_POOL_HANDLE) {
+                       if (poolfd < 0) {
                                os_usleep(usec);
                                usec <<= 1;
                                if (usec > 32000000) {
@@ -392,12 +392,12 @@ static void *master_thread (void *path) {
  * doing that yet.  Then, wait until a message has been received.
  */
 static void registry_recvmsg (struct registry_entry *entry) {
-       static pool_handle_t lastpoolfd = INVALID_POOL_HANDLE;
+       static int lastpoolfd = -1;
        //
        // Detect poolfd socket change for potential dangling recipients
        if (entry->pfd != lastpoolfd) {
                lastpoolfd = tlspool_open_poolhandle (NULL);
-               if ((entry->pfd != lastpoolfd) && (lastpoolfd != INVALID_POOL_HANDLE)) {
+               if ((entry->pfd != lastpoolfd) && (lastpoolfd >= 0)) {
                        // Signal PIOC_ERROR to outdated recipients.
                        // (That will include the current recipient.)
                        registry_flush (lastpoolfd);
@@ -434,12 +434,12 @@ int tlspool_ping (pingpool_t *pingdata) {
        pthread_mutex_t recvwait = PTHREAD_MUTEX_INITIALIZER;
        struct registry_entry regent = { .sig = &recvwait, .buf = &cmd };
        int entry_reqid = -1;
-       pool_handle_t poolfd = INVALID_POOL_HANDLE;
+       int poolfd = -1;
 
        /* Prepare command structure */
        poolfd = tlspool_open_poolhandle (NULL);
 // printf ("DEBUG: poolfd = %d\n", poolfd);
-       if (poolfd == INVALID_POOL_HANDLE) {
+       if (poolfd < 0) {
                errno = ENODEV;
                return -1;
        }
@@ -511,7 +511,7 @@ int tlspool_starttls (int cryptfd, starttls_t *tlsdata,
        pthread_mutex_t recvwait = PTHREAD_MUTEX_INITIALIZER;
        struct registry_entry regent = { .sig = &recvwait, .buf = &cmd };
        int entry_reqid = -1;
-       pool_handle_t poolfd = INVALID_POOL_HANDLE;
+       int poolfd = -1;
        int plainfd = -1;
        int sentfd = -1;
        int processing;
@@ -523,7 +523,7 @@ int tlspool_starttls (int cryptfd, starttls_t *tlsdata,
        }
        /* Prepare command structure */
        poolfd = tlspool_open_poolhandle (NULL);
-       if (poolfd == INVALID_POOL_HANDLE) {
+       if (poolfd < 0) {
                closesocket(cryptfd);
                errno = ENODEV;
                return -1;
@@ -682,7 +682,7 @@ int _tlspool_control_command (int cmdcode, uint8_t *ctlkey) {
 
        /* Prepare command structure */
        poolfd = tlspool_open_poolhandle (NULL);
-       if (poolfd == INVALID_POOL_HANDLE) {
+       if (poolfd < 0) {
                errno = ENODEV;
                return -1;
        }
@@ -776,7 +776,7 @@ int tlspool_prng (char *label,
        pthread_mutex_t recvwait = PTHREAD_MUTEX_INITIALIZER;
        struct registry_entry regent = { .sig = &recvwait, .buf = &cmd };
        int entry_reqid = -1;
-       pool_handle_t poolfd = INVALID_POOL_HANDLE;
+       int poolfd = -1;
        memset (prng_buf, 0, prng_len);
 
        /* Sanity checks */
@@ -791,7 +791,7 @@ int tlspool_prng (char *label,
 
        /* Prepare command structure */
        poolfd = tlspool_open_poolhandle (NULL);
-       if (poolfd == INVALID_POOL_HANDLE) {
+       if (poolfd < 0) {
                errno = ENODEV;
                return -1;
        }
@@ -873,7 +873,7 @@ int tlspool_info (uint32_t info_kind,
        pthread_mutex_t recvwait = PTHREAD_MUTEX_INITIALIZER;
        struct registry_entry regent = { .sig = &recvwait, .buf = &cmd };
        int entry_reqid = -1;
-       pool_handle_t poolfd = INVALID_POOL_HANDLE;
+       int poolfd = -1;
        /* Sanity check */
        if ((*infolenptr > TLSPOOL_INFOBUFLEN) && (*infolenptr != 0xffff)) {
                errno = EINVAL;
@@ -881,7 +881,7 @@ int tlspool_info (uint32_t info_kind,
        }
        /* Prepare command structure */
        poolfd = tlspool_open_poolhandle (NULL);
-       if (poolfd == INVALID_POOL_HANDLE) {
+       if (poolfd < 0) {
                errno = ENODEV;
                return -1;
        }
index 0f4c91b..1ebcdf6 100644 (file)
@@ -109,7 +109,7 @@ bool tlspool_async_open (struct tlspool_async_pool *pool,
        }
 #else
        sox = open_named_pipe ((LPCTSTR) socket_path);
-       if (sox == INVALID_POOL_HANDLE) {
+       if (sox < 0) {
                //TODO// errno = ... (if not set yet)
                return false;
        }
@@ -399,5 +399,5 @@ bool tlspool_async_close (struct tlspool_async_pool *pool,
 }
 
 
-//TODO// How to register with an event loop?  The pool_handle_t is strange on Windows...
+//TODO// How to register with an event loop?  The int is strange on Windows...
 
index 48c7020..fb8de05 100644 (file)
@@ -1,7 +1,7 @@
 /* This file is #include'd by libtlspool.c */
 #define closesocket(s) close(s)
 
-int os_sendmsg_command(pool_handle_t poolfd, struct tlspool_command *cmd, int fd) {
+int os_sendmsg_command(int poolfd, struct tlspool_command *cmd, int fd) {
        struct iovec iov;
        struct cmsghdr *cmsg;
        struct msghdr mh = { 0 };
@@ -23,7 +23,7 @@ int os_sendmsg_command(pool_handle_t poolfd, struct tlspool_command *cmd, int fd
 }
 
 
-int os_recvmsg_command(pool_handle_t poolfd, struct tlspool_command *cmd) {
+int os_recvmsg_command(int poolfd, struct tlspool_command *cmd) {
        struct iovec iov;
        struct cmsghdr *cmsg;
        struct msghdr mh = { 0 };
@@ -110,18 +110,18 @@ int os_usleep(unsigned int usec) {
        return usleep(usec);
 }
 
-pool_handle_t open_pool (void *path) {
+int open_pool (void *path) {
        struct sockaddr_un sun;
        //
        // Setup path information -- value and size were checked
        memset (&sun, 0, sizeof (sun));
        strcpy (sun.sun_path, (char *) path);
        sun.sun_family = AF_UNIX;
-       pool_handle_t newpoolfd = socket (AF_UNIX, SOCK_STREAM, 0);
-       if (newpoolfd != INVALID_POOL_HANDLE) {
+       int newpoolfd = socket (AF_UNIX, SOCK_STREAM, 0);
+       if (newpoolfd >= 0) {
                if (connect (newpoolfd, (struct sockaddr *) &sun, SUN_LEN (&sun)) != 0) {
                        tlspool_close_poolhandle (newpoolfd);
-                       newpoolfd = INVALID_POOL_HANDLE;
+                       newpoolfd = -1;
                }
        }
 // printf ("DEBUG: Trying new poolfd %d for path %s\n", newpoolfd, sun.sun_path);
index 443364a..51963c4 100644 (file)
@@ -3039,7 +3039,7 @@ static swig_module_info swig_module = {swig_types, 12, 0, 0, 0, 0};
 
        typedef char service_t [16];
 
-       typedef int pool_handle_t;
+       typedef int int;
 
        typedef struct {
                int tlserrno;
@@ -5263,7 +5263,7 @@ SWIGINTERN PyObject *_wrap__open_poolhandle(PyObject *SWIGUNUSEDPARM(self), PyOb
   char *buf1 = 0 ;
   int alloc1 = 0 ;
   PyObject * obj0 = 0 ;
-  pool_handle_t result;
+  int result;
   
   if (!PyArg_ParseTuple(args,(char *)"O:_open_poolhandle",&obj0)) SWIG_fail;
   res1 = SWIG_AsCharPtrAndSize(obj0, &buf1, NULL, &alloc1);
@@ -5273,7 +5273,7 @@ SWIGINTERN PyObject *_wrap__open_poolhandle(PyObject *SWIGUNUSEDPARM(self), PyOb
   arg1 = (char *)(buf1);
   {
     SWIG_PYTHON_THREAD_BEGIN_ALLOW;
-    result = (pool_handle_t)tlspool_open_poolhandle(arg1);
+    result = (int)tlspool_open_poolhandle(arg1);
     SWIG_PYTHON_THREAD_END_ALLOW;
   }
   resultobj = SWIG_From_int((int)(result));
@@ -5617,7 +5617,7 @@ static swig_type_info _swigt__p_a_16__uint8_t = {"_p_a_16__uint8_t", "uint8_t (*
 static swig_type_info _swigt__p_char = {"_p_char", "char *", 0, 0, (void*)0, 0};
 static swig_type_info _swigt__p_control_data = {"_p_control_data", "control_data *", 0, 0, (void*)0, 0};
 static swig_type_info _swigt__p_error_data = {"_p_error_data", "error_data *", 0, 0, (void*)0, 0};
-static swig_type_info _swigt__p_int = {"_p_int", "int *|pool_handle_t *", 0, 0, (void*)0, 0};
+static swig_type_info _swigt__p_int = {"_p_int", "int *|int *", 0, 0, (void*)0, 0};
 static swig_type_info _swigt__p_ping_data = {"_p_ping_data", "ping_data *", 0, 0, (void*)0, 0};
 static swig_type_info _swigt__p_prng_data = {"_p_prng_data", "prng_data *", 0, 0, (void*)0, 0};
 static swig_type_info _swigt__p_socket_data = {"_p_socket_data", "socket_data *", 0, 0, (void*)0, 0};
index f5c2696..626a542 100644 (file)
@@ -45,8 +45,6 @@
 
        typedef char service_t [16];
 
-       typedef int pool_handle_t;
-
        typedef struct {
                int tlserrno;
                char message [128];
index 4d99b80..5cb94c6 100644 (file)
@@ -102,7 +102,7 @@ static pthread_mutex_t ctlkey_registry_lock = PTHREAD_MUTEX_INITIALIZER;
  * be -1 to signal it is detached.  The forked flag should be non-zero
  * to indicate that this is a forked connection.
  */
-int ctlkey_register (uint8_t *ctlkey, struct ctlkeynode *ckn, enum security_layer sec, pool_handle_t ctlfd, int forked) {
+int ctlkey_register (uint8_t *ctlkey, struct ctlkeynode *ckn, enum security_layer sec, int ctlfd, int forked) {
        int i;
        int todo;
        struct ctlkeynode **nodepp;
@@ -191,7 +191,7 @@ int ctlkey_unregister (uint8_t *ctlkey) {
  * which means that a non-NULL return value must later be passed to a function
  * that unlocks the resource, ctlkey_unfind().
  */
-struct ctlkeynode *ctlkey_find (uint8_t *ctlkey, enum security_layer sec, pool_handle_t ctlfd) {
+struct ctlkeynode *ctlkey_find (uint8_t *ctlkey, enum security_layer sec, int ctlfd) {
        struct ctlkeynode *ckn;
        //
        // Claim unique access; this lock survives until cltkey_unfind()
@@ -264,11 +264,11 @@ void ctlkey_detach (struct command *cmd) {
                int cmp = memcmp (ctlkey, (*nodepp)->ctlkey, TLSPOOL_CTLKEYLEN);
                if (cmp == 0) {
                        /* Found the right node */
-                       if ((*nodepp)->ctlfd == INVALID_POOL_HANDLE) {
+                       if ((*nodepp)->ctlfd < 0) {
                                tlserrno = E_TLSPOOL_CTLKEY_DETACHED;
                                errstr = "TLS Pool found the control key already detached";
                        } else if ((*nodepp)->ctlfd == cmd->clientfd) {
-                               (*nodepp)->ctlfd = INVALID_POOL_HANDLE;
+                               (*nodepp)->ctlfd = -1;
                                //FORK!=DETACH// ctlkey_signalling_raise ();
                                tlserrno = 0;
                                errstr = NULL;
@@ -306,7 +306,7 @@ void ctlkey_reattach (struct command *cmd) {
                int cmp = memcmp (ctlkey, (*nodepp)->ctlkey, TLSPOOL_CTLKEYLEN);
                if (cmp == 0) {
                        /* Found the right node */
-                       if ((*nodepp)->ctlfd == INVALID_POOL_HANDLE) {
+                       if ((*nodepp)->ctlfd < 0) {
                                (*nodepp)->ctlfd = cmd->clientfd;
                                //FORK!=DETACH// ctlkey_signalling_raise ();
                                tlserrno = 0;
@@ -342,7 +342,7 @@ void ctlkey_reattach (struct command *cmd) {
  * be cleaned up.  Note that detaching is not done before the TLS handshake
  * is complete.
  */
-static void _ctlkey_close_ctlfd_recurse (pool_handle_t clisox, struct ctlkeynode **nodepp) {
+static void _ctlkey_close_ctlfd_recurse (int clisox, struct ctlkeynode **nodepp) {
        struct ctlkeynode *node = *nodepp;
        if (node == NULL) {
                return;
@@ -355,7 +355,7 @@ static void _ctlkey_close_ctlfd_recurse (pool_handle_t clisox, struct ctlkeynode
                assert (*nodepp == node);
 //DEBUG// fprintf(stderr,"Unregistering control key (automatically, as controlling fd closes)\n");
                if (node->forked) {
-                       node->ctlfd = INVALID_POOL_HANDLE;
+                       node->ctlfd = -1;
                } else {
                        _ctlkey_unregister_nodepp (nodepp);
                        // Now we know that *nodepp has changed, it is no longer
@@ -367,7 +367,7 @@ static void _ctlkey_close_ctlfd_recurse (pool_handle_t clisox, struct ctlkeynode
                }
        }
 }
-void ctlkey_close_ctlfd (pool_handle_t clisox) {
+void ctlkey_close_ctlfd (int clisox) {
        assert (pthread_mutex_lock (&ctlkey_registry_lock) == 0);
        _ctlkey_close_ctlfd_recurse (clisox, &rootnode);
        pthread_mutex_unlock (&ctlkey_registry_lock);
index 57c24c6..9369943 100644 (file)
@@ -1014,7 +1014,7 @@ void cleanup_starttls (void) {
  * GNUTLS_E_REHANDSHAKE which client or server side may receive when an
  * attempt is made to renegotiate the security of the connection.
  */
-static int copycat (int local, int remote, gnutls_session_t wrapped, pool_handle_t client) {
+static int copycat (int local, int remote, gnutls_session_t wrapped, int client) {
        char buf [1024];
        struct pollfd inout [3];
        ssize_t sz;
@@ -1024,14 +1024,14 @@ static int copycat (int local, int remote, gnutls_session_t wrapped, pool_handle
        bool local_shutdown_done = false;
        bool remote_shutdown_done = false;
        
-       client = INVALID_POOL_HANDLE;
+       client = -1;
        inout [0].fd = local;
        inout [1].fd = remote;
 #ifdef WINDOWS_PORT
        have_client = 0;
 #else
        inout [2].fd = client;
-       have_client = inout [2].fd != INVALID_POOL_HANDLE;
+       have_client = inout [2].fd >= 0;
 #endif
        if (!have_client) {
                inout [2].revents = 0;  // Will not be written by poll
@@ -5384,7 +5384,7 @@ fprintf (stderr, "ctlkey_unregister under ckn=%p at %d\n", (void *)ckn, __LINE__
                ckn->cryptfd = cryptfd;
                ckn->plainfd = plainfd;
 //DEBUG// fprintf (stderr, "Registering control key\n");
-               if (renegotiating || (ctlkey_register (orig_starttls.ctlkey, &ckn->regent, security_tls, detach ? INVALID_POOL_HANDLE : cmd->clientfd, forked) == 0)) {
+               if (renegotiating || (ctlkey_register (orig_starttls.ctlkey, &ckn->regent, security_tls, detach ? -1 : cmd->clientfd, forked) == 0)) {
                        int copied = GNUTLS_E_SUCCESS;
                        send_command (replycmd, -1);            // app sent plainfd to us
                        if (preauth) {
@@ -5408,12 +5408,12 @@ fprintf (stderr, "ctlkey_unregister under ckn=%p at %d\n", (void *)ckn, __LINE__
                                        tlog (TLOG_COPYCAT, LOG_DEBUG, "Passed on %d remote bytes from anonymous precursor to %d\n", preauthlen, plainfd);
                                        free (preauth);
                                        preauth = NULL;
-                                       copied = copycat (plainfd, cryptfd, session, detach ? INVALID_POOL_HANDLE : cmd->clientfd);
+                                       copied = copycat (plainfd, cryptfd, session, detach ? -1 : cmd->clientfd);
                                } else {
                                        tlog (TLOG_COPYCAT, LOG_DEBUG, "Failed to pass on %d remote bytes from anonymous precursor to %d\n", preauthlen, plainfd);
                                }
                        } else {
-                               copied = copycat (plainfd, cryptfd, session, detach ? INVALID_POOL_HANDLE : cmd->clientfd);
+                               copied = copycat (plainfd, cryptfd, session, detach ? -1 : cmd->clientfd);
                        }
                        // Renegotiate if copycat asked us to
                        if (copied == GNUTLS_E_REHANDSHAKE) {
index 57c8e7d..b49f9d6 100644 (file)
@@ -53,7 +53,7 @@
  */
 static pthread_mutex_t lidentry_lock = PTHREAD_MUTEX_INITIALIZER;
 static struct command *lidentry_cmd = NULL;
-static pool_handle_t lidentry_client = INVALID_POOL_HANDLE;
+static int lidentry_client = -1;
 static time_t lidentry_rereg_timeout = 0;
 static uint32_t lidentry_regflags;     // Setup during registration
 static uint32_t lidentry_timeout;      // Setup during registration (#sec)
@@ -187,7 +187,7 @@ void register_lidentry_command (struct command *cmd) {
  * being closed.  The LIDENTRY facility is freed up immediately for the next
  * requestor.
  */
-void lidentry_forget_clientfd (pool_handle_t fd) {
+void lidentry_forget_clientfd (int fd) {
        assert (pthread_mutex_lock (&lidentry_lock) == 0);
 printf ("DEBUG: forgetting LID entry clientfd %d (if it is %d and not -1)\n", fd, lidentry_client);
        // Only respond when the current client wants to be forgotten
@@ -197,7 +197,7 @@ printf ("DEBUG: forgetting LID entry clientfd %d (if it is %d and not -1)\n", fd
                // Immediately free up for any new LIDENTRY request
                lidentry_rereg_timeout = 0;
                // The following is needless but more consistent with restart
-               lidentry_client = INVALID_POOL_HANDLE;
+               lidentry_client = -1;
                // Forcefully free the callback sequence claim
                lidentry_cbseq_claimed = 0;
                // Note: Callbacks waiting on fd should receive an ERROR reply
index d67bbe1..e44e537 100644 (file)
@@ -61,7 +61,7 @@
  */
 static pthread_mutex_t pinentry_lock = PTHREAD_MUTEX_INITIALIZER;
 static struct command *pinentry_cmd = NULL;
-static pool_handle_t pinentry_client = INVALID_POOL_HANDLE;
+static int pinentry_client = -1;
 static time_t pinentry_timeout = 0;
 
 
@@ -112,7 +112,7 @@ void register_pinentry_command (struct command *cmd) {
  * being closed.  The PINENTRY facility is freed up immediately for the next
  * requestor.
  */
-void pinentry_forget_clientfd (pool_handle_t fd) {
+void pinentry_forget_clientfd (int fd) {
        assert (pthread_mutex_lock (&pinentry_lock) == 0);
        if (pinentry_client == fd) {
                // No response possible.  Service reclaims for cmd pooling
@@ -120,7 +120,7 @@ void pinentry_forget_clientfd (pool_handle_t fd) {
                // Immediately free up for any new PINENTRY request
                pinentry_timeout = 0;
                // The following is needless but more consistent with restart
-               pinentry_client = INVALID_POOL_HANDLE;
+               pinentry_client = -1;
        }
        pthread_mutex_unlock (&pinentry_lock);
 }
index ead1ee5..7077e64 100644 (file)
@@ -110,7 +110,7 @@ void cleanup_service (void) {
  */
 static struct command *cmdpool = NULL;
 static int cmdpool_len = 1000;
-static struct command *allocate_command_for_clientfd (pool_handle_t fd) {
+static struct command *allocate_command_for_clientfd (int fd) {
        static int cmdpool_pos = 0;
        int pos;
        struct command *cmd;
@@ -149,7 +149,7 @@ static struct command *allocate_command_for_clientfd (pool_handle_t fd) {
  *
  * TODO: This is O(cmdpool_len) so linked lists could help to avoid trouble.
  */
-static void free_commands_by_clientfd (pool_handle_t clientfd) {
+static void free_commands_by_clientfd (int clientfd) {
        int i;
        if (cmdpool == NULL) {
                return;
@@ -325,7 +325,7 @@ struct command *send_callback_and_await_response (struct command *cmdresp, time_
  */
 static void post_callback (struct command *cmd) {
        uint16_t cbid = cmd->cmd.pio_cbid - 1;
-       cblist [cbid].fd = INVALID_POOL_HANDLE;
+       cblist [cbid].fd = -1;
        cblist [cbid].followup = cmd;
        assert (pthread_mutex_lock (&cbfree_mutex) == 0);
        tlog (TLOG_UNIXSOCK, LOG_DEBUG, "Signaling on the semaphore of callback 0x%08x", &cblist [cbid]);
@@ -348,7 +348,7 @@ static void post_callback (struct command *cmd) {
  * in the TLS Pool when a clientfd is closed by the client (perhaps due to
  * a crash in response to the callback).
  */
-static void free_callbacks_by_clientfd (pool_handle_t clientfd) {
+static void free_callbacks_by_clientfd (int clientfd) {
        int i;
        for (i=0; i<1024; i++) {
 //TODO// == clientfd was >= 0 (and managed to get closes sent back to all)
@@ -494,7 +494,7 @@ void run_service (void) {
        }
        for (i=0; i<1024; i++) {
                cblist [i].next = cbfree;
-               cblist [i].fd = INVALID_POOL_HANDLE; // Mark as unused
+               cblist [i].fd = -1; // Mark as unused
                pthread_cond_init (&cblist [i].semaphore, NULL);
                cblist [i].followup = NULL;
                cbfree = &cblist [i];
index 747da62..381414c 100644 (file)
@@ -5,7 +5,7 @@ static struct soxinfo soxinfo [1024];
 static struct pollfd soxpoll [1024];
 
 /* Register a socket.  It is assumed that first all server sockets register */
-static void register_socket (pool_handle_t sox, uint32_t soxinfo_flags) {
+static void register_socket (int sox, uint32_t soxinfo_flags) {
        int flags = fcntl (sox, F_GETFD);
        flags |= O_NONBLOCK;
        fcntl (sox, F_SETFD, flags);
@@ -27,7 +27,7 @@ static void register_socket (pool_handle_t sox, uint32_t soxinfo_flags) {
 /* TODO: This may copy information back and thereby avoid processing in the
  * current loop passthrough.  No problem, poll() will show it once more. */
 static void unregister_client_socket_byindex (int soxidx) {
-       pool_handle_t sox = soxpoll [soxidx].fd;
+       int sox = soxpoll [soxidx].fd;
        free_callbacks_by_clientfd (sox);
        free_commands_by_clientfd (sox);
        pinentry_forget_clientfd (sox);
@@ -75,7 +75,7 @@ static int os_send_command (struct command *cmd, int passfd)
 }
 
 /* Receive a command.  Return nonzero on success, zero on failure. */
-static int receive_command (pool_handle_t sox, struct command *cmd) {
+static int receive_command (int sox, struct command *cmd) {
        int newfds [2];
        int newfdcnt = 0;
        char anc [CMSG_SPACE (sizeof (int))];
@@ -116,12 +116,12 @@ static int receive_command (pool_handle_t sox, struct command *cmd) {
        return 1;
 }
 
-void register_server_socket (pool_handle_t srvsox) {
+void register_server_socket (int srvsox) {
        register_socket (srvsox, SOF_SERVER);
 }
 
 
-void register_client_socket (pool_handle_t clisox) {
+void register_client_socket (int clisox) {
        register_socket (clisox, SOF_CLIENT);
 }
 
@@ -130,7 +130,7 @@ void register_client_socket (pool_handle_t clisox) {
  *  - to trigger a thread that is hoping writing after EAGAIN
  *  - to read a message and further process it
  */
-void process_activity (pool_handle_t sox, int soxidx, struct soxinfo *soxi, short int revents) {
+void process_activity (int sox, int soxidx, struct soxinfo *soxi, short int revents) {
        if (revents & POLLOUT) {
                //TODO// signal waiting thread that it may continue
                tlog (TLOG_UNIXSOCK, LOG_CRIT, "Eekk!!  Could send a packet?!?  Unregistering client");
@@ -141,8 +141,8 @@ void process_activity (pool_handle_t sox, int soxidx, struct soxinfo *soxi, shor
                if (soxi->flags & SOF_SERVER) {
                        struct sockaddr sa;
                        socklen_t salen = sizeof (sa);
-                       pool_handle_t newsox = accept (sox, &sa, &salen);
-                       if (newsox != INVALID_POOL_HANDLE) {
+                       int newsox = accept (sox, &sa, &salen);
+                       if (newsox >= 0) {
                                tlog (TLOG_UNIXSOCK, LOG_NOTICE, "Received incoming connection.  Registering it");
                                register_client_socket (newsox);
                        }
@@ -167,7 +167,7 @@ static void os_run_service ()
                tlog (TLOG_UNIXSOCK, LOG_DEBUG, "Polled %d sockets, returned %d", num_sox, polled);
                for (i=0; i<num_sox; i++) {
                        if (soxpoll [i].revents & (POLLHUP|POLLERR|POLLNVAL)) {
-                               pool_handle_t sox = soxpoll [i].fd;
+                               int sox = soxpoll [i].fd;
                                tlog (TLOG_UNIXSOCK, LOG_NOTICE, "Unregistering socket %d", sox);
                                unregister_client_socket_byindex (i);
                                close (sox);
index bc4a983..0092b3e 100644 (file)
@@ -590,7 +590,7 @@ int main (int argc, char *argv []) {
                exit (1);
        }
        if (cmdsoxpath) {
-               if (tlspool_open_poolhandle (cmdsoxpath) == INVALID_POOL_HANDLE) {
+               if (tlspool_open_poolhandle (cmdsoxpath) < 0) {
                        perror ("Failed to open TLS Pool command socket");
                        exit (1);
                }