From b60b10f786662b1398ad1cacb26994efda900dbe Mon Sep 17 00:00:00 2001 From: Richard Russon Date: Wed, 27 Feb 2019 00:16:33 +0000 Subject: [PATCH] add typedef for SecurityFlags --- email/email.h | 3 ++- ncrypt/crypt.c | 34 +++++++++++++++++----------------- ncrypt/crypt_gpgme.c | 5 ++--- ncrypt/crypt_mod.h | 5 +++-- ncrypt/cryptglue.c | 8 ++++---- ncrypt/ncrypt.h | 12 +++++++----- ncrypt/pgp.c | 2 +- ncrypt/pgp.h | 2 +- ncrypt/pgpinvoke.c | 8 ++++---- ncrypt/smime.c | 2 +- postpone.c | 18 +++++++++--------- protos.h | 3 ++- recvattach.c | 3 ++- 13 files changed, 55 insertions(+), 50 deletions(-) diff --git a/email/email.h b/email/email.h index 5a65b3060..98cecd3ee 100644 --- a/email/email.h +++ b/email/email.h @@ -27,6 +27,7 @@ #include #include #include "mutt/mutt.h" +#include "ncrypt/ncrypt.h" #include "tags.h" /** @@ -34,7 +35,7 @@ */ struct Email { - unsigned int security : 12; /**< bit 0-8: flags, bit 9,10: application. + SecurityFlags security; /**< bit 0-8: flags, bit 9,10: application. see: ncrypt/ncrypt.h pgplib.h, smime.h */ bool mime : 1; /**< has a MIME-Version email? */ diff --git a/ncrypt/crypt.c b/ncrypt/crypt.c index 9860aadd8..165094aae 100644 --- a/ncrypt/crypt.c +++ b/ncrypt/crypt.c @@ -138,11 +138,11 @@ static void disable_coredumps(void) /** * crypt_valid_passphrase - Check that we have a usable passphrase, ask if not - * @param flags Flags, e.g. #APPLICATION_PGP + * @param flags Flags, see #SecurityFlags * @retval 0 Success * @retval -1 Failure */ -int crypt_valid_passphrase(int flags) +int crypt_valid_passphrase(SecurityFlags flags) { int rc = 0; @@ -523,11 +523,11 @@ int mutt_is_malformed_multipart_pgp_encrypted(struct Body *b) * mutt_is_application_pgp - Does the message use PGP? * @param m Body of email * @retval >0 Message uses PGP, e.g. #PGP_ENCRYPT - * @retval 0 Message doesn't use PGP + * @retval 0 Message doesn't use PGP, (#SEC_NO_FLAGS) */ -int mutt_is_application_pgp(struct Body *m) +SecurityFlags mutt_is_application_pgp(struct Body *m) { - int t = 0; + SecurityFlags t = SEC_NO_FLAGS; char *p = NULL; if (m->type == TYPE_APPLICATION) @@ -582,15 +582,15 @@ int mutt_is_application_pgp(struct Body *m) * mutt_is_application_smime - Does the message use S/MIME? * @param m Body of email * @retval >0 Message uses S/MIME, e.g. #SMIME_ENCRYPT - * @retval 0 Message doesn't use S/MIME + * @retval 0 Message doesn't use S/MIME, (#SEC_NO_FLAGS) */ -int mutt_is_application_smime(struct Body *m) +SecurityFlags mutt_is_application_smime(struct Body *m) { if (!m) - return 0; + return SEC_NO_FLAGS; if (((m->type & TYPE_APPLICATION) == 0) || !m->subtype) - return 0; + return SEC_NO_FLAGS; char *t = NULL; bool complain = false; @@ -606,7 +606,7 @@ int mutt_is_application_smime(struct Body *m) else if (mutt_str_strcasecmp(t, "signed-data") == 0) return SMIME_SIGN | SMIME_OPAQUE; else - return 0; + return SEC_NO_FLAGS; } /* Netscape 4.7 uses * Content-Description: S/MIME Encrypted Message @@ -617,7 +617,7 @@ int mutt_is_application_smime(struct Body *m) complain = true; } else if (mutt_str_strcasecmp(m->subtype, "octet-stream") != 0) - return 0; + return SEC_NO_FLAGS; t = mutt_param_get(&m->parameter, "name"); @@ -632,7 +632,7 @@ int mutt_is_application_smime(struct Body *m) mutt_message( _("S/MIME messages with no hints on content are unsupported")); } - return 0; + return SEC_NO_FLAGS; } /* no .p7c, .p10 support yet. */ @@ -651,26 +651,26 @@ int mutt_is_application_smime(struct Body *m) return SMIME_SIGN | SMIME_OPAQUE; } - return 0; + return SEC_NO_FLAGS; } /** * crypt_query - Check out the type of encryption used * @param m Body of email * @retval num Flags, e.g. #SEC_GOODSIGN - * @retval 0 Error + * @retval 0 Error (#SEC_NO_FLAGS) * * Set the cached status values if there are any. */ int crypt_query(struct Body *m) { - int t = 0; + SecurityFlags t = SEC_NO_FLAGS; if (!WithCrypto) - return 0; + return SEC_NO_FLAGS; if (!m) - return 0; + return SEC_NO_FLAGS; if (m->type == TYPE_APPLICATION) { diff --git a/ncrypt/crypt_gpgme.c b/ncrypt/crypt_gpgme.c index fe029854b..f91b21eb2 100644 --- a/ncrypt/crypt_gpgme.c +++ b/ncrypt/crypt_gpgme.c @@ -2666,14 +2666,13 @@ static int pgp_check_traditional_one_body(FILE *fp, struct Body *b) int pgp_gpgme_check_traditional(FILE *fp, struct Body *b, bool just_one) { int rc = 0; - int r; for (; b; b = b->next) { if (!just_one && is_multipart(b)) rc = (pgp_gpgme_check_traditional(fp, b->parts, false) || rc); else if (b->type == TYPE_TEXT) { - r = mutt_is_application_pgp(b); + SecurityFlags r = mutt_is_application_pgp(b); if (r != 0) rc = (rc || r); else @@ -4450,7 +4449,7 @@ static char *list_to_pattern(struct ListHead *list) * * Select by looking at the HINTS list. */ -static struct CryptKeyInfo *get_candidates(struct ListHead *hints, unsigned int app, int secret) +static struct CryptKeyInfo *get_candidates(struct ListHead *hints, SecurityFlags app, int secret) { struct CryptKeyInfo *db = NULL, *k = NULL, **kend = NULL; gpgme_error_t err; diff --git a/ncrypt/crypt_mod.h b/ncrypt/crypt_mod.h index a0a1bb54f..f09fd3964 100644 --- a/ncrypt/crypt_mod.h +++ b/ncrypt/crypt_mod.h @@ -25,6 +25,7 @@ #include #include +#include "ncrypt.h" struct Address; struct Body; @@ -152,12 +153,12 @@ struct CryptModuleSpecs /** * pgp_traditional_encryptsign - Create an inline PGP encrypted, signed email * @param a Body of the email - * @param flags Flags, e.g. #SEC_ENCRYPT + * @param flags Flags, see #SecurityFlags * @param keylist List of keys to encrypt to (space-separated) * @retval ptr New encrypted/siged Body * @retval NULL Error */ - struct Body *(*pgp_traditional_encryptsign)(struct Body *a, int flags, char *keylist); + struct Body *(*pgp_traditional_encryptsign)(struct Body *a, SecurityFlags flags, char *keylist); /** * pgp_invoke_getkeys - Run a command to download a PGP key * @param addr Address to search for diff --git a/ncrypt/cryptglue.c b/ncrypt/cryptglue.c index f2226e971..e49315379 100644 --- a/ncrypt/cryptglue.c +++ b/ncrypt/cryptglue.c @@ -131,11 +131,11 @@ void crypt_init(void) /** * crypt_invoke_message - Display an informative message - * @param type Crypto type, e.g. #APPLICATION_PGP + * @param type Crypto type, see #SecurityFlags * * Show a message that a backend will be invoked. */ -void crypt_invoke_message(int type) +void crypt_invoke_message(SecurityFlags type) { if (((WithCrypto & APPLICATION_PGP) != 0) && (type & APPLICATION_PGP)) mutt_message(_("Invoking PGP...")); @@ -145,11 +145,11 @@ void crypt_invoke_message(int type) /** * crypt_has_module_backend - Is there a crypto backend for a given type? - * @param type Crypto type, e.g. #APPLICATION_PGP + * @param type Crypto type, see #SecurityFlags * @retval true Backend is present * @retval false Backend is not present */ -bool crypt_has_module_backend(int type) +bool crypt_has_module_backend(SecurityFlags type) { if (((WithCrypto & APPLICATION_PGP) != 0) && (type & APPLICATION_PGP) && crypto_module_lookup(APPLICATION_PGP)) diff --git a/ncrypt/ncrypt.h b/ncrypt/ncrypt.h index b79fa8c71..b5fcd1b55 100644 --- a/ncrypt/ncrypt.h +++ b/ncrypt/ncrypt.h @@ -115,6 +115,8 @@ extern long C_SmimeTimeout; extern char *C_SmimeVerifyCommand; extern char *C_SmimeVerifyOpaqueCommand; +typedef uint16_t SecurityFlags; ///< Flags, e.g. #SEC_ENCRYPT +#define SEC_NO_FLAGS 0 ///< No flags are set #define SEC_ENCRYPT (1 << 0) ///< Email is encrypted #define SEC_SIGN (1 << 1) ///< Email is signed #define SEC_GOODSIGN (1 << 2) ///< Email has a valid signature @@ -182,9 +184,9 @@ void crypt_forget_passphrase(void); int crypt_get_keys(struct Email *msg, char **keylist, bool oppenc_mode); void crypt_opportunistic_encrypt(struct Email *msg); int crypt_query(struct Body *m); -int crypt_valid_passphrase(int flags); -int mutt_is_application_pgp(struct Body *m); -int mutt_is_application_smime(struct Body *m); +int crypt_valid_passphrase(SecurityFlags flags); +SecurityFlags mutt_is_application_pgp(struct Body *m); +SecurityFlags mutt_is_application_smime(struct Body *m); int mutt_is_malformed_multipart_pgp_encrypted(struct Body *b); int mutt_is_multipart_encrypted(struct Body *b); int mutt_is_multipart_signed(struct Body *b); @@ -195,9 +197,9 @@ bool mutt_should_hide_protected_subject(struct Email *e); int mutt_signed_handler(struct Body *a, struct State *s); /* cryptglue.c */ -bool crypt_has_module_backend(int type); +bool crypt_has_module_backend(SecurityFlags type); void crypt_init(void); -void crypt_invoke_message(int type); +void crypt_invoke_message(SecurityFlags type); int crypt_pgp_application_handler(struct Body *m, struct State *s); int crypt_pgp_check_traditional(FILE *fp, struct Body *b, bool just_one); int crypt_pgp_decrypt_mime(FILE *a, FILE **b, struct Body *c, struct Body **d); diff --git a/ncrypt/pgp.c b/ncrypt/pgp.c index f723a2c96..aa4ded51e 100644 --- a/ncrypt/pgp.c +++ b/ncrypt/pgp.c @@ -1667,7 +1667,7 @@ struct Body *pgp_class_encrypt_message(struct Body *a, char *keylist, bool sign) /** * pgp_class_traditional_encryptsign - Implements CryptModuleSpecs::pgp_traditional_encryptsign() */ -struct Body *pgp_class_traditional_encryptsign(struct Body *a, int flags, char *keylist) +struct Body *pgp_class_traditional_encryptsign(struct Body *a, SecurityFlags flags, char *keylist) { struct Body *b = NULL; diff --git a/ncrypt/pgp.h b/ncrypt/pgp.h index 1956a4965..d79e825dd 100644 --- a/ncrypt/pgp.h +++ b/ncrypt/pgp.h @@ -55,7 +55,7 @@ void pgp_class_void_passphrase(void); int pgp_class_valid_passphrase(void); int pgp_class_verify_one(struct Body *sigbdy, struct State *s, const char *tempfile); -struct Body *pgp_class_traditional_encryptsign(struct Body *a, int flags, char *keylist); +struct Body *pgp_class_traditional_encryptsign(struct Body *a, SecurityFlags flags, char *keylist); struct Body *pgp_class_encrypt_message(struct Body *a, char *keylist, bool sign); struct Body *pgp_class_sign_message(struct Body *a); diff --git a/ncrypt/pgpinvoke.c b/ncrypt/pgpinvoke.c index 1a992f43a..35d1fc90e 100644 --- a/ncrypt/pgpinvoke.c +++ b/ncrypt/pgpinvoke.c @@ -369,16 +369,16 @@ pid_t pgp_invoke_encrypt(FILE **pgpin, FILE **pgpout, FILE **pgperr, * @param[in] pgperrfd stderr for the command, or -1 (OPTIONAL) * @param[in] fname Filename to pass to the command * @param[in] uids List of IDs/fingerprints, space separated - * @param[in] flags Flags, e.g. #SEC_SIGN, #SEC_ENCRYPT + * @param[in] flags Flags, see #SecurityFlags * @retval num PID of the created process * @retval -1 Error creating pipes or forking * * @note `pgpin` has priority over `pgpinfd`. * Likewise `pgpout` and `pgperr`. */ -pid_t pgp_invoke_traditional(FILE **pgpin, FILE **pgpout, FILE **pgperr, - int pgpinfd, int pgpoutfd, int pgperrfd, - const char *fname, const char *uids, int flags) +pid_t pgp_invoke_traditional(FILE **pgpin, FILE **pgpout, FILE **pgperr, int pgpinfd, + int pgpoutfd, int pgperrfd, const char *fname, + const char *uids, SecurityFlags flags) { if (flags & SEC_ENCRYPT) { diff --git a/ncrypt/smime.c b/ncrypt/smime.c index 30b516f31..964c01ca0 100644 --- a/ncrypt/smime.c +++ b/ncrypt/smime.c @@ -2007,7 +2007,7 @@ static struct Body *smime_handle_entity(struct Body *m, struct State *s, FILE *o struct stat info; struct Body *p = NULL; pid_t thepid = -1; - unsigned int type = mutt_is_application_smime(m); + SecurityFlags type = mutt_is_application_smime(m); if (!(type & APPLICATION_SMIME)) return NULL; diff --git a/postpone.c b/postpone.c index 4e5e7b111..b29e75811 100644 --- a/postpone.c +++ b/postpone.c @@ -447,16 +447,16 @@ int mutt_get_postponed(struct Context *ctx, struct Email *hdr, * @param p Header string to parse * @param set_empty_signas Allow an empty "Sign as" * @param crypt_app App, e.g. #APPLICATION_PGP - * @retval num Flags, e.g. #SEC_ENCRYPT + * @retval num SecurityFlags, see #SecurityFlags */ -int mutt_parse_crypt_hdr(const char *p, int set_empty_signas, int crypt_app) +SecurityFlags mutt_parse_crypt_hdr(const char *p, int set_empty_signas, SecurityFlags crypt_app) { char smime_cryptalg[1024] = "\0"; char sign_as[1024] = "\0", *q = NULL; - int flags = 0; + SecurityFlags flags = SEC_NO_FLAGS; if (!WithCrypto) - return 0; + return SEC_NO_FLAGS; p = mutt_str_skip_email_wsp(p); for (; *p; p++) @@ -478,7 +478,7 @@ int mutt_parse_crypt_hdr(const char *p, int set_empty_signas, int crypt_app) if (*p != '>') { mutt_error(_("Illegal S/MIME header")); - return 0; + return SEC_NO_FLAGS; } } @@ -509,7 +509,7 @@ int mutt_parse_crypt_hdr(const char *p, int set_empty_signas, int crypt_app) if (*p != '>') { mutt_error(_("Illegal crypto header")); - return 0; + return SEC_NO_FLAGS; } } @@ -535,7 +535,7 @@ int mutt_parse_crypt_hdr(const char *p, int set_empty_signas, int crypt_app) if (*p != '>') { mutt_error(_("Illegal crypto header")); - return 0; + return SEC_NO_FLAGS; } } @@ -544,7 +544,7 @@ int mutt_parse_crypt_hdr(const char *p, int set_empty_signas, int crypt_app) default: mutt_error(_("Illegal crypto header")); - return 0; + return SEC_NO_FLAGS; } } @@ -590,7 +590,7 @@ int mutt_prepare_template(FILE *fp, struct Mailbox *m, struct Email *newhdr, FILE *bfp = NULL; int rc = -1; struct State s = { 0 }; - int sec_type; + SecurityFlags sec_type; struct Envelope *protected_headers = NULL; if (!fp && !(msg = mx_msg_open(m, e->msgno))) diff --git a/protos.h b/protos.h index 461fb8b3d..b98ea8f89 100644 --- a/protos.h +++ b/protos.h @@ -30,6 +30,7 @@ #include #include "config/lib.h" #include "mutt.h" +#include "ncrypt/ncrypt.h" struct Context; struct EnterState; @@ -75,7 +76,7 @@ int mutt_enter_string(char *buf, size_t buflen, int col, CompletionFlags flags); int mutt_enter_string_full(char *buf, size_t buflen, int col, CompletionFlags flags, bool multiple, char ***files, int *numfiles, struct EnterState *state); int mutt_get_postponed(struct Context *ctx, struct Email *e, struct Email **cur, char *fcc, size_t fcclen); -int mutt_parse_crypt_hdr(const char *p, int set_empty_signas, int crypt_app); +SecurityFlags mutt_parse_crypt_hdr(const char *p, int set_empty_signas, SecurityFlags crypt_app); int mutt_num_postponed(struct Mailbox *m, bool force); int mutt_thread_set_flag(struct Email *e, int flag, bool bf, bool subthread); void mutt_update_num_postponed(void); diff --git a/recvattach.c b/recvattach.c index 682f232d7..79ab0e98c 100644 --- a/recvattach.c +++ b/recvattach.c @@ -1136,7 +1136,8 @@ static void mutt_generate_recvattach_list(struct AttachCtx *actx, struct Email * struct Body *m = NULL; struct Body *new_body = NULL; FILE *new_fp = NULL; - int type, need_secured, secured; + SecurityFlags type; + int need_secured, secured; for (m = parts; m; m = m->next) { -- 2.40.0