diff options
author | Werner Koch <wk@gnupg.org> | 2006-09-14 11:17:33 +0000 |
---|---|---|
committer | Werner Koch <wk@gnupg.org> | 2006-09-14 11:17:33 +0000 |
commit | f4f90811735b1f599e207e49d449abfa9d47897d (patch) | |
tree | b509639246290da27975771f95b8d46cf57ec60c /src | |
parent | 7a22110230b9f1e5b5a73c065571935df21ef9b1 (diff) | |
download | libassuan-f4f90811735b1f599e207e49d449abfa9d47897d.tar.gz |
Preparing a new releaselibassuan-0.9.0
Diffstat (limited to 'src')
-rw-r--r-- | src/ChangeLog | 12 | ||||
-rw-r--r-- | src/assuan-buffer.c | 22 | ||||
-rw-r--r-- | src/assuan-client.c | 4 | ||||
-rw-r--r-- | src/assuan-connect.c | 22 | ||||
-rw-r--r-- | src/assuan-defs.h | 51 | ||||
-rw-r--r-- | src/assuan-io.c | 22 | ||||
-rw-r--r-- | src/assuan-pipe-connect.c | 14 | ||||
-rw-r--r-- | src/assuan-pipe-server.c | 18 | ||||
-rw-r--r-- | src/assuan-socket-server.c | 25 | ||||
-rw-r--r-- | src/assuan.h | 28 |
10 files changed, 149 insertions, 69 deletions
diff --git a/src/ChangeLog b/src/ChangeLog index 04fb712..1126a1e 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,15 @@ +2006-09-14 Werner Koch <wk@g10code.com> + + * assuan-io.c (_assuan_waitpid): New. Changed all waitpid calls + to this. + + * assuan.h (_ASSUAN_DEPRECATED): New internal macro. + (assuan_pipe_connect2): Declare deprecated. + (assuan_init_connected_socket_server): Declare deprecated. + + * assuan-connect.c (assuan_get_peercred): New. + * assuan-socket-server.c (accept_connection_bottom): Save uid and gid. + 2006-09-13 Werner Koch <wk@g10code.com> * assuan-client.c (assuan_transact): Need to map the error code. diff --git a/src/assuan-buffer.c b/src/assuan-buffer.c index f7b45a3..0a49b0d 100644 --- a/src/assuan-buffer.c +++ b/src/assuan-buffer.c @@ -35,7 +35,7 @@ /* Extended version of write(2) to guarantee that all bytes are written. Returns 0 on success or -1 and ERRNO on failure. */ static int -writen (ASSUAN_CONTEXT ctx, const char *buffer, size_t length) +writen (assuan_context_t ctx, const char *buffer, size_t length) { while (length) { @@ -57,7 +57,7 @@ writen (ASSUAN_CONTEXT ctx, const char *buffer, size_t length) failure. EOF is indictated by setting the integer at address R_EOF. */ static int -readline (ASSUAN_CONTEXT ctx, char *buf, size_t buflen, +readline (assuan_context_t ctx, char *buf, size_t buflen, int *r_nread, int *r_eof) { size_t nleft = buflen; @@ -96,7 +96,7 @@ readline (ASSUAN_CONTEXT ctx, char *buf, size_t buflen, /* Function returns an Assuan error. */ int -_assuan_read_line (ASSUAN_CONTEXT ctx) +_assuan_read_line (assuan_context_t ctx) { char *line = ctx->inbound.line; int nread, atticlen; @@ -216,7 +216,7 @@ _assuan_read_line (ASSUAN_CONTEXT ctx) See also: assuan_pending_line(). */ assuan_error_t -assuan_read_line (ASSUAN_CONTEXT ctx, char **line, size_t *linelen) +assuan_read_line (assuan_context_t ctx, char **line, size_t *linelen) { assuan_error_t err; @@ -233,7 +233,7 @@ assuan_read_line (ASSUAN_CONTEXT ctx, char **line, size_t *linelen) /* Return true if a full line is buffered (i.e. an entire line may be read without any I/O). */ int -assuan_pending_line (ASSUAN_CONTEXT ctx) +assuan_pending_line (assuan_context_t ctx) { return ctx && ctx->inbound.attic.pending; } @@ -300,7 +300,7 @@ _assuan_write_line (assuan_context_t ctx, const char *prefix, assuan_error_t -assuan_write_line (ASSUAN_CONTEXT ctx, const char *line) +assuan_write_line (assuan_context_t ctx, const char *line) { size_t len; const char *s; @@ -329,7 +329,7 @@ assuan_write_line (ASSUAN_CONTEXT ctx, const char *line) int _assuan_cookie_write_data (void *cookie, const char *buffer, size_t orig_size) { - ASSUAN_CONTEXT ctx = cookie; + assuan_context_t ctx = cookie; size_t size = orig_size; char *line; size_t linelen; @@ -406,7 +406,7 @@ _assuan_cookie_write_data (void *cookie, const char *buffer, size_t orig_size) int _assuan_cookie_write_flush (void *cookie) { - ASSUAN_CONTEXT ctx = cookie; + assuan_context_t ctx = cookie; char *line; size_t linelen; @@ -462,7 +462,7 @@ _assuan_cookie_write_flush (void *cookie) **/ assuan_error_t -assuan_send_data (ASSUAN_CONTEXT ctx, const void *buffer, size_t length) +assuan_send_data (assuan_context_t ctx, const void *buffer, size_t length) { if (!ctx) return _assuan_error (ASSUAN_Invalid_Value); @@ -488,7 +488,7 @@ assuan_send_data (ASSUAN_CONTEXT ctx, const void *buffer, size_t length) } assuan_error_t -assuan_sendfd (ASSUAN_CONTEXT ctx, int fd) +assuan_sendfd (assuan_context_t ctx, int fd) { if (! ctx->io->sendfd) return set_error (ctx, Not_Implemented, @@ -498,7 +498,7 @@ assuan_sendfd (ASSUAN_CONTEXT ctx, int fd) } assuan_error_t -assuan_receivefd (ASSUAN_CONTEXT ctx, int *fd) +assuan_receivefd (assuan_context_t ctx, int *fd) { if (! ctx->io->receivefd) return set_error (ctx, Not_Implemented, diff --git a/src/assuan-client.c b/src/assuan-client.c index f82abbd..a5d9798 100644 --- a/src/assuan-client.c +++ b/src/assuan-client.c @@ -34,7 +34,7 @@ assuan_error_t -_assuan_read_from_server (ASSUAN_CONTEXT ctx, int *okay, int *off) +_assuan_read_from_server (assuan_context_t ctx, int *okay, int *off) { char *line; int linelen; @@ -130,7 +130,7 @@ _assuan_read_from_server (ASSUAN_CONTEXT ctx, int *okay, int *off) * will altter return an Assuan error (write erro in most cases). **/ assuan_error_t -assuan_transact (ASSUAN_CONTEXT ctx, +assuan_transact (assuan_context_t ctx, const char *command, int (*data_cb)(void *, const void *, size_t), void *data_cb_arg, diff --git a/src/assuan-connect.c b/src/assuan-connect.c index a9d9eeb..92995d8 100644 --- a/src/assuan-connect.c +++ b/src/assuan-connect.c @@ -50,10 +50,30 @@ assuan_disconnect (assuan_context_t ctx) } } -/* Return the PID of the peer or -1 if not known. */ +/* Return the PID of the peer or -1 if not known. This function works + in some situations where assuan_get_ucred fails. */ pid_t assuan_get_pid (assuan_context_t ctx) { return (ctx && ctx->pid)? ctx->pid : -1; } + +/* Return user credentials. PID, UID and GID amy be gived as NULL if + you are not interested in this value. For getting the pid of the + peer the assuan_get_pid is usually better suited. */ +assuan_error_t +assuan_get_peercred (assuan_context_t ctx, pid_t *pid, uid_t *uid, gid_t *gid) +{ + if (!ctx) + return _assuan_error (ASSUAN_Invalid_Value); + if (!ctx->peercred.valid) + return _assuan_error (ASSUAN_General_Error); + if (pid) + *pid = ctx->peercred.pid; + if (uid) + *uid = ctx->peercred.uid; + if (gid) + *gid = ctx->peercred.gid; + return 0; +} diff --git a/src/assuan-defs.h b/src/assuan-defs.h index 93aca85..868ef0a 100644 --- a/src/assuan-defs.h +++ b/src/assuan-defs.h @@ -67,7 +67,7 @@ char * stpcpy (char *dest, const char *src); struct cmdtbl_s { const char *name; - int (*handler)(ASSUAN_CONTEXT, char *line); + int (*handler)(assuan_context_t, char *line); }; @@ -76,13 +76,13 @@ struct cmdtbl_s struct assuan_io { /* Routine to read from input_fd. */ - ssize_t (*readfnc) (ASSUAN_CONTEXT, void *, size_t); + ssize_t (*readfnc) (assuan_context_t, void *, size_t); /* Routine to write to output_fd. */ - ssize_t (*writefnc) (ASSUAN_CONTEXT, const void *, size_t); + ssize_t (*writefnc) (assuan_context_t, const void *, size_t); /* Send a file descriptor. */ - assuan_error_t (*sendfd) (ASSUAN_CONTEXT, int); + assuan_error_t (*sendfd) (assuan_context_t, int); /* Receive a file descriptor. */ - assuan_error_t (*receivefd) (ASSUAN_CONTEXT, int *); + assuan_error_t (*receivefd) (assuan_context_t, int *); }; @@ -140,6 +140,12 @@ struct assuan_context_s int listen_fd; /* The fd we are listening on (used by socket servers) */ int connected_fd; /* helper */ + struct { + int valid; /* Whether this structure has valid information. */ + pid_t pid; /* The pid of the peer. */ + uid_t uid; /* The uid of the peer. */ + gid_t gid; /* The gid of the peer. */ + } peercred; /* Used for Unix domain sockets. */ struct sockaddr_un myaddr; @@ -158,20 +164,20 @@ struct assuan_context_s int pendingfdscount; /* Number of received descriptors. */ } uds; - void (*deinit_handler)(ASSUAN_CONTEXT); - int (*accept_handler)(ASSUAN_CONTEXT); - int (*finish_handler)(ASSUAN_CONTEXT); + void (*deinit_handler)(assuan_context_t); + int (*accept_handler)(assuan_context_t); + int (*finish_handler)(assuan_context_t); struct cmdtbl_s *cmdtbl; size_t cmdtbl_used; /* used entries */ size_t cmdtbl_size; /* allocated size of table */ - void (*bye_notify_fnc)(ASSUAN_CONTEXT); - void (*reset_notify_fnc)(ASSUAN_CONTEXT); - void (*cancel_notify_fnc)(ASSUAN_CONTEXT); - int (*option_handler_fnc)(ASSUAN_CONTEXT,const char*, const char*); - void (*input_notify_fnc)(ASSUAN_CONTEXT, const char *); - void (*output_notify_fnc)(ASSUAN_CONTEXT, const char *); + void (*bye_notify_fnc)(assuan_context_t); + void (*reset_notify_fnc)(assuan_context_t); + void (*cancel_notify_fnc)(assuan_context_t); + int (*option_handler_fnc)(assuan_context_t,const char*, const char*); + void (*input_notify_fnc)(assuan_context_t, const char *); + void (*output_notify_fnc)(assuan_context_t, const char *); int input_fd; /* set by INPUT command */ int output_fd; /* set by OUTPUT command */ @@ -181,8 +187,8 @@ struct assuan_context_s }; /*-- assuan-pipe-server.c --*/ -int _assuan_new_context (ASSUAN_CONTEXT *r_ctx); -void _assuan_release_context (ASSUAN_CONTEXT ctx); +int _assuan_new_context (assuan_context_t *r_ctx); +void _assuan_release_context (assuan_context_t ctx); /*-- assuan-uds.c --*/ void _assuan_uds_close_fds (assuan_context_t ctx); @@ -191,17 +197,18 @@ void _assuan_init_uds_io (assuan_context_t ctx); /*-- assuan-handler.c --*/ -int _assuan_register_std_commands (ASSUAN_CONTEXT ctx); +int _assuan_register_std_commands (assuan_context_t ctx); /*-- assuan-buffer.c --*/ -int _assuan_read_line (ASSUAN_CONTEXT ctx); +int _assuan_read_line (assuan_context_t ctx); int _assuan_cookie_write_data (void *cookie, const char *buffer, size_t size); int _assuan_cookie_write_flush (void *cookie); assuan_error_t _assuan_write_line (assuan_context_t ctx, const char *prefix, const char *line, size_t len); /*-- assuan-client.c --*/ -assuan_error_t _assuan_read_from_server (ASSUAN_CONTEXT ctx, int *okay, int *off); +assuan_error_t _assuan_read_from_server (assuan_context_t ctx, + int *okay, int *off); /*-- assuan-error.c --*/ @@ -254,8 +261,10 @@ void _assuan_log_sanitized_string (const char *string); /*-- assuan-io.c --*/ -ssize_t _assuan_simple_read (ASSUAN_CONTEXT ctx, void *buffer, size_t size); -ssize_t _assuan_simple_write (ASSUAN_CONTEXT ctx, const void *buffer, +pid_t _assuan_waitpid (pid_t pid, int *status, int options); + +ssize_t _assuan_simple_read (assuan_context_t ctx, void *buffer, size_t size); +ssize_t _assuan_simple_write (assuan_context_t ctx, const void *buffer, size_t size); ssize_t _assuan_simple_sendmsg (assuan_context_t ctx, struct msghdr *msg); ssize_t _assuan_simple_recvmsg (assuan_context_t ctx, struct msghdr *msg); diff --git a/src/assuan-io.c b/src/assuan-io.c index 3a3a017..0fe48b7 100644 --- a/src/assuan-io.c +++ b/src/assuan-io.c @@ -25,13 +25,16 @@ #include <sys/types.h> #include <sys/socket.h> +#include <sys/wait.h> #if HAVE_SYS_UIO_H -#include <sys/uio.h> +# include <sys/uio.h> #endif #include <unistd.h> #include <errno.h> #ifdef HAVE_W32_SYSTEM -#include <windows.h> +# include <windows.h> +#else +# include <sys/wait.h> #endif #include "assuan-defs.h" @@ -46,12 +49,14 @@ #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 @@ -84,6 +89,17 @@ my_pth_select (int nfd, fd_set *rfds, fd_set *wfds, fd_set *efds, } #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 ssize_t @@ -98,7 +114,7 @@ _assuan_simple_read (assuan_context_t ctx, void *buffer, size_t size) return pth_read ? pth_read (ctx->inbound.fd, buffer, size) : recv (ctx->inbound.fd, buffer, size, 0); # endif -# endif +#endif } ssize_t diff --git a/src/assuan-pipe-connect.c b/src/assuan-pipe-connect.c index 5dd91cc..d389741 100644 --- a/src/assuan-pipe-connect.c +++ b/src/assuan-pipe-connect.c @@ -126,7 +126,7 @@ do_finish (assuan_context_t ctx) #ifndef HAVE_W32_SYSTEM #ifndef _ASSUAN_USE_DOUBLE_FORK if (!ctx->flags.no_waitpid) - waitpid (ctx->pid, NULL, 0); + _assuan_waitpid (ctx->pid, NULL, 0); ctx->pid = -1; #endif #endif /*!HAVE_W32_SYSTEM*/ @@ -342,7 +342,7 @@ pipe_connect_unix (assuan_context_t *ctx, } #ifdef _ASSUAN_USE_DOUBLE_FORK - waitpid ((*ctx)->pid, NULL, 0); + _assuan_waitpid ((*ctx)->pid, NULL, 0); (*ctx)->pid = -1; #endif @@ -525,7 +525,7 @@ socketpair_connect (assuan_context_t *ctx, #ifdef _ASSUAN_USE_DOUBLE_FORK - waitpid ((*ctx)->pid, NULL, 0); + _assuan_waitpid ((*ctx)->pid, NULL, 0); (*ctx)->pid = -1; #endif @@ -824,13 +824,7 @@ assuan_pipe_connect (assuan_context_t *ctx, const char *name, } -/* Connect to a server over a pipe, creating the assuan context and - returning it in CTX. The server filename is NAME, the argument - vector in ARGV. FD_CHILD_LIST is a -1 terminated list of file - descriptors not to close in the child. ATFORK is called in the - child right after the fork; ATFORKVALUE is passed as the first - argument and 0 is passed as the second argument. The ATFORK - function should only act if the second value is 0. */ + assuan_error_t assuan_pipe_connect2 (assuan_context_t *ctx, const char *name, const char *const argv[], diff --git a/src/assuan-pipe-server.c b/src/assuan-pipe-server.c index 18f8cc5..a19c88e 100644 --- a/src/assuan-pipe-server.c +++ b/src/assuan-pipe-server.c @@ -34,20 +34,20 @@ static void -deinit_pipe_server (ASSUAN_CONTEXT ctx) +deinit_pipe_server (assuan_context_t ctx) { /* nothing to do for this simple server */ } static int -accept_connection (ASSUAN_CONTEXT ctx) +accept_connection (assuan_context_t ctx) { /* This is a NOP for a pipe server */ return 0; } static int -finish_connection (ASSUAN_CONTEXT ctx) +finish_connection (assuan_context_t ctx) { /* This is a NOP for a pipe server */ return 0; @@ -56,13 +56,13 @@ finish_connection (ASSUAN_CONTEXT ctx) /* Create a new context. Note that the handlers are set up for a pipe server/client - this way we don't need extra dummy functions */ int -_assuan_new_context (ASSUAN_CONTEXT *r_ctx) +_assuan_new_context (assuan_context_t *r_ctx) { static struct assuan_io io = { _assuan_simple_read, _assuan_simple_write, 0, 0 }; - ASSUAN_CONTEXT ctx; + assuan_context_t ctx; int rc; *r_ctx = NULL; @@ -104,14 +104,14 @@ is_valid_socket (const char *s) int -assuan_init_pipe_server (ASSUAN_CONTEXT *r_ctx, int filedes[2]) +assuan_init_pipe_server (assuan_context_t *r_ctx, int filedes[2]) { int rc; rc = _assuan_new_context (r_ctx); if (!rc) { - ASSUAN_CONTEXT ctx = *r_ctx; + assuan_context_t ctx = *r_ctx; const char *s; unsigned long ul; @@ -162,7 +162,7 @@ assuan_init_pipe_server (ASSUAN_CONTEXT *r_ctx, int filedes[2]) void -_assuan_release_context (ASSUAN_CONTEXT ctx) +_assuan_release_context (assuan_context_t ctx) { if (ctx) { @@ -173,7 +173,7 @@ _assuan_release_context (ASSUAN_CONTEXT ctx) } void -assuan_deinit_server (ASSUAN_CONTEXT ctx) +assuan_deinit_server (assuan_context_t ctx) { if (ctx) { diff --git a/src/assuan-socket-server.c b/src/assuan-socket-server.c index 468826e..3cc9bae 100644 --- a/src/assuan-socket-server.c +++ b/src/assuan-socket-server.c @@ -43,16 +43,24 @@ accept_connection_bottom (assuan_context_t ctx) { int fd = ctx->connected_fd; + ctx->peercred.valid = 0; #ifdef HAVE_SO_PEERCRED { - /* This overrides any already set PID if the function returns a - valid one. */ struct ucred cr; - int cl = sizeof cr; - - if ( !getsockopt (fd, SOL_SOCKET, SO_PEERCRED, &cr, &cl) - && cr.pid != (pid_t)-1 && cr.pid ) - ctx->pid = cr.pid; + socklen_t cl = sizeof cr; + + if ( !getsockopt (fd, SOL_SOCKET, SO_PEERCRED, &cr, &cl)) + { + ctx->peercred.pid = cr.pid; + ctx->peercred.uid = cr.uid; + ctx->peercred.gid = cr.gid; + ctx->peercred.valid = 1; + + /* This overrides any already set PID if the function returns + a valid one. */ + if (cr.pid != (pid_t)-1 && cr.pid) + ctx->pid = cr.pid; + } } #endif @@ -117,7 +125,8 @@ assuan_init_socket_server (assuan_context_t *r_ctx, int listen_fd) return assuan_init_socket_server_ext (r_ctx, listen_fd, 0); } -/* Initialize a server using the already accepted socket FD. */ +/* Initialize a server using the already accepted socket FD. This + fucntion is deprecated. */ int assuan_init_connected_socket_server (assuan_context_t *r_ctx, int fd) { diff --git a/src/assuan.h b/src/assuan.h index 8a22f90..6265633 100644 --- a/src/assuan.h +++ b/src/assuan.h @@ -99,6 +99,7 @@ #define assuan_socket_connect_ext _ASSUAN_PREFIX(assuan_socket_connect_ext) #define assuan_disconnect _ASSUAN_PREFIX(assuan_disconnect) #define assuan_get_pid _ASSUAN_PREFIX(assuan_get_pid) +#define assuan_get_peercred _ASSUAN_PREFIX(assuan_get_peercred) #define assuan_transact _ASSUAN_PREFIX(assuan_transact) #define assuan_inquire _ASSUAN_PREFIX(assuan_inquire) #define assuan_read_line _ASSUAN_PREFIX(assuan_read_line) @@ -168,9 +169,25 @@ extern "C" #endif #endif -#ifndef _ASSUAN_ONLY_GPG_ERRORS + +/* Check for compiler features. */ +#if __GNUC__ +#define _ASSUAN_GCC_VERSION (__GNUC__ * 10000 \ + + __GNUC_MINOR__ * 100 \ + + __GNUC_PATCHLEVEL__) + +#if _ASSUAN_GCC_VERSION > 30100 +#define _ASSUAN_DEPRECATED __attribute__ ((__deprecated__)) +#endif +#endif +#ifndef _ASSUAN_DEPRECATED +#define _ASSUAN_DEPRECATED +#endif + + /* Assuan error codes. These are only used by old applications or those applications which won't make use of libgpg-error. */ +#ifndef _ASSUAN_ONLY_GPG_ERRORS typedef enum { #ifndef _ASSUAN_IN_LIBASSUAN @@ -311,7 +328,7 @@ assuan_flag_t; struct assuan_context_s; typedef struct assuan_context_s *assuan_context_t; #ifndef _ASSUAN_ONLY_GPG_ERRORS -typedef struct assuan_context_s *ASSUAN_CONTEXT; +typedef struct assuan_context_s *ASSUAN_CONTEXT _ASSUAN_DEPRECATED; #endif /*_ASSUAN_ONLY_GPG_ERRORS*/ /*-- assuan-handler.c --*/ @@ -366,7 +383,8 @@ void assuan_deinit_server (assuan_context_t ctx); /*-- assuan-socket-server.c --*/ int assuan_init_socket_server (assuan_context_t *r_ctx, int listen_fd); -int assuan_init_connected_socket_server (assuan_context_t *r_ctx, int fd); +int assuan_init_connected_socket_server (assuan_context_t *r_ctx, + int fd) _ASSUAN_DEPRECATED; int assuan_init_socket_server_ext (assuan_context_t *r_ctx, int fd, unsigned int flags); @@ -380,7 +398,7 @@ assuan_error_t assuan_pipe_connect2 (assuan_context_t *ctx, const char *const argv[], int *fd_child_list, void (*atfork) (void*, int), - void *atforkvalue); + void *atforkvalue) _ASSUAN_DEPRECATED; assuan_error_t assuan_pipe_connect_ext (assuan_context_t *ctx, const char *name, const char *const argv[], @@ -401,6 +419,8 @@ assuan_error_t assuan_socket_connect_ext (assuan_context_t *ctx, /*-- assuan-connect.c --*/ void assuan_disconnect (assuan_context_t ctx); pid_t assuan_get_pid (assuan_context_t ctx); +assuan_error_t assuan_get_peercred (assuan_context_t ctx, + pid_t *pid, uid_t *uid, gid_t *gid); /*-- assuan-client.c --*/ assuan_error_t |