X-Git-Url: http://git.madism.org/?p=apps%2Fmadmutt.git;a=blobdiff_plain;f=lib-crypt%2Fpgp.c;h=297eb73764c12b24a4767ab32c2a12f9bdb6562c;hp=85725d7c749d1790ce9951bdf2ecd5fa9f2110df;hb=a4e6d1eb7521b75921259ae370607074dde0e765;hpb=3766db5f849cea008b1cd3d532c712aeb17aa062 diff --git a/lib-crypt/pgp.c b/lib-crypt/pgp.c index 85725d7..297eb73 100644 --- a/lib-crypt/pgp.c +++ b/lib-crypt/pgp.c @@ -130,7 +130,7 @@ static int pgp_copy_checksig (FILE * fpin, FILE * fpout) rv = 0; } - if (strncmp (line, "[GNUPG:] ", 9) == 0) + if (m_strncmp (line, "[GNUPG:] ", 9) == 0) continue; fputs (line, fpout); fputc ('\n', fpout); @@ -454,6 +454,7 @@ static int pgp_check_traditional_one_body (FILE * fp, BODY * b, char tempfile[_POSIX_PATH_MAX]; char buf[HUGE_STRING]; FILE *tfp; + int tempfd; short sgn = 0; short enc = 0; @@ -465,14 +466,14 @@ static int pgp_check_traditional_one_body (FILE * fp, BODY * b, if (tagged_only && !b->tagged) return 0; - mutt_mktemp (tempfile); - if (mutt_decode_save_attachment (fp, b, tempfile, 0, 0) != 0) { + tempfd = m_tempfd(tempfile, sizeof(tempfile), NONULL(Tempdir), NULL); + if (mutt_decode_save_attachment (fp, b, tempfd, 0) != 0) { unlink (tempfile); return 0; } - if ((tfp = fopen (tempfile, "r")) == NULL) { - unlink (tempfile); + if (!(tfp = fopen(tempfile, "r"))) { + unlink(tempfile); return 0; } @@ -545,7 +546,7 @@ int pgp_verify_one (BODY * sigbdy, STATE * s, const char *tempfile) fseeko (s->fpin, sigbdy->offset, 0); mutt_copy_bytes (s->fpin, fp, sigbdy->length); - fclose (fp); + m_fclose(&fp); pgperr = m_tempfile(pgperrfile, sizeof(pgperrfile), NONULL(Tempdir), NULL); if (pgperr == NULL) { @@ -595,7 +596,7 @@ static void pgp_extract_keys_from_attachment (FILE * fp, BODY * top) tempfp = m_tempfile(tempfname, sizeof(tempfname), NONULL(Tempdir), NULL); if (tempfp == NULL) { - mutt_perror (tempfname); + mutt_perror (_("Can't create temporary file")); return; } @@ -606,7 +607,7 @@ static void pgp_extract_keys_from_attachment (FILE * fp, BODY * top) mutt_body_handler (top, &s); - fclose (tempfp); + m_fclose(&tempfp); pgp_invoke_import (tempfname); mutt_any_key_to_continue (NULL); @@ -649,16 +650,16 @@ BODY *pgp_decrypt_part (BODY * a, STATE * s, FILE * fpout, BODY * p) int rv; pgperr = m_tempfile(pgperrfile, sizeof(pgperrfile), NONULL(Tempdir), NULL); - if (pgperr == NULL) { + if (!pgperr) { mutt_perror (pgperrfile); return NULL; } unlink (pgperrfile); pgptmp = m_tempfile(pgptmpfile, sizeof(pgptmpfile), NONULL(Tempdir), NULL); - if (pgptmp == NULL) { + if (!pgptmp) { mutt_perror (pgptmpfile); - fclose (pgperr); + m_fclose(&pgperr); return NULL; } @@ -668,11 +669,11 @@ BODY *pgp_decrypt_part (BODY * a, STATE * s, FILE * fpout, BODY * p) fseeko (s->fpin, a->offset, 0); mutt_copy_bytes (s->fpin, pgptmp, a->length); - fclose (pgptmp); + m_fclose(&pgptmp); if ((thepid = pgp_invoke_decrypt (&pgpin, &pgpout, NULL, -1, -1, fileno (pgperr), pgptmpfile)) == -1) { - fclose (pgperr); + m_fclose(&pgperr); unlink (pgptmpfile); if (s->flags & M_DISPLAY) state_attach_puts (_ @@ -687,7 +688,7 @@ BODY *pgp_decrypt_part (BODY * a, STATE * s, FILE * fpout, BODY * p) if (!pgp_use_gpg_agent ()) fputs (PgpPass, pgpin); fputc ('\n', pgpin); - fclose (pgpin); + m_fclose(&pgpin); /* Read the output from PGP, and make sure to change CRLF to LF, otherwise * read_mime_header has a hard time parsing the message. @@ -695,11 +696,11 @@ BODY *pgp_decrypt_part (BODY * a, STATE * s, FILE * fpout, BODY * p) while (fgets (buf, sizeof (buf) - 1, pgpout) != NULL) { len = m_strlen(buf); if (len > 1 && buf[len - 2] == '\r') - strcpy (buf + len - 2, "\n"); /* __STRCPY_CHECKED__ */ + m_strcpy(buf + len - 2, len - 2, "\n"); fputs (buf, fpout); } - fclose (pgpout); + m_fclose(&pgpout); rv = mutt_wait_filter (thepid); mutt_unlink (pgptmpfile); @@ -712,7 +713,7 @@ BODY *pgp_decrypt_part (BODY * a, STATE * s, FILE * fpout, BODY * p) p->goodsig = 0; state_attach_puts (_("[-- End of PGP output --]\n\n"), s); } - fclose (pgperr); + m_fclose(&pgperr); fflush (fpout); rewind (fpout); @@ -758,7 +759,7 @@ int pgp_decrypt_mime (FILE * fpin, FILE ** fpout, BODY * b, BODY ** cur) s.fpin = fpin; *fpout = m_tempfile(tempfile, sizeof(tempfile), NONULL(Tempdir), NULL); if (*fpout == NULL) { - mutt_perror (tempfile); + mutt_perror (_("Can't create temporary file")); return (-1); } unlink (tempfile); @@ -844,7 +845,7 @@ int pgp_encrypted_handler (BODY * a, STATE * s) rc = -1; } - fclose (fpout); + m_fclose(&fpout); mutt_unlink (tempfile); return (rc); @@ -875,7 +876,7 @@ BODY *pgp_sign_message (BODY * a) sfp = m_tempfile(signedfile, sizeof(signedfile), NONULL(Tempdir), NULL); if (sfp == NULL) { mutt_perror (signedfile); - fclose (fp); + m_fclose(&fp); unlink (sigfile); return NULL; } @@ -883,13 +884,13 @@ BODY *pgp_sign_message (BODY * a) mutt_write_mime_header (a, sfp); fputc ('\n', sfp); mutt_write_mime_body (a, sfp); - fclose (sfp); + m_fclose(&sfp); if ((thepid = pgp_invoke_sign (&pgpin, &pgpout, &pgperr, -1, -1, -1, signedfile)) == -1) { mutt_perror (_("Can't open PGP subprocess!")); - fclose (fp); + m_fclose(&fp); unlink (sigfile); unlink (signedfile); return NULL; @@ -898,7 +899,7 @@ BODY *pgp_sign_message (BODY * a) if (!pgp_use_gpg_agent ()) fputs (PgpPass, pgpin); fputc ('\n', pgpin); - fclose (pgpin); + m_fclose(&pgpin); /* * Read back the PGP signature. Also, change MESSAGE=>SIGNATURE as @@ -924,11 +925,11 @@ BODY *pgp_sign_message (BODY * a) if (mutt_wait_filter (thepid) && option (OPTPGPCHECKEXIT)) empty = 1; - fclose (pgperr); - fclose (pgpout); + m_fclose(&pgperr); + m_fclose(&pgpout); unlink (signedfile); - if (fclose (fp) != 0) { + if (m_fclose(&fp) != 0) { mutt_perror ("fclose"); unlink (sigfile); return (NULL); @@ -974,7 +975,7 @@ BODY *pgp_sign_message (BODY * a) static short is_numerical_keyid (const char *s) { /* or should we require the "0x"? */ - if (strncmp (s, "0x", 2) == 0) + if (m_strncmp (s, "0x", 2) == 0) s += 2; if (m_strlen(s) % 8) return 0; @@ -1022,8 +1023,7 @@ char *pgp_findKeys (address_t * to, address_t * cc, address_t * bcc) last = &((*last)->next); } - if (fqdn) - rfc822_qualify (tmp, fqdn); + rfc822_qualify (tmp, fqdn); address_list_uniq(tmp); @@ -1040,7 +1040,7 @@ char *pgp_findKeys (address_t * to, address_t * cc, address_t * bcc) p->mailbox); if ((r = mutt_yesorno (buf, M_YES)) == M_YES) { if (is_numerical_keyid (keyID)) { - if (strncmp (keyID, "0x", 2) == 0) + if (m_strncmp (keyID, "0x", 2) == 0) keyID += 2; goto bypass_selection; /* you don't see this. */ } @@ -1048,8 +1048,7 @@ char *pgp_findKeys (address_t * to, address_t * cc, address_t * bcc) /* check for e-mail address */ if ((t = strchr (keyID, '@')) && (addr = rfc822_parse_adrlist (NULL, keyID))) { - if (fqdn) - rfc822_qualify (addr, fqdn); + rfc822_qualify (addr, fqdn); q = addr; } else @@ -1087,7 +1086,7 @@ char *pgp_findKeys (address_t * to, address_t * cc, address_t * bcc) bypass_selection: keylist_size += m_strlen(keyID) + 4; p_realloc(&keylist, keylist_size); - sprintf (keylist + keylist_used, "%s0x%s", keylist_used ? " " : "", /* __SPRINTF_CHECKED__ */ + sprintf (keylist + keylist_used, "%s0x%s", keylist_used ? " " : "", keyID); keylist_used = m_strlen(keylist); @@ -1115,14 +1114,14 @@ BODY *pgp_encrypt_message (BODY * a, char *keylist, int sign) fpout = m_tempfile(tempfile, sizeof(tempfile), NONULL(Tempdir), NULL); if (fpout == NULL) { - mutt_perror (tempfile); + mutt_perror (_("Can't create temporary file")); return (NULL); } pgperr = m_tempfile(pgperrfile, sizeof(pgperrfile), NONULL(Tempdir), NULL); if (pgperr == NULL) { mutt_perror (pgperrfile); - fclose (fpout); + m_fclose(&fpout); unlink (tempfile); return NULL; } @@ -1131,9 +1130,9 @@ BODY *pgp_encrypt_message (BODY * a, char *keylist, int sign) fptmp = m_tempfile(pgpinfile, sizeof(pgpinfile), NONULL(Tempdir), NULL); if (fptmp == NULL) { mutt_perror (pgpinfile); - fclose (fpout); + m_fclose(&fpout); unlink (tempfile); - fclose (pgperr); + m_fclose(&pgperr); unlink (pgperrfile); return NULL; } @@ -1144,12 +1143,12 @@ BODY *pgp_encrypt_message (BODY * a, char *keylist, int sign) mutt_write_mime_header (a, fptmp); fputc ('\n', fptmp); mutt_write_mime_body (a, fptmp); - fclose (fptmp); + m_fclose(&fptmp); if ((thepid = pgp_invoke_encrypt (&pgpin, NULL, NULL, -1, fileno (fpout), fileno (pgperr), pgpinfile, keylist, sign)) == -1) { - fclose (pgperr); + m_fclose(&pgperr); unlink (pgpinfile); return (NULL); } @@ -1159,7 +1158,7 @@ BODY *pgp_encrypt_message (BODY * a, char *keylist, int sign) fputs (PgpPass, pgpin); fputc ('\n', pgpin); } - fclose (pgpin); + m_fclose(&pgpin); if (mutt_wait_filter (thepid) && option (OPTPGPCHECKEXIT)) empty = 1; @@ -1170,7 +1169,7 @@ BODY *pgp_encrypt_message (BODY * a, char *keylist, int sign) rewind (fpout); if (!empty) empty = (fgetc (fpout) == EOF); - fclose (fpout); + m_fclose(&fpout); fflush (pgperr); rewind (pgperr); @@ -1178,7 +1177,7 @@ BODY *pgp_encrypt_message (BODY * a, char *keylist, int sign) err = 1; fputs (buf, stdout); } - fclose (pgperr); + m_fclose(&pgperr); /* pause if there is any error output from PGP */ if (err) @@ -1255,7 +1254,7 @@ BODY *pgp_traditional_encryptsign (BODY * a, int flags, char *keylist) pgpin = m_tempfile(pgpinfile, sizeof(pgpinfile), NONULL(Tempdir), NULL); if (pgpin == NULL) { mutt_perror (pgpinfile); - fclose (fp); + m_fclose(&fp); return NULL; } @@ -1291,22 +1290,18 @@ BODY *pgp_traditional_encryptsign (BODY * a, int flags, char *keylist) mutt_copy_stream (fp, pgpin); } m_fclose(&fp); - fclose (pgpin); + m_fclose(&pgpin); 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); + m_fclose(&pgpin); unlink (pgpinfile); - if (pgpout) { - fclose (pgpout); - unlink (pgpoutfile); - } - if (pgperr) { - fclose(pgperr); - unlink(pgperrfile); - } + m_fclose(&pgpout); + unlink (pgpoutfile); + m_fclose(&pgperr); + unlink(pgperrfile); return NULL; } @@ -1317,8 +1312,8 @@ BODY *pgp_traditional_encryptsign (BODY * a, int flags, char *keylist) pgpinfile, keylist, flags)) == -1) { mutt_perror (_("Can't invoke PGP")); - fclose (pgpout); - fclose (pgperr); + m_fclose(&pgpout); + m_fclose(&pgperr); mutt_unlink (pgpinfile); unlink (pgpoutfile); return NULL; @@ -1328,7 +1323,7 @@ BODY *pgp_traditional_encryptsign (BODY * a, int flags, char *keylist) *PgpPass = 0; if (flags & SIGN) fprintf (pgpin, "%s\n", PgpPass); - fclose (pgpin); + m_fclose(&pgpin); if (mutt_wait_filter (thepid) && option (OPTPGPCHECKEXIT)) empty = 1; @@ -1343,7 +1338,7 @@ BODY *pgp_traditional_encryptsign (BODY * a, int flags, char *keylist) if (!empty) empty = (fgetc (pgpout) == EOF); - fclose (pgpout); + m_fclose(&pgpout); err = 0; @@ -1352,7 +1347,7 @@ BODY *pgp_traditional_encryptsign (BODY * a, int flags, char *keylist) fputs (buff, stdout); } - fclose (pgperr); + m_fclose(&pgperr); if (err) mutt_any_key_to_continue (NULL); @@ -1392,7 +1387,7 @@ BODY *pgp_traditional_encryptsign (BODY * a, int flags, char *keylist) int pgp_send_menu (HEADER * msg, int *redraw) { pgp_key_t p; - char input_signas[SHORT_STRING]; + char input_signas[STRING]; char prompt[LONG_STRING]; @@ -1430,11 +1425,6 @@ int pgp_send_menu (HEADER * msg, int *redraw) crypt_pgp_void_passphrase (); /* probably need a different passphrase */ } -#if 0 - else { - msg->security &= ~SIGN; - } -#endif *redraw = REDRAW_FULL; break;