diff options
author | Volker Lendecke <vlendec@samba.org> | 2002-09-27 09:47:02 +0000 |
---|---|---|
committer | Volker Lendecke <vlendec@samba.org> | 2002-09-27 09:47:02 +0000 |
commit | 3f78923a6feefffae6203d27a765b2a8cf3c5c24 (patch) | |
tree | 8935af47281c469f6867947abb81b0ad01666fed /source/script/creategroup | |
parent | 685387b0109e880e30191fbea0aad1e5c677273a (diff) | |
download | samba-3f78923a6feefffae6203d27a765b2a8cf3c5c24.tar.gz samba-3f78923a6feefffae6203d27a765b2a8cf3c5c24.tar.xz samba-3f78923a6feefffae6203d27a765b2a8cf3c5c24.zip |
An example of a group creation command that can handle failures
of groupadd.
Volker
Diffstat (limited to 'source/script/creategroup')
-rwxr-xr-x | source/script/creategroup | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/source/script/creategroup b/source/script/creategroup new file mode 100755 index 00000000000..01fb0659444 --- /dev/null +++ b/source/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 |