From 40dbee86f3043aff8a8c2055521e270318e33068 Mon Sep 17 00:00:00 2001 From: Justus Winter Date: Tue, 24 Nov 2015 18:39:30 +0100 Subject: tools: Add encryption and decryption support to gpgtar. * tools/Makefile.am: Amend CFLAGS and LDADD. * tools/gpgtar-create.c (gpgtar_create): Add encrypt flag and encrypt stream if requested. * tools/gpgtar-extract.c (gpgtar_extract): Likewise for decryption. * tools/gpgtar-list.c (gpgtar_list): Likewise. * tools/gpgtar.c (main): Initialize npth and assuan. Parse recipient and local user, and note which flags are currently ignored. Adapt calls to gpgtar_list and friends. (tar_and_encrypt): Drop stub function and prototype. (decrypt_and_untar): Likewise. (decrypt_and_list): Likewise. * tools/gpgtar.h (gpgtar_{create,extract,list}): Add encryption or decryption argument. Signed-off-by: Justus Winter --- tools/gpgtar-list.c | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) (limited to 'tools/gpgtar-list.c') diff --git a/tools/gpgtar-list.c b/tools/gpgtar-list.c index d525d24d7..41e08dbe1 100644 --- a/tools/gpgtar-list.c +++ b/tools/gpgtar-list.c @@ -26,6 +26,7 @@ #include "i18n.h" #include "gpgtar.h" +#include "../common/call-gpg.h" @@ -267,10 +268,11 @@ print_header (tar_header_t header, estream_t out) /* List the tarball FILENAME or, if FILENAME is NULL, the tarball read from stdin. */ void -gpgtar_list (const char *filename) +gpgtar_list (const char *filename, int decrypt) { gpg_error_t err; estream_t stream; + estream_t cipher_stream = NULL; tar_header_t header; if (filename) @@ -292,6 +294,24 @@ gpgtar_list (const char *filename) if (stream == es_stdin) es_set_binary (es_stdin); + if (decrypt) + { + cipher_stream = stream; + stream = es_fopenmem (0, "rwb"); + if (! stream) + { + err = gpg_error_from_syserror (); + goto leave; + } + err = gpg_decrypt_stream (NULL, NULL, cipher_stream, stream); + if (err) + goto leave; + + err = es_fseek (stream, 0, SEEK_SET); + if (err) + goto leave; + } + for (;;) { header = read_header (stream); @@ -311,6 +331,8 @@ gpgtar_list (const char *filename) xfree (header); if (stream != es_stdin) es_fclose (stream); + if (stream != cipher_stream) + es_fclose (cipher_stream); return; } -- cgit v1.2.3