aboutsummaryrefslogtreecommitdiffstats
path: root/common/call-gpg.c
diff options
context:
space:
mode:
authorJustus Winter <[email protected]>2015-11-26 14:01:40 +0000
committerJustus Winter <[email protected]>2015-11-26 14:01:40 +0000
commit1a045b1324efabe7423a8d00245f01718ed72556 (patch)
treedff462aee1851881a41b27ee679dbb42f19082ce /common/call-gpg.c
parenttools/gpgtar: Handle '--tar-args' for compatibility with gpg-zip. (diff)
downloadgnupg-1a045b1324efabe7423a8d00245f01718ed72556.tar.gz
gnupg-1a045b1324efabe7423a8d00245f01718ed72556.zip
common: Make the GPG arguments configurable in call-gpg.
* common/call-gpg.c (start_gpg): Add parameter 'gpg_arguments'. (_gpg_encrypt, gpg_encrypt_blob, gpg_encrypt_stream): Likewise. (_gpg_decrypt, gpg_decrypt_blob, gpg_decrypt_stream): Likewise. * common/call-gpg.h: Adapt prototypes. * g13/create.c (encrypt_keyblob): Adapt callsite. * g13/g13-common.h (opt): Add field 'gpg_arguments'. * g13/g13.c (main): Construct default arguments. * g13/mount.c (decrypt_keyblob): Adapt callsite. * tools/gpgtar-create.c (gpgtar_create): Likewise. * tools/gpgtar-extract.c (gpgtar_extract): Likewise. * tools/gpgtar-list.c (gpgtar_list): Likewise. Signed-off-by: Justus Winter <[email protected]>
Diffstat (limited to 'common/call-gpg.c')
-rw-r--r--common/call-gpg.c55
1 files changed, 37 insertions, 18 deletions
diff --git a/common/call-gpg.c b/common/call-gpg.c
index 8258b8378..4a32c889f 100644
--- a/common/call-gpg.c
+++ b/common/call-gpg.c
@@ -33,19 +33,20 @@
#include "i18n.h"
#include "logging.h"
#include "membuf.h"
+#include "strlist.h"
#include "util.h"
/* Fire up a new GPG. Handle the server's initial greeting. Returns
0 on success and stores the assuan context at R_CTX. */
static gpg_error_t
-start_gpg (ctrl_t ctrl, const char *gpg_program,
+start_gpg (ctrl_t ctrl, const char *gpg_program, strlist_t gpg_arguments,
int input_fd, int output_fd, assuan_context_t *r_ctx)
{
gpg_error_t err;
assuan_context_t ctx = NULL;
const char *pgmname;
- const char *argv[10];
+ const char **argv;
int no_close_list[5];
int i;
char line[ASSUAN_LINELENGTH];
@@ -78,13 +79,17 @@ start_gpg (ctrl_t ctrl, const char *gpg_program,
return err;
}
+ argv = xtrycalloc (strlist_length (gpg_arguments) + 3, sizeof *argv);
+ if (argv == NULL)
+ {
+ err = gpg_error_from_syserror ();
+ return err;
+ }
i = 0;
argv[i++] = pgmname;
argv[i++] = "--server";
- argv[i++] = "-z";
- argv[i++] = "0";
- argv[i++] = "--trust-model";
- argv[i++] = "always";
+ for (; gpg_arguments; gpg_arguments = gpg_arguments->next)
+ argv[i++] = gpg_arguments->d;
argv[i++] = NULL;
i = 0;
@@ -386,7 +391,9 @@ start_reader (int fd, membuf_t *mb, estream_t stream,
*/
static gpg_error_t
-_gpg_encrypt (ctrl_t ctrl, const char *gpg_program,
+_gpg_encrypt (ctrl_t ctrl,
+ const char *gpg_program,
+ strlist_t gpg_arguments,
const void *plain, size_t plainlen,
estream_t plain_stream,
strlist_t keys,
@@ -420,7 +427,8 @@ _gpg_encrypt (ctrl_t ctrl, const char *gpg_program,
}
/* Start GPG and send the INPUT and OUTPUT commands. */
- err = start_gpg (ctrl, gpg_program, outbound_fds[0], inbound_fds[1], &ctx);
+ err = start_gpg (ctrl, gpg_program, gpg_arguments,
+ outbound_fds[0], inbound_fds[1], &ctx);
if (err)
goto leave;
close (outbound_fds[0]); outbound_fds[0] = -1;
@@ -514,7 +522,9 @@ _gpg_encrypt (ctrl_t ctrl, const char *gpg_program,
}
gpg_error_t
-gpg_encrypt_blob (ctrl_t ctrl, const char *gpg_program,
+gpg_encrypt_blob (ctrl_t ctrl,
+ const char *gpg_program,
+ strlist_t gpg_arguments,
const void *plain, size_t plainlen,
strlist_t keys,
void **r_ciph, size_t *r_ciphlen)
@@ -528,7 +538,7 @@ gpg_encrypt_blob (ctrl_t ctrl, const char *gpg_program,
/* Init the memory buffer to receive the encrypted stuff. */
init_membuf (&reader_mb, 4096);
- err = _gpg_encrypt (ctrl, gpg_program,
+ err = _gpg_encrypt (ctrl, gpg_program, gpg_arguments,
plain, plainlen, NULL,
keys,
&reader_mb, NULL);
@@ -550,12 +560,14 @@ gpg_encrypt_blob (ctrl_t ctrl, const char *gpg_program,
}
gpg_error_t
-gpg_encrypt_stream (ctrl_t ctrl, const char *gpg_program,
+gpg_encrypt_stream (ctrl_t ctrl,
+ const char *gpg_program,
+ strlist_t gpg_arguments,
estream_t plain_stream,
strlist_t keys,
estream_t cipher_stream)
{
- return _gpg_encrypt (ctrl, gpg_program,
+ return _gpg_encrypt (ctrl, gpg_program, gpg_arguments,
NULL, 0, plain_stream,
keys,
NULL, cipher_stream);
@@ -566,7 +578,9 @@ gpg_encrypt_stream (ctrl_t ctrl, const char *gpg_program,
*/
static gpg_error_t
-_gpg_decrypt (ctrl_t ctrl, const char *gpg_program,
+_gpg_decrypt (ctrl_t ctrl,
+ const char *gpg_program,
+ strlist_t gpg_arguments,
const void *ciph, size_t ciphlen,
estream_t cipher_stream,
membuf_t *reader_mb,
@@ -597,7 +611,8 @@ _gpg_decrypt (ctrl_t ctrl, const char *gpg_program,
}
/* Start GPG and send the INPUT and OUTPUT commands. */
- err = start_gpg (ctrl, gpg_program, outbound_fds[0], inbound_fds[1], &ctx);
+ err = start_gpg (ctrl, gpg_program, gpg_arguments,
+ outbound_fds[0], inbound_fds[1], &ctx);
if (err)
goto leave;
close (outbound_fds[0]); outbound_fds[0] = -1;
@@ -677,7 +692,9 @@ _gpg_decrypt (ctrl_t ctrl, const char *gpg_program,
}
gpg_error_t
-gpg_decrypt_blob (ctrl_t ctrl, const char *gpg_program,
+gpg_decrypt_blob (ctrl_t ctrl,
+ const char *gpg_program,
+ strlist_t gpg_arguments,
const void *ciph, size_t ciphlen,
void **r_plain, size_t *r_plainlen)
{
@@ -690,7 +707,7 @@ gpg_decrypt_blob (ctrl_t ctrl, const char *gpg_program,
/* Init the memory buffer to receive the encrypted stuff. */
init_membuf_secure (&reader_mb, 1024);
- err = _gpg_decrypt (ctrl, gpg_program,
+ err = _gpg_decrypt (ctrl, gpg_program, gpg_arguments,
ciph, ciphlen, NULL,
&reader_mb, NULL);
@@ -711,11 +728,13 @@ gpg_decrypt_blob (ctrl_t ctrl, const char *gpg_program,
}
gpg_error_t
-gpg_decrypt_stream (ctrl_t ctrl, const char *gpg_program,
+gpg_decrypt_stream (ctrl_t ctrl,
+ const char *gpg_program,
+ strlist_t gpg_arguments,
estream_t cipher_stream,
estream_t plain_stream)
{
- return _gpg_decrypt (ctrl, gpg_program,
+ return _gpg_decrypt (ctrl, gpg_program, gpg_arguments,
NULL, 0, cipher_stream,
NULL, plain_stream);
}