From: Tomi Ollila Date: Fri, 11 Dec 2015 22:02:33 +0000 (+0200) Subject: Re: [PATCH 7/9] add a gpg_path value for notmuch_database_t X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=f8b48472005a1c0235911727689b4eebc94a2e51;p=notmuch-archives.git Re: [PATCH 7/9] add a gpg_path value for notmuch_database_t --- diff --git a/03/59d7b6fde3b83d85394eefaba17a55838c41aa b/03/59d7b6fde3b83d85394eefaba17a55838c41aa new file mode 100644 index 000000000..2d6e47d3f --- /dev/null +++ b/03/59d7b6fde3b83d85394eefaba17a55838c41aa @@ -0,0 +1,147 @@ +Return-Path: +X-Original-To: notmuch@notmuchmail.org +Delivered-To: notmuch@notmuchmail.org +Received: from localhost (localhost [127.0.0.1]) + by arlo.cworth.org (Postfix) with ESMTP id 4CD1E6DE0A9A + for ; Fri, 11 Dec 2015 14:02:24 -0800 (PST) +X-Virus-Scanned: Debian amavisd-new at cworth.org +X-Spam-Flag: NO +X-Spam-Score: 0.699 +X-Spam-Level: +X-Spam-Status: No, score=0.699 tagged_above=-999 required=5 tests=[AWL=0.047, + SPF_NEUTRAL=0.652] autolearn=disabled +Received: from arlo.cworth.org ([127.0.0.1]) + by localhost (arlo.cworth.org [127.0.0.1]) (amavisd-new, port 10024) + with ESMTP id lVfFyy-93Ylm for ; + Fri, 11 Dec 2015 14:02:22 -0800 (PST) +Received: from guru.guru-group.fi (guru.guru-group.fi [46.183.73.34]) + by arlo.cworth.org (Postfix) with ESMTP id 85A476DE005F + for ; Fri, 11 Dec 2015 14:02:22 -0800 (PST) +Received: from guru.guru-group.fi (localhost [IPv6:::1]) + by guru.guru-group.fi (Postfix) with ESMTP id 234BB100218; + Sat, 12 Dec 2015 00:02:33 +0200 (EET) +From: Tomi Ollila +To: Daniel Kahn Gillmor , + Notmuch Mail +Subject: Re: [PATCH 7/9] add a gpg_path value for notmuch_database_t +In-Reply-To: <1449718786-28000-8-git-send-email-dkg@fifthhorseman.net> +References: <1449718786-28000-1-git-send-email-dkg@fifthhorseman.net> + <1449718786-28000-8-git-send-email-dkg@fifthhorseman.net> +User-Agent: Notmuch/0.21+32~g73439f8 (http://notmuchmail.org) Emacs/24.3.1 + (x86_64-unknown-linux-gnu) +X-Face: HhBM'cA~ +MIME-Version: 1.0 +Content-Type: text/plain +X-BeenThere: notmuch@notmuchmail.org +X-Mailman-Version: 2.1.20 +Precedence: list +List-Id: "Use and development of the notmuch mail system." + +List-Unsubscribe: , + +List-Archive: +List-Post: +List-Help: +List-Subscribe: , + +X-List-Received-Date: Fri, 11 Dec 2015 22:02:24 -0000 + +On Thu, Dec 10 2015, Daniel Kahn Gillmor wrote: + +> Exposing this to the user of the library lets the user point to +> arbitrary gpg executables when trying to decrypt. +> --- +> lib/database-private.h | 3 ++ +> lib/database.cc | 93 +++++++++++++++++++++++++++++++++++++++++++------- +> lib/notmuch.h | 31 +++++++++++++++++ +> 3 files changed, 115 insertions(+), 12 deletions(-) +> +...... + +> + +> +static notmuch_bool_t +> +_find_in_path(const char* path) +> +{ +> + char *c = NULL, *save = NULL, *tok; +> + size_t n; +> + int dfd = -1; +> + notmuch_bool_t ret = FALSE; +> + +> + n = confstr(_CS_PATH, NULL, 0); +> + c = (char*)talloc_size(NULL, n); +> + if (!c) +> + return FALSE; +> + confstr(_CS_PATH, c, n); +> + +> + tok = strtok_r(c, ":", &save); +> + while (tok) { +> + dfd = open(tok, O_DIRECTORY | O_RDONLY); +> + if (dfd != -1) { +> + if (!faccessat(dfd, path, X_OK, 0)) { +> + ret = TRUE; +> + goto done; +> + } +> + close(dfd); +> + } +> + tok = strtok_r(NULL, ":", &save); +> + } + +The above code finds gpg/gpg2 (when called w/ these args) from +_CS_PATH (seems to be /bin:/usr/bin by default in linux (tried to +look how this set in *BSD -- initially it looks like /usr/local/bin +not included but... maybe we let them to complain if this is the case +... :/) +... anyway, the full found path is not set anywhere -- how is it found +when used (exec*p() using $PATH? :O) + +> +done: +> + if (dfd != -1) +> + close(dfd); +> + if (c) +> + talloc_free(c); +> + return ret; +> +} +> + +> +notmuch_status_t +> +notmuch_database_set_gpg_path (notmuch_database_t *notmuch, const char* path) +> +{ +> + /* return success if this matches what is already configured */ +> + if ((!path && !notmuch->gpg_path) || +> + (path && notmuch->gpg_path && 0 == strcmp(path, notmuch->gpg_path))) +> + return NOTMUCH_STATUS_SUCCESS; +> + +> + if (!path && !_find_in_path(path)) +> + return NOTMUCH_STATUS_FILE_ERROR; +> + +> + /* clear any existing gpg_crypto_ctx, since things are changing */ +> + if (notmuch->gpg_crypto_ctx) { +> + g_object_unref (notmuch->gpg_crypto_ctx); +> + notmuch->gpg_crypto_ctx = NULL; +> + } +> + +> + if (notmuch->gpg_path) { +> + talloc_free(notmuch->gpg_path); +> + notmuch->gpg_path = NULL; +> + } +> + +> + if (path) +> + notmuch->gpg_path = talloc_strdup (notmuch, path); +> + +> + return NOTMUCH_STATUS_SUCCESS; +> +} +> + +> +const char* +> +notmuch_database_get_gpg_path (const notmuch_database_t *notmuch) +> +{ +> + if (notmuch->gpg_path) +> + return notmuch->gpg_path; +> + +> +#define try_gpg_path(z) if (_find_in_path(z)) return z +> + try_gpg_path("gpg2"); +> + try_gpg_path("gpg"); +> + return NULL; +> +}