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

Comparing CCSAdmin/adduser.c (file contents):
Revision 565 by douglas, 2005-08-28T03:22:30-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  
# Line 135 | 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