tools/gpgtar: Handle '--gpg-args'.
authorJustus Winter <justus@g10code.com>
Thu, 26 Nov 2015 14:36:52 +0000 (15:36 +0100)
committerJustus Winter <justus@g10code.com>
Thu, 26 Nov 2015 14:36:52 +0000 (15:36 +0100)
* tools/gpgtar-create.c (gpgtar_create): Use given arguments.
* tools/gpgtar-extract.c (gpgtar_extract): Likewise.
* tools/gpgtar-list.c (gpgtar_list): Likewise.
* tools/gpgtar.c (enum cmd_and_opt_values): New value.
(opts): Add 'gpg-args'.
(parse_arguments): Handle arguments.
* tools/gpgtar.h (opt): Add field 'gpg_arguments'.
* tests/openpgp/gpgtar.test: Simplify accordingly.

Signed-off-by: Justus Winter <justus@g10code.com>
tests/openpgp/gpgtar.test
tools/gpgtar-create.c
tools/gpgtar-extract.c
tools/gpgtar-list.c
tools/gpgtar.c
tools/gpgtar.h

index 5cb2353..acfaf3f 100755 (executable)
@@ -25,24 +25,30 @@ TESTFILES="$plain_files $data_files"
 TESTDIR=gpgtar.d
 FILELIST="${TESTDIR}/filelist"
 GPG=../../g10/gpg2
+GPGARGS="--trust-model=always"
+
 GPGTAR="../../tools/gpgtar"
-GPGZIP="sh ../../tools/gpg-zip --gpg-args --trust-model=always"
+GPGZIP="sh ../../tools/gpg-zip"
 
 for TOOL in "$GPGTAR" "$GPGZIP"
 do
     rm -rf -- "${TESTDIR}"
     mkdir "${TESTDIR}"
 
-    $TOOL --gpg "$GPG" --encrypt --recipient "$usrname2" \
+    $TOOL --gpg "$GPG" --gpg-args "$GPGARGS" \
+          --encrypt --recipient "$usrname2" \
          --output "${TESTDIR}/test.tar.pgp" $TESTFILES
 
-    $TOOL --gpg "$GPG" --list-archive "${TESTDIR}/test.tar.pgp" >"$FILELIST"
+    $TOOL --gpg "$GPG" --gpg-args "$GPGARGS" \
+          --list-archive "${TESTDIR}/test.tar.pgp" \
+          >"$FILELIST"
     for F in $TESTFILES
     do
        grep -qe "\\b${F}\\b" "$FILELIST"
     done
 
-    $TOOL --gpg "$GPG" --tar-args --directory="${TESTDIR}" \
+    $TOOL --gpg "$GPG"  --gpg-args "$GPGARGS" \
+          --tar-args --directory="${TESTDIR}" \
           --decrypt "${TESTDIR}/test.tar.pgp"
     for F in $TESTFILES
     do
index 774fcd3..cc82889 100644 (file)
@@ -894,7 +894,7 @@ gpgtar_create (char **inpattern, int encrypt)
 
       err = gpg_encrypt_stream (NULL,
                                 opt.gpg_program,
-                                NULL,
+                                opt.gpg_arguments,
                                 outstream,
                                 opt.recipients,
                                 cipher_stream);
index 7e7a351..3b73c85 100644 (file)
@@ -303,7 +303,7 @@ gpgtar_extract (const char *filename, int decrypt)
           err = gpg_error_from_syserror ();
           goto leave;
         }
-      err = gpg_decrypt_stream (NULL, opt.gpg_program, NULL,
+      err = gpg_decrypt_stream (NULL, opt.gpg_program, opt.gpg_arguments,
                                 cipher_stream, stream);
       if (err)
         goto leave;
index 1eab7e5..cb2ca5d 100644 (file)
@@ -306,7 +306,7 @@ gpgtar_list (const char *filename, int decrypt)
           err = gpg_error_from_syserror ();
           goto leave;
         }
-      err = gpg_decrypt_stream (NULL, opt.gpg_program, NULL,
+      err = gpg_decrypt_stream (NULL, opt.gpg_program, opt.gpg_arguments,
                                 cipher_stream, stream);
       if (err)
         goto leave;
index 2968fb5..90fee05 100644 (file)
@@ -75,6 +75,7 @@ enum cmd_and_opt_values
     oNull,
 
     /* Compatibility with gpg-zip.  */
+    oGpgArgs,
     oTarArgs,
   };
 
@@ -111,6 +112,7 @@ static ARGPARSE_OPTS opts[] = {
                 N_("|FILE|get names to create from FILE")),
   ARGPARSE_s_n (oNull, "null", N_("-T reads null-terminated names")),
 
+  ARGPARSE_s_s (oGpgArgs, "gpg-args", "@"),
   ARGPARSE_s_s (oTarArgs, "tar-args", "@"),
 
   ARGPARSE_end ()
@@ -340,6 +342,20 @@ parse_arguments (ARGPARSE_ARGS *pargs, ARGPARSE_OPTS *popts)
         case oOpenPGP: /* Dummy option for now.  */ break;
         case oCMS:     /* Dummy option for now.  */ break;
 
+        case oGpgArgs:;
+          strlist_t list;
+          if (shell_parse_stringlist (pargs->r.ret_str, &list))
+            log_error ("failed to parse gpg arguments '%s'\n",
+                       pargs->r.ret_str);
+          else
+            {
+              if (opt.gpg_arguments)
+                strlist_last (opt.gpg_arguments)->next = list;
+              else
+                opt.gpg_arguments = list;
+            }
+          break;
+
         case oTarArgs:;
           int tar_argc;
           char **tar_argv;
index 66a8ae1..f130c94 100644 (file)
@@ -30,6 +30,7 @@ struct
   unsigned int debug_level;
   int quiet;
   const char *gpg_program;
+  strlist_t gpg_arguments;
   const char *outfile;
   strlist_t recipients;
   const char *user;