aboutsummaryrefslogtreecommitdiffstats
path: root/common/sysutils.c
diff options
context:
space:
mode:
authorWerner Koch <[email protected]>2016-11-29 15:18:24 +0000
committerWerner Koch <[email protected]>2016-11-29 15:54:36 +0000
commit60b4982836a00ef6b2a97d16f735b3f6b74dce62 (patch)
tree95b51ae8ed413646ebdc601d8344fd85e34965dd /common/sysutils.c
parentg10: Fix memory leak. (diff)
downloadgnupg-60b4982836a00ef6b2a97d16f735b3f6b74dce62.tar.gz
gnupg-60b4982836a00ef6b2a97d16f735b3f6b74dce62.zip
gpg,sm: Merge the two versions of check_special_filename.
* sm/gpgsm.c (check_special_filename): Move to .. * common/sysutils.c (check_special_filename): here. Add arg NOTRANSLATE. (allow_special_filenames): New local var. (enable_special_filenames): New public functions. * sm/gpgsm.c (allow_special_filenames): Remove var. (main): Call enable_special_filenames instead of setting the var. (open_read, open_es_fread, open_es_fwrite): Call check_special_filename with 0 for NOTRANSLATE. * common/iobuf.c (special_names_enabled): Remove var. (iobuf_enable_special_filenames): Remove func. (check_special_filename): Remove func. (iobuf_is_pipe_filename): Call new version of the function with NOTRANSLATE set. (do_open): Ditto. * g10/gpg.c (main): Call enable_special_filenames instead of iobuf_enable_special_filenames. * g10/gpgv.c (main): Ditto. -- Note that we keep the iobuf.c:translate_file_handle because it is a bit different (for whatever reasons) than the translate function from sysutils. Signed-off-by: Werner Koch <[email protected]>
Diffstat (limited to 'common/sysutils.c')
-rw-r--r--common/sysutils.c36
1 files changed, 35 insertions, 1 deletions
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