From owner-freebsd-hackers Fri Feb 7 0:11: 8 2003 Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 22A3637B401 for ; Fri, 7 Feb 2003 00:11:06 -0800 (PST) Received: from skywalker.creative.net.au (skywalker.creative.net.au [203.56.168.1]) by mx1.FreeBSD.org (Postfix) with SMTP id E416043FDD for ; Fri, 7 Feb 2003 00:11:04 -0800 (PST) (envelope-from freebsd@skywalker.creative.net.au) Received: (qmail 86379 invoked by uid 1008); 7 Feb 2003 08:10:57 -0000 Date: Fri, 7 Feb 2003 16:10:56 +0800 From: Adrian Chadd To: freebsd-hackers@freebsd.org Subject: adduser change: telling you when a group isn't there Message-ID: <20030207081056.GA84685@skywalker.creative.net.au> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.4i Sender: owner-freebsd-hackers@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG 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 To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-hackers" in the body of the message