1 Return-Path: <dkg@fifthhorseman.net>
\r
2 X-Original-To: notmuch@notmuchmail.org
\r
3 Delivered-To: notmuch@notmuchmail.org
\r
4 Received: from localhost (localhost [127.0.0.1])
\r
5 by arlo.cworth.org (Postfix) with ESMTP id 800D16DE1781
\r
6 for <notmuch@notmuchmail.org>; Sun, 31 Jan 2016 12:40:12 -0800 (PST)
\r
7 X-Virus-Scanned: Debian amavisd-new at cworth.org
\r
11 X-Spam-Status: No, score=0 tagged_above=-999 required=5 tests=[none]
\r
13 Received: from arlo.cworth.org ([127.0.0.1])
\r
14 by localhost (arlo.cworth.org [127.0.0.1]) (amavisd-new, port 10024)
\r
15 with ESMTP id qgCMc9u7yGpG for <notmuch@notmuchmail.org>;
\r
16 Sun, 31 Jan 2016 12:40:10 -0800 (PST)
\r
17 Received: from che.mayfirst.org (che.mayfirst.org [209.234.253.108])
\r
18 by arlo.cworth.org (Postfix) with ESMTP id E20866DE0022
\r
19 for <notmuch@notmuchmail.org>; Sun, 31 Jan 2016 12:40:08 -0800 (PST)
\r
20 Received: from fifthhorseman.net (ip-64-134-185-108.public.wayport.net
\r
22 by che.mayfirst.org (Postfix) with ESMTPSA id 77452F991
\r
23 for <notmuch@notmuchmail.org>; Sun, 31 Jan 2016 15:40:05 -0500 (EST)
\r
24 Received: by fifthhorseman.net (Postfix, from userid 1000)
\r
25 id 38F1720544; Sun, 31 Jan 2016 15:40:06 -0500 (EST)
\r
26 From: Daniel Kahn Gillmor <dkg@fifthhorseman.net>
\r
27 To: Notmuch Mail <notmuch@notmuchmail.org>
\r
28 Subject: [PATCH v3 04/16] Provide _notmuch_crypto_{set,get}_gpg_path
\r
29 Date: Sun, 31 Jan 2016 15:39:49 -0500
\r
30 Message-Id: <1454272801-23623-5-git-send-email-dkg@fifthhorseman.net>
\r
31 X-Mailer: git-send-email 2.7.0.rc3
\r
32 In-Reply-To: <1454272801-23623-1-git-send-email-dkg@fifthhorseman.net>
\r
33 References: <1454272801-23623-1-git-send-email-dkg@fifthhorseman.net>
\r
34 X-BeenThere: notmuch@notmuchmail.org
\r
35 X-Mailman-Version: 2.1.20
\r
37 List-Id: "Use and development of the notmuch mail system."
\r
38 <notmuch.notmuchmail.org>
\r
39 List-Unsubscribe: <https://notmuchmail.org/mailman/options/notmuch>,
\r
40 <mailto:notmuch-request@notmuchmail.org?subject=unsubscribe>
\r
41 List-Archive: <http://notmuchmail.org/pipermail/notmuch/>
\r
42 List-Post: <mailto:notmuch@notmuchmail.org>
\r
43 List-Help: <mailto:notmuch-request@notmuchmail.org?subject=help>
\r
44 List-Subscribe: <https://notmuchmail.org/mailman/listinfo/notmuch>,
\r
45 <mailto:notmuch-request@notmuchmail.org?subject=subscribe>
\r
46 X-List-Received-Date: Sun, 31 Jan 2016 20:40:12 -0000
\r
48 Use functions to access the gpg_path for a _notmuch_crypto_t object.
\r
49 This lets us return sensible defaults based on the state of the user's
\r
52 notmuch-reply.c | 13 ++++++++++---
\r
53 notmuch-show.c | 12 ++++++++++--
\r
54 util/crypto.c | 48 +++++++++++++++++++++++++++++++++++++++++++++++-
\r
55 util/crypto.h | 8 +++++++-
\r
56 4 files changed, 74 insertions(+), 7 deletions(-)
\r
58 diff --git a/notmuch-reply.c b/notmuch-reply.c
\r
59 index eccfb32..793e6f9 100644
\r
60 --- a/notmuch-reply.c
\r
61 +++ b/notmuch-reply.c
\r
62 @@ -790,13 +790,15 @@ notmuch_reply_command (notmuch_config_t *config, int argc, char *argv[])
\r
70 int format = FORMAT_DEFAULT;
\r
71 int reply_all = TRUE;
\r
72 struct sprinter *sp = NULL;
\r
74 + notmuch_status_t status;
\r
75 + const char *gpg_path = NULL;
\r
77 notmuch_opt_desc_t options[] = {
\r
78 { NOTMUCH_OPT_KEYWORD, &format, "format", 'f',
\r
79 (notmuch_keyword_t []){ { "default", FORMAT_DEFAULT },
\r
80 @@ -845,7 +847,12 @@ notmuch_reply_command (notmuch_config_t *config, int argc, char *argv[])
\r
81 return EXIT_FAILURE;
\r
84 - params.crypto.gpgpath = notmuch_config_get_crypto_gpg_path (config);
\r
85 + gpg_path = notmuch_config_get_crypto_gpg_path (config);
\r
86 + status = _notmuch_crypto_set_gpg_path (&(params.crypto), gpg_path);
\r
87 + if (status != NOTMUCH_STATUS_SUCCESS) {
\r
88 + fprintf (stderr, "Error: could not set gpg_path to '%s'.\n", gpg_path);
\r
89 + return EXIT_FAILURE;
\r
92 if (notmuch_database_open (notmuch_config_get_database_path (config),
\r
93 NOTMUCH_DATABASE_MODE_READ_ONLY, ¬much))
\r
94 diff --git a/notmuch-show.c b/notmuch-show.c
\r
95 index 3c91ece..096fd49 100644
\r
96 --- a/notmuch-show.c
\r
97 +++ b/notmuch-show.c
\r
98 @@ -1006,13 +1006,15 @@ notmuch_show_command (notmuch_config_t *config, int argc, char *argv[])
\r
105 .include_html = FALSE
\r
107 int format_sel = NOTMUCH_FORMAT_NOT_SPECIFIED;
\r
108 int exclude = EXCLUDE_TRUE;
\r
109 int entire_thread = ENTIRE_THREAD_DEFAULT;
\r
110 + notmuch_status_t status;
\r
111 + const char *gpg_path = NULL;
\r
113 notmuch_opt_desc_t options[] = {
\r
114 { NOTMUCH_OPT_KEYWORD, &format_sel, "format", 'f',
\r
115 @@ -1130,7 +1132,13 @@ notmuch_show_command (notmuch_config_t *config, int argc, char *argv[])
\r
116 return EXIT_FAILURE;
\r
119 - params.crypto.gpgpath = notmuch_config_get_crypto_gpg_path (config);
\r
121 + gpg_path = notmuch_config_get_crypto_gpg_path (config);
\r
122 + status = _notmuch_crypto_set_gpg_path (&(params.crypto), gpg_path);
\r
123 + if (status != NOTMUCH_STATUS_SUCCESS) {
\r
124 + fprintf (stderr, "Error: could not set gpg_path to '%s'.\n", gpg_path);
\r
125 + return EXIT_FAILURE;
\r
128 if (notmuch_database_open (notmuch_config_get_database_path (config),
\r
129 NOTMUCH_DATABASE_MODE_READ_ONLY, ¬much))
\r
130 diff --git a/util/crypto.c b/util/crypto.c
\r
131 index 151a352..c89ce8a 100644
\r
132 --- a/util/crypto.c
\r
133 +++ b/util/crypto.c
\r
136 #include "notmuch.h"
\r
137 #include "crypto.h"
\r
138 +#include "search-path.h"
\r
139 #include <string.h>
\r
140 +#include <talloc.h>
\r
142 #define ARRAY_SIZE(arr) (sizeof (arr) / sizeof (arr[0]))
\r
144 @@ -38,7 +40,7 @@ get_gpg_context (_notmuch_crypto_t *crypto, GMimeCryptoContext **ctx)
\r
147 /* TODO: GMimePasswordRequestFunc */
\r
148 - crypto->gpgctx = g_mime_gpg_context_new (NULL, crypto->gpgpath ? crypto->gpgpath : "gpg");
\r
149 + crypto->gpgctx = g_mime_gpg_context_new (NULL, _notmuch_crypto_get_gpg_path(crypto));
\r
150 if (! crypto->gpgctx) {
\r
151 return NOTMUCH_STATUS_FAILED_CRYPTO_CONTEXT_CREATION;
\r
153 @@ -120,6 +122,47 @@ _notmuch_crypto_get_gmime_ctx_for_protocol (_notmuch_crypto_t *crypto,
\r
154 return NOTMUCH_STATUS_UNKNOWN_CRYPTO_PROTOCOL;
\r
158 +_notmuch_crypto_get_gpg_path (const _notmuch_crypto_t *crypto)
\r
160 + if (crypto->gpg_path)
\r
161 + return crypto->gpg_path;
\r
163 +#define try_gpg_path(z) if (test_for_executable(z)) return z
\r
164 + try_gpg_path("gpg2");
\r
165 + try_gpg_path("gpg");
\r
166 +#undef try_gpg_path
\r
171 +_notmuch_crypto_set_gpg_path (_notmuch_crypto_t *crypto, const char* gpg_path)
\r
173 + /* return success if this matches what is already configured */
\r
174 + if ((!gpg_path && !crypto->gpg_path) ||
\r
175 + (gpg_path && crypto->gpg_path && 0 == strcmp(gpg_path, crypto->gpg_path)))
\r
176 + return NOTMUCH_STATUS_SUCCESS;
\r
178 + if (!gpg_path && !test_for_executable(gpg_path))
\r
179 + return NOTMUCH_STATUS_FILE_ERROR;
\r
181 + /* clear any existing gpgctx, since things are changing */
\r
182 + if (crypto->gpgctx) {
\r
183 + g_object_unref (crypto->gpgctx);
\r
184 + crypto->gpgctx = NULL;
\r
187 + if (crypto->gpg_path) {
\r
188 + talloc_free(crypto->gpg_path);
\r
189 + crypto->gpg_path = NULL;
\r
193 + crypto->gpg_path = talloc_strdup (NULL, gpg_path);
\r
195 + return NOTMUCH_STATUS_SUCCESS;
\r
199 _notmuch_crypto_cleanup (_notmuch_crypto_t *crypto)
\r
201 @@ -132,4 +175,7 @@ _notmuch_crypto_cleanup (_notmuch_crypto_t *crypto)
\r
202 g_object_unref (crypto->pkcs7ctx);
\r
203 crypto->pkcs7ctx = NULL;
\r
206 + talloc_free (crypto->gpg_path);
\r
207 + crypto->gpg_path = NULL;
\r
209 diff --git a/util/crypto.h b/util/crypto.h
\r
210 index 7cb0a39..70fc8ef 100644
\r
211 --- a/util/crypto.h
\r
212 +++ b/util/crypto.h
\r
213 @@ -11,7 +11,7 @@ typedef struct _notmuch_crypto {
\r
214 GMimeCryptoContext* pkcs7ctx;
\r
215 notmuch_bool_t verify;
\r
216 notmuch_bool_t decrypt;
\r
217 - const char *gpgpath;
\r
219 } _notmuch_crypto_t;
\r
222 @@ -20,6 +20,12 @@ _notmuch_crypto_get_gmime_ctx_for_protocol (_notmuch_crypto_t *crypto,
\r
223 const char *protocol,
\r
224 GMimeCryptoContext **ctx);
\r
227 +_notmuch_crypto_set_gpg_path (_notmuch_crypto_t *crypto, const char *gpg_path);
\r
230 +_notmuch_crypto_get_gpg_path (const _notmuch_crypto_t *crypto);
\r
233 _notmuch_crypto_cleanup (_notmuch_crypto_t *crypto);
\r