summaryrefslogtreecommitdiff
path: root/sysutils/user_cygwin
diff options
context:
space:
mode:
authorobache <obache>2013-03-06 12:37:15 +0000
committerobache <obache>2013-03-06 12:37:15 +0000
commit753a49f30c856c14ce2b9b8316766154230a1903 (patch)
tree891b405f7f83f10bf38020336b4d78fea5158b81 /sysutils/user_cygwin
parentae927c185602ea5c9019b48567c4d3b54a30966b (diff)
downloadpkgsrc-753a49f30c856c14ce2b9b8316766154230a1903.tar.gz
Import user-20130306 as sysutils/user_cygwin.
This implements a subset of useradd(8)/groupadd(8) functionality on Cygwin that is sufficient for pkgsrc use.
Diffstat (limited to 'sysutils/user_cygwin')
-rw-r--r--sysutils/user_cygwin/DESCR2
-rw-r--r--sysutils/user_cygwin/Makefile26
-rw-r--r--sysutils/user_cygwin/PLIST5
-rwxr-xr-xsysutils/user_cygwin/files/groupadd.sh32
-rwxr-xr-xsysutils/user_cygwin/files/groupdel.sh29
-rwxr-xr-xsysutils/user_cygwin/files/useradd.sh129
-rwxr-xr-xsysutils/user_cygwin/files/userdel.sh47
7 files changed, 270 insertions, 0 deletions
diff --git a/sysutils/user_cygwin/DESCR b/sysutils/user_cygwin/DESCR
new file mode 100644
index 00000000000..88e2421e15b
--- /dev/null
+++ b/sysutils/user_cygwin/DESCR
@@ -0,0 +1,2 @@
+This implements a subset of useradd(8)/groupadd(8) functionality on
+Cygwin that is sufficient for pkgsrc use.
diff --git a/sysutils/user_cygwin/Makefile b/sysutils/user_cygwin/Makefile
new file mode 100644
index 00000000000..c272bb6cdca
--- /dev/null
+++ b/sysutils/user_cygwin/Makefile
@@ -0,0 +1,26 @@
+# $NetBSD: Makefile,v 1.1 2013/03/06 12:37:15 obache Exp $
+#
+
+DISTNAME= user-20130306
+CATEGORIES= sysutils
+MASTER_SITES= # empty
+DISTFILES= # empty
+
+MAINTAINER= obache@NetBSD.org
+COMMENT= Limited NetBSD-compatible useradd/groupadd commands
+
+ONLY_FOR_PLATFORM= Cygwin-*-*
+
+PKG_INSTALLATION_TYPES= overwrite pkgviews
+
+NO_CONFIGURE= yes
+NO_BUILD= yes
+
+INSTALLATION_DIRS= sbin
+
+do-install:
+.for f in useradd userdel groupadd groupdel
+ ${INSTALL_SCRIPT} ${FILESDIR}/${f}.sh ${DESTDIR}${PREFIX}/sbin/${f}
+.endfor
+
+.include "../../mk/bsd.pkg.mk"
diff --git a/sysutils/user_cygwin/PLIST b/sysutils/user_cygwin/PLIST
new file mode 100644
index 00000000000..b925c385942
--- /dev/null
+++ b/sysutils/user_cygwin/PLIST
@@ -0,0 +1,5 @@
+@comment $NetBSD: PLIST,v 1.1 2013/03/06 12:37:15 obache Exp $
+sbin/groupadd
+sbin/groupdel
+sbin/useradd
+sbin/userdel
diff --git a/sysutils/user_cygwin/files/groupadd.sh b/sysutils/user_cygwin/files/groupadd.sh
new file mode 100755
index 00000000000..17e7752f0d6
--- /dev/null
+++ b/sysutils/user_cygwin/files/groupadd.sh
@@ -0,0 +1,32 @@
+#!/bin/bash
+# $NetBSD: groupadd.sh,v 1.1 2013/03/06 12:37:15 obache Exp $
+
+export PATH=/bin:$PATH
+
+show_usage () {
+ echo "usage: $0 [-v] group" >&2
+ exit 1
+}
+
+verbose=false
+run_cmd () {
+ if $verbose; then printf '%s\n' "+ $*"; fi
+ "$@"
+}
+
+while getopts 'g:ov' f; do
+ case $f in
+ g) echo "$0: numeric gid cannot be set manually; ignoring" >&2;;
+ o) echo "$0: cannot reuse numeric gid of another group; aborting" >&2; exit 1;;
+ v) verbose=true;;
+ \?) show_usage;;
+ esac
+done
+shift $(($OPTIND - 1))
+
+if [ $# -ne 1 ]; then show_usage; fi
+$verbose || exec >/dev/null
+
+run_cmd net localgroup $1 /add /comment:"Group added by Cygwin groupadd command" || exit 1
+### regenerate cygwin /etc/group
+(/bin/flock -x -n 9 || exit 1; /bin/mkgroup -l -g "$1" >&9 ) 9>> /etc/group
diff --git a/sysutils/user_cygwin/files/groupdel.sh b/sysutils/user_cygwin/files/groupdel.sh
new file mode 100755
index 00000000000..0ef65063657
--- /dev/null
+++ b/sysutils/user_cygwin/files/groupdel.sh
@@ -0,0 +1,29 @@
+#!/bin/bash
+# $NetBSD: groupdel.sh,v 1.1 2013/03/06 12:37:16 obache Exp $
+
+export PATH=/bin:$PATH
+
+show_usage () {
+ echo "usage: $0 [-v] group" >&2
+ exit 1
+}
+
+verbose=false
+run_cmd () {
+ if $verbose; then printf '%s\n' "+ $*"; fi
+ "$@"
+}
+
+while getopts 'v' f; do
+ case $f in
+ v) verbose=true;;
+ \?) show_usage;;
+ esac
+done
+shift $(($OPTIND - 1))
+
+if [ $# -ne 1 ]; then show_usage; fi
+$verbose || exec >/dev/null
+
+run_cmd net localgroup $1 /delete || exit 1
+/bin/sed -i -e "/^$1.*/d" /etc/group
diff --git a/sysutils/user_cygwin/files/useradd.sh b/sysutils/user_cygwin/files/useradd.sh
new file mode 100755
index 00000000000..c42968766b9
--- /dev/null
+++ b/sysutils/user_cygwin/files/useradd.sh
@@ -0,0 +1,129 @@
+#!/bin/bash
+# $NetBSD: useradd.sh,v 1.1 2013/03/06 12:37:16 obache Exp $
+
+export PATH=/bin:$PATH
+
+show_usage () {
+ echo "usage: $0 [-mv] [-G secondary-group] [-b base-dir] [-c comment] [-d home-dir] [-g group|=uid] user" >&2
+ echo " $0 -D" >&2
+ exit 1
+}
+
+verbose=false
+run_cmd () {
+ if $verbose; then printf '%s\n' "+ $*"; fi
+ "$@"
+}
+
+base_dir="/home"
+
+extra_groups=()
+create_homedir=false
+gecos=
+group=Users
+home_dir=
+
+show_defaults () {
+ printf 'base_dir\t%s\n' "$base_dir"
+ printf 'comment\t\t%s\n' "$gecos"
+ printf 'group\t\t%s\n' "$group"
+ exit 0
+}
+
+while getopts 'DG:L:b:c:d:e:f:g:k:mp:or:s:u:v' f; do
+ case $f in
+ D) show_defaults;;
+ G) extra_groups[${#extra_groups}]="$OPTARG";;
+ L) echo "$0: login classes not supported; ignoring" >&2;;
+ b) base_dir="$OPTARG";;
+ c) gecos="$OPTARG";;
+ d) home_dir="$OPTARG";;
+ e) echo "$0: expiry time not yet supported; ignoring" >&2;;
+ f) echo "$0: inactive time not yet supported; ignoring" >&2;;
+ g) group="$OPTARG";;
+ k) echo "$0: skeleton files not yet supported; ignoring" >&22;;
+ m) create_homedir=true;;
+ p) echo "$0: cannot set password from command line; aborting" >&2; exit 1;;
+ o) echo "$0: cannot reuse numeric uid of another user; aborting" >&2; exit 1;;
+ r) echo "$0: numeric ID range cannot be set manually; ignoring" >&2;;
+ s) echo "$0: setting login shell not yet supported; ignoring" >&2;;
+ u) echo "$0: numeric uid cannot be set manually; ignoring" >&2;;
+ v) verbose=true;;
+ \?) show_usage;;
+ esac
+done
+shift $(($OPTIND - 1))
+
+if [ $# -ne 1 ]; then show_usage; fi
+$verbose || exec >/dev/null
+
+### check for existence of desired groups
+
+if [ "$group" != "=uid" ]; then
+ if ! net localgroup "${group#+}" >/dev/null 2>&1; then
+ echo "$0: group '$group' does not exist" >&2; exit 1
+ fi
+fi
+
+for g in "${extra_groups[@]}"; do
+ if ! net localgroup "${g#+}" >/dev/null 2>&1; then
+ echo "$0: group '$g' does not exist" >&2; exit 1
+ fi
+done
+
+### check for ability to create homedir
+
+if $create_homedir && [ "$home_dir" = "" ]; then
+ if [ ! -d "$base_dir" ]; then
+ echo "$0: base dir '$base_dir' does not exist" >&2; exit 1
+ fi
+
+ home_dir="$base_dir/$1"
+fi
+
+if $create_homedir && [ -d "$home_dir" ]; then
+ echo "$0: home dir '$home_dir' already exists; not clobbering" >&2
+ create_homedir=false
+fi
+
+### add the user
+
+run_cmd net user $1 /add /fullname:"$gecos" /comment:"User added by Cygwin useradd command" || exit 1
+
+### regenerate cygwin /etc/passwd
+(/bin/flock -x -n 9 || exit 1; /bin/mkpasswd -l -u "$1" >&9 ) 9>> /etc/passwd
+
+### put user in groups
+
+if [ "${group}" != "Users" ]; then
+ # "Users" added by default; remove and add the real one here:
+ run_cmd net localgroup "Users" $1 /delete || exit 1
+
+ # Under Windows, a user *is* a group. Do nothing if =uid is given.
+ if [ "$group" != "=uid" ]; then
+ run_cmd net localgroup "${group}" $1 /add || exit 1
+ fi
+fi
+
+for g in "${extra_groups[@]}"; do
+ # Don't add a "primary" group as a "secondary" group too.
+ if [ "${g}" != "${group}" ]; then
+ run_cmd net localgroup "${g}" $1 /add || exit 1
+ fi
+done
+
+### set, and optionally create and cacls the homedir
+
+if [ "$home_dir" != "" ]; then
+ home_dir_nt="$(/bin/cygpath -m "$home_dir")"
+
+ if $create_homedir; then
+ run_cmd /bin/mkdir -p "$home_dir" || exit 1
+ run_cmd /bin/chown "$1" "$home_dir" || exit 1
+
+ run_cmd /bin/setfacl -r -m d:u:"$1":rwx,u:SYSTEM:rwx,u:Administrators:rwx "$home_dir" || exit 1
+ fi
+
+ run_cmd net user "$1" /homedir:"$home_dir_nt" || exit 1
+fi
+
diff --git a/sysutils/user_cygwin/files/userdel.sh b/sysutils/user_cygwin/files/userdel.sh
new file mode 100755
index 00000000000..444b6ae9a4c
--- /dev/null
+++ b/sysutils/user_cygwin/files/userdel.sh
@@ -0,0 +1,47 @@
+#!/bin/bash
+# $NetBSD: userdel.sh,v 1.1 2013/03/06 12:37:16 obache Exp $
+
+export PATH=/bin:$PATH
+
+show_usage () {
+ echo "usage: $0 [-rv] user" >&2
+ exit 1
+}
+
+verbose=false
+run_cmd () {
+ if $verbose; then printf '%s\n' "+ $*"; fi
+ "$@"
+}
+
+remove_home_dir=false
+
+while getopts 'prv' f; do
+ case $f in
+ p) echo "$0: cannot yet lock out user with -p; aborting" >&2; exit 1;;
+ r) remove_home_dir=true;;
+ v) verbose=true;;
+ \?) show_usage;;
+ esac
+done
+shift $(($OPTIND - 1))
+
+if [ $# -ne 1 ]; then show_usage; fi
+$verbose || exec >/dev/null
+
+if ! net user $1 >/dev/null 2>&1; then
+ echo "$0: user $1 does not exist" >&2; exit 1
+fi
+
+if $remove_home_dir; then
+ home_dir="$(eval "echo ~$1")"
+
+ case "$home_dir" in
+ /) echo "$0: user $1 has no home directory; ignoring remove request" >&2;;
+ /*/*) rm -rf "$home_dir";;
+ *) echo "$0: could not delete home directory '$home_dir'; aborting" >&2; exit 1;;
+ esac
+fi
+
+run_cmd net user $1 /delete
+/bin/sed -i -e "/^$1.*/d" /etc/passwd