Deleted Added
full compact
pw_user.c (241108) pw_user.c (242349)
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

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

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 */
27
28#ifndef lint
29static const char rcsid[] =
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

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

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 */
27
28#ifndef lint
29static const char rcsid[] =
30 "$FreeBSD: head/usr.sbin/pw/pw_user.c 241108 2012-10-01 17:00:33Z bapt $";
30 "$FreeBSD: head/usr.sbin/pw/pw_user.c 242349 2012-10-30 08:00:53Z bapt $";
31#endif /* not lint */
32
33#include <ctype.h>
34#include <err.h>
35#include <fcntl.h>
36#include <sys/param.h>
37#include <dirent.h>
38#include <paths.h>
39#include <termios.h>
40#include <sys/types.h>
41#include <sys/time.h>
42#include <sys/resource.h>
43#include <unistd.h>
44#include <login_cap.h>
31#endif /* not lint */
32
33#include <ctype.h>
34#include <err.h>
35#include <fcntl.h>
36#include <sys/param.h>
37#include <dirent.h>
38#include <paths.h>
39#include <termios.h>
40#include <sys/types.h>
41#include <sys/time.h>
42#include <sys/resource.h>
43#include <unistd.h>
44#include <login_cap.h>
45#include <pwd.h>
46#include <grp.h>
47#include <libutil.h>
45#include "pw.h"
46#include "bitmap.h"
47
48#define LOGNAMESIZE (MAXLOGNAME-1)
49
50static char locked_str[] = "*LOCKED*";
51
52static int print_user(struct passwd * pwd, int pretty, int v7);

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

287 return EXIT_SUCCESS;
288 warn("config update");
289 return EX_IOERR;
290 }
291
292 if (mode == M_PRINT && getarg(args, 'a')) {
293 int pretty = getarg(args, 'P') != NULL;
294 int v7 = getarg(args, '7') != NULL;
48#include "pw.h"
49#include "bitmap.h"
50
51#define LOGNAMESIZE (MAXLOGNAME-1)
52
53static char locked_str[] = "*LOCKED*";
54
55static int print_user(struct passwd * pwd, int pretty, int v7);

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

290 return EXIT_SUCCESS;
291 warn("config update");
292 return EX_IOERR;
293 }
294
295 if (mode == M_PRINT && getarg(args, 'a')) {
296 int pretty = getarg(args, 'P') != NULL;
297 int v7 = getarg(args, '7') != NULL;
295
296 SETPWENT();
297 while ((pwd = GETPWENT()) != NULL)
298 print_user(pwd, pretty, v7);
299 ENDPWENT();
300 return EXIT_SUCCESS;
301 }
302
303 if ((a_name = getarg(args, 'n')) != NULL)

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

417 rc = delnispwent(cnf->nispasswd, a_name->val);
418 if (rc == -1)
419 warnx("WARNING: user '%s' does not exist in NIS passwd", pwd->pw_name);
420 else if (rc != 0)
421 warn("WARNING: NIS passwd update");
422 /* non-fatal */
423 }
424
298 SETPWENT();
299 while ((pwd = GETPWENT()) != NULL)
300 print_user(pwd, pretty, v7);
301 ENDPWENT();
302 return EXIT_SUCCESS;
303 }
304
305 if ((a_name = getarg(args, 'n')) != NULL)

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

419 rc = delnispwent(cnf->nispasswd, a_name->val);
420 if (rc == -1)
421 warnx("WARNING: user '%s' does not exist in NIS passwd", pwd->pw_name);
422 else if (rc != 0)
423 warn("WARNING: NIS passwd update");
424 /* non-fatal */
425 }
426
425 editgroups(a_name->val, NULL);
427 grp = GETGRNAM(a_name->val);
428 if (*grp->gr_mem == NULL)
429 delgrent(GETGRNAM(a_name->val));
430 SETGRENT();
431 while ((grp = GETGRENT()) != NULL) {
432 int i;
433 char group[MAXLOGNAME];
434 for (i = 0; grp->gr_mem[i] != NULL; i++) {
435 if (!strcmp(grp->gr_mem[i], a_name->val)) {
436 while (grp->gr_mem[i] != NULL) {
437 grp->gr_mem[i] = grp->gr_mem[i+1];
438 }
439 strlcpy(group, grp->gr_name, MAXLOGNAME);
440 chggrent(group, grp);
441 }
442 }
443 }
444 ENDGRENT();
426
427 pw_log(cnf, mode, W_USER, "%s(%ld) account removed", a_name->val, (long) uid);
428
429 if (!PWALTDIR()) {
430 /*
431 * Remove mail file
432 */
433 remove(file);

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

720 }
721 }
722 }
723
724 /*
725 * Ok, user is created or changed - now edit group file
726 */
727
445
446 pw_log(cnf, mode, W_USER, "%s(%ld) account removed", a_name->val, (long) uid);
447
448 if (!PWALTDIR()) {
449 /*
450 * Remove mail file
451 */
452 remove(file);

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

739 }
740 }
741 }
742
743 /*
744 * Ok, user is created or changed - now edit group file
745 */
746
728 if (mode == M_ADD || getarg(args, 'G') != NULL)
729 editgroups(pwd->pw_name, cnf->groups);
747 if (mode == M_ADD || getarg(args, 'G') != NULL) {
748 int i, j;
749 for (i = 0; cnf->groups[i] != NULL; i++) {
750 grp = GETGRNAM(cnf->groups[i]);
751 for (j = 0; grp->gr_mem[j] != NULL; j++) {
752 if (!strcmp(grp->gr_mem[j], pwd->pw_name))
753 break;
754 }
755 if (grp->gr_mem[j] != NULL) /* user already member of group */
756 continue;
730
757
758 if (j == 0)
759 grp->gr_mem = NULL;
760
761 grp->gr_mem = reallocf(grp->gr_mem, sizeof(*grp->gr_mem) *
762 (j + 2));
763
764 grp->gr_mem[j] = pwd->pw_name;
765 grp->gr_mem[j+1] = NULL;
766 chggrent(cnf->groups[i], grp);
767 }
768 }
769
770
731 /* go get a current version of pwd */
732 pwd = GETPWNAM(a_name->val);
733 if (pwd == NULL) {
734 /* This will fail when we rename, so special case that */
735 if (mode == M_UPDATE && (arg = getarg(args, 'l')) != NULL) {
736 a_name->val = arg->val; /* update new name */
737 pwd = GETPWNAM(a_name->val); /* refetch renamed rec */
738 }

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

1085 return pw_pwcrypt(pwbuf);
1086}
1087
1088
1089static int
1090print_user(struct passwd * pwd, int pretty, int v7)
1091{
1092 if (!pretty) {
771 /* go get a current version of pwd */
772 pwd = GETPWNAM(a_name->val);
773 if (pwd == NULL) {
774 /* This will fail when we rename, so special case that */
775 if (mode == M_UPDATE && (arg = getarg(args, 'l')) != NULL) {
776 a_name->val = arg->val; /* update new name */
777 pwd = GETPWNAM(a_name->val); /* refetch renamed rec */
778 }

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

1125 return pw_pwcrypt(pwbuf);
1126}
1127
1128
1129static int
1130print_user(struct passwd * pwd, int pretty, int v7)
1131{
1132 if (!pretty) {
1093 char buf[_UC_MAXLINE];
1133 char *buf;
1094
1134
1095 fmtpwentry(buf, pwd, v7 ? PWF_PASSWD : PWF_STANDARD);
1096 fputs(buf, stdout);
1135 if (!v7)
1136 pwd->pw_passwd = (pwd->pw_passwd == NULL) ? "" : "*";
1137
1138 buf = v7 ? pw_make_v7(pwd) : pw_make(pwd);
1139 printf("%s\n", buf);
1140 free(buf);
1097 } else {
1098 int j;
1099 char *p;
1100 struct group *grp = GETGRGID(pwd->pw_gid);
1101 char uname[60] = "User &", office[60] = "[None]",
1102 wphone[60] = "[None]", hphone[60] = "[None]";
1103 char acexpire[32] = "[None]", pwexpire[32] = "[None]";
1104 struct tm * tptr;

--- 172 unchanged lines hidden ---
1141 } else {
1142 int j;
1143 char *p;
1144 struct group *grp = GETGRGID(pwd->pw_gid);
1145 char uname[60] = "User &", office[60] = "[None]",
1146 wphone[60] = "[None]", hphone[60] = "[None]";
1147 char acexpire[32] = "[None]", pwexpire[32] = "[None]";
1148 struct tm * tptr;

--- 172 unchanged lines hidden ---