Revision 12350,
1.6 KB
checked in by ghudson, 26 years ago
(diff) |
Some RCS ID cleanup: delete $Log$ and replace other RCS keywords with $Id$.
|
Line | |
---|
1 | /* |
---|
2 | * |
---|
3 | * Copyright (C) 1988, 1989 by the Massachusetts Institute of Technology |
---|
4 | * Developed by the MIT Student Information Processing Board (SIPB). |
---|
5 | * For copying information, see the file mit-copyright.h in this release. |
---|
6 | * |
---|
7 | */ |
---|
8 | /* |
---|
9 | * Create a meeting directory; this program should run setuid root. |
---|
10 | * However, it is secure.. |
---|
11 | */ |
---|
12 | |
---|
13 | #include <stdio.h> |
---|
14 | #include <sys/file.h> |
---|
15 | #include <sys/param.h> |
---|
16 | #include <pwd.h> |
---|
17 | #include <string.h> |
---|
18 | #ifdef SOLARIS |
---|
19 | #include <unistd.h> |
---|
20 | #include <string.h> |
---|
21 | #endif |
---|
22 | #ifndef lint |
---|
23 | static char rcsid_create_mtg_dir_c[] = "$Id: create_mtg_dir.c,v 1.7 1999-01-22 23:10:07 ghudson Exp $"; |
---|
24 | #endif |
---|
25 | |
---|
26 | main(argc, argv) |
---|
27 | int argc; |
---|
28 | char **argv; |
---|
29 | { |
---|
30 | char *dir; |
---|
31 | char *entry; |
---|
32 | struct passwd *pw; |
---|
33 | |
---|
34 | if (argc != 2) { |
---|
35 | fprintf(stderr, "usage: %s directory\n", argv[0]); |
---|
36 | exit(1); |
---|
37 | } |
---|
38 | |
---|
39 | if((pw = getpwnam("discuss")) == NULL) { |
---|
40 | fprintf(stderr, "discuss: unknown user\n"); |
---|
41 | exit(1); |
---|
42 | } |
---|
43 | |
---|
44 | dir = argv[1]; |
---|
45 | if (dir[0] != '/') { |
---|
46 | fprintf(stderr, "%s: Must be absolute pathname\n", dir); |
---|
47 | exit(1); |
---|
48 | } |
---|
49 | |
---|
50 | if ((entry = strrchr(dir, '/')) == dir) { |
---|
51 | fprintf(stderr, "%s: Can't create meeting there\n", dir); |
---|
52 | exit(1); |
---|
53 | } |
---|
54 | *entry++ = '\0'; |
---|
55 | |
---|
56 | /* |
---|
57 | * Access uses real uid, rather than effective uid. |
---|
58 | */ |
---|
59 | if (access(dir, W_OK)) { |
---|
60 | perror(dir); |
---|
61 | exit(1); |
---|
62 | } |
---|
63 | if (chdir(dir)) { |
---|
64 | perror(dir); |
---|
65 | exit(1); |
---|
66 | } |
---|
67 | if (!access(entry, 0)) { |
---|
68 | fprintf(stderr, "%s/%s: already exists\n", dir, entry); |
---|
69 | exit(1); |
---|
70 | } |
---|
71 | if (mkdir(entry, 0777)) { |
---|
72 | fprintf(stderr, "Cannot create "); |
---|
73 | perror(entry); |
---|
74 | exit(1); |
---|
75 | } |
---|
76 | if (chown(entry, pw->pw_uid, -1)) { |
---|
77 | fprintf(stderr, "Cannot change ownership for "); |
---|
78 | perror(entry); |
---|
79 | exit(1); |
---|
80 | } |
---|
81 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.