diff options
author | Justus Winter <[email protected]> | 2015-11-24 17:39:30 +0000 |
---|---|---|
committer | Justus Winter <[email protected]> | 2015-11-25 11:19:50 +0000 |
commit | 40dbee86f3043aff8a8c2055521e270318e33068 (patch) | |
tree | 9f04ed386099beb56a59c085fab0e4f7c6e92e4a /tools/gpgtar-extract.c | |
parent | common: Add stream interface to call-pgp. (diff) | |
download | gnupg-40dbee86f3043aff8a8c2055521e270318e33068.tar.gz gnupg-40dbee86f3043aff8a8c2055521e270318e33068.zip |
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 <[email protected]>
Diffstat (limited to 'tools/gpgtar-extract.c')
-rw-r--r-- | tools/gpgtar-extract.c | 24 |
1 files changed, 23 insertions, 1 deletions
diff --git a/tools/gpgtar-extract.c b/tools/gpgtar-extract.c index 6e506d94d..19db0eb42 100644 --- a/tools/gpgtar-extract.c +++ b/tools/gpgtar-extract.c @@ -28,6 +28,7 @@ #include <assert.h> #include "i18n.h" +#include "../common/call-gpg.h" #include "../common/sysutils.h" #include "gpgtar.h" @@ -265,10 +266,11 @@ create_directory (const char *dirprefix) void -gpgtar_extract (const char *filename) +gpgtar_extract (const char *filename, int decrypt) { gpg_error_t err; estream_t stream; + estream_t cipher_stream = NULL; tar_header_t header = NULL; const char *dirprefix = NULL; char *dirname = NULL; @@ -292,6 +294,24 @@ gpgtar_extract (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; + } + if (filename) { dirprefix = strrchr (filename, '/'); @@ -340,5 +360,7 @@ gpgtar_extract (const char *filename) xfree (dirname); if (stream != es_stdin) es_fclose (stream); + if (stream != cipher_stream) + es_fclose (cipher_stream); return; } |