aboutsummaryrefslogtreecommitdiffstats
path: root/assuan/assuan-pipe-connect.c
diff options
context:
space:
mode:
authorMarcus Brinkmann <[email protected]>2008-06-25 16:52:31 +0000
committerMarcus Brinkmann <[email protected]>2008-06-25 16:52:31 +0000
commit0560f3089b5d1f24fd9625612921ceffc995fff8 (patch)
tree40b86f1540d69cbfea674ad41aa6cb23524797bc /assuan/assuan-pipe-connect.c
parentUpdated example. (diff)
downloadgpgme-0560f3089b5d1f24fd9625612921ceffc995fff8.tar.gz
gpgme-0560f3089b5d1f24fd9625612921ceffc995fff8.zip
assuan/
2008-06-25 Marcus Brinkmann <[email protected]> * assuan-pipe-connect.c (struct spawn_fd_item_s): Add new members. (HANDLE_TRANSLATION): New macro. (pipe_connect_gpgme): Adjust caller of _gpgme_io_spawn. [HANDLE_TRANSLATION]: Return translated handles. gpgme/ 2008-06-25 Marcus Brinkmann <[email protected]> * gpgme-w32spawn.c: New file. * Makefile.am (libexec_PROGRAMS) [HAVE_W32_SYSTEM]: New variable with gpgme-w32spawn. * engine-gpgsm.c (gpgsm_new): Use server translated handles. (gpgsm_set_locale): Return early if locale value is NULL. * util.h (_gpgme_mkstemp) (_gpgme_get_w32spawn_path) [HAVE_W32_SYSTEM]: New function prototypes. * w32-util.c: Include <stdint.h>, <sys/stat.h> and <unistd.h>. (letters, mkstemp, _gpgme_mkstemp, _gpgme_get_w32spawn_path): New functions. * rungpg.c (gpg_decrypt, gpg_encrypt, gpg_encrypt_sign) (gpg_genkey, gpg_import, gpg_verify, gpg_sign): Pass data over special filename FD rather than stdin. (struct arg_and_data_s): Add member ARG_LOCP. (struct fd_data_map_s): Add member ARG_LOC. (struct engine_gpg): Add member ARG_LOC to status and colon. (_add_arg, add_arg_with_locp): New function. (add_arg_ext): Reimplement in terms of _add_arg. (gpg_new): Remember argument location for status FD. (build_argv): Set argument location if requested. Also set argument location of fd_data_map for data items. (start): Adjust caller of _gpgme_io_spawn. * priv-io.h (struct spawn_fd_item_s): Add members peer_name and arg_loc. (_gpgme_io_spawn): Remove parent fd list argument. * posix-io.c (get_max_fds): New function. (_gpgme_io_dup): Add tracing. (_gpgme_io_spawn): Remove parent fd list. Change meaning of child fd list to contain all child fds that should be inherited. Close all other file descriptors after fork. * w32-io.c, w32-glib-io.c, w32-qt-io.c(_gpgme_io_spawn): Remove parent fd list. Change meaning of child fd list to contain all child fds that should be inherited. Do not inherit any file descriptors, but DuplicateHandle them. Spawn process through wrapper process. Provide wrapper process with a temporary file containing handle translation data. Return translated handle names. * w32-io.c (reader): Add more tracing output. (_gpgme_io_read): Likewise. * engine-gpgconf.c (gpgconf_read): Adjust caller of _gpgme_io_spawn. * version.c (_gpgme_get_program_version): Likewise.
Diffstat (limited to 'assuan/assuan-pipe-connect.c')
-rw-r--r--assuan/assuan-pipe-connect.c68
1 files changed, 49 insertions, 19 deletions
diff --git a/assuan/assuan-pipe-connect.c b/assuan/assuan-pipe-connect.c
index 32a62191..a0091c6a 100644
--- a/assuan/assuan-pipe-connect.c
+++ b/assuan/assuan-pipe-connect.c
@@ -41,10 +41,19 @@
#ifdef _ASSUAN_IN_GPGME_BUILD_ASSUAN
+/* From GPGME priv-io.h */
+struct spawn_fd_item_s
+{
+ int fd;
+ int dup_to;
+ int peer_name;
+ int arg_loc;
+};
+
+
int _gpgme_io_pipe (int filedes[2], int inherit_idx);
int _gpgme_io_spawn (const char *path, char **argv,
- struct spawn_fd_item_s *fd_child_list,
- struct spawn_fd_item_s *fd_parent_list, pid_t *r_pid);
+ struct spawn_fd_item_s *fd_list, pid_t *r_pid);
#endif
/* Hacks for Slowaris. */
@@ -566,13 +575,6 @@ socketpair_connect (assuan_context_t *ctx,
#define pipe_connect pipe_connect_gpgme
-/* From GPGME priv-io.h */
-struct spawn_fd_item_s
-{
- int fd;
- int dup_to;
-};
-
/* W32 version of the pipe connection code. */
static assuan_error_t
pipe_connect_gpgme (assuan_context_t *ctx,
@@ -583,14 +585,25 @@ pipe_connect_gpgme (assuan_context_t *ctx,
{
assuan_error_t err;
int res;
+ int idx;
+ int nr;
int rp[2];
int wp[2];
char mypidstr[50];
- struct spawn_fd_item_s child_fds[3]; /* stdin, stdout, terminating -1 */
+ struct spawn_fd_item_s *child_fds;
if (!ctx || !name || !argv || !argv[0])
return _assuan_error (ASSUAN_Invalid_Value);
+ /* stdin, stdout, terminating -1 */
+ nr = 3;
+ for (idx = 0; fd_child_list[idx] != -1; idx++)
+ nr++;
+
+ child_fds = calloc (nr, sizeof *child_fds);
+ if (! child_fds)
+ return _assuan_error (ASSUAN_Out_Of_Core);
+
/* Actually, GPGME does this for us. But we plan to reuse this code
in the generic assuan. */
fix_signals ();
@@ -631,19 +644,28 @@ pipe_connect_gpgme (assuan_context_t *ctx,
the old value, changeit, create proces and restore it, is not
thread safe. */
- /* Parent list is same as client list. Note that GPGME will dup nul
- to stderr even if the caller wants to inherit the handle for
- it. */
+ nr = 0;
/* Server stdout is its write end of our read pipe. */
- child_fds[0].fd = rp[1];
- child_fds[0].dup_to = 1;
+ child_fds[nr].fd = rp[1];
+ child_fds[nr].dup_to = 1;
+ nr++;
/* Server stdin is its read end of our write pipe. */
- child_fds[1].fd = wp[0];
- child_fds[1].dup_to = 0;
- child_fds[2].fd = -1;
+ child_fds[nr].fd = wp[0];
+ child_fds[nr].dup_to = 0;
+ nr++;
+
+ for (idx = 0; fd_child_list[idx] != -1; idx++)
+ {
+ child_fds[nr].fd = fd_child_list[idx];
+ child_fds[nr].dup_to = -1;
+ nr++;
+ }
+
+ child_fds[nr].fd = -1;
+ child_fds[nr].dup_to = -1;
/* Start the process. */
- res = _gpgme_io_spawn (name, argv, child_fds, child_fds, NULL);
+ res = _gpgme_io_spawn (name, argv, child_fds, NULL);
if (res == -1)
{
_assuan_log_printf ("CreateProcess failed: %s\n", strerror (errno));
@@ -653,6 +675,14 @@ pipe_connect_gpgme (assuan_context_t *ctx,
_gpgme_io_close (wp[1]);
return _assuan_error (ASSUAN_General_Error);
}
+ else
+ {
+ /* For W32, the user needs to know the server-local names of the
+ inherited handles. Return them here. */
+ for (idx = 0; fd_child_list[idx] != -1; idx++)
+ /* We add 2 to skip over the stdin/stdout pair. */
+ fd_child_list[idx] = child_fds[idx + 2].peer_name;
+ }
(*ctx)->pid = 0; /* We don't use the PID. */