mirror of
git://git.gnupg.org/gnupg.git
synced 2025-07-03 22:56:33 +02:00
common: Add gnupg_check_special_filename.
* common/sysutils.h (gnupg_check_special_filename): New. * common/sysutils.c (gnupg_check_special_filename): New. * common/iobuf.c (translate_file_handle): Remove. (iobuf_is_pipe_filename): Use gnupg_check_special_filename. (do_open): Use gnupg_check_special_filename. * g10/plaintext.c (get_output_file): Use gnupg_check_special_filename and open_stream_nc. -- GnuPG-bug-id: 6580 Signed-off-by: NIIBE Yutaka <gniibe@fsij.org>
This commit is contained in:
parent
37343db08f
commit
250733c0d8
4 changed files with 52 additions and 41 deletions
|
@ -682,6 +682,48 @@ check_special_filename (const char *fname, int for_write, int notranslate)
|
|||
}
|
||||
|
||||
|
||||
/* Check whether FNAME has the form "-&nnnn", where N is a number
|
||||
* representing a file. Returns GNUPG_INVALID_FD if it is not the
|
||||
* case. Returns a file descriptor on POSIX, a system handle on
|
||||
* Windows. */
|
||||
gnupg_fd_t
|
||||
gnupg_check_special_filename (const char *fname)
|
||||
{
|
||||
if (allow_special_filenames
|
||||
&& fname && *fname == '-' && fname[1] == '&')
|
||||
{
|
||||
int i;
|
||||
|
||||
fname += 2;
|
||||
for (i=0; digitp (fname+i); i++ )
|
||||
;
|
||||
if (!fname[i])
|
||||
{
|
||||
es_syshd_t syshd;
|
||||
|
||||
if (gnupg_parse_fdstr (fname, &syshd))
|
||||
return GNUPG_INVALID_FD;
|
||||
|
||||
#ifdef HAVE_W32_SYSTEM
|
||||
if (syshd.type == ES_SYSHD_FD)
|
||||
{
|
||||
if (syshd.u.fd == 0)
|
||||
return GetStdHandle (STD_INPUT_HANDLE);
|
||||
else if (syshd.u.fd == 1)
|
||||
return GetStdHandle (STD_OUTPUT_HANDLE);
|
||||
else if (syshd.u.fd == 2)
|
||||
return GetStdHandle (STD_ERROR_HANDLE);
|
||||
}
|
||||
else
|
||||
return syshd.u.handle;
|
||||
#else
|
||||
return syshd.u.fd;
|
||||
#endif
|
||||
}
|
||||
}
|
||||
return GNUPG_INVALID_FD;
|
||||
}
|
||||
|
||||
/* Replacement for tmpfile(). This is required because the tmpfile
|
||||
function of Windows' runtime library is broken, insecure, ignores
|
||||
TMPDIR and so on. In addition we create a file with an inheritable
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue