* please see the file GPL in the top level source directory.
*/
-#if HAVE_CONFIG_H
-# include "config.h"
-#endif
+#include <lib-lib/lib-lib.h>
-#include <lib-lib/mem.h>
-#include <lib-lib/str.h>
-#include <lib-lib/macros.h>
-#include <lib-lib/file.h>
-#include <lib-lib/debug.h>
+#ifdef HAVE_SYS_RESOURCE_H
+# include <sys/resource.h>
+#endif
#include <lib-mime/mime.h>
+#include <lib-sys/unix.h>
#include <lib-ui/curses.h>
#include <lib-ui/enter.h>
#include <lib-ui/menu.h>
-#include "mutt.h"
+#include "alias.h"
#include "handler.h"
#include "copy.h"
-
-
-#include <sys/wait.h>
-#include <string.h>
-#include <stdlib.h>
-#include <unistd.h>
-#include <sys/stat.h>
-#include <errno.h>
-#include <ctype.h>
-
-#ifdef HAVE_LOCALE_H
-#include <locale.h>
-#endif
-
-#ifdef HAVE_SYS_TIME_H
-# include <sys/time.h>
-#endif
-
-#ifdef HAVE_SYS_RESOURCE_H
-# include <sys/resource.h>
-#endif
+#include "alias.h"
#include "crypt.h"
+#include "smime.h"
struct smime_command_context {
const char *key; /* %k */
{
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,
return m_strdup(key);
}
-
-
-
/*
This sets the '*ToUse' variables for an upcoming decryption, where
the reuquired key is different from SmimeDefaultKey.
*/
-
-void _smime_getkeys (char *mailbox)
+static void _smime_getkeys (char *mailbox)
{
char *k = NULL;
char buf[STRING];
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];
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_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;
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_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;
rewind (fpout);
rewind (fperr);
fflush (fperr);
+
empty = (fgetc (fpout) == EOF);
+
+ fclose (fpout);
+
if (empty) {
mutt_perror (pk7out);
mutt_copy_stream (fperr, stdout);
- fclose (fpout);
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);
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_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 (fpout);
+
/* Extract signer's certificate
*/
if ((thepid = smime_invoke (NULL, NULL, NULL,
mutt_any_key_to_continue (_
("Error: unable to create OpenSSL subprocess!"));
fclose (fperr);
- fclose (fpout);
mutt_unlink (pk7out);
mutt_unlink (certfile);
return NULL;
mutt_wait_filter (thepid);
- fflush (fpout);
- rewind (fpout);
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);
-
- 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__((notused)))
+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;
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_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);
-
buf[0] = '\0';
if (option (OPTASKCERTLABEL))
mutt_get_field ("Label for certificate:", buf, sizeof (buf), 0);
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;
}
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);
- 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_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);
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;
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_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);
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");
}
-
-
-
-
/*
* Handling S/MIME - bodies.
*/
-
-
-
-
static
pid_t smime_invoke_verify (FILE ** smimein, FILE ** smimeout,
FILE ** smimeerr, int smimeinfd, int smimeoutfd,
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;
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_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);
- smimeout = NULL;
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);
- smimeout = NULL;
fclose (smimeerr);
- smimeerr = NULL;
return NULL;
}
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);
- smimeout = NULL;
return NULL;
}
}
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);
}
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;