pw_user.c (326848) | pw_user.c (327090) |
---|---|
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: stable/11/usr.sbin/pw/pw_user.c 326848 2017-12-14 13:06:41Z eugen $"; | 30 "$FreeBSD: stable/11/usr.sbin/pw/pw_user.c 327090 2017-12-22 18:14:55Z eugen $"; |
31#endif /* not lint */ 32 33#include <sys/param.h> 34#include <sys/types.h> 35 36#include <assert.h> 37#include <ctype.h> 38#include <dirent.h> --- 1339 unchanged lines hidden (view full) --- 1378 grname = cmdcnf->default_group; 1379 1380 pwd = &fakeuser; 1381 pwd->pw_name = name; 1382 pwd->pw_class = cmdcnf->default_class ? cmdcnf->default_class : ""; 1383 pwd->pw_uid = pw_uidpolicy(cmdcnf, id); 1384 pwd->pw_gid = pw_gidpolicy(cnf, grname, pwd->pw_name, 1385 (gid_t) pwd->pw_uid, dryrun); | 31#endif /* not lint */ 32 33#include <sys/param.h> 34#include <sys/types.h> 35 36#include <assert.h> 37#include <ctype.h> 38#include <dirent.h> --- 1339 unchanged lines hidden (view full) --- 1378 grname = cmdcnf->default_group; 1379 1380 pwd = &fakeuser; 1381 pwd->pw_name = name; 1382 pwd->pw_class = cmdcnf->default_class ? cmdcnf->default_class : ""; 1383 pwd->pw_uid = pw_uidpolicy(cmdcnf, id); 1384 pwd->pw_gid = pw_gidpolicy(cnf, grname, pwd->pw_name, 1385 (gid_t) pwd->pw_uid, dryrun); |
1386 | 1386 1387 /* cmdcnf->password_days and cmdcnf->expire_days hold unixtime here */ |
1387 if (cmdcnf->password_days > 0) | 1388 if (cmdcnf->password_days > 0) |
1388 pwd->pw_change = now + cmdcnf->password_days * 86400L; | 1389 pwd->pw_change = cmdcnf->password_days; |
1389 if (cmdcnf->expire_days > 0) | 1390 if (cmdcnf->expire_days > 0) |
1390 pwd->pw_expire = now + cmdcnf->expire_days * 86400L; | 1391 pwd->pw_expire = cmdcnf->expire_days; |
1391 1392 pwd->pw_dir = pw_homepolicy(cmdcnf, homedir, pwd->pw_name); 1393 pwd->pw_shell = pw_shellpolicy(cmdcnf); 1394 lc = login_getpwclass(pwd); 1395 if (lc == NULL || login_setcryptfmt(lc, "sha512", NULL) == NULL) 1396 warn("setting crypt(3) format"); 1397 login_close(lc); 1398 pwd->pw_passwd = pw_password(cmdcnf, pwd->pw_name, dryrun); --- 117 unchanged lines hidden (view full) --- 1516 login_cap_t *lc; 1517 struct stat st; 1518 intmax_t id = -1; 1519 int ch, fd = -1; 1520 size_t i, j; 1521 bool quiet, createhome, pretty, dryrun, nis, edited; 1522 bool precrypted; 1523 mode_t homemode = 0; | 1392 1393 pwd->pw_dir = pw_homepolicy(cmdcnf, homedir, pwd->pw_name); 1394 pwd->pw_shell = pw_shellpolicy(cmdcnf); 1395 lc = login_getpwclass(pwd); 1396 if (lc == NULL || login_setcryptfmt(lc, "sha512", NULL) == NULL) 1397 warn("setting crypt(3) format"); 1398 login_close(lc); 1399 pwd->pw_passwd = pw_password(cmdcnf, pwd->pw_name, dryrun); --- 117 unchanged lines hidden (view full) --- 1517 login_cap_t *lc; 1518 struct stat st; 1519 intmax_t id = -1; 1520 int ch, fd = -1; 1521 size_t i, j; 1522 bool quiet, createhome, pretty, dryrun, nis, edited; 1523 bool precrypted; 1524 mode_t homemode = 0; |
1524 time_t expire_days, password_days, now; | 1525 time_t expire_time, password_time, now; |
1525 | 1526 |
1526 expire_days = password_days = -1; | 1527 expire_time = password_time = -1; |
1527 gecos = homedir = grname = name = newname = skel = shell =NULL; 1528 passwd = NULL; 1529 class = nispasswd = NULL; 1530 quiet = createhome = pretty = dryrun = nis = precrypted = false; 1531 edited = false; 1532 now = time(NULL); 1533 1534 if (arg1 != NULL) { --- 19 unchanged lines hidden (view full) --- 1554 break; 1555 case 'c': 1556 gecos = pw_checkname(optarg, 1); 1557 break; 1558 case 'd': 1559 homedir = optarg; 1560 break; 1561 case 'e': | 1528 gecos = homedir = grname = name = newname = skel = shell =NULL; 1529 passwd = NULL; 1530 class = nispasswd = NULL; 1531 quiet = createhome = pretty = dryrun = nis = precrypted = false; 1532 edited = false; 1533 now = time(NULL); 1534 1535 if (arg1 != NULL) { --- 19 unchanged lines hidden (view full) --- 1555 break; 1556 case 'c': 1557 gecos = pw_checkname(optarg, 1); 1558 break; 1559 case 'd': 1560 homedir = optarg; 1561 break; 1562 case 'e': |
1562 expire_days = parse_date(now, optarg); | 1563 expire_time = parse_date(now, optarg); |
1563 break; 1564 case 'p': | 1564 break; 1565 case 'p': |
1565 password_days = parse_date(now, optarg); | 1566 password_time = parse_date(now, optarg); |
1566 break; 1567 case 'g': 1568 group_from_name_or_id(optarg); 1569 grname = optarg; 1570 break; 1571 case 'G': 1572 split_groups(&groups, optarg); 1573 break; --- 118 unchanged lines hidden (view full) --- 1692 grp = GETGRGID(pw_checkid(grname, GID_MAX)); 1693 if (grp->gr_gid != pwd->pw_gid) { 1694 pwd->pw_gid = grp->gr_gid; 1695 edited = true; 1696 } 1697 } 1698 1699 | 1567 break; 1568 case 'g': 1569 group_from_name_or_id(optarg); 1570 grname = optarg; 1571 break; 1572 case 'G': 1573 split_groups(&groups, optarg); 1574 break; --- 118 unchanged lines hidden (view full) --- 1693 grp = GETGRGID(pw_checkid(grname, GID_MAX)); 1694 if (grp->gr_gid != pwd->pw_gid) { 1695 pwd->pw_gid = grp->gr_gid; 1696 edited = true; 1697 } 1698 } 1699 1700 |
1700 if (password_days >= 0) { 1701 pwd->pw_change = now + password_days * 86400L; | 1701 if (password_time >= 0 && pwd->pw_change != password_time) { 1702 pwd->pw_change = password_time; |
1702 edited = true; 1703 } 1704 | 1703 edited = true; 1704 } 1705 |
1705 if (expire_days >= 0) { 1706 pwd->pw_expire = now + expire_days * 86400L; | 1706 if (expire_time >= 0 && pwd->pw_expire != expire_time) { 1707 pwd->pw_expire = expire_time; |
1707 edited = true; 1708 } 1709 1710 if (shell) { 1711 shell = shell_path(cnf->shelldir, cnf->shells, shell); 1712 if (shell == NULL) 1713 shell = ""; 1714 if (strcmp(shell, pwd->pw_shell) != 0) { --- 122 unchanged lines hidden --- | 1708 edited = true; 1709 } 1710 1711 if (shell) { 1712 shell = shell_path(cnf->shelldir, cnf->shells, shell); 1713 if (shell == NULL) 1714 shell = ""; 1715 if (strcmp(shell, pwd->pw_shell) != 0) { --- 122 unchanged lines hidden --- |