]> diplodocus.org Git - nmh/commitdiff
Always check that mktemp()/mktemp2() succeeds before trying to
authorDavid Levine <levinedl@acm.org>
Wed, 22 Jan 2014 02:55:57 +0000 (20:55 -0600)
committerDavid Levine <levinedl@acm.org>
Wed, 22 Jan 2014 02:55:57 +0000 (20:55 -0600)
use result.  And if it fails, have the error message report
the directory where the failed temporary file creation occurred.
And, removed all chmod()'s of temporary files created by mktemp()/
mktemp2() because they set the umask to 077 before calling mkstemp(3).

20 files changed:
uip/annosbr.c
uip/attach.c
uip/burst.c
uip/distsbr.c
uip/forwsbr.c
uip/mhbuild.c
uip/mhbuildsbr.c
uip/mhfixmsg.c
uip/mhparse.c
uip/mhstoresbr.c
uip/post.c
uip/prompter.c
uip/rcvdist.c
uip/rcvstore.c
uip/rcvtty.c
uip/send.c
uip/sendsbr.c
uip/slocal.c
uip/viamail.c
uip/whatnowsbr.c

index ae9df280b04b3ac0477429e254e654630915b646..2f40560b51e2c14b991030dfa698b8c5c7d80921 100644 (file)
@@ -184,7 +184,10 @@ annosbr (int fd, char *file, char *comp, char *text, int inplace, int datesw, in
 
     mode = fstat (fd, &st) != NOTOK ? (int) (st.st_mode & 0777) : m_gmprot ();
 
 
     mode = fstat (fd, &st) != NOTOK ? (int) (st.st_mode & 0777) : m_gmprot ();
 
-    strncpy (tmpfil, m_mktemp2(file, "annotate", NULL, &tmp), sizeof(tmpfil));
+    if ((cp = m_mktemp2(file, "annotate", NULL, &tmp)) == NULL) {
+       adios(NULL, "unable to create temporary file in %s", get_temp_dir());
+    }
+    strncpy (tmpfil, cp, sizeof(tmpfil));
     chmod (tmpfil, mode);
 
     /*
     chmod (tmpfil, mode);
 
     /*
index e19a0eba0a20d50be72a78278f0303ca1628ed3c..9ff7d0955598dbe73cc736173478f48c165fb8be 100644 (file)
@@ -100,12 +100,15 @@ attach(char *attachment_header_field_name, char *draft_file_name,
      * Make names for the temporary files.
      */
 
      * Make names for the temporary files.
      */
 
-    (void)strncpy(body_file_name,
-                  m_mktemp2(NULL, invo_name, NULL, NULL),
-                  body_file_name_len);
-    (void)strncpy(composition_file_name,
-                  m_mktemp2(NULL, invo_name, NULL, NULL),
-                  composition_file_name_len);
+    if ((p = m_mktemp2(NULL, invo_name, NULL, NULL)) == NULL) {
+       adios(NULL, "unable to create temporary file in %s", get_temp_dir());
+    }
+    (void)strncpy(body_file_name, p, body_file_name_len);
+    if ((p = m_mktemp2(NULL, invo_name, NULL, NULL)) == NULL) {
+        unlink(body_file_name);
+       adios(NULL, "unable to create temporary file in %s", get_temp_dir());
+    }
+    (void)strncpy(composition_file_name, p, composition_file_name_len);
 
     if (has_body)
        body_file = fopen(body_file_name, "w");
 
     if (has_body)
        body_file = fopen(body_file_name, "w");
index 9b893cfea3b68fa10ddf32d94e7bc1c0a28bfc93..c3f217103c209067d9ea1a062de494df908d1de9 100644 (file)
@@ -464,8 +464,14 @@ burst (struct msgs **mpp, int msgnum, struct smsg *smsgs, int numburst,
 
     i = inplace ? msgnum + numburst : mp->hghmsg;
     for (j = numburst; j >= (inplace ? 0 : 1); i--, j--) {
 
     i = inplace ? msgnum + numburst : mp->hghmsg;
     for (j = numburst; j >= (inplace ? 0 : 1); i--, j--) {
+        char *tempfile;
+
+       if ((tempfile = m_mktemp2(NULL, invo_name, NULL, &out)) == NULL) {
+           adios(NULL, "unable to create temporary file in %s",
+                 get_temp_dir());
+       }
+       strncpy (f2, tempfile, sizeof(f2));
        strncpy (f1, m_name (i), sizeof(f1));
        strncpy (f1, m_name (i), sizeof(f1));
-       strncpy (f2, m_mktemp2(NULL, invo_name, NULL, &out), sizeof(f2));
 
        if (verbosw && i != msgnum)
            printf ("message %d of digest %d becomes message %d\n", j, msgnum, i);
 
        if (verbosw && i != msgnum)
            printf ("message %d of digest %d becomes message %d\n", j, msgnum, i);
index d7a271209e383df2fc99f01f504e33cafebb365b..d371ec1dbf77d709eb332c18b1d849ae50be3172 100644 (file)
@@ -141,9 +141,8 @@ ready_msg (char *msgnam)
 
     cp = m_mktemp2(NULL, "dist", &hdrfd, NULL);
     if (cp == NULL) {
 
     cp = m_mktemp2(NULL, "dist", &hdrfd, NULL);
     if (cp == NULL) {
-        adios("distsbr", "unable to create temporary file");
+       adios(NULL, "unable to create temporary file in %s", get_temp_dir());
     }
     }
-    fchmod(hdrfd, 0600);
     strncpy(tmpfil, cp, sizeof(tmpfil));
     if ((out = dup (hdrfd)) == NOTOK
            || (ofp = fdopen (out, "w")) == NULL)
     strncpy(tmpfil, cp, sizeof(tmpfil));
     if ((out = dup (hdrfd)) == NOTOK
            || (ofp = fdopen (out, "w")) == NULL)
@@ -170,7 +169,8 @@ ready_msg (char *msgnam)
 
                 cp = m_mktemp2(NULL, "dist", &txtfd, NULL);
                 if (cp == NULL) {
 
                 cp = m_mktemp2(NULL, "dist", &txtfd, NULL);
                 if (cp == NULL) {
-                    adios("distsbr", "unable to create temporary file");
+                   adios(NULL, "unable to create temporary file in %s",
+                         get_temp_dir());
                 }
                 fchmod(txtfd, 0600);
                strncpy (tmpfil, cp, sizeof(tmpfil));
                 }
                 fchmod(txtfd, 0600);
                strncpy (tmpfil, cp, sizeof(tmpfil));
index 48fecb179a6b05f50463e004bf499c2988ff435c..90838e2418dffd06a803c78111067bc040ea2d96 100644 (file)
@@ -174,7 +174,9 @@ finished:
     }
 
     cp = m_mktemp2(NULL, invo_name, NULL, &tmp);
     }
 
     cp = m_mktemp2(NULL, invo_name, NULL, &tmp);
-    if (cp == NULL) adios("forw", "unable to create temporary file");
+    if (cp == NULL) {
+       adios(NULL, "unable to create temporary file in %s", get_temp_dir());
+    }
     strncpy (tmpfil, cp, sizeof(tmpfil));
     unlink (tmpfil);
     if ((in = dup (fileno (tmp))) == NOTOK)
     strncpy (tmpfil, cp, sizeof(tmpfil));
     unlink (tmpfil);
     if ((in = dup (fileno (tmp))) == NOTOK)
index 624cf4b9707a28c15f147e6b607e9b2f1dd06855..f3dc91c7a5772d5fb5dad69a1c8b1869160f56d9 100644 (file)
@@ -315,8 +315,13 @@ main (int argc, char **argv)
      * Process the composition file from standard input.
      */
     if (compfile[0] == '-' && compfile[1] == '\0') {
      * Process the composition file from standard input.
      */
     if (compfile[0] == '-' && compfile[1] == '\0') {
+       if ((cp = m_mktemp2(NULL, invo_name, NULL, &fp)) == NULL) {
+           adios(NULL, "unable to create temporary file in %s",
+                 get_temp_dir());
+       }
+
        /* copy standard input to temporary file */
        /* copy standard input to temporary file */
-       strncpy (infile, m_mktemp2(NULL, invo_name, NULL, &fp), sizeof(infile));
+       strncpy (infile, cp, sizeof(infile));
        while (fgets (buffer, BUFSIZ, stdin))
            fputs (buffer, fp);
        fclose (fp);
        while (fgets (buffer, BUFSIZ, stdin))
            fputs (buffer, fp);
        fclose (fp);
@@ -367,8 +372,10 @@ main (int argc, char **argv)
     cts[1] = NULL;
 
     /* output MIME message to this temporary file */
     cts[1] = NULL;
 
     /* output MIME message to this temporary file */
-    strncpy(outfile, m_mktemp2(compfile, invo_name, NULL, &fp_out),
-            sizeof(outfile));
+    if ((cp = m_mktemp2(compfile, invo_name, NULL, &fp_out)) == NULL) {
+       adios(NULL, "unable to create temporary file in %s", get_temp_dir());
+    }
+    strncpy(outfile, cp, sizeof(outfile));
     unlink_outfile = 1;
 
     /* output the message */
     unlink_outfile = 1;
 
     /* output the message */
index ea47bf0b09e4be80b6fa39eda4a6f0fa576d2252..2b78a364d75742c81949ee4022f8587da8618565 100644 (file)
@@ -527,8 +527,10 @@ user_content (FILE *in, char *file, char *buf, CT *ctp)
        FILE *out;
         char *cp;
 
        FILE *out;
         char *cp;
 
-        cp = m_mktemp2(NULL, invo_name, NULL, &out);
-        if (cp == NULL) adios("mhbuildsbr", "unable to create temporary file");
+       if ((cp = m_mktemp2(NULL, invo_name, NULL, &out)) == NULL) {
+           adios("mhbuildsbr", "unable to create temporary file in %s",
+                 get_temp_dir());
+       }
 
        /* use a temp file to collect the plain text lines */
        ce->ce_file = add (cp, NULL);
 
        /* use a temp file to collect the plain text lines */
        ce->ce_file = add (cp, NULL);
@@ -1087,10 +1089,10 @@ compose_content (CT ct)
            if (!(cp = ci->ci_magic))
                adios (NULL, "internal error(5)");
 
            if (!(cp = ci->ci_magic))
                adios (NULL, "internal error(5)");
 
-            tfile = m_mktemp2(NULL, invo_name, NULL, NULL);
-            if (tfile == NULL) {
-                adios("mhbuildsbr", "unable to create temporary file");
-            }
+           if ((tfile = m_mktemp2(NULL, invo_name, NULL, NULL)) == NULL) {
+               adios("mhbuildsbr", "unable to create temporary file in %s",
+                     get_temp_dir());
+           }
            ce->ce_file = add (tfile, NULL);
            ce->ce_unlink = 1;
 
            ce->ce_file = add (tfile, NULL);
            ce->ce_unlink = 1;
 
index ad4bf0df13f36ba666424377273ffa1dc6b8c42d..d81337d6e42534ea2eec6b994f4939580a93e454 100644 (file)
@@ -290,11 +290,11 @@ main (int argc, char **argv) {
             using_stdin = 1;
 
             if ((cp = m_mktemp2 (NULL, invo_name, &fd, NULL)) == NULL) {
             using_stdin = 1;
 
             if ((cp = m_mktemp2 (NULL, invo_name, &fd, NULL)) == NULL) {
-                adios (NULL, "unable to create temporary file");
+                adios (NULL, "unable to create temporary file in %s",
+                       get_temp_dir());
             } else {
                 free (file);
                 file = add (cp, NULL);
             } else {
                 free (file);
                 file = add (cp, NULL);
-                chmod (file, 0600);
                 cpydata (STDIN_FILENO, fd, "-", file);
             }
 
                 cpydata (STDIN_FILENO, fd, "-", file);
             }
 
@@ -396,7 +396,12 @@ mhfixmsgsbr (CT *ctp, const fix_transformations *fx, char *outfile) {
         modify_inplace = 1;
 
         if ((*ctp)->c_file) {
         modify_inplace = 1;
 
         if ((*ctp)->c_file) {
-            outfile = add (m_mktemp2 (NULL, invo_name, NULL, NULL), NULL);
+            char *tempfile;
+            if ((tempfile = m_mktemp2 (NULL, invo_name, NULL, NULL)) == NULL) {
+                adios (NULL, "unable to create temporary file in %s",
+                       get_temp_dir());
+            }
+            outfile = add (tempfile, NULL);
         } else {
             adios (NULL, "missing both input and output filenames\n");
         }
         } else {
             adios (NULL, "missing both input and output filenames\n");
         }
@@ -534,7 +539,8 @@ fix_boundary (CT *ct, int *message_mods) {
                         status = NOTOK;
                     }
                 } else {
                         status = NOTOK;
                     }
                 } else {
-                    advise (NULL, "unable to create temporary file");
+                    advise (NULL, "unable to create temporary file in %s",
+                            get_temp_dir());
                     status = NOTOK;
                 }
 
                     status = NOTOK;
                 }
 
@@ -1019,7 +1025,13 @@ build_text_plain_part (CT encoded_part) {
            contains the decoded contents.  And the decoding function, such
            as openQuoted, will have set ...->ce_unlink to 1 so that it will
            be unlinked by free_content (). */
            contains the decoded contents.  And the decoding function, such
            as openQuoted, will have set ...->ce_unlink to 1 so that it will
            be unlinked by free_content (). */
-        tmp_plain_file = add (m_mktemp2 (NULL, invo_name, NULL, NULL), NULL);
+        char *tempfile;
+
+        if ((tempfile = m_mktemp2 (NULL, invo_name, NULL, NULL)) == NULL) {
+            advise (NULL, "unable to create temporary file in %s",
+                    get_temp_dir());
+        }
+        tmp_plain_file = add (tempfile, NULL);
         if (reformat_part (tp_part, tmp_plain_file,
                            tp_part->c_ctinfo.ci_type,
                            tp_part->c_ctinfo.ci_subtype,
         if (reformat_part (tp_part, tmp_plain_file,
                            tp_part->c_ctinfo.ci_type,
                            tp_part->c_ctinfo.ci_subtype,
@@ -1090,8 +1102,12 @@ static int
 decode_part (CT ct) {
     char *tmp_decoded;
     int status;
 decode_part (CT ct) {
     char *tmp_decoded;
     int status;
+    char *tempfile;
 
 
-    tmp_decoded = add (m_mktemp2 (NULL, invo_name, NULL, NULL), NULL);
+    if ((tempfile = m_mktemp2 (NULL, invo_name, NULL, NULL)) == NULL) {
+        adios (NULL, "unable to create temporary file in %s", get_temp_dir());
+    }
+    tmp_decoded = add (tempfile, NULL);
     /* The following call will load ct->c_cefile.ce_file with the tmp
        filename of the decoded content.  tmp_decoded will contain the
        encoded output, get rid of that. */
     /* The following call will load ct->c_cefile.ce_file with the tmp
        filename of the decoded content.  tmp_decoded will contain the
        encoded output, get rid of that. */
@@ -1679,8 +1695,14 @@ strip_crs (CT ct, int *message_mods) {
 
             if (has_crs) {
                 int fd;
 
             if (has_crs) {
                 int fd;
-                char *stripped_content_file =
-                    add (m_mktemp2 (NULL, invo_name, &fd, NULL), NULL);
+                char *stripped_content_file;
+                char *tempfile = m_mktemp2 (NULL, invo_name, &fd, NULL); 
+
+                if (tempfile == NULL) {
+                    adios (NULL, "unable to create temporary file in %s",
+                           get_temp_dir());
+                }
+                stripped_content_file = add (tempfile, NULL);
 
                 /* Strip each CR before a LF from the content. */
                 fseeko (*fp, begin, SEEK_SET);
 
                 /* Strip each CR before a LF from the content. */
                 fseeko (*fp, begin, SEEK_SET);
@@ -1832,6 +1854,7 @@ convert_codeset (CT ct, char *dest_codeset, int *message_mods) {
         int opened_input_file = 0;
         char src_buffer[BUFSIZ];
         HF hf;
         int opened_input_file = 0;
         char src_buffer[BUFSIZ];
         HF hf;
+        char *tempfile;
 
         if ((conv_desc = iconv_open (dest_codeset, src_codeset)) ==
             (iconv_t) -1) {
 
         if ((conv_desc = iconv_open (dest_codeset, src_codeset)) ==
             (iconv_t) -1) {
@@ -1839,7 +1862,11 @@ convert_codeset (CT ct, char *dest_codeset, int *message_mods) {
             return -1;
         }
 
             return -1;
         }
 
-        dest = add (m_mktemp2 (NULL, invo_name, &fd, NULL), NULL);
+        if ((tempfile = m_mktemp2 (NULL, invo_name, &fd, NULL)) == NULL) {
+            adios (NULL, "unable to create temporary file in %s",
+                   get_temp_dir());
+        }
+        dest = add (tempfile, NULL);
 
         if (ct->c_cefile.ce_file) {
             file = &ct->c_cefile.ce_file;
 
         if (ct->c_cefile.ce_file) {
             file = &ct->c_cefile.ce_file;
index e15296e5280fb8ecdc39dd06075a97c70b4850ea..9489a8e4c01840ac64bb3c8dc459998954ecd0e7 100644 (file)
@@ -194,11 +194,11 @@ parse_mime (char *file)
     if ((is_stdin = !(strcmp (file, "-")))) {
         char *tfile = m_mktemp2(NULL, invo_name, NULL, &fp);
         if (tfile == NULL) {
     if ((is_stdin = !(strcmp (file, "-")))) {
         char *tfile = m_mktemp2(NULL, invo_name, NULL, &fp);
         if (tfile == NULL) {
-            advise("mhparse", "unable to create temporary file");
+            advise("mhparse", "unable to create temporary file in %s",
+                  get_temp_dir());
             return NULL;
         }
        file = add (tfile, NULL);
             return NULL;
         }
        file = add (tfile, NULL);
-       chmod (file, 0600);
 
        while (fgets (buffer, sizeof(buffer), stdin))
            fputs (buffer, fp);
 
        while (fgets (buffer, sizeof(buffer), stdin))
            fputs (buffer, fp);
@@ -1646,7 +1646,12 @@ openBase64 (CT ct, char **file)
     }
 
     if (*file == NULL) {
     }
 
     if (*file == NULL) {
-       ce->ce_file = add (m_mktemp2(NULL, invo_name, NULL, NULL), NULL);
+       char *tempfile;
+       if ((tempfile = m_mktemp2(NULL, invo_name, NULL, NULL)) == NULL) {
+           adios(NULL, "unable to create temporary file in %s",
+                 get_temp_dir());
+       }
+       ce->ce_file = add (tempfile, NULL);
        ce->ce_unlink = 1;
     } else {
        ce->ce_file = add (*file, NULL);
        ce->ce_unlink = 1;
     } else {
        ce->ce_file = add (*file, NULL);
@@ -1880,7 +1885,12 @@ openQuoted (CT ct, char **file)
     }
 
     if (*file == NULL) {
     }
 
     if (*file == NULL) {
-       ce->ce_file = add (m_mktemp2(NULL, invo_name, NULL, NULL), NULL);
+       char *tempfile;
+       if ((tempfile = m_mktemp2(NULL, invo_name, NULL, NULL)) == NULL) {
+           adios(NULL, "unable to create temporary file in %s",
+                 get_temp_dir());
+       }
+       ce->ce_file = add (tempfile, NULL);
        ce->ce_unlink = 1;
     } else {
        ce->ce_file = add (*file, NULL);
        ce->ce_unlink = 1;
     } else {
        ce->ce_file = add (*file, NULL);
@@ -2104,7 +2114,12 @@ open7Bit (CT ct, char **file)
     }
 
     if (*file == NULL) {
     }
 
     if (*file == NULL) {
-       ce->ce_file = add (m_mktemp2(NULL, invo_name, NULL, NULL), NULL);
+       char *tempfile;
+       if ((tempfile = m_mktemp2(NULL, invo_name, NULL, NULL)) == NULL) {
+           adios(NULL, "unable to create temporary file in %s",
+                 get_temp_dir());
+       }
+       ce->ce_file = add (tempfile, NULL);
        ce->ce_unlink = 1;
     } else {
        ce->ce_file = add (*file, NULL);
        ce->ce_unlink = 1;
     } else {
        ce->ce_file = add (*file, NULL);
@@ -2493,8 +2508,14 @@ openFTP (CT ct, char **file)
        ce->ce_file = add (*file, NULL);
     else if (caching)
        ce->ce_file = add (cachefile, NULL);
        ce->ce_file = add (*file, NULL);
     else if (caching)
        ce->ce_file = add (cachefile, NULL);
-    else
-       ce->ce_file = add (m_mktemp2(NULL, invo_name, NULL, NULL), NULL);
+    else {
+       char *tempfile;
+       if ((tempfile = m_mktemp2(NULL, invo_name, NULL, NULL)) == NULL) {
+           adios(NULL, "unable to create temporary file in %s",
+                 get_temp_dir());
+       }
+       ce->ce_file = add (tempfile, NULL);
+    }
 
     if ((ce->ce_fp = fopen (ce->ce_file, "w+")) == NULL) {
        content_error (ce->ce_file, ct, "unable to fopen for reading/writing");
 
     if ((ce->ce_fp = fopen (ce->ce_file, "w+")) == NULL) {
        content_error (ce->ce_file, ct, "unable to fopen for reading/writing");
@@ -2682,7 +2703,12 @@ openMail (CT ct, char **file)
     }
 
     if (*file == NULL) {
     }
 
     if (*file == NULL) {
-       ce->ce_file = add (m_mktemp2(NULL, invo_name, NULL, NULL), NULL);
+       char *tempfile;
+       if ((tempfile = m_mktemp2(NULL, invo_name, NULL, NULL)) == NULL) {
+           adios(NULL, "unable to create temporary file in %s",
+                 get_temp_dir());
+       }
+       ce->ce_file = add (tempfile, NULL);
        ce->ce_unlink = 1;
     } else {
        ce->ce_file = add (*file, NULL);
        ce->ce_unlink = 1;
     } else {
        ce->ce_file = add (*file, NULL);
@@ -2775,8 +2801,14 @@ openURL (CT ct, char **file)
        ce->ce_file = add(*file, NULL);
     else if (caching)
        ce->ce_file = add(cachefile, NULL);
        ce->ce_file = add(*file, NULL);
     else if (caching)
        ce->ce_file = add(cachefile, NULL);
-    else
-       ce->ce_file = add(m_mktemp2(NULL, invo_name, NULL, NULL), NULL);
+    else {
+       char *tempfile;
+       if ((tempfile = m_mktemp2(NULL, invo_name, NULL, NULL)) == NULL) {
+           adios(NULL, "unable to create temporary file in %s",
+                 get_temp_dir());
+       }
+       ce->ce_file = add (tempfile, NULL);
+    }
 
     if ((ce->ce_fp = fopen(ce->ce_file, "w+")) == NULL) {
        content_error(ce->ce_file, ct, "unable to fopen for read/writing");
 
     if ((ce->ce_fp = fopen(ce->ce_file, "w+")) == NULL) {
        content_error(ce->ce_file, ct, "unable to fopen for read/writing");
index 93d3e90259fc8e90bf2612bd6b2c0b233d320d42..3b68970297ffaa69739a2221abf95bf684d6162f 100644 (file)
@@ -562,7 +562,10 @@ store_content (CT ct, CT p)
            char *tmpfilenam, *folder;
 
            /* Store content in temporary file for now */
            char *tmpfilenam, *folder;
 
            /* Store content in temporary file for now */
-           tmpfilenam = m_mktemp(invo_name, NULL, NULL);
+           if ((tmpfilenam = m_mktemp(invo_name, NULL, NULL)) == NULL) {
+               adios(NULL, "unable to create temporary file in %s",
+                     get_temp_dir());
+           }
            ct->c_storage = add (tmpfilenam, NULL);
 
            /* Get the folder name */
            ct->c_storage = add (tmpfilenam, NULL);
 
            /* Get the folder name */
index 9483dbf6b3b84cac4062083b4bdd4c731cac58a7..2683622e55051115ed8c3af8f2efddcc54c8533a 100644 (file)
@@ -535,12 +535,12 @@ main (int argc, char **argv)
            if ((out = fopen ("/dev/null", "w")) == NULL)
                adios ("/dev/null", "unable to open");
        } else {
            if ((out = fopen ("/dev/null", "w")) == NULL)
                adios ("/dev/null", "unable to open");
        } else {
-            char *cp = m_mktemp2(NULL, invo_name, NULL, &out);
-            if (cp == NULL) {
-                adios ("post", "unable to create temporary file");
-            }
+           char *cp = m_mktemp2(NULL, invo_name, NULL, &out);
+           if (cp == NULL) {
+               adios(NULL, "unable to create temporary file in %s",
+                     get_temp_dir());
+           }
             strncpy(tmpfil, cp, sizeof(tmpfil));
             strncpy(tmpfil, cp, sizeof(tmpfil));
-           chmod (tmpfil, 0600);
        }
     }
 
        }
     }
 
@@ -1279,8 +1279,9 @@ make_bcc_file (int dashstuff)
     FILE *out;
     char *tfile = NULL, *program;
 
     FILE *out;
     char *tfile = NULL, *program;
 
-    tfile = m_mktemp2(NULL, "bccs", NULL, &out);
-    if (tfile == NULL) adios("bcc", "unable to create temporary file");
+    if ((tfile = m_mktemp2(NULL, "bccs", NULL, &out)) == NULL) {
+       adios(NULL, "unable to create temporary file in %s", get_temp_dir());
+    }
     strncpy (bccfil, tfile, sizeof(bccfil));
 
     fprintf (out, "From: %s\n", fullfrom);
     strncpy (bccfil, tfile, sizeof(bccfil));
 
     fprintf (out, "From: %s\n", fullfrom);
index afa81f5f15c10f0972979864d1bf1c5e9ca17489..0aedc8c1d13417abee8ea92249f27cda3cf7f937 100644 (file)
@@ -154,9 +154,9 @@ main (int argc, char **argv)
     if ((in = fopen (drft, "r")) == NULL)
        adios (drft, "unable to open");
 
     if ((in = fopen (drft, "r")) == NULL)
        adios (drft, "unable to open");
 
-    tmpfil = m_mktemp2(NULL, invo_name, NULL, &out);
-    if (tmpfil == NULL) adios("prompter", "unable to create temporary file");
-    chmod (tmpfil, 0600);
+    if ((tmpfil = m_mktemp2(NULL, invo_name, NULL, &out)) == NULL) {
+       adios(NULL, "unable to create temporary file in %s", get_temp_dir());
+    }
 
     /*
      * Are we changing the kill or erase character?
 
     /*
      * Are we changing the kill or erase character?
index 6cc8e27764a3c11bac096440985ccb85dab964ca..4f7a83f7b30635993d17e9eadc97ea900364891e 100644 (file)
@@ -104,15 +104,17 @@ main (int argc, char **argv)
 
     umask (~m_gmprot ());
 
 
     umask (~m_gmprot ());
 
-    tfile = m_mktemp2(NULL, invo_name, NULL, &fp);
-    if (tfile == NULL) adios("rcvdist", "unable to create temporary file");
+    if ((tfile = m_mktemp2(NULL, invo_name, NULL, &fp)) == NULL) {
+       adios(NULL, "unable to create temporary file in %s", get_temp_dir());
+    }
     strncpy (tmpfil, tfile, sizeof(tmpfil));
 
     cpydata (fileno (stdin), fileno (fp), "message", tmpfil);
     fseek (fp, 0L, SEEK_SET);
 
     strncpy (tmpfil, tfile, sizeof(tmpfil));
 
     cpydata (fileno (stdin), fileno (fp), "message", tmpfil);
     fseek (fp, 0L, SEEK_SET);
 
-    tfile = m_mktemp2(NULL, invo_name, NULL, NULL);
-    if (tfile == NULL) adios("forw", "unable to create temporary file");
+    if ((tfile = m_mktemp2(NULL, invo_name, NULL, NULL)) == NULL) {
+       adios(NULL, "unable to create temporary file in %s", get_temp_dir());
+    }
     strncpy (drft, tfile, sizeof(tmpfil));
 
     rcvdistout (fp, form, addrs);
     strncpy (drft, tfile, sizeof(tmpfil));
 
     rcvdistout (fp, form, addrs);
index 2822093e57f851e1b207f82de24512f7effa0093..e6de62b0e9d57f844ed28c7bdefb4aadce02542b 100644 (file)
@@ -164,7 +164,7 @@ main (int argc, char **argv)
     /* create a temporary file */
     tmpfilenam = m_mktemp (invo_name, &fd, NULL);
     if (tmpfilenam == NULL) {
     /* create a temporary file */
     tmpfilenam = m_mktemp (invo_name, &fd, NULL);
     if (tmpfilenam == NULL) {
-       adios ("rcvstore", "unable to create temporary file");
+       adios(NULL, "unable to create temporary file in %s", get_temp_dir());
     }
     chmod (tmpfilenam, m_gmprot());
 
     }
     chmod (tmpfilenam, m_gmprot());
 
index 356234adf3062a5f68ffb603412a76e233ecc9d2..760d22dc839ed25b06e59b0ad44a5be2c7f0c066 100644 (file)
@@ -255,8 +255,10 @@ header_fd (void)
     char *nfs;
     char *tfile = NULL;
 
     char *nfs;
     char *tfile = NULL;
 
-    tfile = m_mktemp2(NULL, invo_name, &fd, NULL);
-    if (tfile == NULL) return NOTOK;
+    if ((tfile = m_mktemp2(NULL, invo_name, &fd, NULL)) == NULL) {
+       advise(NULL, "unable to create temporary file in %s", get_temp_dir());
+        return NOTOK;
+    }
     unlink (tfile);
 
     rewind (stdin);
     unlink (tfile);
 
     rewind (stdin);
index e7ca7157b26a50055ca72fe38c8ddf6a8798b17d..2fabe1c368c8855bbd015361198b1bbb4486aaf4 100644 (file)
@@ -398,7 +398,11 @@ go_to_it:
            && (distsw = atoi (cp))
            && altmsg) {
        vec[vecp++] = "-dist";
            && (distsw = atoi (cp))
            && altmsg) {
        vec[vecp++] = "-dist";
-       distfile = getcpy (m_mktemp2 (altmsg, invo_name, NULL, NULL));
+       if ((cp = m_mktemp2(altmsg, invo_name, NULL, NULL)) == NULL) {
+           adios(NULL, "unable to create temporary file in %s",
+                 get_temp_dir());
+       }
+       distfile = getcpy (cp);
        unlink(distfile);
        if (link (altmsg, distfile) == NOTOK) {
            /* Cygwin with FAT32 filesystem produces EPERM. */
        unlink(distfile);
        if (link (altmsg, distfile) == NOTOK) {
            /* Cygwin with FAT32 filesystem produces EPERM. */
@@ -409,7 +413,11 @@ go_to_it:
                )
                adios (distfile, "unable to link %s to", altmsg);
            free (distfile);
                )
                adios (distfile, "unable to link %s to", altmsg);
            free (distfile);
-           distfile = getcpy (m_mktemp2(NULL, invo_name, NULL, NULL));
+           if ((cp = m_mktemp2(NULL, invo_name, NULL, NULL)) == NULL) {
+               adios(NULL, "unable to create temporary file in %s",
+                     get_temp_dir());
+           }
+           distfile = getcpy (cp);
            {
                int in, out;
                struct stat st;
            {
                int in, out;
                struct stat st;
index 2b9466890210c0a3924bdcf8be85fe2acbd80abc..c1914aa13c675f07ba4c3e4a6f5cd5e86e29059c 100644 (file)
@@ -109,10 +109,11 @@ sendsbr (char **vec, int vecp, char *program, char *drft, struct stat *st,
         * rename the draft file.  I'm not quite sure why.
         */
        if (pushsw && unique) {
         * rename the draft file.  I'm not quite sure why.
         */
        if (pushsw && unique) {
-            char *cp = m_mktemp2(drft, invo_name, NULL, NULL);
-            if (cp == NULL) {
-                adios ("sendsbr", "unable to create temporary file");
-            }
+           char *cp = m_mktemp2(drft, invo_name, NULL, NULL);
+           if (cp == NULL) {
+               adios(NULL, "unable to create temporary file in %s",
+                     get_temp_dir());
+           }
            if (rename (drft, strncpy(file, cp, sizeof(file))) == NOTOK)
                adios (file, "unable to rename %s to", drft);
            drft = file;
            if (rename (drft, strncpy(file, cp, sizeof(file))) == NOTOK)
                adios (file, "unable to rename %s to", drft);
            drft = file;
@@ -321,10 +322,10 @@ splitmsg (char **vec, int vecp, char *program, char *drft,
 
        char *cp = m_mktemp2(drft, invo_name, NULL, &out);
         if (cp == NULL) {
 
        char *cp = m_mktemp2(drft, invo_name, NULL, &out);
         if (cp == NULL) {
-           adios (drft, "unable to create temporary file for");
+           adios(NULL, "unable to create temporary file in %s",
+                 get_temp_dir());
         }
        strncpy(tmpdrf, cp, sizeof(tmpdrf));
         }
        strncpy(tmpdrf, cp, sizeof(tmpdrf));
-       chmod (tmpdrf, 0600);
 
        /*
         * Output the header fields
 
        /*
         * Output the header fields
@@ -430,7 +431,8 @@ sendaux (char **vec, int vecp, char *program, char *drft, struct stat *st)
            snprintf (buf, sizeof(buf), "%d", fd2);
            vec[vecp++] = buf;
        } else {
            snprintf (buf, sizeof(buf), "%d", fd2);
            vec[vecp++] = buf;
        } else {
-           admonish (NULL, "unable to create file for annotation list");
+           admonish (NULL, "unable to create temporary file in %s "
+                      "for annotation list", get_temp_dir());
        }
     }
     if (distfile && distout (drft, distfile, backup) == NOTOK)
        }
     }
     if (distfile && distout (drft, distfile, backup) == NOTOK)
@@ -571,11 +573,9 @@ static int
 tmp_fd (void)
 {
     int fd;
 tmp_fd (void)
 {
     int fd;
-    char *tfile = NULL;
+    char *tfile;
 
 
-    tfile = m_mktemp2(NULL, invo_name, &fd, NULL);
-    if (tfile == NULL) return NOTOK;
-    fchmod(fd, 0600);
+    if ((tfile = m_mktemp2(NULL, invo_name, &fd, NULL)) == NULL) return NOTOK;
 
     if (debugsw)
        advise (NULL, "temporary file %s selected", tfile);
 
     if (debugsw)
        advise (NULL, "temporary file %s selected", tfile);
index 8daf6081ac9ccf2c3dd1f2a8c00e3b91e598ef22..7ffbe57d8d85ef125a1660ae07dc3fe65120116b 100644 (file)
@@ -317,14 +317,16 @@ main (int argc, char **argv)
        if (debug)
            debug_printf ("retrieving message from file \"%s\"\n", file);
        if ((fd = copy_message (tempfd, tmpfil, 1)) == -1)
        if (debug)
            debug_printf ("retrieving message from file \"%s\"\n", file);
        if ((fd = copy_message (tempfd, tmpfil, 1)) == -1)
-           adios (NULL, "unable to create temporary file");
+           adios(NULL, "unable to create temporary file in %s",
+                  get_temp_dir());
        close (tempfd);
     } else {
        /* getting message from stdin */
        if (debug)
            debug_printf ("retrieving message from stdin\n");
        if ((fd = copy_message (fileno (stdin), tmpfil, 1)) == -1)
        close (tempfd);
     } else {
        /* getting message from stdin */
        if (debug)
            debug_printf ("retrieving message from stdin\n");
        if ((fd = copy_message (fileno (stdin), tmpfil, 1)) == -1)
-           adios (NULL, "unable to create temporary file");
+           adios(NULL, "unable to create temporary file in %s",
+                  get_temp_dir());
     }
 
     if (debug)
     }
 
     if (debug)
@@ -1198,7 +1200,6 @@ copy_message (int qd, char *tmpfil, int fold)
 
     tfile = m_mktemp2(NULL, invo_name, &fd1, NULL);
     if (tfile == NULL) return -1;
 
     tfile = m_mktemp2(NULL, invo_name, &fd1, NULL);
     if (tfile == NULL) return -1;
-    fchmod(fd1, 0600);
     strncpy (tmpfil, tfile, BUFSIZ);
 
     if (!fold) {
     strncpy (tmpfil, tfile, BUFSIZ);
 
     if (!fold) {
index 7c81079da9958735a31835b2aff2218bcc9ceb36..198413f293d2439672a4a842cb367741c3b00524 100644 (file)
@@ -191,9 +191,9 @@ via_mail (char *mailsw, char *subjsw, char *parmsw, char *descsw,
 
     umask (~m_gmprot ());
 
 
     umask (~m_gmprot ());
 
-    tfile = m_mktemp2(NULL, invo_name, NULL, &fp);
-    if (tfile == NULL) adios("viamail", "unable to create temporary file");
-    chmod(tfile, 0600);
+    if ((tfile = m_mktemp2(NULL, invo_name, NULL, &fp)) == NULL) {
+       adios(NULL, "unable to create temporary file in %s", get_temp_dir());
+    }
     strncpy (tmpfil, tfile, sizeof(tmpfil));
 
     if (!strchr(mailsw, '@'))
     strncpy (tmpfil, tfile, sizeof(tmpfil));
 
     if (!strchr(mailsw, '@'))
index 7c2c021b1bfd34c536ce8aaedf9d49dd70ab9bd5..d41413898e3cc23fcab13e9f4bcfbd2878b5734b 100644 (file)
@@ -1304,7 +1304,11 @@ sendit (char *sp, char **arg, char *file, int pushed)
 #endif /* not lint */
            && altmsg) {
        vec[vecp++] = "-dist";
 #endif /* not lint */
            && altmsg) {
        vec[vecp++] = "-dist";
-       distfile = getcpy (m_mktemp2(altmsg, invo_name, NULL, NULL));
+       if ((cp = m_mktemp2(altmsg, invo_name, NULL, NULL)) == NULL) {
+           adios(NULL, "unable to create temporary file in %s",
+                 get_temp_dir());
+       }
+       distfile = getcpy (cp);
        unlink(distfile);
        if (link (altmsg, distfile) == NOTOK)
            adios (distfile, "unable to link %s to", altmsg);
        unlink(distfile);
        if (link (altmsg, distfile) == NOTOK)
            adios (distfile, "unable to link %s to", altmsg);