nmh-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Nmh-commits] nmh ChangeLog etc/Makefile.in h/prototypes.h sb...


From: Earl Hood
Subject: [Nmh-commits] nmh ChangeLog etc/Makefile.in h/prototypes.h sb...
Date: Thu, 04 Feb 2010 01:39:22 +0000

CVSROOT:        /cvsroot/nmh
Module name:    nmh
Changes by:     Earl Hood <ehood>       10/02/04 01:39:22

Modified files:
        .              : ChangeLog 
        etc            : Makefile.in 
        h              : prototypes.h 
        sbr            : Makefile.in fmt_rfc2047.c fmt_scan.c 
                         getarguments.c m_scratch.c m_tmpfil.c pidwait.c 
        uip            : annosbr.c burst.c distsbr.c forw.c inc.c 
                         mhbuild.c mhbuildsbr.c mhlsbr.c mhmail.c 
                         mhoutsbr.c mhparse.c mhstoresbr.c msh.c 
                         mshcmds.c new.c popsbr.c post.c prompter.c 
                         rcvdist.c rcvstore.c rcvtty.c scansbr.c send.c 
                         sendsbr.c show.c slocal.c viamail.c 
                         whatnowsbr.c 
Added files:
        sbr            : m_mktemp.c 

Log message:
        * Bug #15213, #18635: The use of the insecure m_scratch() and
          m_tmpfil() functions have been replaced by m_mktemp()
          or m_mktemp2() functions (defined in sbr/m_mktemp.c).
          The new functions use mkstemp() to securely create
          temporary files to avoid the numerous race conditions
          that exist with the old functions.  This does assume
          that mkstemp() is available.  Unsure if we need to
          create an alternative implementation if mkstemp() is
          not available.  More information about new temp file
          functions in m_mktemp.c, including the support for
          MHTMPDIR, TMPDIR, and TMP envvars.
        
        NOTE: The files sbr/m_scratch.c and sbr/m_tmpfil.c should be removed.
        Until more testing verifies changes to support new functions have not
        broken functionality, the files are be left in the tree, but comments
        have been added stating the functions in them should not be called.

CVSWeb URLs:
http://cvs.savannah.gnu.org/viewcvs/nmh/ChangeLog?cvsroot=nmh&r1=1.309&r2=1.310
http://cvs.savannah.gnu.org/viewcvs/nmh/etc/Makefile.in?cvsroot=nmh&r1=1.16&r2=1.17
http://cvs.savannah.gnu.org/viewcvs/nmh/h/prototypes.h?cvsroot=nmh&r1=1.26&r2=1.27
http://cvs.savannah.gnu.org/viewcvs/nmh/sbr/Makefile.in?cvsroot=nmh&r1=1.28&r2=1.29
http://cvs.savannah.gnu.org/viewcvs/nmh/sbr/fmt_rfc2047.c?cvsroot=nmh&r1=1.9&r2=1.10
http://cvs.savannah.gnu.org/viewcvs/nmh/sbr/fmt_scan.c?cvsroot=nmh&r1=1.25&r2=1.26
http://cvs.savannah.gnu.org/viewcvs/nmh/sbr/getarguments.c?cvsroot=nmh&r1=1.3&r2=1.4
http://cvs.savannah.gnu.org/viewcvs/nmh/sbr/m_scratch.c?cvsroot=nmh&r1=1.6&r2=1.7
http://cvs.savannah.gnu.org/viewcvs/nmh/sbr/m_tmpfil.c?cvsroot=nmh&r1=1.4&r2=1.5
http://cvs.savannah.gnu.org/viewcvs/nmh/sbr/pidwait.c?cvsroot=nmh&r1=1.6&r2=1.7
http://cvs.savannah.gnu.org/viewcvs/nmh/sbr/m_mktemp.c?cvsroot=nmh&rev=1.1
http://cvs.savannah.gnu.org/viewcvs/nmh/uip/annosbr.c?cvsroot=nmh&r1=1.9&r2=1.10
http://cvs.savannah.gnu.org/viewcvs/nmh/uip/burst.c?cvsroot=nmh&r1=1.7&r2=1.8
http://cvs.savannah.gnu.org/viewcvs/nmh/uip/distsbr.c?cvsroot=nmh&r1=1.4&r2=1.5
http://cvs.savannah.gnu.org/viewcvs/nmh/uip/forw.c?cvsroot=nmh&r1=1.11&r2=1.12
http://cvs.savannah.gnu.org/viewcvs/nmh/uip/inc.c?cvsroot=nmh&r1=1.28&r2=1.29
http://cvs.savannah.gnu.org/viewcvs/nmh/uip/mhbuild.c?cvsroot=nmh&r1=1.14&r2=1.15
http://cvs.savannah.gnu.org/viewcvs/nmh/uip/mhbuildsbr.c?cvsroot=nmh&r1=1.19&r2=1.20
http://cvs.savannah.gnu.org/viewcvs/nmh/uip/mhlsbr.c?cvsroot=nmh&r1=1.14&r2=1.15
http://cvs.savannah.gnu.org/viewcvs/nmh/uip/mhmail.c?cvsroot=nmh&r1=1.6&r2=1.7
http://cvs.savannah.gnu.org/viewcvs/nmh/uip/mhoutsbr.c?cvsroot=nmh&r1=1.8&r2=1.9
http://cvs.savannah.gnu.org/viewcvs/nmh/uip/mhparse.c?cvsroot=nmh&r1=1.21&r2=1.22
http://cvs.savannah.gnu.org/viewcvs/nmh/uip/mhstoresbr.c?cvsroot=nmh&r1=1.15&r2=1.16
http://cvs.savannah.gnu.org/viewcvs/nmh/uip/msh.c?cvsroot=nmh&r1=1.14&r2=1.15
http://cvs.savannah.gnu.org/viewcvs/nmh/uip/mshcmds.c?cvsroot=nmh&r1=1.16&r2=1.17
http://cvs.savannah.gnu.org/viewcvs/nmh/uip/new.c?cvsroot=nmh&r1=1.2&r2=1.3
http://cvs.savannah.gnu.org/viewcvs/nmh/uip/popsbr.c?cvsroot=nmh&r1=1.20&r2=1.21
http://cvs.savannah.gnu.org/viewcvs/nmh/uip/post.c?cvsroot=nmh&r1=1.23&r2=1.24
http://cvs.savannah.gnu.org/viewcvs/nmh/uip/prompter.c?cvsroot=nmh&r1=1.6&r2=1.7
http://cvs.savannah.gnu.org/viewcvs/nmh/uip/rcvdist.c?cvsroot=nmh&r1=1.13&r2=1.14
http://cvs.savannah.gnu.org/viewcvs/nmh/uip/rcvstore.c?cvsroot=nmh&r1=1.14&r2=1.15
http://cvs.savannah.gnu.org/viewcvs/nmh/uip/rcvtty.c?cvsroot=nmh&r1=1.14&r2=1.15
http://cvs.savannah.gnu.org/viewcvs/nmh/uip/scansbr.c?cvsroot=nmh&r1=1.13&r2=1.14
http://cvs.savannah.gnu.org/viewcvs/nmh/uip/send.c?cvsroot=nmh&r1=1.10&r2=1.11
http://cvs.savannah.gnu.org/viewcvs/nmh/uip/sendsbr.c?cvsroot=nmh&r1=1.18&r2=1.19
http://cvs.savannah.gnu.org/viewcvs/nmh/uip/show.c?cvsroot=nmh&r1=1.10&r2=1.11
http://cvs.savannah.gnu.org/viewcvs/nmh/uip/slocal.c?cvsroot=nmh&r1=1.27&r2=1.28
http://cvs.savannah.gnu.org/viewcvs/nmh/uip/viamail.c?cvsroot=nmh&r1=1.11&r2=1.12
http://cvs.savannah.gnu.org/viewcvs/nmh/uip/whatnowsbr.c?cvsroot=nmh&r1=1.13&r2=1.14

Patches:
Index: ChangeLog
===================================================================
RCS file: /cvsroot/nmh/nmh/ChangeLog,v
retrieving revision 1.309
retrieving revision 1.310
diff -u -b -r1.309 -r1.310
--- ChangeLog   3 Feb 2010 05:56:56 -0000       1.309
+++ ChangeLog   4 Feb 2010 01:39:21 -0000       1.310
@@ -1,4 +1,19 @@
+2010-02-03  Earl Hood <address@hidden>
+
+       * Bug #15213, #18635: The use of the insecure m_scratch() and
+         m_tmpfil() functions have been replaced by m_mktemp()
+         or m_mktemp2() functions (defined in sbr/m_mktemp.c).
+         The new functions use mkstemp() to securely create
+         temporary files to avoid the numerous race conditions
+         that exist with the old functions.  This does assume
+         that mkstemp() is available.  Unsure if we need to
+         create an alternative implementation if mkstemp() is
+         not available.  More information about new temp file
+         functions in m_mktemp.c, including the support for
+         MHTMPDIR, TMPDIR, and TMP envvars.
+
 2010-02-02  Earl Hood <address@hidden>
+
        * mts/smtp/smtp.c: added SASL support if mts configuration
          setting is set to "sendmail".  This is useful if sendmail
          conf option is to a custom script that creates a proxy

Index: etc/Makefile.in
===================================================================
RCS file: /cvsroot/nmh/nmh/etc/Makefile.in,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -b -r1.16 -r1.17
--- etc/Makefile.in     4 Mar 2006 22:14:18 -0000       1.16
+++ etc/Makefile.in     4 Feb 2010 01:39:21 -0000       1.17
@@ -1,7 +1,7 @@
 #
 # Makefile for etc subdirectory
 #
-# $Id: Makefile.in,v 1.16 2006/03/04 22:14:18 pm215 Exp $
+# $Id: Makefile.in,v 1.17 2010/02/04 01:39:21 ehood Exp $
 #
 
 SHELL = /bin/sh
@@ -100,18 +100,12 @@
        for path in $$INSTALL_FILES; do \
          file=`basename $$path`; \
          echo "Installing $$file..."; \
-         if [ -f $(DESTDIR)$(etcdir)/$$file ]; then \
-           mv $(DESTDIR)$(etcdir)/$$file $(DESTDIR)$(etcdir)/$$file.prev; \
-           $(INSTALL_DATA) $$path $(DESTDIR)$(etcdir)/$$file; \
-           if diff $(DESTDIR)$(etcdir)/$$file.prev $(DESTDIR)$(etcdir)/$$file; 
then \
-             rm $(DESTDIR)$(etcdir)/$$file.prev; \
+         if [ -f "$(DESTDIR)$(etcdir)/$$file" ]; then \
+           if cmp -s "$$path" "$(DESTDIR)$(etcdir)/$$file"; then \
+             echo "$(DESTDIR)$(etcdir)/$$file unchanged, skipped"; \
            else \
-             echo; \
-             echo "  Previous version of $$file saved as $$file.prev due\c";\
-             echo   " to diffs."; \
-             echo "  Please merge any local config changes into the new\c"; \
-             echo   " $$file."; \
-             echo; \
+             $(INSTALL_DATA) "$$path" "$(DESTDIR)$(etcdir)/$$file.dist"; \
+             echo "INFO: $(DESTDIR)$(etcdir)/$$file installed with .dist 
extension"; \
            fi; \
          else \
            $(INSTALL_DATA) $$path $(DESTDIR)$(etcdir)/$$file; \

Index: h/prototypes.h
===================================================================
RCS file: /cvsroot/nmh/nmh/h/prototypes.h,v
retrieving revision 1.26
retrieving revision 1.27
diff -u -b -r1.26 -r1.27
--- h/prototypes.h      16 Jan 2009 02:28:54 -0000      1.26
+++ h/prototypes.h      4 Feb 2010 01:39:21 -0000       1.27
@@ -2,7 +2,7 @@
 /*
  * prototypes.h -- various prototypes
  *
- * $Id: prototypes.h,v 1.26 2009/01/16 02:28:54 kenh Exp $
+ * $Id: prototypes.h,v 1.27 2010/02/04 01:39:21 ehood Exp $
  */
 
 /*
@@ -81,6 +81,8 @@
 int m_putenv (char *, char *);
 char *m_scratch (char *, char *);
 char *m_tmpfil (char *);
+char *m_mktemp(const char *, int *, FILE **);
+char *m_mktemp2(const char *, const char *, int *, FILE **);
 void m_unknown(FILE *);
 int makedir (char *);
 char *nmh_getpass(const char *);

Index: sbr/Makefile.in
===================================================================
RCS file: /cvsroot/nmh/nmh/sbr/Makefile.in,v
retrieving revision 1.28
retrieving revision 1.29
diff -u -b -r1.28 -r1.29
--- sbr/Makefile.in     17 Jan 2009 16:47:30 -0000      1.28
+++ sbr/Makefile.in     4 Feb 2010 01:39:21 -0000       1.29
@@ -1,7 +1,7 @@
 #
 # Makefile for sbr subdirectory
 #
-# $Id: Makefile.in,v 1.28 2009/01/17 16:47:30 epg Exp $
+# $Id: Makefile.in,v 1.29 2010/02/04 01:39:21 ehood Exp $
 #
 
 SHELL = /bin/sh
@@ -78,7 +78,7 @@
        seq_setprev.c seq_setunseen.c showfile.c signals.c              \
        smatch.c snprintb.c ssequal.c strcasecmp.c                      \
        strindex.c trimcpy.c uprf.c vfgets.c fmt_def.c                  \
-       m_msgdef.c mf.c utils.c
+       m_msgdef.c mf.c utils.c m_mktemp.c
 
 # source for compatibility functions
 COMPAT = memmove.c snprintf.c strdup.c strerror.c

Index: sbr/fmt_rfc2047.c
===================================================================
RCS file: /cvsroot/nmh/nmh/sbr/fmt_rfc2047.c,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -b -r1.9 -r1.10
--- sbr/fmt_rfc2047.c   9 Mar 2006 19:51:13 -0000       1.9
+++ sbr/fmt_rfc2047.c   4 Feb 2010 01:39:21 -0000       1.10
@@ -2,7 +2,7 @@
 /*
  * fmt_rfc2047.c -- decode RFC-2047 header format 
  *
- * $Id: fmt_rfc2047.c,v 1.9 2006/03/09 19:51:13 bress Exp $
+ * $Id: fmt_rfc2047.c,v 1.10 2010/02/04 01:39:21 ehood Exp $
  *
  * This code is Copyright (c) 2002, by the authors of nmh.  See the
  * COPYRIGHT file in the root directory of the nmh distribution for
@@ -71,7 +71,7 @@
     int whitespace = 0;                /* how much whitespace between 
encodings? */
 #ifdef HAVE_ICONV
     int use_iconv = 0;          /* are we converting encoding with iconv? */
-    iconv_t cd;
+    iconv_t cd = NULL;
     int fromutf8 = 0;
     char *saveq, *convbuf = NULL;
     size_t savedstlen;

Index: sbr/fmt_scan.c
===================================================================
RCS file: /cvsroot/nmh/nmh/sbr/fmt_scan.c,v
retrieving revision 1.25
retrieving revision 1.26
diff -u -b -r1.25 -r1.26
--- sbr/fmt_scan.c      5 Apr 2008 18:41:37 -0000       1.25
+++ sbr/fmt_scan.c      4 Feb 2010 01:39:21 -0000       1.26
@@ -2,7 +2,7 @@
 /*
  * fmt_scan.c -- format string interpretation
  *
- * $Id: fmt_scan.c,v 1.25 2008/04/05 18:41:37 pm215 Exp $
+ * $Id: fmt_scan.c,v 1.26 2010/02/04 01:39:21 ehood Exp $
  *
  * This code is Copyright (c) 2002, by the authors of nmh.  See the
  * COPYRIGHT file in the root directory of the nmh distribution for
@@ -297,7 +297,7 @@
 {
     char *cp, *ep;
     unsigned char *sp;
-    char *savestr;
+    char *savestr = NULL;
     unsigned char *str = NULL;
     char buffer[BUFSIZ], buffer2[BUFSIZ];
     int i, c, ljust, n;

Index: sbr/getarguments.c
===================================================================
RCS file: /cvsroot/nmh/nmh/sbr/getarguments.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -b -r1.3 -r1.4
--- sbr/getarguments.c  2 Jan 2006 03:17:42 -0000       1.3
+++ sbr/getarguments.c  4 Feb 2010 01:39:21 -0000       1.4
@@ -2,7 +2,7 @@
 /*
  * getarguments.c -- Get the argument vector ready to go.
  *
- * $Id: getarguments.c,v 1.3 2006/01/02 03:17:42 bress Exp $
+ * $Id: getarguments.c,v 1.4 2010/02/04 01:39:21 ehood Exp $
  *
  * This code is Copyright (c) 2002, by the authors of nmh.  See the
  * COPYRIGHT file in the root directory of the nmh distribution for
@@ -15,7 +15,7 @@
 char **
 getarguments (char *invo_name, int argc, char **argv, int check_context)
 {
-    char *cp, **ap, **bp, **arguments;
+    char *cp = NULL, **ap = NULL, **bp = NULL, **arguments = NULL;
     int n = 0;
 
     /*
@@ -35,7 +35,7 @@
     bp = arguments;
 
     /* Copy any arguments from profile/context */
-    if (n > 0) {
+    if (ap != NULL && n > 0) {
        while (*ap)
            *bp++ = *ap++;
      }

Index: sbr/m_scratch.c
===================================================================
RCS file: /cvsroot/nmh/nmh/sbr/m_scratch.c,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -b -r1.6 -r1.7
--- sbr/m_scratch.c     5 Apr 2008 18:41:37 -0000       1.6
+++ sbr/m_scratch.c     4 Feb 2010 01:39:21 -0000       1.7
@@ -2,7 +2,7 @@
 /*
  * m_scratch.c -- construct a scratch file
  *
- * $Id: m_scratch.c,v 1.6 2008/04/05 18:41:37 pm215 Exp $
+ * $Id: m_scratch.c,v 1.7 2010/02/04 01:39:21 ehood Exp $
  *
  * This code is Copyright (c) 2002, by the authors of nmh.  See the
  * COPYRIGHT file in the root directory of the nmh distribution for
@@ -11,7 +11,10 @@
 
 #include <h/mh.h>
 
-
+/***************************************************************************
+ * DO NOT USE THIS FUNCTION!  IT WILL BE REMOVED IN THE FUTURE.
+ * THIS FUNCTION IS INSECURE.  USE THE FUNCTIONS DEFINED IN m_mktemp.c.
+ ***************************************************************************/
 char *
 m_scratch (char *file, char *template)
 {

Index: sbr/m_tmpfil.c
===================================================================
RCS file: /cvsroot/nmh/nmh/sbr/m_tmpfil.c,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -b -r1.4 -r1.5
--- sbr/m_tmpfil.c      2 Jul 2002 22:09:14 -0000       1.4
+++ sbr/m_tmpfil.c      4 Feb 2010 01:39:21 -0000       1.5
@@ -1,8 +1,7 @@
-
 /*
  * m_tmpfil.c -- construct a temporary file
  *
- * $Id: m_tmpfil.c,v 1.4 2002/07/02 22:09:14 kenh Exp $
+ * $Id: m_tmpfil.c,v 1.5 2010/02/04 01:39:21 ehood Exp $
  *
  * This code is Copyright (c) 2002, by the authors of nmh.  See the
  * COPYRIGHT file in the root directory of the nmh distribution for
@@ -11,7 +10,10 @@
 
 #include <h/mh.h>
 
-
+/***************************************************************************
+ * DO NOT USE THIS FUNCTION!  IT WILL BE REMOVED IN THE FUTURE.
+ * THIS FUNCTION IS INSECURE.  USE THE FUNCTIONS DEFINED IN m_mktemp.c.
+ ***************************************************************************/
 char *
 m_tmpfil (char *template)
 {

Index: sbr/pidwait.c
===================================================================
RCS file: /cvsroot/nmh/nmh/sbr/pidwait.c,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -b -r1.6 -r1.7
--- sbr/pidwait.c       11 Apr 2008 14:12:55 -0000      1.6
+++ sbr/pidwait.c       4 Feb 2010 01:39:21 -0000       1.7
@@ -2,7 +2,7 @@
 /*
  * pidwait.c -- wait for child to exit
  *
- * $Id: pidwait.c,v 1.6 2008/04/11 14:12:55 opk Exp $
+ * $Id: pidwait.c,v 1.7 2010/02/04 01:39:21 ehood Exp $
  *
  * This code is Copyright (c) 2002, by the authors of nmh.  See the
  * COPYRIGHT file in the root directory of the nmh distribution for
@@ -22,7 +22,7 @@
 pidwait (pid_t id, int sigsok)
 {
     pid_t pid;
-    SIGNAL_HANDLER istat, qstat;
+    SIGNAL_HANDLER istat = NULL, qstat = NULL;
 
 #ifdef HAVE_UNION_WAIT
     union wait status;

Index: uip/annosbr.c
===================================================================
RCS file: /cvsroot/nmh/nmh/uip/annosbr.c,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -b -r1.9 -r1.10
--- uip/annosbr.c       5 Apr 2008 18:41:38 -0000       1.9
+++ uip/annosbr.c       4 Feb 2010 01:39:21 -0000       1.10
@@ -2,7 +2,7 @@
 /*
  * annosbr.c -- prepend annotation to messages
  *
- * $Id: annosbr.c,v 1.9 2008/04/05 18:41:38 pm215 Exp $
+ * $Id: annosbr.c,v 1.10 2010/02/04 01:39:21 ehood Exp $
  *
  * This code is Copyright (c) 2002, by the authors of nmh.  See the
  * COPYRIGHT file in the root directory of the nmh distribution for
@@ -179,20 +179,15 @@
     FILE       *tmp;
     int                c;              /* current character */
     int                count;          /* header field (annotation) counter */
-    char       *field;         /* buffer for header field */
-    int                field_size;     /* size of field buffer */
-    FILE       *fp;            /* file pointer made from locked file 
descriptor */
+    char       *field = NULL;  /* buffer for header field */
+    int                field_size = 0; /* size of field buffer */
+    FILE       *fp = NULL;     /* file pointer made from locked file 
descriptor */
     int                length;         /* length of field name */
     int                n;              /* number of bytes written */
 
     mode = fstat (fd, &st) != NOTOK ? (st.st_mode & 0777) : m_gmprot ();
 
-    strncpy (tmpfil, m_scratch (file, "annotate"), sizeof(tmpfil));
-
-    if ((tmp = fopen (tmpfil, "w")) == NULL) {
-       admonish (tmpfil, "unable to create");
-       return 1;
-    }
+    strncpy (tmpfil, m_mktemp2(file, "annotate", NULL, &tmp), sizeof(tmpfil));
     chmod (tmpfil, mode);
 
     /*

Index: uip/burst.c
===================================================================
RCS file: /cvsroot/nmh/nmh/uip/burst.c,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -b -r1.7 -r1.8
--- uip/burst.c 4 Nov 2007 11:54:33 -0000       1.7
+++ uip/burst.c 4 Feb 2010 01:39:21 -0000       1.8
@@ -2,7 +2,7 @@
 /*
  * burst.c -- explode digests into individual messages
  *
- * $Id: burst.c,v 1.7 2007/11/04 11:54:33 jjr Exp $
+ * $Id: burst.c,v 1.8 2010/02/04 01:39:21 ehood Exp $
  *
  * This code is Copyright (c) 2002, by the authors of nmh.  See the
  * COPYRIGHT file in the root directory of the nmh distribution for
@@ -347,12 +347,11 @@
     i = inplace ? msgnum + numburst : mp->hghmsg;
     for (j = numburst; j >= (inplace ? 0 : 1); i--, j--) {
        strncpy (f1, m_name (i), sizeof(f1));
-       strncpy (f2, m_scratch ("", invo_name), sizeof(f2));
+       strncpy (f2, m_mktemp(invo_name, NULL, &out), sizeof(f2));
+
        if (verbosw && i != msgnum)
            printf ("message %d of digest %d becomes message %d\n", j, msgnum, 
i);
 
-       if ((out = fopen (f2, "w")) == NULL)
-           adios (f2, "unable to write message");
        chmod (f2, mode);
        fseek (in, smsgs[j].s_start, SEEK_SET);
        cpybrst (in, out, msgnam, f2,

Index: uip/distsbr.c
===================================================================
RCS file: /cvsroot/nmh/nmh/uip/distsbr.c,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -b -r1.4 -r1.5
--- uip/distsbr.c       13 Apr 2007 11:53:08 -0000      1.4
+++ uip/distsbr.c       4 Feb 2010 01:39:21 -0000       1.5
@@ -2,7 +2,7 @@
 /*
  * distsbr.c -- routines to do additional "dist-style" processing
  *
- * $Id: distsbr.c,v 1.4 2007/04/13 11:53:08 jjr Exp $
+ * $Id: distsbr.c,v 1.5 2010/02/04 01:39:21 ehood Exp $
  *
  * This code is Copyright (c) 2002, by the authors of nmh.  See the
  * COPYRIGHT file in the root directory of the nmh distribution for
@@ -132,6 +132,7 @@
     int state, out;
     char name[NAMESZ], buffer[BUFSIZ], tmpfil[BUFSIZ];
     register FILE *ifp, *ofp;
+    char *cp = NULL;
 
     if (hdrfd != NOTOK)
        close (hdrfd), hdrfd = NOTOK;
@@ -141,9 +142,12 @@
     if ((ifp = fopen (msgnam, "r")) == NULL)
        adios (msgnam, "unable to open message");
 
-    strncpy (tmpfil, m_tmpfil ("dist"), sizeof(tmpfil));
-    if ((hdrfd = open (tmpfil, O_RDWR | O_CREAT | O_TRUNC, 0600)) == NOTOK)
-       adios (tmpfil, "unable to re-open temporary file");
+    cp = m_mktemp2(NULL, "dist", &hdrfd, NULL);
+    if (cp == NULL) {
+        adios("distsbr", "unable to create temporary file");
+    }
+    fchmod(hdrfd, 0600);
+    strncpy(tmpfil, cp, sizeof(tmpfil));
     if ((out = dup (hdrfd)) == NOTOK
            || (ofp = fdopen (out, "w")) == NULL)
        adios (NULL, "no file descriptors -- you lose big");
@@ -171,9 +175,12 @@
            case BODYEOF: 
                fclose (ofp);
 
-               strncpy (tmpfil, m_tmpfil ("dist"), sizeof(tmpfil));
-               if ((txtfd = open (tmpfil, O_RDWR | O_CREAT | O_TRUNC, 0600)) 
== NOTOK)
-                   adios (tmpfil, "unable to open temporary file");
+                cp = m_mktemp2(NULL, "dist", &txtfd, NULL);
+                if (cp == NULL) {
+                    adios("distsbr", "unable to create temporary file");
+                }
+                fchmod(txtfd, 0600);
+               strncpy (tmpfil, cp, sizeof(tmpfil));
                if ((out = dup (txtfd)) == NOTOK
                        || (ofp = fdopen (out, "w")) == NULL)
                    adios (NULL, "no file descriptors -- you lose big");

Index: uip/forw.c
===================================================================
RCS file: /cvsroot/nmh/nmh/uip/forw.c,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -b -r1.11 -r1.12
--- uip/forw.c  4 Nov 2007 11:54:34 -0000       1.11
+++ uip/forw.c  4 Feb 2010 01:39:21 -0000       1.12
@@ -2,7 +2,7 @@
 /*
  * forw.c -- forward a message, or group of messages.
  *
- * $Id: forw.c,v 1.11 2007/11/04 11:54:34 jjr Exp $
+ * $Id: forw.c,v 1.12 2010/02/04 01:39:21 ehood Exp $
  *
  * This code is Copyright (c) 2002, by the authors of nmh.  See the
  * COPYRIGHT file in the root directory of the nmh distribution for
@@ -650,10 +650,11 @@
     int fmtsize;
     register char *nfs;
     char *line, tmpfil[BUFSIZ];
-    register FILE *tmp;
+    FILE *tmp;
     register struct comp *cptr;
     struct format *fmt;
     int dat[5];
+    char *cp = NULL;
 
     /* Get new format string */
     nfs = new_fs (form, NULL, NULL);
@@ -675,9 +676,9 @@
     dat[3] = fmtsize;
     dat[4] = 0;
 
-    strncpy (tmpfil, m_tmpfil (invo_name), sizeof(tmpfil));
-    if ((tmp = fopen (tmpfil, "w+")) == NULL)
-       adios (tmpfil, "unable to create");
+    cp = m_mktemp2(NULL, invo_name, NULL, &tmp);
+    if (cp == NULL) adios("forw", "unable to create temporary file");
+    strncpy (tmpfil, cp, sizeof(tmpfil));
     unlink (tmpfil);
     if ((in = dup (fileno (tmp))) == NOTOK)
        adios ("dup", "unable to");

Index: uip/inc.c
===================================================================
RCS file: /cvsroot/nmh/nmh/uip/inc.c,v
retrieving revision 1.28
retrieving revision 1.29
diff -u -b -r1.28 -r1.29
--- uip/inc.c   25 Dec 2009 14:47:39 -0000      1.28
+++ uip/inc.c   4 Feb 2010 01:39:21 -0000       1.29
@@ -2,7 +2,7 @@
 /*
  * inc.c -- incorporate messages from a maildrop into a folder
  *
- * $Id: inc.c,v 1.28 2009/12/25 14:47:39 levine Exp $
+ * $Id: inc.c,v 1.29 2010/02/04 01:39:21 ehood Exp $
  *
  * This code is Copyright (c) 2002, by the authors of nmh.  See the
  * COPYRIGHT file in the root directory of the nmh distribution for
@@ -236,18 +236,18 @@
 {
     int chgflag = 1, trnflag = 1;
     int noisy = 1, width = 0;
-    int rpop, i, hghnum, msgnum;
+    int rpop, i, hghnum = 0, msgnum = 0;
     int kpop = 0, sasl = 0;
-    char *cp, *maildir, *folder = NULL;
+    char *cp, *maildir = NULL, *folder = NULL;
     char *format = NULL, *form = NULL;
     char *host = NULL, *user = NULL, *proxy = NULL;
     char *audfile = NULL, *from = NULL, *saslmech = NULL;
     char buf[BUFSIZ], **argp, *nfs, **arguments;
-    struct msgs *mp;
+    struct msgs *mp = NULL;
     struct stat st, s1;
     FILE *aud = NULL;
     char       b[MAXPATHLEN + 1];
-    char       *maildir_copy;          /* copy of mail directory because the 
static gets overwritten */
+    char *maildir_copy = NULL; /* copy of mail directory because the static 
gets overwritten */
 
 #ifdef POP
     int nmsgs, nbytes, p = 0;

Index: uip/mhbuild.c
===================================================================
RCS file: /cvsroot/nmh/nmh/uip/mhbuild.c,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -b -r1.14 -r1.15
--- uip/mhbuild.c       14 Aug 2008 00:56:39 -0000      1.14
+++ uip/mhbuild.c       4 Feb 2010 01:39:21 -0000       1.15
@@ -2,7 +2,7 @@
 /*
  * mhbuild.c -- expand/translate MIME composition files
  *
- * $Id: mhbuild.c,v 1.14 2008/08/14 00:56:39 epg Exp $
+ * $Id: mhbuild.c,v 1.15 2010/02/04 01:39:21 ehood Exp $
  *
  * This code is Copyright (c) 2002, by the authors of nmh.  See the
  * COPYRIGHT file in the root directory of the nmh distribution for
@@ -104,6 +104,7 @@
 /* mhbuildsbr.c */
 CT build_mime (char *);
 int output_message (CT, char *);
+int output_message_fp (CT, FILE *, char*);
 
 /* mhlistsbr.c */
 int list_all_messages (CT *, int, int, int, int);
@@ -124,7 +125,8 @@
     char buffer[BUFSIZ], *compfile = NULL;
     char **argp, **arguments;
     CT ct, cts[2];
-    FILE *fp;
+    FILE *fp = NULL;
+    FILE *fp_out = NULL;
 
     done=unlink_done;
 
@@ -305,11 +307,8 @@
      * Process the composition file from standard input.
      */
     if (compfile[0] == '-' && compfile[1] == '\0') {
-
        /* copy standard input to temporary file */
-       strncpy (infile, m_scratch ("", invo_name), sizeof(infile));
-       if ((fp = fopen (infile, "w")) == NULL)
-           adios (infile, "unable to open");
+       strncpy (infile, m_mktemp(invo_name, NULL, &fp), sizeof(infile));
        while (fgets (buffer, BUFSIZ, stdin))
            fputs (buffer, fp);
        fclose (fp);
@@ -321,11 +320,12 @@
        cts[1] = NULL;
 
        /* output MIME message to this temporary file */
-       strncpy (outfile, m_scratch ("", invo_name), sizeof(outfile));
+       strncpy (outfile, m_mktemp(invo_name, NULL, &fp_out), sizeof(outfile));
        unlink_outfile = 1;
 
        /* output the message */
-       output_message (ct, outfile);
+       output_message_fp (ct, fp_out, outfile);
+        fclose(fp_out);
 
        /* output the temp file to standard output */
        if ((fp = fopen (outfile, "r")) == NULL)
@@ -354,11 +354,13 @@
     cts[1] = NULL;
 
     /* output MIME message to this temporary file */
-    strncpy (outfile, m_scratch (compfile, invo_name), sizeof(outfile));
+    strncpy(outfile, m_mktemp2(compfile, invo_name, NULL, &fp_out),
+            sizeof(outfile));
     unlink_outfile = 1;
 
     /* output the message */
-    output_message (ct, outfile);
+    output_message_fp (ct, fp_out, outfile);
+    fclose(fp_out);
 
     /*
      * List the message info
@@ -368,12 +370,13 @@
 
     /* Rename composition draft */
     snprintf (buffer, sizeof(buffer), "%s.orig", m_backup (compfile));
-    if (rename (compfile, buffer) == NOTOK)
-       adios (compfile, "unable to rename %s to", buffer);
+    if (rename (compfile, buffer) == NOTOK) {
+       adios (compfile, "unable to rename comp draft %s to", buffer);
+    }
 
     /* Rename output file to take its place */
     if (rename (outfile, compfile) == NOTOK) {
-       advise (outfile, "unable to rename %s to", compfile);
+       advise (outfile, "unable to rename output %s to", compfile);
        rename (buffer, compfile);
        done (1);
     }

Index: uip/mhbuildsbr.c
===================================================================
RCS file: /cvsroot/nmh/nmh/uip/mhbuildsbr.c,v
retrieving revision 1.19
retrieving revision 1.20
diff -u -b -r1.19 -r1.20
--- uip/mhbuildsbr.c    14 Aug 2008 00:56:39 -0000      1.19
+++ uip/mhbuildsbr.c    4 Feb 2010 01:39:21 -0000       1.20
@@ -2,7 +2,7 @@
 /*
  * mhbuildsbr.c -- routines to expand/translate MIME composition files
  *
- * $Id: mhbuildsbr.c,v 1.19 2008/08/14 00:56:39 epg Exp $
+ * $Id: mhbuildsbr.c,v 1.20 2010/02/04 01:39:21 ehood Exp $
  *
  * This code is Copyright (c) 2002, by the authors of nmh.  See the
  * COPYRIGHT file in the root directory of the nmh distribution for
@@ -414,14 +414,15 @@
        long pos;
        char content[BUFSIZ];
        FILE *out;
+        char *cp;
+
+        cp = m_mktemp2(NULL, invo_name, NULL, &out);
+        if (cp == NULL) adios("mhbuildsbr", "unable to create temporary file");
 
        /* use a temp file to collect the plain text lines */
-       ce->ce_file = add (m_tmpfil (invo_name), NULL);
+       ce->ce_file = add (cp, NULL);
        ce->ce_unlink = 1;
 
-       if ((out = fopen (ce->ce_file, "w")) == NULL)
-           adios (ce->ce_file, "unable to open for writing");
-
        if (buf[0] == '#' && buf[1] == '<') {
            strncpy (content, buf + 2, sizeof(content));
            inlineD = 1;
@@ -1007,11 +1008,16 @@
            char *vec[4], buffer[BUFSIZ];
            FILE *out;
            CI ci = &ct->c_ctinfo;
+            char *tfile = NULL;
 
            if (!(cp = ci->ci_magic))
                adios (NULL, "internal error(5)");
 
-           ce->ce_file = add (m_tmpfil (invo_name), NULL);
+            tfile = m_mktemp2(NULL, invo_name, NULL, NULL);
+            if (tfile == NULL) {
+                adios("mhbuildsbr", "unable to create temporary file");
+            }
+           ce->ce_file = add (tfile, NULL);
            ce->ce_unlink = 1;
 
            xstdout = 0;
@@ -1152,14 +1158,14 @@
 scan_content (CT ct)
 {
     int len;
-    int check8bit, contains8bit = 0;     /* check if contains 8bit data        
        */
-    int checklinelen, linelen = 0;       /* check for long lines               
        */
-    int checkboundary, boundaryclash = 0; /* check if clashes with multipart 
boundary   */
-    int checklinespace, linespace = 0;   /* check if any line ends with space  
        */
-    int checkebcdic, ebcdicunsafe = 0;   /* check if contains ebcdic unsafe 
characters */
-    unsigned char *cp, buffer[BUFSIZ];
-    struct text *t;
-    FILE *in;
+    int check8bit = 0, contains8bit = 0;  /* check if contains 8bit data       
         */
+    int checklinelen = 0, linelen = 0;   /* check for long lines               
        */
+    int checkboundary = 0, boundaryclash = 0; /* check if clashes with 
multipart boundary   */
+    int checklinespace = 0, linespace = 0;  /* check if any line ends with 
space          */
+    int checkebcdic = 0, ebcdicunsafe = 0;  /* check if contains ebcdic unsafe 
characters */
+    unsigned char *cp = NULL, buffer[BUFSIZ];
+    struct text *t = NULL;
+    FILE *in = NULL;
     CE ce = ct->c_cefile;
 
     /*

Index: uip/mhlsbr.c
===================================================================
RCS file: /cvsroot/nmh/nmh/uip/mhlsbr.c,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -b -r1.14 -r1.15
--- uip/mhlsbr.c        30 Dec 2009 01:42:45 -0000      1.14
+++ uip/mhlsbr.c        4 Feb 2010 01:39:22 -0000       1.15
@@ -2,7 +2,7 @@
 /*
  * mhlsbr.c -- main routines for nmh message lister
  *
- * $Id: mhlsbr.c,v 1.14 2009/12/30 01:42:45 levine Exp $
+ * $Id: mhlsbr.c,v 1.15 2010/02/04 01:39:22 ehood Exp $
  *
  * This code is Copyright (c) 2002, by the authors of nmh.  See the
  * COPYRIGHT file in the root directory of the nmh distribution for
@@ -794,8 +794,8 @@
 static void
 process (char *folder, char *fname, int ofilen, int ofilec)
 {
-    char *cp;
-    FILE *fp;
+    char *cp = NULL;
+    FILE *fp = NULL;
     struct mcomp *c1;
 
     switch (setjmp (env)) {
@@ -1687,8 +1687,8 @@
 int
 mhlsbr (int argc, char **argv, FILE *(*action)())
 {
-    SIGNAL_HANDLER istat, pstat, qstat;
-    char *cp;
+    SIGNAL_HANDLER istat = NULL, pstat = NULL, qstat = NULL;
+    char *cp = NULL;
     struct mcomp *c1;
 
     switch (setjmp (mhlenv)) {

Index: uip/mhmail.c
===================================================================
RCS file: /cvsroot/nmh/nmh/uip/mhmail.c,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -b -r1.6 -r1.7
--- uip/mhmail.c        5 Apr 2008 19:04:42 -0000       1.6
+++ uip/mhmail.c        4 Feb 2010 01:39:22 -0000       1.7
@@ -2,7 +2,7 @@
 /*
  * mhmail.c -- simple mail program
  *
- * $Id: mhmail.c,v 1.6 2008/04/05 19:04:42 pm215 Exp $
+ * $Id: mhmail.c,v 1.7 2010/02/04 01:39:22 ehood Exp $
  *
  * This code is Copyright (c) 2002, by the authors of nmh.  See the
  * COPYRIGHT file in the root directory of the nmh distribution for
@@ -52,6 +52,7 @@
     char *from = NULL, *body = NULL, **argp, **arguments;
     char *vec[5], buf[BUFSIZ];
     FILE *out;
+    char *tfile = NULL;
 
 #ifdef LOCALE
     setlocale(LC_ALL, "");
@@ -125,10 +126,11 @@
 
     if (tolist == NULL)
        adios (NULL, "usage: %s addrs ... [switches]", invo_name);
-    strncpy (tmpfil, m_tmpfil (invo_name), sizeof(tmpfil));
-    if ((out = fopen (tmpfil, "w")) == NULL)
-       adios (tmpfil, "unable to write");
-    chmod (tmpfil, 0600);
+
+    tfile = m_mktemp2(NULL, invo_name, NULL, &out);
+    if (tfile == NULL) adios("mhmail", "unable to create temporary file");
+    chmod(tfile, 0600);
+    strncpy (tmpfil, tfile, sizeof(tmpfil));
 
     SIGNAL2 (SIGINT, intrser);
 

Index: uip/mhoutsbr.c
===================================================================
RCS file: /cvsroot/nmh/nmh/uip/mhoutsbr.c,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -b -r1.8 -r1.9
--- uip/mhoutsbr.c      8 Mar 2006 12:14:16 -0000       1.8
+++ uip/mhoutsbr.c      4 Feb 2010 01:39:22 -0000       1.9
@@ -3,7 +3,7 @@
  * mhoutsbr.c -- routines to output MIME messages
  *            -- given a Content structure
  *
- * $Id: mhoutsbr.c,v 1.8 2006/03/08 12:14:16 bress Exp $
+ * $Id: mhoutsbr.c,v 1.9 2010/02/04 01:39:22 ehood Exp $
  *
  * This code is Copyright (c) 2002, by the authors of nmh.  See the
  * COPYRIGHT file in the root directory of the nmh distribution for
@@ -70,6 +70,7 @@
  * prototypes
  */
 int output_message (CT, char *);
+int output_message_fp (CT, FILE *, char *);
 int writeBase64aux (FILE *, FILE *);
 
 /*
@@ -90,27 +91,33 @@
  */
 
 int
-output_message (CT ct, char *file)
+output_message_fp (CT ct, FILE *fp, char *file)
 {
-    FILE *fp;
-
-    if ((fp = fopen (file, "w")) == NULL) {
-       advise (file, "unable to open for writing");
-       return NOTOK;
-    }
-
     if (output_content (ct, fp) == NOTOK)
        return NOTOK;
 
     if (fflush (fp)) {
-       advise (file, "error writing to");
+       advise ((file?file:"<FILE*>"), "error writing to");
        return NOTOK;
     }
-    fclose (fp);
-
     return OK;
 }
 
+int
+output_message (CT ct, char *file)
+{
+    FILE *fp;
+    int status;
+
+    if ((fp = fopen (file, "w")) == NULL) {
+       advise (file, "unable to open for writing");
+       return NOTOK;
+    }
+    status = output_message_fp(ct, fp, file);
+    fclose(fp);
+    return status;
+}
+
 
 /*
  * Output a Content structure to a file.

Index: uip/mhparse.c
===================================================================
RCS file: /cvsroot/nmh/nmh/uip/mhparse.c,v
retrieving revision 1.21
retrieving revision 1.22
diff -u -b -r1.21 -r1.22
--- uip/mhparse.c       14 Aug 2008 06:19:08 -0000      1.21
+++ uip/mhparse.c       4 Feb 2010 01:39:22 -0000       1.22
@@ -2,7 +2,7 @@
 /*
  * mhparse.c -- routines to parse the contents of MIME messages
  *
- * $Id: mhparse.c,v 1.21 2008/08/14 06:19:08 epg Exp $
+ * $Id: mhparse.c,v 1.22 2010/02/04 01:39:22 ehood Exp $
  *
  * This code is Copyright (c) 2002, by the authors of nmh.  See the
  * COPYRIGHT file in the root directory of the nmh distribution for
@@ -204,12 +204,14 @@
      * Check if file is actually standard input
      */
     if ((is_stdin = !(strcmp (file, "-")))) {
-       file = add (m_tmpfil (invo_name), NULL);
-       if ((fp = fopen (file, "w+")) == NULL) {
-           advise (file, "unable to fopen for writing and reading");
+        char *tfile = m_mktemp2(NULL, invo_name, NULL, &fp);
+        if (tfile == NULL) {
+            advise("mhparse", "unable to create temporary file");
            return NULL;
        }
+       file = add (tfile, NULL);
        chmod (file, 0600);
+
        while (fgets (buffer, sizeof(buffer), stdin))
            fputs (buffer, fp);
        fflush (fp);
@@ -1764,7 +1766,7 @@
     }
 
     if (*file == NULL) {
-       ce->ce_file = add (m_scratch ("", tmp), NULL);
+       ce->ce_file = add (m_mktemp(tmp, NULL, NULL), NULL);
        ce->ce_unlink = 1;
     } else {
        ce->ce_file = add (*file, NULL);
@@ -1781,8 +1783,21 @@
                   ci->ci_type);
         cp = context_find (buffer);
     }
-    if (cp != NULL && *cp != '\0')
+    if (cp != NULL && *cp != '\0') {
+        if (ce->ce_unlink) {
+            // Temporary file already exists, so we rename to
+            // version with extension.
+            char *file_org = strdup(ce->ce_file);
+            ce->ce_file = add (cp, ce->ce_file);
+            if (rename(file_org, ce->ce_file)) {
+                adios (ce->ce_file, "unable to rename %s to ", file_org);
+            }
+            free(file_org);
+
+        } else {
         ce->ce_file = add (cp, ce->ce_file);
+        }
+    }
 
     if ((ce->ce_fp = fopen (ce->ce_file, "w+")) == NULL) {
        content_error (ce->ce_file, ct, "unable to fopen for reading/writing");
@@ -1972,7 +1987,7 @@
     }
 
     if (*file == NULL) {
-       ce->ce_file = add (m_scratch ("", tmp), NULL);
+       ce->ce_file = add (m_mktemp(tmp, NULL, NULL), NULL);
        ce->ce_unlink = 1;
     } else {
        ce->ce_file = add (*file, NULL);
@@ -1989,8 +2004,21 @@
                   ci->ci_type);
         cp = context_find (buffer);
     }
-    if (cp != NULL && *cp != '\0')
+    if (cp != NULL && *cp != '\0') {
+        if (ce->ce_unlink) {
+            // Temporary file already exists, so we rename to
+            // version with extension.
+            char *file_org = strdup(ce->ce_file);
         ce->ce_file = add (cp, ce->ce_file);
+            if (rename(file_org, ce->ce_file)) {
+                adios (ce->ce_file, "unable to rename %s to ", file_org);
+            }
+            free(file_org);
+
+        } else {
+            ce->ce_file = add (cp, ce->ce_file);
+        }
+    }
 
     if ((ce->ce_fp = fopen (ce->ce_file, "w+")) == NULL) {
        content_error (ce->ce_file, ct, "unable to fopen for reading/writing");
@@ -2177,7 +2205,7 @@
     }
 
     if (*file == NULL) {
-       ce->ce_file = add (m_scratch ("", tmp), NULL);
+       ce->ce_file = add (m_mktemp(tmp, NULL, NULL), NULL);
        ce->ce_unlink = 1;
     } else {
        ce->ce_file = add (*file, NULL);
@@ -2194,8 +2222,21 @@
                   ci->ci_type);
         cp = context_find (buffer);
     }
-    if (cp != NULL && *cp != '\0')
+    if (cp != NULL && *cp != '\0') {
+        if (ce->ce_unlink) {
+            // Temporary file already exists, so we rename to
+            // version with extension.
+            char *file_org = strdup(ce->ce_file);
         ce->ce_file = add (cp, ce->ce_file);
+            if (rename(file_org, ce->ce_file)) {
+                adios (ce->ce_file, "unable to rename %s to ", file_org);
+            }
+            free(file_org);
+
+        } else {
+            ce->ce_file = add (cp, ce->ce_file);
+        }
+    }
 
     if ((ce->ce_fp = fopen (ce->ce_file, "w+")) == NULL) {
        content_error (ce->ce_file, ct, "unable to fopen for reading/writing");
@@ -2545,7 +2586,7 @@
     else if (caching)
        ce->ce_file = add (cachefile, NULL);
     else
-       ce->ce_file = add (m_scratch ("", tmp), NULL);
+       ce->ce_file = add (m_mktemp(tmp, NULL, NULL), NULL);
 
     if ((ce->ce_fp = fopen (ce->ce_file, "w+")) == NULL) {
        content_error (ce->ce_file, ct, "unable to fopen for reading/writing");
@@ -2747,7 +2788,7 @@
     }
 
     if (*file == NULL) {
-       ce->ce_file = add (m_scratch ("", tmp), NULL);
+       ce->ce_file = add (m_mktemp(tmp, NULL, NULL), NULL);
        ce->ce_unlink = 1;
     } else {
        ce->ce_file = add (*file, NULL);

Index: uip/mhstoresbr.c
===================================================================
RCS file: /cvsroot/nmh/nmh/uip/mhstoresbr.c,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -b -r1.15 -r1.16
--- uip/mhstoresbr.c    4 Jun 2006 08:37:24 -0000       1.15
+++ uip/mhstoresbr.c    4 Feb 2010 01:39:22 -0000       1.16
@@ -2,7 +2,7 @@
 /*
  * mhstoresbr.c -- routines to save/store the contents of MIME messages
  *
- * $Id: mhstoresbr.c,v 1.15 2006/06/04 08:37:24 jjr Exp $
+ * $Id: mhstoresbr.c,v 1.16 2010/02/04 01:39:22 ehood Exp $
  *
  * This code is Copyright (c) 2002, by the authors of nmh.  See the
  * COPYRIGHT file in the root directory of the nmh distribution for
@@ -482,7 +482,7 @@
 static int
 store_content (CT ct, CT p)
 {
-    int appending = 0, msgnum;
+    int appending = 0, msgnum = 0;
     int is_partial = 0, first_partial = 0;
     int last_partial = 0;
     char *cp, buffer[BUFSIZ];
@@ -560,7 +560,7 @@
        char *tmpfilenam, *folder;
 
        /* Store content in temporary file for now */
-       tmpfilenam = m_scratch ("", invo_name);
+       tmpfilenam = m_mktemp(invo_name, NULL, NULL);
        ct->c_storage = add (tmpfilenam, NULL);
 
        /* Get the folder name */

Index: uip/msh.c
===================================================================
RCS file: /cvsroot/nmh/nmh/uip/msh.c,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -b -r1.14 -r1.15
--- uip/msh.c   14 Aug 2008 01:50:46 -0000      1.14
+++ uip/msh.c   4 Feb 2010 01:39:22 -0000       1.15
@@ -2,7 +2,7 @@
 /*
  * msh.c -- The nmh shell
  *
- * $Id: msh.c,v 1.14 2008/08/14 01:50:46 epg Exp $
+ * $Id: msh.c,v 1.15 2010/02/04 01:39:22 ehood Exp $
  *
  * This code is Copyright (c) 2002, by the authors of nmh.  See the
  * COPYRIGHT file in the root directory of the nmh distribution for
@@ -733,10 +733,10 @@
 
 #ifdef BPOP
     if (pmsh) {
-       strncpy (tmpfil, m_tmpfil (invo_name), sizeof(tmpfil));
-       if ((fp = fopen (tmpfil, "w+")) == NULL)
-           padios (tmpfil, "unable to create");
-       unlink (tmpfil);
+        char *tfile = m_mktemp2(NULL, invo_name, NULL, &fp);
+        if (tfile == NULL) padios("msh", "unable to create temporary file");
+        unlink(tfile);
+       strncpy(tmpfil, tfile, sizeof(tmpfil));
     }
     else
 #endif /* BPOP */
@@ -996,10 +996,10 @@
        if (Msgs[msgnum].m_top == 0)
            padios (NULL, "msh_ready (%d, %d) botch", msgnum, full);
        if (!full) {
-           strncpy (tmpfil, m_tmpfil (invo_name), sizeof(tmpfil));
-           if ((yp = fopen (tmpfil, "w+")) == NULL)
-               padios (tmpfil, "unable to create");
-           unlink (tmpfil);
+            char *tfile = m_mktemp2(NULL, invo_name, NULL, &yp);
+            if (tfile == NULL) padios("msh", "unable to create temporary 
file");
+            unlink(tfile);
+            strncpy(tmpfil, tfile, sizeof(tmpfil));
 
            if (pop_top (Msgs[msgnum].m_top, 4, pop_action) == NOTOK)
                padios (NULL, "%s", response);
@@ -1163,7 +1163,7 @@
 void
 readids (int id)
 {
-    register int cur, seqnum, i, msgnum;
+    register int cur, seqnum, i=0, msgnum;
 
     if (mp->curmsg == 0)
        seq_setcur (mp, mp->lowmsg);

Index: uip/mshcmds.c
===================================================================
RCS file: /cvsroot/nmh/nmh/uip/mshcmds.c,v
retrieving revision 1.16
retrieving revision 1.17
diff -u -b -r1.16 -r1.17
--- uip/mshcmds.c       13 Apr 2007 11:53:08 -0000      1.16
+++ uip/mshcmds.c       4 Feb 2010 01:39:22 -0000       1.17
@@ -2,7 +2,7 @@
 /*
  * mshcmds.c -- command handlers in msh
  *
- * $Id: mshcmds.c,v 1.16 2007/04/13 11:53:08 jjr Exp $
+ * $Id: mshcmds.c,v 1.17 2010/02/04 01:39:22 ehood Exp $
  *
  * This code is Copyright (c) 2002, by the authors of nmh.  See the
  * COPYRIGHT file in the root directory of the nmh distribution for
@@ -867,6 +867,8 @@
     int        msgp = 0, vecp = 1, msgnum;
     char *cp, *filter = NULL, buf[BUFSIZ];
     char *msgs[MAXARGS], *vec[MAXARGS];
+    char *tfile = NULL;
+    char tmpfil[BUFSIZ];
 
     if (fmsh) {
        forkcmd (args, cmd_name);
@@ -939,16 +941,12 @@
 
                                        /* foil search of .mh_profile */
     snprintf (buf, sizeof(buf), "%sXXXXXX", invo_name);
-/*
-  Mkstemp work postponed until later -Doug
-#ifdef HAVE_MKSTEMP
-    vec[0] = (char *)mkstemp (buf);
-#else
-*/
-    vec[0] = (char *)mktemp (buf);
-/*
-#endif
-*/
+
+    tfile = m_mktemp(buf, NULL, NULL);
+    if (tfile == NULL) adios("forwcmd", "unable to create temporary file");
+    strncpy (tmpfil, tfile, sizeof(tmpfil));
+    vec[0] = tmpfil;
+
     vec[vecp++] = "-file";
     vec[vecp] = NULL;
     if (!msgp)
@@ -979,10 +977,14 @@
 forw (char *proc, char *filter, int vecp, char **vec)
 {
     int i, child_id, msgnum, msgcnt;
-    char tmpfil[80], *args[MAXARGS];
+    char tmpfil[BUFSIZ], *args[MAXARGS];
     FILE *out;
+    char *tfile = NULL;
+
+    tfile = m_mktemp2(NULL, invo_name, NULL, NULL);
+    if (tfile == NULL) adios("forw", "unable to create temporary file");
+    strncpy (tmpfil, tfile, sizeof(tmpfil));
 
-    strncpy (tmpfil, m_tmpfil (invo_name), sizeof(tmpfil));
     interrupted = 0;
     if (filter)
        switch (child_id = fork ()) {
@@ -2995,8 +2997,9 @@
 process (int msgnum, char *proc, int vecp, char **vec)
 {
     int        child_id, status;
-    char tmpfil[80];
+    char tmpfil[BUFSIZ];
     FILE *out;
+    char *cp;
 
     if (fmsh) {
        strncpy (tmpfil, m_name (msgnum), sizeof(tmpfil));
@@ -3007,23 +3010,20 @@
        goto ready;
     }
 
-    strncpy (tmpfil, m_scratch ("", invo_name), sizeof(tmpfil));
-    if ((out = fopen (tmpfil, "w")) == NULL) {
-       int olderr;
-       char newfil[80];
-
-       olderr = errno;
-       strncpy (newfil, m_tmpfil (invo_name), sizeof(newfil));
-       if ((out = fopen (newfil, "w")) == NULL) {
+    cp = m_mktemp(invo_name, NULL, &out);
+    if (cp == NULL) {
+        /* Try again, but try to create under /tmp */
+       int olderr = errno;
+        cp = m_mktemp2(NULL, invo_name, NULL, &out);
+        if (cp == NULL) {
            errno = olderr;
-           advise (tmpfil, "unable to create temporary file");
+           advise (NULL, "unable to create temporary file");
            return NOTOK;
-       } else {
-           strncpy (tmpfil, newfil, sizeof(tmpfil));
        }
     }
     copy_message (msgnum, out);
     fclose (out);
+    strncpy(tmpfil, cp, sizeof(tmpfil));
 
 ready: ;
     fflush (stdout);
@@ -3089,7 +3089,7 @@
 copy_digest (int msgnum, FILE *out)
 {
     char c;
-    long pos;
+    long pos = 0L;
     static char buffer[BUFSIZ];
     register FILE *zp;
 

Index: uip/new.c
===================================================================
RCS file: /cvsroot/nmh/nmh/uip/new.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -b -r1.2 -r1.3
--- uip/new.c   30 Dec 2009 01:41:47 -0000      1.2
+++ uip/new.c   4 Feb 2010 01:39:22 -0000       1.3
@@ -4,7 +4,7 @@
  *       -- as fnext,  move to next folder with unseen messages
  *       -- as fprev,  move to previous folder with unseen messages
  *       -- as unseen, scan all unseen messages
- * $Id: new.c,v 1.2 2009/12/30 01:41:47 levine Exp $
+ * $Id: new.c,v 1.3 2010/02/04 01:39:22 ehood Exp $
  *
  * This code is Copyright (c) 2008, by the authors of nmh.  See the
  * COPYRIGHT file in the root directory of the nmh distribution for
@@ -300,7 +300,7 @@
     struct node *first, *cur_node, *node, *last, *prev;
     size_t folder_len;
     int count, total = 0;
-    char *command, *sequences_s;
+    char *command = NULL, *sequences_s = NULL;
 
     if (cur == NULL || cur[0] == '\0') {
         cur = "inbox";

Index: uip/popsbr.c
===================================================================
RCS file: /cvsroot/nmh/nmh/uip/popsbr.c,v
retrieving revision 1.20
retrieving revision 1.21
diff -u -b -r1.20 -r1.21
--- uip/popsbr.c        16 Jan 2009 02:28:55 -0000      1.20
+++ uip/popsbr.c        4 Feb 2010 01:39:22 -0000       1.21
@@ -1,7 +1,7 @@
 /*
  * popsbr.c -- POP client subroutines
  *
- * $Id: popsbr.c,v 1.20 2009/01/16 02:28:55 kenh Exp $
+ * $Id: popsbr.c,v 1.21 2010/02/04 01:39:22 ehood Exp $
  *
  * This code is Copyright (c) 2002, by the authors of nmh.  See the
  * COPYRIGHT file in the root directory of the nmh distribution for
@@ -1103,7 +1103,7 @@
 static int
 sasl_getline (char *s, int n, FILE *iop)
 {
-    int c;
+    int c = -2;
     char *p;
 
     p = s;

Index: uip/post.c
===================================================================
RCS file: /cvsroot/nmh/nmh/uip/post.c,v
retrieving revision 1.23
retrieving revision 1.24
diff -u -b -r1.23 -r1.24
--- uip/post.c  16 Jan 2009 02:28:55 -0000      1.23
+++ uip/post.c  4 Feb 2010 01:39:22 -0000       1.24
@@ -2,7 +2,7 @@
 /*
  * post.c -- enter messages into the mail transport system
  *
- * $Id: post.c,v 1.23 2009/01/16 02:28:55 kenh Exp $
+ * $Id: post.c,v 1.24 2010/02/04 01:39:22 ehood Exp $
  *
  * This code is Copyright (c) 2002, by the authors of nmh.  See the
  * COPYRIGHT file in the root directory of the nmh distribution for
@@ -554,13 +554,14 @@
            if ((out = fopen (fill_in ? fill_in : "/dev/null", "w")) == NULL)
                adios ("/dev/null", "unable to open");
        } else {
-           strncpy (tmpfil, m_scratch ("", m_maildir (invo_name)),
-               sizeof(tmpfil));
-           if ((out = fopen (tmpfil, "w")) == NULL) {
-               strncpy (tmpfil, m_tmpfil (invo_name), sizeof(tmpfil));
-               if ((out = fopen (tmpfil, "w")) == NULL)
-                   adios (tmpfil, "unable to create");
+            char *cp = m_mktemp(m_maildir(invo_name), NULL, &out);
+            if (cp == NULL) {
+                cp = m_mktemp2(NULL, invo_name, NULL, &out);
+                if (cp == NULL) {
+                   adios ("post", "unable to create temporary file");
            }
+            }
+            strncpy(tmpfil, cp, sizeof(tmpfil));
            chmod (tmpfil, 0600);
        }
     }
@@ -662,7 +663,7 @@
     int count, grp, i, keep;
     char *cp, *pp, *qp;
     char namep[BUFSIZ];
-    struct mailname *mp, *np;
+    struct mailname *mp = NULL, *np = NULL;
     struct headers *hdr;
 
     while (*str == ' ' || *str == '\t')
@@ -1166,11 +1167,12 @@
     pid_t child_id;
     char *vec[6];
     FILE *out;
+    char *tfile = NULL;
 
-    strncpy (bccfil, m_tmpfil ("bccs"), sizeof(bccfil));
-    if ((out = fopen (bccfil, "w")) == NULL)
-       adios (bccfil, "unable to create");
+    tfile = m_mktemp2(NULL, "bccs", NULL, &out);
+    if (tfile == NULL) adios("bcc", "unable to create temporary file");
     chmod (bccfil, 0600);
+    strncpy (bccfil, tfile, sizeof(bccfil));
 
     fprintf (out, "Date: %s\n", dtime (&tclock, 0));
     if (msgid)

Index: uip/prompter.c
===================================================================
RCS file: /cvsroot/nmh/nmh/uip/prompter.c,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -b -r1.6 -r1.7
--- uip/prompter.c      4 Nov 2007 11:54:35 -0000       1.6
+++ uip/prompter.c      4 Feb 2010 01:39:22 -0000       1.7
@@ -2,7 +2,7 @@
 /*
  * prompter.c -- simple prompting editor front-end
  *
- * $Id: prompter.c,v 1.6 2007/11/04 11:54:35 jjr Exp $
+ * $Id: prompter.c,v 1.7 2010/02/04 01:39:22 ehood Exp $
  *
  * This code is Copyright (c) 2002, by the authors of nmh.  See the
  * COPYRIGHT file in the root directory of the nmh distribution for
@@ -108,6 +108,7 @@
     char buffer[BUFSIZ], tmpfil[BUFSIZ];
     char **arguments, **argp;
     FILE *in, *out;
+    char *tfile = NULL;
 
 #ifdef LOCALE
     setlocale(LC_ALL, "");
@@ -185,10 +186,10 @@
     if ((in = fopen (drft, "r")) == NULL)
        adios (drft, "unable to open");
 
-    strncpy (tmpfil, m_tmpfil (invo_name), sizeof(tmpfil));
-    if ((out = fopen (tmpfil, "w")) == NULL)
-       adios (tmpfil, "unable to create");
+    tfile = m_mktemp2(NULL, invo_name, NULL, &out);
+    if (tfile == NULL) adios("prompter", "unable to create temporary file");
     chmod (tmpfil, 0600);
+    strncpy (tmpfil, tfile, sizeof(tmpfil));
 
     /*
      * Are we changing the kill or erase character?

Index: uip/rcvdist.c
===================================================================
RCS file: /cvsroot/nmh/nmh/uip/rcvdist.c,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -b -r1.13 -r1.14
--- uip/rcvdist.c       2 Jun 2008 22:37:02 -0000       1.13
+++ uip/rcvdist.c       4 Feb 2010 01:39:22 -0000       1.14
@@ -2,7 +2,7 @@
 /*
  * rcvdist.c -- asynchronously redistribute messages
  *
- * $Id: rcvdist.c,v 1.13 2008/06/02 22:37:02 pm215 Exp $
+ * $Id: rcvdist.c,v 1.14 2010/02/04 01:39:22 ehood Exp $
  *
  * This code is Copyright (c) 2002, by the authors of nmh.  See the
  * COPYRIGHT file in the root directory of the nmh distribution for
@@ -44,7 +44,8 @@
     int i, vecp = 1;
     char *addrs = NULL, *cp, *form = NULL, buf[BUFSIZ];
     char **argp, **arguments, *vec[MAXARGS];
-    register FILE *fp;
+    FILE *fp;
+    char *tfile = NULL;
 
     done=unlink_done;
 
@@ -94,12 +95,18 @@
            invo_name);
 
     umask (~m_gmprot ());
-    strncpy (tmpfil, m_tmpfil (invo_name), sizeof(tmpfil));
-    if ((fp = fopen (tmpfil, "w+")) == NULL)
-       adios (tmpfil, "unable to create");
+
+    tfile = m_mktemp2(NULL, invo_name, NULL, &fp);
+    if (tfile == NULL) adios("rcvdist", "unable to create temporary file");
+    strncpy (tmpfil, tfile, sizeof(tmpfil));
+
     cpydata (fileno (stdin), fileno (fp), "message", tmpfil);
     fseek (fp, 0L, SEEK_SET);
-    strncpy (drft, m_tmpfil (invo_name), sizeof(drft));
+
+    tfile = m_mktemp2(NULL, invo_name, NULL, NULL);
+    if (tfile == NULL) adios("forw", "unable to create temporary file");
+    strncpy (drft, tfile, sizeof(tmpfil));
+
     rcvdistout (fp, form, addrs);
     fclose (fp);
 

Index: uip/rcvstore.c
===================================================================
RCS file: /cvsroot/nmh/nmh/uip/rcvstore.c,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -b -r1.14 -r1.15
--- uip/rcvstore.c      2 Jun 2008 22:37:02 -0000       1.14
+++ uip/rcvstore.c      4 Feb 2010 01:39:22 -0000       1.15
@@ -2,7 +2,7 @@
 /*
  * rcvstore.c -- asynchronously add mail to a folder
  *
- * $Id: rcvstore.c,v 1.14 2008/06/02 22:37:02 pm215 Exp $
+ * $Id: rcvstore.c,v 1.15 2010/02/04 01:39:22 ehood Exp $
  *
  * This code is Copyright (c) 2002, by the authors of nmh.  See the
  * COPYRIGHT file in the root directory of the nmh distribution for
@@ -173,9 +173,10 @@
     SIGNAL (SIGTERM, SIG_IGN);
 
     /* create a temporary file */
-    tmpfilenam = m_scratch ("", invo_name);
-    if ((fd = creat (tmpfilenam, m_gmprot ())) == NOTOK)
-       adios (tmpfilenam, "unable to create");
+    tmpfilenam = m_mktemp (invo_name, &fd, NULL);
+    if (tmpfilenam == NULL) {
+       adios ("rcvstore", "unable to create temporary file");
+    }
     chmod (tmpfilenam, m_gmprot());
 
     /* copy the message from stdin into temp file */

Index: uip/rcvtty.c
===================================================================
RCS file: /cvsroot/nmh/nmh/uip/rcvtty.c,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -b -r1.14 -r1.15
--- uip/rcvtty.c        11 Apr 2008 14:12:55 -0000      1.14
+++ uip/rcvtty.c        4 Feb 2010 01:39:22 -0000       1.15
@@ -2,7 +2,7 @@
 /*
  * rcvtty.c -- a rcvmail program (a lot like rcvalert) handling IPC ttys
  *
- * $Id: rcvtty.c,v 1.14 2008/04/11 14:12:55 opk Exp $
+ * $Id: rcvtty.c,v 1.15 2010/02/04 01:39:22 ehood Exp $
  *
  * This code is Copyright (c) 2002, by the authors of nmh.  See the
  * COPYRIGHT file in the root directory of the nmh distribution for
@@ -287,12 +287,12 @@
 header_fd (void)
 {
     int fd;
-    char *nfs, tmpfil[BUFSIZ];
+    char *nfs;
+    char *tfile = NULL;
 
-    strncpy (tmpfil, m_tmpfil (invo_name), sizeof(tmpfil));
-    if ((fd = open (tmpfil, O_RDWR | O_CREAT | O_TRUNC, 0600)) == NOTOK)
-       return NOTOK;
-    unlink (tmpfil);
+    tfile = m_mktemp2(NULL, invo_name, &fd, NULL);
+    if (tfile == NULL) return NOTOK;
+    unlink (tfile);
 
     rewind (stdin);
 

Index: uip/scansbr.c
===================================================================
RCS file: /cvsroot/nmh/nmh/uip/scansbr.c,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -b -r1.13 -r1.14
--- uip/scansbr.c       8 Aug 2008 23:45:24 -0000       1.13
+++ uip/scansbr.c       4 Feb 2010 01:39:22 -0000       1.14
@@ -2,7 +2,7 @@
 /*
  * scansbr.c -- routines to help scan along...
  *
- * $Id: scansbr.c,v 1.13 2008/08/08 23:45:24 epg Exp $
+ * $Id: scansbr.c,v 1.14 2010/02/04 01:39:22 ehood Exp $
  *
  * This code is Copyright (c) 2002, by the authors of nmh.  See the
  * COPYRIGHT file in the root directory of the nmh distribution for
@@ -81,11 +81,11 @@
     int i, compnum, encrypted, state;
     unsigned char *cp, *tmpbuf;
     char **nxtbuf;
-    char *saved_c_text;
+    char *saved_c_text = NULL;
     struct comp *cptr;
     struct comp **savecomp;
-    char *scnmsg;
-    FILE *scnout;
+    char *scnmsg = NULL;
+    FILE *scnout = NULL;
     char name[NAMESZ];
     static int rlwidth, slwidth;
 

Index: uip/send.c
===================================================================
RCS file: /cvsroot/nmh/nmh/uip/send.c,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -b -r1.10 -r1.11
--- uip/send.c  16 Jan 2009 02:28:55 -0000      1.10
+++ uip/send.c  4 Feb 2010 01:39:22 -0000       1.11
@@ -2,7 +2,7 @@
 /*
  * send.c -- send a composed message
  *
- * $Id: send.c,v 1.10 2009/01/16 02:28:55 kenh Exp $
+ * $Id: send.c,v 1.11 2010/02/04 01:39:22 ehood Exp $
  *
  * This code is Copyright (c) 2002, by the authors of nmh.  See the
  * COPYRIGHT file in the root directory of the nmh distribution for
@@ -423,7 +423,7 @@
            && (distsw = atoi (cp))
            && altmsg) {
        vec[vecp++] = "-dist";
-       distfile = getcpy (m_scratch (altmsg, invo_name));
+       distfile = getcpy (m_mktemp2 (altmsg, invo_name, NULL, NULL));
        if (link (altmsg, distfile) == NOTOK) {
            if (errno != EXDEV
 #ifdef EISREMOTE
@@ -432,7 +432,7 @@
                )
                adios (distfile, "unable to link %s to", altmsg);
            free (distfile);
-           distfile = getcpy (m_tmpfil (invo_name));
+           distfile = getcpy (m_mktemp2(NULL, invo_name, NULL, NULL));
            {
                int in, out;
                struct stat st;

Index: uip/sendsbr.c
===================================================================
RCS file: /cvsroot/nmh/nmh/uip/sendsbr.c,v
retrieving revision 1.18
retrieving revision 1.19
diff -u -b -r1.18 -r1.19
--- uip/sendsbr.c       2 Jun 2008 22:37:02 -0000       1.18
+++ uip/sendsbr.c       4 Feb 2010 01:39:22 -0000       1.19
@@ -2,7 +2,7 @@
 /*
  * sendsbr.c -- routines to help WhatNow/Send along
  *
- * $Id: sendsbr.c,v 1.18 2008/06/02 22:37:02 pm215 Exp $
+ * $Id: sendsbr.c,v 1.19 2010/02/04 01:39:22 ehood Exp $
  *
  * This code is Copyright (c) 2002, by the authors of nmh.  See the
  * COPYRIGHT file in the root directory of the nmh distribution for
@@ -125,8 +125,11 @@
         * rename the draft file.  I'm not quite sure why.
         */
        if (pushsw && unique) {
-           if (rename (drft, strncpy (file, m_scratch (drft, invo_name), 
sizeof(file)))
-                   == NOTOK)
+            char *cp = m_mktemp2(drft, invo_name, NULL, NULL);
+            if (cp == NULL) {
+                adios ("sendsbr", "unable to create temporary file");
+            }
+           if (rename (drft, strncpy(file, cp, sizeof(file))) == NOTOK)
                adios (file, "unable to rename %s to", drft);
            drft = file;
        }
@@ -253,8 +256,12 @@
      * Make names for the temporary files.
      */
 
-    (void)strncpy(body_file_name, m_scratch("", m_maildir(invo_name)), sizeof 
(body_file_name));
-    (void)strncpy(composition_file_name, m_scratch("", m_maildir(invo_name)), 
sizeof (composition_file_name));
+    (void)strncpy(body_file_name,
+                  m_mktemp(m_maildir(invo_name), NULL, NULL),
+                  sizeof (body_file_name));
+    (void)strncpy(composition_file_name,
+                  m_mktemp(m_maildir(invo_name), NULL, NULL),
+                  sizeof (composition_file_name));
 
     if (has_body)
        body_file = fopen(body_file_name, "w");
@@ -676,9 +683,11 @@
        char tmpdrf[BUFSIZ];
        FILE *out;
 
-       strncpy (tmpdrf, m_scratch (drft, invo_name), sizeof(tmpdrf));
-       if ((out = fopen (tmpdrf, "w")) == NULL)
-           adios (tmpdrf, "unable to open for writing");
+       char *cp = m_mktemp2(drft, invo_name, NULL, &out);
+        if (cp == NULL) {
+           adios (drft, "unable to create temporary file for");
+        }
+       strncpy(tmpdrf, cp, sizeof(tmpdrf));
        chmod (tmpdrf, 0600);
 
        /*
@@ -919,16 +928,17 @@
 tmp_fd (void)
 {
     int fd;
-    char tmpfil[BUFSIZ];
+    char *tfile = NULL;
+
+    tfile = m_mktemp2(NULL, invo_name, &fd, NULL);
+    if (tfile == NULL) return NOTOK;
+    fchmod(fd, 0600);
 
-    strncpy (tmpfil, m_tmpfil (invo_name), sizeof(tmpfil));
-    if ((fd = open (tmpfil, O_RDWR | O_CREAT | O_TRUNC, 0600)) == NOTOK)
-       return NOTOK;
     if (debugsw)
-       advise (NULL, "temporary file %s selected", tmpfil);
+       advise (NULL, "temporary file %s selected", tfile);
     else
-       if (unlink (tmpfil) == NOTOK)
-           advise (tmpfil, "unable to remove");
+       if (unlink (tfile) == NOTOK)
+           advise (tfile, "unable to remove");
 
     return fd;
 }

Index: uip/show.c
===================================================================
RCS file: /cvsroot/nmh/nmh/uip/show.c,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -b -r1.10 -r1.11
--- uip/show.c  13 Apr 2007 11:53:08 -0000      1.10
+++ uip/show.c  4 Feb 2010 01:39:22 -0000       1.11
@@ -2,7 +2,7 @@
 /*
  * show.c -- show/list messages
  *
- * $Id: show.c,v 1.10 2007/04/13 11:53:08 jjr Exp $
+ * $Id: show.c,v 1.11 2010/02/04 01:39:22 ehood Exp $
  *
  * This code is Copyright (c) 2002, by the authors of nmh.  See the
  * COPYRIGHT file in the root directory of the nmh distribution for
@@ -71,7 +71,7 @@
     char *cp, *maildir, *file = NULL, *folder = NULL, *proc;
     char buf[BUFSIZ], **argp, **arguments;
     char *msgs[MAXARGS], *vec[MAXARGS];
-    struct msgs *mp;
+    struct msgs *mp = NULL;
 
 #ifdef LOCALE
     setlocale(LC_ALL, "");

Index: uip/slocal.c
===================================================================
RCS file: /cvsroot/nmh/nmh/uip/slocal.c,v
retrieving revision 1.27
retrieving revision 1.28
diff -u -b -r1.27 -r1.28
--- uip/slocal.c        11 Apr 2008 14:12:55 -0000      1.27
+++ uip/slocal.c        4 Feb 2010 01:39:22 -0000       1.28
@@ -2,7 +2,7 @@
 /*
  * slocal.c -- asynchronously filter and deliver new mail
  *
- * $Id: slocal.c,v 1.27 2008/04/11 14:12:55 opk Exp $
+ * $Id: slocal.c,v 1.28 2010/02/04 01:39:22 ehood Exp $
  *
  * This code is Copyright (c) 2002, by the authors of nmh.  See the
  * COPYRIGHT file in the root directory of the nmh distribution for
@@ -1274,12 +1274,12 @@
     int i, first = 1, fd1, fd2;
     char buffer[BUFSIZ];
     FILE *qfp, *ffp;
+    char *tfile = NULL;
 
-    strcpy (tmpfil, m_tmpfil (invo_name));
-
-    /* open temporary file to put message in */
-    if ((fd1 = open (tmpfil, O_RDWR | O_CREAT | O_TRUNC, 0600)) == -1)
-       return -1;
+    tfile = m_mktemp2(NULL, invo_name, &fd1, NULL);
+    if (tfile == NULL) return -1;
+    fchmod(fd1, 0600);
+    strncpy (tmpfil, tfile, BUFSIZ);
 
     if (!fold) {
        while ((i = read (qd, buffer, sizeof(buffer))) > 0)

Index: uip/viamail.c
===================================================================
RCS file: /cvsroot/nmh/nmh/uip/viamail.c,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -b -r1.11 -r1.12
--- uip/viamail.c       4 Nov 2007 11:54:36 -0000       1.11
+++ uip/viamail.c       4 Feb 2010 01:39:22 -0000       1.12
@@ -2,7 +2,7 @@
 /*
  * viamail.c -- send multiple files in a MIME message
  *
- * $Id: viamail.c,v 1.11 2007/11/04 11:54:36 jjr Exp $
+ * $Id: viamail.c,v 1.12 2010/02/04 01:39:22 ehood Exp $
  *
  * This code is Copyright (c) 2002, by the authors of nmh.  See the
  * COPYRIGHT file in the root directory of the nmh distribution for
@@ -181,13 +181,14 @@
     char *vec[MAXARGS];
     struct stat st;
     FILE *fp;
+    char *tfile = NULL;
 
     umask (~m_gmprot ());
 
-    strncpy (tmpfil, m_tmpfil (invo_name), sizeof(tmpfil));
-    if ((fp = fopen (tmpfil, "w+")) == NULL)
-       adios (tmpfil, "unable to open for writing");
-    chmod (tmpfil, 0600);
+    tfile = m_mktemp2(NULL, invo_name, NULL, &fp);
+    if (tfile == NULL) adios("viamail", "unable to create temporary file");
+    chmod(tfile, 0600);
+    strncpy (tmpfil, tfile, sizeof(tmpfil));
 
     if (!strchr(mailsw, '@'))
        mailsw = concat (mailsw, "@", LocalName (), NULL);

Index: uip/whatnowsbr.c
===================================================================
RCS file: /cvsroot/nmh/nmh/uip/whatnowsbr.c,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -b -r1.13 -r1.14
--- uip/whatnowsbr.c    21 Jan 2009 19:38:36 -0000      1.13
+++ uip/whatnowsbr.c    4 Feb 2010 01:39:22 -0000       1.14
@@ -2,7 +2,7 @@
 /*
  * whatnowsbr.c -- the WhatNow shell
  *
- * $Id: whatnowsbr.c,v 1.13 2009/01/21 19:38:36 kenh Exp $
+ * $Id: whatnowsbr.c,v 1.14 2010/02/04 01:39:22 ehood Exp $
  *
  * This code is Copyright (c) 2002, by the authors of nmh.  See the
  * COPYRIGHT file in the root directory of the nmh distribution for
@@ -634,7 +634,7 @@
     struct stat st;
 
 #ifdef HAVE_LSTAT
-    int        slinked;
+    int        slinked = 0;
 #if 0
     int oumask;        /* PJS: for setting permissions on symlinks. */
 #endif
@@ -1315,7 +1315,7 @@
 #endif /* not lint */
            && altmsg) {
        vec[vecp++] = "-dist";
-       distfile = getcpy (m_scratch (altmsg, invo_name));
+       distfile = getcpy (m_mktemp2(altmsg, invo_name, NULL, NULL));
        if (link (altmsg, distfile) == NOTOK)
            adios (distfile, "unable to link %s to", altmsg);
     } else {

Index: sbr/m_mktemp.c
===================================================================
RCS file: sbr/m_mktemp.c
diff -N sbr/m_mktemp.c
--- /dev/null   1 Jan 1970 00:00:00 -0000
+++ sbr/m_mktemp.c      4 Feb 2010 01:39:21 -0000       1.1
@@ -0,0 +1,147 @@
+/*
+ * m_mktemp.c -- Construct a temporary file.
+ *
+ * $Id: m_mktemp.c,v 1.1 2010/02/04 01:39:21 ehood Exp $
+ *
+ * This code is Copyright (c) 2010, by the authors of nmh.  See the
+ * COPYRIGHT file in the root directory of the nmh distribution for
+ * complete copyright information.
+ */
+
+#include <errno.h>
+#include <h/mh.h>
+
+static char *get_temp_dir();
+
+/*  Create a temporary file.  If pfx_in is null, the temporary file
+ *  will be created in the temporary directory (more on that later).
+ *  If pfx_in is not null, then the temporary file location will be
+ *  defined by the value pfx_in.
+ *
+ *  The file created will be at the pathname specified appended with
+ *  6 random (we hope :) characters.
+ *
+ *  The return value will be the pathname to the file created.
+ *
+ *  CAUTION: The return pointer references static data.  If
+ *  you need to modify, or save, the return string, make a copy of it
+ *  first.
+ *
+ *  When pfx_in is null, the temporary directory is determined as
+ *  follows, in order:
+ *  
+ *    MHTMPDIR envvar
+ *    TMPDIR envvar
+ *    TMP envvar
+ *    User's mail directory.
+ *
+ *  NOTE: One will probably use m_mktemp2() instead of this function.
+ *  For example, if you want to create a temp file in the defined
+ *  temporary directory, but with a custom basename prefix, do
+ *  something like the following:
+ *
+ *    char *tmp_pathname = m_mktemp2(NULL, "mypre", ...);
+ */
+char *
+m_mktemp (
+    const char *pfx_in,   /* Pathname prefix for temporary file. */
+    int *fd_ret,          /* (return,optional) File descriptor to temp file. */
+    FILE **fp_ret         /* (return,optional) FILE pointer to temp file. */
+)
+{
+    static char tmpfil[BUFSIZ];
+    int fd = -1;
+    int keep_open = 0;
+    mode_t oldmode = umask(077);
+
+    if (pfx_in == NULL) {
+        snprintf(tmpfil, sizeof(tmpfil), "%s/nmhXXXXXX", get_temp_dir());
+    } else {
+        snprintf(tmpfil, sizeof(tmpfil), "%sXXXXXX", pfx_in);
+    }
+
+    fd = mkstemp(tmpfil);
+    if (fd < 0) {
+        umask(oldmode);
+        return NULL;
+    }
+    if (fd_ret != NULL) {
+        *fd_ret = fd;
+        keep_open = 1;
+    }
+    if (fp_ret != NULL) {
+        FILE *fp = fdopen(fd, "w+");
+        if (fp == NULL) {
+            int olderr = errno;
+            unlink(tmpfil);
+            close(fd);
+            errno = olderr;
+            umask(oldmode);
+            return NULL;
+        }
+        *fp_ret = fp;
+        keep_open = 1;
+    }
+    if (!keep_open) {
+        close(fd);
+    }
+    umask(oldmode);
+    return tmpfil;
+}
+
+/* This version allows one to specify the directory the temp file should
+ * by created based on a given pathname.  Although m_mktemp() technically
+ * supports this, this version is when the directory is defined by
+ * a separate variable from the prefix, eliminating the caller from having
+ * to do string manipulation to generate the desired. pathname prefix.
+ *
+ * The pfx_in parameter specifies a basename prefix for the file.  If dir_in
+ * is NULL, then the defined temporary directory (see comments to m_mktemp()
+ * above) is used to create the temp file.
+ */
+char *
+m_mktemp2 (
+    const char *dir_in,   /* Directory to place temp file. */
+    const char *pfx_in,   /* Basename prefix for temp file. */
+    int *fd_ret,          /* (return,optional) File descriptor to temp file. */
+    FILE **fp_ret         /* (return,optional) FILE pointer to temp file. */
+)
+{
+    static char buffer[BUFSIZ];
+    char *cp;
+
+    if (dir_in == NULL) {
+        if (pfx_in == NULL) {
+            return m_mktemp(NULL, fd_ret, fp_ret);
+        }
+        snprintf(buffer, sizeof(buffer), "%s/%s", get_temp_dir(), pfx_in);
+        return m_mktemp(buffer, fd_ret, fp_ret);
+    }
+
+    if ((cp = r1bindex ((char *)dir_in, '/')) == dir_in) {
+        /* No directory component */
+        return m_mktemp(pfx_in, fd_ret, fp_ret);
+    }
+    int n = (int)(cp-dir_in-1); /* Length of dir component */
+    snprintf(buffer, sizeof(buffer), "%.*s%s", n, dir_in, pfx_in);
+    return m_mktemp(buffer, fd_ret, fp_ret);
+}
+
+
+static char *
+get_temp_dir()
+{
+    // Ignore envvars if we are setuid
+    if ((getuid()==geteuid()) && (getgid()==getegid())) {
+        char *tmpdir = NULL;
+        tmpdir = getenv("MHTMPDIR");
+        if (tmpdir != NULL && *tmpdir != '\0') return tmpdir;
+
+        tmpdir = getenv("TMPDIR");
+        if (tmpdir != NULL && *tmpdir != '\0') return tmpdir;
+
+        tmpdir = getenv("TMP");
+        if (tmpdir != NULL && *tmpdir != '\0') return tmpdir;
+    }
+    return m_maildir("");
+}




reply via email to

[Prev in Thread] Current Thread [Next in Thread]