diff options
author | Marcus Brinkmann <[email protected]> | 2006-09-19 14:01:54 +0000 |
---|---|---|
committer | Marcus Brinkmann <[email protected]> | 2006-09-19 14:01:54 +0000 |
commit | 9e09d93de83fe1160689acb36b082c02ccb52716 (patch) | |
tree | 807126be9dd89fe2850ad748de978de0c5d3b340 /assuan/assuan-pipe-server.c | |
parent | 2006-07-29 Marcus Brinkmann <[email protected]> (diff) | |
download | gpgme-9e09d93de83fe1160689acb36b082c02ccb52716.tar.gz gpgme-9e09d93de83fe1160689acb36b082c02ccb52716.zip |
assuan/
Update to current version.
2006-09-19 Marcus Brinkmann <[email protected]>
* configure.ac: Turn stpcpy into a replacement function.
Check for unistd.h and add setenv as replacement function.
gpgme/
2006-09-19 Marcus Brinkmann <[email protected]>
* setenv.c: New file.
Diffstat (limited to '')
-rw-r--r-- | assuan/assuan-pipe-server.c | 61 |
1 files changed, 48 insertions, 13 deletions
diff --git a/assuan/assuan-pipe-server.c b/assuan/assuan-pipe-server.c index beff9a3e..a19c88ec 100644 --- a/assuan/assuan-pipe-server.c +++ b/assuan/assuan-pipe-server.c @@ -15,12 +15,15 @@ * * 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, + * USA. */ #include <config.h> #include <stdlib.h> #include <stdio.h> +#include <sys/types.h> +#include <sys/stat.h> #include <unistd.h> #ifdef HAVE_W32_SYSTEM #include <windows.h> @@ -31,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; @@ -53,19 +56,19 @@ 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; ctx = xtrycalloc (1, sizeof *ctx); if (!ctx) - return ASSUAN_Out_Of_Core; + return _assuan_error (ASSUAN_Out_Of_Core); ctx->input_fd = -1; ctx->output_fd = -1; @@ -88,15 +91,27 @@ _assuan_new_context (ASSUAN_CONTEXT *r_ctx) } +/* Returns true if atoi(S) denotes a valid socket. */ +static int +is_valid_socket (const char *s) +{ + struct stat buf; + + if ( fstat (atoi (s), &buf ) ) + return 0; + return S_ISSOCK (buf.st_mode); +} + + 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; @@ -110,8 +125,28 @@ assuan_init_pipe_server (ASSUAN_CONTEXT *r_ctx, int filedes[2]) ctx->inbound.fd = _get_osfhandle (filedes[0]); ctx->outbound.fd = _get_osfhandle (filedes[1]); #else - ctx->inbound.fd = filedes[0]; - ctx->outbound.fd = filedes[1]; + s = getenv ("_assuan_connection_fd"); + if (s && *s && is_valid_socket (s) ) + { + /* Well, we are called with an bi-directional file + descriptor. Prepare for using sendmsg/recvmsg. In this + case we ignore the passed file descriptors. */ + ctx->inbound.fd = ctx->outbound.fd = atoi (s); + _assuan_init_uds_io (ctx); + ctx->deinit_handler = _assuan_uds_deinit; + } + else if (filedes && filedes[0] != -1 && filedes[1] != -1 ) + { + /* Standard pipe server. */ + ctx->inbound.fd = filedes[0]; + ctx->outbound.fd = filedes[1]; + } + else + { + _assuan_release_context (*r_ctx); + *r_ctx = NULL; + return ASSUAN_Problem_Starting_Server; + } #endif ctx->pipe_mode = 1; @@ -127,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) { @@ -138,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) { |