This implements a subset of useradd(8)/groupadd(8) functionality on

Darwin that is sufficient for pkgsrc use.
This commit is contained in:
danw 2004-04-01 02:58:32 +00:00
parent 22cc61d2c3
commit 1b7d430c4a
7 changed files with 177 additions and 0 deletions

View file

@ -0,0 +1,2 @@
This implements a subset of useradd(8)/groupadd(8) functionality on
Darwin that is sufficient for pkgsrc use.

View file

@ -0,0 +1,28 @@
# $NetBSD: Makefile,v 1.1.1.1 2004/04/01 02:58:32 danw Exp $
#
DISTNAME= user-20040331
CATEGORIES= sysutils
MASTER_SITES= # empty
DISTFILES= # empty
MAINTAINER= danw@NetBSD.org
COMMENT= Limited NetBSD-compatible useradd/groupadd commands
ONLY_FOR_PLATFORM= Darwin-*-*
PKG_INSTALLATION_TYPES= overwrite pkgviews
NO_CHECKSUM= yes
NO_BUILDLINK= yes
NO_CONFIGURE= yes
NO_TOOLS= yes
NO_BUILD= yes
do-install:
${INSTALL_SCRIPT} ${FILESDIR}/useradd.sh ${PREFIX}/sbin/useradd
${INSTALL_SCRIPT} ${FILESDIR}/userdel.sh ${PREFIX}/sbin/userdel
${INSTALL_SCRIPT} ${FILESDIR}/groupadd.sh ${PREFIX}/sbin/groupadd
${INSTALL_SCRIPT} ${FILESDIR}/groupdel.sh ${PREFIX}/sbin/groupdel
.include "../../mk/bsd.pkg.mk"

View file

@ -0,0 +1,5 @@
@comment $NetBSD: PLIST,v 1.1.1.1 2004/04/01 02:58:32 danw Exp $
sbin/groupadd
sbin/groupdel
sbin/useradd
sbin/userdel

View file

@ -0,0 +1,42 @@
#!/bin/sh
while [ $# -gt 1 ]; do
case $1 in
-g) gid="$2" ;;
*) echo "groupadd: Unrecognized option $1" 1>&2; exit 1; ;;
esac
shift; shift
done
group="$1"
if [ -z "$group" ]; then
echo "groupadd: Must specify group name" 1>&2
exit 1
fi
if nireport . /groups/$group gid 2>/dev/null; then
echo "groupadd: Group '$group' already exists" 1>&2
exit 1
fi
if [ -n "$gid" ]; then
if nireport . /groups/gid=$gid gid 2>/dev/null; then
echo "groupadd: GID $gid already exists" 1>&2
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
fi
echo "${group}:*:${gid}:" | niload group .
if ! nireport . /groups/$group gid 2>/dev/null; then
echo "groupadd: Could not create group" 1>&2
exit 1
fi

View file

@ -0,0 +1,17 @@
#!/bin/sh
if [ $# -gt 1 ]; then
echo "groupdel: Unrecognized option $1" 1>&2
exit 1
fi
group="$1"
if [ -z "$group" ]; then
echo "groupdel: Must specify group" 1>&2
exit 1
fi
if ! niutil -destroy . /groups/$group 2>/dev/null; then
echo "groupdel: Could not delete group" 1>&2
exit 1
fi

View file

@ -0,0 +1,66 @@
#!/bin/sh
homedir="/var/empty"
shell="/usr/bin/false"
while [ $# -gt 1 ]; do
case $1 in
-c) comment="$2" ;;
-d) homedir="$2" ;;
-g) group="$2" ;;
-s) shell="$2" ;;
-u) uid="$2" ;;
*) echo "useradd: Unrecognized option $1" 1>&2; exit 1; ;;
esac
shift; shift
done
user="$1"
if [ -z "$user" ]; then
echo "useradd: Must specify username" 1>&2
exit 1
fi
if nireport . /users/$user uid 2>/dev/null; then
echo "useradd: User '$user' already exists" 1>&2
exit 1
fi
if [ -z "$group" ]; then
echo "useradd: Must specify group name" 1>&2
exit 1
fi
gid=`niutil -readprop . /groups/$group gid 2>/dev/null`
if [ -z "$gid" ]; then
echo "useradd: No group '$group'" 1>&2
exit 1
fi
if [ -n "$uid" ]; then
if nireport . /users/uid=$uid uid 2>/dev/null; then
echo "useradd: UID $uid already exists" 1>&2
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
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 .
if ! nireport . /users/$user uid 2>/dev/null; then
echo "useradd: Could not create user" 1>&2
exit 1
fi

View file

@ -0,0 +1,17 @@
#!/bin/sh
if [ $# -gt 1 ]; then
echo "userdel: Unrecognized option $1" 1>&2
exit 1
fi
user="$1"
if [ -z "$user" ]; then
echo "userdel: Must specify username" 1>&2
exit 1
fi
if ! niutil -destroy . /users/$user 2>/dev/null; then
echo "userdel: Could not delete user" 1>&2
exit 1
fi