aboutsummaryrefslogtreecommitdiffstats
path: root/tools/gpgtar-create.c
diff options
context:
space:
mode:
authorJustus Winter <[email protected]>2015-11-24 17:39:30 +0000
committerJustus Winter <[email protected]>2015-11-25 11:19:50 +0000
commit40dbee86f3043aff8a8c2055521e270318e33068 (patch)
tree9f04ed386099beb56a59c085fab0e4f7c6e92e4a /tools/gpgtar-create.c
parentcommon: Add stream interface to call-pgp. (diff)
downloadgnupg-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-create.c')
-rw-r--r--tools/gpgtar-create.c38
1 files changed, 37 insertions, 1 deletions
diff --git a/tools/gpgtar-create.c b/tools/gpgtar-create.c
index fad6d57ae..59b88bfb9 100644
--- a/tools/gpgtar-create.c
+++ b/tools/gpgtar-create.c
@@ -36,6 +36,7 @@
#include <assert.h>
#include "i18n.h"
+#include "../common/call-gpg.h"
#include "../common/sysutils.h"
#include "gpgtar.h"
@@ -740,13 +741,14 @@ write_eof_mark (estream_t stream)
INPATTERN is NULL take the pattern as null terminated strings from
stdin. */
void
-gpgtar_create (char **inpattern)
+gpgtar_create (char **inpattern, int encrypt)
{
gpg_error_t err = 0;
struct scanctrl_s scanctrl_buffer;
scanctrl_t scanctrl = &scanctrl_buffer;
tar_header_t hdr, *start_tail;
estream_t outstream = NULL;
+ estream_t cipher_stream = NULL;
int eof_seen = 0;
if (!inpattern)
@@ -863,6 +865,17 @@ gpgtar_create (char **inpattern)
if (outstream == es_stdout)
es_set_binary (es_stdout);
+ if (encrypt)
+ {
+ cipher_stream = outstream;
+ outstream = es_fopenmem (0, "rwb");
+ if (! outstream)
+ {
+ err = gpg_error_from_syserror ();
+ goto leave;
+ }
+ }
+
for (hdr = scanctrl->flist; hdr; hdr = hdr->next)
{
err = write_file (outstream, hdr);
@@ -870,6 +883,22 @@ gpgtar_create (char **inpattern)
goto leave;
}
err = write_eof_mark (outstream);
+ if (err)
+ goto leave;
+
+ if (encrypt)
+ {
+ err = es_fseek (outstream, 0, SEEK_SET);
+ if (err)
+ goto leave;
+
+ err = gpg_encrypt_stream (NULL, NULL,
+ outstream,
+ opt.recipients,
+ cipher_stream);
+ if (err)
+ goto leave;
+ }
leave:
if (!err)
@@ -879,6 +908,11 @@ gpgtar_create (char **inpattern)
else
err = es_fflush (outstream);
outstream = NULL;
+ if (cipher_stream != es_stdout)
+ err = es_fclose (cipher_stream);
+ else
+ err = es_fflush (cipher_stream);
+ cipher_stream = NULL;
}
if (err)
{
@@ -886,6 +920,8 @@ gpgtar_create (char **inpattern)
es_fname_get (outstream), gpg_strerror (err));
if (outstream && outstream != es_stdout)
es_fclose (outstream);
+ if (cipher_stream && cipher_stream != es_stdout)
+ es_fclose (cipher_stream);
if (opt.outfile)
gnupg_remove (opt.outfile);
}