diff options
author | schmonz <schmonz@pkgsrc.org> | 2004-08-01 18:23:35 +0000 |
---|---|---|
committer | schmonz <schmonz@pkgsrc.org> | 2004-08-01 18:23:35 +0000 |
commit | 1640604ca5e59d3ec161d5b56e3be3357777edb4 (patch) | |
tree | ce5cc7e65467761f6d338a1ad7ffed3c0de230cf /sysutils/user_darwin | |
parent | a21d375bde80f4e8c45283f25667b1002f0aa3e1 (diff) | |
download | pkgsrc-1640604ca5e59d3ec161d5b56e3be3357777edb4.tar.gz |
Move the UID- and GID-assignment stuff into functions, and model
the logic after that of NetBSD's user(8). Now we get unique IDs as
intended (instead of always getting 300).
On Panther Server, we need to send a HUP to lookupd(8) to make the
system notice a newly niload'd user account. No harm done on the
consumer version of Panther.
Ensure that PATH is set to our liking.
Bump version to 20040801.
Diffstat (limited to 'sysutils/user_darwin')
-rw-r--r-- | sysutils/user_darwin/Makefile | 4 | ||||
-rwxr-xr-x | sysutils/user_darwin/files/groupadd.sh | 29 | ||||
-rwxr-xr-x | sysutils/user_darwin/files/groupdel.sh | 2 | ||||
-rwxr-xr-x | sysutils/user_darwin/files/useradd.sh | 53 | ||||
-rwxr-xr-x | sysutils/user_darwin/files/userdel.sh | 2 |
5 files changed, 65 insertions, 25 deletions
diff --git a/sysutils/user_darwin/Makefile b/sysutils/user_darwin/Makefile index 850154510fb..74275409fe7 100644 --- a/sysutils/user_darwin/Makefile +++ b/sysutils/user_darwin/Makefile @@ -1,7 +1,7 @@ -# $NetBSD: Makefile,v 1.1.1.1 2004/04/01 02:58:32 danw Exp $ +# $NetBSD: Makefile,v 1.2 2004/08/01 18:23:35 schmonz Exp $ # -DISTNAME= user-20040331 +DISTNAME= user-20040801 CATEGORIES= sysutils MASTER_SITES= # empty DISTFILES= # empty diff --git a/sysutils/user_darwin/files/groupadd.sh b/sysutils/user_darwin/files/groupadd.sh index f7e9d92ec61..5fd6ee8156f 100755 --- a/sysutils/user_darwin/files/groupadd.sh +++ b/sysutils/user_darwin/files/groupadd.sh @@ -1,5 +1,7 @@ #!/bin/sh +PATH=/bin:/usr/bin:$PATH + while [ $# -gt 1 ]; do case $1 in -g) gid="$2" ;; @@ -8,6 +10,24 @@ while [ $# -gt 1 ]; do shift; shift done +getnextgid() +{ + # See the comments in useradd for more details. + + used_gids=`nireport . /groups gid` + low_gid=300 + + maybe_gid=$low_gid + while true; do + if echo $used_gids | grep -q $maybe_gid; then + maybe_gid=`expr $maybe_gid + 1` + else + echo $maybe_gid + return 0 + fi + done +} + group="$1" if [ -z "$group" ]; then echo "groupadd: Must specify group name" 1>&2 @@ -25,14 +45,7 @@ if [ -n "$gid" ]; then exit 1 fi else - # Find a good unused gid. See the comments in useradd for - # more details - gid=300 - nireport . /groups gid | sort -n | while read used_gid; do - if [ $gid = $used_gid ]; then - gid=`expr $gid + 1` - fi - done + gid=`getnextgid` fi echo "${group}:*:${gid}:" | niload group . diff --git a/sysutils/user_darwin/files/groupdel.sh b/sysutils/user_darwin/files/groupdel.sh index 678a0c0450c..3f1a2ef984c 100755 --- a/sysutils/user_darwin/files/groupdel.sh +++ b/sysutils/user_darwin/files/groupdel.sh @@ -1,5 +1,7 @@ #!/bin/sh +PATH=/bin:/usr/bin:$PATH + if [ $# -gt 1 ]; then echo "groupdel: Unrecognized option $1" 1>&2 exit 1 diff --git a/sysutils/user_darwin/files/useradd.sh b/sysutils/user_darwin/files/useradd.sh index fa92ffeeb55..23dfbf199d4 100755 --- a/sysutils/user_darwin/files/useradd.sh +++ b/sysutils/user_darwin/files/useradd.sh @@ -1,5 +1,7 @@ #!/bin/sh +PATH=/bin:/usr/bin:$PATH + homedir="/var/empty" shell="/usr/bin/false" @@ -15,6 +17,37 @@ while [ $# -gt 1 ]; do shift; shift done +getnextuid() +{ + # Find an unused UID. Constraints: + # * must be <500 (typical OS X user accounts are 500 and up) + # * must be <400 (Fink uses 400 and up) + # * must be from a reasonably sized range + + used_uids=`nireport . /users uid` + low_uid=300; high_uid=399 + + # Try to use the GID as the UID. + maybe_uid=$1 + if [ $maybe_uid -ge $low_uid ] && [ $maybe_uid -le $high_uid ] && \ + ! echo $used_uids | grep -q $maybe_uid; then + echo $maybe_uid + return 0 + fi + + # Else, walk the pkgsrc-"allocated" range. + maybe_uid=$low_uid + while [ $maybe_uid -le $high_uid ]; do + if echo $used_uids | grep -q $maybe_uid; then + maybe_uid=`expr $maybe_uid + 1` + else + echo $maybe_uid + return 0 + fi + done + return 1 +} + user="$1" if [ -z "$user" ]; then echo "useradd: Must specify username" 1>&2 @@ -41,22 +74,10 @@ if [ -n "$uid" ]; then exit 1 fi else - # Find an unused uid, using the gid as the default value if it's - # not already being used. Assuming this is a system account, not - # a user account, we want a UID less than 500, so OS X won't - # display it in the login window or the Accounts preference pane. - # Apple seems to be using UIDs and GIDs below (but approaching) 100, - # and fink uses UIDs starting with 400, so we'll use the 300s. - - uid=$gid - if [ $uid -lt 300 ]; then - uid=300 + if ! uid=`getnextuid $gid`; then + echo "useradd: no UIDs available in pkgsrc range" 1>&2 + exit 1 fi - nireport . /users uid | sort -n | while read used_uid; do - if [ $uid = $used_uid ]; then - uid=`expr $uid + 1` - fi - done fi echo "${user}:*:${uid}:${gid}::0:0:${comment}:${homedir}:${shell}" | niload passwd . @@ -64,3 +85,5 @@ if ! nireport . /users/$user uid 2>/dev/null; then echo "useradd: Could not create user" 1>&2 exit 1 fi + +kill -HUP `cat /var/run/lookupd.pid` diff --git a/sysutils/user_darwin/files/userdel.sh b/sysutils/user_darwin/files/userdel.sh index eed42cb0e86..56087c3b6db 100755 --- a/sysutils/user_darwin/files/userdel.sh +++ b/sysutils/user_darwin/files/userdel.sh @@ -1,5 +1,7 @@ #!/bin/sh +PATH=/bin:/usr/bin:$PATH + if [ $# -gt 1 ]; then echo "userdel: Unrecognized option $1" 1>&2 exit 1 |