From owner-svn-src-head@freebsd.org Fri Dec 15 06:05:17 2017 Return-Path: Delivered-To: svn-src-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 6CCAAE9C4DD; Fri, 15 Dec 2017 06:05:17 +0000 (UTC) (envelope-from eugen@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 4687868FC4; Fri, 15 Dec 2017 06:05:17 +0000 (UTC) (envelope-from eugen@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id vBF65GYW011436; Fri, 15 Dec 2017 06:05:16 GMT (envelope-from eugen@FreeBSD.org) Received: (from eugen@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id vBF65GYp011435; Fri, 15 Dec 2017 06:05:16 GMT (envelope-from eugen@FreeBSD.org) Message-Id: <201712150605.vBF65GYp011435@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: eugen set sender to eugen@FreeBSD.org using -f From: Eugene Grosbein Date: Fri, 15 Dec 2017 06:05:16 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r326872 - head/usr.sbin/pw X-SVN-Group: head X-SVN-Commit-Author: eugen X-SVN-Commit-Paths: head/usr.sbin/pw X-SVN-Commit-Revision: 326872 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.25 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 15 Dec 2017 06:05:17 -0000 Author: eugen Date: Fri Dec 15 06:05:16 2017 New Revision: 326872 URL: https://svnweb.freebsd.org/changeset/base/326872 Log: 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 Modified: head/usr.sbin/pw/pw_user.c Modified: head/usr.sbin/pw/pw_user.c ============================================================================== --- head/usr.sbin/pw/pw_user.c Fri Dec 15 04:51:47 2017 (r326871) +++ head/usr.sbin/pw/pw_user.c Fri Dec 15 06:05:16 2017 (r326872) @@ -1385,11 +1385,12 @@ pw_user_add(int argc, char **argv, char *arg1) pwd->pw_uid = pw_uidpolicy(cmdcnf, id); pwd->pw_gid = pw_gidpolicy(cnf, grname, pwd->pw_name, (gid_t) pwd->pw_uid, dryrun); - + + /* cmdcnf->password_days and cmdcnf->expire_days hold unixtime here */ if (cmdcnf->password_days > 0) - pwd->pw_change = now + cmdcnf->password_days * 86400L; + pwd->pw_change = cmdcnf->password_days; 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_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 precrypted; 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; passwd = NULL; class = nispasswd = NULL; @@ -1561,10 +1562,10 @@ pw_user_mod(int argc, char **argv, char *arg1) homedir = optarg; break; case 'e': - expire_days = parse_date(now, optarg); + expire_time = parse_date(now, optarg); break; case 'p': - password_days = parse_date(now, optarg); + password_time = parse_date(now, optarg); break; case 'g': group_from_name_or_id(optarg); @@ -1699,13 +1700,13 @@ pw_user_mod(int argc, char **argv, char *arg1) } - if (password_days >= 0) { - pwd->pw_change = now + password_days * 86400L; + if (password_time >= 0 && pwd->pw_change != password_time) { + pwd->pw_change = password_time; edited = true; } - if (expire_days >= 0) { - pwd->pw_expire = now + expire_days * 86400L; + if (expire_time >= 0 && pwd->pw_expire != expire_time) { + pwd->pw_expire = expire_time; edited = true; }