From owner-freebsd-current Fri Feb 7 0:30:12 2003 Delivered-To: freebsd-current@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 617E137B401 for ; Fri, 7 Feb 2003 00:30:09 -0800 (PST) Received: from skywalker.creative.net.au (skywalker.creative.net.au [203.56.168.1]) by mx1.FreeBSD.org (Postfix) with SMTP id 3D02F43FBD for ; Fri, 7 Feb 2003 00:30:08 -0800 (PST) (envelope-from freebsd@skywalker.creative.net.au) Received: (qmail 86702 invoked by uid 1008); 7 Feb 2003 08:30:07 -0000 Date: Fri, 7 Feb 2003 16:30:07 +0800 From: Adrian Chadd 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> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.4i Sender: owner-freebsd-current@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG Oops. I should have sent this to -current :-P adrian ----- Forwarded message from Adrian Chadd ----- 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 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 learning is bad it just makes the people around you dumber (angryskul == alfred@irc) :( To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-current" in the body of the message