FreeBSD Bugzilla – Attachment 187757 Details for
Bug 223431
"pw useradd -D -e" writes bogus expire_days value into pw.conf
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
Remember
[x]
|
Forgot Password
Login:
[x]
[patch]
fix -e and -p with -D, properly use the config values
pw.diff (text/plain), 3.73 KB, created by
Yuri Pankov
on 2017-11-05 13:28:11 UTC
(
hide
)
Description:
fix -e and -p with -D, properly use the config values
Filename:
MIME Type:
Creator:
Yuri Pankov
Created:
2017-11-05 13:28:11 UTC
Size:
3.73 KB
patch
obsolete
>diff --git a/usr.sbin/pw/pw_conf.c b/usr.sbin/pw/pw_conf.c >index a3bd0bd36733..8688196352e7 100644 >--- a/usr.sbin/pw/pw_conf.c >+++ b/usr.sbin/pw/pw_conf.c >@@ -426,7 +426,7 @@ write_userconfig(struct userconf *cnf, const char *file) > close(fd); > return (0); > } >- >+ > buf = sbuf_new_auto(); > for (i = _UC_NONE; i < _UC_FIELDS; i++) { > int quote = 1; >diff --git a/usr.sbin/pw/pw_user.c b/usr.sbin/pw/pw_user.c >index 92d5c6c5dbb5..2fe669c45b17 100644 >--- a/usr.sbin/pw/pw_user.c >+++ b/usr.sbin/pw/pw_user.c >@@ -22,7 +22,7 @@ > * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY > * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF > * SUCH DAMAGE. >- * >+ * > */ > > #ifndef lint >@@ -1123,7 +1123,8 @@ validate_mode(char *mode) > } > > static void >-mix_config(struct userconf *cmdcnf, struct userconf *cfg) >+mix_config(struct userconf *cmdcnf, struct userconf *cfg, bool genconf, >+ char *edays, char *pdays) > { > > if (cmdcnf->default_password == 0) >@@ -1164,10 +1165,59 @@ mix_config(struct userconf *cmdcnf, struct userconf *cfg) > cmdcnf->min_gid = cfg->min_gid; > if (cmdcnf->max_gid == 0) > cmdcnf->max_gid = cfg->max_gid; >- if (cmdcnf->expire_days == 0) >- cmdcnf->expire_days = cfg->expire_days; >- if (cmdcnf->password_days == 0) >- cmdcnf->password_days = cfg->password_days; >+ >+ /* >+ * If we are writing the config, use the values specified on the command >+ * line. Otherwise, if the values are not specified, use the ones from >+ * config file. >+ */ >+ if (genconf) { >+ const char *errstr; >+ >+ if (edays != NULL) { >+ cmdcnf->expire_days = strtonum(edays, 0, INT_MAX, >+ &errstr); >+ if (errstr != NULL) { >+ errx(EX_USAGE, "argument to -e must be " >+ "numeric if -D is specified"); >+ } >+ } >+ if (pdays != NULL) { >+ cmdcnf->password_days = strtonum(pdays, 0, INT_MAX, >+ &errstr); >+ if (errstr != NULL) { >+ errx(EX_USAGE, "argument to -p must be " >+ "numeric if -D is specified"); >+ } >+ } >+ } else { >+ char *tmp; >+ time_t now; >+ >+ if (edays != NULL) >+ tmp = strdup(edays); >+ else if (cfg->expire_days != 0) >+ asprintf(&tmp, "+%ldd", cfg->expire_days); >+ else >+ tmp = strdup("0"); >+ if (tmp == NULL) >+ errx(EX_UNAVAILABLE, "out of memory"); >+ now = time(NULL); >+ cmdcnf->expire_days = parse_date(now, tmp); >+ free(tmp); >+ >+ if (pdays != NULL) >+ tmp = strdup(pdays); >+ else if (cfg->password_days != 0) >+ asprintf(&tmp, "+%ldd", cfg->password_days); >+ else >+ tmp = strdup("0"); >+ if (tmp == NULL) >+ errx(EX_UNAVAILABLE, "out of memory"); >+ now = time(NULL); >+ cmdcnf->password_days = parse_date(now, tmp); >+ free(tmp); >+ } > } > > int >@@ -1181,11 +1231,11 @@ pw_user_add(int argc, char **argv, char *arg1) > char line[_PASSWORD_LEN+1], path[MAXPATHLEN]; > char *gecos, *homedir, *skel, *walk, *userid, *groupid, *grname; > char *default_passwd, *name, *p; >+ char *edays = NULL, *pdays = NULL; > const char *cfg = NULL; > login_cap_t *lc; > FILE *pfp, *fp; > intmax_t id = -1; >- time_t now; > int rc, ch, fd = -1; > size_t i; > bool dryrun, nis, pretty, quiet, createhome, precrypted, genconf; >@@ -1226,12 +1276,10 @@ pw_user_add(int argc, char **argv, char *arg1) > homedir = optarg; > break; > case 'e': >- now = time(NULL); >- cmdcnf->expire_days = parse_date(now, optarg); >+ edays = optarg; > break; > case 'p': >- now = time(NULL); >- cmdcnf->password_days = parse_date(now, optarg); >+ pdays = optarg; > break; > case 'g': > validate_grname(cmdcnf, optarg); >@@ -1317,7 +1365,7 @@ pw_user_add(int argc, char **argv, char *arg1) > > cnf = get_userconfig(cfg); > >- mix_config(cmdcnf, cnf); >+ mix_config(cmdcnf, cnf, genconf, edays, pdays); > if (default_passwd) > cmdcnf->default_password = passwd_val(default_passwd, > cnf->default_password);
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 223431
:
187753
|
187757
|
187758
|
187759
|
187765