diff --git a/agent/gpg-agent.c b/agent/gpg-agent.c index a0ac3c622..7d1ffc614 100644 --- a/agent/gpg-agent.c +++ b/agent/gpg-agent.c @@ -3022,7 +3022,7 @@ handle_connections (gnupg_fd_t listen_fd, npth_sigev_add (SIGTERM); npth_sigev_fini (); # ifdef HAVE_PSELECT_NO_EINTR - ret = gnupg_create_pipe (pipe_fd); + ret = gnupg_create_pipe (pipe_fd, 0); if (ret) { log_error ("pipe creation failed: %s\n", gpg_strerror (ret)); diff --git a/common/call-gpg.c b/common/call-gpg.c index 8c69a0c9a..75943a315 100644 --- a/common/call-gpg.c +++ b/common/call-gpg.c @@ -429,9 +429,9 @@ _gpg_encrypt (ctrl_t ctrl, assert ((reader_mb == NULL) != (cipher_stream == NULL)); /* Create two pipes. */ - err = gnupg_create_pipe (outbound_fds); + err = gnupg_create_pipe (outbound_fds, GNUPG_PIPE_OUTBOUND); if (!err) - err = gnupg_create_pipe (inbound_fds); + err = gnupg_create_pipe (inbound_fds, GNUPG_PIPE_INBOUND); if (err) { log_error (_("error creating a pipe: %s\n"), gpg_strerror (err)); @@ -613,9 +613,9 @@ _gpg_decrypt (ctrl_t ctrl, assert ((reader_mb == NULL) != (plain_stream == NULL)); /* Create two pipes. */ - err = gnupg_create_pipe (outbound_fds); + err = gnupg_create_pipe (outbound_fds, GNUPG_PIPE_OUTBOUND); if (!err) - err = gnupg_create_pipe (inbound_fds); + err = gnupg_create_pipe (inbound_fds, GNUPG_PIPE_INBOUND); if (err) { log_error (_("error creating a pipe: %s\n"), gpg_strerror (err)); diff --git a/common/exechelp-posix.c b/common/exechelp-posix.c index 2c7cb2adf..a9d91d9e7 100644 --- a/common/exechelp-posix.c +++ b/common/exechelp-posix.c @@ -348,11 +348,14 @@ gnupg_create_outbound_pipe (gnupg_fd_t *r_fd, estream_t *r_fp, int nonblock) } -/* Portable function to create a pipe. Under Windows both ends are - inheritable. */ +/* Portable function to create a pipe. FLAGS=GNUPG_PIPE_INBOUND for + ihneritable write-end for Windows, GNUPG_PIPE_OUTBOUND for + inheritable read-end for Windows, GNUPG_PIPE_BOTH to specify + both ends may be inheritable. */ gpg_error_t -gnupg_create_pipe (int filedes[2]) +gnupg_create_pipe (int filedes[2], int flags) { + (void)flags; return do_create_pipe (filedes); } diff --git a/common/exechelp-w32.c b/common/exechelp-w32.c index 0c8314296..3c57e7724 100644 --- a/common/exechelp-w32.c +++ b/common/exechelp-w32.c @@ -229,8 +229,16 @@ create_pipe_and_estream (gnupg_fd_t *r_fd, int flags, gpg_error_t err = 0; es_syshd_t syshd; gnupg_fd_t fds[2]; + int inherit_flags = 0; - if (create_inheritable_pipe (fds, flags) < 0) + if (flags == GNUPG_PIPE_OUTBOUND) + inherit_flags = INHERIT_READ; + else if (flags == GNUPG_PIPE_INBOUND) + inherit_flags = INHERIT_WRITE; + else + inherit_flags = INHERIT_BOTH; + + if (create_inheritable_pipe (fds, inherit_flags) < 0) { err = my_error_from_syserror (); log_error (_("error creating a pipe: %s\n"), gpg_strerror (err)); @@ -275,7 +283,7 @@ gnupg_create_inbound_pipe (gnupg_fd_t *r_fd, estream_t *r_fp, int nonblock) if (!r_fd || !r_fp) gpg_error (GPG_ERR_INV_ARG); - return create_pipe_and_estream (r_fd, INHERIT_WRITE, r_fp, 0, nonblock); + return create_pipe_and_estream (r_fd, GNUPG_PIPE_INBOUND, r_fp, 0, nonblock); } @@ -288,19 +296,29 @@ gnupg_create_outbound_pipe (gnupg_fd_t *r_fd, estream_t *r_fp, int nonblock) if (!r_fd || !r_fp) gpg_error (GPG_ERR_INV_ARG); - return create_pipe_and_estream (r_fd, INHERIT_READ, r_fp, 1, nonblock); + return create_pipe_and_estream (r_fd, GNUPG_PIPE_OUTBOUND, r_fp, 1, nonblock); } -/* Portable function to create a pipe. Under Windows both ends are - inheritable. */ +/* Portable function to create a pipe. FLAGS=GNUPG_PIPE_INBOUND for + ihneritable write-end for Windows, GNUPG_PIPE_OUTBOUND for + inheritable read-end for Windows, GNUPG_PIPE_BOTH to specify + both ends may be inheritable. */ gpg_error_t -gnupg_create_pipe (int filedes[2]) +gnupg_create_pipe (int filedes[2], int flags) { gnupg_fd_t fds[2]; gpg_error_t err = 0; + int inherit_flags = 0; - if (create_inheritable_pipe (fds, INHERIT_BOTH) < 0) + if (flags == GNUPG_PIPE_OUTBOUND) + inherit_flags = INHERIT_READ; + else if (flags == GNUPG_PIPE_INBOUND) + inherit_flags = INHERIT_WRITE; + else + inherit_flags = INHERIT_BOTH; + + if (create_inheritable_pipe (fds, inherit_flags) < 0) return my_error_from_syserror (); filedes[0] = _open_osfhandle (handle_to_fd (fds[0]), O_RDONLY); diff --git a/common/exechelp.h b/common/exechelp.h index d2aac4b39..10127859f 100644 --- a/common/exechelp.h +++ b/common/exechelp.h @@ -65,11 +65,17 @@ gpg_error_t gnupg_create_inbound_pipe (gnupg_fd_t *r_fd, gpg_error_t gnupg_create_outbound_pipe (gnupg_fd_t *r_fd, estream_t *r_fp, int nonblock); -/* Portable function to create a pipe. Under Windows both ends are - inheritable. */ -gpg_error_t gnupg_create_pipe (int filedes[2]); +enum { + GNUPG_PIPE_DONTCARE=0, + GNUPG_PIPE_INBOUND=1, + GNUPG_PIPE_OUTBOUND=2, + GNUPG_PIPE_BOTH=3 +}; -/* Close the end of a pipe. */ -void gnupg_close_pipe (int fd); +/* Portable function to create a pipe. FLAGS=GNUPG_PIPE_INBOUND for + ihneritable write-end for Windows, GNUPG_PIPE_OUTBOUND for + inheritable read-end for Windows, GNUPG_PIPE_BOTH to specify + both ends may be inheritable. */ +gpg_error_t gnupg_create_pipe (int filedes[2], int flags); #endif /*GNUPG_COMMON_EXECHELP_H*/ diff --git a/kbx/keyboxd.c b/kbx/keyboxd.c index ad14d8681..f6332c127 100644 --- a/kbx/keyboxd.c +++ b/kbx/keyboxd.c @@ -1527,7 +1527,7 @@ handle_connections (gnupg_fd_t listen_fd) npth_sigev_add (SIGTERM); npth_sigev_fini (); # ifdef HAVE_PSELECT_NO_EINTR - ret = gnupg_create_pipe (pipe_fd); + ret = gnupg_create_pipe (pipe_fd, 0); if (ret) { log_error ("pipe creation failed: %s\n", gpg_strerror (ret)); diff --git a/scd/app.c b/scd/app.c index 625f9b914..c2ff50285 100644 --- a/scd/app.c +++ b/scd/app.c @@ -2649,7 +2649,7 @@ initialize_module_command (void) #ifdef HAVE_W32_SYSTEM scd_init_event (&card_list_lock.the_event, card_list_lock.events); #else - ret = gnupg_create_pipe (card_list_lock.notify_pipe); + ret = gnupg_create_pipe (card_list_lock.notify_pipe, 0); if (ret) { err = gpg_error_from_syserror (); diff --git a/scd/scdaemon.c b/scd/scdaemon.c index a52dc5a2f..5e08a5abd 100644 --- a/scd/scdaemon.c +++ b/scd/scdaemon.c @@ -1312,7 +1312,7 @@ handle_connections (gnupg_fd_t listen_fd) #ifdef HAVE_PSELECT_NO_EINTR int pipe_fd[2]; - ret = gnupg_create_pipe (pipe_fd); + ret = gnupg_create_pipe (pipe_fd, 0); if (ret) { log_error ("pipe creation failed: %s\n", gpg_strerror (ret)); diff --git a/tests/gpgscm/ffi.c b/tests/gpgscm/ffi.c index 96b0b21e5..16d9147bf 100644 --- a/tests/gpgscm/ffi.c +++ b/tests/gpgscm/ffi.c @@ -1227,7 +1227,7 @@ do_pipe (scheme *sc, pointer args) FFI_PROLOG (); int filedes[2]; FFI_ARGS_DONE_OR_RETURN (sc, args); - err = gnupg_create_pipe (filedes); + err = gnupg_create_pipe (filedes, GNUPG_PIPE_BOTH); #define IMC(A, B) \ _cons (sc, sc->vptr->mk_integer (sc, (unsigned long) (A)), (B), 1) FFI_RETURN_POINTER (sc, IMC (filedes[0], @@ -1241,7 +1241,7 @@ do_inbound_pipe (scheme *sc, pointer args) FFI_PROLOG (); int filedes[2]; FFI_ARGS_DONE_OR_RETURN (sc, args); - err = gnupg_create_pipe (filedes); + err = gnupg_create_pipe (filedes, GNUPG_PIPE_INBOUND); #define IMC(A, B) \ _cons (sc, sc->vptr->mk_integer (sc, (unsigned long) (A)), (B), 1) FFI_RETURN_POINTER (sc, IMC (filedes[0], @@ -1255,7 +1255,7 @@ do_outbound_pipe (scheme *sc, pointer args) FFI_PROLOG (); int filedes[2]; FFI_ARGS_DONE_OR_RETURN (sc, args); - err = gnupg_create_pipe (filedes); + err = gnupg_create_pipe (filedes, GNUPG_PIPE_OUTBOUND); #define IMC(A, B) \ _cons (sc, sc->vptr->mk_integer (sc, (unsigned long) (A)), (B), 1) FFI_RETURN_POINTER (sc, IMC (filedes[0], diff --git a/tpm2d/tpm2daemon.c b/tpm2d/tpm2daemon.c index 46d20388a..e25a08748 100644 --- a/tpm2d/tpm2daemon.c +++ b/tpm2d/tpm2daemon.c @@ -1093,7 +1093,7 @@ handle_connections (gnupg_fd_t listen_fd) #ifdef HAVE_PSELECT_NO_EINTR int pipe_fd[2]; - ret = gnupg_create_pipe (pipe_fd); + ret = gnupg_create_pipe (pipe_fd, 0); if (ret) { log_error ("pipe creation failed: %s\n", gpg_strerror (ret));