]> diplodocus.org Git - nmh/blobdiff - sbr/context_read.c
fmt_scan(): Avoid undefined behaviour from overlapping strncpy(3).
[nmh] / sbr / context_read.c
index 748114ed14eba8092ae62aa3a289700ab5effa6f..499dba41379b143f82ec31b10d9fadc410bfce2a 100644 (file)
@@ -1,5 +1,4 @@
-/*
- * context_read.c -- find and read profile and context files
+/* context_read.c -- find and read profile and context files
  *
  * This code is Copyright (c) 2002, by the authors of nmh.  See the
  * COPYRIGHT file in the root directory of the nmh distribution for
  *         environment variable or by the profile.
  */
 
-#include <h/mh.h>                              /* mh internals */
-#include <pwd.h>                               /* structure for getpwuid() results */
+#include "h/mh.h"
+#include "read_yes_or_no_if_tty.h"
+#include "concat.h"
+#include "context_read.h"
+#include "context_find.h"
+#include "readconfig.h"
+#include "path.h"
+#include "error.h"
+#include "lock_file.h"
+#include "m_maildir.h"
+#include "makedir.h"
+#include <pwd.h>
+#include "h/utils.h"
 
 void
 context_read (void)
@@ -37,7 +47,7 @@ context_read (void)
     int failed_to_lock = 0;
 
     /*
-     *  If this routine _is_ called again (despite the wanings in the
+     *  If this routine _is_ called again (despite the warnings in the
      *  comments above), return immediately.
      */
     if ( m_defs != 0 )
@@ -50,9 +60,8 @@ context_read (void)
 
     if ((mypath = getenv("HOME")) == NULL) {
        if ((pw = getpwuid(getuid())) == NULL || *pw->pw_dir == '\0')
-           adios(NULL, "cannot determine your home directory");
-       else
-           mypath = pw->pw_dir;
+           die("cannot determine your home directory");
+        mypath = pw->pw_dir;
     }
 
     /*
@@ -68,16 +77,16 @@ context_read (void)
         /* defpath is an absolute path; make sure that always MH is, too. */
        setenv("MH", defpath, 1);
        if (stat(defpath, &st) != -1 && (st.st_mode & S_IFREG) == 0)
-               adios(NULL, "`%s' specified by your MH environment variable is not a normal file", cp);
+               die("`%s' specified by your MH environment variable is not a normal file", cp);
 
        if ((ib = fopen(defpath, "r")) == NULL)
-           adios(NULL, "unable to read the `%s' profile specified by your MH environment variable", defpath);
+           die("unable to read the `%s' profile specified by your MH environment variable", defpath);
     }
     else {
        defpath = concat(mypath, "/", mh_profile, NULL);
 
        if ((ib = fopen(defpath, "r")) == NULL)
-           adios(NULL, "Doesn't look like nmh is installed.  Run install-mh to do so.");
+           die("Doesn't look like nmh is installed.  Run install-mh to do so.");
 
        cp = mh_profile;
     }
@@ -91,10 +100,10 @@ context_read (void)
      */
 
     if ((cp = context_find ("path")) == NULL)
-       adios(NULL, "Your %s file does not contain a path entry.", defpath);
+       die("Your %s file does not contain a path entry.", defpath);
 
     if (*cp == '\0')
-       adios(NULL, "Your `%s' profile file does not contain a valid path entry.", defpath);
+       die("Your `%s' profile file does not contain a valid path entry.", defpath);
 
     if (*cp != '/')
        (void)snprintf (nd = buf, sizeof(buf), "%s/%s", mypath, cp);
@@ -108,16 +117,16 @@ context_read (void)
        cp = concat ("Your MH-directory \"", nd, "\" doesn't exist; Create it? ", NULL);
 
        if (!read_yes_or_no_if_tty(cp))
-           adios (NULL, "unable to access MH-directory \"%s\"", nd);
+           die("unable to access MH-directory \"%s\"", nd);
 
        free (cp);
 
        if (!makedir (nd))
-           adios (NULL, "unable to create %s", nd);
+           die("unable to create %s", nd);
     }
 
     else if ((st.st_mode & S_IFDIR) == 0)
-       adios (NULL, "`%s' is not a directory", nd);
+       die("`%s' is not a directory", nd);
 
     /*
      * Open and read user's context file.  The name of the context file comes from the
@@ -129,19 +138,17 @@ context_read (void)
 
     /* context is NULL if context_foil() was called to disable use of context
      * We also support users setting explicitly setting MHCONTEXT to /dev/null.
-     * (if this wasn't specialcased then the locking would be liable to fail)
+     * (if this wasn't special-cased then the locking would be liable to fail)
      */
     if (!cp || (strcmp(cp,"/dev/null") == 0)) {
        ctxpath = NULL;
        return;
     }
     
-    ctxpath = getcpy (m_maildir (cp));
+    ctxpath = mh_xstrdup(m_maildir(cp));
 
     if ((ib = lkfopendata (ctxpath, "r", &failed_to_lock))) {
-       readconfig ((struct node **) 0, ib, cp, 1);
+       readconfig(NULL, ib, cp, 1);
        lkfclosedata (ib, ctxpath);
     }
-
-    return;
 }