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 564 by douglas, 2005-08-28T03:22:30-07:00 vs.
Revision 583 by douglas, 2005-11-21T12:56:05-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  
# Line 14 | Line 20 | 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;
# Line 107 | Line 115 | int main(int argc, char *argv[])
115                  check(setenv("USER", user, 1), environment);
116                  check(setenv("NAME", name, 1), environment);
117                  check(setenv("FILE", slappasswd, 1), environment);
118 +                setshells(shells + bash, environment);
119                  check(execl("/ccs/bin/adduser.sh", argv[0], NULL), environment);
120          }
121  
# Line 133 | Line 142 | int main(int argc, char *argv[])
142          if (!entry)
143                  longjmp(environment, 1);
144  
145 <        check(mkdir(entry->pw_dir, 0755), environment);
145 >        check(mkdir(entry->pw_dir, S_IRWXU | S_IRWXG | S_IRWXO), environment);
146          check(chown(entry->pw_dir, entry->pw_uid, entry->pw_gid), environment);
147 +        check(chdir(entry->pw_dir), environment);
148 +
149 +        FTS *traversal = fts_open((char *[]){ "/usr/share/skel", "/ccs/skel", NULL }, FTS_LOGICAL | FTS_NOCHDIR, NULL);
150 +
151 +        if (!traversal)
152 +                longjmp(environment, 1);
153 +
154 +        FTSENT *entity;
155 +
156 +        while ((entity = fts_read(traversal)))
157 +                switch (entity->fts_info)
158 +                {
159 +                case FTS_D:
160 +                        if (entity->fts_level != FTS_ROOTLEVEL)
161 +                        {
162 +                                check(mkdir(entity->fts_name, entity->fts_statp->st_mode), environment);
163 +                                check(chown(entity->fts_name, entry->pw_uid, entry->pw_gid), environment);
164 +                                check(chdir(entity->fts_name), environment);
165 +                        }
166 +
167 +                        break;
168 +                case FTS_DP:
169 +                        if (entity->fts_level != FTS_ROOTLEVEL)
170 +                                check(chdir(".."), environment);
171 +
172 +                        break;
173 +                case FTS_F:
174 +                        {
175 +                                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);
176 +                                char buffer[entity->fts_statp->st_blksize];
177 +                                size_t size;
178 +
179 +                                while ((size = check(read(input, buffer, sizeof (buffer)), environment)))
180 +                                        check(write(output, buffer, size), environment);
181 +
182 +                                check(fchown(output, entry->pw_uid, entry->pw_gid), environment);
183 +                                check(close(output), environment);
184 +                                check(close(input), environment);
185 +                        }
186 +
187 +                        break;
188 +                }
189 +
190 +        if (errno)
191 +                longjmp(environment, 1);
192 +
193 +        if (fts_close(traversal))
194 +                longjmp(environment, 1);
195   #else
196          longjmp(environment, (int)"Log in to zweihander.ccs.ucsb.edu to add users");
197   #endif

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines