From c66dacb98a1989c9977247c388fc5e5c5da4faae Mon Sep 17 00:00:00 2001 From: Werner Koch Date: Thu, 26 Jan 2023 11:39:19 +0100 Subject: [PATCH] gpgtar: Allow decryption from stdin. * tools/gpgtar.c (main): Revamp switch and fix usage test for aDecrypt and aList. -- GnuPG-bug-id: 6355 --- doc/tools.texi | 8 ++++++-- tools/gpgtar.c | 31 ++++++++++++++----------------- 2 files changed, 20 insertions(+), 19 deletions(-) diff --git a/doc/tools.texi b/doc/tools.texi index 6b9a9fea5..a68976ce6 100644 --- a/doc/tools.texi +++ b/doc/tools.texi @@ -1846,6 +1846,8 @@ Put given files and directories into a vanilla ``ustar'' archive. @item --extract @opindex extract Extract all files from a vanilla ``ustar'' archive. +If no file name is given (or it is "-") the archive is taken from +stdin. @item --encrypt @itemx -e @@ -1857,7 +1859,8 @@ be decrypted via a secret key or a passphrase. @item --decrypt @itemx -d @opindex decrypt -Extract all files from an encrypted archive. +Extract all files from an encrypted archive. If no file name is given +(or it is "-") the archive is taken from stdin. @item --sign @itemx -s @@ -1868,7 +1871,8 @@ encrypted archive. @item --list-archive @itemx -t @opindex list-archive -List the contents of the specified archive. +List the contents of the specified archive. If no file name is given +(or it is "-") the archive is taken from stdin. @item --symmetric @itemx -c diff --git a/tools/gpgtar.c b/tools/gpgtar.c index e86ed3299..8b943fde3 100644 --- a/tools/gpgtar.c +++ b/tools/gpgtar.c @@ -493,17 +493,27 @@ main (int argc, char **argv) switch (cmd) { + case aDecrypt: case aList: if (argc > 1) usage (1); - fname = argc ? *argv : NULL; + fname = (argc && strcmp (*argv, "-"))? *argv : NULL; if (opt.filename) log_info ("note: ignoring option --set-filename\n"); if (files_from) log_info ("note: ignoring option --files-from\n"); - err = gpgtar_list (fname, !skip_crypto); - if (err && log_get_errorcount (0) == 0) - log_error ("listing archive failed: %s\n", gpg_strerror (err)); + if (cmd == aDecrypt) + { + err = gpgtar_extract (fname, !skip_crypto); + if (err && !log_get_errorcount (0)) + log_error ("extracting archive failed: %s\n", gpg_strerror (err)); + } + else + { + err = gpgtar_list (fname, !skip_crypto); + if (err && !log_get_errorcount (0)) + log_error ("listing archive failed: %s\n", gpg_strerror (err)); + } break; case aEncrypt: @@ -524,19 +534,6 @@ main (int argc, char **argv) log_error ("creating archive failed: %s\n", gpg_strerror (err)); break; - case aDecrypt: - if (argc != 1) - usage (1); - if (opt.outfile) - log_info ("note: ignoring option --output\n"); - if (files_from) - log_info ("note: ignoring option --files-from\n"); - fname = argc ? *argv : NULL; - err = gpgtar_extract (fname, !skip_crypto); - if (err && log_get_errorcount (0) == 0) - log_error ("extracting archive failed: %s\n", gpg_strerror (err)); - break; - default: log_error (_("invalid command (there is no implicit command)\n")); break;