From aa1c0a545dfbddead04abb8a1754606672cc667c Mon Sep 17 00:00:00 2001 From: Marcus Brinkmann Date: Wed, 29 Nov 2006 16:25:46 +0000 Subject: [PATCH] Update to rev 231 of libassuan. --- assuan/ChangeLog | 67 ++++++++++++++++ assuan/assuan-buffer.c | 66 +++++++++++++--- assuan/assuan-client.c | 8 +- assuan/assuan-defs.h | 16 +++- assuan/assuan-domain-connect.c | 0 assuan/assuan-domain-server.c | 0 assuan/assuan-handler.c | 50 ++++++++++-- assuan/assuan-io.c | 140 ++------------------------------- assuan/assuan-pipe-server.c | 1 + assuan/assuan-uds.c | 36 +++++++-- assuan/assuan-util.c | 15 ++++ assuan/assuan.h | 13 +++ assuan/mkerrors | 2 + 13 files changed, 253 insertions(+), 161 deletions(-) delete mode 100644 assuan/assuan-domain-connect.c delete mode 100644 assuan/assuan-domain-server.c diff --git a/assuan/ChangeLog b/assuan/ChangeLog index d9519c12..a3b3f928 100644 --- a/assuan/ChangeLog +++ b/assuan/ChangeLog @@ -1,3 +1,70 @@ +2006-11-22 Werner Koch + + * assuan-handler.c (fun1_cookie_write, fun2_cookie_write): New. + (assuan_get_data_fp) [HAVE_FUNOPEN]: Use it. + +2006-11-21 Werner Koch + + * Makefile.am (libassuan_pth_a_CFLAGS): New. + + * assuan-pipe-server.c (_assuan_release_context): Free CMDTBL. + +2006-11-14 Werner Koch + + * libassuan.m4 (AM_CHECK_LIBASSUAN): New. + + * assuan-handler.c (assuan_register_post_cmd_notify) + (assuan_register_post_cmd_notify): New. + * assuan-util.c (assuan_set_io_monitor): New. + * assuan-buffer.c (_assuan_read_line): Use it. + (_assuan_write_line): Ditto. + (_assuan_cookie_write_data): Ditto. + (_assuan_cookie_write_flush): Ditto. + +2006-10-18 Werner Koch + + * libassuan.m4: Pass "pthread" to the common macro. Reported by + Rex Dieter. + +2006-10-16 Werner Koch + + * mkerrors: Map ASSUAN_Not_Confirmed. + +2006-10-10 Werner Koch + + * libassuan.m4 (AM_PATH_LIBASSUAN_PTH) + (AM_PATH_LIBASSUAN_PTHREAD): Fixed. + + * assuan-buffer.c (assuan_sendfd): Implement a runtime detection + of implemented descripotr passing. + + * assuan-uds.c: Take care of USE_DESCRIPTOR_PASSING. + + * assuan-defs.h: Add missing semicolon. + +2006-10-09 Werner Koch + + * assuan-handler.c (process_request): Use weak pragma for the sake + of old gcc's. Reported by Alain Guibert. + + * assuan-io.c: Removed Pth support. + * assuan-io-pth.c: New. Based on assuan-io.c + +2006-10-06 Werner Koch + + * libassuan-config.in: New options --api-version and --thread. + +2006-10-04 Werner Koch + + * assuan-client.c (assuan_transact): Need to map old assuan status + codes so that for example CANCELED is correctly mapped. + +2006-09-28 Marcus Brinkmann + + * assuan-client.c (assuan_transact): Do not convert error on + status line, it is already a gpg-error. Do convert + ASSUAN_Server_Fault. + 2006-09-19 Marcus Brinkmann * assuan.h (assuan_init_socket_server_ext) diff --git a/assuan/assuan-buffer.c b/assuan/assuan-buffer.c index 5580392a..b06025b4 100644 --- a/assuan/assuan-buffer.c +++ b/assuan/assuan-buffer.c @@ -1,5 +1,5 @@ /* assuan-buffer.c - read and send data - * Copyright (C) 2001, 2002, 2003, 2004 Free Software Foundation, Inc. + * Copyright (C) 2001, 2002, 2003, 2004, 2006 Free Software Foundation, Inc. * * This file is part of Assuan. * @@ -159,7 +159,9 @@ _assuan_read_line (assuan_context_t ctx) if (endp) { + unsigned monitor_result; int n = endp - line + 1; + if (n < nread) /* LINE contains more than one line. We copy it to the attic now as handlers are allowed to modify the passed @@ -176,7 +178,16 @@ _assuan_read_line (assuan_context_t ctx) *endp = 0; ctx->inbound.linelen = endp - line; - if (ctx->log_fp) + + monitor_result = (ctx->io_monitor + ? ctx->io_monitor (ctx, 0, + ctx->inbound.line, + ctx->inbound.linelen) + : 0); + if ( (monitor_result & 2) ) + ctx->inbound.linelen = 0; + + if (ctx->log_fp && !(monitor_result & 1)) { fprintf (ctx->log_fp, "%s[%u.%d] DBG: <- ", assuan_get_assuan_log_prefix (), @@ -245,6 +256,7 @@ _assuan_write_line (assuan_context_t ctx, const char *prefix, { assuan_error_t rc = 0; size_t prefixlen = prefix? strlen (prefix):0; + unsigned int monitor_result; /* Make sure that the line is short enough. */ if (len + prefixlen + 2 > ASSUAN_LINELENGTH) @@ -260,8 +272,12 @@ _assuan_write_line (assuan_context_t ctx, const char *prefix, len = ASSUAN_LINELENGTH - prefixlen - 2 - 1; } + monitor_result = (ctx->io_monitor + ? ctx->io_monitor (ctx, 1, line, len) + : 0); + /* Fixme: we should do some kind of line buffering. */ - if (ctx->log_fp) + if (ctx->log_fp && !(monitor_result & 1)) { fprintf (ctx->log_fp, "%s[%u.%d] DBG: -> ", assuan_get_assuan_log_prefix (), @@ -277,13 +293,13 @@ _assuan_write_line (assuan_context_t ctx, const char *prefix, putc ('\n', ctx->log_fp); } - if (prefixlen) + if (prefixlen && !(monitor_result & 2)) { rc = writen (ctx, prefix, prefixlen); if (rc) rc = _assuan_error (ASSUAN_Write_Error); } - if (!rc) + if (!rc && !(monitor_result & 2)) { rc = writen (ctx, line, len); if (rc) @@ -325,7 +341,7 @@ assuan_write_line (assuan_context_t ctx, const char *line) /* Write out the data in buffer as datalines with line wrapping and - percent escaping. This function is used for GNU's custom streams */ + percent escaping. This function is used for GNU's custom streams. */ int _assuan_cookie_write_data (void *cookie, const char *buffer, size_t orig_size) { @@ -342,7 +358,9 @@ _assuan_cookie_write_data (void *cookie, const char *buffer, size_t orig_size) line += linelen; while (size) { - /* insert data line header */ + unsigned int monitor_result; + + /* Insert data line header. */ if (!linelen) { *line++ = 'D'; @@ -350,7 +368,7 @@ _assuan_cookie_write_data (void *cookie, const char *buffer, size_t orig_size) linelen += 2; } - /* copy data, keep some space for the CRLF and to escape one character */ + /* Copy data, keep space for the CRLF and to escape one character. */ while (size && linelen < LINELENGTH-2-2) { if (*buffer == '%' || *buffer == '\r' || *buffer == '\n') @@ -368,9 +386,15 @@ _assuan_cookie_write_data (void *cookie, const char *buffer, size_t orig_size) size--; } + + monitor_result = (ctx->io_monitor + ? ctx->io_monitor (ctx, 1, + ctx->outbound.data.line, linelen) + : 0); + if (linelen >= LINELENGTH-2-2) { - if (ctx->log_fp) + if (ctx->log_fp && !(monitor_result & 1)) { fprintf (ctx->log_fp, "%s[%u.%d] DBG: -> ", assuan_get_assuan_log_prefix (), @@ -386,7 +410,8 @@ _assuan_cookie_write_data (void *cookie, const char *buffer, size_t orig_size) } *line++ = '\n'; linelen++; - if (writen (ctx, ctx->outbound.data.line, linelen)) + if ( !(monitor_result & 2) + && writen (ctx, ctx->outbound.data.line, linelen)) { ctx->outbound.data.error = _assuan_error (ASSUAN_Write_Error); return 0; @@ -409,6 +434,7 @@ _assuan_cookie_write_flush (void *cookie) assuan_context_t ctx = cookie; char *line; size_t linelen; + unsigned int monitor_result; if (ctx->outbound.data.error) return 0; @@ -416,9 +442,15 @@ _assuan_cookie_write_flush (void *cookie) line = ctx->outbound.data.line; linelen = ctx->outbound.data.linelen; line += linelen; + + monitor_result = (ctx->io_monitor + ? ctx->io_monitor (ctx, 1, + ctx->outbound.data.line, linelen) + : 0); + if (linelen) { - if (ctx->log_fp) + if (ctx->log_fp && !(monitor_result & 1)) { fprintf (ctx->log_fp, "%s[%u.%d] DBG: -> ", assuan_get_assuan_log_prefix (), @@ -432,7 +464,8 @@ _assuan_cookie_write_flush (void *cookie) } *line++ = '\n'; linelen++; - if (writen (ctx, ctx->outbound.data.line, linelen)) + if ( !(monitor_result & 2) + && writen (ctx, ctx->outbound.data.line, linelen)) { ctx->outbound.data.error = _assuan_error (ASSUAN_Write_Error); return 0; @@ -490,6 +523,15 @@ assuan_send_data (assuan_context_t ctx, const void *buffer, size_t length) assuan_error_t assuan_sendfd (assuan_context_t ctx, int fd) { + /* It is explicitly allowed to use (NULL, -1) as a runtime test to + check whether descriptor passing is available. */ + if (!ctx && fd == -1) +#ifdef USE_DESCRIPTOR_PASSING + return 0; +#else + return _assuan_error (ASSUAN_Not_Implemented); +#endif + if (! ctx->io->sendfd) return set_error (ctx, Not_Implemented, "server does not support sending and receiving " diff --git a/assuan/assuan-client.c b/assuan/assuan-client.c index 06e3966f..978c6954 100644 --- a/assuan/assuan-client.c +++ b/assuan/assuan-client.c @@ -161,9 +161,11 @@ assuan_transact (assuan_context_t ctx, if (!okay) { - rc = _assuan_error (atoi (line)); - if (rc < 100) - rc = ASSUAN_Server_Fault; + rc = atoi (line); + if (rc > 0 && rc < 100) + rc = _assuan_error (ASSUAN_Server_Fault); + else if (rc > 0 && rc <= 128) + rc = _assuan_error (rc); } else if (okay == 2) { diff --git a/assuan/assuan-defs.h b/assuan/assuan-defs.h index 7a96c0f8..fa04f0b2 100644 --- a/assuan/assuan-defs.h +++ b/assuan/assuan-defs.h @@ -179,6 +179,20 @@ struct assuan_context_s void (*input_notify_fnc)(assuan_context_t, const char *); void (*output_notify_fnc)(assuan_context_t, const char *); + /* This function is called right after a command has been processed. + It may be used to command related cleanup. */ + void (*post_cmd_notify_fnc)(assuan_context_t, int); + + /* 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. */ + unsigned int (*io_monitor)(assuan_context_t ctx, + int direction, + const char *line, + size_t linelen); + int input_fd; /* set by INPUT command */ int output_fd; /* set by OUTPUT command */ @@ -299,7 +313,7 @@ char *stpcpy (char *dest, const char *src); int setenv (const char *name, const char *value, int replace); #endif #ifndef HAVE_PUTC_UNLOCKED -int putc_unlocked (int c, FILE *stream) +int putc_unlocked (int c, FILE *stream); #endif #define DIM(v) (sizeof(v)/sizeof((v)[0])) diff --git a/assuan/assuan-domain-connect.c b/assuan/assuan-domain-connect.c deleted file mode 100644 index e69de29b..00000000 diff --git a/assuan/assuan-domain-server.c b/assuan/assuan-domain-server.c deleted file mode 100644 index e69de29b..00000000 diff --git a/assuan/assuan-handler.c b/assuan/assuan-handler.c index bf00d1a1..866db225 100644 --- a/assuan/assuan-handler.c +++ b/assuan/assuan-handler.c @@ -291,6 +291,16 @@ assuan_register_command (assuan_context_t ctx, return 0; } +int +assuan_register_post_cmd_notify (assuan_context_t ctx, + void (*fnc)(assuan_context_t, int)) +{ + if (!ctx) + return _assuan_error (ASSUAN_Invalid_Value); + ctx->post_cmd_notify_fnc = fnc; + return 0; +} + int assuan_register_bye_notify (assuan_context_t ctx, void (*fnc)(assuan_context_t)) @@ -506,14 +516,20 @@ process_request (assuan_context_t ctx) problem if they are not available. We need to make sure that we are using ELF because only this guarantees that weak symbol support is available in case GNU ld is not - used. */ + used. It seems that old gcc versions don't implement the + weak attribute properly but it works with the weak + pragma. */ + unsigned int source, code; int gpg_strerror_r (unsigned int err, char *buf, size_t buflen) __attribute__ ((weak)); - const char *gpg_strsource (unsigned int err) __attribute__ ((weak)); +#if !defined(HAVE_W32_SYSTEM) && __GNUC__ < 3 +#pragma weak gpg_strerror_r +#pragma weak gpg_strsource +#endif source = ((rc >> 24) & 0xff); code = (rc & 0x00ffffff); @@ -537,6 +553,9 @@ process_request (assuan_context_t ctx) rc = assuan_write_line (ctx, errline); } + if (ctx->post_cmd_notify_fnc) + ctx->post_cmd_notify_fnc (ctx, rc); + ctx->confidential = 0; if (ctx->okay_line) { @@ -633,6 +652,23 @@ assuan_get_active_fds (assuan_context_t ctx, int what, return n; } + +/* Two simple wrappers to make the expected function types match. */ +#ifdef HAVE_FUNOPEN +static int +fun1_cookie_write (void *cookie, const char *buffer, int orig_size) +{ + return _assuan_cookie_write_data (cookie, buffer, orig_size); +} +#endif /*HAVE_FUNOPEN*/ +#ifdef HAVE_FOPENCOOKIE +static ssize_t +fun2_cookie_write (void *cookie, const char *buffer, size_t orig_size) +{ + return _assuan_cookie_write_data (cookie, buffer, orig_size); +} +#endif /*HAVE_FOPENCOOKIE*/ + /* Return a FP to be used for data output. The FILE pointer is valid until the end of a handler. So a close is not needed. Assuan does all the buffering needed to insert the status line as well as the @@ -648,10 +684,14 @@ assuan_get_data_fp (assuan_context_t ctx) if (ctx->outbound.data.fp) return ctx->outbound.data.fp; - - ctx->outbound.data.fp = funopen (ctx, 0, - _assuan_cookie_write_data, +#ifdef HAVE_FUNOPEN + ctx->outbound.data.fp = funopen (ctx, 0, fun1_cookie_write, 0, _assuan_cookie_write_flush); +#else + ctx->outbound.data.fp = funopen (ctx, 0, fun2_cookie_write, + 0, _assuan_cookie_write_flush); +#endif + ctx->outbound.data.error = 0; return ctx->outbound.data.fp; #else diff --git a/assuan/assuan-io.c b/assuan/assuan-io.c index 0fe48b70..d1f0d5e4 100644 --- a/assuan/assuan-io.c +++ b/assuan/assuan-io.c @@ -23,12 +23,9 @@ #include #endif +#include #include #include -#include -#if HAVE_SYS_UIO_H -# include -#endif #include #include #ifdef HAVE_W32_SYSTEM @@ -39,65 +36,12 @@ #include "assuan-defs.h" -/* We can't include pth.h and we are not sure whether other headers - already included it. This we define macros with the same - values. */ -#define MY_PTH_FDMODE_ERROR (-1) -#define MY_PTH_FDMODE_POLL 0 -#define MY_PTH_FDMODE_BLOCK 1 -#define MY_PTH_FDMODE_NONBLOCK 2 - - -#ifndef _ASSUAN_NO_PTH -extern pid_t pth_waitpid (pid_t pid, int *status, int options); -extern ssize_t pth_read (int fd, void *buffer, size_t size); -extern ssize_t pth_write (int fd, const void *buffer, size_t size); -extern int pth_fdmode (int, int); -extern int pth_select(int, fd_set*, fd_set*, fd_set*, struct timeval*); - -#ifndef HAVE_W32_SYSTEM -#pragma weak pth_waitpid -#pragma weak pth_read -#pragma weak pth_write -#pragma weak pth_fdmode -#pragma weak pth_select -#endif -#endif /*!_ASSUAN_NO_PTH*/ - -#ifndef _ASSUAN_NO_PTH -/* Wrapper around pth_fdmode. */ -static int -my_pth_fdmode (int fd, int mode) -{ - if (pth_fdmode) - return pth_fdmode (fd, mode); - else - return MY_PTH_FDMODE_NONBLOCK; /* This is okay, given the way we use it. */ -} -#endif /*_ASSUAN_NO_PTH*/ - -#ifndef _ASSUAN_NO_PTH -/* Wrapper around pth_select. */ -static int -my_pth_select (int nfd, fd_set *rfds, fd_set *wfds, fd_set *efds, - struct timeval *timeout) -{ - if (pth_select) - return pth_select (nfd, rfds, wfds, efds, timeout); - else - return 1; /* Fake one fd ready; this is okay, given the way we use it. */ -} -#endif /*_ASSUAN_NO_PTH*/ #ifndef HAVE_W32_SYSTEM pid_t _assuan_waitpid (pid_t pid, int *status, int options) { -#ifdef _ASSUAN_NO_PTH return waitpid (pid, status, options); -#else - return (pth_waitpid ? pth_waitpid : waitpid) (pid, status, options); -#endif } #endif @@ -105,72 +49,26 @@ _assuan_waitpid (pid_t pid, int *status, int options) ssize_t _assuan_simple_read (assuan_context_t ctx, void *buffer, size_t size) { -#ifdef _ASSUAN_NO_PTH return read (ctx->inbound.fd, buffer, size); -#else -# ifndef HAVE_W32_SYSTEM - return (pth_read ? pth_read : read) (ctx->inbound.fd, buffer, size); -# else - return pth_read ? pth_read (ctx->inbound.fd, buffer, size) - : recv (ctx->inbound.fd, buffer, size, 0); -# endif -#endif } ssize_t _assuan_simple_write (assuan_context_t ctx, const void *buffer, size_t size) { -#ifdef _ASSUAN_NO_PTH return write (ctx->outbound.fd, buffer, size); -#else -# ifndef HAVE_W32_SYSTEM - return (pth_write ? pth_write : write) (ctx->outbound.fd, buffer, size); -# else - return pth_write ? pth_write (ctx->outbound.fd, buffer, size) - : send (ctx->outbound.fd, buffer, size, 0); -# endif -#endif } ssize_t _assuan_simple_sendmsg (assuan_context_t ctx, struct msghdr *msg) { -#if defined(HAVE_W32_SYSTEM) +#ifdef HAVE_W32_SYSTEM return _assuan_error (ASSUAN_Not_Implemented); -#elif defined(_ASSUAN_NO_PTH) +#else int ret; while ( (ret = sendmsg (ctx->outbound.fd, msg, 0)) == -1 && errno == EINTR) ; return ret; -#else - /* Pth does not provide a sendmsg function. Thus we implement it here. */ - int ret; - int fd = ctx->outbound.fd; - int fdmode; - - fdmode = my_pth_fdmode (fd, MY_PTH_FDMODE_POLL); - if (fdmode == MY_PTH_FDMODE_ERROR) - { - errno = EBADF; - return -1; - } - if (fdmode == MY_PTH_FDMODE_BLOCK) - { - fd_set fds; - - FD_ZERO (&fds); - FD_SET (fd, &fds); - while ( (ret = my_pth_select (fd+1, NULL, &fds, NULL, NULL)) < 0 - && errno == EINTR) - ; - if (ret < 0) - return -1; - } - - while ((ret = sendmsg (fd, msg, 0)) == -1 && errno == EINTR) - ; - return ret; #endif } @@ -178,40 +76,12 @@ _assuan_simple_sendmsg (assuan_context_t ctx, struct msghdr *msg) ssize_t _assuan_simple_recvmsg (assuan_context_t ctx, struct msghdr *msg) { -#if defined(HAVE_W32_SYSTEM) +#ifdef HAVE_W32_SYSTEM return _assuan_error (ASSUAN_Not_Implemented); -#elif defined(_ASSUAN_NO_PTH) +#else int ret; while ( (ret = recvmsg (ctx->inbound.fd, msg, 0)) == -1 && errno == EINTR) ; return ret; -#else - /* Pth does not provide a recvmsg function. Thus we implement it here. */ - int ret; - int fd = ctx->inbound.fd; - int fdmode; - - fdmode = my_pth_fdmode (fd, MY_PTH_FDMODE_POLL); - if (fdmode == MY_PTH_FDMODE_ERROR) - { - errno = EBADF; - return -1; - } - if (fdmode == MY_PTH_FDMODE_BLOCK) - { - fd_set fds; - - FD_ZERO (&fds); - FD_SET (fd, &fds); - while ( (ret = my_pth_select (fd+1, &fds, NULL, NULL, NULL)) < 0 - && errno == EINTR) - ; - if (ret < 0) - return -1; - } - - while ((ret = recvmsg (fd, msg, 0)) == -1 && errno == EINTR) - ; - return ret; #endif } diff --git a/assuan/assuan-pipe-server.c b/assuan/assuan-pipe-server.c index a19c88ec..f8851614 100644 --- a/assuan/assuan-pipe-server.c +++ b/assuan/assuan-pipe-server.c @@ -168,6 +168,7 @@ _assuan_release_context (assuan_context_t ctx) { xfree (ctx->hello_line); xfree (ctx->okay_line); + xfree (ctx->cmdtbl); xfree (ctx); } } diff --git a/assuan/assuan-uds.c b/assuan/assuan-uds.c index c7253928..77945fb5 100644 --- a/assuan/assuan-uds.c +++ b/assuan/assuan-uds.c @@ -44,6 +44,26 @@ #include "assuan-defs.h" +#ifdef USE_DESCRIPTOR_PASSING +/* Provide replacement for missing CMSG maccros. We assume that + size_t matches the alignment requirement. */ +#define MY_ALIGN(n) ((((n))+ sizeof(size_t)-1) & (size_t)~(sizeof(size_t)-1)) +#ifndef CMSG_SPACE +#define CMSG_SPACE(n) (MY_ALIGN(sizeof(struct cmsghdr)) + MY_ALIGN((n))) +#endif +#ifndef CMSG_LEN +#define CMSG_LEN(n) (MY_ALIGN(sizeof(struct cmsghdr)) + (n)) +#endif +#ifndef CMSG_FIRSTHDR +#define CMSG_FIRSTHDR(mhdr) \ + ((size_t)(mhdr)->msg_controllen >= sizeof (struct cmsghdr) \ + ? (struct cmsghdr*) (mhdr)->msg_control : (struct cmsghdr*)NULL) +#endif +#ifndef CMSG_DATA +#define CMSG_DATA(cmsg) ((unsigned char*)((struct cmsghdr*)(cmsg)+1)) +#endif +#endif /*USE_DESCRIPTOR_PASSING*/ + /* Read from a unix domain socket using sendmsg. @@ -55,7 +75,6 @@ uds_reader (assuan_context_t ctx, void *buf, size_t buflen) int len = ctx->uds.buffersize; #ifndef HAVE_W32_SYSTEM - if (!ctx->uds.bufferallocated) { ctx->uds.buffer = xtrymalloc (2048); @@ -68,11 +87,13 @@ uds_reader (assuan_context_t ctx, void *buf, size_t buflen) { struct msghdr msg; struct iovec iovec; +#ifdef USE_DESCRIPTOR_PASSING union { struct cmsghdr cm; char control[CMSG_SPACE(sizeof (int))]; } control_u; struct cmsghdr *cmptr; +#endif /*USE_DESCRIPTOR_PASSING*/ memset (&msg, 0, sizeof (msg)); @@ -82,8 +103,10 @@ uds_reader (assuan_context_t ctx, void *buf, size_t buflen) msg.msg_iovlen = 1; iovec.iov_base = ctx->uds.buffer; iovec.iov_len = ctx->uds.bufferallocated; +#ifdef USE_DESCRIPTOR_PASSING msg.msg_control = control_u.control; msg.msg_controllen = sizeof (control_u.control); +#endif len = _assuan_simple_recvmsg (ctx, &msg); if (len < 0) @@ -92,6 +115,7 @@ uds_reader (assuan_context_t ctx, void *buf, size_t buflen) ctx->uds.buffersize = len; ctx->uds.bufferoffset = 0; +#ifdef USE_DESCRIPTOR_PASSING cmptr = CMSG_FIRSTHDR (&msg); if (cmptr && cmptr->cmsg_len == CMSG_LEN (sizeof(int))) { @@ -112,9 +136,13 @@ uds_reader (assuan_context_t ctx, void *buf, size_t buflen) ctx->uds.pendingfds[ctx->uds.pendingfdscount++] = fd; } } +#endif /*USE_DESCRIPTOR_PASSING*/ } + #else /*HAVE_W32_SYSTEM*/ + len = recvfrom (ctx->inbound.fd, buf, buflen, 0, NULL, NULL); + #endif /*HAVE_W32_SYSTEM*/ /* Return some data to the user. */ @@ -149,8 +177,6 @@ uds_writer (assuan_context_t ctx, const void *buf, size_t buflen) msg.msg_iov = &iovec; iovec.iov_base = (void*)buf; iovec.iov_len = buflen; - msg.msg_control = 0; - msg.msg_controllen = 0; len = _assuan_simple_sendmsg (ctx, &msg); #else /*HAVE_W32_SYSTEM*/ @@ -167,7 +193,7 @@ uds_writer (assuan_context_t ctx, const void *buf, size_t buflen) static assuan_error_t uds_sendfd (assuan_context_t ctx, int fd) { -#ifndef HAVE_W32_SYSTEM +#ifdef USE_DESCRIPTOR_PASSING struct msghdr msg; struct iovec iovec; union { @@ -217,7 +243,7 @@ uds_sendfd (assuan_context_t ctx, int fd) static assuan_error_t uds_receivefd (assuan_context_t ctx, int *fd) { -#ifndef HAVE_W32_SYSTEM +#ifdef USE_DESCRIPTOR_PASSING int i; if (!ctx->uds.pendingfdscount) diff --git a/assuan/assuan-util.c b/assuan/assuan-util.c index 3e627fc5..d12277fc 100644 --- a/assuan/assuan-util.c +++ b/assuan/assuan-util.c @@ -125,6 +125,21 @@ assuan_end_confidential (assuan_context_t ctx) } +void +assuan_set_io_monitor (assuan_context_t ctx, + unsigned int (*monitor)(assuan_context_t ctx, + int direction, + const char *line, + size_t linelen)) +{ + if (ctx) + { + ctx->io_monitor = monitor; + } +} + + + /* For context CTX, set the flag FLAG to VALUE. Values for flags are usually 1 or 0 but certain flags might allow for other values; diff --git a/assuan/assuan.h b/assuan/assuan.h index 0f36cddb..4916d6fb 100644 --- a/assuan/assuan.h +++ b/assuan/assuan.h @@ -95,6 +95,8 @@ int _gpgme_ath_recvmsg (int s, struct msghdr *msg, int flags); #define _ASSUAN_PREFIX(x) _ASSUAN_PREFIX2(_ASSUAN_EXT_SYM_PREFIX,x) #define assuan_ _ASSUAN_PREFIX(assuan_) #define assuan_register_command _ASSUAN_PREFIX(assuan_register_command) +#define assuan_register_post_cmd_notify \ + _ASSUAN_PREFIX(assuan_register_post_cmd_notify) #define assuan_register_bye_notify _ASSUAN_PREFIX(assuan_register_bye_notify) #define assuan_register_reset_notify \ _ASSUAN_PREFIX(assuan_register_reset_notify) @@ -146,6 +148,7 @@ int _gpgme_ath_recvmsg (int s, struct msghdr *msg, int flags); #define assuan_set_error _ASSUAN_PREFIX(assuan_set_error) #define assuan_set_pointer _ASSUAN_PREFIX(assuan_set_pointer) #define assuan_get_pointer _ASSUAN_PREFIX(assuan_get_pointer) +#define assuan_set_io_monitor _ASSUAN_PREFIX(assuan_set_io_monitor) #define assuan_begin_confidential _ASSUAN_PREFIX(assuan_begin_confidential) #define assuan_end_confidential _ASSUAN_PREFIX(assuan_end_confidential) #define assuan_strerror _ASSUAN_PREFIX(assuan_strerror) @@ -282,9 +285,11 @@ extern "C" #define ASSUAN_Unexpected_Data 125 #define ASSUAN_Invalid_Status 126 #define ASSUAN_Locale_Problem 127 +#endif #define ASSUAN_Not_Confirmed 128 /* Warning: Don't use the Error codes, below they are deprecated. */ +#ifndef _ASSUAN_IN_LIBASSUAN #define ASSUAN_Bad_Certificate 201 #define ASSUAN_Bad_Certificate_Chain 202 #define ASSUAN_Missing_Certificate 203 @@ -367,6 +372,8 @@ typedef struct assuan_context_s *ASSUAN_CONTEXT _ASSUAN_DEPRECATED; int assuan_register_command (assuan_context_t ctx, const char *cmd_string, int (*handler)(assuan_context_t, char *)); +int assuan_register_post_cmd_notify (assuan_context_t ctx, + void (*fnc)(assuan_context_t, int)); int assuan_register_bye_notify (assuan_context_t ctx, void (*fnc)(assuan_context_t)); int assuan_register_reset_notify (assuan_context_t ctx, @@ -497,6 +504,12 @@ void *assuan_get_pointer (assuan_context_t ctx); void assuan_begin_confidential (assuan_context_t ctx); void assuan_end_confidential (assuan_context_t ctx); +void assuan_set_io_monitor (assuan_context_t ctx, + unsigned int (*monitor)(assuan_context_t ctx, + int direction, + const char *line, + size_t linelen)); + /* For context CTX, set the flag FLAG to VALUE. Values for flags are usually 1 or 0 but certain flags might allow for other values; see the description of the type assuan_flag_t for details. */ diff --git a/assuan/mkerrors b/assuan/mkerrors index ded7ba31..57485411 100755 --- a/assuan/mkerrors +++ b/assuan/mkerrors @@ -84,6 +84,7 @@ _assuan_error (int oldcode) case ASSUAN_Unknown_Command: n = 275; break; case ASSUAN_Canceled: n = 277; break; case ASSUAN_No_Secret_Key: n = 17; break; + case ASSUAN_Not_Confirmed: n = 114; break; case ASSUAN_Read_Error: switch (errno) @@ -200,6 +201,7 @@ cat <