summaryrefslogtreecommitdiffstats
path: root/compose.c
diff options
context:
space:
mode:
authorWerner Koch <wk@gnupg.org>2003-01-21 12:33:41 +0000
committerWerner Koch <wk@gnupg.org>2003-01-21 12:33:41 +0000
commitc901be35d96df6dcdef8bf96c32f8fd6159f19d9 (patch)
tree0684a86565bd4eb26c6f9f7b935a78669fa58c2e /compose.c
parente6f3bd255bf9edf2c155e33e611174aef272d89e (diff)
- To cleanup the pgp/smime code and prepare for other backends.
- Support gpg-agent by not asking for a passphrase - autconf cleanups. This is just a start and probably we need a couple of other things to do. One drawback is that the help menu does always list all crypto realted stuff even when configured for no crypto at all. Same goes for the configure options but I consider thsi a feature: It allows to use the same .muttrc for different versions of mutt - at least during development, this is an advantage. This all might be fixed but requires some changes to the configuration system. Note, the use of the WithCrypto macro - it enables the compiler to do dead-code-elimination depending on the configured backend. This is better readable than all the nested ifdefs. I did some short tests and it seems to work, althoug mutt's size does not change largely when compiled w/o crypto. cryptglue.c is new as a warpper to all crypto calls; some are still in crypt.c but they should eventually also be wrapped. We don't use function pointers to keep a path to use dlopen or runtime configured backends. crypt.h is also new and replaces pgp.h and smime.h in most files (except for the backend). 2003-01-06 Werner Koch <wk@gnupg.org> * crypt.c (crypt_valid_passphrase): Detect gpg-agent and don't ask for the passphrase. * pgp.c (pgp_decrypt_part, pgp_application_pgp_handler) (pgp_sign_message, pgp_encrypt_message) (pgp_traditional_encryptsign): Make sure that we never ever send the passphrase if the gpg-agent has been detected. Likewise. * acconfig.h: Removed all remaining stuff as AC_TEMPLATEs to configure.in. BTW, we should consider to rename configure.in to configure.ac. 2003-01-04 Werner Koch <wk@gnupg.org> Replaced the use of HAVE_PGP and HAVE_SMIME by a more readable and extendable solution. * pgplib.h: Moved enum pgp_ring and KEYFLAGS_* to * crypt.h: here. * smime.c (mutt_is_application_smime): Moved to * crypt.c (mutt_is_application_smime): here. * pgp.c (mutt_is_application_pgp): Moved to * crypt.c (mutt_is_application_pgp): here. * pgp.c (pgp_is_multipart_encrypted): Removed. Merged code with * crypt.c (mutt_is_multipart_encrypted): this. * mutt.h: Protect against double inclusion. * pgplib.h (struct pgp_keyinfo): Remove the typedef to pgp_key_t. * crypt.h (pgp_key_t): Declare the typedef here. NOTE: This is now a pointer. Changed all usages accordingly. * configure.in: Replace HAVE_PGP and HAVE_SMIME by the new CRYPT_BACKEND macros. Always include all OPS.*. (LIBOBJ): Replaced by AC_LIBOBJ as required by newer autoconfs. * Makefile.am (EXTRA_mutt_SOURCES): Move crypt.c to mutt_SOURCES. (mutt_SOURCES): Add cryptglue.c (EXTRA_DIST): Add crypt.h * pgp.h, pgplib.h, smime.h: Use the header only when the approriate backend has been configured. * pgp.c, pgpkey.c, smime.c: Build only if the approriate CRYPT_BACKEND_ macro is defined. * pgp.h, smime.h, global.h: Moved all variable declarations to global.h because they are now always defined. * sort.h: Always define PgpSortKey, although it does not belong to here. * keymap.h: Unconditionally include all PGP and SMIME stuff. * mutt.h: Ditto. * protos.h: Ditto. * init.h (HAVE_SMIME): Unconditionally include all crypto related definitions. Mark the doc entries with "(Crypto/PGP/SMIME only)". * globals.h: Replace gpg.h and smime.h by crypt.h. * functions.h: Always include all crypto commands. * copy.h: Unconditionally define the crypto related M_CM_ * pgplib.h: Move APPLICATION_PGP and PGP* to crypt.h and include it. * smime.h: Move APPLICATION_SMIME and SMIME* to crypt.h and include it. * mutt_crypt.h (ENCRYPT,SIGN,GOODSIGN, BADSIGN): Move to crypt.h. * crypt.c: Replaced pgp.h and smime.h header by crypt.h. Always include all functions but shortcut them depending on WITHCRYPTO. All over the place use WITHCRYPTO instead of ifdefs. Replaced all direct calls of the backend fucntions by twrapper functions defined in cryptglue.c (crypt_get_keys): Removed prototypes. * pgp.h (pgp_findKeys): New prototype. * smime.h (smime_findKeys): New prototype. * cryptglue.c: New. * crypt.h: New. * mutt_crypt.h: Moved all crypt_* prototypes to gcrypt.h. Unconditionally use this file. * init.c: Replaced pgp.h and smime.h header by crypt.h. (parse_set): Use WITHCRYPTO instead of ifdefs. (mutt_var_value_complete): Ditto. * sendlib.c: Replaced pgp.h and smime.h header by crypt.h. (write_as_text_part): Now one macro using WITHCRYPTO. (mutt_write_mime_body): Use WITHCRYPTO instead of ifdefs. (mutt_make_message_attach): Ditto. (mutt_write_fcc): Ditto. * send.c: Replaced pgp.h and smime.h header by crypt.h. (include_forward): Use WITHCRYPTO and validate passphrases for pgp and smime. (include_reply): Ditto. (generate_body): Use WITHCRYPTO instead of ifdefs. (ci_send_message): Ditto. * recvattach.c: Replaced pgp.h and smime.h header by crypt.h. (mutt_gen_attach_list): Use WITHCRYPTO instead of ifdefs. (mutt_attach_display_loop): Ditto (mutt_view_attachments): Ditto. * postpone.c: Replaced pgp.h and smime.h header by crypt.h. (mutt_get_postponed): Use WITHCRYPTO instead of ifdefs. (mutt_parse_crypt_hdr): Always include and use WITHCRYPTO instead of ifdefs. (mutt_prepare_template): Use WITHCRYPTO instead of ifdefs. * pop.c: Removed pgp.h and smime.h. (pop_fetch_message): Use WITHCRYPTO instead of ifdefs. * pattern.c: Replaced pgp.h and smime.h header by crypt.h. (Flags): Always include the crypto flags. (msg_search): Use WITHCRYPTO instead of ifdefs. (mutt_pattern_exec): Ditto. * parse.c: Removed pgp.h and smime.h. (mutt_parse_mime_message): Use WITHCRYPTO instead of ifdefs. * pager.c: Replaced pgp.h and smime.h header by crypt.h. (mutt_pager): Use WITHCRYPTO instead of ifdefs. * mx.c: Removed smime.h and pgp.h. (mx_update_context): Use WITHCRYPTO instead of ifdefs. * muttlib.c: Replaced pgp.h and smime.h header by crypt.h. (mutt_needs_mailcap): Use WITHCRYPTO. Note, that there used to be an error when PGP was not configured so that TYPEAPPLICATION was not recognized for SMIME. (mutt_is_text_part): Use WITHCRYPTO instead of ifdefs. * main.c: Include crypt.h. (show_version): Remove HAVE_PGP and HAVE_SMIME. Add CRYPT_BACKEND_CLASSIC_PGP, CRYPT_BACKEND_CLASSIC_SMIME. * keymap.c: Include crypt.h so that we can test WITHCRYPTO. (Menus): Always include pgp and smime. (km_init): Create smime and pgp bindings depending on WITHCRYPTO. (km_get_table): Return OpPgp depending on WITHCRYPTO. * hook.c (mutt_parse_hook): Use WITHCRYPTO instead of ifdefs. (mutt_crypt_hook): Always include. * headers.c: Replaced pgp.h and smime.h header by crypt.h. (mutt_edit_headers): Use WITHCRYPTO instead of ifdefs * hdrline.c: Replaced pgp.h and smime.h header by crypt.h. (hdr_format_str): Use WITHCRYPTO. * handler.c: Replaced pgp.h and smime.h header by crypt.h. (mutt_can_decode): Use WITHCRYPTO instead of ifdefs. (mutt_can_decode): Application/smime is now also checked when PGP support is not configured. (mutt_body_handler): Use WITHCRYPTO * curs_main.c: Replaced pgp.h and smime.h header by crypt.h. (mutt_index_menu): Shortcut crypto only operations depending on WITHCRYPTO. * copy.c: Replaced pgp.h and smime.h header by crypt.h. (_mutt_copy_message): * compose.c: Replaced pgp.h and smime.h header by crypt.h. (enum): Always include HDR_CRYPT and HDR_CRYPTINFO. (redraw_crypt_lines): Always include this fnc but shortcut it depending on WITHCRYPT. Draw lines depending on the configured crypto support. (pgp_send_menu): Always include this one. Call wrapper functions. (smime_send_menu): Likewise. (draw_envelope): Use WITHCRYPTO instead of ifdefs. (mutt_compose_menu): Allow pgp/smime commands only when configured. * commands.c: Replaced pgp.h and smime.h header by crypt.h. (mutt_display_message,pipe_msg, _mutt_pipe_message) (set_copy_flags, mutt_save_message, mutt_edit_content_type) (_mutt_check_traditional_pgp): Use pgp wrapper. * attach.c (mutt_view_attachment): Removed HAVE_GPG and HAVE_SMIME and replaced by global variable WITHCRYPTO. Replaced pgp and smime header by crypt.h.x
Diffstat (limited to 'compose.c')
-rw-r--r--compose.c131
1 files changed, 54 insertions, 77 deletions
diff --git a/compose.c b/compose.c
index fe12d126..28d87a9c 100644
--- a/compose.c
+++ b/compose.c
@@ -58,10 +58,8 @@ enum
HDR_MIX,
#endif
-#if defined(HAVE_PGP) || defined(HAVE_SMIME)
HDR_CRYPT,
HDR_CRYPTINFO,
-#endif
HDR_ATTACH = (HDR_FCC + 5) /* where to start printing the attachments */
};
@@ -102,38 +100,27 @@ static void snd_entry (char *b, size_t blen, MUTTMENU *menu, int num)
-#ifdef HAVE_SMIME
-#include "smime.h"
-#endif
-
-#ifdef HAVE_PGP
-#include "pgp.h"
-#endif
-
-#if defined(HAVE_PGP) || defined(HAVE_SMIME)
+#include "mutt_crypt.h"
static void redraw_crypt_lines (HEADER *msg)
{
-#ifdef HAVE_SMIME
int off = 0;
-#endif
-#if defined(HAVE_PGP) && defined(HAVE_SMIME)
- if (!msg->security)
- mvaddstr (HDR_CRYPT, 0, "Security: ");
- else if (msg->security & APPLICATION_SMIME)
+ if ((WithCrypto & APPLICATION_PGP) && (WithCrypto & APPLICATION_SMIME))
+ {
+ if (!msg->security)
+ mvaddstr (HDR_CRYPT, 0, "Security: ");
+ else if (msg->security & APPLICATION_SMIME)
+ mvaddstr (HDR_CRYPT, 0, " S/MIME: ");
+ else if (msg->security & APPLICATION_PGP)
+ mvaddstr (HDR_CRYPT, 0, " PGP: ");
+ }
+ else if ((WithCrypto & APPLICATION_SMIME))
mvaddstr (HDR_CRYPT, 0, " S/MIME: ");
- else if (msg->security & APPLICATION_PGP)
+ else if ((WithCrypto & APPLICATION_PGP))
mvaddstr (HDR_CRYPT, 0, " PGP: ");
-#else
-#ifdef HAVE_SMIME
- mvaddstr (HDR_CRYPT, 0, " S/MIME: ");
-#endif
-#ifdef HAVE_PGP
- mvaddstr (HDR_CRYPT, 0, " PGP: ");
-#endif
-#endif
-
+ else
+ return;
if ((msg->security & (ENCRYPT | SIGN)) == (ENCRYPT | SIGN))
addstr (_("Sign, Encrypt"));
@@ -147,31 +134,33 @@ static void redraw_crypt_lines (HEADER *msg)
move (HDR_CRYPTINFO, 0);
clrtoeol ();
-#ifdef HAVE_PGP
- if (msg->security & APPLICATION_PGP && msg->security & SIGN)
+ if ((WithCrypto & APPLICATION_PGP)
+ && msg->security & APPLICATION_PGP && msg->security & SIGN)
printw ("%s%s", _(" sign as: "), PgpSignAs ? PgpSignAs : _("<default>"));
-#endif
-#ifdef HAVE_SMIME
- if (msg->security & APPLICATION_SMIME && msg->security & SIGN) {
+
+ if ((WithCrypto & APPLICATION_SMIME)
+ && msg->security & APPLICATION_SMIME && msg->security & SIGN) {
printw ("%s%s", _(" sign as: "), SmimeDefaultKey ? SmimeDefaultKey : _("<default>"));
}
- if (msg->security & APPLICATION_SMIME && (msg->security & ENCRYPT)) {
+
+ if ((WithCrypto & APPLICATION_SMIME)
+ && msg->security & APPLICATION_SMIME && (msg->security & ENCRYPT)) {
mvprintw (HDR_CRYPTINFO, 40, "%s%s", _("Encrypt with: "),
NONULL(SmimeCryptAlg));
off = 20;
}
-#endif
}
-#endif /* defined(HAVE_PGP) || defined(HAVE_SMIME) */
-#ifdef HAVE_PGP
static int pgp_send_menu (HEADER *msg, int *redraw)
{
- pgp_key_t *p;
+ pgp_key_t p;
char input_signas[SHORT_STRING];
+ if (!(WithCrypto & APPLICATION_PGP))
+ return msg->security;
+
switch (mutt_multi_choice (_("PGP (e)ncrypt, (s)ign, sign (a)s, (b)oth, or (f)orget it? "),
_("esabf")))
{
@@ -184,18 +173,19 @@ static int pgp_send_menu (HEADER *msg, int *redraw)
break;
case 3: /* sign (a)s */
-
unset_option(OPTPGPCHECKTRUST);
- if ((p = pgp_ask_for_key (_("Sign as: "), NULL, KEYFLAG_CANSIGN, PGP_PUBRING)))
+ if ((p = crypt_pgp_ask_for_key (_("Sign as: "), NULL,
+ KEYFLAG_CANSIGN, PGP_PUBRING)))
{
- snprintf (input_signas, sizeof (input_signas), "0x%s", pgp_keyid (p));
+ snprintf (input_signas, sizeof (input_signas), "0x%s",
+ crypt_pgp_keyid (p));
mutt_str_replace (&PgpSignAs, input_signas);
- pgp_free_key (&p);
+ crypt_pgp_free_key (&p);
msg->security |= PGPSIGN;
- pgp_void_passphrase (); /* probably need a different passphrase */
+ crypt_pgp_void_passphrase (); /* probably need a different passphrase */
}
else
{
@@ -218,15 +208,15 @@ static int pgp_send_menu (HEADER *msg, int *redraw)
redraw_crypt_lines (msg);
return (msg->security);
}
-#endif /* HAVE_PGP */
-
-#ifdef HAVE_SMIME
static int smime_send_menu (HEADER *msg, int *redraw)
{
- char *p;
+ char *p;
+
+ if (!(WithCrypto & APPLICATION_SMIME))
+ return msg->security;
switch (mutt_multi_choice (_("S/MIME (e)ncrypt, (s)ign, encrypt (w)ith, sign (a)s, (b)oth, or (f)orget it? "),
_("eswabf")))
@@ -270,14 +260,14 @@ static int smime_send_menu (HEADER *msg, int *redraw)
case 4: /* sign (a)s */
- if ((p = smime_ask_for_key (_("Sign as: "), NULL, 0))) {
+ if ((p = crypt_smime_ask_for_key (_("Sign as: "), NULL, 0))) {
p[mutt_strlen (p)-1] = '\0';
mutt_str_replace (&SmimeDefaultKey, p);
msg->security |= SMIMESIGN;
/* probably need a different passphrase */
- smime_void_passphrase ();
+ crypt_smime_void_passphrase ();
}
else
msg->security &= ~SMIMESIGN;
@@ -298,7 +288,7 @@ static int smime_send_menu (HEADER *msg, int *redraw)
redraw_crypt_lines (msg);
return (msg->security);
}
-#endif /* HAVE_SMIME */
+
#ifdef MIXMASTER
@@ -332,7 +322,7 @@ static void redraw_mix_line (LIST *chain)
c += mutt_strlen (t) + 2;
}
}
-#endif
+#endif /* MIXMASTER */
static int
check_attachments(ATTACHPTR **idx, short idxlen)
@@ -390,12 +380,8 @@ static void draw_envelope (HEADER *msg, char *fcc)
mvprintw (HDR_FCC, 0, TITLE_FMT, Prompts[HDR_FCC - 1]);
mutt_paddstr (W, fcc);
-
-
-#if defined(HAVE_PGP) || defined(HAVE_SMIME)
- redraw_crypt_lines (msg);
-#endif /* HAVE_PGP || HAVE_SMIE */
-
+ if (WithCrypto)
+ redraw_crypt_lines (msg);
#ifdef MIXMASTER
redraw_mix_line (msg->chain);
@@ -735,9 +721,9 @@ int mutt_compose_menu (HEADER *msg, /* structure for new message */
-#ifdef HAVE_PGP
case OP_COMPOSE_ATTACH_KEY:
-
+ if (!(WithCrypto & APPLICATION_PGP))
+ break;
if (idxlen == idxmax)
{
safe_realloc ((void **) &idx, sizeof (ATTACHPTR *) * (idxmax += 5));
@@ -745,7 +731,7 @@ int mutt_compose_menu (HEADER *msg, /* structure for new message */
}
idx[idxlen] = (ATTACHPTR *) safe_calloc (1, sizeof (ATTACHPTR));
- if ((idx[idxlen]->content = pgp_make_key_attachment(NULL)) != NULL)
+ if ((idx[idxlen]->content = crypt_pgp_make_key_attachment(NULL)) != NULL)
{
idx[idxlen]->level = (idxlen > 0) ? idx[idxlen-1]->level : 0;
@@ -769,8 +755,6 @@ int mutt_compose_menu (HEADER *msg, /* structure for new message */
}
break;
-#endif
-
case OP_COMPOSE_ATTACH_FILE:
@@ -1310,11 +1294,11 @@ int mutt_compose_menu (HEADER *msg, /* structure for new message */
-#ifdef HAVE_PGP
case OP_COMPOSE_PGP_MENU:
-
-#ifdef HAVE_SMIME
- if (msg->security & APPLICATION_SMIME)
+ if (!(WithCrypto & APPLICATION_PGP))
+ break;
+ if ((WithCrypto & APPLICATION_SMIME)
+ && msg->security & APPLICATION_SMIME)
{
if (mutt_yesorno (_("S/MIME already selected. Clear & continue ? "),
M_YES) == M_NO)
@@ -1324,27 +1308,22 @@ int mutt_compose_menu (HEADER *msg, /* structure for new message */
}
msg->security = 0;
}
-#endif /* HAVE_SMIME */
msg->security = pgp_send_menu (msg, &menu->redraw);
redraw_crypt_lines (msg);
break;
-#endif /* HAVE_PGP */
-#if defined(HAVE_PGP) || defined(HAVE_SMIME)
case OP_FORGET_PASSPHRASE:
-
crypt_forget_passphrase ();
break;
-#endif /* HAVE_(PGP||SMIME) */
-
-#ifdef HAVE_SMIME
case OP_COMPOSE_SMIME_MENU:
+ if (!(WithCrypto & APPLICATION_SMIME))
+ break;
-#ifdef HAVE_PGP
- if (msg->security & APPLICATION_PGP)
+ if ((WithCrypto & APPLICATION_PGP)
+ && msg->security & APPLICATION_PGP)
{
if (mutt_yesorno (_("PGP already selected. Clear & continue ? "),
M_YES) == M_NO)
@@ -1354,13 +1333,10 @@ int mutt_compose_menu (HEADER *msg, /* structure for new message */
}
msg->security = 0;
}
-#endif /* HAVE_pgp */
msg->security = smime_send_menu(msg, &menu->redraw);
redraw_crypt_lines (msg);
break;
-#endif /* HAVE_SMIME */
-
#ifdef MIXMASTER
case OP_COMPOSE_MIX:
@@ -1398,3 +1374,4 @@ int mutt_compose_menu (HEADER *msg, /* structure for new message */
return (r);
}
+