1
0
Fork 0
mirror of git://git.gnupg.org/gnupg.git synced 2025-07-02 22:46:30 +02:00

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
This commit is contained in:
Werner Koch 2024-03-26 15:46:56 +01:00
parent cec1fde1bc
commit f9919bcc48
No known key found for this signature in database
GPG key ID: E3FDFF218E45B72B
6 changed files with 50 additions and 9 deletions

View file

@ -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);

View file

@ -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);