Subject: bin/11123: user(8) and useradd(8) do not support -G
To: None <gnats-bugs@gnats.netbsd.org>
From: None <dme@dme.org>
List: netbsd-bugs
Date: 10/03/2000 05:27:20
>Number:         11123
>Category:       bin
>Synopsis:       user(8) and useradd(8) do not support -G
>Confidential:   no
>Severity:       non-critical
>Priority:       medium
>Responsible:    bin-bug-people
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Tue Oct 03 05:33:00 PDT 2000
>Closed-Date:
>Last-Modified:
>Originator:     David Edmondson
>Release:        gnats-3.101
>Organization:
	None.
>Environment:
System: NetBSD serafina-pekkala.dme.org 1.5_ALPHA2 NetBSD 1.5_ALPHA2 (S-P) #3: Wed Sep 20 22:16:37 BST 2000 dme@serafina-pekkala.dme.org:/home/dme/netbsd/1.5_ALPHA2/sys/arch/i386/compile/S-P i386


>Description:
	The manual pages and usage messages for user(8) and useradd(8)
	indicate that a list of supplemental groups can be indicated
	using the -G argument.  Neither user(8) nor useradd(8)
	actually support this.
>How-To-Repeat:
	As root:
		# useradd -G wheel idontexist
	check /etc/group - idontexist has not been added to group
	wheel.
>Fix:
	The following patch adds support for -G to user(8) (and
	therefore to useradd(8)).

	There is also new code to issue a warning if a non-existent
	group is used.

	The patch should be applied in basesrc/usr.sbin/user.


Index: user.c
===================================================================
RCS file: /cvsroot/basesrc/usr.sbin/user/user.c,v
retrieving revision 1.24
diff -c -r1.24 user.c
*** user.c	2000/10/01 08:56:28	1.24
--- user.c	2000/10/03 12:24:54
***************
*** 414,420 ****
  	int		j;
  
  	for (i = 0 ; i < ngroups ; i++) {
! 		if ((grp = getgrnam(groups[i])) != NULL) {
  			for (j = 0 ; grp->gr_mem[j] ; j++) {
  				if (strcmp(user, grp->gr_mem[j]) == 0) {
  					/* already in it */
--- 414,424 ----
  	int		j;
  
  	for (i = 0 ; i < ngroups ; i++) {
! 		if ((grp = getgrnam(groups[i])) == NULL) {
! 			warn("can't append group %s for %s",
! 			     groups[i], user);
! 			groups[i] = "";
! 		} else {
  			for (j = 0 ; grp->gr_mem[j] ; j++) {
  				if (strcmp(user, grp->gr_mem[j]) == 0) {
  					/* already in it */
***************
*** 853,858 ****
--- 857,870 ----
  		(void) close(ptmpfd);
  		(void) pw_abort();
  		err(EXIT_FAILURE, "can't create gid %d for login name %s", gid, login);
+ 	}
+ 	if (up->u_groupc > 0 &&
+ 	    !append_group(login, up->u_groupc, up->u_groupv)) {
+ 		(void) close(ptmpfd);
+ 		(void) pw_abort();
+ 		errx(EXIT_FAILURE,
+ 		     "can't append `%s' to new groups",
+ 		     login);
  	}
  	(void) close(ptmpfd);
  	if (pw_mkdb() < 0) {
>Release-Note:
>Audit-Trail:
>Unformatted: