Revision 12455,
1.5 KB
checked in by danw, 26 years ago
(diff) |
This commit was generated by cvs2svn to compensate for changes in r12454,
which included commits to RCS files with non-trunk default branches.
|
Line | |
---|
1 | |
---|
2 | /* |
---|
3 | * makedir.c -- make a directory |
---|
4 | * |
---|
5 | * $Id: makedir.c,v 1.1.1.1 1999-02-07 18:14:09 danw Exp $ |
---|
6 | */ |
---|
7 | |
---|
8 | /* |
---|
9 | * Modified to try recursive create. |
---|
10 | */ |
---|
11 | |
---|
12 | #include <h/mh.h> |
---|
13 | #include <errno.h> |
---|
14 | #include <sys/param.h> |
---|
15 | #include <sys/file.h> |
---|
16 | |
---|
17 | extern int errno; |
---|
18 | |
---|
19 | int |
---|
20 | makedir (char *dir) |
---|
21 | { |
---|
22 | pid_t pid; |
---|
23 | register char *cp; |
---|
24 | register char *c; |
---|
25 | char path[PATH_MAX]; |
---|
26 | |
---|
27 | context_save(); /* save the context file */ |
---|
28 | fflush(stdout); |
---|
29 | |
---|
30 | if (getuid () == geteuid ()) { |
---|
31 | c = strncpy(path, dir, sizeof(path)); |
---|
32 | |
---|
33 | while ((c = strchr((c + 1), '/')) != NULL) { |
---|
34 | *c = (char)0; |
---|
35 | if (access(path, X_OK)) { |
---|
36 | if (errno != ENOENT){ |
---|
37 | advise (dir, "unable to create directory"); |
---|
38 | return 0; |
---|
39 | } |
---|
40 | if (mkdir(path, 0775)) { |
---|
41 | advise (dir, "unable to create directory"); |
---|
42 | return 0; |
---|
43 | } |
---|
44 | } |
---|
45 | *c = '/'; |
---|
46 | } |
---|
47 | |
---|
48 | if (mkdir (dir, 0755) == -1) { |
---|
49 | advise (dir, "unable to create directory"); |
---|
50 | return 0; |
---|
51 | } |
---|
52 | } else { |
---|
53 | switch (pid = vfork()) { |
---|
54 | case -1: |
---|
55 | advise ("fork", "unable to"); |
---|
56 | return 0; |
---|
57 | |
---|
58 | case 0: |
---|
59 | setgid (getgid ()); |
---|
60 | setuid (getuid ()); |
---|
61 | |
---|
62 | execl ("/bin/mkdir", "mkdir", dir, NULL); |
---|
63 | execl ("/usr/bin/mkdir", "mkdir", dir, NULL); |
---|
64 | fprintf (stderr, "unable to exec "); |
---|
65 | perror ("mkdir"); |
---|
66 | _exit (-1); |
---|
67 | |
---|
68 | default: |
---|
69 | if (pidXwait(pid, "mkdir")) |
---|
70 | return 0; |
---|
71 | break; |
---|
72 | } |
---|
73 | } |
---|
74 | |
---|
75 | if (!(cp = context_find ("folder-protect"))) |
---|
76 | cp = foldprot; |
---|
77 | chmod (dir, atooi (cp)); |
---|
78 | return 1; |
---|
79 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.