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 579 by douglas, 2005-11-14T17:52:38-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 + #include <fts.h>
16  
17   #include "common.h"
18  
19   int main(int argc, char *argv[])
20   {
21 +        if (argc < 1)
22 +                return 1;
23 +
24 +        umask(S_IWGRP | S_IWOTH);
25 +        
26          int exception;
27          jmp_buf environment;
28  
# Line 36 | Line 47 | int main(int argc, char *argv[])
47          regcheck(regcomp(&name_, "^-name=([^:]+)$", REG_EXTENDED), &name_, environment);
48  
49          char user[MAXLOGNAME] = "", *name = NULL;
50 <        
50 >
51          for (int index = 1; index != argc; ++index)
52          {
53                  regmatch_t match[2];
# Line 130 | Line 141 | int main(int argc, char *argv[])
141          if (!entry)
142                  longjmp(environment, 1);
143  
144 <        check(mkdir(entry->pw_dir, 0755), environment);
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", "/ccs/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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines