aboutsummaryrefslogtreecommitdiffstats
path: root/sm/gpgsm.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 /sm/gpgsm.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 '')
-rw-r--r--sm/gpgsm.c33
1 files changed, 6 insertions, 27 deletions
diff --git a/sm/gpgsm.c b/sm/gpgsm.c
index c4fd1c21d..08d48308a 100644
--- a/sm/gpgsm.c
+++ b/sm/gpgsm.c
@@ -439,9 +439,6 @@ static int maybe_setuid = 1;
static const char *debug_level;
static unsigned int debug_value;
-/* Option --enable-special-filenames */
-static int allow_special_filenames;
-
/* Default value for include-certs. We need an extra macro for
gpgconf-list because the variable will be changed by the command
line option.
@@ -468,7 +465,6 @@ static void set_cmd (enum cmd_and_opt_values *ret_cmd,
enum cmd_and_opt_values new_cmd );
static void emergency_cleanup (void);
-static int check_special_filename (const char *fname, int for_write);
static int open_read (const char *filename);
static estream_t open_es_fread (const char *filename, const char *mode);
static estream_t open_es_fwrite (const char *filename);
@@ -1420,7 +1416,9 @@ main ( int argc, char **argv)
case oNoRandomSeedFile: use_random_seed = 0; break;
case oNoCommonCertsImport: no_common_certs_import = 1; break;
- case oEnableSpecialFilenames: allow_special_filenames =1; break;
+ case oEnableSpecialFilenames:
+ enable_special_filenames ();
+ break;
case oValidationModel: parse_validation_model (pargs.r.ret_str); break;
@@ -2107,25 +2105,6 @@ gpgsm_parse_validation_model (const char *model)
}
-/* Check 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, int for_write)
-{
- if (allow_special_filenames
- && fname && *fname == '-' && fname[1] == '&' ) {
- int i;
-
- fname += 2;
- for (i=0; isdigit (fname[i]); i++ )
- ;
- if ( !fname[i] )
- return translate_sys2libc_fd_int (atoi (fname), for_write);
- }
- return -1;
-}
-
-
/* Open the FILENAME for read and return the file descriptor. Stop
with an error message in case of problems. "-" denotes stdin and
@@ -2140,7 +2119,7 @@ open_read (const char *filename)
set_binary (stdin);
return 0; /* stdin */
}
- fd = check_special_filename (filename, 0);
+ fd = check_special_filename (filename, 0, 0);
if (fd != -1)
return fd;
fd = open (filename, O_RDONLY | O_BINARY);
@@ -2162,7 +2141,7 @@ open_es_fread (const char *filename, const char *mode)
if (filename[0] == '-' && !filename[1])
fd = fileno (stdin);
else
- fd = check_special_filename (filename, 0);
+ fd = check_special_filename (filename, 0, 0);
if (fd != -1)
{
fp = es_fdopen_nc (fd, mode);
@@ -2200,7 +2179,7 @@ open_es_fwrite (const char *filename)
return fp;
}
- fd = check_special_filename (filename, 1);
+ fd = check_special_filename (filename, 1, 0);
if (fd != -1)
{
fp = es_fdopen_nc (fd, "wb");