mirror of
git://git.gnupg.org/gnupg.git
synced 2025-07-03 22:56:33 +02:00
gpgtar: Finally use a pipe for decryption.
* tools/gpgtar.h (opt): Add new flags.
* tools/gpgtar.c: new options --batch, --yes, --no, --status-fd, and
--require-compliance.
(main): Init signals.
* tools/gpgtar-create.c: Add new header files.
(gpgtar_create): Rework to use a pipe for encryption and signing.
* tools/gpgtar-list.c: Add new header files.
(gpgtar_list): Rework to use a pipe for decryption.
* tools/gpgtar-extract.c: Add new header files.
(gpgtar_extract): Rework to use a pipe for decryption.
--
Fixes-commit: 40dbee86f3
This commit is contained in:
parent
2f1afc1296
commit
e5ef5e3b91
6 changed files with 275 additions and 146 deletions
|
@ -27,8 +27,10 @@
|
|||
#include <string.h>
|
||||
|
||||
#include "../common/i18n.h"
|
||||
#include <gpg-error.h>
|
||||
#include "gpgtar.h"
|
||||
#include "../common/exectool.h"
|
||||
#include "../common/exechelp.h"
|
||||
#include "../common/sysutils.h"
|
||||
#include "../common/ccparray.h"
|
||||
|
||||
|
||||
|
@ -453,53 +455,43 @@ gpg_error_t
|
|||
gpgtar_list (const char *filename, int decrypt)
|
||||
{
|
||||
gpg_error_t err;
|
||||
estream_t stream;
|
||||
estream_t cipher_stream = NULL;
|
||||
estream_t stream = NULL;
|
||||
tar_header_t header = NULL;
|
||||
strlist_t extheader = NULL;
|
||||
struct tarinfo_s tarinfo_buffer;
|
||||
tarinfo_t tarinfo = &tarinfo_buffer;
|
||||
pid_t pid = (pid_t)(-1);
|
||||
|
||||
memset (&tarinfo_buffer, 0, sizeof tarinfo_buffer);
|
||||
|
||||
if (filename)
|
||||
{
|
||||
if (!strcmp (filename, "-"))
|
||||
stream = es_stdin;
|
||||
else
|
||||
stream = es_fopen (filename, "rb");
|
||||
if (!stream)
|
||||
{
|
||||
err = gpg_error_from_syserror ();
|
||||
log_error ("error opening '%s': %s\n", filename, gpg_strerror (err));
|
||||
return err;
|
||||
}
|
||||
}
|
||||
else
|
||||
stream = es_stdin;
|
||||
|
||||
if (stream == es_stdin)
|
||||
es_set_binary (es_stdin);
|
||||
|
||||
if (decrypt)
|
||||
{
|
||||
strlist_t arg;
|
||||
ccparray_t ccp;
|
||||
const char **argv;
|
||||
|
||||
cipher_stream = stream;
|
||||
stream = es_fopenmem (0, "rwb");
|
||||
if (! stream)
|
||||
{
|
||||
err = gpg_error_from_syserror ();
|
||||
goto leave;
|
||||
}
|
||||
|
||||
ccparray_init (&ccp, 0);
|
||||
if (opt.batch)
|
||||
ccparray_put (&ccp, "--batch");
|
||||
if (opt.require_compliance)
|
||||
ccparray_put (&ccp, "--require-compliance");
|
||||
if (opt.status_fd != -1)
|
||||
{
|
||||
char tmpbuf[40];
|
||||
|
||||
snprintf (tmpbuf, sizeof tmpbuf, "--status-fd=%d", opt.status_fd);
|
||||
ccparray_put (&ccp, tmpbuf);
|
||||
}
|
||||
ccparray_put (&ccp, "--output");
|
||||
ccparray_put (&ccp, "-");
|
||||
ccparray_put (&ccp, "--decrypt");
|
||||
for (arg = opt.gpg_arguments; arg; arg = arg->next)
|
||||
ccparray_put (&ccp, arg->d);
|
||||
if (filename)
|
||||
{
|
||||
ccparray_put (&ccp, "--");
|
||||
ccparray_put (&ccp, filename);
|
||||
}
|
||||
|
||||
ccparray_put (&ccp, NULL);
|
||||
argv = ccparray_get (&ccp, NULL);
|
||||
|
@ -509,15 +501,34 @@ gpgtar_list (const char *filename, int decrypt)
|
|||
goto leave;
|
||||
}
|
||||
|
||||
err = gnupg_exec_tool_stream (opt.gpg_program, argv,
|
||||
cipher_stream, NULL, stream, NULL, NULL);
|
||||
err = gnupg_spawn_process (opt.gpg_program, argv, NULL, NULL,
|
||||
((filename? 0 : GNUPG_SPAWN_KEEP_STDIN)
|
||||
| GNUPG_SPAWN_KEEP_STDERR),
|
||||
NULL, &stream, NULL, &pid);
|
||||
xfree (argv);
|
||||
if (err)
|
||||
goto leave;
|
||||
|
||||
err = es_fseek (stream, 0, SEEK_SET);
|
||||
if (err)
|
||||
goto leave;
|
||||
es_set_binary (stream);
|
||||
}
|
||||
else if (filename) /* No decryption requested. */
|
||||
{
|
||||
if (!strcmp (filename, "-"))
|
||||
stream = es_stdin;
|
||||
else
|
||||
stream = es_fopen (filename, "rb,sysopen");
|
||||
if (!stream)
|
||||
{
|
||||
err = gpg_error_from_syserror ();
|
||||
log_error ("error opening '%s': %s\n", filename, gpg_strerror (err));
|
||||
goto leave;
|
||||
}
|
||||
if (stream == es_stdin)
|
||||
es_set_binary (es_stdin);
|
||||
}
|
||||
else
|
||||
{
|
||||
stream = es_stdin;
|
||||
es_set_binary (es_stdin);
|
||||
}
|
||||
|
||||
for (;;)
|
||||
|
@ -536,17 +547,34 @@ gpgtar_list (const char *filename, int decrypt)
|
|||
header = NULL;
|
||||
}
|
||||
|
||||
if (pid != (pid_t)(-1))
|
||||
{
|
||||
int exitcode;
|
||||
|
||||
err = es_fclose (stream);
|
||||
stream = NULL;
|
||||
if (err)
|
||||
log_error ("error closing pipe: %s\n", gpg_strerror (err));
|
||||
else
|
||||
{
|
||||
err = gnupg_wait_process (opt.gpg_program, pid, 1, &exitcode);
|
||||
if (err)
|
||||
log_error ("running %s failed (exitcode=%d): %s",
|
||||
opt.gpg_program, exitcode, gpg_strerror (err));
|
||||
gnupg_release_process (pid);
|
||||
pid = (pid_t)(-1);
|
||||
}
|
||||
}
|
||||
|
||||
leave:
|
||||
free_strlist (extheader);
|
||||
xfree (header);
|
||||
if (stream != es_stdin)
|
||||
es_fclose (stream);
|
||||
if (stream != cipher_stream)
|
||||
es_fclose (cipher_stream);
|
||||
return err;
|
||||
}
|
||||
|
||||
|
||||
gpg_error_t
|
||||
gpgtar_read_header (estream_t stream, tarinfo_t info,
|
||||
tar_header_t *r_header, strlist_t *r_extheader)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue