diff options
author | Werner Koch <[email protected]> | 2024-03-26 14:46:56 +0000 |
---|---|---|
committer | Werner Koch <[email protected]> | 2024-03-26 14:46:56 +0000 |
commit | f9919bcc48831fcb7aa01cd6ce9d8028a6485e99 (patch) | |
tree | dd849c0253ee5c27c3cd85a8b0b1a2ae36f42ed7 /common | |
parent | scd: Add new OpenPGP vendor (diff) | |
download | gnupg-f9919bcc48831fcb7aa01cd6ce9d8028a6485e99.tar.gz gnupg-f9919bcc48831fcb7aa01cd6ce9d8028a6485e99.zip |
gpg,gpgsm: New option --disable-fd-translation.
* common/sysutils.c (no_translate_sys2libc_fd) [W32]: New global.
(disable_translate_sys2libc_fd): New.
(translate_sys2libc_fd): Make static and cobuild only for Windows.
(translate_sys2libc_fd_int): Use no_translate_sys2libc_fd flag.
* g10/gpg.c, sm/gpgsm.c (oDisableFdTranslation): New const.
(opts): Add option "disable-fd-translation".
(main): Set option.
--
GnuPG-bug-id: 7060
Diffstat (limited to 'common')
-rw-r--r-- | common/sysutils.c | 24 | ||||
-rw-r--r-- | common/sysutils.h | 3 |
2 files changed, 19 insertions, 8 deletions
diff --git a/common/sysutils.c b/common/sysutils.c index 6c7d616b9..780af58bd 100644 --- a/common/sysutils.c +++ b/common/sysutils.c @@ -113,6 +113,8 @@ static int allow_special_filenames; #ifdef HAVE_W32_SYSTEM /* State of gnupg_inhibit_set_foregound_window. */ static int inhibit_set_foregound_window; +/* Disable the use of _open_osfhandle. */ +static int no_translate_sys2libc_fd; #endif @@ -351,6 +353,16 @@ enable_special_filenames (void) } +/* Disable the use use of _open_osfhandle on Windows. */ +void +disable_translate_sys2libc_fd (void) +{ +#ifdef HAVE_W32_SYSTEM + no_translate_sys2libc_fd = 1; +#endif +} + + /* Return a string which is used as a kind of process ID. */ const byte * get_session_marker (size_t *rlen) @@ -537,10 +549,10 @@ gnupg_usleep (unsigned int usecs) different from the libc file descriptors (like open). This function translates system file handles to libc file handles. FOR_WRITE gives the direction of the handle. */ -int +#if defined(HAVE_W32_SYSTEM) +static int translate_sys2libc_fd (gnupg_fd_t fd, int for_write) { -#if defined(HAVE_W32_SYSTEM) int x; if (fd == GNUPG_INVALID_FD) @@ -552,11 +564,9 @@ translate_sys2libc_fd (gnupg_fd_t fd, int for_write) if (x == -1) log_error ("failed to translate osfhandle %p\n", (void *) fd); return x; -#else /*!HAVE_W32_SYSTEM */ - (void)for_write; - return fd; -#endif } +#endif /*!HAVE_W32_SYSTEM */ + /* This is the same as translate_sys2libc_fd but takes an integer which is assumed to be such an system handle. */ @@ -564,7 +574,7 @@ int translate_sys2libc_fd_int (int fd, int for_write) { #ifdef HAVE_W32_SYSTEM - if (fd <= 2) + if (fd <= 2 || no_translate_sys2libc_fd) return fd; /* Do not do this for stdin, stdout, and stderr. */ return translate_sys2libc_fd ((void*)(intptr_t)fd, for_write); diff --git a/common/sysutils.h b/common/sysutils.h index dac2d9244..9a90d1018 100644 --- a/common/sysutils.h +++ b/common/sysutils.h @@ -75,12 +75,13 @@ void trap_unaligned (void); int disable_core_dumps (void); int enable_core_dumps (void); void enable_special_filenames (void); +void disable_translate_sys2libc_fd (void); + const unsigned char *get_session_marker (size_t *rlen); unsigned int get_uint_nonce (void); /*int check_permissions (const char *path,int extension,int checkonly);*/ void gnupg_sleep (unsigned int seconds); void gnupg_usleep (unsigned int usecs); -int translate_sys2libc_fd (gnupg_fd_t fd, int for_write); int translate_sys2libc_fd_int (int fd, int for_write); gpg_error_t gnupg_parse_fdstr (const char *fdstr, es_syshd_t *r_syshd); int check_special_filename (const char *fname, int for_write, int notranslate); |