summaryrefslogtreecommitdiff
path: root/source3
diff options
context:
space:
mode:
authorVolker Lendecke <vlendec@samba.org>2002-09-27 09:47:02 +0000
committerVolker Lendecke <vlendec@samba.org>2002-09-27 09:47:02 +0000
commitdc262e3f39ec41576a586332b01e183b5583d3a6 (patch)
tree79ee192c6966acd94fb0527269c27f9e03bee4d7 /source3
parente9878f0bbe0193f1d3ba9eeab5df5a866e40fcf3 (diff)
downloadsamba-dc262e3f39ec41576a586332b01e183b5583d3a6.tar.gz
samba-dc262e3f39ec41576a586332b01e183b5583d3a6.tar.bz2
samba-dc262e3f39ec41576a586332b01e183b5583d3a6.zip
An example of a group creation command that can handle failures
of groupadd. Volker (This used to be commit 3f78923a6feefffae6203d27a765b2a8cf3c5c24)
Diffstat (limited to 'source3')
-rwxr-xr-xsource3/script/creategroup27
1 files changed, 27 insertions, 0 deletions
diff --git a/source3/script/creategroup b/source3/script/creategroup
new file mode 100755
index 0000000000..01fb065944
--- /dev/null
+++ b/source3/script/creategroup
@@ -0,0 +1,27 @@
+#!/bin/sh
+
+# Example script for 'add group command'. Handle weird NT group
+# names. First attempt to create the group directly, if that fails
+# then create a random group and print the numeric group id.
+#
+# Note that this is only an example and assumes /dev/urandom.
+#
+# Volker
+
+GROUPNAME="$1"
+ITERS=0
+
+while ! /usr/sbin/groupadd "$GROUPNAME" > /dev/null 2>&1
+do
+ # we had difficulties creating that group. Maybe the name was
+ # too weird, or it already existed. Create a random name.
+ GROUPNAME=nt-$(dd if=/dev/urandom bs=16 count=1 2>/dev/null | md5sum | cut -b 1-5)
+ ITERS=$(expr "$ITERS" + 1)
+ if [ "$ITERS" -gt 10 ]
+ then
+ # Too many attempts
+ exit 1
+ fi
+done
+
+getent group | grep ^"$GROUPNAME": | cut -d : -f 3