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 similarity index 93% rename from g13/call-gpg.c rename to common/call-gpg.c index 0bd935c1f..bcad1d61a 100644 --- a/g13/call-gpg.c +++ b/common/call-gpg.c @@ -18,27 +18,29 @@ */ #include -#include -#include -#include -#include -#include + #include -#include - -#include "g13.h" #include -#include "i18n.h" -#include "call-gpg.h" -#include "utils.h" -#include "../common/exechelp.h" +#include +#include +#include +#include +#include +#include +#include "call-gpg.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 similarity index 82% rename from g13/call-gpg.h rename to 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;