diff options
Diffstat (limited to 'common')
-rw-r--r-- | common/iobuf.c | 37 | ||||
-rw-r--r-- | common/iobuf.h | 8 | ||||
-rw-r--r-- | common/sysutils.c | 36 | ||||
-rw-r--r-- | common/sysutils.h | 2 |
4 files changed, 42 insertions, 41 deletions
diff --git a/common/iobuf.c b/common/iobuf.c index ed90bd7a2..d346027e4 100644 --- a/common/iobuf.c +++ b/common/iobuf.c @@ -155,11 +155,6 @@ typedef struct block_filter_ctx_t; -/* Global flag to tell whether special file names are enabled. See - gpg.c for an explanation of these file names. FIXME: This does not - belong in the iobuf subsystem. */ -static int special_names_enabled; - /* Local prototypes. */ static int underflow (iobuf_t a, int clear_pending_eof); static int underflow_target (iobuf_t a, int clear_pending_eof, size_t target); @@ -1237,41 +1232,16 @@ iobuf_temp_with_content (const char *buffer, size_t length) return a; } -void -iobuf_enable_special_filenames (int yes) -{ - special_names_enabled = yes; -} - - -/* See whether the filename has the form "-&nnnn", where n is a - non-zero number. Returns this number or -1 if it is not the - case. */ -static int -check_special_filename (const char *fname) -{ - if (special_names_enabled && fname && *fname == '-' && fname[1] == '&') - { - int i; - - fname += 2; - for (i = 0; digitp (fname+i); i++) - ; - if (!fname[i]) - return atoi (fname); - } - return -1; -} - int iobuf_is_pipe_filename (const char *fname) { if (!fname || (*fname=='-' && !fname[1]) ) return 1; - return check_special_filename (fname) != -1; + return check_special_filename (fname, 0, 1) != -1; } + static iobuf_t do_open (const char *fname, int special_filenames, int use, const char *opentype, int mode700) @@ -1304,7 +1274,8 @@ do_open (const char *fname, int special_filenames, } else if (!fname) return NULL; - else if (special_filenames && (fd = check_special_filename (fname)) != -1) + else if (special_filenames + && (fd = check_special_filename (fname, 0, 1)) != -1) return iobuf_fdopen (translate_file_handle (fd, use == IOBUF_INPUT ? 0 : 1), opentype); else diff --git a/common/iobuf.h b/common/iobuf.h index 4fa56609f..22e02daad 100644 --- a/common/iobuf.h +++ b/common/iobuf.h @@ -258,16 +258,10 @@ struct iobuf_struct #endif EXTERN_UNLESS_MAIN_MODULE int iobuf_debug_mode; -/* Whether iobuf_open, iobuf_create and iobuf_is_pipefilename - recognize special filenames. Special filenames are of the form - "-&nnnn" where n is a positive integer. The integer corresponds to - a file descriptor. Note: these functions always recognize the - special filename '-', which corresponds to standard input. */ -void iobuf_enable_special_filenames (int yes); /* Returns whether the specified filename corresponds to a pipe. In particular, this function checks if FNAME is "-" and, if special - filenames are enabled (see iobuf_enable_special_filenames), whether + filenames are enabled (see check_special_filename), whether FNAME is a special filename. */ int iobuf_is_pipe_filename (const char *fname); diff --git a/common/sysutils.c b/common/sysutils.c index c7df8722a..e67420f18 100644 --- a/common/sysutils.c +++ b/common/sysutils.c @@ -1,7 +1,7 @@ /* sysutils.c - system helpers * Copyright (C) 1991-2001, 2003-2004, * 2006-2008 Free Software Foundation, Inc. - * Copyright (C) 2013-2014 Werner Koch + * Copyright (C) 2013-2016 Werner Koch * * This file is part of GnuPG. * @@ -83,6 +83,10 @@ #define tohex(n) ((n) < 10 ? ((n) + '0') : (((n) - 10) + 'A')) +/* Flag to tell whether special file names are enabled. See gpg.c for + * an explanation of these file names. */ +static int allow_special_filenames; + static GPGRT_INLINE gpg_error_t my_error_from_syserror (void) @@ -168,6 +172,13 @@ enable_core_dumps (void) } +/* Allow the use of special "-&nnn" style file names. */ +void +enable_special_filenames (void) +{ + allow_special_filenames = 1; +} + /* Return a string which is used as a kind of process ID. */ const byte * @@ -402,6 +413,29 @@ translate_sys2libc_fd_int (int fd, int for_write) } +/* Check whether FNAME has the form "-&nnnn", where N is a non-zero + * number. Returns this number or -1 if it is not the case. If the + * caller wants to use the file descriptor for writing FOR_WRITE shall + * be set to 1. If NOTRANSLATE is set the Windows spefic mapping is + * not done. */ +int +check_special_filename (const char *fname, int for_write, int notranslate) +{ + if (allow_special_filenames + && fname && *fname == '-' && fname[1] == '&') + { + int i; + + fname += 2; + for (i=0; digitp (fname+i); i++ ) + ; + if (!fname[i]) + return notranslate? atoi (fname) + /**/ : translate_sys2libc_fd_int (atoi (fname), for_write); + } + return -1; +} + /* Replacement for tmpfile(). This is required because the tmpfile function of Windows' runtime library is broken, insecure, ignores diff --git a/common/sysutils.h b/common/sysutils.h index fef6ba13e..a9316d7ce 100644 --- a/common/sysutils.h +++ b/common/sysutils.h @@ -50,6 +50,7 @@ typedef int gnupg_fd_t; void trap_unaligned (void); int disable_core_dumps (void); int enable_core_dumps (void); +void enable_special_filenames (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);*/ @@ -57,6 +58,7 @@ 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); +int check_special_filename (const char *fname, int for_write, int notranslate); FILE *gnupg_tmpfile (void); void gnupg_reopen_std (const char *pgmname); void gnupg_allow_set_foregound_window (pid_t pid); |