X-Git-Url: http://git.madism.org/?p=apps%2Fmadmutt.git;a=blobdiff_plain;f=lib-crypt%2Fpgp.c;h=8b53ffa6988bb4ae5b0c5f2f887779bf2c186b8a;hp=1cbcc6f842e7784bf5a5bfcf8e1b90094dc14118;hb=011e430fa558910ad28eb49937c328602dadb198;hpb=69f4685e616347559d4ec714fd826d7f97a472ef diff --git a/lib-crypt/pgp.c b/lib-crypt/pgp.c index 1cbcc6f..8b53ffa 100644 --- a/lib-crypt/pgp.c +++ b/lib-crypt/pgp.c @@ -17,49 +17,25 @@ * a message. */ -#if HAVE_CONFIG_H -# include "config.h" -#endif +#include -#include -#include -#include -#include -#include +#ifdef HAVE_SYS_RESOURCE_H +# include +#endif #include +#include #include #include #include +#include -#include "mutt.h" #include "handler.h" #include "pgp.h" #include "copy.h" #include "attach.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 "crypt.h" @@ -290,8 +266,8 @@ int pgp_application_pgp_handler (BODY * m, STATE * s) have_any_sigs = have_any_sigs || (clearsign && (s->flags & M_VERIFY)); /* Copy PGP material to temporary file */ - mutt_mktemp (tmpfname); - if ((tmpfp = safe_fopen (tmpfname, "w+")) == NULL) { + tmpfp = m_tempfile(tmpfname, sizeof(tmpfname), NONULL(Tempdir), NULL); + if (tmpfp == NULL) { mutt_perror (tmpfname); return (-1); } @@ -319,9 +295,9 @@ int pgp_application_pgp_handler (BODY * m, STATE * s) /* Invoke PGP if needed */ if (!clearsign || (s->flags & M_VERIFY)) { - mutt_mktemp (outfile); - if ((pgpout = safe_fopen (outfile, "w+")) == NULL) { - mutt_perror (tmpfname); + pgpout = m_tempfile(outfile, sizeof(outfile), NONULL(Tempdir), NULL); + if (pgpout == NULL) { + mutt_perror (outfile); return (-1); } @@ -571,8 +547,8 @@ int pgp_verify_one (BODY * sigbdy, STATE * s, const char *tempfile) mutt_copy_bytes (s->fpin, fp, sigbdy->length); fclose (fp); - mutt_mktemp (pgperrfile); - if (!(pgperr = safe_fopen (pgperrfile, "w+"))) { + pgperr = m_tempfile(pgperrfile, sizeof(pgperrfile), NONULL(Tempdir), NULL); + if (pgperr == NULL) { mutt_perror (pgperrfile); unlink (sigfile); return -1; @@ -611,69 +587,14 @@ int pgp_verify_one (BODY * sigbdy, STATE * s, const char *tempfile) /* Extract pgp public keys from messages or attachments */ -void pgp_extract_keys_from_messages (HEADER * h) -{ - int i; - char tempfname[_POSIX_PATH_MAX]; - FILE *fpout; - - if (h) { - mutt_parse_mime_message (Context, h); - if (h->security & PGPENCRYPT && !pgp_valid_passphrase ()) - return; - } - - mutt_mktemp (tempfname); - if (!(fpout = safe_fopen (tempfname, "w"))) { - mutt_perror (tempfname); - return; - } - - set_option (OPTDONTHANDLEPGPKEYS); - - if (!h) { - for (i = 0; i < Context->vcount; i++) { - if (Context->hdrs[Context->v2r[i]]->tagged) { - mutt_parse_mime_message (Context, Context->hdrs[Context->v2r[i]]); - if (Context->hdrs[Context->v2r[i]]->security & PGPENCRYPT - && !pgp_valid_passphrase ()) { - fclose (fpout); - goto bailout; - } - mutt_copy_message (fpout, Context, Context->hdrs[Context->v2r[i]], - M_CM_DECODE | M_CM_CHARCONV, 0); - } - } - } - else { - mutt_parse_mime_message (Context, h); - if (h->security & PGPENCRYPT && !pgp_valid_passphrase ()) { - fclose (fpout); - goto bailout; - } - mutt_copy_message (fpout, Context, h, M_CM_DECODE | M_CM_CHARCONV, 0); - } - - fclose (fpout); - mutt_endwin (NULL); - pgp_invoke_import (tempfname); - mutt_any_key_to_continue (NULL); - -bailout: - - mutt_unlink (tempfname); - unset_option (OPTDONTHANDLEPGPKEYS); - -} - static void pgp_extract_keys_from_attachment (FILE * fp, BODY * top) { STATE s; FILE *tempfp; char tempfname[_POSIX_PATH_MAX]; - mutt_mktemp (tempfname); - if (!(tempfp = safe_fopen (tempfname, "w"))) { + tempfp = m_tempfile(tempfname, sizeof(tempfname), NONULL(Tempdir), NULL); + if (tempfp == NULL) { mutt_perror (tempfname); return; } @@ -727,15 +648,15 @@ BODY *pgp_decrypt_part (BODY * a, STATE * s, FILE * fpout, BODY * p) pid_t thepid; int rv; - mutt_mktemp (pgperrfile); - if ((pgperr = safe_fopen (pgperrfile, "w+")) == NULL) { + pgperr = m_tempfile(pgperrfile, sizeof(pgperrfile), NONULL(Tempdir), NULL); + if (pgperr == NULL) { mutt_perror (pgperrfile); return NULL; } unlink (pgperrfile); - mutt_mktemp (pgptmpfile); - if ((pgptmp = safe_fopen (pgptmpfile, "w")) == NULL) { + pgptmp = m_tempfile(pgptmpfile, sizeof(pgptmpfile), NONULL(Tempdir), NULL); + if (pgptmp == NULL) { mutt_perror (pgptmpfile); fclose (pgperr); return NULL; @@ -835,8 +756,8 @@ int pgp_decrypt_mime (FILE * fpin, FILE ** fpout, BODY * b, BODY ** cur) p_clear(&s, 1); s.fpin = fpin; - mutt_mktemp (tempfile); - if ((*fpout = safe_fopen (tempfile, "w+")) == NULL) { + *fpout = m_tempfile(tempfile, sizeof(tempfile), NONULL(Tempdir), NULL); + if (*fpout == NULL) { mutt_perror (tempfile); return (-1); } @@ -876,8 +797,8 @@ int pgp_encrypted_handler (BODY * a, STATE * s) */ a = a->next; - mutt_mktemp (tempfile); - if ((fpout = safe_fopen (tempfile, "w+")) == NULL) { + fpout = m_tempfile(tempfile, sizeof(tempfile), NONULL(Tempdir), NULL); + if (fpout == NULL) { if (s->flags & M_DISPLAY) state_attach_puts (_ ("[-- Error: could not create temporary file! --]\n"), @@ -914,7 +835,7 @@ int pgp_encrypted_handler (BODY * a, STATE * s) state_attach_puts (_("[-- End of PGP/MIME encrypted data --]\n"), s); } - mutt_free_body (&tattach); + body_list_wipe(&tattach); /* clear 'Invoking...' message, since there's no error */ mutt_message _("PGP message successfully decrypted."); } else { @@ -946,13 +867,13 @@ BODY *pgp_sign_message (BODY * a) convert_to_7bit (a); /* Signed data _must_ be in 7-bit format. */ - mutt_mktemp (sigfile); - if ((fp = safe_fopen (sigfile, "w")) == NULL) { + fp = m_tempfile(sigfile, sizeof(sigfile), NONULL(Tempdir), NULL); + if (fp == NULL) { return (NULL); } - mutt_mktemp (signedfile); - if ((sfp = safe_fopen (signedfile, "w")) == NULL) { + sfp = m_tempfile(signedfile, sizeof(signedfile), NONULL(Tempdir), NULL); + if (sfp == NULL) { mutt_perror (signedfile); fclose (fp); unlink (sigfile); @@ -1023,7 +944,7 @@ BODY *pgp_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; @@ -1037,7 +958,7 @@ BODY *pgp_sign_message (BODY * a) 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("pgp-signature"); @@ -1069,7 +990,8 @@ static short is_numerical_keyid (const char *s) */ char *pgp_findKeys (address_t * to, address_t * cc, address_t * bcc) { - char *keyID, *keylist = NULL, *t; + char *keylist = NULL, *t; + const char *keyID; size_t keylist_size = 0; size_t keylist_used = 0; address_t *tmp = NULL, *addr = NULL; @@ -1103,7 +1025,7 @@ char *pgp_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]; @@ -1191,27 +1113,28 @@ BODY *pgp_encrypt_message (BODY * a, char *keylist, int sign) int empty = 0; pid_t thepid; - mutt_mktemp (tempfile); - if ((fpout = safe_fopen (tempfile, "w+")) == NULL) { + fpout = m_tempfile(tempfile, sizeof(tempfile), NONULL(Tempdir), NULL); + if (fpout == NULL) { mutt_perror (tempfile); return (NULL); } - mutt_mktemp (pgperrfile); - if ((pgperr = safe_fopen (pgperrfile, "w+")) == NULL) { + pgperr = m_tempfile(pgperrfile, sizeof(pgperrfile), NONULL(Tempdir), NULL); + if (pgperr == NULL) { mutt_perror (pgperrfile); - unlink (tempfile); fclose (fpout); + unlink (tempfile); return NULL; } unlink (pgperrfile); - mutt_mktemp (pgpinfile); - if ((fptmp = safe_fopen (pgpinfile, "w")) == NULL) { + fptmp = m_tempfile(pgpinfile, sizeof(pgpinfile), NONULL(Tempdir), NULL); + if (fptmp == NULL) { mutt_perror (pgpinfile); - unlink (tempfile); fclose (fpout); + unlink (tempfile); fclose (pgperr); + unlink (pgperrfile); return NULL; } @@ -1269,7 +1192,7 @@ BODY *pgp_encrypt_message (BODY * a, char *keylist, int sign) return (NULL); } - t = mutt_new_body (); + t = body_new(); t->type = TYPEMULTIPART; t->subtype = m_strdup("encrypted"); t->encoding = ENC7BIT; @@ -1279,12 +1202,12 @@ BODY *pgp_encrypt_message (BODY * a, char *keylist, int sign) parameter_set_boundary(&t->parameter); parameter_setval(&t->parameter, "protocol", "application/pgp-encrypted"); - t->parts = mutt_new_body (); + t->parts = body_new(); t->parts->type = TYPEAPPLICATION; t->parts->subtype = m_strdup("pgp-encrypted"); t->parts->encoding = ENC7BIT; - t->parts->next = mutt_new_body (); + t->parts->next = body_new(); t->parts->next->type = TYPEAPPLICATION; t->parts->next->subtype = m_strdup("octet-stream"); t->parts->next->encoding = ENC7BIT; @@ -1329,8 +1252,8 @@ BODY *pgp_traditional_encryptsign (BODY * a, int flags, char *keylist) return NULL; } - mutt_mktemp (pgpinfile); - if ((pgpin = safe_fopen (pgpinfile, "w")) == NULL) { + pgpin = m_tempfile(pgpinfile, sizeof(pgpinfile), NONULL(Tempdir), NULL); + if (pgpin == NULL) { mutt_perror (pgpinfile); fclose (fp); return NULL; @@ -1370,11 +1293,11 @@ BODY *pgp_traditional_encryptsign (BODY * a, int flags, char *keylist) safe_fclose (&fp); fclose (pgpin); - mutt_mktemp (pgpoutfile); - mutt_mktemp (pgperrfile); - if ((pgpout = safe_fopen (pgpoutfile, "w+")) == NULL || - (pgperr = safe_fopen (pgperrfile, "w+")) == NULL) { + pgpout = m_tempfile(pgpoutfile, sizeof(pgpoutfile), NONULL(Tempdir), NULL); + pgperr = m_tempfile(pgperrfile, sizeof(pgperrfile), NONULL(Tempdir), NULL); + if (pgpout == NULL || pgperr == NULL) { mutt_perror (pgpout ? pgperrfile : pgpoutfile); + fclose (pgpin); unlink (pgpinfile); if (pgpout) { fclose (pgpout); @@ -1437,7 +1360,7 @@ BODY *pgp_traditional_encryptsign (BODY * a, int flags, char *keylist) return NULL; } - b = mutt_new_body (); + b = body_new(); b->encoding = ENC7BIT;