diff options
author | bapt <bapt@FreeBSD.org> | 2017-04-01 09:27:00 +0000 |
---|---|---|
committer | bapt <bapt@FreeBSD.org> | 2017-04-01 09:27:00 +0000 |
commit | 867866d608759d41f5060dedc73289f91d26f98d (patch) | |
tree | f7d5bfc87dacacd9a6309ff274a4cb1568a11335 /usr.sbin/pw | |
parent | 8704b0b19561ae51f61022fc7b5cbe100ca76014 (diff) | |
download | FreeBSD-src-867866d608759d41f5060dedc73289f91d26f98d.zip FreeBSD-src-867866d608759d41f5060dedc73289f91d26f98d.tar.gz |
MFC: r315912 (by eugen@) and r315935
Properly initialise with content of pw.conf(5) that was mistakenly ignored.
Also, respect "defaultgroup" if specified there.
Add a regression test
PR: 217934
Reported by: Victor Sudakov <vas@mpeks.tomsk.su>
Diffstat (limited to 'usr.sbin/pw')
-rw-r--r-- | usr.sbin/pw/pw_user.c | 7 | ||||
-rwxr-xr-x | usr.sbin/pw/tests/pw_useradd_test.sh | 14 |
2 files changed, 19 insertions, 2 deletions
diff --git a/usr.sbin/pw/pw_user.c b/usr.sbin/pw/pw_user.c index 8cffac9..5466bec 100644 --- a/usr.sbin/pw/pw_user.c +++ b/usr.sbin/pw/pw_user.c @@ -1177,7 +1177,7 @@ 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; - const char *cfg; + const char *cfg = NULL; login_cap_t *lc; FILE *pfp, *fp; intmax_t id = -1; @@ -1356,6 +1356,9 @@ pw_user_add(int argc, char **argv, char *arg1) if (GETPWNAM(name) != NULL) errx(EX_DATAERR, "login name `%s' already exists", name); + if (!grname) + grname = cmdcnf->default_group; + pwd = &fakeuser; pwd->pw_name = name; pwd->pw_class = cmdcnf->default_class ? cmdcnf->default_class : ""; @@ -1485,7 +1488,7 @@ pw_user_mod(int argc, char **argv, char *arg1) struct group *grp; StringList *groups = NULL; char args[] = "C:qn:u:c:d:e:p:g:G:mM:l:k:s:w:L:h:H:NPYy:"; - const char *cfg; + const char *cfg = NULL; char *gecos, *homedir, *grname, *name, *newname, *walk, *skel, *shell; char *passwd, *class, *nispasswd; login_cap_t *lc; diff --git a/usr.sbin/pw/tests/pw_useradd_test.sh b/usr.sbin/pw/tests/pw_useradd_test.sh index b1ff8d4..d14e4dd 100755 --- a/usr.sbin/pw/tests/pw_useradd_test.sh +++ b/usr.sbin/pw/tests/pw_useradd_test.sh @@ -384,6 +384,19 @@ user_add_with_pw_conf_body() atf_check -s exit:0 \ ${PW} useradd foo -C ${HOME}/pw.conf } +atf_test_case user_add_defaultgroup +user_add_defaultgroup_body() +{ + populate_etc_skel + echo 'defaultgroup = "plop"' > ${HOME}/pw.conf + atf_check -s exit:0 \ + ${PW} groupadd plop -g 442 + atf_check -s exit:0 \ + ${PW} useradd foo -C ${HOME}/pw.conf + atf_check -s exit:0 \ + -o inline:"foo:*:1001:442::0:0:User &:/home/foo:/bin/sh\n" \ + ${PW} usershow foo +} atf_init_test_cases() { atf_add_test_case user_add @@ -419,4 +432,5 @@ atf_init_test_cases() { atf_add_test_case user_add_w_random atf_add_test_case user_add_w_yes atf_add_test_case user_add_with_pw_conf + atf_add_test_case user_add_defaultgroup } |