X-Git-Url: http://git.madism.org/?p=apps%2Fmadmutt.git;a=blobdiff_plain;f=smime.c;h=102732f130942c6e77f438ea64f50acb126ceb12;hp=1f2522232713ee7cadafec885405e7b1c3117672;hb=debd2491451020d9fd5f0440bb2dada0b9eac6e7;hpb=df70e07e24add1869bcc9b7af2277d9d0c09a281 diff --git a/smime.c b/smime.c index 1f25222..102732f 100644 --- a/smime.c +++ b/smime.c @@ -1,21 +1,12 @@ /* + * Copyright notice from original mutt: * Copyright (C) 2001,2002 Oliver Ehli * Copyright (C) 2002 Mike Schiraldi * Copyright (C) 2004 g10 Code GmbH * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA. + * This file is part of mutt-ng, see http://www.muttng.org/. + * It's licensed under the GNU General Public License, + * please see the file GPL in the top level source directory. */ #if HAVE_CONFIG_H @@ -29,6 +20,11 @@ #include "mime.h" #include "copy.h" +#include "lib/mem.h" +#include "lib/intl.h" +#include "lib/str.h" +#include "lib/debug.h" + #include #include #include @@ -254,12 +250,9 @@ static void mutt_smime_command (char *d, size_t dlen, { mutt_FormatString (d, dlen, NONULL (fmt), _mutt_fmt_smime_command, (unsigned long) cctx, 0); - dprint (2, (debugfile, "mutt_smime_command: %s\n", d)); + debug_print (2, ("%s\n", d)); } - - - static pid_t smime_invoke (FILE ** smimein, FILE ** smimeout, FILE ** smimeerr, int smimeinfd, int smimeoutfd, int smimeerrfd, const char *fname, @@ -408,7 +401,7 @@ char *smime_ask_for_key (char *prompt, char *mailbox, short public) continue; /* Check if query matches this certificate */ - if (!mutt_stristr (fields[0], qry) && !mutt_stristr (fields[2], qry)) + if (!str_isstr (fields[0], qry) && !str_isstr (fields[2], qry)) continue; Table[cur].hash = hash; @@ -516,7 +509,7 @@ char *smime_get_field_from_db (char *mailbox, char *query, short public, } while (fgets (buf, sizeof (buf) - 1, fp) != NULL) - if (mailbox && !(mutt_strncasecmp (mailbox, buf, addr_len))) { + if (mailbox && !(safe_strncasecmp (mailbox, buf, addr_len))) { numFields = sscanf (buf, MUTT_FORMAT (STRING) " " MUTT_FORMAT (STRING) " " MUTT_FORMAT (STRING) " " MUTT_FORMAT (STRING) " " @@ -578,13 +571,13 @@ char *smime_get_field_from_db (char *mailbox, char *query, short public, /* query = label: return certificate. */ if (numFields >= 3 && - !(mutt_strncasecmp (query, fields[2], query_len))) { + !(safe_strncasecmp (query, fields[2], query_len))) { ask = 0; strfcpy (key, fields[1], sizeof (key)); } /* query = certificate: return intermediate certificate. */ else if (numFields >= 4 && - !(mutt_strncasecmp (query, fields[1], query_len))) { + !(safe_strncasecmp (query, fields[1], query_len))) { ask = 0; strfcpy (key, fields[3], sizeof (key)); } @@ -653,7 +646,7 @@ void _smime_getkeys (char *mailbox) if (k) { /* the key used last time. */ if (*SmimeKeyToUse && - !mutt_strcasecmp (k, SmimeKeyToUse + mutt_strlen (SmimeKeys) + 1)) { + !safe_strcasecmp (k, SmimeKeyToUse + mutt_strlen (SmimeKeys) + 1)) { FREE (&k); return; } @@ -666,7 +659,7 @@ void _smime_getkeys (char *mailbox) snprintf (SmimeCertToUse, sizeof (SmimeCertToUse), "%s/%s", NONULL (SmimeCertificates), k); - if (mutt_strcasecmp (k, SmimeDefaultKey)) + if (safe_strcasecmp (k, SmimeDefaultKey)) smime_void_passphrase (); FREE (&k); @@ -674,7 +667,7 @@ void _smime_getkeys (char *mailbox) } if (*SmimeKeyToUse) { - if (!mutt_strcasecmp (SmimeDefaultKey, + if (!safe_strcasecmp (SmimeDefaultKey, SmimeKeyToUse + mutt_strlen (SmimeKeys) + 1)) return; @@ -838,7 +831,7 @@ static int smime_handle_cert_email (char *certificate, char *mailbox, while ((fgets (email, sizeof (email), fpout))) { *(email + mutt_strlen (email) - 1) = '\0'; - if (mutt_strncasecmp (email, mailbox, mutt_strlen (mailbox)) == 0) + if (safe_strncasecmp (email, mailbox, mutt_strlen (mailbox)) == 0) ret = 1; ret = ret < 0 ? 0 : ret; @@ -1380,7 +1373,7 @@ BODY *smime_sign_message (BODY * a) if ((thepid = smime_invoke_sign (&smimein, NULL, &smimeerr, -1, fileno (smimeout), -1, filetosign)) == -1) { - mutt_perror _("Can't open OpenSSL subprocess!"); + mutt_perror (_("Can't open OpenSSL subprocess!")); fclose (smimeout); mutt_unlink (signedfile); @@ -1569,7 +1562,7 @@ int smime_verify_one (BODY * sigbdy, STATE * s, const char *tempfile) rewind (smimeerr); line = mutt_read_line (line, &linelen, smimeerr, &lineno); - if (linelen && !mutt_strcasecmp (line, "verification successful")) + if (linelen && !safe_strcasecmp (line, "verification successful")) badsig = 0; FREE (&line); @@ -1666,9 +1659,8 @@ static BODY *smime_handle_entity (BODY * m, STATE * s, FILE * outFile) fclose (smimeout); smimeout = NULL; mutt_unlink (tmpfname); - state_attach_puts (_ - ("[-- Error: unable to create OpenSSL subprocess! --]\n"), - s); + if (s->flags & M_DISPLAY) + state_attach_puts (_("[-- Error: unable to create OpenSSL subprocess! --]\n"), s); return NULL; } else if ((type & SIGNOPAQUE) && @@ -1679,9 +1671,8 @@ static BODY *smime_handle_entity (BODY * m, STATE * s, FILE * outFile) fclose (smimeout); smimeout = NULL; mutt_unlink (tmpfname); - state_attach_puts (_ - ("[-- Error: unable to create OpenSSL subprocess! --]\n"), - s); + if (s->flags & M_DISPLAY) + state_attach_puts (_("[-- Error: unable to create OpenSSL subprocess! --]\n"), s); return NULL; } @@ -1785,7 +1776,7 @@ static BODY *smime_handle_entity (BODY * m, STATE * s, FILE * outFile) rewind (smimeerr); line = mutt_read_line (line, &linelen, smimeerr, &lineno); - if (linelen && !mutt_strcasecmp (line, "verification successful")) + if (linelen && !safe_strcasecmp (line, "verification successful")) m->goodsig = 1; FREE (&line); } @@ -1812,6 +1803,7 @@ int smime_decrypt_mime (FILE * fpin, FILE ** fpout, BODY * b, BODY ** cur) size_t tmplength = b->length; int origType = b->type; FILE *tmpfp = NULL; + int rv = 0; if (!mutt_is_application_smime (b)) return -1; @@ -1842,21 +1834,28 @@ int smime_decrypt_mime (FILE * fpin, FILE ** fpout, BODY * b, BODY ** cur) mutt_mktemp (tempfile); if ((*fpout = safe_fopen (tempfile, "w+")) == NULL) { mutt_perror (tempfile); - return (-1); + rv = -1; + goto bail; } mutt_unlink (tempfile); - *cur = smime_handle_entity (b, &s, *fpout); + if (!(*cur = smime_handle_entity (b, &s, *fpout))) { + rv = -1; + goto bail; + } + (*cur)->goodsig = b->goodsig; - (*cur)->badsig = b->badsig; + (*cur)->badsig = b->badsig; + +bail: b->type = origType; b->length = tmplength; b->offset = tmpoffset; - fclose (tmpfp); - - rewind (*fpout); - return (0); + safe_fclose (&tmpfp); + if (*fpout) + rewind (*fpout); + return (rv); } @@ -1889,19 +1888,19 @@ int smime_send_menu (HEADER * msg, int *redraw) " 4: RC2-64, 5: RC2-128, or (f)orget it? "), _("12345f"))) { case 1: - mutt_str_replace (&SmimeCryptAlg, "des"); + str_replace (&SmimeCryptAlg, "des"); break; case 2: - mutt_str_replace (&SmimeCryptAlg, "des3"); + str_replace (&SmimeCryptAlg, "des3"); break; case 3: - mutt_str_replace (&SmimeCryptAlg, "rc2-40"); + str_replace (&SmimeCryptAlg, "rc2-40"); break; case 4: - mutt_str_replace (&SmimeCryptAlg, "rc2-64"); + str_replace (&SmimeCryptAlg, "rc2-64"); break; case 5: - mutt_str_replace (&SmimeCryptAlg, "rc2-128"); + str_replace (&SmimeCryptAlg, "rc2-128"); break; case 6: /* forget it */ break; @@ -1923,7 +1922,7 @@ int smime_send_menu (HEADER * msg, int *redraw) if ((p = smime_ask_for_key (_("Sign as: "), NULL, 0))) { p[mutt_strlen (p) - 1] = '\0'; - mutt_str_replace (&SmimeDefaultKey, p); + str_replace (&SmimeDefaultKey, p); msg->security |= SIGN;