projects
/
apps
/
madmutt.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Clean up code and use m_tempfile instead of mutt_mktemp
[apps/madmutt.git]
/
lib-crypt
/
smime.c
diff --git
a/lib-crypt/smime.c
b/lib-crypt/smime.c
index
479fd8c
..
0cc5cbc
100644
(file)
--- a/
lib-crypt/smime.c
+++ b/
lib-crypt/smime.c
@@
-778,15
+778,15
@@
static int smime_handle_cert_email (char *certificate, char *mailbox,
int ret = -1, count = 0;
pid_t thepid;
int ret = -1, count = 0;
pid_t thepid;
-
mutt_mktemp (tmpfname
);
- if (
(fperr = safe_fopen (tmpfname, "w+")) == NULL
) {
+
fperr = m_tempfile (tmpfname, sizeof(tmpfname), NONULL(Tempdir), NULL
);
+ if (
!fperr
) {
mutt_perror (tmpfname);
return 1;
}
mutt_unlink (tmpfname);
mutt_perror (tmpfname);
return 1;
}
mutt_unlink (tmpfname);
-
mutt_mktemp (tmpfname
);
- if (
(fpout = safe_fopen (tmpfname, "w+")) == NULL
) {
+
fpout = m_tempfile (tmpfname, sizeof(tmpfname), NONULL(Tempdir), NULL
);
+ if (
!fpout
) {
fclose (fperr);
mutt_perror (tmpfname);
return 1;
fclose (fperr);
mutt_perror (tmpfname);
return 1;
@@
-864,15
+864,15
@@
static char *smime_extract_certificate (char *infile)
int empty;
int empty;
-
mutt_mktemp (tmpfname
);
- if (
(fperr = safe_fopen (tmpfname, "w+")) == NULL
) {
+
fperr = m_tempfile (tmpfname, sizeof(tmpfname), NONULL(Tempdir), NULL
);
+ if (
!fperr
) {
mutt_perror (tmpfname);
return NULL;
}
mutt_unlink (tmpfname);
mutt_perror (tmpfname);
return NULL;
}
mutt_unlink (tmpfname);
-
mutt_mktemp (pk7out
);
- if (
(fpout = safe_fopen (pk7out, "w+")) == NULL
) {
+
fpout = m_tempfile (pk7out, sizeof(tmpfname), NONULL(Tempdir), NULL
);
+ if (
!fpout
) {
fclose (fperr);
mutt_perror (pk7out);
return NULL;
fclose (fperr);
mutt_perror (pk7out);
return NULL;
@@
-900,21
+900,21
@@
static char *smime_extract_certificate (char *infile)
rewind (fpout);
rewind (fperr);
fflush (fperr);
rewind (fpout);
rewind (fperr);
fflush (fperr);
+
empty = (fgetc (fpout) == EOF);
empty = (fgetc (fpout) == EOF);
+
+ fclose (fpout);
+
if (empty) {
mutt_perror (pk7out);
mutt_copy_stream (fperr, stdout);
if (empty) {
mutt_perror (pk7out);
mutt_copy_stream (fperr, stdout);
- fclose (fpout);
fclose (fperr);
mutt_unlink (pk7out);
return NULL;
fclose (fperr);
mutt_unlink (pk7out);
return NULL;
-
}
}
-
- fclose (fpout);
- mutt_mktemp (certfile);
- if ((fpout = safe_fopen (certfile, "w+")) == NULL) {
+ fpout = m_tempfile (certfile, sizeof(certfile), NONULL(Tempdir), NULL);
+ if (!fpout) {
fclose (fperr);
mutt_unlink (pk7out);
mutt_perror (certfile);
fclose (fperr);
mutt_unlink (pk7out);
mutt_perror (certfile);
@@
-965,24
+965,23
@@
static char *smime_extract_signer_certificate (char *infile)
char pk7out[_POSIX_PATH_MAX], certfile[_POSIX_PATH_MAX];
char tmpfname[_POSIX_PATH_MAX];
pid_t thepid;
char pk7out[_POSIX_PATH_MAX], certfile[_POSIX_PATH_MAX];
char tmpfname[_POSIX_PATH_MAX];
pid_t thepid;
- int empty;
-
- mutt_mktemp (tmpfname);
- if ((fperr = safe_fopen (tmpfname, "w+")) == NULL) {
+ fperr = m_tempfile (tmpfname, sizeof(tmpfname), NONULL(Tempdir), NULL);
+ if (!fperr) {
mutt_perror (tmpfname);
return NULL;
}
mutt_unlink (tmpfname);
mutt_perror (tmpfname);
return NULL;
}
mutt_unlink (tmpfname);
-
- mutt_mktemp (certfile);
- if ((fpout = safe_fopen (certfile, "w+")) == NULL) {
+ m_tempfile (certfile, sizeof(certfile), NONULL(Tempdir), NULL);
+ if (!fpout) {
fclose (fperr);
mutt_perror (certfile);
return NULL;
}
fclose (fperr);
mutt_perror (certfile);
return NULL;
}
+ fclose (fpout);
+
/* Extract signer's certificate
*/
if ((thepid = smime_invoke (NULL, NULL, NULL,
/* Extract signer's certificate
*/
if ((thepid = smime_invoke (NULL, NULL, NULL,
@@
-992,7
+991,6
@@
static char *smime_extract_signer_certificate (char *infile)
mutt_any_key_to_continue (_
("Error: unable to create OpenSSL subprocess!"));
fclose (fperr);
mutt_any_key_to_continue (_
("Error: unable to create OpenSSL subprocess!"));
fclose (fperr);
- fclose (fpout);
mutt_unlink (pk7out);
mutt_unlink (certfile);
return NULL;
mutt_unlink (pk7out);
mutt_unlink (certfile);
return NULL;
@@
-1000,30
+998,17
@@
static char *smime_extract_signer_certificate (char *infile)
mutt_wait_filter (thepid);
mutt_wait_filter (thepid);
- fflush (fpout);
- rewind (fpout);
rewind (fperr);
fflush (fperr);
rewind (fperr);
fflush (fperr);
- empty = (fgetc (fpout) == EOF);
- if (empty) {
- mutt_endwin (NULL);
- mutt_copy_stream (fperr, stdout);
- mutt_any_key_to_continue (NULL);
- fclose (fpout);
- fclose (fperr);
- mutt_unlink (certfile);
- return NULL;
- }
- fclose (fpout);
+ mutt_endwin (NULL);
+ mutt_copy_stream (fperr, stdout);
fclose (fperr);
fclose (fperr);
-
- return m_strdup(certfile);
+ mutt_any_key_to_continue (NULL);
+ mutt_unlink (certfile);
+ return NULL;
}
}
-
-
-
/* Add a certificate and update index file (externally). */
void smime_invoke_import (char *infile, char *mailbox __attribute__ ((unused)))
/* Add a certificate and update index file (externally). */
void smime_invoke_import (char *infile, char *mailbox __attribute__ ((unused)))
@@
-1032,22
+1017,21
@@
void smime_invoke_import (char *infile, char *mailbox __attribute__ ((unused)))
FILE *smimein = NULL, *fpout = NULL, *fperr = NULL;
pid_t thepid = -1;
FILE *smimein = NULL, *fpout = NULL, *fperr = NULL;
pid_t thepid = -1;
-
mutt_mktemp (tmpfname
);
- if (
(fperr = safe_fopen (tmpfname, "w+")) == NULL
) {
+
fperr = m_tempfile (tmpfname, sizeof(tmpfname), NONULL(Tempdir), NULL
);
+ if (
!fperr
) {
mutt_perror (tmpfname);
return;
}
mutt_unlink (tmpfname);
mutt_perror (tmpfname);
return;
}
mutt_unlink (tmpfname);
-
mutt_mktemp (tmpfname
);
- if (
(fpout = safe_fopen (tmpfname, "w+")) == NULL
) {
+
fpout = m_tempfile (tmpfname, sizeof(tmpfname), NONULL(Tempdir), NULL
);
+ if (
!fpout
) {
fclose (fperr);
mutt_perror (tmpfname);
return;
}
mutt_unlink (tmpfname);
fclose (fperr);
mutt_perror (tmpfname);
return;
}
mutt_unlink (tmpfname);
-
buf[0] = '\0';
if (option (OPTASKCERTLABEL))
mutt_get_field ("Label for certificate:", buf, sizeof (buf), 0);
buf[0] = '\0';
if (option (OPTASKCERTLABEL))
mutt_get_field ("Label for certificate:", buf, sizeof (buf), 0);
@@
-1094,8
+1078,8
@@
int smime_verify_sender (HEADER * h)
FILE *fpout;
int retval = 1;
FILE *fpout;
int retval = 1;
-
mutt_mktemp (tempfname
);
- if (!
(fpout = safe_fopen (tempfname, "w"))
) {
+
fpout = m_tempfile (tempfname, sizeof(tempfname), NONULL(Tempdir), NULL
);
+ if (!
fpout
) {
mutt_perror (tempfname);
return 1;
}
mutt_perror (tempfname);
return 1;
}
@@
-1194,14
+1178,14
@@
BODY *smime_build_smime_entity (BODY * a, char *certlist)
int err = 0, empty;
pid_t thepid;
int err = 0, empty;
pid_t thepid;
-
mutt_mktemp (tempfile
);
- if (
(fpout = safe_fopen (tempfile, "w+")) == NULL
) {
+
fpout = m_tempfile (tempfile, sizeof(tempfile), NONULL(Tempdir), NULL
);
+ if (
!fpout
) {
mutt_perror (tempfile);
mutt_perror (tempfile);
- return
(NULL)
;
+ return
NULL
;
}
}
-
mutt_mktemp (smimeerrfile
);
- if (
(smimeerr = safe_fopen (smimeerrfile, "w+")) == NULL
) {
+
smimeerr = m_tempfile (smimeerrfile, sizeof(smimeerrfile), NONULL(Tempdir), NULL
);
+ if (
!smimeerr
) {
mutt_perror (smimeerrfile);
fclose (fpout);
mutt_unlink (tempfile);
mutt_perror (smimeerrfile);
fclose (fpout);
mutt_unlink (tempfile);
@@
-1209,8
+1193,8
@@
BODY *smime_build_smime_entity (BODY * a, char *certlist)
}
mutt_unlink (smimeerrfile);
}
mutt_unlink (smimeerrfile);
-
mutt_mktemp (smimeinfile
);
- if (
(fptmp = safe_fopen (smimeinfile, "w+")) == NULL
) {
+
fptmp = m_tempfile (smimeinfile, sizeof(smimeinfile), NONULL(Tempdir), NULL
);
+ if (
!fptmp
) {
mutt_perror (smimeinfile);
mutt_unlink (tempfile);
fclose (fpout);
mutt_perror (smimeinfile);
mutt_unlink (tempfile);
fclose (fpout);
@@
-1319,14
+1303,14
@@
BODY *smime_sign_message (BODY * a)
convert_to_7bit (a); /* Signed data _must_ be in 7-bit format. */
convert_to_7bit (a); /* Signed data _must_ be in 7-bit format. */
-
mutt_mktemp (filetosign
);
- if (
(sfp = safe_fopen (filetosign, "w+")) == NULL
) {
+
sfp = m_tempfile (filetosign, sizeof(filetosign), NONULL(Tempdir), NULL
);
+ if (
!sfp
) {
mutt_perror (filetosign);
return NULL;
}
mutt_perror (filetosign);
return NULL;
}
-
mutt_mktemp (signedfile
);
- if (
(smimeout = safe_fopen (signedfile, "w+")) == NULL
) {
+
smimeout = m_tempfile (signedfile, sizeof(signedfile), NONULL(Tempdir), NULL
);
+ if (
!smimeout
) {
mutt_perror (signedfile);
fclose (sfp);
mutt_unlink (filetosign);
mutt_perror (signedfile);
fclose (sfp);
mutt_unlink (filetosign);
@@
-1508,9
+1492,8
@@
int smime_verify_one (BODY * sigbdy, STATE * s, const char *tempfile)
sigbdy->type = origType;
sigbdy->type = origType;
-
- mutt_mktemp (smimeerrfile);
- if (!(smimeerr = safe_fopen (smimeerrfile, "w+"))) {
+ smimeerr = m_tempfile(smimeerrfile, sizeof(smimeerrfile), NONULL(Tempdir), NULL);
+ if (!smimeerr) {
mutt_perror (smimeerrfile);
mutt_unlink (signedfile);
return -1;
mutt_perror (smimeerrfile);
mutt_unlink (signedfile);
return -1;
@@
-1591,29
+1574,25
@@
static BODY *smime_handle_entity (BODY * m, STATE * s, FILE * outFile)
if (!(type & APPLICATION_SMIME))
return NULL;
if (!(type & APPLICATION_SMIME))
return NULL;
-
mutt_mktemp (outfile
);
- if (
(smimeout = safe_fopen (outfile, "w+")) == NULL
) {
+
smimeout = m_tempfile (outfile, sizeof(outfile), NONULL(Tempdir), NULL
);
+ if (
!smimeout
) {
mutt_perror (outfile);
return NULL;
}
mutt_perror (outfile);
return NULL;
}
-
mutt_mktemp (errfile
);
- if (
(smimeerr = safe_fopen (errfile, "w+")) == NULL
) {
+
smimeerr = m_tempfile(errfile, sizeof(errfile), NONULL(Tempdir), NULL
);
+ if (
!smimeerr
) {
mutt_perror (errfile);
fclose (smimeout);
mutt_perror (errfile);
fclose (smimeout);
- smimeout = NULL;
return NULL;
}
mutt_unlink (errfile);
return NULL;
}
mutt_unlink (errfile);
-
- mutt_mktemp (tmpfname);
- if ((tmpfp = safe_fopen (tmpfname, "w+")) == NULL) {
+ tmpfp = m_tempfile (tmpfname, sizeof(tmpfname), NONULL(Tempdir), NULL);
+ if (!tmpfp) {
mutt_perror (tmpfname);
fclose (smimeout);
mutt_perror (tmpfname);
fclose (smimeout);
- smimeout = NULL;
fclose (smimeerr);
fclose (smimeerr);
- smimeerr = NULL;
return NULL;
}
return NULL;
}
@@
-1689,11
+1668,10
@@
static BODY *smime_handle_entity (BODY * m, STATE * s, FILE * outFile)
if (outFile)
fpout = outFile;
else {
if (outFile)
fpout = outFile;
else {
-
mutt_mktemp (tmptmpfname
);
- if (
(fpout = safe_fopen (tmptmpfname, "w+")) == NULL
) {
+
fpout = m_tempfile (tmptmpfname, sizeof(tmptmpfname), NONULL(Tempdir), NULL
);
+ if (
!fpout
) {
mutt_perror (tmptmpfname);
fclose (smimeout);
mutt_perror (tmptmpfname);
fclose (smimeout);
- smimeout = NULL;
return NULL;
}
}
return NULL;
}
}
@@
-1788,8
+1766,8
@@
int smime_decrypt_mime (FILE * fpin, FILE ** fpout, BODY * b, BODY ** cur)
s.fpin = fpin;
fseeko (s.fpin, b->offset, 0);
s.fpin = fpin;
fseeko (s.fpin, b->offset, 0);
-
mutt_mktemp (tempfile
);
- if (
(tmpfp = safe_fopen (tempfile, "w+")) == NULL
) {
+
tmpfp = m_tempfile (tempfile, sizeof(tempfile), NONULL(Tempdir), NULL
);
+ if (
!tmpfp
) {
mutt_perror (tempfile);
return (-1);
}
mutt_perror (tempfile);
return (-1);
}
@@
-1804,8
+1782,8
@@
int smime_decrypt_mime (FILE * fpin, FILE ** fpout, BODY * b, BODY ** cur)
s.fpin = tmpfp;
s.fpout = 0;
s.fpin = tmpfp;
s.fpout = 0;
-
mutt_mktemp (tempfile
);
- if (
(*fpout = safe_fopen (tempfile, "w+")) == NULL
) {
+
*fpout = m_tempfile (tempfile, sizeof(tempfile), NONULL(Tempdir), NULL
);
+ if (
!*fpout
) {
mutt_perror (tempfile);
rv = -1;
goto bail;
mutt_perror (tempfile);
rv = -1;
goto bail;