source: trunk/athena/bin/discuss/mclient/create_mtg_dir.c @ 12439

Revision 12439, 1.6 KB checked in by kcr, 26 years ago (diff)
Autoconfiscation and cleanup.
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 HAVE_UNISTD_H
19#include <unistd.h>
20#endif
21#ifndef lint
22static char rcsid_create_mtg_dir_c[] = "$Id: create_mtg_dir.c,v 1.8 1999-02-02 20:40:32 kcr Exp $";
23#endif
24
25main(argc, argv)
26        int argc;
27        char **argv;
28{
29        char *dir;
30        char *entry;
31        struct passwd *pw;
32
33        if (argc != 2) {
34                fprintf(stderr, "usage: %s directory\n", argv[0]);
35                exit(1);
36        }
37
38        if((pw = getpwnam("discuss")) == NULL) {
39                fprintf(stderr, "discuss: unknown user\n");
40                exit(1);
41        }
42
43        dir = argv[1];
44        if (dir[0] != '/') {
45                fprintf(stderr, "%s: Must be absolute pathname\n", dir);
46                exit(1);
47        }
48
49        if ((entry = strrchr(dir, '/')) == dir) {
50                fprintf(stderr, "%s: Can't create meeting there\n", dir);
51                exit(1);
52        }
53        *entry++ = '\0';
54
55        /*
56         *      Access uses real uid, rather than effective uid.
57         */
58        if (access(dir, W_OK)) {
59                perror(dir);
60                exit(1);
61        }
62        if (chdir(dir)) {
63                perror(dir);
64                exit(1);
65        }
66        if (!access(entry, 0)) {
67                fprintf(stderr, "%s/%s: already exists\n", dir, entry);
68                exit(1);
69        }
70        if (mkdir(entry, 0777)) {
71                fprintf(stderr, "Cannot create ");
72                perror(entry);
73                exit(1);
74        }
75        if (chown(entry, pw->pw_uid, -1)) {
76                fprintf(stderr, "Cannot change ownership for ");
77                perror(entry);
78                exit(1);
79        }
80}
Note: See TracBrowser for help on using the repository browser.