]> git.saurik.com Git - apple/xnu.git/blob - tools/tests/libMicro/od_account_create.sh
xnu-1699.22.73.tar.gz
[apple/xnu.git] / tools / tests / libMicro / od_account_create.sh
1 #!/bin/bash
2
3
4 function sighandler {
5 echo
6 echo "Interrupting account creation"
7 rm -f $TMPF
8 exit 1
9 }
10
11 trap sighandler INT TERM
12
13 # Fixed parameters
14 #
15 NAME=`basename $0`
16 COUNT=$1
17 NODE=$2
18 PREFIX="od_test_"
19 GROUP_ID=1211 # A group everybody's in
20 GROUP_ID2=1212 # A group nobody's in
21 GROUP_NAME='od_test_group'
22 UID_BASE=5000
23 TMPF=/tmp/.${NAME}.$$
24
25 usage () {
26 echo
27 echo "Usage: ${NAME} count nodename"
28 echo
29 echo " ie. ${NAME} 1000 /Local/Default"
30 echo
31 echo " will create users 1000 users (from '${PREFIX}1' to '${PREFIX}1000')"
32 echo " Default password is set to 'test'"
33 echo " User ID starts from 5000"
34 echo " Default group is '${GROUP_NAME}', Group ID 1211"
35 echo
36 echo "This tool assumes user 'diradmin' with password 'admin' for OD admin"
37 echo
38 exit 85 # WRONGARGS
39 }
40
41 if [ $# -ne 2 ]; then
42 usage
43 fi
44
45 # if local node we don't need credentials
46 if [ $NODE != "/Local/Default" ]; then
47 OD_ADMIN="diradmin"
48 OD_PASS="admin"
49 fi
50
51 echo "Creating users ${PREFIX}1 to ${PREFIX}$COUNT"
52
53 # check to see if od_test_group exist. if not, create one
54 #
55 result=`dscl $NODE -list Groups/${GROUP_NAME}1 2> /dev/null`
56 if [ $? -ne 0 ]; then
57 echo "Group \"${GROUP_NAME}\" does not exist. Creating ${GROUP_NAME}"
58 if [ -n "$OD_ADMIN" ]; then
59 dseditgroup -q -o create -n $NODE -u $OD_ADMIN -P $OD_PASS -i ${GROUP_ID} ${GROUP_NAME}1
60 dseditgroup -q -o create -n $NODE -u $OD_ADMIN -P $OD_PASS -i ${GROUP_ID2} ${GROUP_NAME}2
61 else
62 dseditgroup -q -o create -n $NODE -i ${GROUP_ID} ${GROUP_NAME}1
63 dseditgroup -q -o create -n $NODE -i ${GROUP_ID2} ${GROUP_NAME}2
64 fi
65 fi
66
67 if [ $? -ne 0 ]; then
68 echo "Failed to create test_group"
69 exit 1
70 fi
71
72 # using dsimport is faster than using dscl
73 i=1
74 uid=$UID_BASE
75 echo "Writing a temporary import file ..."
76 while [ $i -le $COUNT ]
77 do
78 result=`dscl $NODE -list Users/${PREFIX}${i} 2> /dev/null`
79 if [ $? -ne 0 ]; then
80 # Uses standard template
81 # RecordName:Password:UniqueID:PrimaryGroupID:DistinguishedName:NFSHomeDirectory:UserShell
82 echo "${PREFIX}${i}:test:${uid}:1211:${PREFIX}${i}:/Users/${PREFIX}${i}:/bin/bash" >> $TMPF
83 printf "\r${PREFIX}${i} / ${COUNT}"
84 else
85 echo "account $PREFIX$i already exist. skipping"
86 fi
87 i=`expr $i + 1`
88 uid=`expr $uid + 1`
89 done
90 echo
91
92 # Now do the real work
93 #
94 if [[ -f $TMPF ]]; then
95 echo "Running dsimport to create users. Please be patient. This takes a while ..."
96 # assume if admin is provided that slapconfig exists
97 if [ -n "$OD_ADMIN" ]; then
98 if [[ -x "/usr/sbin/slapconfig" ]]; then
99 /usr/sbin/slapconfig -setfullsyncmode no
100 sleep 2
101 fi
102 /usr/bin/time dsimport $TMPF $NODE I --username $OD_ADMIN --password $OD_PASS --template StandardUser
103 sleep 2
104 if [[ -x "/usr/sbin/slapconfig" ]]; then
105 /usr/sbin/slapconfig -setfullsyncmode yes
106 fi
107 else
108 /usr/bin/time dsimport $TMPF $NODE I --template StandardUser
109 sleep 2
110 fi
111
112 # and now delete the temp file
113 #
114 rm -f $TMPF
115 else
116 echo "Nothing done. All users already exist"
117 fi
118
119 echo Create a SACL group for libMicro
120 # Create a sample SACL group
121 dseditgroup -q -o create -r "libMicro ACL" com.apple.access_libMicro
122 i=1
123 while [ $i -le $COUNT ]; do
124 dseditgroup -q -o edit -a ${PREFIX}${i} -t user com.apple.access_libMicro
125 i=`expr $i + 1`
126 done
127
128 echo 'Finished'
129