]> diplodocus.org Git - nmh/blobdiff - sbr/makedir.c
Fixed number of bytes to fread() in strip_crs() in mhfixmsg.
[nmh] / sbr / makedir.c
index e4c3c26c15f60baea3645bf6ecadd814d0fe0400..67f69c86e2b1efd99c1aa3d06e9eb55d34b758f2 100644 (file)
@@ -2,7 +2,9 @@
 /*
  * makedir.c -- make a directory
  *
 /*
  * makedir.c -- make a directory
  *
- * $Id$
+ * This code is Copyright (c) 2002, by the authors of nmh.  See the
+ * COPYRIGHT file in the root directory of the nmh distribution for
+ * complete copyright information.
  */
 
 /*
  */
 
 /*
  */
 
 #include <h/mh.h>
  */
 
 #include <h/mh.h>
-#include <errno.h>
-#include <sys/param.h>
 #include <sys/file.h>
 #include <sys/file.h>
-
-extern int errno;
        
 int
 makedir (char *dir)
        
 int
 makedir (char *dir)
@@ -30,20 +28,23 @@ makedir (char *dir)
     fflush(stdout);
 
     if (!(folder_perms_ASCII = context_find ("folder-protect")))
     fflush(stdout);
 
     if (!(folder_perms_ASCII = context_find ("folder-protect")))
-       folder_perms_ASCII = foldprot;  /* defaults to "0700" */
-    
-    /* Call strtoul() with radix=0, which means it'll determine the base by
-       looking at the first digit.  That way it'll know "0700" is an octal
-       constant (and if someone gets wacky and changes the representation to hex
-       it'll still work). */
-    folder_perms = strtoul(folder_perms_ASCII, NULL, 0);
+       folder_perms_ASCII = foldprot;  /* defaults to "700" */
+
+    /* Because mh-profile.man documents "Folder-Protect:" as an octal constant,
+       and we don't want to force the user to remember to include a leading
+       zero, we call atooi(folder_perms_ASCII) here rather than
+       strtoul(folder_perms_ASCII, NULL, 0).  Therefore, if anyone ever tries to
+       specify a mode in say, hex, they'll get garbage.  (I guess nmh uses its
+       atooi() function rather than calling strtoul() with a radix of 8 because
+       some ancient platforms are missing that functionality. */
+    folder_perms = atooi(folder_perms_ASCII);
 
     /* Folders have definite desired permissions that are set -- we don't want
        to interact with the umask.  Clear it temporarily. */
     saved_umask = umask(0);
 
     if (getuid () == geteuid ()) {
 
     /* Folders have definite desired permissions that are set -- we don't want
        to interact with the umask.  Clear it temporarily. */
     saved_umask = umask(0);
 
     if (getuid () == geteuid ()) {
-       c = strncpy(path, dir, sizeof(path));     
+       c = strncpy(path, dir, sizeof(path));
        
        while (!had_an_error && (c = strchr((c + 1), '/')) != NULL) {   
            *c = (char)0;
        
        while (!had_an_error && (c = strchr((c + 1), '/')) != NULL) {   
            *c = (char)0;
@@ -82,22 +83,22 @@ makedir (char *dir)
           nested directories like the above code can.
 
           -- Dan Harkless <dan-nmh@dilvish.speed.net> */
           nested directories like the above code can.
 
           -- Dan Harkless <dan-nmh@dilvish.speed.net> */
-       switch (pid = vfork()) {
-           case -1: 
+       switch (pid = fork()) {
+           case -1:
                advise ("fork", "unable to");
                return 0;
                
                advise ("fork", "unable to");
                return 0;
                
-           case 0: 
+           case 0:
                setgid (getgid ());
                setuid (getuid ());
                
                setgid (getgid ());
                setuid (getuid ());
                
-               execl ("/bin/mkdir", "mkdir", dir, NULL);
-               execl ("/usr/bin/mkdir", "mkdir", dir, NULL);
+               execl ("/bin/mkdir", "mkdir", dir, (void *) NULL);
+               execl ("/usr/bin/mkdir", "mkdir", dir, (void *) NULL);
                fprintf (stderr, "unable to exec ");
                perror ("mkdir");
                _exit (-1);
                
                fprintf (stderr, "unable to exec ");
                perror ("mkdir");
                _exit (-1);
                
-           default: 
+           default:
                if (pidXwait(pid, "mkdir"))
                    return 0;
                break;
                if (pidXwait(pid, "mkdir"))
                    return 0;
                break;