summaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorNIIBE Yutaka <gniibe@fsij.org>2023-06-23 06:10:19 +0200
committerNIIBE Yutaka <gniibe@fsij.org>2023-06-23 06:22:00 +0200
commit2756147e392c8f58fc79db6b9420b306b6ddd082 (patch)
tree49e38830c3414ccd2051166c816430b135027da5 /tools
parentcommon: Add gnupg_sys2libc_fdstr function. (diff)
downloadgnupg2-2756147e392c8f58fc79db6b9420b306b6ddd082.tar.xz
gnupg2-2756147e392c8f58fc79db6b9420b306b6ddd082.zip
gpg,sm,tools: Use string for option --*-fd.
* g10/gpg.c (opts): Use string for oLoggerFD, oOverrideSessionKeyFD, oStatusFD, oAttributeFD, oCommandFD, and oPassphraseFD. (main): Use translate_sys2libc_fdstr. * g10/gpgv.c (opts): Use string for oLoggerFD, and oStatusFD. (main): Use translate_sys2libc_fdstr. * sm/gpgsm.c (opts): Use string for oLoggerFD, oStatusFD, and oPassphraseFD. (main): Use translate_sys2libc_fdstr. * tools/gpg-auth.c (opts): Use string for oStatusFD. (main): Use translate_sys2libc_fdstr. tools/gpg-card.c (opts): Use string for oStatusFD. (main): Use translate_sys2libc_fdstr. * tools/gpg-pair-tool.c (opts): Use string for oStatusFD. (main): Use translate_sys2libc_fdstr. * tools/gpg-wks-client.c (opts): Use string for oStatusFD. (main): Use translate_sys2libc_fdstr. * tools/gpgconf.c (opts): Use string for oStatusFD. (main): Use translate_sys2libc_fdstr. * tools/gpgtar-create.c (gpgtar_create): Fix for opt.status_fd. * tools/gpgtar-extract.c (gpgtar_extract): Fix for opt.status_fd. * tools/gpgtar-list.c (gpgtar_list): Fix for opt.status_fd. * tools/gpgtar.c (opts): Use string for oStatusFD. (main): Use translate_sys2libc_fdstr. * tools/gpgtar.h (opts): Use string for oStatusFD. -- GnuPG-bug-id: 6551 Signed-off-by: NIIBE Yutaka <gniibe@fsij.org>
Diffstat (limited to 'tools')
-rw-r--r--tools/gpg-auth.c4
-rw-r--r--tools/gpg-card.c4
-rw-r--r--tools/gpg-pair-tool.c4
-rw-r--r--tools/gpg-wks-client.c4
-rw-r--r--tools/gpgconf.c4
-rw-r--r--tools/gpgtar-create.c12
-rw-r--r--tools/gpgtar-extract.c12
-rw-r--r--tools/gpgtar-list.c12
-rw-r--r--tools/gpgtar.c36
-rw-r--r--tools/gpgtar.h2
10 files changed, 66 insertions, 28 deletions
diff --git a/tools/gpg-auth.c b/tools/gpg-auth.c
index f433ba220..6de3494ad 100644
--- a/tools/gpg-auth.c
+++ b/tools/gpg-auth.c
@@ -94,7 +94,7 @@ static gpgrt_opt_t opts[] = {
ARGPARSE_s_n (oVerbose, "verbose", ("verbose")),
ARGPARSE_s_n (oQuiet, "quiet", ("be somewhat more quiet")),
ARGPARSE_s_s (oDebug, "debug", "@"),
- ARGPARSE_s_i (oStatusFD, "status-fd", N_("|FD|write status info to this FD")),
+ ARGPARSE_s_s (oStatusFD, "status-fd", N_("|FD|write status info to this FD")),
ARGPARSE_s_n (oWithColons, "with-colons", "@"),
ARGPARSE_s_n (oNoAutostart, "no-autostart", "@"),
ARGPARSE_s_s (oAgentProgram, "agent-program", "@"),
@@ -168,7 +168,7 @@ parse_arguments (gpgrt_argparse_t *pargs, gpgrt_opt_t *popts)
case oAgentProgram: opt.agent_program = pargs->r.ret_str; break;
case oStatusFD:
- gnupg_set_status_fd (translate_sys2libc_fd_int (pargs->r.ret_int, 1));
+ gnupg_set_status_fd (translate_sys2libc_fdstr (pargs->r.ret_str, 1));
break;
case oWithColons: opt.with_colons = 1; break;
diff --git a/tools/gpg-card.c b/tools/gpg-card.c
index 4002cc185..24518d105 100644
--- a/tools/gpg-card.c
+++ b/tools/gpg-card.c
@@ -94,7 +94,7 @@ static gpgrt_opt_t opts[] = {
ARGPARSE_s_s (oDebug, "debug", "@"),
ARGPARSE_s_s (oGpgProgram, "gpg", "@"),
ARGPARSE_s_s (oGpgsmProgram, "gpgsm", "@"),
- ARGPARSE_s_i (oStatusFD, "status-fd", N_("|FD|write status info to this FD")),
+ ARGPARSE_s_s (oStatusFD, "status-fd", N_("|FD|write status info to this FD")),
ARGPARSE_s_n (oWithColons, "with-colons", "@"),
ARGPARSE_s_n (oNoAutostart, "no-autostart", "@"),
ARGPARSE_s_s (oAgentProgram, "agent-program", "@"),
@@ -225,7 +225,7 @@ parse_arguments (gpgrt_argparse_t *pargs, gpgrt_opt_t *popts)
case oAgentProgram: opt.agent_program = pargs->r.ret_str; break;
case oStatusFD:
- gnupg_set_status_fd (translate_sys2libc_fd_int (pargs->r.ret_int, 1));
+ gnupg_set_status_fd (translate_sys2libc_fdstr (pargs->r.ret_str, 1));
break;
case oWithColons: opt.with_colons = 1; break;
diff --git a/tools/gpg-pair-tool.c b/tools/gpg-pair-tool.c
index cf9778838..069bd1668 100644
--- a/tools/gpg-pair-tool.c
+++ b/tools/gpg-pair-tool.c
@@ -179,7 +179,7 @@ static gpgrt_opt_t opts[] = {
ARGPARSE_s_s (oSAS, "sas", N_("|SAS|the SAS as shown by the peer")),
ARGPARSE_s_s (oDebug, "debug", "@"),
ARGPARSE_s_s (oOutput, "output", N_("|FILE|write the request to FILE")),
- ARGPARSE_s_i (oStatusFD, "status-fd", N_("|FD|write status info to this FD")),
+ ARGPARSE_s_s (oStatusFD, "status-fd", N_("|FD|write status info to this FD")),
ARGPARSE_s_s (oHomedir, "homedir", "@"),
@@ -390,7 +390,7 @@ main (int argc, char **argv)
break;
case oStatusFD:
- set_status_fd (translate_sys2libc_fd_int (pargs.r.ret_int, 1));
+ set_status_fd (translate_sys2libc_fdstr (pargs.r.ret_str, 1));
break;
case oHomedir:
diff --git a/tools/gpg-wks-client.c b/tools/gpg-wks-client.c
index 521222631..ee0554014 100644
--- a/tools/gpg-wks-client.c
+++ b/tools/gpg-wks-client.c
@@ -115,7 +115,7 @@ static gpgrt_opt_t opts[] = {
ARGPARSE_s_s (oGpgProgram, "gpg", "@"),
ARGPARSE_s_n (oSend, "send", "send the mail using sendmail"),
ARGPARSE_s_s (oOutput, "output", "|FILE|write the mail to FILE"),
- ARGPARSE_s_i (oStatusFD, "status-fd", N_("|FD|write status info to this FD")),
+ ARGPARSE_s_s (oStatusFD, "status-fd", N_("|FD|write status info to this FD")),
ARGPARSE_s_n (oNoAutostart, "no-autostart", "@"),
ARGPARSE_s_n (oWithColons, "with-colons", "@"),
ARGPARSE_s_s (oBlacklist, "blacklist", "@"),
@@ -248,7 +248,7 @@ parse_arguments (gpgrt_argparse_t *pargs, gpgrt_opt_t *popts)
fake_submission_addr = pargs->r.ret_str;
break;
case oStatusFD:
- wks_set_status_fd (translate_sys2libc_fd_int (pargs->r.ret_int, 1));
+ wks_set_status_fd (translate_sys2libc_fdstr (pargs->r.ret_str, 1));
break;
case oWithColons:
opt.with_colons = 1;
diff --git a/tools/gpgconf.c b/tools/gpgconf.c
index 522ce517b..9738ffe97 100644
--- a/tools/gpgconf.c
+++ b/tools/gpgconf.c
@@ -118,7 +118,7 @@ static gpgrt_opt_t opts[] =
{ oQuiet, "quiet", 0, N_("quiet") },
{ oDryRun, "dry-run", 0, N_("do not make any changes") },
{ oRuntime, "runtime", 0, N_("activate changes at runtime, if possible") },
- ARGPARSE_s_i (oStatusFD, "status-fd",
+ ARGPARSE_s_s (oStatusFD, "status-fd",
N_("|FD|write status info to this FD")),
/* hidden options */
{ oHomedir, "homedir", 2, "@" },
@@ -645,7 +645,7 @@ main (int argc, char **argv)
case oBuilddir: gnupg_set_builddir (pargs.r.ret_str); break;
case oNull: opt.null = 1; break;
case oStatusFD:
- set_status_fd (translate_sys2libc_fd_int (pargs.r.ret_int, 1));
+ set_status_fd (translate_sys2libc_fdstr (pargs.r.ret_str, 1));
break;
case oShowSocket: show_socket = 1; break;
case oChUid: changeuser = pargs.r.ret_str; break;
diff --git a/tools/gpgtar-create.c b/tools/gpgtar-create.c
index e6f5b55a2..99da9ecf0 100644
--- a/tools/gpgtar-create.c
+++ b/tools/gpgtar-create.c
@@ -1246,13 +1246,19 @@ gpgtar_create (char **inpattern, const char *files_from, int null_names,
ccparray_put (&ccp, "--no");
if (opt.require_compliance)
ccparray_put (&ccp, "--require-compliance");
- if (opt.status_fd != -1)
+ if (opt.status_fd)
{
static char tmpbuf[40];
+ es_syshd_t hd;
- snprintf (tmpbuf, sizeof tmpbuf, "--status-fd=%d", opt.status_fd);
+ snprintf (tmpbuf, sizeof tmpbuf, "--status-fd=%s", opt.status_fd);
ccparray_put (&ccp, tmpbuf);
- except[0] = opt.status_fd;
+ es_syshd (opt.status_stream, &hd);
+#ifdef HAVE_W32_SYSTEM
+ except[0] = hd.u.handle;
+#else
+ except[0] = hd.u.fd;
+#endif
}
ccparray_put (&ccp, "--output");
diff --git a/tools/gpgtar-extract.c b/tools/gpgtar-extract.c
index be483f87c..33b88ff4d 100644
--- a/tools/gpgtar-extract.c
+++ b/tools/gpgtar-extract.c
@@ -392,13 +392,19 @@ gpgtar_extract (const char *filename, int decrypt)
ccparray_put (&ccp, "--batch");
if (opt.require_compliance)
ccparray_put (&ccp, "--require-compliance");
- if (opt.status_fd != -1)
+ if (opt.status_fd)
{
static char tmpbuf[40];
+ es_syshd_t hd;
- snprintf (tmpbuf, sizeof tmpbuf, "--status-fd=%d", opt.status_fd);
+ snprintf (tmpbuf, sizeof tmpbuf, "--status-fd=%s", opt.status_fd);
ccparray_put (&ccp, tmpbuf);
- except[0] = opt.status_fd;
+ es_syshd (opt.status_stream, &hd);
+#ifdef HAVE_W32_SYSTEM
+ except[0] = hd.u.handle;
+#else
+ except[0] = hd.u.fd;
+#endif
}
if (opt.with_log)
{
diff --git a/tools/gpgtar-list.c b/tools/gpgtar-list.c
index 31bcd8d46..846008ee8 100644
--- a/tools/gpgtar-list.c
+++ b/tools/gpgtar-list.c
@@ -476,13 +476,19 @@ gpgtar_list (const char *filename, int decrypt)
ccparray_put (&ccp, "--batch");
if (opt.require_compliance)
ccparray_put (&ccp, "--require-compliance");
- if (opt.status_fd != -1)
+ if (opt.status_fd)
{
static char tmpbuf[40];
+ es_syshd_t hd;
- snprintf (tmpbuf, sizeof tmpbuf, "--status-fd=%d", opt.status_fd);
+ snprintf (tmpbuf, sizeof tmpbuf, "--status-fd=%s", opt.status_fd);
ccparray_put (&ccp, tmpbuf);
- except[0] = opt.status_fd;
+ es_syshd (opt.status_stream, &hd);
+#ifdef HAVE_W32_SYSTEM
+ except[0] = hd.u.handle;
+#else
+ except[0] = hd.u.fd;
+#endif
}
ccparray_put (&ccp, "--output");
ccparray_put (&ccp, "-");
diff --git a/tools/gpgtar.c b/tools/gpgtar.c
index 492b3d5e5..dd269043f 100644
--- a/tools/gpgtar.c
+++ b/tools/gpgtar.c
@@ -125,7 +125,7 @@ static gpgrt_opt_t opts[] = {
ARGPARSE_s_n (oBatch, "batch", "@"),
ARGPARSE_s_n (oAnswerYes, "yes", "@"),
ARGPARSE_s_n (oAnswerNo, "no", "@"),
- ARGPARSE_s_i (oStatusFD, "status-fd", "@"),
+ ARGPARSE_s_s (oStatusFD, "status-fd", "@"),
ARGPARSE_s_n (oRequireCompliance, "require-compliance", "@"),
ARGPARSE_s_n (oWithLog, "with-log", "@"),
@@ -395,7 +395,7 @@ parse_arguments (gpgrt_argparse_t *pargs, gpgrt_opt_t *popts)
case oBatch: opt.batch = 1; break;
case oAnswerYes: opt.answer_yes = 1; break;
case oAnswerNo: opt.answer_no = 1; break;
- case oStatusFD: opt.status_fd = pargs->r.ret_int; break;
+ case oStatusFD: opt.status_fd = pargs->r.ret_str; break;
case oRequireCompliance: opt.require_compliance = 1; break;
case oWithLog: opt.with_log = 1; break;
@@ -477,7 +477,7 @@ main (int argc, char **argv)
log_assert (sizeof (struct ustar_raw_header) == 512);
/* Set default options */
- opt.status_fd = -1;
+ opt.status_fd = NULL;
/* The configuraton directories for use by gpgrt_argparser. */
gpgrt_set_confdir (GPGRT_CONFDIR_SYS, gnupg_sysconfdir ());
@@ -509,12 +509,23 @@ main (int argc, char **argv)
/* Set status stream for our own use of --status-fd. The original
* status fd is passed verbatim to gpg. */
- if (opt.status_fd != -1)
+ if (opt.status_fd)
{
- int fd = translate_sys2libc_fd_int (opt.status_fd, 1);
+ int fd = -1;
- if (!gnupg_fd_valid (fd))
- log_fatal ("status-fd is invalid: %s\n", strerror (errno));
+#ifdef HAVE_W32_SYSTEM
+ gnupg_fd_t hd;
+
+ err = gnupg_sys2libc_fdstr (opt.status_fd, 1, &hd, NULL);
+ if ((uintptr_t)hd == 1)
+ fd = 1;
+ else if ((uintptr_t)hd == 2)
+ fd = 2;
+#else
+ err = gnupg_sys2libc_fdstr (opt.status_fd, 1, NULL, &fd);
+#endif
+ if (err)
+ log_fatal ("status-fd is invalid: %s\n", gpg_strerror (err));
if (fd == 1)
{
@@ -526,7 +537,16 @@ main (int argc, char **argv)
opt.status_stream = es_stderr;
else
{
- opt.status_stream = es_fdopen (fd, "w");
+ es_syshd_t syshd;
+
+#ifdef HAVE_W32_SYSTEM
+ syshd.type = ES_SYSHD_HANDLE;
+ syshd.u.handle = hd;
+#else
+ syshd.type = ES_SYSHD_FD;
+ syshd.u.handle = fd;
+#endif
+ opt.status_stream = es_sysopen (&syshd, "w");
if (opt.status_stream)
es_setvbuf (opt.status_stream, NULL, _IOLBF, 0);
}
diff --git a/tools/gpgtar.h b/tools/gpgtar.h
index 9177fcfcb..26b405f0b 100644
--- a/tools/gpgtar.h
+++ b/tools/gpgtar.h
@@ -44,7 +44,7 @@ struct
int batch;
int answer_yes;
int answer_no;
- int status_fd;
+ const char *status_fd;
estream_t status_stream;
int require_compliance;
int with_log;