Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 1 Apr 2017 09:29:47 +0000 (UTC)
From:      Baptiste Daroussin <bapt@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-10@freebsd.org
Subject:   svn commit: r316348 - in stable/10/usr.sbin/pw: . tests
Message-ID:  <201704010929.v319Tlr0059401@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: bapt
Date: Sat Apr  1 09:29:47 2017
New Revision: 316348
URL: https://svnweb.freebsd.org/changeset/base/316348

Log:
  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>

Modified:
  stable/10/usr.sbin/pw/pw_user.c
  stable/10/usr.sbin/pw/tests/pw_useradd_test.sh
Directory Properties:
  stable/10/   (props changed)

Modified: stable/10/usr.sbin/pw/pw_user.c
==============================================================================
--- stable/10/usr.sbin/pw/pw_user.c	Sat Apr  1 09:27:00 2017	(r316347)
+++ stable/10/usr.sbin/pw/pw_user.c	Sat Apr  1 09:29:47 2017	(r316348)
@@ -1179,7 +1179,7 @@ pw_user_add(int argc, char **argv, char 
 	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 
 	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 
 	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;

Modified: stable/10/usr.sbin/pw/tests/pw_useradd_test.sh
==============================================================================
--- stable/10/usr.sbin/pw/tests/pw_useradd_test.sh	Sat Apr  1 09:27:00 2017	(r316347)
+++ stable/10/usr.sbin/pw/tests/pw_useradd_test.sh	Sat Apr  1 09:29:47 2017	(r316348)
@@ -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
 }



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201704010929.v319Tlr0059401>