0
|
1 /* makedir.c - make a directory */
|
|
2 #ifndef lint
|
|
3 static char ident[] = "@(#)$Id$";
|
|
4 #endif /* lint */
|
|
5
|
|
6 #if defined (BSD42) || defined (hpux)
|
|
7 /* Modified to try recursive create. Really, this should be broken
|
|
8 * out into a subr so that SYS5 systems can do this too. I don't
|
|
9 * have a SYS5 machine around to test anymore, so someone else will
|
|
10 * have to send me the code.
|
|
11 */
|
|
12 #endif
|
|
13
|
|
14 #include "../h/mh.h"
|
|
15 #include <stdio.h>
|
|
16
|
|
17 #if defined (BSD42) || defined(SVR4) || \
|
|
18 defined (hpux) || defined(sgi) || defined(__osf__) || defined(ncr) || \
|
|
19 defined (_AIX) || defined(AUX) || defined(linux) || defined(__CYGWIN32__)
|
|
20 #include <errno.h>
|
|
21 #include <sys/param.h>
|
|
22 #include <sys/file.h>
|
|
23 #endif /* BSD42 ... */
|
|
24 #ifdef SYS5DIR
|
|
25 #include <sys/types.h>
|
|
26 #include <sys/stat.h>
|
|
27 #endif /* SYS5DIR */
|
|
28 #if defined(SVR4) || defined(ncr) || defined(UNISTD)
|
|
29 #include <unistd.h>
|
|
30 #endif
|
|
31
|
10
|
32 #include <errno.h>
|
0
|
33
|
|
34 makedir (dir)
|
|
35 register char *dir;
|
|
36 {
|
|
37 int pid;
|
|
38 register char *cp;
|
|
39 #if defined (BSD42) || defined (hpux) || defined (SYS5DIR)
|
|
40 register char *c;
|
|
41 char path[MAXPATHLEN];
|
|
42 #endif /* BSD42 */
|
|
43
|
|
44 m_update ();
|
|
45 (void) fflush (stdout);
|
|
46
|
|
47 #if defined (BSD42) || defined (hpux) || defined (SYS5DIR)
|
|
48 if (getuid () == geteuid ()) {
|
|
49 c = strcpy(path, dir);
|
|
50
|
|
51 while ((c = index((c + 1), '/')) != NULL) {
|
|
52 *c = (char)0;
|
|
53 if (access(path, X_OK)) {
|
|
54 if (errno != ENOENT){
|
|
55 advise (dir, "unable to create directory");
|
|
56 return 0;
|
|
57 }
|
|
58 if (mkdir(path, 0775)) {
|
|
59 advise (dir, "unable to create directory");
|
|
60 return 0;
|
|
61 }
|
|
62 }
|
|
63 *c = '/';
|
|
64 }
|
|
65
|
|
66 if (mkdir (dir, 0755) == NOTOK) {
|
|
67 advise (dir, "unable to create directory");
|
|
68 return 0;
|
|
69 }
|
|
70 }
|
|
71 else
|
|
72 #endif /* BSD42 or hpux or SYS5DIR */
|
|
73 switch (pid = vfork ()) {
|
|
74 case NOTOK:
|
|
75 advise ("fork", "unable to");
|
|
76 return 0;
|
|
77
|
|
78 case OK:
|
|
79 (void) setgid (getgid ());
|
|
80 (void) setuid (getuid ());
|
|
81
|
|
82 execl ("/bin/mkdir", "mkdir", dir, NULLCP);
|
|
83 execl ("/usr/bin/mkdir", "mkdir", dir, NULLCP);
|
|
84 fprintf (stderr, "unable to exec ");
|
|
85 perror ("mkdir");
|
|
86 _exit (-1);
|
|
87
|
|
88 default:
|
|
89 if (pidXwait (pid, "mkdir"))
|
|
90 return 0;
|
|
91 break;
|
|
92 }
|
|
93
|
|
94 if ((cp = m_find ("folder-protect")) == NULL)
|
|
95 cp = foldprot;
|
|
96 (void) chmod (dir, atooi (cp));
|
|
97 return 1;
|
|
98 }
|
|
99
|