From 1951199b744b2104bf7fe60effe5dd0f455aee9c Mon Sep 17 00:00:00 2001 From: Pierre Habouzit Date: Sun, 13 May 2007 23:56:46 +0200 Subject: [PATCH] Move many things to the crypt module \o/ Signed-off-by: Pierre Habouzit --- buffy.cpkg | 1 - commands.c | 2 +- crypt.c => crypt.cpkg | 85 ++++++++++++++++++++++++++++++++++++++++++- crypt.h | 1 + init.h | 74 ------------------------------------- lib-lua/lua-token.sh | 8 ++++ lib-lua/runtime.c | 2 + mutt.h | 8 ---- send.c | 22 +++++------ tools/Makefile | 1 + 10 files changed, 106 insertions(+), 98 deletions(-) rename crypt.c => crypt.cpkg (97%) diff --git a/buffy.cpkg b/buffy.cpkg index 5ea4188..dc5f6c2 100644 --- a/buffy.cpkg +++ b/buffy.cpkg @@ -173,7 +173,6 @@ int buffy_check(int force) m_strcmp(tmp->path, Context->path))) { switch (tmp->magic) { case M_MBOX: - case M_MMDF: /* only check on force or $mail_check reached */ if (force == 1 || (now - last1 >= Buffy.mail_check)) { if (!count) { diff --git a/commands.c b/commands.c index 147742a..8e24718 100644 --- a/commands.c +++ b/commands.c @@ -86,7 +86,7 @@ int mutt_display_message (HEADER * cur) } else if (cur->security & SIGN) { /* find out whether or not the verify signature */ - if (query_quadoption (OPT_VERIFYSIG, _("Verify PGP signature?")) == + if (query_quadoption2(mod_crypt.verify_sig, _("Verify PGP signature?")) == M_YES) { cmflags |= M_CM_VERIFY; } diff --git a/crypt.c b/crypt.cpkg similarity index 97% rename from crypt.c rename to crypt.cpkg index 2273165..1350166 100644 --- a/crypt.c +++ b/crypt.cpkg @@ -29,6 +29,85 @@ #include "recvattach.h" #include "sort.h" +@import "lib-lua/base.cpkg" + +@package mod_crypt { + bool autosmime = 1; + /* + ** .pp + ** This variable controls whether or not Madmutt may automatically enable + ** S/MIME encryption/signing for messages. See also ``$$crypt_autoencrypt'', + ** ``$$crypt_replyencrypt'', + ** ``$$crypt_autosign'', ``$$crypt_replysign'' and ``$$smime_is_default''. + */ + bool autopgp = 1; + /* + ** .pp + ** This variable controls whether or not Madmutt may automatically enable + ** PGP encryption/signing for messages. See also ``$$crypt_autoencrypt'', + ** ``$$crypt_replyencrypt'', + ** ``$$crypt_autosign'', ``$$crypt_replysign'' and ``$$smime_is_default''. + */ + bool autosign = 0; + /* + ** .pp + ** Setting this variable will cause Madmutt to always attempt to + ** cryptographically sign outgoing messages. This can be overridden + ** by use of the \fIpgp-menu\fP, when signing is not required or + ** encryption is requested as well. If ``$$smime_is_default'' is \fIset\fP, + ** then OpenSSL is used instead to create S/MIME messages and settings can + ** be overridden by use of the \fIsmime-menu\fP. + ** (Crypto only) + */ + bool autoencrypt = 0; + /* + ** .pp + ** Setting this variable will cause Madmutt to always attempt to PGP + ** encrypt outgoing messages. This is probably only useful in + ** connection to the \fIsend-hook\fP command. It can be overridden + ** by use of the \fIpgp-menu\fP, when encryption is not required or + ** signing is requested as well. If ``$$smime_is_default'' is \fIset\fP, + ** then OpenSSL is used instead to create S/MIME messages and + ** settings can be overridden by use of the \fIsmime-menu\fP. + ** (Crypto only) + */ + bool replyencrypt = 1; + /* + ** .pp + ** If \fIset\fP, automatically PGP or OpenSSL encrypt replies to messages which are + ** encrypted. + ** (Crypto only) + */ + bool replysign = 0; + /* + ** .pp + ** If \fIset\fP, automatically PGP or OpenSSL sign replies to messages which are + ** signed. + ** .pp + ** \fBNote:\fP this does not work on messages that are encrypted \fBand\fP signed! + ** (Crypto only) + */ + bool replysignencrypted = 1; + /* + ** .pp + ** If \fIset\fP, automatically PGP or OpenSSL sign replies to messages + ** which are encrypted. This makes sense in combination with + ** ``$$crypt_replyencrypt'', because it allows you to sign all + ** messages which are automatically encrypted. This works around + ** the problem noted in ``$$crypt_replysign'', that Madmutt is not able + ** to find out whether an encrypted message is also signed. + ** (Crypto only) + */ + quadopt_t verify_sig = M_YES; + /* + ** .pp + ** If ``\fIyes\fP'', always attempt to verify PGP or S/MIME signatures. + ** If ``\fIask\fP'', ask whether or not to verify the signature. + ** If ``\fIno\fP'', never attempt to verify cryptographic signatures. + ** (Crypto only) + */ +}; + /* Values used for comparing addresses. */ #define CRYPT_KV_VALID 1 #define CRYPT_KV_ADDR 2 @@ -2360,7 +2439,7 @@ static const unsigned char *parse_dn_part (struct dn_array_s *array, s++; if (*s == ',' || *s == '=' || *s == '+' || *s == '<' || *s == '>' || *s == '#' || *s == ';' - || *s == '\\' || *s == '\"' || *s == ' ') + || *s == '\\' || *s == '"' || *s == ' ') n++; else if (hexval(*s) >= 0 && hexval(*s + 1) >= 0) { s++; @@ -2369,7 +2448,7 @@ static const unsigned char *parse_dn_part (struct dn_array_s *array, else return NULL; /* invalid escape sequence */ } - else if (*s == '\"') + else if (*s == '"') return NULL; /* invalid encoding */ else if (*s == ',' || *s == '=' || *s == '+' || *s == '<' || *s == '>' || *s == '#' || *s == ';') @@ -3927,3 +4006,5 @@ int mutt_signed_handler(BODY *a, STATE *s) return (rc); } + +/* vim:set ft=c: */ diff --git a/crypt.h b/crypt.h index 2858136..8c5e274 100644 --- a/crypt.h +++ b/crypt.h @@ -18,6 +18,7 @@ #include #include "state.h" +#include "crypt.li" #define ENCRYPT (1 << 0) #define SIGN (1 << 1) diff --git a/init.h b/init.h index b5cd61a..a20f7e1 100644 --- a/init.h +++ b/init.h @@ -377,22 +377,6 @@ struct option_t MuttVars[] = { ** will be saved for later references. Also see ``$$record'', ** and ``$fcc-hook''. */ - {"crypt_autopgp", DT_BOOL, R_NONE, OPTCRYPTAUTOPGP, "yes" }, - /* - ** .pp - ** This variable controls whether or not Madmutt may automatically enable - ** PGP encryption/signing for messages. See also ``$$crypt_autoencrypt'', - ** ``$$crypt_replyencrypt'', - ** ``$$crypt_autosign'', ``$$crypt_replysign'' and ``$$smime_is_default''. - */ - {"crypt_autosmime", DT_BOOL, R_NONE, OPTCRYPTAUTOSMIME, "yes" }, - /* - ** .pp - ** This variable controls whether or not Madmutt may automatically enable - ** S/MIME encryption/signing for messages. See also ``$$crypt_autoencrypt'', - ** ``$$crypt_replyencrypt'', - ** ``$$crypt_autosign'', ``$$crypt_replysign'' and ``$$smime_is_default''. - */ {"date_format", DT_STR, R_BOTH, UL &DateFmt, "!%a, %b %d, %Y at %I:%M:%S%p %Z"}, /* ** .pp @@ -1519,64 +1503,6 @@ struct option_t MuttVars[] = { ** when you are at the end of a message and invoke the \fInext-page\fP ** function. */ - {"crypt_autosign", DT_BOOL, R_NONE, OPTCRYPTAUTOSIGN, "no" }, - /* - ** .pp - ** Setting this variable will cause Madmutt to always attempt to - ** cryptographically sign outgoing messages. This can be overridden - ** by use of the \fIpgp-menu\fP, when signing is not required or - ** encryption is requested as well. If ``$$smime_is_default'' is \fIset\fP, - ** then OpenSSL is used instead to create S/MIME messages and settings can - ** be overridden by use of the \fIsmime-menu\fP. - ** (Crypto only) - */ - {"crypt_autoencrypt", DT_BOOL, R_NONE, OPTCRYPTAUTOENCRYPT, "no" }, - /* - ** .pp - ** Setting this variable will cause Madmutt to always attempt to PGP - ** encrypt outgoing messages. This is probably only useful in - ** connection to the \fIsend-hook\fP command. It can be overridden - ** by use of the \fIpgp-menu\fP, when encryption is not required or - ** signing is requested as well. If ``$$smime_is_default'' is \fIset\fP, - ** then OpenSSL is used instead to create S/MIME messages and - ** settings can be overridden by use of the \fIsmime-menu\fP. - ** (Crypto only) - */ - {"crypt_replyencrypt", DT_BOOL, R_NONE, OPTCRYPTREPLYENCRYPT, "yes" }, - /* - ** .pp - ** If \fIset\fP, automatically PGP or OpenSSL encrypt replies to messages which are - ** encrypted. - ** (Crypto only) - */ - {"crypt_replysign", DT_BOOL, R_NONE, OPTCRYPTREPLYSIGN, "no" }, - /* - ** .pp - ** If \fIset\fP, automatically PGP or OpenSSL sign replies to messages which are - ** signed. - ** .pp - ** \fBNote:\fP this does not work on messages that are encrypted \fBand\fP signed! - ** (Crypto only) - */ - {"crypt_replysignencrypted", DT_BOOL, R_NONE, OPTCRYPTREPLYSIGNENCRYPTED, "no" }, - /* - ** .pp - ** If \fIset\fP, automatically PGP or OpenSSL sign replies to messages - ** which are encrypted. This makes sense in combination with - ** ``$$crypt_replyencrypt'', because it allows you to sign all - ** messages which are automatically encrypted. This works around - ** the problem noted in ``$$crypt_replysign'', that Madmutt is not able - ** to find out whether an encrypted message is also signed. - ** (Crypto only) - */ - {"crypt_verify_sig", DT_QUAD, R_NONE, OPT_VERIFYSIG, "yes" }, - /* - ** .pp - ** If ``\fIyes\fP'', always attempt to verify PGP or S/MIME signatures. - ** If ``\fIask\fP'', ask whether or not to verify the signature. - ** If ``\fIno\fP'', never attempt to verify cryptographic signatures. - ** (Crypto only) - */ {"smime_is_default", DT_BOOL, R_NONE, OPTSMIMEISDEFAULT, "no" }, /* ** .pp diff --git a/lib-lua/lua-token.sh b/lib-lua/lua-token.sh index d744d73..aac0da7 100644 --- a/lib-lua/lua-token.sh +++ b/lib-lua/lua-token.sh @@ -115,6 +115,10 @@ exit 0 ## ask-no ## ask-yes ## assumed_charset +## autoencrypt +## autopgp +## autosign +## autosmime ## beep ## beep_new ## bindir @@ -142,6 +146,9 @@ exit 0 ## operating_system ## quit ## record +## replyencrypt +## replysign +## replysignencrypted ## send_charset ## sendmail ## sendmail_wait @@ -158,5 +165,6 @@ exit 0 ## username ## use_sslv3 ## use_tlsv1 +## verify_sig ## version ## yes diff --git a/lib-lua/runtime.c b/lib-lua/runtime.c index 2214e9b..55bdeef 100644 --- a/lib-lua/runtime.c +++ b/lib-lua/runtime.c @@ -24,6 +24,7 @@ #include "../mutt.h" #include "../charset.h" #include "../buffy.h" +#include "../crypt.h" #include static lua_State *L; @@ -46,6 +47,7 @@ void luaM_initialize(void) {"Mime", luaopen_Mime}, {"Buffy", luaopen_Buffy}, {"mod_ssl", luaopen_mod_ssl}, + {"mod_crypt", luaopen_mod_crypt}, }; int i; diff --git a/mutt.h b/mutt.h index 86d6d55..fca80e6 100644 --- a/mutt.h +++ b/mutt.h @@ -170,7 +170,6 @@ enum { OPT_REPLYTO, OPT_RECALL, OPT_SUBJECT, - OPT_VERIFYSIG, /* verify PGP signatures */ OPT_LISTREPLY, #ifdef USE_NNTP OPT_TOMODERATED, @@ -310,13 +309,6 @@ enum { /* PGP options */ - OPTCRYPTAUTOSIGN, - OPTCRYPTAUTOENCRYPT, - OPTCRYPTAUTOPGP, - OPTCRYPTAUTOSMIME, - OPTCRYPTREPLYENCRYPT, - OPTCRYPTREPLYSIGN, - OPTCRYPTREPLYSIGNENCRYPTED, OPTSMIMEISDEFAULT, OPTPGPAUTODEC, OPTPGPRETAINABLESIG, diff --git a/send.c b/send.c index f403320..0d25bc1 100644 --- a/send.c +++ b/send.c @@ -1327,16 +1327,15 @@ int ci_send_message (int flags, /* send mode */ * can take effect. */ - if (option (OPTCRYPTAUTOSIGN)) + if (mod_crypt.autosign) msg->security |= SIGN; - if (option (OPTCRYPTAUTOENCRYPT)) + if (mod_crypt.autoencrypt) msg->security |= ENCRYPT; - if (option (OPTCRYPTREPLYENCRYPT) && cur && (cur->security & ENCRYPT)) + if (mod_crypt.replyencrypt && cur && (cur->security & ENCRYPT)) msg->security |= ENCRYPT; - if (option (OPTCRYPTREPLYSIGN) && cur && (cur->security & SIGN)) + if (mod_crypt.replysign && cur && (cur->security & SIGN)) msg->security |= SIGN; - if (option (OPTCRYPTREPLYSIGNENCRYPTED) && cur - && (cur->security & ENCRYPT)) + if (mod_crypt.replysignencrypted && cur && (cur->security & ENCRYPT)) msg->security |= SIGN; if (msg->security) { @@ -1350,10 +1349,9 @@ int ci_send_message (int flags, /* send mode */ * disable individual mechanisms at run-time? */ if (cur) { - if (option (OPTCRYPTAUTOPGP) && (cur->security & APPLICATION_PGP)) + if (mod_crypt.autopgp && (cur->security & APPLICATION_PGP)) msg->security |= APPLICATION_PGP; - else if (option (OPTCRYPTAUTOSMIME) - && (cur->security & APPLICATION_SMIME)) + else if (mod_crypt.autosmime && (cur->security & APPLICATION_SMIME)) msg->security |= APPLICATION_SMIME; } @@ -1362,11 +1360,11 @@ int ci_send_message (int flags, /* send mode */ * for the decision. */ if (!(msg->security & (APPLICATION_SMIME | APPLICATION_PGP))) { - if (option (OPTCRYPTAUTOSMIME) && option (OPTSMIMEISDEFAULT)) + if (mod_crypt.autosmime && option(OPTSMIMEISDEFAULT)) msg->security |= APPLICATION_SMIME; - else if (option (OPTCRYPTAUTOPGP)) + else if (mod_crypt.autopgp) msg->security |= APPLICATION_PGP; - else if (option (OPTCRYPTAUTOSMIME)) + else if (mod_crypt.autosmime) msg->security |= APPLICATION_SMIME; } } diff --git a/tools/Makefile b/tools/Makefile index 6b5625a..680d15f 100644 --- a/tools/Makefile +++ b/tools/Makefile @@ -5,6 +5,7 @@ all: ../lib-mime/mime-token.h \ ../lib-lua/madmutt.li \ ../lib-sys/mutt_ssl.li \ ../alias.li \ + ../crypt.li \ ../buffy.li \ ../charset.li -- 2.20.1