Skip site navigation (1)Skip section navigation (2)
Date:      Fri, 7 Feb 2003 16:30:07 +0800
From:      Adrian Chadd <adrian@freebsd.org>
To:        freebsd-current@freebsd.org
Subject:   [adrian@freebsd.org: adduser change: telling you when a group isn't there]
Message-ID:  <20030207083007.GD84685@skywalker.creative.net.au>

next in thread | raw e-mail | index | archive | help

Oops. I should have sent this to -current :-P




adrian

----- Forwarded message from Adrian Chadd <adrian@freebsd.org> -----

Date: Fri, 7 Feb 2003 16:10:56 +0800
From: Adrian Chadd <adrian@freebsd.org>
To: freebsd-hackers@freebsd.org
Subject: adduser change: telling you when a group isn't there
User-Agent: Mutt/1.4i



Hi,

The adduser in -current doesn't check if a specified group exists until
the call to pw right at the end. eep.

My sh foo isn't terribly great, but this did it for me.

Comments/rewrites are welcome. I'll commit the group consensus. 




Adrian


diff:

--- /usr/src/usr.sbin/adduser/adduser.sh	Fri Jan 24 02:05:51 2003
+++ adduser.sh	Fri Feb  7 08:04:15 2003
@@ -47,6 +47,16 @@
 	fi
 }
 
+# Check whether the given group exists
+check_group() {
+	${PWCMD} show group $1 1> /dev/null 2> /dev/null
+	if [ "$?" = "0" ]; then
+		echo "1"
+		return
+	fi
+	echo "0"
+}
+
 # get_nextuid
 #	Output the value of $_uid if it is available for use. If it
 #	is not, output the value of the next higher uid that is available.
@@ -570,8 +580,31 @@
 	get_user
 	get_gecos
 	get_uid
-	get_logingroup
-	get_groups
+	ok="NO"
+
+	# The code creates a group = $user if one doesn't exist.
+	# We are just going to capture other non-existant groups!
+	while [ "$ok" = "NO" ] ; do
+		ok="YES"
+		get_logingroup
+		if [ "$ulogingroup" != "" -a "$username" != "$ulogingroup" -a "`check_group $ulogingroup`" = "0" ]; then
+			echo "Group $ulogingroup does not exist!"
+			ok="NO"
+		fi
+	done
+
+	ok="NO"
+	while [ "$ok" = "NO" ] ; do
+		ok="YES"
+		get_groups
+		for i in $ugroups; do
+			if [ "$username" != "$i" -a "`check_group $i`" = "0" ]; then
+				echo "Group $i does not exist!"
+				ok="NO"
+			fi
+		done
+	done
+
 	get_class
 	get_shell
 	get_homedir


----- End forwarded message -----

-- 
Adrian Chadd			<angryskul> learning is bad
<adrian@FreeBSD.org>		  <angryskul> it just makes the people around you dumber
(angryskul == alfred@irc)	    <angryskul> :(


To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-current" in the body of the message




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