#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,
* 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;
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...
#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 */
* information for local administrative purposes.
*/
struct command {
- pool_handle_t clientfd;
+ int clientfd;
int passfd;
int claimed;
pthread_t handler;
*/
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 */
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);
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;
struct ctlkeynode {
uint8_t ctlkey [TLSPOOL_CTLKEYLEN];
struct ctlkeynode *lessnode, *morenode;
- pool_handle_t ctlfd;
+ int ctlfd;
int forked;
enum security_layer security;
};
* 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.
* 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.
*
* 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
* 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
#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
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
* 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
typedef char service_t [16];
- typedef int pool_handle_t;
+ typedef int int;
typedef struct {
int tlserrno;
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;
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;
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;
* 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
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);
//
// 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);
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;
* 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 (®istry_lock) == 0);
while (regid-- > 0) {
//
// 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;
}
//
// 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) {
* 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);
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;
}
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;
}
/* Prepare command structure */
poolfd = tlspool_open_poolhandle (NULL);
- if (poolfd == INVALID_POOL_HANDLE) {
+ if (poolfd < 0) {
closesocket(cryptfd);
errno = ENODEV;
return -1;
/* Prepare command structure */
poolfd = tlspool_open_poolhandle (NULL);
- if (poolfd == INVALID_POOL_HANDLE) {
+ if (poolfd < 0) {
errno = ENODEV;
return -1;
}
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 */
/* Prepare command structure */
poolfd = tlspool_open_poolhandle (NULL);
- if (poolfd == INVALID_POOL_HANDLE) {
+ if (poolfd < 0) {
errno = ENODEV;
return -1;
}
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;
}
/* Prepare command structure */
poolfd = tlspool_open_poolhandle (NULL);
- if (poolfd == INVALID_POOL_HANDLE) {
+ if (poolfd < 0) {
errno = ENODEV;
return -1;
}
}
#else
sox = open_named_pipe ((LPCTSTR) socket_path);
- if (sox == INVALID_POOL_HANDLE) {
+ if (sox < 0) {
//TODO// errno = ... (if not set yet)
return false;
}
}
-//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...
/* 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 };
}
-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 };
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);
typedef char service_t [16];
- typedef int pool_handle_t;
+ typedef int int;
typedef struct {
int tlserrno;
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);
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));
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};
typedef char service_t [16];
- typedef int pool_handle_t;
-
typedef struct {
int tlserrno;
char message [128];
* 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;
* 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()
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;
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;
* 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;
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
}
}
}
-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);
* 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;
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
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) {
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) {
*/
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)
* 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
// 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
*/
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;
* 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
// 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);
}
*/
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;
*
* 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;
*/
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]);
* 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)
}
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];
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);
/* 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);
}
/* 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))];
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);
}
* - 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");
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);
}
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);
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);
}