diff options
Diffstat (limited to 'assuan/assuan-socket-server.c')
-rw-r--r-- | assuan/assuan-socket-server.c | 63 |
1 files changed, 39 insertions, 24 deletions
diff --git a/assuan/assuan-socket-server.c b/assuan/assuan-socket-server.c index 5c461644..c536dba4 100644 --- a/assuan/assuan-socket-server.c +++ b/assuan/assuan-socket-server.c @@ -1,5 +1,5 @@ /* assuan-socket-server.c - Assuan socket based server - * Copyright (C) 2002 Free Software Foundation, Inc. + * Copyright (C) 2002, 2007 Free Software Foundation, Inc. * * This file is part of Assuan. * @@ -14,9 +14,7 @@ * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public - * License along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, - * USA. + * License along with this program; if not, see <http://www.gnu.org/licenses/>. */ #include <config.h> @@ -40,14 +38,13 @@ #include "assuan-defs.h" -static struct assuan_io io = { _assuan_simple_read, - _assuan_simple_write }; - +static struct assuan_io io = { _assuan_simple_read, _assuan_simple_write, + NULL, NULL }; static int accept_connection_bottom (assuan_context_t ctx) { - int fd = ctx->connected_fd; + assuan_fd_t fd = ctx->connected_fd; ctx->peercred.valid = 0; #ifdef HAVE_SO_PEERCRED @@ -89,16 +86,23 @@ accept_connection_bottom (assuan_context_t ctx) static int accept_connection (assuan_context_t ctx) { - int fd; + assuan_fd_t fd; struct sockaddr_un clnt_addr; socklen_t len = sizeof clnt_addr; - fd = accept (ctx->listen_fd, (struct sockaddr*)&clnt_addr, &len ); - if (fd == -1) + fd = SOCKET2HANDLE(accept (HANDLE2SOCKET(ctx->listen_fd), + (struct sockaddr*)&clnt_addr, &len )); + if (fd == ASSUAN_INVALID_FD) { ctx->os_errno = errno; return _assuan_error (ASSUAN_Accept_Failed); } + if (_assuan_sock_check_nonce (fd, &ctx->listen_nonce)) + { + _assuan_close (fd); + ctx->os_errno = EACCES; + return _assuan_error (ASSUAN_Accept_Failed); + } ctx->connected_fd = fd; return accept_connection_bottom (ctx); @@ -107,12 +111,12 @@ accept_connection (assuan_context_t ctx) static int finish_connection (assuan_context_t ctx) { - if (ctx->inbound.fd != -1) + if (ctx->inbound.fd != ASSUAN_INVALID_FD) { _assuan_close (ctx->inbound.fd); } - ctx->inbound.fd = -1; - ctx->outbound.fd = -1; + ctx->inbound.fd = ASSUAN_INVALID_FD; + ctx->outbound.fd = ASSUAN_INVALID_FD; return 0; } @@ -126,15 +130,15 @@ deinit_socket_server (assuan_context_t ctx) /* Initialize a server for the socket LISTEN_FD which has already be put into listen mode */ int -assuan_init_socket_server (assuan_context_t *r_ctx, int listen_fd) +assuan_init_socket_server (assuan_context_t *r_ctx, assuan_fd_t listen_fd) { return assuan_init_socket_server_ext (r_ctx, listen_fd, 0); } /* Initialize a server using the already accepted socket FD. This - fucntion is deprecated. */ + function is deprecated. */ int -assuan_init_connected_socket_server (assuan_context_t *r_ctx, int fd) +assuan_init_connected_socket_server (assuan_context_t *r_ctx, assuan_fd_t fd) { return assuan_init_socket_server_ext (r_ctx, fd, 2); } @@ -145,7 +149,7 @@ assuan_init_connected_socket_server (assuan_context_t *r_ctx, int fd) 1 - FD has already been accepted. */ int -assuan_init_socket_server_ext (assuan_context_t *r_ctx, int fd, +assuan_init_socket_server_ext (assuan_context_t *r_ctx, assuan_fd_t fd, unsigned int flags) { assuan_context_t ctx; @@ -158,21 +162,21 @@ assuan_init_socket_server_ext (assuan_context_t *r_ctx, int fd, ctx->is_server = 1; if ((flags & 2)) ctx->pipe_mode = 1; /* We want a second accept to indicate EOF. */ - ctx->input_fd = -1; - ctx->output_fd = -1; + ctx->input_fd = ASSUAN_INVALID_FD; + ctx->output_fd = ASSUAN_INVALID_FD; - ctx->inbound.fd = -1; - ctx->outbound.fd = -1; + ctx->inbound.fd = ASSUAN_INVALID_FD; + ctx->outbound.fd = ASSUAN_INVALID_FD; if ((flags & 2)) { - ctx->listen_fd = -1; + ctx->listen_fd = ASSUAN_INVALID_FD; ctx->connected_fd = fd; } else { ctx->listen_fd = fd; - ctx->connected_fd = -1; + ctx->connected_fd = ASSUAN_INVALID_FD; } ctx->deinit_handler = (flags & 1)? _assuan_uds_deinit:deinit_socket_server; ctx->accept_handler = ((flags & 2) @@ -191,3 +195,14 @@ assuan_init_socket_server_ext (assuan_context_t *r_ctx, int fd, *r_ctx = ctx; return rc; } + + +/* Save a copy of NONCE in context CTX. This should be used to + register the server's nonce with an context established by + assuan_init_socket_server. */ +void +assuan_set_sock_nonce (assuan_context_t ctx, assuan_sock_nonce_t *nonce) +{ + if (ctx && nonce) + ctx->listen_nonce = *nonce; +} |