# HG changeset patch # User Kevin McCarthy # Date 1423248568 28800 # Fri Feb 06 10:49:28 2015 -0800 # Node ID 641480cff53addb92ac1bb0153580d164f1344a8 # Parent 0cbb7cd6fb8d7925654845e429e2270c792dca8d Introduce an oppenc_mode parameter It's added to the parameter lists through the call stack down to the find_keys calls. No functionality is implemented yet. This patch is separated just to keep other patches more readable. diff --git a/crypt-gpgme.c b/crypt-gpgme.c --- a/crypt-gpgme.c +++ b/crypt-gpgme.c @@ -4324,18 +4324,20 @@ return key; BEEP (); } /* not reached */ } /* This routine attempts to find the keyids of the recipients of a - message. It returns NULL if any of the keys can not be found. */ -static char *find_keys (ADDRESS *adrlist, unsigned int app) + message. It returns NULL if any of the keys can not be found. + If oppenc_mode is true, only keys that can be determined without + prompting will be used. */ +static char *find_keys (ADDRESS *adrlist, unsigned int app, int oppenc_mode) { char *keyID, *keylist = NULL, *t; size_t keylist_size = 0; size_t keylist_used = 0; ADDRESS *addr = NULL; ADDRESS *p, *q; crypt_key_t *k_info, *key; const char *fqdn = mutt_fqdn (1); @@ -4428,24 +4430,24 @@ keylist_used = mutt_strlen (keylist); crypt_free_key (&key); rfc822_free_address (&addr); } return (keylist); } -char *pgp_gpgme_findkeys (ADDRESS *adrlist) +char *pgp_gpgme_findkeys (ADDRESS *adrlist, int oppenc_mode) { - return find_keys (adrlist, APPLICATION_PGP); + return find_keys (adrlist, APPLICATION_PGP, oppenc_mode); } -char *smime_gpgme_findkeys (ADDRESS *adrlist) +char *smime_gpgme_findkeys (ADDRESS *adrlist, int oppenc_mode) { - return find_keys (adrlist, APPLICATION_SMIME); + return find_keys (adrlist, APPLICATION_SMIME, oppenc_mode); } #ifdef HAVE_GPGME_OP_EXPORT_KEYS BODY *pgp_gpgme_make_key_attachment (char *tempf) { crypt_key_t *key = NULL; gpgme_ctx_t context = NULL; gpgme_key_t export_keys[2]; diff --git a/crypt-gpgme.h b/crypt-gpgme.h --- a/crypt-gpgme.h +++ b/crypt-gpgme.h @@ -19,18 +19,18 @@ #ifndef CRYPT_GPGME_H #define CRYPT_GPGME_H #include "mutt_crypt.h" void pgp_gpgme_init (void); void smime_gpgme_init (void); -char *pgp_gpgme_findkeys (ADDRESS *adrlist); -char *smime_gpgme_findkeys (ADDRESS *adrlist); +char *pgp_gpgme_findkeys (ADDRESS *adrlist, int oppenc_mode); +char *smime_gpgme_findkeys (ADDRESS *adrlist, int oppenc_mode); BODY *pgp_gpgme_encrypt_message (BODY *a, char *keylist, int sign); BODY *smime_gpgme_build_smime_entity (BODY *a, char *keylist); int pgp_gpgme_decrypt_mime (FILE *fpin, FILE **fpout, BODY *b, BODY **cur); int smime_gpgme_decrypt_mime (FILE *fpin, FILE **fpout, BODY *b, BODY **cur); int pgp_gpgme_check_traditional (FILE *fp, BODY *b, int tagged_only); diff --git a/crypt-mod-pgp-classic.c b/crypt-mod-pgp-classic.c --- a/crypt-mod-pgp-classic.c +++ b/crypt-mod-pgp-classic.c @@ -41,19 +41,19 @@ { return pgp_decrypt_mime (a, b, c, d); } static int crypt_mod_pgp_application_handler (BODY *m, STATE *s) { return pgp_application_pgp_handler (m, s); } -static char *crypt_mod_pgp_findkeys (ADDRESS *adrlist) +static char *crypt_mod_pgp_findkeys (ADDRESS *adrlist, int oppenc_mode) { - return pgp_findKeys (adrlist); + return pgp_findKeys (adrlist, oppenc_mode); } static BODY *crypt_mod_pgp_sign_message (BODY *a) { return pgp_sign_message (a); } static int crypt_mod_pgp_verify_one (BODY *sigbdy, STATE *s, const char *tempf) diff --git a/crypt-mod-pgp-gpgme.c b/crypt-mod-pgp-gpgme.c --- a/crypt-mod-pgp-gpgme.c +++ b/crypt-mod-pgp-gpgme.c @@ -65,19 +65,19 @@ return pgp_gpgme_check_traditional (fp, b, tagged_only); } static void crypt_mod_pgp_invoke_import (const char *fname) { pgp_gpgme_invoke_import (fname); } -static char *crypt_mod_pgp_findkeys (ADDRESS *adrlist) +static char *crypt_mod_pgp_findkeys (ADDRESS *adrlist, int oppenc_mode) { - return pgp_gpgme_findkeys (adrlist); + return pgp_gpgme_findkeys (adrlist, oppenc_mode); } static BODY *crypt_mod_pgp_sign_message (BODY *a) { return pgp_gpgme_sign_message (a); } static int crypt_mod_pgp_verify_one (BODY *sigbdy, STATE *s, const char *tempf) diff --git a/crypt-mod-smime-classic.c b/crypt-mod-smime-classic.c --- a/crypt-mod-smime-classic.c +++ b/crypt-mod-smime-classic.c @@ -41,19 +41,19 @@ { return smime_decrypt_mime (a, b, c, d); } static int crypt_mod_smime_application_handler (BODY *m, STATE *s) { return smime_application_smime_handler (m, s); } -static char *crypt_mod_smime_findkeys (ADDRESS *adrlist) +static char *crypt_mod_smime_findkeys (ADDRESS *adrlist, int oppenc_mode) { - return smime_findKeys (adrlist); + return smime_findKeys (adrlist, oppenc_mode); } static BODY *crypt_mod_smime_sign_message (BODY *a) { return smime_sign_message (a); } static int crypt_mod_smime_verify_one (BODY *sigbdy, STATE *s, const char *tempf) diff --git a/crypt-mod-smime-gpgme.c b/crypt-mod-smime-gpgme.c --- a/crypt-mod-smime-gpgme.c +++ b/crypt-mod-smime-gpgme.c @@ -50,19 +50,19 @@ return smime_gpgme_decrypt_mime (a, b, c, d); } static int crypt_mod_smime_application_handler (BODY *m, STATE *s) { return smime_gpgme_application_handler (m, s); } -static char *crypt_mod_smime_findkeys (ADDRESS *adrlist) +static char *crypt_mod_smime_findkeys (ADDRESS *adrlist, int oppenc_mode) { - return smime_gpgme_findkeys (adrlist); + return smime_gpgme_findkeys (adrlist, oppenc_mode); } static BODY *crypt_mod_smime_sign_message (BODY *a) { return smime_gpgme_sign_message (a); } static int crypt_mod_smime_verify_one (BODY *sigbdy, STATE *s, const char *tempf) diff --git a/crypt-mod.h b/crypt-mod.h --- a/crypt-mod.h +++ b/crypt-mod.h @@ -38,17 +38,17 @@ typedef int (*crypt_func_encrypted_handler_t) (BODY *m, STATE *s); typedef void (*crypt_func_pgp_invoke_getkeys_t) (ADDRESS *addr); typedef int (*crypt_func_pgp_check_traditional_t) (FILE *fp, BODY *b, int tagged_only); typedef BODY *(*crypt_func_pgp_traditional_encryptsign_t) (BODY *a, int flags, char *keylist); typedef BODY *(*crypt_func_pgp_make_key_attachment_t) (char *tempf); -typedef char *(*crypt_func_findkeys_t) (ADDRESS *adrlist); +typedef char *(*crypt_func_findkeys_t) (ADDRESS *adrlist, int oppenc_mode); typedef BODY *(*crypt_func_sign_message_t) (BODY *a); typedef BODY *(*crypt_func_pgp_encrypt_message_t) (BODY *a, char *keylist, int sign); typedef void (*crypt_func_pgp_invoke_import_t) (const char *fname); typedef int (*crypt_func_verify_one_t) (BODY *sigbdy, STATE *s, const char *tempf); typedef void (*crypt_func_pgp_extract_keys_from_attachment_list_t) (FILE *fp, int tag, BODY *top); diff --git a/crypt.c b/crypt.c --- a/crypt.c +++ b/crypt.c @@ -732,27 +732,27 @@ *keylist = NULL; if (msg->security & ENCRYPT) { if ((WithCrypto & APPLICATION_PGP) && (msg->security & APPLICATION_PGP)) { - if ((*keylist = crypt_pgp_findkeys (adrlist)) == NULL) + if ((*keylist = crypt_pgp_findkeys (adrlist, 0)) == NULL) { rfc822_free_address (&adrlist); return (-1); } unset_option (OPTPGPCHECKTRUST); } if ((WithCrypto & APPLICATION_SMIME) && (msg->security & APPLICATION_SMIME)) { - if ((*keylist = crypt_smime_findkeys (adrlist)) == NULL) + if ((*keylist = crypt_smime_findkeys (adrlist, 0)) == NULL) { rfc822_free_address (&adrlist); return (-1); } } } rfc822_free_address (&adrlist); diff --git a/cryptglue.c b/cryptglue.c --- a/cryptglue.c +++ b/cryptglue.c @@ -194,21 +194,23 @@ { if (CRYPT_MOD_CALL_CHECK (PGP, pgp_make_key_attachment)) return (CRYPT_MOD_CALL (PGP, pgp_make_key_attachment)) (tempf); return NULL; } /* This routine attempts to find the keyids of the recipients of a - message. It returns NULL if any of the keys can not be found. */ -char *crypt_pgp_findkeys (ADDRESS *adrlist) + message. It returns NULL if any of the keys can not be found. + If oppenc_mode is true, only keys that can be determined without + prompting will be used. */ +char *crypt_pgp_findkeys (ADDRESS *adrlist, int oppenc_mode) { if (CRYPT_MOD_CALL_CHECK (PGP, findkeys)) - return (CRYPT_MOD_CALL (PGP, findkeys)) (adrlist); + return (CRYPT_MOD_CALL (PGP, findkeys)) (adrlist, oppenc_mode); return NULL; } /* Create a new body with a PGP signed message from A. */ BODY *crypt_pgp_sign_message (BODY *a) { if (CRYPT_MOD_CALL_CHECK (PGP, sign_message)) @@ -328,21 +330,23 @@ { if (CRYPT_MOD_CALL_CHECK (SMIME, smime_verify_sender)) return (CRYPT_MOD_CALL (SMIME, smime_verify_sender)) (h); return 1; } /* This routine attempts to find the keyids of the recipients of a - message. It returns NULL if any of the keys can not be found. */ -char *crypt_smime_findkeys (ADDRESS *adrlist) + message. It returns NULL if any of the keys can not be found. + If oppenc_mode is true, only keys that can be determined without + prompting will be used. */ +char *crypt_smime_findkeys (ADDRESS *adrlist, int oppenc_mode) { if (CRYPT_MOD_CALL_CHECK (SMIME, findkeys)) - return (CRYPT_MOD_CALL (SMIME, findkeys)) (adrlist); + return (CRYPT_MOD_CALL (SMIME, findkeys)) (adrlist, oppenc_mode); return NULL; } /* fixme: Needs documentation. */ BODY *crypt_smime_sign_message (BODY *a) { if (CRYPT_MOD_CALL_CHECK (SMIME, sign_message)) diff --git a/mutt_crypt.h b/mutt_crypt.h --- a/mutt_crypt.h +++ b/mutt_crypt.h @@ -191,18 +191,20 @@ /* Release the PGP key KPP (note, that we pass a pointer to it). */ void crypt_pgp_free_key (pgp_key_t *kpp); /* Generate a PGP public key attachment. */ BODY *crypt_pgp_make_key_attachment (char *tempf); /* This routine attempts to find the keyids of the recipients of a - message. It returns NULL if any of the keys can not be found. */ -char *crypt_pgp_findkeys (ADDRESS *adrlist); + message. It returns NULL if any of the keys can not be found. + If oppenc_mode is true, only keys that can be determined without + prompting will be used. */ +char *crypt_pgp_findkeys (ADDRESS *adrlist, int oppenc_mode); /* Create a new body with a PGP signed message from A. */ BODY *crypt_pgp_sign_message (BODY *a); /* Warning: A is no longer freed in this routine, you need to free it later. This is necessary for $fcc_attach. */ BODY *crypt_pgp_encrypt_message (BODY *a, char *keylist, int sign); @@ -240,18 +242,20 @@ /* Check that the sender matches. */ int crypt_smime_verify_sender(HEADER *h); /* Ask for an SMIME key. */ char *crypt_smime_ask_for_key (char *prompt, char *mailbox, short public); /* This routine attempts to find the keyids of the recipients of a - message. It returns NULL if any of the keys can not be found. */ -char *crypt_smime_findkeys (ADDRESS *adrlist); + message. It returns NULL if any of the keys can not be found. + If oppenc_mode is true, only keys that can be determined without + prompting will be used. */ +char *crypt_smime_findkeys (ADDRESS *adrlist, int oppenc_mode); /* fixme: Needs documentation. */ BODY *crypt_smime_sign_message (BODY *a); /* fixme: needs documentation. */ BODY *crypt_smime_build_smime_entity (BODY *a, char *certlist); /* Add a certificate and update index file (externally). */ diff --git a/pgp.c b/pgp.c --- a/pgp.c +++ b/pgp.c @@ -1165,18 +1165,20 @@ if (strchr ("0123456789ABCDEFabcdef", *s++) == NULL) return 0; return 1; } /* This routine attempts to find the keyids of the recipients of a message. * It returns NULL if any of the keys can not be found. + * If oppenc_mode is true, only keys that can be determined without + * prompting will be used. */ -char *pgp_findKeys (ADDRESS *adrlist) +char *pgp_findKeys (ADDRESS *adrlist, int oppenc_mode) { char *keyID, *keylist = NULL; size_t keylist_size = 0; size_t keylist_used = 0; ADDRESS *addr = NULL; ADDRESS *p, *q; pgp_key_t k_info = NULL, key = NULL; diff --git a/pgp.h b/pgp.h --- a/pgp.h +++ b/pgp.h @@ -46,17 +46,17 @@ /* int pgp_string_matches_hint (const char *s, LIST * hints); */ /* pgp_key_t gpg_get_candidates (struct pgp_vinfo *, pgp_ring_t, LIST *); */ pgp_key_t pgp_ask_for_key (char *, char *, short, pgp_ring_t); pgp_key_t pgp_get_candidates (pgp_ring_t, LIST *); pgp_key_t pgp_getkeybyaddr (ADDRESS *, short, pgp_ring_t); pgp_key_t pgp_getkeybystr (char *, short, pgp_ring_t); -char *pgp_findKeys (ADDRESS *adrlist); +char *pgp_findKeys (ADDRESS *adrlist, int oppenc_mode); void pgp_forget_passphrase (void); int pgp_application_pgp_handler (BODY *, STATE *); int pgp_encrypted_handler (BODY *, STATE *); void pgp_extract_keys_from_attachment_list (FILE * fp, int tag, BODY * top); void pgp_void_passphrase (void); int pgp_valid_passphrase (void); diff --git a/smime.c b/smime.c --- a/smime.c +++ b/smime.c @@ -724,19 +724,21 @@ { _smime_getkeys (t->mailbox); rfc822_free_address (&t); } } /* This routine attempts to find the keyids of the recipients of a message. * It returns NULL if any of the keys can not be found. + * If oppenc_mode is true, only keys that can be determined without + * prompting will be used. */ -char *smime_findKeys (ADDRESS *adrlist) +char *smime_findKeys (ADDRESS *adrlist, int oppenc_mode) { char *keyID, *keylist = NULL; size_t keylist_size = 0; size_t keylist_used = 0; ADDRESS *p, *q; for (p = adrlist; p ; p = p->next) { diff --git a/smime.h b/smime.h --- a/smime.h +++ b/smime.h @@ -45,17 +45,17 @@ char* smime_get_field_from_db (char *, char *, short, short); void smime_getkeys (ENVELOPE *); char* smime_ask_for_key (char *, char *, short); -char *smime_findKeys (ADDRESS *adrlist); +char *smime_findKeys (ADDRESS *adrlist, int oppenc_mode); void smime_invoke_import (char *, char *); int smime_send_menu (HEADER *msg, int *redraw); #endif