more constness.
[apps/madmutt.git] / smime.c
diff --git a/smime.c b/smime.c
index ece2fd8..cba7100 100644 (file)
--- a/smime.c
+++ b/smime.c
@@ -14,6 +14,8 @@
 #endif
 
 #include "mutt.h"
 #endif
 
 #include "mutt.h"
+#include "enter.h"
+#include "handler.h"
 #include "mutt_curses.h"
 #include "mutt_menu.h"
 #include "smime.h"
 #include "mutt_curses.h"
 #include "mutt_menu.h"
 #include "smime.h"
@@ -104,7 +106,7 @@ int smime_valid_passphrase (void)
 
   smime_void_passphrase ();
 
 
   smime_void_passphrase ();
 
-  if (mutt_get_field_unbuffered (_("Enter SMIME passphrase:"), SmimePass,
+  if (mutt_get_field_unbuffered (_("Enter S/MIME passphrase:"), SmimePass,
                                  sizeof (SmimePass), M_PASS) == 0) {
     SmimeExptime = time (NULL) + SmimeTimeout;
     return (1);
                                  sizeof (SmimePass), M_PASS) == 0) {
     SmimeExptime = time (NULL) + SmimeTimeout;
     return (1);
@@ -301,7 +303,7 @@ static void smime_entry (char *s, size_t l, MUTTMENU * menu, int num)
 {
   smime_id *Table = (smime_id *) menu->data;
   smime_id this = Table[num];
 {
   smime_id *Table = (smime_id *) menu->data;
   smime_id this = Table[num];
-  char *truststate;
+  const char *truststate;
 
   switch (this.trust) {
   case 't':
 
   switch (this.trust) {
   case 't':
@@ -387,7 +389,7 @@ char *smime_ask_for_key (char *prompt, char *mailbox, short public)
     }
     /* Read Entries */
     cur = 0;
     }
     /* Read Entries */
     cur = 0;
-    Table = safe_calloc (cert_num, sizeof (smime_id));
+    Table = mem_calloc (cert_num, sizeof (smime_id));
     while (!feof (index)) {
       numFields =
         fscanf (index, MUTT_FORMAT (STRING) " %x.%i " MUTT_FORMAT (STRING),
     while (!feof (index)) {
       numFields =
         fscanf (index, MUTT_FORMAT (STRING) " %x.%i " MUTT_FORMAT (STRING),
@@ -453,14 +455,14 @@ char *smime_ask_for_key (char *prompt, char *mailbox, short public)
       }
     }
     if (hash) {
       }
     }
     if (hash) {
-      fname = safe_malloc (13); /* Hash + '.' + Suffix + \0 */
+      fname = mem_malloc (13); /* Hash + '.' + Suffix + \0 */
       sprintf (fname, "%.8x.%i", Table[cur].hash, Table[cur].suffix);
     }
     else
       fname = NULL;
 
     mutt_menuDestroy (&menu);
       sprintf (fname, "%.8x.%i", Table[cur].hash, Table[cur].suffix);
     }
     else
       fname = NULL;
 
     mutt_menuDestroy (&menu);
-    FREE (&Table);
+    mem_free (&Table);
     set_option (OPTNEEDREDRAW);
 
     if (fname)
     set_option (OPTNEEDREDRAW);
 
     if (fname)
@@ -647,7 +649,7 @@ void _smime_getkeys (char *mailbox)
     /* the key used last time. */
     if (*SmimeKeyToUse &&
         !str_casecmp (k, SmimeKeyToUse + str_len (SmimeKeys) + 1)) {
     /* the key used last time. */
     if (*SmimeKeyToUse &&
         !str_casecmp (k, SmimeKeyToUse + str_len (SmimeKeys) + 1)) {
-      FREE (&k);
+      mem_free (&k);
       return;
     }
     else
       return;
     }
     else
@@ -662,7 +664,7 @@ void _smime_getkeys (char *mailbox)
     if (str_casecmp (k, SmimeDefaultKey))
       smime_void_passphrase ();
 
     if (str_casecmp (k, SmimeDefaultKey))
       smime_void_passphrase ();
 
-    FREE (&k);
+    mem_free (&k);
     return;
   }
 
     return;
   }
 
@@ -764,14 +766,14 @@ char *smime_findKeys (ADDRESS * to, ADDRESS * cc, ADDRESS * bcc)
     }
     if (!keyID) {
       mutt_message (_("No (valid) certificate found for %s."), q->mailbox);
     }
     if (!keyID) {
       mutt_message (_("No (valid) certificate found for %s."), q->mailbox);
-      FREE (&keylist);
+      mem_free (&keylist);
       rfc822_free_address (&tmp);
       rfc822_free_address (&addr);
       return NULL;
     }
 
     keylist_size += str_len (keyID) + 2;
       rfc822_free_address (&tmp);
       rfc822_free_address (&addr);
       return NULL;
     }
 
     keylist_size += str_len (keyID) + 2;
-    safe_realloc (&keylist, keylist_size);
+    mem_realloc (&keylist, keylist_size);
     sprintf (keylist + keylist_used, "%s\n", keyID);    /* __SPRINTF_CHECKED__ */
     keylist_used = str_len (keylist);
 
     sprintf (keylist + keylist_used, "%s\n", keyID);    /* __SPRINTF_CHECKED__ */
     keylist_used = str_len (keylist);
 
@@ -852,13 +854,13 @@ static int smime_handle_cert_email (char *certificate, char *mailbox,
 
   if (copy && buffer && num) {
     (*num) = count;
 
   if (copy && buffer && num) {
     (*num) = count;
-    *buffer = safe_calloc (sizeof (char *), count);
+    *buffer = mem_calloc (sizeof (char *), count);
     count = 0;
 
     rewind (fpout);
     while ((fgets (email, sizeof (email), fpout))) {
       *(email + str_len (email) - 1) = '\0';
     count = 0;
 
     rewind (fpout);
     while ((fgets (email, sizeof (email), fpout))) {
       *(email + str_len (email) - 1) = '\0';
-      (*buffer)[count] = safe_calloc (1, str_len (email) + 1);
+      (*buffer)[count] = mem_calloc (1, str_len (email) + 1);
       strncpy ((*buffer)[count], email, str_len (email));
       count++;
     }
       strncpy ((*buffer)[count], email, str_len (email));
       count++;
     }
@@ -1089,7 +1091,7 @@ void smime_invoke_import (char *infile, char *mailbox)
     mutt_wait_filter (thepid);
 
     mutt_unlink (certfile);
     mutt_wait_filter (thepid);
 
     mutt_unlink (certfile);
-    FREE (&certfile);
+    mem_free (&certfile);
   }
 
   fflush (fpout);
   }
 
   fflush (fpout);
@@ -1148,7 +1150,7 @@ int smime_verify_sender (HEADER * h)
       else
         retval = 0;
       mutt_unlink (certfile);
       else
         retval = 0;
       mutt_unlink (certfile);
-      FREE (&certfile);
+      mem_free (&certfile);
     }
     else
       mutt_any_key_to_continue (_("no certfile"));
     }
     else
       mutt_any_key_to_continue (_("no certfile"));
@@ -1521,7 +1523,7 @@ int smime_verify_one (BODY * sigbdy, STATE * s, const char *tempfile)
 
   mutt_decode_attachment (sigbdy, s);
 
 
   mutt_decode_attachment (sigbdy, s);
 
-  sigbdy->length = ftell (s->fpout);
+  sigbdy->length = ftello (s->fpout);
   sigbdy->offset = 0;
   fclose (s->fpout);
 
   sigbdy->offset = 0;
   fclose (s->fpout);
 
@@ -1565,7 +1567,7 @@ int smime_verify_one (BODY * sigbdy, STATE * s, const char *tempfile)
       if (linelen && !str_casecmp (line, "verification successful"))
         badsig = 0;
 
       if (linelen && !str_casecmp (line, "verification successful"))
         badsig = 0;
 
-      FREE (&line);
+      mem_free (&line);
     }
   }
 
     }
   }
 
@@ -1644,7 +1646,7 @@ static BODY *smime_handle_entity (BODY * m, STATE * s, FILE * outFile)
     return NULL;
   }
 
     return NULL;
   }
 
-  fseek (s->fpin, m->offset, 0);
+  fseeko (s->fpin, m->offset, 0);
   last_pos = m->offset;
 
   mutt_copy_bytes (s->fpin, tmpfp, m->length);
   last_pos = m->offset;
 
   mutt_copy_bytes (s->fpin, tmpfp, m->length);
@@ -1778,7 +1780,7 @@ static BODY *smime_handle_entity (BODY * m, STATE * s, FILE * outFile)
     line = mutt_read_line (line, &linelen, smimeerr, &lineno);
     if (linelen && !str_casecmp (line, "verification successful"))
       m->goodsig = 1;
     line = mutt_read_line (line, &linelen, smimeerr, &lineno);
     if (linelen && !str_casecmp (line, "verification successful"))
       m->goodsig = 1;
-    FREE (&line);
+    mem_free (&line);
   }
   else {
     m->goodsig = p->goodsig;
   }
   else {
     m->goodsig = p->goodsig;
@@ -1813,7 +1815,7 @@ int smime_decrypt_mime (FILE * fpin, FILE ** fpout, BODY * b, BODY ** cur)
 
   memset (&s, 0, sizeof (s));
   s.fpin = fpin;
 
   memset (&s, 0, sizeof (s));
   s.fpin = fpin;
-  fseek (s.fpin, b->offset, 0);
+  fseeko (s.fpin, b->offset, 0);
 
   mutt_mktemp (tempfile);
   if ((tmpfp = safe_fopen (tempfile, "w+")) == NULL) {
 
   mutt_mktemp (tempfile);
   if ((tmpfp = safe_fopen (tempfile, "w+")) == NULL) {
@@ -1825,7 +1827,7 @@ int smime_decrypt_mime (FILE * fpin, FILE ** fpout, BODY * b, BODY ** cur)
   s.fpout = tmpfp;
   mutt_decode_attachment (b, &s);
   fflush (tmpfp);
   s.fpout = tmpfp;
   mutt_decode_attachment (b, &s);
   fflush (tmpfp);
-  b->length = ftell (s.fpout);
+  b->length = ftello (s.fpout);
   b->offset = 0;
   rewind (tmpfp);
   s.fpin = tmpfp;
   b->offset = 0;
   rewind (tmpfp);
   s.fpin = tmpfp;
@@ -1859,11 +1861,9 @@ bail:
 }
 
 
 }
 
 
-void smime_application_smime_handler (BODY * m, STATE * s)
+int smime_application_smime_handler (BODY * m, STATE * s)
 {
 {
-
-  smime_handle_entity (m, s, NULL);
-
+  return smime_handle_entity (m, s, NULL) ? 0 : -1;
 }
 
 int smime_send_menu (HEADER * msg, int *redraw)
 }
 
 int smime_send_menu (HEADER * msg, int *redraw)
@@ -1883,27 +1883,65 @@ int smime_send_menu (HEADER * msg, int *redraw)
     break;
 
   case 3:                      /* encrypt (w)ith */
     break;
 
   case 3:                      /* encrypt (w)ith */
-    msg->security |= ENCRYPT;
-    switch (mutt_multi_choice (_("1: DES, 2: Triple-DES, 3: RC2-40,"
-                                 " 4: RC2-64, 5: RC2-128, or (f)orget it? "),
-                               _("12345f"))) {
-    case 1:
-      str_replace (&SmimeCryptAlg, "des");
-      break;
-    case 2:
-      str_replace (&SmimeCryptAlg, "des3");
-      break;
-    case 3:
-      str_replace (&SmimeCryptAlg, "rc2-40");
-      break;
-    case 4:
-      str_replace (&SmimeCryptAlg, "rc2-64");
-      break;
-    case 5:
-      str_replace (&SmimeCryptAlg, "rc2-128");
-      break;
-    case 6:                    /* forget it */
-      break;
+    {
+      int choice = 0;
+      msg->security |= ENCRYPT;
+
+      do {
+        /* I use "dra" because "123" is recognized anyway */
+        switch (mutt_multi_choice (_("Choose algorithm family:"
+                                     " 1: DES, 2: RC2, 3: AES,"
+                                     " or (c)lear? "), _("drac"))) {
+          case 1:
+            switch (choice = mutt_multi_choice (_("1: DES, 2: Triple-DES "),
+                                                _("dt"))) {
+              case 1:
+                str_replace (&SmimeCryptAlg, "des");
+                break;
+              case 2:
+                str_replace (&SmimeCryptAlg, "des3");
+                break;
+            }
+            break;
+
+          case 2:
+            switch (choice = mutt_multi_choice (_("1: RC2-40, 2: RC2-64, 3: RC2-128 "),
+                                                _("468"))) {
+              case 1:
+                str_replace (&SmimeCryptAlg, "rc2-40");
+                break;
+              case 2:
+                str_replace (&SmimeCryptAlg, "rc2-64");
+                break;
+              case 3:
+                str_replace (&SmimeCryptAlg, "rc2-128");
+                break;
+            }
+            break;
+
+          case 3:
+            switch (choice = mutt_multi_choice (_("1: AES128, 2: AES192, 3: AES256 "),
+                                                _("895"))) {
+              case 1:
+                str_replace (&SmimeCryptAlg, "aes128");
+                break;
+              case 2:
+                str_replace (&SmimeCryptAlg, "aes192");
+                break;
+              case 3:
+                str_replace (&SmimeCryptAlg, "aes256");
+                break;
+            }
+            break;
+
+          case 4: /* (c)lear */
+            mem_free (&SmimeCryptAlg);
+            /* fallback */
+          case -1: /* Ctrl-G or Enter */
+            choice = 0;
+            break;
+        }
+      } while (choice == -1);
     }
     break;
 
     }
     break;
 
@@ -1921,7 +1959,6 @@ int smime_send_menu (HEADER * msg, int *redraw)
   case 4:                      /* sign (a)s */
 
     if ((p = smime_ask_for_key (_("Sign as: "), NULL, 0))) {
   case 4:                      /* sign (a)s */
 
     if ((p = smime_ask_for_key (_("Sign as: "), NULL, 0))) {
-      p[str_len (p) - 1] = '\0';
       str_replace (&SmimeDefaultKey, p);
 
       msg->security |= SIGN;
       str_replace (&SmimeDefaultKey, p);
 
       msg->security |= SIGN;