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 563 by douglas, 2005-08-28T01:55:06-07:00 vs.
Revision 584 by douglas, 2005-11-22T18:14:57-08:00

# Line 4 | Line 4
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 +
16 + #ifdef _Zweihander_
17 + #include <fts.h>
18 + #endif
19  
20   #include "common.h"
21  
22   int main(int argc, char *argv[])
23   {
24 +        if (argc < 1)
25 +                return 1;
26 +
27 +        umask(S_IWGRP | S_IWOTH);
28 +        
29          int exception;
30          jmp_buf environment;
31  
# Line 36 | Line 50 | int main(int argc, char *argv[])
50          regcheck(regcomp(&name_, "^-name=([^:]+)$", REG_EXTENDED), &name_, environment);
51  
52          char user[MAXLOGNAME] = "", *name = NULL;
53 <        
53 >
54          for (int index = 1; index != argc; ++index)
55          {
56                  regmatch_t match[2];
# Line 104 | Line 118 | int main(int argc, char *argv[])
118                  check(setenv("USER", user, 1), environment);
119                  check(setenv("NAME", name, 1), environment);
120                  check(setenv("FILE", slappasswd, 1), environment);
121 +                setshells(shells + bash, environment);
122                  check(execl("/ccs/bin/adduser.sh", argv[0], NULL), environment);
123          }
124  
# Line 130 | Line 145 | int main(int argc, char *argv[])
145          if (!entry)
146                  longjmp(environment, 1);
147  
148 <        check(mkdir(entry->pw_dir, 0755), environment);
148 >        check(mkdir(entry->pw_dir, S_IRWXU | S_IRWXG | S_IRWXO), environment);
149          check(chown(entry->pw_dir, entry->pw_uid, entry->pw_gid), environment);
150 +        check(chdir(entry->pw_dir), environment);
151 +
152 +        FTS *traversal = fts_open((char *[]){ "/usr/share/skel", "/ccs/skel", NULL }, FTS_LOGICAL | FTS_NOCHDIR, NULL);
153 +
154 +        if (!traversal)
155 +                longjmp(environment, 1);
156 +
157 +        FTSENT *entity;
158 +
159 +        while ((entity = fts_read(traversal)))
160 +                switch (entity->fts_info)
161 +                {
162 +                case FTS_D:
163 +                        if (entity->fts_level != FTS_ROOTLEVEL)
164 +                        {
165 +                                check(mkdir(entity->fts_name, entity->fts_statp->st_mode), environment);
166 +                                check(chown(entity->fts_name, entry->pw_uid, entry->pw_gid), environment);
167 +                                check(chdir(entity->fts_name), environment);
168 +                        }
169 +
170 +                        break;
171 +                case FTS_DP:
172 +                        if (entity->fts_level != FTS_ROOTLEVEL)
173 +                                check(chdir(".."), environment);
174 +
175 +                        break;
176 +                case FTS_F:
177 +                        {
178 +                                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);
179 +                                char buffer[entity->fts_statp->st_blksize];
180 +                                size_t size;
181 +
182 +                                while ((size = check(read(input, buffer, sizeof (buffer)), environment)))
183 +                                        check(write(output, buffer, size), environment);
184 +
185 +                                check(fchown(output, entry->pw_uid, entry->pw_gid), environment);
186 +                                check(close(output), environment);
187 +                                check(close(input), environment);
188 +                        }
189 +
190 +                        break;
191 +                }
192 +
193 +        if (errno)
194 +                longjmp(environment, 1);
195 +
196 +        if (fts_close(traversal))
197 +                longjmp(environment, 1);
198   #else
199          longjmp(environment, (int)"Log in to zweihander.ccs.ucsb.edu to add users");
200   #endif

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines