Deleted Added
full compact
pw_user.c (21242) pw_user.c (21330)
1/*-
2 * Copyright (C) 1996
3 * David L. Nugent. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 9 unchanged lines hidden (view full) ---

18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 * SUCH DAMAGE.
25 *
1/*-
2 * Copyright (C) 1996
3 * David L. Nugent. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 9 unchanged lines hidden (view full) ---

18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24 * SUCH DAMAGE.
25 *
26 * $Id: pw_user.c,v 1.10 1996/12/30 11:52:34 davidn Exp $
26 * $Id: pw_user.c,v 1.11 1997/01/03 04:42:18 davidn Exp $
27 */
28
29#include <unistd.h>
30#include <fcntl.h>
31#include <ctype.h>
32#include <paths.h>
33#include <sys/param.h>
34#include <dirent.h>

--- 47 unchanged lines hidden (view full) ---

82 * -k dir default home skeleton
83 * -s shell default shell
84 * -w method default password method
85 */
86
87int
88pw_user(struct userconf * cnf, int mode, struct cargs * args)
89{
27 */
28
29#include <unistd.h>
30#include <fcntl.h>
31#include <ctype.h>
32#include <paths.h>
33#include <sys/param.h>
34#include <dirent.h>

--- 47 unchanged lines hidden (view full) ---

82 * -k dir default home skeleton
83 * -s shell default shell
84 * -w method default password method
85 */
86
87int
88pw_user(struct userconf * cnf, int mode, struct cargs * args)
89{
90 int r, r1;
90 char *p = NULL;
91 struct carg *a_name;
92 struct carg *a_uid;
93 struct carg *arg;
94 struct passwd *pwd = NULL;
95 struct group *grp;
96 struct stat st;
97 char line[_PASSWORD_LEN+1];

--- 88 unchanged lines hidden (view full) ---

186 } else if (!S_ISDIR(st.st_mode))
187 cmderr(EX_OSFILE, "root home `%s' is not a directory\n", cnf->home);
188 }
189
190
191 if ((arg = getarg(args, 'e')) != NULL)
192 cnf->expire_days = atoi(arg->val);
193
91 char *p = NULL;
92 struct carg *a_name;
93 struct carg *a_uid;
94 struct carg *arg;
95 struct passwd *pwd = NULL;
96 struct group *grp;
97 struct stat st;
98 char line[_PASSWORD_LEN+1];

--- 88 unchanged lines hidden (view full) ---

187 } else if (!S_ISDIR(st.st_mode))
188 cmderr(EX_OSFILE, "root home `%s' is not a directory\n", cnf->home);
189 }
190
191
192 if ((arg = getarg(args, 'e')) != NULL)
193 cnf->expire_days = atoi(arg->val);
194
195 if ((arg = getarg(args, 'y')) != NULL)
196 cnf->nispasswd = arg->val;
197
194 if ((arg = getarg(args, 'p')) != NULL && arg->val)
195 cnf->password_days = atoi(arg->val);
196
197 if ((arg = getarg(args, 'g')) != NULL) {
198 p = arg->val;
199 if ((grp = getgrnam(p)) == NULL) {
200 if (!isdigit(*p) || (grp = getgrgid((gid_t) atoi(p))) == NULL)
201 cmderr(EX_NOUSER, "group `%s' does not exist\n", p);

--- 125 unchanged lines hidden (view full) ---

327 * invalidated by deletion
328 */
329 sprintf(file, "%s/%s", _PATH_MAILDIR, pwd->pw_name);
330 strncpy(home, pwd->pw_dir, sizeof home);
331 home[sizeof home - 1] = '\0';
332
333 if (!delpwent(pwd))
334 cmderr(EX_IOERR, "Error updating passwd file: %s\n", strerror(errno));
198 if ((arg = getarg(args, 'p')) != NULL && arg->val)
199 cnf->password_days = atoi(arg->val);
200
201 if ((arg = getarg(args, 'g')) != NULL) {
202 p = arg->val;
203 if ((grp = getgrnam(p)) == NULL) {
204 if (!isdigit(*p) || (grp = getgrgid((gid_t) atoi(p))) == NULL)
205 cmderr(EX_NOUSER, "group `%s' does not exist\n", p);

--- 125 unchanged lines hidden (view full) ---

331 * invalidated by deletion
332 */
333 sprintf(file, "%s/%s", _PATH_MAILDIR, pwd->pw_name);
334 strncpy(home, pwd->pw_dir, sizeof home);
335 home[sizeof home - 1] = '\0';
336
337 if (!delpwent(pwd))
338 cmderr(EX_IOERR, "Error updating passwd file: %s\n", strerror(errno));
339
340 if (cnf->nispasswd && *cnf->nispasswd=='/' && !delnispwent(cnf->nispasswd, a_name->val))
341 perror("WARNING: NIS passwd update");
342
335 editgroups(a_name->val, NULL);
336
337 pw_log(cnf, mode, W_USER, "%s(%ld) account removed", a_name->val, (long) uid);
338
339 /*
340 * Remove mail file
341 */
342 remove(file);

--- 150 unchanged lines hidden (view full) ---

493 }
494
495 /*
496 * Special case: -N only displays & exits
497 */
498 if (getarg(args, 'N') != NULL)
499 return print_user(pwd, getarg(args, 'P') != NULL);
500
343 editgroups(a_name->val, NULL);
344
345 pw_log(cnf, mode, W_USER, "%s(%ld) account removed", a_name->val, (long) uid);
346
347 /*
348 * Remove mail file
349 */
350 remove(file);

--- 150 unchanged lines hidden (view full) ---

501 }
502
503 /*
504 * Special case: -N only displays & exits
505 */
506 if (getarg(args, 'N') != NULL)
507 return print_user(pwd, getarg(args, 'P') != NULL);
508
501 if ((mode == M_ADD && !addpwent(pwd)) ||
502 (mode == M_UPDATE && !chgpwent(a_name->val, pwd))) {
509 r = r1 = 1;
510 if (mode == M_ADD) {
511 r = addpwent(pwd);
512 if (r && cnf->nispasswd && *cnf->nispasswd=='/')
513 r1 = addnispwent(cnf->nispasswd, pwd);
514 } else if (mode == M_UPDATE) {
515 r = chgpwent(a_name->val, pwd);
516 if (r && cnf->nispasswd && *cnf->nispasswd=='/')
517 r1 = chgnispwent(cnf->nispasswd, a_name->val, pwd);
518 }
519
520 if (!r) {
503 perror("password update");
504 return EX_IOERR;
521 perror("password update");
522 return EX_IOERR;
523 } else if (!r1) {
524 perror("WARNING: NIS password update");
525 /* Keep on trucking */
505 }
526 }
527
506 /*
507 * Ok, user is created or changed - now edit group file
508 */
509
510 if (mode == M_ADD || getarg(args, 'G') != NULL)
511 editgroups(pwd->pw_name, cnf->groups);
512
513 /* pwd may have been invalidated */

--- 566 unchanged lines hidden ---
528 /*
529 * Ok, user is created or changed - now edit group file
530 */
531
532 if (mode == M_ADD || getarg(args, 'G') != NULL)
533 editgroups(pwd->pw_name, cnf->groups);
534
535 /* pwd may have been invalidated */

--- 566 unchanged lines hidden ---