diff options
Diffstat (limited to 'tools')
-rw-r--r-- | tools/Makefile.am | 3 | ||||
-rw-r--r-- | tools/call-dirmngr.c | 3 | ||||
-rw-r--r-- | tools/card-call-scd.c | 3 | ||||
-rw-r--r-- | tools/gpg-auth.c | 2 | ||||
-rw-r--r-- | tools/gpg-authcode-sign.sh | 257 | ||||
-rw-r--r-- | tools/gpg-card.c | 60 | ||||
-rw-r--r-- | tools/gpg-connect-agent.c | 91 | ||||
-rw-r--r-- | tools/gpgconf-comp.c | 115 | ||||
-rw-r--r-- | tools/gpgconf.c | 44 | ||||
-rw-r--r-- | tools/gpgtar-create.c | 49 | ||||
-rw-r--r-- | tools/gpgtar-extract.c | 46 | ||||
-rw-r--r-- | tools/gpgtar-list.c | 49 | ||||
-rw-r--r-- | tools/gpgtar.c | 25 | ||||
-rw-r--r-- | tools/gpgtar.h | 2 | ||||
-rw-r--r-- | tools/mime-parser.c | 23 | ||||
-rw-r--r-- | tools/no-libgcrypt.c | 8 | ||||
-rw-r--r-- | tools/wks-util.c | 15 |
17 files changed, 591 insertions, 204 deletions
diff --git a/tools/Makefile.am b/tools/Makefile.am index 769a81a00..9321da9e3 100644 --- a/tools/Makefile.am +++ b/tools/Makefile.am @@ -18,7 +18,7 @@ EXTRA_DIST = \ Manifest watchgnupg.c no-libgcrypt.c \ - addgnupghome applygnupgdefaults \ + addgnupghome applygnupgdefaults gpg-authcode-sign.sh \ lspgpot mail-signed-keys convert-from-106 sockprox.c \ ccidmon.c ChangeLog-2011 \ gpg-connect-agent-w32info.rc gpg-connect-agent.w32-manifest.in \ @@ -54,6 +54,7 @@ endif AM_CFLAGS = $(LIBGCRYPT_CFLAGS) $(GPG_ERROR_CFLAGS) $(LIBASSUAN_CFLAGS) sbin_SCRIPTS = addgnupghome applygnupgdefaults +bin_SCRIPTS = gpg-authcode-sign.sh if BUILD_WKS_TOOLS gpg_wks_server = gpg-wks-server diff --git a/tools/call-dirmngr.c b/tools/call-dirmngr.c index c0ddcf568..d85801530 100644 --- a/tools/call-dirmngr.c +++ b/tools/call-dirmngr.c @@ -65,7 +65,8 @@ connect_dirmngr (assuan_context_t *r_ctx) err = start_new_dirmngr (&ctx, GPG_ERR_SOURCE_DEFAULT, NULL, - opt.autostart, opt.verbose, opt.debug_ipc, + opt.autostart?ASSHELP_FLAG_AUTOSTART:0, + opt.verbose, opt.debug_ipc, NULL, NULL); if (!opt.autostart && gpg_err_code (err) == GPG_ERR_NO_DIRMNGR) { diff --git a/tools/card-call-scd.c b/tools/card-call-scd.c index f6ce565c3..f8557e32b 100644 --- a/tools/card-call-scd.c +++ b/tools/card-call-scd.c @@ -306,7 +306,8 @@ start_agent (unsigned int flags) opt.agent_program, opt.lc_ctype, opt.lc_messages, opt.session_env, - opt.autostart, opt.verbose, DBG_IPC, + opt.autostart?ASSHELP_FLAG_AUTOSTART:0, + opt.verbose, DBG_IPC, NULL, NULL); if (!opt.autostart && gpg_err_code (err) == GPG_ERR_NO_AGENT) { diff --git a/tools/gpg-auth.c b/tools/gpg-auth.c index f433ba220..a818bee5d 100644 --- a/tools/gpg-auth.c +++ b/tools/gpg-auth.c @@ -396,7 +396,7 @@ start_agent (assuan_context_t *ctx_p) opt.agent_program, NULL, NULL, session_env, - opt.autostart, + opt.autostart?ASSHELP_FLAG_AUTOSTART:0, !opt.quiet, 0, NULL, NULL); diff --git a/tools/gpg-authcode-sign.sh b/tools/gpg-authcode-sign.sh new file mode 100644 index 000000000..0f6a34824 --- /dev/null +++ b/tools/gpg-authcode-sign.sh @@ -0,0 +1,257 @@ +#!/bin/sh +# gpg-authcode-sign.sh - Wrapper for osslsigncode +# Copyright (C) 2024 g10 Code GmbH +# +# This file is free software; as a special exception the author gives +# unlimited permission to copy and/or distribute it, with or without +# modifications, as long as this notice is preserved. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY, to the extent permitted by law; without even the +# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + +VERSION=2024-03-25 +PGM=gpg-authcode-sign.sh + +set -e + +usage() +{ + cat <<EOF +Usage: $PGM [OPTIONS] FILE_TO_SIGN SIGNED_FILE +Options: + [--desc=STRING] Include STRING as description (default=$url) + [--url=STRING] Include STRING as URL (default=$desc) + [--stamp] Use a stamp file to avoid double signing + [--dry-run] Do not actually run osslsigncode + [--template] Print a template for ~/.gnupg-autogenrc + [--version] Print version and exit +EOF + exit $1 +} + + +# The information required to sign the tarballs and binaries +# are expected in the developer specific file ~/.gnupg-autogen.rc". +# Here is an example: +print_autogenrc_template() +{ +cat <<EOF +# Location of the released tarball archives. Note that this is an +# internal archive and before uploading this to the public server, +# manual tests should be run and the git release tagged and pushed. +# This is greped by the Makefile. +RELEASE_ARCHIVE=foo@somehost:tarball-archive + +# The key used to sign the GnuPG sources. +# This is greped by the Makefile. +RELEASE_SIGNKEY=6DAA6E64A76D2840571B4902528897B826403ADA + +# The key used to sign the VERSION files of some MSI installers. +VERSION_SIGNKEY=02F38DFF731FF97CB039A1DA549E695E905BA208 + +# For signing Windows binaries we need to employ a Windows machine. +# We connect to this machine via ssh and take the connection +# parameters via .ssh/config. For example a VM could be specified +# like this: +# +# Host authenticode-signhost +# HostName localhost +# Port 27042 +# User gpgsign +# +# Depending on the used token it might be necessary to allow single +# signon and unlock the token before running the make. The following +# variable references this entry. This is greped by the Makefile. +# To enable this use authenticode-signhost as value. +AUTHENTICODE_SIGNHOST= + +# The name of the signtool as used on Windows. +# This is greped by the Makefile. +AUTHENTICODE_TOOL="C:\Program Files (x86)\Windows Kits\10\bin\signtool.exe" + +# The URL for the timestamping service +AUTHENTICODE_TSURL=http://rfc3161timestamp.globalsign.com/advanced + +# To use osslsigncode the follwing entries are required and +# an empty string must be given for AUTHENTICODE_SIGNHOST. +# They are greped by the Makefile. For example: +#AUTHENTICODE_KEY=/home/foo/.gnupg/my-authenticode-key.p12 +#AUTHENTICODE_CERTS=/home/foo/.gnupg/my-authenticode-certs.pem + +# If a smartcard is used for the Authenticode signature these +# entries are required instead (remove comment). +#AUTHENTICODE_KEY=card +AUTHENTICODE_CERTS=/home/foo/.gnupg/my_authenticode_cert.pem +OSSLSIGNCODE=/usr/bin/osslsigncode +OSSLPKCS11ENGINE=/usr/lib/x86_64-linux-gnu/engines-1.1/pkcs11.so +SCUTEMODULE=/usr/local/lib/scute.so + +# Signing can also be disabled: +AUTHENTICODE_KEY=none + +# +EOF +} + + +autogenrc="$HOME/.gnupg-autogen.rc" +dryrun= +stamp= +buildtype= +# Set defaults accrding to our build system. +if [ -n "$abs_top_srcdir" -a -f "$abs_top_srcdir/packages/BUILDTYPE" ]; then + buildtype=$(cat "$abs_top_srcdir/packages/BUILDTYPE") +elif [ -f "../packages/BUILDTYPE" ]; then + buildtype=$(cat "../packages/BUILDTYPE") +elif [ -f "packages/BUILDTYPE" ]; then + buildtype=$(cat "packages/BUILDTYPE") +fi +case "$buildtype" in + vsd) + desc="GnuPG VS-Desktop" + url="https://gnupg.com" + ;; + gpd) + desc="GnuPG Desktop" + url="https://gnupg.com" + ;; + default|gpg4win) + desc="Gpg4win" + url="https://gpg4win.org" + ;; + *) + desc="GnuPG" + url="https://gnupg.org" + ;; +esac + +while [ $# -gt 0 ]; do + case "$1" in + --*=*) + optarg=`echo "$1" | sed 's/[-_a-zA-Z0-9]*=//'` + ;; + *) + optarg="" + ;; + esac + + case $1 in + --desc=*) + desc="$optarg" + ;; + --url=*) + url="$optarg" + ;; + --dry-run|-n) + dryrun=yes + ;; + --stamp) + stamp=yes + ;; + --help|-h) + usage 0 + ;; + --version) + echo $VERSION + exit 0 + ;; + --template) + print_autogenrc_template + exit 0 + ;; + --*) + usage 1 1>&2 + ;; + *) + break + ;; + esac + shift +done + +if [ $# -ne 2 ]; then + usage 1 1>&2 +fi +inname="$1" +outname="$2" +shift + +if [ ! -f $autogenrc ]; then + echo >&2 "$PGM: error: '$autogenrc' missing" + echo >&2 "$PGM: hint: use option --template" + exit 1 +fi + + +for v in AUTHENTICODE_SIGNHOST AUTHENTICODE_TOOL AUTHENTICODE_TSURL \ + AUTHENTICODE_KEY AUTHENTICODE_CERTS VERSION_SIGNKEY \ + OSSLSIGNCODE OSSLPKCS11ENGINE SCUTEMODULE ; do + eval $v=$(grep '^[[:blank:]]*'$v'[[:blank:]]*=' "$autogenrc"|cut -d= -f2\ + |sed -e 's,\\,\\\\,g'| sed -e 's,^",'\', -e 's,"$,'\',) +done + + +if [ "$stamp" = yes ]; then + if [ "$outname.asig-done" -nt "$outname" ]; then + echo >&2 "$PGM: file is '$outname' is already signed" + exit 0 + fi +fi + +if [ -n "$dryrun" ]; then + + echo >&2 "$PGM: would sign: '$inname' to '$outname'" + +elif [ -n "$AUTHENTICODE_SIGNHOST" ]; then + + echo >&2 "$PGM: Signing via host $AUTHENTICODE_SIGNHOST" + + scp "$inname" "$AUTHENTICODE_SIGNHOST:a.exe" + # Invoke command on Windows via ssh + ssh "$AUTHENTICODE_SIGNHOST" \""$AUTHENTICODE_TOOL"\" sign \ + /v /sm \ + /a /n '"g10 Code GmbH"' \ + /tr \""$AUTHENTICODE_TSURL"\" /td sha256 \ + /d \""$desc"\" \ + /fd sha256 /du https://gnupg.com a.exe + scp "$AUTHENTICODE_SIGNHOST:a.exe" "$outname" + +elif [ "$AUTHENTICODE_KEY" = card ]; then + + echo >&2 "$PGM: Signing using a card: '$inname'" + + "$OSSLSIGNCODE" sign \ + -pkcs11engine "$OSSLPKCS11ENGINE" \ + -pkcs11module "$SCUTEMODULE" \ + -certs "$AUTHENTICODE_CERTS" \ + -h sha256 -n "$desc" -i "$url" \ + -ts "$AUTHENTICODE_TSURL" \ + -in "$inname" -out "$outname.tmp" + cp "$outname.tmp" "$outname" + rm "$outname.tmp" + +elif [ "$AUTHENTICODE_KEY" = none ]; then + + echo >&2 "$PGM: Signing disabled; would sign: '$inname'" + [ "$inname" != "$outname" ] && cp "$inname" "$outname" + +else + + echo >&2 "$PGM: Signing using key $AUTHENTICODE_KEY" + osslsigncode sign -certs "$AUTHENTICODE_CERTS" \ + -pkcs12 "$AUTHENTICODE_KEY" -askpass \ + -ts "$AUTHENTICODE_TSURL" \ + -h sha256 -n "$desc" -i "$url" \ + -in "$inname" -out "$outname.tmp" + cp "$outname.tmp" "$outname" + rm "$outname.tmp" + +fi + +if [ -z "$dryrun" ]; then + [ "$stamp" = yes ] && touch "$outname.asig-done" + echo >&2 "$PGM: signed file is '$outname'" +fi + +# eof diff --git a/tools/gpg-card.c b/tools/gpg-card.c index 22b95d0d7..8b3a3082b 100644 --- a/tools/gpg-card.c +++ b/tools/gpg-card.c @@ -315,9 +315,9 @@ main (int argc, char **argv) /* Set defaults for non given options. */ if (!opt.gpg_program) - opt.gpg_program = gnupg_module_name (GNUPG_MODULE_NAME_GPG); + opt.gpg_program = xstrdup (gnupg_module_name (GNUPG_MODULE_NAME_GPG)); if (!opt.gpgsm_program) - opt.gpgsm_program = gnupg_module_name (GNUPG_MODULE_NAME_GPGSM); + opt.gpgsm_program = xstrdup (gnupg_module_name (GNUPG_MODULE_NAME_GPGSM)); /* Now build the list of commands. We guess the size of the array * by assuming each item is a complete command. Obviously this will @@ -836,6 +836,21 @@ list_one_kinfo (card_info_t info, key_info_t kinfo, } +/* Return the retired key number if KEYREF is for a retired key; 0 if + * not. */ +static int +piv_keyref_is_retired (const char *keyref) +{ + if (!strncmp (keyref, "PIV.8", 5) + && keyref[5] >= '2' && hexdigitp (keyref + 5)) + return xtoi_1 (keyref+5) - 1; + else if (!strncmp (keyref, "PIV.9", 5) + && keyref[5] >= '0' && keyref[5] <= '5') + return atoi_1 (keyref+5) + 15; + else + return 0; +} + /* List all keyinfo in INFO using the list of LABELS. */ static void list_all_kinfo (card_info_t info, keyinfolabel_t labels, estream_t fp, @@ -843,6 +858,7 @@ list_all_kinfo (card_info_t info, keyinfolabel_t labels, estream_t fp, { key_info_t kinfo; int idx, i, j; + int rn; /* Print the keyinfo. We first print those we known and then all * remaining item. */ @@ -864,9 +880,15 @@ list_all_kinfo (card_info_t info, keyinfolabel_t labels, estream_t fp, { if (kinfo->xflag) continue; - tty_fprintf (fp, "Key %s", kinfo->keyref); - for (i=4+strlen (kinfo->keyref), j=0; i < 18; i++, j=1) - tty_fprintf (fp, j? ".":" "); + if (info->apptype == APP_TYPE_PIV + && (rn = piv_keyref_is_retired (kinfo->keyref))) + tty_fprintf (fp, "Key retired %2d ...", rn); + else + { + tty_fprintf (fp, "Key %s", kinfo->keyref); + for (i=4+strlen (kinfo->keyref), j=0; i < 18; i++, j=1) + tty_fprintf (fp, j? ".":" "); + } tty_fprintf (fp, ":"); list_one_kinfo (info, kinfo, NULL, fp, no_key_lookup, create_shadow); } @@ -2218,13 +2240,15 @@ cmd_writecert (card_info_t info, char *argstr) && ascii_memistr (data, datalen, "-----END CERTIFICATE-----") && !memchr (data, 0, datalen) && !memchr (data, 1, datalen)) { - struct b64state b64; + gpgrt_b64state_t b64; - err = b64dec_start (&b64, ""); - if (!err) - err = b64dec_proc (&b64, data, datalen, &datalen); + b64 = gpgrt_b64dec_start (""); + if (!b64) + err = gpg_error_from_syserror (); + else + err = gpgrt_b64dec_proc (b64, data, datalen, &datalen); if (!err) - err = b64dec_finish (&b64); + err = gpgrt_b64dec_finish (b64); if (err) goto leave; } @@ -3779,7 +3803,7 @@ cmd_gpg (card_info_t info, char *argstr, int use_gpgsm) char **argarray; ccparray_t ccp; const char **argv = NULL; - pid_t pid; + gnupg_process_t proc; int i; if (!info) @@ -3807,15 +3831,15 @@ cmd_gpg (card_info_t info, char *argstr, int use_gpgsm) goto leave; } - err = gnupg_spawn_process (use_gpgsm? opt.gpgsm_program:opt.gpg_program, - argv, NULL, (GNUPG_SPAWN_KEEP_STDOUT - |GNUPG_SPAWN_KEEP_STDERR), - NULL, NULL, NULL, &pid); + err = gnupg_process_spawn (use_gpgsm? opt.gpgsm_program:opt.gpg_program, + argv, + (GNUPG_PROCESS_STDOUT_KEEP + | GNUPG_PROCESS_STDERR_KEEP), + NULL, NULL, &proc); if (!err) { - err = gnupg_wait_process (use_gpgsm? opt.gpgsm_program:opt.gpg_program, - pid, 1, NULL); - gnupg_release_process (pid); + err = gnupg_process_wait (proc, 1); + gnupg_process_release (proc); } diff --git a/tools/gpg-connect-agent.c b/tools/gpg-connect-agent.c index cf4e64e2b..577b12575 100644 --- a/tools/gpg-connect-agent.c +++ b/tools/gpg-connect-agent.c @@ -898,8 +898,10 @@ static void do_sendfd (assuan_context_t ctx, char *line) { estream_t fp; - char *name, *mode, *p; - int rc, fd; + char *name, *p; + int rc; + char mode[32]; + es_syshd_t hd; /* Get file name. */ name = line; @@ -911,17 +913,25 @@ do_sendfd (assuan_context_t ctx, char *line) p++; /* Get mode. */ - mode = p; - if (!*mode) - mode = "r"; + if (!*p) + { + mode[0] = 'r'; + mode[1] = 0; + p = &mode[1]; + } else { - for (p=mode; *p && !spacep (p); p++) - ; - if (*p) - *p++ = 0; + int i; + for (i = 0; *p && !spacep (p); p++) + mode[i++] = *p; + mode[i] = 0; + p = &mode[i]; } +#ifdef HAVE_W32_SYSTEM + strcpy (p, ",sysopen"); +#endif + /* Open and send. */ fp = es_fopen (name, mode); if (!fp) @@ -930,15 +940,30 @@ do_sendfd (assuan_context_t ctx, char *line) name, mode, strerror (errno)); return; } - fd = es_fileno (fp); + es_syshd (fp, &hd); + +#ifdef HAVE_W32_SYSTEM + if (opt.verbose) + log_error ("file '%s' opened in \"%s\" mode, fd=%p\n", + name, mode, hd.u.handle); +#else if (opt.verbose) log_error ("file '%s' opened in \"%s\" mode, fd=%d\n", - name, mode, fd); + name, mode, hd.u.fd); +#endif - rc = assuan_sendfd (ctx, INT2FD (fd) ); +#ifdef HAVE_W32_SYSTEM + rc = assuan_sendfd (ctx, hd.u.handle); + if (rc) + log_error ("sending descriptor %p failed: %s\n", hd.u.handle, + gpg_strerror (rc)); +#else + rc = assuan_sendfd (ctx, hd.u.fd); if (rc) - log_error ("sending descriptor %d failed: %s\n", fd, gpg_strerror (rc)); + log_error ("sending descriptor %d failed: %s\n", hd.u.fd, + gpg_strerror (rc)); +#endif es_fclose (fp); } @@ -1013,8 +1038,9 @@ do_open (char *line) #if defined(HAVE_W32_SYSTEM) { HANDLE prochandle, handle, newhandle; + char numbuf[35]; - handle = (void*)_get_osfhandle (fd); + handle = (HANDLE)_get_osfhandle (fd); prochandle = OpenProcess (PROCESS_DUP_HANDLE, FALSE, server_pid); if (!prochandle) @@ -1035,11 +1061,13 @@ do_open (char *line) } CloseHandle (prochandle); open_fd_table[fd].handle = newhandle; + + snprintf (numbuf, sizeof numbuf, "%p", open_fd_table[fd].handle); + set_var (varname, numbuf); } if (opt.verbose) - log_info ("file '%s' opened in \"%s\" mode, fd=%d (libc=%d)\n", - name, mode, (int)open_fd_table[fd].handle, fd); - set_int_var (varname, (int)open_fd_table[fd].handle); + log_info ("file '%s' opened in \"%s\" mode, fd=%p (libc=%d)\n", + name, mode, open_fd_table[fd].handle, fd); #else /* Unix */ if (opt.verbose) log_info ("file '%s' opened in \"%s\" mode, fd=%d\n", @@ -1060,13 +1088,28 @@ do_open (char *line) static void do_close (char *line) { - int fd = atoi (line); + int fd; #ifdef HAVE_W32_SYSTEM int i; + gpg_error_t err; + es_syshd_t syshd; + + err = gnupg_parse_fdstr (line, &syshd); + if (err) + { + log_error ("given fd (system handle) is not valid\n"); + return; + } + + if (syshd.type == ES_SYSHD_FD) + { + log_error ("given fd is stdin/out/err\n"); + return; + } for (i=0; i < DIM (open_fd_table); i++) - if ( open_fd_table[i].inuse && open_fd_table[i].handle == (void*)fd) + if (open_fd_table[i].inuse && open_fd_table[i].handle == syshd.u.handle) break; if (i < DIM (open_fd_table)) fd = i; @@ -1075,6 +1118,8 @@ do_close (char *line) log_error ("given fd (system handle) has not been opened\n"); return; } +#else + fd = atoi (line); #endif if (fd < 0 || fd >= DIM (open_fd_table)) @@ -1105,7 +1150,7 @@ do_showopen (void) if (open_fd_table[i].inuse) { #ifdef HAVE_W32_SYSTEM - printf ("%-15d (libc=%d)\n", (int)open_fd_table[i].handle, i); + printf ("%p (libc=%d)\n", open_fd_table[i].handle, i); #else printf ("%-15d\n", i); #endif @@ -2302,14 +2347,14 @@ start_agent (void) err = start_new_dirmngr (&ctx, GPG_ERR_SOURCE_DEFAULT, opt.dirmngr_program, - opt.autostart, + opt.autostart?ASSHELP_FLAG_AUTOSTART:0, !opt.quiet, 0, NULL, NULL); else if (opt.use_keyboxd) err = start_new_keyboxd (&ctx, GPG_ERR_SOURCE_DEFAULT, opt.keyboxd_program, - opt.autostart, + opt.autostart?ASSHELP_FLAG_AUTOSTART:0, !opt.quiet, 0, NULL, NULL); else @@ -2318,7 +2363,7 @@ start_agent (void) opt.agent_program, NULL, NULL, session_env, - opt.autostart, + opt.autostart?ASSHELP_FLAG_AUTOSTART:0, !opt.quiet, 0, NULL, NULL); diff --git a/tools/gpgconf-comp.c b/tools/gpgconf-comp.c index 90f2f53d3..d6aa9d61b 100644 --- a/tools/gpgconf-comp.c +++ b/tools/gpgconf-comp.c @@ -744,7 +744,7 @@ gpg_agent_runtime_change (int killflag) gpg_error_t err = 0; const char *pgmname; const char *argv[5]; - pid_t pid = (pid_t)(-1); + gnupg_process_t proc = NULL; int i = 0; int cmdidx; @@ -761,13 +761,13 @@ gpg_agent_runtime_change (int killflag) log_assert (i < DIM(argv)); if (!err) - err = gnupg_spawn_process_fd (pgmname, argv, -1, -1, -1, &pid); + err = gnupg_process_spawn (pgmname, argv, 0, NULL, NULL, &proc); if (!err) - err = gnupg_wait_process (pgmname, pid, 1, NULL); + err = gnupg_process_wait (proc, 1); if (err) gc_error (0, 0, "error running '%s %s': %s", pgmname, argv[cmdidx], gpg_strerror (err)); - gnupg_release_process (pid); + gnupg_process_release (proc); } @@ -777,7 +777,7 @@ scdaemon_runtime_change (int killflag) gpg_error_t err = 0; const char *pgmname; const char *argv[9]; - pid_t pid = (pid_t)(-1); + gnupg_process_t proc = NULL; int i = 0; int cmdidx; @@ -805,13 +805,13 @@ scdaemon_runtime_change (int killflag) log_assert (i < DIM(argv)); if (!err) - err = gnupg_spawn_process_fd (pgmname, argv, -1, -1, -1, &pid); + err = gnupg_process_spawn (pgmname, argv, 0, NULL, NULL, &proc); if (!err) - err = gnupg_wait_process (pgmname, pid, 1, NULL); + err = gnupg_process_wait (proc, 1); if (err) gc_error (0, 0, "error running '%s %s': %s", pgmname, argv[cmdidx], gpg_strerror (err)); - gnupg_release_process (pid); + gnupg_process_release (proc); } @@ -822,7 +822,7 @@ tpm2daemon_runtime_change (int killflag) gpg_error_t err = 0; const char *pgmname; const char *argv[9]; - pid_t pid = (pid_t)(-1); + gnupg_process_t proc = NULL; int i = 0; int cmdidx; @@ -850,13 +850,13 @@ tpm2daemon_runtime_change (int killflag) log_assert (i < DIM(argv)); if (!err) - err = gnupg_spawn_process_fd (pgmname, argv, -1, -1, -1, &pid); + err = gnupg_process_spawn (pgmname, argv, 0, NULL, NULL, &proc); if (!err) - err = gnupg_wait_process (pgmname, pid, 1, NULL); + err = gnupg_process_wait (proc, 1); if (err) gc_error (0, 0, "error running '%s %s': %s", pgmname, argv[cmdidx], gpg_strerror (err)); - gnupg_release_process (pid); + gnupg_process_release (proc); } #endif @@ -867,7 +867,7 @@ dirmngr_runtime_change (int killflag) gpg_error_t err = 0; const char *pgmname; const char *argv[6]; - pid_t pid = (pid_t)(-1); + gnupg_process_t proc = NULL; int i = 0; int cmdidx; @@ -885,13 +885,13 @@ dirmngr_runtime_change (int killflag) log_assert (i < DIM(argv)); if (!err) - err = gnupg_spawn_process_fd (pgmname, argv, -1, -1, -1, &pid); + err = gnupg_process_spawn (pgmname, argv, 0, NULL, NULL, &proc); if (!err) - err = gnupg_wait_process (pgmname, pid, 1, NULL); + err = gnupg_process_wait (proc, 1); if (err) gc_error (0, 0, "error running '%s %s': %s", pgmname, argv[cmdidx], gpg_strerror (err)); - gnupg_release_process (pid); + gnupg_process_release (proc); } @@ -901,7 +901,7 @@ keyboxd_runtime_change (int killflag) gpg_error_t err = 0; const char *pgmname; const char *argv[6]; - pid_t pid = (pid_t)(-1); + gnupg_process_t proc = NULL; int i = 0; int cmdidx; @@ -919,13 +919,13 @@ keyboxd_runtime_change (int killflag) log_assert (i < DIM(argv)); if (!err) - err = gnupg_spawn_process_fd (pgmname, argv, -1, -1, -1, &pid); + err = gnupg_process_spawn (pgmname, argv, 0, NULL, NULL, &proc); if (!err) - err = gnupg_wait_process (pgmname, pid, 1, NULL); + err = gnupg_process_wait (proc, 1); if (err) gc_error (0, 0, "error running '%s %s': %s", pgmname, argv[cmdidx], gpg_strerror (err)); - gnupg_release_process (pid); + gnupg_process_release (proc); } @@ -937,7 +937,7 @@ gc_component_launch (int component) const char *pgmname; const char *argv[6]; int i; - pid_t pid; + gnupg_process_t proc = NULL; if (component < 0) { @@ -985,9 +985,9 @@ gc_component_launch (int component) argv[i] = NULL; log_assert (i < DIM(argv)); - err = gnupg_spawn_process_fd (pgmname, argv, -1, -1, -1, &pid); + err = gnupg_process_spawn (pgmname, argv, 0, NULL, NULL, &proc); if (!err) - err = gnupg_wait_process (pgmname, pid, 1, NULL); + err = gnupg_process_wait (proc, 1); if (err) gc_error (0, 0, "error running '%s%s%s': %s", pgmname, @@ -995,7 +995,7 @@ gc_component_launch (int component) : component == GC_COMPONENT_KEYBOXD? " --keyboxd":"", " NOP", gpg_strerror (err)); - gnupg_release_process (pid); + gnupg_process_release (proc); return err; } @@ -1336,8 +1336,7 @@ gc_component_check_options (int component, estream_t out, const char *conf_file) const char *pgmname; const char *argv[6]; int i; - pid_t pid; - int exitcode; + gnupg_process_t proc; estream_t errfp; error_line_t errlines; @@ -1370,22 +1369,28 @@ gc_component_check_options (int component, estream_t out, const char *conf_file) result = 0; errlines = NULL; - err = gnupg_spawn_process (pgmname, argv, NULL, 0, - NULL, NULL, &errfp, &pid); + err = gnupg_process_spawn (pgmname, argv, + GNUPG_PROCESS_STDERR_PIPE, + NULL, NULL, &proc); if (err) result |= 1; /* Program could not be run. */ else { + gnupg_process_get_streams (proc, 0, NULL, NULL, &errfp); errlines = collect_error_output (errfp, gc_component[component].name); - if (gnupg_wait_process (pgmname, pid, 1, &exitcode)) + if (!gnupg_process_wait (proc, 1)) { + int exitcode; + + gnupg_process_ctl (proc, GNUPG_PROCESS_GET_EXIT_ID, &exitcode); if (exitcode == -1) result |= 1; /* Program could not be run or it terminated abnormally. */ - result |= 2; /* Program returned an error. */ + else if (exitcode) + result |= 2; /* Program returned an error. */ } - gnupg_release_process (pid); + gnupg_process_release (proc); es_fclose (errfp); } @@ -1725,8 +1730,7 @@ retrieve_options_from_program (gc_component_id_t component, int only_installed) const char *pgmname; const char *argv[2]; estream_t outfp; - int exitcode; - pid_t pid; + gnupg_process_t proc; known_option_t *known_option; gc_option_t *option; char *line = NULL; @@ -1759,14 +1763,17 @@ retrieve_options_from_program (gc_component_id_t component, int only_installed) /* First we need to read the option table from the program. */ argv[0] = "--dump-option-table"; argv[1] = NULL; - err = gnupg_spawn_process (pgmname, argv, NULL, 0, - NULL, &outfp, NULL, &pid); + err = gnupg_process_spawn (pgmname, argv, + GNUPG_PROCESS_STDOUT_PIPE, + NULL, NULL, &proc); if (err) { gc_error (1, 0, "could not gather option table from '%s': %s", pgmname, gpg_strerror (err)); } + gnupg_process_get_streams (proc, 0, NULL, &outfp, NULL); + read_line_parm.pgmname = pgmname; read_line_parm.fp = outfp; read_line_parm.line = line; @@ -1925,12 +1932,17 @@ retrieve_options_from_program (gc_component_id_t component, int only_installed) line_len = read_line_parm.line_len; log_assert (opt_table_used + pseudo_count == opt_info_used); + err = gnupg_process_wait (proc, 1); + if (!err) + { + int exitcode; - err = gnupg_wait_process (pgmname, pid, 1, &exitcode); - if (err) - gc_error (1, 0, "running %s failed (exitcode=%d): %s", - pgmname, exitcode, gpg_strerror (err)); - gnupg_release_process (pid); + gnupg_process_ctl (proc, GNUPG_PROCESS_GET_EXIT_ID, &exitcode); + if (exitcode) + gc_error (1, 0, "running %s failed (exitcode=%d): %s", + pgmname, exitcode, gpg_strerror (err)); + } + gnupg_process_release (proc); /* Make the gpgrt option table and the internal option table available. */ gc_component[component].opt_table = opt_table; @@ -1940,14 +1952,17 @@ retrieve_options_from_program (gc_component_id_t component, int only_installed) /* Now read the default options. */ argv[0] = "--gpgconf-list"; argv[1] = NULL; - err = gnupg_spawn_process (pgmname, argv, NULL, 0, - NULL, &outfp, NULL, &pid); + err = gnupg_process_spawn (pgmname, argv, + GNUPG_PROCESS_STDOUT_PIPE, + NULL, NULL, &proc); if (err) { gc_error (1, 0, "could not gather active options from '%s': %s", pgmname, gpg_strerror (err)); } + gnupg_process_get_streams (proc, 0, NULL, &outfp, NULL); + while ((length = es_read_line (outfp, &line, &line_len, NULL)) > 0) { char *linep; @@ -2030,11 +2045,17 @@ retrieve_options_from_program (gc_component_id_t component, int only_installed) if (es_fclose (outfp)) gc_error (1, errno, "error closing %s", pgmname); - err = gnupg_wait_process (pgmname, pid, 1, &exitcode); - if (err) - gc_error (1, 0, "running %s failed (exitcode=%d): %s", - pgmname, exitcode, gpg_strerror (err)); - gnupg_release_process (pid); + err = gnupg_process_wait (proc, 1); + if (!err) + { + int exitcode; + + gnupg_process_ctl (proc, GNUPG_PROCESS_GET_EXIT_ID, &exitcode); + if (exitcode) + gc_error (1, 0, "running %s failed (exitcode=%d): %s", + pgmname, exitcode, gpg_strerror (err)); + } + gnupg_process_release (proc); /* At this point, we can parse the configuration file. */ diff --git a/tools/gpgconf.c b/tools/gpgconf.c index 061a4f727..ac709ae21 100644 --- a/tools/gpgconf.c +++ b/tools/gpgconf.c @@ -343,7 +343,7 @@ list_dirs (estream_t fp, char **names, int show_config_mode) #ifdef HAVE_W32_SYSTEM tmp = read_w32_registry_string (NULL, - GNUPG_REGISTRY_DIR, + gnupg_registry_dir (), "HomeDir"); if (tmp) { @@ -352,14 +352,14 @@ list_dirs (estream_t fp, char **names, int show_config_mode) xfree (tmp); if ((tmp = read_w32_registry_string ("HKEY_CURRENT_USER", - GNUPG_REGISTRY_DIR, + gnupg_registry_dir (), "HomeDir"))) { xfree (tmp); hkcu = 1; } if ((tmp = read_w32_registry_string ("HKEY_LOCAL_MACHINE", - GNUPG_REGISTRY_DIR, + gnupg_registry_dir (), "HomeDir"))) { xfree (tmp); @@ -372,15 +372,15 @@ list_dirs (estream_t fp, char **names, int show_config_mode) "Note: homedir taken from registry key %s%s\\%s:%s\n" "\n", hkcu?"HKCU":"", hklm?"HKLM":"", - GNUPG_REGISTRY_DIR, "HomeDir"); + gnupg_registry_dir (), "HomeDir"); else log_info ("Warning: homedir taken from registry key (%s:%s) in%s%s\n", - GNUPG_REGISTRY_DIR, "HomeDir", + gnupg_registry_dir (), "HomeDir", hkcu?" HKCU":"", hklm?" HKLM":""); } else if ((tmp = read_w32_registry_string (NULL, - GNUPG_REGISTRY_DIR, + gnupg_registry_dir (), NULL))) { xfree (tmp); @@ -391,7 +391,7 @@ list_dirs (estream_t fp, char **names, int show_config_mode) "\n", GNUPG_REGISTRY_DIR); else log_info ("Warning: registry key (%s) without value in HKCU or HKLM\n", - GNUPG_REGISTRY_DIR); + gnupg_registry_dir ()); } #else /*!HAVE_W32_SYSTEM*/ @@ -1303,17 +1303,17 @@ show_versions_via_dirmngr (estream_t fp) const char *pgmname; const char *argv[2]; estream_t outfp; - pid_t pid; + gnupg_process_t proc; char *line = NULL; size_t line_len = 0; ssize_t length; - int exitcode; pgmname = gnupg_module_name (GNUPG_MODULE_NAME_DIRMNGR); argv[0] = "--gpgconf-versions"; argv[1] = NULL; - err = gnupg_spawn_process (pgmname, argv, NULL, 0, - NULL, &outfp, NULL, &pid); + err = gnupg_process_spawn (pgmname, argv, + GNUPG_PROCESS_STDOUT_PIPE, + NULL, NULL, &proc); if (err) { log_error ("error spawning %s: %s", pgmname, gpg_strerror (err)); @@ -1321,6 +1321,7 @@ show_versions_via_dirmngr (estream_t fp) return; } + gnupg_process_get_streams (proc, 0, NULL, &outfp, NULL); while ((length = es_read_line (outfp, &line, &line_len, NULL)) > 0) { /* Strip newline and carriage return, if present. */ @@ -1341,14 +1342,17 @@ show_versions_via_dirmngr (estream_t fp) pgmname, gpg_strerror (err)); } - err = gnupg_wait_process (pgmname, pid, 1, &exitcode); - if (err) + err = gnupg_process_wait (proc, 1); + if (!err) { + int exitcode; + + gnupg_process_ctl (proc, GNUPG_PROCESS_GET_EXIT_ID, &exitcode); log_error ("running %s failed (exitcode=%d): %s\n", pgmname, exitcode, gpg_strerror (err)); es_fprintf (fp, "[error: can't get further info]\n"); } - gnupg_release_process (pid); + gnupg_process_release (proc); xfree (line); } @@ -1485,13 +1489,14 @@ show_other_registry_entries (estream_t outfp) static struct { int group; const char *name; + unsigned int prependregkey:1; } names[] = { { 1, "HKLM\\Software\\Gpg4win:Install Directory" }, { 1, "HKLM\\Software\\Gpg4win:Desktop-Version" }, { 1, "HKLM\\Software\\Gpg4win:VS-Desktop-Version" }, - { 1, "\\" GNUPG_REGISTRY_DIR ":HomeDir" }, - { 1, "\\" GNUPG_REGISTRY_DIR ":DefaultLogFile" }, + { 1, ":HomeDir", 1 }, + { 1, ":DefaultLogFile", 1 }, { 2, "\\Software\\Microsoft\\Office\\Outlook\\Addins\\GNU.GpgOL" ":LoadBehavior" }, { 2, "HKCU\\Software\\Microsoft\\Office\\16.0\\Outlook\\Options\\Mail:" @@ -1537,6 +1542,13 @@ show_other_registry_entries (estream_t outfp) names[idx].name, NULL); name = namebuf; } + else if (names[idx].prependregkey) + { + xfree (namebuf); + namebuf = xstrconcat ("\\", gnupg_registry_dir (), + names[idx].name, NULL); + name = namebuf; + } value = read_w32_reg_string (name, &from_hklm); if (!value) diff --git a/tools/gpgtar-create.c b/tools/gpgtar-create.c index 0994322ea..7af5a2ede 100644 --- a/tools/gpgtar-create.c +++ b/tools/gpgtar-create.c @@ -1069,7 +1069,7 @@ gpgtar_create (char **inpattern, const char *files_from, int null_names, estream_t files_from_stream = NULL; estream_t outstream = NULL; int eof_seen = 0; - pid_t pid = (pid_t)(-1); + gnupg_process_t proc = NULL; unsigned int skipped_open = 0; memset (scanctrl, 0, sizeof *scanctrl); @@ -1228,7 +1228,11 @@ gpgtar_create (char **inpattern, const char *files_from, int null_names, { strlist_t arg; ccparray_t ccp; +#ifdef HAVE_W32_SYSTEM + HANDLE except[2] = { INVALID_HANDLE_VALUE, INVALID_HANDLE_VALUE }; +#else int except[2] = { -1, -1 }; +#endif const char **argv; /* '--encrypt' may be combined with '--symmetric', but 'encrypt' @@ -1246,13 +1250,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"); @@ -1286,14 +1296,15 @@ gpgtar_create (char **inpattern, const char *files_from, int null_names, goto leave; } - err = gnupg_spawn_process (opt.gpg_program, argv, - except[0] == -1? NULL : except, - (GNUPG_SPAWN_KEEP_STDOUT - | GNUPG_SPAWN_KEEP_STDERR), - &outstream, NULL, NULL, &pid); + err = gnupg_process_spawn (opt.gpg_program, argv, + (GNUPG_PROCESS_STDIN_PIPE + | GNUPG_PROCESS_STDOUT_KEEP + | GNUPG_PROCESS_STDERR_KEEP), + gnupg_spawn_helper, except, &proc); xfree (argv); if (err) goto leave; + gnupg_process_get_streams (proc, 0, &outstream, NULL, NULL); es_set_binary (outstream); } else if (opt.outfile) /* No crypto */ @@ -1332,23 +1343,25 @@ gpgtar_create (char **inpattern, const char *files_from, int null_names, write_progress (1, global_written_files, global_total_files); write_progress (0, global_written_data, global_total_data); - if (pid != (pid_t)(-1)) + if (proc) { - int exitcode; - err = es_fclose (outstream); outstream = NULL; if (err) log_error ("error closing pipe: %s\n", gpg_strerror (err)); - else + + err = gnupg_process_wait (proc, 1); + if (!err) { - err = gnupg_wait_process (opt.gpg_program, pid, 1, &exitcode); - if (err) + int exitcode; + + gnupg_process_ctl (proc, GNUPG_PROCESS_GET_EXIT_ID, &exitcode); + if (exitcode) log_error ("running %s failed (exitcode=%d): %s", opt.gpg_program, exitcode, gpg_strerror (err)); - gnupg_release_process (pid); - pid = (pid_t)(-1); } + gnupg_process_release (proc); + proc = NULL; } if (skipped_open) @@ -1361,7 +1374,7 @@ gpgtar_create (char **inpattern, const char *files_from, int null_names, if (!err) { gpg_error_t first_err; - if (outstream != es_stdout || pid != (pid_t)(-1)) + if (outstream != es_stdout) first_err = es_fclose (outstream); else first_err = es_fflush (outstream); diff --git a/tools/gpgtar-extract.c b/tools/gpgtar-extract.c index 936d03e3e..87113b054 100644 --- a/tools/gpgtar-extract.c +++ b/tools/gpgtar-extract.c @@ -339,7 +339,7 @@ gpgtar_extract (const char *filename, int decrypt) char *dirname = NULL; struct tarinfo_s tarinfo_buffer; tarinfo_t tarinfo = &tarinfo_buffer; - pid_t pid = (pid_t)(-1); + gnupg_process_t proc; char *logfilename = NULL; unsigned long long notextracted; @@ -384,7 +384,11 @@ gpgtar_extract (const char *filename, int decrypt) { strlist_t arg; ccparray_t ccp; +#ifdef HAVE_W32_SYSTEM + HANDLE except[2] = { INVALID_HANDLE_VALUE, INVALID_HANDLE_VALUE }; +#else int except[2] = { -1, -1 }; +#endif const char **argv; ccparray_init (&ccp, 0); @@ -392,13 +396,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) { @@ -425,14 +435,14 @@ gpgtar_extract (const char *filename, int decrypt) goto leave; } - err = gnupg_spawn_process (opt.gpg_program, argv, - except[0] == -1? NULL : except, - ((filename? 0 : GNUPG_SPAWN_KEEP_STDIN) - | GNUPG_SPAWN_KEEP_STDERR), - NULL, &stream, NULL, &pid); + err = gnupg_process_spawn (opt.gpg_program, argv, + ((filename ? 0 : GNUPG_PROCESS_STDIN_KEEP) + | GNUPG_PROCESS_STDOUT_PIPE), + gnupg_spawn_helper, except, &proc); xfree (argv); if (err) goto leave; + gnupg_process_get_streams (proc, 0, NULL, &stream, NULL); es_set_binary (stream); } else if (filename) @@ -472,23 +482,25 @@ gpgtar_extract (const char *filename, int decrypt) header = NULL; } - if (pid != (pid_t)(-1)) + if (proc) { - int exitcode; - err = es_fclose (stream); stream = NULL; if (err) log_error ("error closing pipe: %s\n", gpg_strerror (err)); - else + + err = gnupg_process_wait (proc, 1); + if (!err) { - err = gnupg_wait_process (opt.gpg_program, pid, 1, &exitcode); - if (err) + int exitcode; + + gnupg_process_ctl (proc, GNUPG_PROCESS_GET_EXIT_ID, &exitcode); + if (exitcode) log_error ("running %s failed (exitcode=%d): %s", opt.gpg_program, exitcode, gpg_strerror (err)); - gnupg_release_process (pid); - pid = (pid_t)(-1); } + gnupg_process_release (proc); + proc = NULL; } leave: diff --git a/tools/gpgtar-list.c b/tools/gpgtar-list.c index c5bf25825..0c5e474f3 100644 --- a/tools/gpgtar-list.c +++ b/tools/gpgtar-list.c @@ -460,7 +460,7 @@ gpgtar_list (const char *filename, int decrypt) strlist_t extheader = NULL; struct tarinfo_s tarinfo_buffer; tarinfo_t tarinfo = &tarinfo_buffer; - pid_t pid = (pid_t)(-1); + gnupg_process_t proc = NULL; memset (&tarinfo_buffer, 0, sizeof tarinfo_buffer); @@ -468,7 +468,11 @@ gpgtar_list (const char *filename, int decrypt) { strlist_t arg; ccparray_t ccp; +#ifdef HAVE_W32_SYSTEM + HANDLE except[2] = { INVALID_HANDLE_VALUE, INVALID_HANDLE_VALUE }; +#else int except[2] = { -1, -1 }; +#endif const char **argv; ccparray_init (&ccp, 0); @@ -476,13 +480,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, "-"); @@ -503,14 +513,14 @@ gpgtar_list (const char *filename, int decrypt) goto leave; } - err = gnupg_spawn_process (opt.gpg_program, argv, - except[0] == -1? NULL : except, - ((filename? 0 : GNUPG_SPAWN_KEEP_STDIN) - | GNUPG_SPAWN_KEEP_STDERR), - NULL, &stream, NULL, &pid); + err = gnupg_process_spawn (opt.gpg_program, argv, + ((filename ? 0 : GNUPG_PROCESS_STDIN_KEEP) + | GNUPG_PROCESS_STDOUT_PIPE), + gnupg_spawn_helper, except, &proc); xfree (argv); if (err) goto leave; + gnupg_process_get_streams (proc, 0, NULL, &stream, NULL); es_set_binary (stream); } else if (filename) /* No decryption requested. */ @@ -550,23 +560,24 @@ gpgtar_list (const char *filename, int decrypt) header = NULL; } - if (pid != (pid_t)(-1)) + if (proc) { - int exitcode; - err = es_fclose (stream); stream = NULL; if (err) log_error ("error closing pipe: %s\n", gpg_strerror (err)); - else + + err = gnupg_process_wait (proc, 1); + if (!err) { - err = gnupg_wait_process (opt.gpg_program, pid, 1, &exitcode); - if (err) - log_error ("running %s failed (exitcode=%d): %s", - opt.gpg_program, exitcode, gpg_strerror (err)); - gnupg_release_process (pid); - pid = (pid_t)(-1); + int exitcode; + + gnupg_process_ctl (proc, GNUPG_PROCESS_GET_EXIT_ID, &exitcode); + log_error ("running %s failed (exitcode=%d): %s", + opt.gpg_program, exitcode, gpg_strerror (err)); } + gnupg_process_release (proc); + proc = NULL; } leave: diff --git a/tools/gpgtar.c b/tools/gpgtar.c index ea1e1e751..f93ba2e65 100644 --- a/tools/gpgtar.c +++ b/tools/gpgtar.c @@ -127,7 +127,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", "@"), @@ -398,7 +398,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; @@ -480,7 +480,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 ()); @@ -512,31 +512,32 @@ 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); + es_syshd_t syshd; - if (!gnupg_fd_valid (fd)) - log_fatal ("status-fd is invalid: %s\n", strerror (errno)); + err = gnupg_parse_fdstr (opt.status_fd, &syshd); + if (err) + log_fatal ("status-fd is invalid: %s\n", gpg_strerror (err)); - if (fd == 1) + if (syshd.type == ES_SYSHD_FD && syshd.u.fd == 1) { opt.status_stream = es_stdout; if (!skip_crypto) log_fatal ("using stdout for the status-fd is not possible\n"); } - else if (fd == 2) + else if (syshd.type == ES_SYSHD_FD && syshd.u.fd == 2) opt.status_stream = es_stderr; else { - opt.status_stream = es_fdopen (fd, "w"); + opt.status_stream = es_sysopen (&syshd, "w"); if (opt.status_stream) es_setvbuf (opt.status_stream, NULL, _IOLBF, 0); } if (!opt.status_stream) { - log_fatal ("can't open fd %d for status output: %s\n", - fd, strerror (errno)); + log_fatal ("can't open fd %s for status output: %s\n", + opt.status_fd, strerror (errno)); } } diff --git a/tools/gpgtar.h b/tools/gpgtar.h index d86010476..4e36deaeb 100644 --- a/tools/gpgtar.h +++ b/tools/gpgtar.h @@ -45,7 +45,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; diff --git a/tools/mime-parser.c b/tools/mime-parser.c index 0db1a9c23..31f766ca5 100644 --- a/tools/mime-parser.c +++ b/tools/mime-parser.c @@ -93,7 +93,7 @@ struct mime_parser_context_s unsigned int boundary : 1; } show; - struct b64state *b64state; /* NULL or malloced Base64 decoder state. */ + gpgrt_b64state_t b64state; /* NULL or malloced Base64 decoder state. */ /* A buffer for reading a mail line, */ char line[5000]; @@ -410,15 +410,11 @@ parse_message_cb (void *opaque, rfc822parse_event_t event, rfc822parse_t msg) { ctx->decode_part = 2; if (ctx->b64state) - b64dec_finish (ctx->b64state); /* Reuse state. */ - else - { - ctx->b64state = xtrymalloc (sizeof *ctx->b64state); - if (!ctx->b64state) - rc = gpg_error_from_syserror (); - } - if (!rc) - rc = b64dec_start (ctx->b64state, NULL); + gpgrt_b64dec_finish (ctx->b64state); /* Release. */ + + ctx->b64state = gpgrt_b64dec_start (NULL); + if (!ctx->b64state) + rc = gpg_error_from_syserror (); } free (value); /* Right, we need a plain free. */ } @@ -528,10 +524,7 @@ mime_parser_release (mime_parser_t ctx) return; if (ctx->b64state) - { - b64dec_finish (ctx->b64state); - xfree (ctx->b64state); - } + gpgrt_b64dec_finish (ctx->b64state); xfree (ctx); } @@ -661,7 +654,7 @@ process_part_data (mime_parser_t ctx, char *line, size_t *length) else if (ctx->decode_part == 2) { log_assert (ctx->b64state); - err = b64dec_proc (ctx->b64state, line, *length, &nbytes); + err = gpgrt_b64dec_proc (ctx->b64state, line, *length, &nbytes); if (err) return err; *length = nbytes; diff --git a/tools/no-libgcrypt.c b/tools/no-libgcrypt.c index 3b577567a..cbf934013 100644 --- a/tools/no-libgcrypt.c +++ b/tools/no-libgcrypt.c @@ -137,14 +137,6 @@ gcry_set_fatalerror_handler (gcry_handler_error_t fnc, void *opaque) } void -gcry_set_log_handler (gcry_handler_log_t f, void *opaque) -{ - (void)f; - (void)opaque; -} - - -void gcry_create_nonce (void *buffer, size_t length) { (void)buffer; diff --git a/tools/wks-util.c b/tools/wks-util.c index 640116ce8..4a15d672a 100644 --- a/tools/wks-util.c +++ b/tools/wks-util.c @@ -599,7 +599,7 @@ wks_armor_key (estream_t *r_newkey, estream_t key, const char *prefix) { gpg_error_t err; estream_t newkey; - struct b64state b64state; + gpgrt_b64state_t b64state; char buffer[4096]; size_t nread; @@ -615,16 +615,19 @@ wks_armor_key (estream_t *r_newkey, estream_t key, const char *prefix) if (prefix) es_fputs (prefix, newkey); - err = b64enc_start_es (&b64state, newkey, "PGP PUBLIC KEY BLOCK"); - if (err) - goto leave; + b64state = gpgrt_b64enc_start (newkey, "PGP PUBLIC KEY BLOCK"); + if (!b64state) + { + err = gpg_error_from_syserror (); + goto leave; + } do { nread = es_fread (buffer, 1, sizeof buffer, key); if (!nread) break; - err = b64enc_write (&b64state, buffer, nread); + err = gpgrt_b64enc_write (b64state, buffer, nread); if (err) goto leave; } @@ -635,7 +638,7 @@ wks_armor_key (estream_t *r_newkey, estream_t key, const char *prefix) goto leave; } - err = b64enc_finish (&b64state); + err = gpgrt_b64enc_finish (b64state); if (err) goto leave; |