summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJustus Winter <justus@g10code.com>2015-11-24 13:40:56 +0100
committerJustus Winter <justus@g10code.com>2015-11-25 12:19:50 +0100
commitba1a5cc17d43d9cba32447876f06a8ab8f97e5ae (patch)
treec81fe95c5780376ed1a5ce59eb659915f408eee1
parentgpg: When comparing keyids, use the keyid, not the fingerprint's suffix. (diff)
downloadgnupg2-ba1a5cc17d43d9cba32447876f06a8ab8f97e5ae.tar.xz
gnupg2-ba1a5cc17d43d9cba32447876f06a8ab8f97e5ae.zip
g13: Move 'call-gpg.c' to common.
* common/Makefile.am (common_sources): Add files. * g13/call-gpg.c: Move to 'common' and adapt slightly. Add a parameter to let callees override the gpg program to execute. * g13/call-gpg.h: Likewise. * g13/Makefile.am (g13_SOURCES): Drop files. * g13/create.c (encrypt_keyblob): Hand in the gpg program to execute. * g13/mount.c (decrypt_keyblob): Likewise. Signed-off-by: Justus Winter <justus@g10code.com>
-rw-r--r--common/Makefile.am3
-rw-r--r--common/call-gpg.c (renamed from g13/call-gpg.c)55
-rw-r--r--common/call-gpg.h (renamed from g13/call-gpg.h)9
-rw-r--r--g13/Makefile.am1
-rw-r--r--g13/create.c4
-rw-r--r--g13/mount.c4
6 files changed, 39 insertions, 37 deletions
diff --git a/common/Makefile.am b/common/Makefile.am
index 678e1a269..c02c60e04 100644
--- a/common/Makefile.am
+++ b/common/Makefile.am
@@ -86,7 +86,8 @@ common_sources = \
agent-opt.c \
helpfile.c \
mkdir_p.c mkdir_p.h \
- strlist.c strlist.h
+ strlist.c strlist.h \
+ call-gpg.c call-gpg.h
if HAVE_W32_SYSTEM
common_sources += w32-reg.c w32-afunix.c w32-afunix.h
diff --git a/g13/call-gpg.c b/common/call-gpg.c
index 0bd935c1f..bcad1d61a 100644
--- a/g13/call-gpg.c
+++ b/common/call-gpg.c
@@ -18,27 +18,29 @@
*/
#include <config.h>
-#include <stdio.h>
+
+#include <assert.h>
+#include <assuan.h>
+#include <errno.h>
+#include <npth.h>
#include <stdlib.h>
+#include <stdio.h>
#include <string.h>
-#include <errno.h>
#include <time.h>
-#include <assert.h>
-#include <npth.h>
-#include "g13.h"
-#include <assuan.h>
-#include "i18n.h"
#include "call-gpg.h"
-#include "utils.h"
-#include "../common/exechelp.h"
-
+#include "exechelp.h"
+#include "i18n.h"
+#include "logging.h"
+#include "membuf.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, int input_fd, int output_fd, assuan_context_t *r_ctx)
+start_gpg (ctrl_t ctrl, const char *gpg_program,
+ int input_fd, int output_fd, assuan_context_t *r_ctx)
{
gpg_error_t err;
assuan_context_t ctx = NULL;
@@ -60,15 +62,12 @@ start_gpg (ctrl_t ctrl, int input_fd, int output_fd, assuan_context_t *r_ctx)
}
/* The first time we are used, intialize the gpg_program variable. */
- if ( !opt.gpg_program || !*opt.gpg_program )
- opt.gpg_program = gnupg_module_name (GNUPG_MODULE_NAME_GPG);
-
- if (opt.verbose)
- log_info (_("no running gpg - starting '%s'\n"), opt.gpg_program);
+ if ( !gpg_program || !*gpg_program )
+ gpg_program = gnupg_module_name (GNUPG_MODULE_NAME_GPG);
/* Compute argv[0]. */
- if ( !(pgmname = strrchr (opt.gpg_program, '/')))
- pgmname = opt.gpg_program;
+ if ( !(pgmname = strrchr (gpg_program, '/')))
+ pgmname = gpg_program;
else
pgmname++;
@@ -82,8 +81,6 @@ start_gpg (ctrl_t ctrl, int input_fd, int output_fd, assuan_context_t *r_ctx)
i = 0;
argv[i++] = pgmname;
argv[i++] = "--server";
- if ((opt.debug & 1024))
- argv[i++] = "--debug=1024";
argv[i++] = "-z";
argv[i++] = "0";
argv[i++] = "--trust-model";
@@ -101,7 +98,7 @@ start_gpg (ctrl_t ctrl, int input_fd, int output_fd, assuan_context_t *r_ctx)
no_close_list[i] = -1;
/* Connect to GPG and perform initial handshaking. */
- err = assuan_pipe_connect (ctx, opt.gpg_program, argv, no_close_list,
+ err = assuan_pipe_connect (ctx, gpg_program, argv, no_close_list,
NULL, NULL, 0);
if (err)
{
@@ -135,9 +132,6 @@ start_gpg (ctrl_t ctrl, int input_fd, int output_fd, assuan_context_t *r_ctx)
}
*r_ctx = ctx;
-
- if (DBG_IPC)
- log_debug ("connection to GPG established\n");
return 0;
}
@@ -328,8 +322,10 @@ start_reader (int fd, membuf_t *mb, npth_t *r_thread, gpg_error_t *err_addr)
*/
gpg_error_t
-gpg_encrypt_blob (ctrl_t ctrl, const void *plain, size_t plainlen,
- strlist_t keys, void **r_ciph, size_t *r_ciphlen)
+gpg_encrypt_blob (ctrl_t ctrl, const char *gpg_program,
+ const void *plain, size_t plainlen,
+ strlist_t keys,
+ void **r_ciph, size_t *r_ciphlen)
{
gpg_error_t err;
assuan_context_t ctx = NULL;
@@ -360,7 +356,7 @@ gpg_encrypt_blob (ctrl_t ctrl, const void *plain, size_t plainlen,
}
/* Start GPG and send the INPUT and OUTPUT commands. */
- err = start_gpg (ctrl, outbound_fds[0], inbound_fds[1], &ctx);
+ err = start_gpg (ctrl, gpg_program, outbound_fds[0], inbound_fds[1], &ctx);
if (err)
goto leave;
close (outbound_fds[0]); outbound_fds[0] = -1;
@@ -471,7 +467,8 @@ gpg_encrypt_blob (ctrl_t ctrl, const void *plain, size_t plainlen,
*/
gpg_error_t
-gpg_decrypt_blob (ctrl_t ctrl, const void *ciph, size_t ciphlen,
+gpg_decrypt_blob (ctrl_t ctrl, const char *gpg_program,
+ const void *ciph, size_t ciphlen,
void **r_plain, size_t *r_plainlen)
{
gpg_error_t err;
@@ -501,7 +498,7 @@ gpg_decrypt_blob (ctrl_t ctrl, const void *ciph, size_t ciphlen,
}
/* Start GPG and send the INPUT and OUTPUT commands. */
- err = start_gpg (ctrl, outbound_fds[0], inbound_fds[1], &ctx);
+ err = start_gpg (ctrl, gpg_program, outbound_fds[0], inbound_fds[1], &ctx);
if (err)
goto leave;
close (outbound_fds[0]); outbound_fds[0] = -1;
diff --git a/g13/call-gpg.h b/common/call-gpg.h
index 339544d50..606473d88 100644
--- a/g13/call-gpg.h
+++ b/common/call-gpg.h
@@ -20,11 +20,16 @@
#ifndef G13_CALL_GPG_H
#define G13_CALL_GPG_H
-gpg_error_t gpg_encrypt_blob (ctrl_t ctrl,
+#include "strlist.h"
+
+typedef struct server_control_s *ctrl_t;
+
+gpg_error_t gpg_encrypt_blob (ctrl_t ctrl, const char *gpg_program,
const void *plain, size_t plainlen,
strlist_t keys,
void **r_ciph, size_t *r_ciphlen);
-gpg_error_t gpg_decrypt_blob (ctrl_t ctrl, const void *ciph, size_t ciphlen,
+gpg_error_t gpg_decrypt_blob (ctrl_t ctrl, const char *gpg_program,
+ const void *ciph, size_t ciphlen,
void **r_plain, size_t *r_plainlen);
diff --git a/g13/Makefile.am b/g13/Makefile.am
index 152cf367e..e17d099c3 100644
--- a/g13/Makefile.am
+++ b/g13/Makefile.am
@@ -37,7 +37,6 @@ g13_SOURCES = \
create.c create.h \
mount.c mount.h \
mountinfo.c mountinfo.h \
- call-gpg.c call-gpg.h \
runner.c runner.h \
backend.c backend.h \
be-encfs.c be-encfs.h \
diff --git a/g13/create.c b/g13/create.c
index 6c09c2e81..c4e94b830 100644
--- a/g13/create.c
+++ b/g13/create.c
@@ -33,7 +33,7 @@
#include "keyblob.h"
#include "backend.h"
#include "utils.h"
-#include "call-gpg.h"
+#include "../common/call-gpg.h"
/* Create a new blob with all the session keys and other meta
information which are to be stored encrypted in the crypto
@@ -111,7 +111,7 @@ encrypt_keyblob (ctrl_t ctrl, void *keyblob, size_t keybloblen,
gpg_error_t err;
/* FIXME: For now we only implement OpenPGP. */
- err = gpg_encrypt_blob (ctrl, keyblob, keybloblen, keys,
+ err = gpg_encrypt_blob (ctrl, opt.gpg_program, keyblob, keybloblen, keys,
r_encblob, r_encbloblen);
return err;
diff --git a/g13/mount.c b/g13/mount.c
index 8d1c0150f..1f7fbcc4c 100644
--- a/g13/mount.c
+++ b/g13/mount.c
@@ -34,7 +34,7 @@
#include "backend.h"
#include "utils.h"
#include "../common/sysutils.h"
-#include "call-gpg.h"
+#include "../common/call-gpg.h"
#include "mountinfo.h"
#include "runner.h"
#include "host2net.h"
@@ -202,7 +202,7 @@ decrypt_keyblob (ctrl_t ctrl, const void *enckeyblob, size_t enckeybloblen,
gpg_error_t err;
/* FIXME: For now we only implement OpenPGP. */
- err = gpg_decrypt_blob (ctrl, enckeyblob, enckeybloblen,
+ err = gpg_decrypt_blob (ctrl, opt.gpg_program, enckeyblob, enckeybloblen,
r_keyblob, r_keybloblen);
return err;