]> granicus.if.org Git - neomutt/commitdiff
add typedef for SecurityFlags
authorRichard Russon <rich@flatcap.org>
Wed, 27 Feb 2019 00:16:33 +0000 (00:16 +0000)
committerRichard Russon <rich@flatcap.org>
Fri, 1 Mar 2019 13:10:32 +0000 (13:10 +0000)
13 files changed:
email/email.h
ncrypt/crypt.c
ncrypt/crypt_gpgme.c
ncrypt/crypt_mod.h
ncrypt/cryptglue.c
ncrypt/ncrypt.h
ncrypt/pgp.c
ncrypt/pgp.h
ncrypt/pgpinvoke.c
ncrypt/smime.c
postpone.c
protos.h
recvattach.c

index 5a65b30601a2304b90e45f4fe8131c3198d1f40c..98cecd3ee0be4f9f4626b0cd429ab036f93dbe7e 100644 (file)
@@ -27,6 +27,7 @@
 #include <stdbool.h>
 #include <time.h>
 #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? */
index 9860aadd88fbb50c83605a666c8cde7af70f6e8d..165094aae9012a052dd7c0607691c7413aa9cf82 100644 (file)
@@ -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)
   {
index fe029854b2206a76f7db14056f8905ef84e4febe..f91b21eb20834997bb99dc59f8b0973a4adec6a7 100644 (file)
@@ -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;
index a0a1bb54f8d285dad4927dab69e042a6f1a77275..f09fd3964eb49a1d6ed6503984ccb3412cc410f0 100644 (file)
@@ -25,6 +25,7 @@
 
 #include <stdbool.h>
 #include <stdio.h>
+#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
index f2226e971377f4fdf5879a65956a64c47b2dbcfe..e49315379f43b20e8f6fa46c0f7e3f7f77bc948a 100644 (file)
@@ -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))
index b79fa8c710d6f3bda1068b813580f27d2ccbbcc0..b5fcd1b5571d6f9b6ad0d8b7e5b6d3fd665200b7 100644 (file)
@@ -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);
index f723a2c9663a81d5f4aaf86ee3891bd926ed17db..aa4ded51ea91ed07d88fec0e1bf6df7b22f93dc9 100644 (file)
@@ -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;
 
index 1956a4965808c9c575e0f320f6b8e2124b462c2d..d79e825dd56a59d342c33fc24fc2fe0107f8409c 100644 (file)
@@ -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);
 
index 1a992f43ad2288cfb8bc44e678108412cd5f6cd6..35d1fc90e36bbc7b41a3f68b92f4519e70138cec 100644 (file)
@@ -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)
   {
index 30b516f31910b925df51a291c5846936ea854814..964c01ca09420d715dff11b2f43ecf5780250c3b 100644 (file)
@@ -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;
index 4e5e7b11112c5014a54795923e9a01e7ed99cd8c..b29e75811fc7d44a43acdbd3960efedbfaa34251 100644 (file)
@@ -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)))
index 461fb8b3d2fdb2fb94c147b09431720d3f01d00f..b98ea8f898089b70806e9bc2240b69631ecb835e 100644 (file)
--- a/protos.h
+++ b/protos.h
@@ -30,6 +30,7 @@
 #include <time.h>
 #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);
index 682f232d77beaa87a818b11e01dc4af137e3985d..79ab0e98c65cbf7b36356e4c17854c7d7a019afd 100644 (file)
@@ -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)
   {