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 562 by douglas, 2005-08-27T21:46:39-07:00 vs.
Revision 566 by douglas, 2005-08-28T22:29:20-07:00

# Line 4 | Line 4
4   //
5   // Add User
6  
7 + #include <errno.h>
8   #include <sys/resource.h>
9   #include <sys/time.h>
10   #include <sys/types.h>
11 + #include <sys/stat.h>
12 + #include <fcntl.h>
13 + #include <fts.h>
14  
15   #include "common.h"
16  
17   int main(int argc, char *argv[])
18   {
19 +        if (argc < 1)
20 +                return 1;
21 +        
22          int exception;
23          jmp_buf environment;
24  
# Line 36 | Line 43 | int main(int argc, char *argv[])
43          regcheck(regcomp(&name_, "^-name=([^:]+)$", REG_EXTENDED), &name_, environment);
44  
45          char user[MAXLOGNAME] = "", *name = NULL;
46 <        
46 >
47          for (int index = 1; index != argc; ++index)
48          {
49                  regmatch_t match[2];
# Line 78 | Line 85 | int main(int argc, char *argv[])
85          if (!name)
86          {
87                  regcheck(regcomp(&name_, "^[^:]+$", REG_EXTENDED), &name_, environment);
88 <
82 <                do
83 <                {
84 <                        printf("Full Name: ");
85 <
86 <                        size_t size;
87 <                        char *name_ = fcheck(fgetln(stdin, &size), stdin, environment);
88 <
89 <                        name = name ? realloc(name, size) : malloc(size);
90 <
91 <                        strlcpy(name, name_, size);
92 <                }
93 <                while (regcheck(regexec(&name_, name, 0, NULL, 0), &name_, environment));
94 <
88 >                get("Full Name", &name_, &name, environment);
89                  regfree(&name_);
90          }
91  
# Line 145 | Line 139 | int main(int argc, char *argv[])
139  
140          check(mkdir(entry->pw_dir, 0755), environment);
141          check(chown(entry->pw_dir, entry->pw_uid, entry->pw_gid), environment);
142 +        check(chdir(entry->pw_dir), environment);
143 +
144 +        FTS *traversal = fts_open((char *[]){ "/usr/share/skel", NULL }, FTS_LOGICAL | FTS_NOCHDIR, NULL);
145 +
146 +        if (!traversal)
147 +                longjmp(environment, 1);
148 +
149 +        FTSENT *entity;
150 +
151 +        while ((entity = fts_read(traversal)))
152 +                switch (entity->fts_info)
153 +                {
154 +                case FTS_D:
155 +                        if (entity->fts_level != FTS_ROOTLEVEL)
156 +                        {
157 +                                check(mkdir(entity->fts_name, entity->fts_statp->st_mode), environment);
158 +                                check(chown(entity->fts_name, entry->pw_uid, entry->pw_gid), environment);
159 +                                check(chdir(entity->fts_name), environment);
160 +                        }
161 +
162 +                        break;
163 +                case FTS_DP:
164 +                        if (entity->fts_level != FTS_ROOTLEVEL)
165 +                                check(chdir(".."), environment);
166 +
167 +                        break;
168 +                case FTS_F:
169 +                        {
170 +                                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);
171 +                                char buffer[entity->fts_statp->st_blksize];
172 +                                size_t size;
173 +
174 +                                while ((size = check(read(input, buffer, sizeof (buffer)), environment)))
175 +                                        check(write(output, buffer, size), environment);
176 +
177 +                                check(fchown(output, entry->pw_uid, entry->pw_gid), environment);
178 +                                check(close(output), environment);
179 +                                check(close(input), environment);
180 +                        }
181 +
182 +                        break;
183 +                }
184 +
185 +        if (errno)
186 +                longjmp(environment, 1);
187 +
188 +        if (fts_close(traversal))
189 +                longjmp(environment, 1);
190   #else
191          longjmp(environment, (int)"Log in to zweihander.ccs.ucsb.edu to add users");
192   #endif

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines