3 I have created a diffile against the 980403 release that adds
4 functionality to newusers for automatic handling of users with only
5 anonomous ftp login (using the guestgroup feature in ftpaccess, which
6 means that the users home directory looks like '/home/user/./'). It also
7 adds a commandline argument to specify an initial directory structure
8 for such users, with a tarball normally containing the bin,lib,etc
9 directories used in the chrooted environment.
11 I am using it to automatically create chunks of users with only ftp
12 access for a webserver.
14 I have tried to follow your coding standards and I believe it is bug
15 free but.. well, who knows. :) It's not much code however.
17 I hope you find it useful. Do what you like with it, feel free to ask if
24 diff -uNr shadow-980403.orig/src/newusers.c shadow-980403/src/newusers.c
25 --- shadow-980403.orig/src/newusers.c Fri Jan 30 00:22:43 1998
26 +++ shadow-980403/src/newusers.c Fri Apr 17 16:55:33 1998
31 - fprintf(stderr, "Usage: %s [ input ]\n", Prog);
32 + fprintf (stderr, "Usage: %s [-p prototype tarfile] [ input ]\n", Prog);
33 + fprintf (stderr, "The prototype tarfile is only used for users\n");
34 + fprintf (stderr, "marked as anonymous ftp users. It must be a full pathname.\n");
39 + * createuserdir - create a directory and chmod it
43 +createuserdir (char * dir, int uid, int gid, int line)
45 + if (mkdir (dir, 0777 & ~getdef_num("UMASK", 077))) {
46 + fprintf (stderr, "%s: line %d: mkdir %s failed\n",
51 + if (chown (dir, uid, gid)) {
52 + fprintf (stderr, "%s: line %d: chown %s failed\n",
61 * add_group - create a new group or add a user to an existing group
65 main(int argc, char **argv)
68 + char anonproto[BUFSIZ];
75 Prog = Basename(argv[0]);
77 - if (argc > 1 && argv[1][0] == '-')
81 + while ((flag = getopt (argc, argv, "p:h")) != EOF) {
84 + STRFCPY(anonproto, optarg);
94 - if (! freopen (argv[1], "r", stdin)) {
95 - snprintf(buf, sizeof buf, "%s: %s", Prog, argv[1]);
96 + if (optind < argc) {
97 + if (! freopen (argv[optind], "r", stdin)) {
98 + snprintf(buf, sizeof buf, "%s: %s", Prog, argv[optind]);
102 @@ -499,15 +536,36 @@
104 newpw.pw_shell = fields[6];
106 - if (newpw.pw_dir[0] && access(newpw.pw_dir, F_OK)) {
107 - if (mkdir (newpw.pw_dir,
108 - 0777 & ~getdef_num("UMASK", 077)))
109 - fprintf (stderr, "%s: line %d: mkdir failed\n",
111 - else if (chown (newpw.pw_dir,
112 - newpw.pw_uid, newpw.pw_gid))
113 - fprintf (stderr, "%s: line %d: chown failed\n",
115 + if (newpw.pw_dir[0]) {
116 + char * userdir = strdup (newpw.pw_dir);
120 + if ((anonpart = strstr (userdir, "/./"))) {
125 + if (access(userdir, F_OK))
126 + rc = createuserdir (userdir, newpw.pw_uid, newpw.pw_gid, line);
130 + if (rc == 0 && anonpart) {
132 + char cmdbuf [BUFSIZ];
133 + snprintf(cmdbuf, sizeof cmdbuf,
134 + "cd %s; tar xf %s",
135 + userdir, anonproto);
138 + if (strlen (anonpart) > 1) {
139 + strcat (userdir, anonpart);
140 + if (access (userdir, F_OK))
141 + createuserdir (userdir, newpw.pw_uid, newpw.pw_gid, line);