pw(8): r326738 broke expiration arithmetic in case of `-D' flag not supplied.
Fix it and rename misnamed time_t variables `expire_days, password_days' (always holding absolute time) to `expire_time, password_time'. Add a comment for a case of overloading `cmdcnf->password_days' and `cmdcnf->expire_days' with absolute time. Reported by: markj Approved by: mav (mentor) MFC after: 1 week
This commit is contained in:
parent
6467a17b49
commit
a2c08ce75b
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=326872
@ -1385,11 +1385,12 @@ pw_user_add(int argc, char **argv, char *arg1)
|
|||||||
pwd->pw_uid = pw_uidpolicy(cmdcnf, id);
|
pwd->pw_uid = pw_uidpolicy(cmdcnf, id);
|
||||||
pwd->pw_gid = pw_gidpolicy(cnf, grname, pwd->pw_name,
|
pwd->pw_gid = pw_gidpolicy(cnf, grname, pwd->pw_name,
|
||||||
(gid_t) pwd->pw_uid, dryrun);
|
(gid_t) pwd->pw_uid, dryrun);
|
||||||
|
|
||||||
|
/* cmdcnf->password_days and cmdcnf->expire_days hold unixtime here */
|
||||||
if (cmdcnf->password_days > 0)
|
if (cmdcnf->password_days > 0)
|
||||||
pwd->pw_change = now + cmdcnf->password_days * 86400L;
|
pwd->pw_change = cmdcnf->password_days;
|
||||||
if (cmdcnf->expire_days > 0)
|
if (cmdcnf->expire_days > 0)
|
||||||
pwd->pw_expire = now + cmdcnf->expire_days * 86400L;
|
pwd->pw_expire = cmdcnf->expire_days;
|
||||||
|
|
||||||
pwd->pw_dir = pw_homepolicy(cmdcnf, homedir, pwd->pw_name);
|
pwd->pw_dir = pw_homepolicy(cmdcnf, homedir, pwd->pw_name);
|
||||||
pwd->pw_shell = pw_shellpolicy(cmdcnf);
|
pwd->pw_shell = pw_shellpolicy(cmdcnf);
|
||||||
@ -1523,9 +1524,9 @@ pw_user_mod(int argc, char **argv, char *arg1)
|
|||||||
bool quiet, createhome, pretty, dryrun, nis, edited;
|
bool quiet, createhome, pretty, dryrun, nis, edited;
|
||||||
bool precrypted;
|
bool precrypted;
|
||||||
mode_t homemode = 0;
|
mode_t homemode = 0;
|
||||||
time_t expire_days, password_days, now;
|
time_t expire_time, password_time, now;
|
||||||
|
|
||||||
expire_days = password_days = -1;
|
expire_time = password_time = -1;
|
||||||
gecos = homedir = grname = name = newname = skel = shell =NULL;
|
gecos = homedir = grname = name = newname = skel = shell =NULL;
|
||||||
passwd = NULL;
|
passwd = NULL;
|
||||||
class = nispasswd = NULL;
|
class = nispasswd = NULL;
|
||||||
@ -1561,10 +1562,10 @@ pw_user_mod(int argc, char **argv, char *arg1)
|
|||||||
homedir = optarg;
|
homedir = optarg;
|
||||||
break;
|
break;
|
||||||
case 'e':
|
case 'e':
|
||||||
expire_days = parse_date(now, optarg);
|
expire_time = parse_date(now, optarg);
|
||||||
break;
|
break;
|
||||||
case 'p':
|
case 'p':
|
||||||
password_days = parse_date(now, optarg);
|
password_time = parse_date(now, optarg);
|
||||||
break;
|
break;
|
||||||
case 'g':
|
case 'g':
|
||||||
group_from_name_or_id(optarg);
|
group_from_name_or_id(optarg);
|
||||||
@ -1699,13 +1700,13 @@ pw_user_mod(int argc, char **argv, char *arg1)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (password_days >= 0) {
|
if (password_time >= 0 && pwd->pw_change != password_time) {
|
||||||
pwd->pw_change = now + password_days * 86400L;
|
pwd->pw_change = password_time;
|
||||||
edited = true;
|
edited = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (expire_days >= 0) {
|
if (expire_time >= 0 && pwd->pw_expire != expire_time) {
|
||||||
pwd->pw_expire = now + expire_days * 86400L;
|
pwd->pw_expire = expire_time;
|
||||||
edited = true;
|
edited = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user