X-Git-Url: http://git.madism.org/?a=blobdiff_plain;f=lib-crypt%2Fsmime.c;h=24ed09a765b28ee9e9e85a54863f84384bbdd0f4;hb=d8aeb41018aaf2f85fbd937278ffdd94164e236e;hp=3040268929f7c42e7c2c6315ad908c738d2d4043;hpb=4761fa78a6dfc9437caa6e6e0aac806e50e01c83;p=apps%2Fmadmutt.git diff --git a/lib-crypt/smime.c b/lib-crypt/smime.c index 3040268..24ed09a 100644 --- a/lib-crypt/smime.c +++ b/lib-crypt/smime.c @@ -9,46 +9,23 @@ * please see the file GPL in the top level source directory. */ -#if HAVE_CONFIG_H -# include "config.h" -#endif +#include -#include -#include -#include -#include +#ifdef HAVE_SYS_RESOURCE_H +# include +#endif #include +#include +#include +#include + #include "mutt.h" -#include "enter.h" +#include "alias.h" #include "handler.h" -#include "mutt_curses.h" -#include "mutt_menu.h" #include "copy.h" - -#include "lib/debug.h" - -#include -#include -#include -#include -#include -#include -#include - -#ifdef HAVE_LOCALE_H -#include -#endif - -#ifdef HAVE_SYS_TIME_H -# include -#endif - -#ifdef HAVE_SYS_RESOURCE_H -# include -#endif - +#include "alias.h" #include "crypt.h" struct smime_command_context { @@ -101,7 +78,7 @@ static char SmimeIntermediateToUse[_POSIX_PATH_MAX]; void smime_void_passphrase (void) { - p_clear(SmimePass, sizeof(SmimePass)); + p_clear(SmimePass, countof(SmimePass)); SmimeExptime = 0; } @@ -133,15 +110,11 @@ int smime_valid_passphrase (void) /* This is almost identical to ppgp's invoking interface. */ -static const char *_mutt_fmt_smime_command (char *dest, - size_t destlen, - char op, - const char *src, - const char *prefix, - const char *ifstring, - const char *elsestring, - unsigned long data, - format_flag flags) +static const char * +_mutt_fmt_smime_command (char *dest, ssize_t destlen, char op, + const char *src, const char *prefix, + const char *ifstring, const char *elsestring, + unsigned long data, format_flag flags) { char fmt[16]; struct smime_command_context *cctx = (struct smime_command_context *) data; @@ -255,13 +228,12 @@ static const char *_mutt_fmt_smime_command (char *dest, -static void mutt_smime_command (char *d, size_t dlen, +static void mutt_smime_command (char *d, ssize_t dlen, struct smime_command_context *cctx, const char *fmt) { mutt_FormatString (d, dlen, NONULL (fmt), _mutt_fmt_smime_command, (unsigned long) cctx, 0); - debug_print (2, ("%s\n", d)); } static pid_t smime_invoke (FILE ** smimein, FILE ** smimeout, @@ -308,7 +280,7 @@ static pid_t smime_invoke (FILE ** smimein, FILE ** smimeout, return certificate file name. */ -static void smime_entry (char *s, size_t l, MUTTMENU * menu, int num) +static void smime_entry (char *s, ssize_t l, MUTTMENU * menu, int num) { smime_id *Table = (smime_id *) menu->data; smime_id this = Table[num]; @@ -348,14 +320,15 @@ static void smime_entry (char *s, size_t l, MUTTMENU * menu, int num) -char *smime_ask_for_key (char *prompt, char *mailbox, short public) +char *smime_ask_for_key (char *prompt, char *mailbox __attribute__((unused)), + short public) { char *fname; smime_id *Table; long cert_num; /* Will contain the number of certificates. * To be able to get it, the .index file will be read twice... */ char index_file[_POSIX_PATH_MAX]; - FILE *index; + FILE *idx; char buf[LONG_STRING]; char fields[5][STRING]; int numFields, hash_suffix, done, cur; /* The current entry */ @@ -370,18 +343,18 @@ char *smime_ask_for_key (char *prompt, char *mailbox, short public) snprintf (index_file, sizeof (index_file), "%s/.index", public ? NONULL (SmimeCertificates) : NONULL (SmimeKeys)); - index = fopen (index_file, "r"); - if (index == NULL) { + idx = fopen (index_file, "r"); + if (idx == NULL) { mutt_perror (index_file); return NULL; } /* Count Lines */ cert_num = 0; - while (!feof (index)) { - if (fgets (buf, sizeof (buf), index)) + while (!feof (idx)) { + if (fgets (buf, sizeof (buf), idx)) cert_num++; } - fclose (index); + fclose (idx); for (;;) { *qry = 0; @@ -391,20 +364,20 @@ char *smime_ask_for_key (char *prompt, char *mailbox, short public) _("S/MIME certificates matching \"%s\"."), qry); - index = fopen (index_file, "r"); - if (index == NULL) { + idx = fopen (index_file, "r"); + if (idx == NULL) { mutt_perror (index_file); return NULL; } /* Read Entries */ cur = 0; Table = p_new(smime_id, cert_num); - while (!feof (index)) { + while (!feof (idx)) { numFields = - fscanf (index, MUTT_FORMAT (STRING) " %x.%i " MUTT_FORMAT (STRING), + fscanf (idx, MUTT_FORMAT (STRING) " %x.%i " MUTT_FORMAT (STRING), fields[0], &hash, &hash_suffix, fields[2]); if (public) - fscanf (index, MUTT_FORMAT (STRING) " " MUTT_FORMAT (STRING) "\n", + fscanf (idx, MUTT_FORMAT (STRING) " " MUTT_FORMAT (STRING) "\n", fields[3], fields[4]); /* 0=email 1=name 2=nick 3=intermediate 4=trust */ @@ -424,7 +397,7 @@ char *smime_ask_for_key (char *prompt, char *mailbox, short public) cur++; } - fclose (index); + fclose (idx); /* Make Helpstring */ helpstr[0] = 0; @@ -719,7 +692,7 @@ void smime_getkeys (ENVELOPE * env) } if (!found && (t = mutt_default_from ())) { _smime_getkeys (t->mailbox); - address_delete (&t); + address_list_wipe(&t); } } @@ -730,8 +703,8 @@ void smime_getkeys (ENVELOPE * env) char *smime_findKeys (address_t * to, address_t * cc, address_t * bcc) { char *keyID, *keylist = NULL; - size_t keylist_size = 0; - size_t keylist_used = 0; + ssize_t keylist_size = 0; + ssize_t keylist_used = 0; address_t *tmp = NULL, *addr = NULL; address_t **last = &tmp; address_t *p, *q; @@ -762,7 +735,7 @@ char *smime_findKeys (address_t * to, address_t * cc, address_t * bcc) if (fqdn) rfc822_qualify (tmp, fqdn); - tmp = mutt_remove_duplicates (tmp); + address_list_uniq(&tmp); for (p = tmp; p; p = p->next) { char buf[LONG_STRING]; @@ -776,8 +749,8 @@ char *smime_findKeys (address_t * to, address_t * cc, address_t * bcc) if (!keyID) { mutt_message (_("No (valid) certificate found for %s."), q->mailbox); p_delete(&keylist); - address_delete (&tmp); - address_delete (&addr); + address_list_wipe(&tmp); + address_list_wipe(&addr); return NULL; } @@ -786,10 +759,10 @@ char *smime_findKeys (address_t * to, address_t * cc, address_t * bcc) sprintf (keylist + keylist_used, "%s\n", keyID); /* __SPRINTF_CHECKED__ */ keylist_used = m_strlen(keylist); - address_delete (&addr); + address_list_wipe(&addr); } - address_delete (&tmp); + address_list_wipe(&tmp); return (keylist); } @@ -1055,7 +1028,7 @@ static char *smime_extract_signer_certificate (char *infile) /* Add a certificate and update index file (externally). */ -void smime_invoke_import (char *infile, char *mailbox) +void smime_invoke_import (char *infile, char *mailbox __attribute__ ((unused))) { char tmpfname[_POSIX_PATH_MAX], *certfile = NULL, buf[STRING]; FILE *smimein = NULL, *fpout = NULL, *fperr = NULL; @@ -1310,11 +1283,11 @@ BODY *smime_build_smime_entity (BODY * a, char *certlist) return (NULL); } - t = mutt_new_body (); + t = body_new(); t->type = TYPEAPPLICATION; t->subtype = m_strdup("x-pkcs7-mime"); - mutt_set_parameter ("name", "smime.p7m", &t->parameter); - mutt_set_parameter ("smime-type", "enveloped-data", &t->parameter); + parameter_setval(&t->parameter, "name", "smime.p7m"); + parameter_setval(&t->parameter, "smime-type", "enveloped-data"); t->encoding = ENCBASE64; /* The output of OpenSSL SHOULD be binary */ t->use_disp = 1; t->disposition = DISPATTACH; @@ -1426,23 +1399,23 @@ BODY *smime_sign_message (BODY * a) return (NULL); /* fatal error while signing */ } - t = mutt_new_body (); + t = body_new(); t->type = TYPEMULTIPART; t->subtype = m_strdup("signed"); t->encoding = ENC7BIT; t->use_disp = 0; t->disposition = DISPINLINE; - mutt_generate_boundary (&t->parameter); + parameter_set_boundary(&t->parameter); /* check if this can be extracted from private key somehow.... */ - mutt_set_parameter ("micalg", "sha1", &t->parameter); - mutt_set_parameter ("protocol", "application/x-pkcs7-signature", - &t->parameter); + parameter_setval(&t->parameter, "micalg", "sha1"); + parameter_setval(&t->parameter, "protocol", + "application/x-pkcs7-signature"); t->parts = a; a = t; - t->parts->next = mutt_new_body (); + t->parts->next = body_new(); t = t->parts->next; t->type = TYPEAPPLICATION; t->subtype = m_strdup("x-pkcs7-signature"); @@ -1458,19 +1431,11 @@ BODY *smime_sign_message (BODY * a) } - - - - /* * Handling S/MIME - bodies. */ - - - - static pid_t smime_invoke_verify (FILE ** smimein, FILE ** smimeout, FILE ** smimeerr, int smimeinfd, int smimeoutfd, @@ -1504,7 +1469,7 @@ int smime_verify_one (BODY * sigbdy, STATE * s, const char *tempfile) int badsig = -1; long tmpoffset = 0; - size_t tmplength = 0; + ssize_t tmplength = 0; int origType = sigbdy->type; char *savePrefix = NULL; @@ -1566,7 +1531,7 @@ int smime_verify_one (BODY * sigbdy, STATE * s, const char *tempfile) else { char *line = NULL; int lineno = 0; - size_t linelen; + ssize_t linelen; fflush (smimeerr); rewind (smimeerr); @@ -1781,7 +1746,7 @@ static BODY *smime_handle_entity (BODY * m, STATE * s, FILE * outFile) if (type & SIGNOPAQUE) { char *line = NULL; int lineno = 0; - size_t linelen; + ssize_t linelen; rewind (smimeerr); @@ -1810,7 +1775,7 @@ int smime_decrypt_mime (FILE * fpin, FILE ** fpout, BODY * b, BODY ** cur) char tempfile[_POSIX_PATH_MAX]; STATE s; long tmpoffset = b->offset; - size_t tmplength = b->length; + ssize_t tmplength = b->length; int origType = b->type; FILE *tmpfp = NULL; int rv = 0;