pkgsrc-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[pkgsrc/trunk]: pkgsrc/sysutils/user_darwin Move the UID- and GID-assignment ...
details: https://anonhg.NetBSD.org/pkgsrc/rev/16438706272d
branches: trunk
changeset: 478906:16438706272d
user: schmonz <schmonz%pkgsrc.org@localhost>
date: Sun Aug 01 18:23:35 2004 +0000
description:
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:
sysutils/user_darwin/Makefile | 4 +-
sysutils/user_darwin/files/groupadd.sh | 29 +++++++++++++-----
sysutils/user_darwin/files/groupdel.sh | 2 +
sysutils/user_darwin/files/useradd.sh | 53 ++++++++++++++++++++++++---------
sysutils/user_darwin/files/userdel.sh | 2 +
5 files changed, 65 insertions(+), 25 deletions(-)
diffs (168 lines):
diff -r 776a68909c5b -r 16438706272d sysutils/user_darwin/Makefile
--- a/sysutils/user_darwin/Makefile Sun Aug 01 17:55:05 2004 +0000
+++ b/sysutils/user_darwin/Makefile Sun Aug 01 18:23:35 2004 +0000
@@ -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 -r 776a68909c5b -r 16438706272d sysutils/user_darwin/files/groupadd.sh
--- a/sysutils/user_darwin/files/groupadd.sh Sun Aug 01 17:55:05 2004 +0000
+++ b/sysutils/user_darwin/files/groupadd.sh Sun Aug 01 18:23:35 2004 +0000
@@ -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 @@
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 @@
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 -r 776a68909c5b -r 16438706272d sysutils/user_darwin/files/groupdel.sh
--- a/sysutils/user_darwin/files/groupdel.sh Sun Aug 01 17:55:05 2004 +0000
+++ b/sysutils/user_darwin/files/groupdel.sh Sun Aug 01 18:23:35 2004 +0000
@@ -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 -r 776a68909c5b -r 16438706272d sysutils/user_darwin/files/useradd.sh
--- a/sysutils/user_darwin/files/useradd.sh Sun Aug 01 17:55:05 2004 +0000
+++ b/sysutils/user_darwin/files/useradd.sh Sun Aug 01 18:23:35 2004 +0000
@@ -1,5 +1,7 @@
#!/bin/sh
+PATH=/bin:/usr/bin:$PATH
+
homedir="/var/empty"
shell="/usr/bin/false"
@@ -15,6 +17,37 @@
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 @@
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 @@
echo "useradd: Could not create user" 1>&2
exit 1
fi
+
+kill -HUP `cat /var/run/lookupd.pid`
diff -r 776a68909c5b -r 16438706272d sysutils/user_darwin/files/userdel.sh
--- a/sysutils/user_darwin/files/userdel.sh Sun Aug 01 17:55:05 2004 +0000
+++ b/sysutils/user_darwin/files/userdel.sh Sun Aug 01 18:23:35 2004 +0000
@@ -1,5 +1,7 @@
#!/bin/sh
+PATH=/bin:/usr/bin:$PATH
+
if [ $# -gt 1 ]; then
echo "userdel: Unrecognized option $1" 1>&2
exit 1
Home |
Main Index |
Thread Index |
Old Index