ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/repos/CCSAdmin/turnin.c
(Generate patch)

Comparing:
CCSAdmin/adduser.c (file contents), Revision 572 by douglas, 2005-09-25T17:43:17-07:00 vs.
CCSAdmin/turnin.c (file contents), Revision 656 by douglas, 2006-01-26T01:50:27-08:00

# Line 2 | Line 2
2   //
3   // CCS Computer Science
4   //
5 < // Add User
6 <
7 < #define _BSD_SOURCE
8 <
9 < #include <errno.h>
10 < #include <sys/resource.h>
11 < #include <sys/time.h>
12 < #include <sys/types.h>
13 < #include <sys/stat.h>
14 < #include <fcntl.h>
15 < #include <fts.h>
5 > // Turn In Stub
6  
7   #include "common.h"
8  
9   int main(int argc, char *argv[])
10   {
21        if (argc < 1)
22                return 1;
23
24        umask(S_IWGRP | S_IWOTH);
25        
11          int exception;
12          jmp_buf environment;
13  
# Line 40 | Line 25 | int main(int argc, char *argv[])
25                  return 1;
26          }
27  
28 < #ifdef _Zweihander_
44 <        regex_t user_, name_;
45 <
46 <        regcheck(regcomp(&user_, "^-user=([a-z0-9]{1,16})$", REG_EXTENDED), &user_, environment);
47 <        regcheck(regcomp(&name_, "^-name=([^:]+)$", REG_EXTENDED), &name_, environment);
48 <
49 <        char user[MAXLOGNAME] = "", *name = NULL;
50 <
51 <        for (int index = 1; index != argc; ++index)
52 <        {
53 <                regmatch_t match[2];
54 <
55 <                if (!regcheck(regexec(&user_, argv[index], 2, match, 0), &user_, environment))
56 <                        strlcpy(user, argv[index] + match[1].rm_so, match[1].rm_eo - match[1].rm_so + 1);
57 <                else if (!regcheck(regexec(&name_, argv[index], 2, match, 0), &name_, environment))
58 <                        name = argv[index] + match[1].rm_so;
59 <                else
60 <                {
61 <                        printf("Usage: %s [-user=user] [-name=name]\n", argv[0]);
62 <
63 <                        return 1;
64 <                }
65 <        }
66 <
67 <        regfree(&user_);
68 <        regfree(&name_);
69 <        authenticate(argv[0], environment);
70 <
71 <        if (!strlen(user))
72 <        {
73 <                regcheck(regcomp(&user_, "^[a-z0-9]{1,16}$", REG_EXTENDED), &user_, environment);
74 <
75 <                do
76 <                {
77 <                        printf("User Name: ");
78 <
79 <                        size_t size;
80 <                        char *user_ = fcheck(fgetln(stdin, &size), stdin, environment);
81 <
82 <                        strlcpy(user, user_, size < sizeof (user) ? size : sizeof (user));
83 <                }
84 <                while (regcheck(regexec(&user_, user, 0, NULL, 0), &user_, environment));
85 <
86 <                regfree(&user_);
87 <        }
88 <
89 <        if (!name)
90 <        {
91 <                regcheck(regcomp(&name_, "^[^:]+$", REG_EXTENDED), &name_, environment);
92 <                get("Full Name", &name_, &name, environment);
93 <                regfree(&name_);
94 <        }
95 <
96 <        char password[_PASSWORD_LEN];
97 <
98 <        getpassword(password, environment);
99 <        check(setuid(geteuid()), environment);
100 <
101 <        char slappasswd[] = "/tmp/slappasswd.XXXXXX";
102 <
103 <        putpassword(password, slappasswd, environment);
104 <
105 <        int pipe_[2];
106 <
107 <        check(pipe(pipe_), environment);
108 <
109 <        pid_t bash;
110 <
111 <        if (!(bash = check(fork(), environment)))
112 <        {
113 <                check(dup2(pipe_[0], 0), environment);
114 <                check(close(pipe_[1]), environment);
115 <                check(setenv("USER", user, 1), environment);
116 <                check(setenv("NAME", name, 1), environment);
117 <                check(setenv("FILE", slappasswd, 1), environment);
118 <                check(execl("/ccs/bin/adduser.sh", argv[0], NULL), environment);
119 <        }
120 <
121 <        check(close(pipe_[0]), environment);
122 <
123 <        FILE *smbpasswd = fdopen(pipe_[1], "w");
124 <
125 <        if (fprintf(smbpasswd, "%s\n%s\n", password, password) < 0)
126 <                longjmp(environment, 1);
127 <
128 <        if (fclose(smbpasswd))
129 <                longjmp(environment, 1);
130 <
131 <        int status;
132 <
133 <        check(waitpid(bash, &status, 0), environment);
134 <        check(unlink(slappasswd), environment);
135 <
136 <        if (WEXITSTATUS(status))
137 <                return 1;
138 <
139 <        struct passwd *entry = getpwnam(user);
140 <
141 <        if (!entry)
142 <                longjmp(environment, 1);
143 <
144 <        check(mkdir(entry->pw_dir, S_IRWXU | S_IRWXG | S_IRWXO), environment);
145 <        check(chown(entry->pw_dir, entry->pw_uid, entry->pw_gid), environment);
146 <        check(chdir(entry->pw_dir), environment);
147 <
148 <        FTS *traversal = fts_open((char *[]){ "/usr/share/skel", NULL }, FTS_LOGICAL | FTS_NOCHDIR, NULL);
149 <
150 <        if (!traversal)
151 <                longjmp(environment, 1);
152 <
153 <        FTSENT *entity;
154 <
155 <        while ((entity = fts_read(traversal)))
156 <                switch (entity->fts_info)
157 <                {
158 <                case FTS_D:
159 <                        if (entity->fts_level != FTS_ROOTLEVEL)
160 <                        {
161 <                                check(mkdir(entity->fts_name, entity->fts_statp->st_mode), environment);
162 <                                check(chown(entity->fts_name, entry->pw_uid, entry->pw_gid), environment);
163 <                                check(chdir(entity->fts_name), environment);
164 <                        }
165 <
166 <                        break;
167 <                case FTS_DP:
168 <                        if (entity->fts_level != FTS_ROOTLEVEL)
169 <                                check(chdir(".."), environment);
170 <
171 <                        break;
172 <                case FTS_F:
173 <                        {
174 <                                int output = check(open(strncmp(entity->fts_name, "dot", 3) ? entity->fts_name : entity->fts_name + 3, O_WRONLY | O_CREAT | O_EXCL, entity->fts_statp->st_mode), environment), input = check(open(entity->fts_accpath, O_RDONLY), environment);
175 <                                char buffer[entity->fts_statp->st_blksize];
176 <                                size_t size;
177 <
178 <                                while ((size = check(read(input, buffer, sizeof (buffer)), environment)))
179 <                                        check(write(output, buffer, size), environment);
180 <
181 <                                check(fchown(output, entry->pw_uid, entry->pw_gid), environment);
182 <                                check(close(output), environment);
183 <                                check(close(input), environment);
184 <                        }
185 <
186 <                        break;
187 <                }
188 <
189 <        if (errno)
190 <                longjmp(environment, 1);
191 <
192 <        if (fts_close(traversal))
193 <                longjmp(environment, 1);
194 < #else
195 <        longjmp(environment, (int)"Log in to zweihander.ccs.ucsb.edu to add users");
196 < #endif
28 >        longjmp(environment, (int)"Um, so, yeah, I'm guessing you want to be logged into a CSIL box.");
29  
30          return 0;
31   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines