diff options
author | bapt <bapt@FreeBSD.org> | 2017-04-01 09:29:47 +0000 |
---|---|---|
committer | bapt <bapt@FreeBSD.org> | 2017-04-01 09:29:47 +0000 |
commit | 974e1c547e80517d4415bc0cdcfa130dc11c29a5 (patch) | |
tree | cbef39eaaba43faf2935b8a93613f8978b3260d5 /usr.sbin | |
parent | f0e80d829a6d0ff8bb7a46bd3a18dd6159b14284 (diff) | |
download | FreeBSD-src-974e1c547e80517d4415bc0cdcfa130dc11c29a5.zip FreeBSD-src-974e1c547e80517d4415bc0cdcfa130dc11c29a5.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
Submitted by: Victor Sudakov <vas@mpeks.tomsk.su>
Diffstat (limited to 'usr.sbin')
-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 96f4a17..f93f9ed 100644 --- a/usr.sbin/pw/pw_user.c +++ b/usr.sbin/pw/pw_user.c @@ -1179,7 +1179,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; @@ -1358,6 +1358,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 : ""; @@ -1487,7 +1490,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 } |