2 # By Spransy, Derek" <DSPRANS () emory ! edu> and Charlie Scott
4 # alterations by bil hays 2013
6 # -Added some sanity checks
7 # -Added routine to find the first 3 contiguous UIDs above 100,
8 # starting at 600 puts this in user space
9 # -Added lines to append the ossec users to the group ossec
10 # so the the list GroupMembership works properly
13 # This checks for an error and exits with a custom message
14 # Returns zero on success
16 # $2 is the error code
18 if [[ ! -f "/usr/bin/dscl" ]]
20 echo "Error, I have no dscl, dying here";
35 # get unique id numbers (uid, gid) that are greater than 100
36 unset -v i new_uid new_gid idvar;
37 declare -i new_uid=0 new_gid=0 i=100 idvar=0;
38 while [[ $idvar -eq 0 ]]; do
42 if [[ -z "$(/usr/bin/dscl . -search /Users uid ${i})" ]] && [[ -z "$(/usr/bin/dscl . -search /Groups gid ${i})" ]] && \
43 [[ -z "$(/usr/bin/dscl . -search /Users uid ${j})" ]] && [[ -z "$(/usr/bin/dscl . -search /Groups gid ${j})" ]] && \
44 [[ -z "$(/usr/bin/dscl . -search /Users uid ${k})" ]] && [[ -z "$(/usr/bin/dscl . -search /Groups gid ${k})" ]];
53 echo "UIDs available are:";
58 # Verify that the uid and gid exist and match
59 if [[ $new_uid -eq 0 ]] || [[ $new_gid -eq 0 ]];
61 echo "Getting unique id numbers (uid, gid) failed!";
64 if [[ ${new_uid} != ${new_gid} ]]
66 echo "I failed to find matching free uid and gid!";
71 # Creating the groups.
72 sudo ${DSCL} localhost -create /Local/Default/Groups/ossec
73 check_errm "Error creating group ossec" "67"
74 sudo ${DSCL} localhost -createprop /Local/Default/Groups/ossec PrimaryGroupID ${new_gid}
75 sudo ${DSCL} localhost -createprop /Local/Default/Groups/ossec RealName ossec
76 sudo ${DSCL} localhost -createprop /Local/Default/Groups/ossec RecordName ossec
77 sudo ${DSCL} localhost -createprop /Local/Default/Groups/ossec RecordType: dsRecTypeStandard:Groups
78 sudo ${DSCL} localhost -createprop /Local/Default/Groups/ossec Password "*"
83 if [[ $(dscl . -read /Users/ossecm) ]]
85 echo "ossecm already exists";
87 sudo ${DSCL} localhost -create /Local/Default/Users/ossecm
88 check_errm "Error creating user ossecm" "87"
89 sudo ${DSCL} localhost -createprop /Local/Default/Users/ossecm RecordName ossecm
90 sudo ${DSCL} localhost -createprop /Local/Default/Users/ossecm RealName "ossecmacct"
91 sudo ${DSCL} localhost -createprop /Local/Default/Users/ossecm NFSHomeDirectory /var/ossec
92 sudo ${DSCL} localhost -createprop /Local/Default/Users/ossecm UniqueID ${j}
93 sudo ${DSCL} localhost -createprop /Local/Default/Users/ossecm PrimaryGroupID ${new_gid}
94 sudo ${DSCL} localhost -append /Local/Default/Groups/ossec GroupMembership ossecm
95 sudo ${DSCL} localhost -createprop /Local/Default/Users/ossecm Password "*"
98 if [[ $(dscl . -read /Users/ossecr) ]]
100 echo "ossecr already exists";
102 sudo ${DSCL} localhost -create /Local/Default/Users/ossecr
103 check_errm "Error creating user ossecr" "97"
104 sudo ${DSCL} localhost -createprop /Local/Default/Users/ossecr RecordName ossecr
105 sudo ${DSCL} localhost -createprop /Local/Default/Users/ossecr RealName "ossecracct"
106 sudo ${DSCL} localhost -createprop /Local/Default/Users/ossecr NFSHomeDirectory /var/ossec
107 sudo ${DSCL} localhost -createprop /Local/Default/Users/ossecr UniqueID ${k}
108 sudo ${DSCL} localhost -createprop /Local/Default/Users/ossecr PrimaryGroupID ${new_gid}
109 sudo ${DSCL} localhost -append /Local/Default/Groups/ossec GroupMembership ossecr
110 sudo ${DSCL} localhost -createprop /Local/Default/Users/ossecr Password "*"
113 if [[ $(dscl . -read /Users/ossec) ]]
115 echo "ossec already exists";
117 sudo ${DSCL} localhost -create /Local/Default/Users/ossec
118 check_errm "Error creating user ossec" "77"
119 sudo ${DSCL} localhost -createprop /Local/Default/Users/ossec RecordName ossec
120 sudo ${DSCL} localhost -createprop /Local/Default/Users/ossec RealName "ossecacct"
121 sudo ${DSCL} localhost -createprop /Local/Default/Users/ossec NFSHomeDirectory /var/ossec
122 sudo ${DSCL} localhost -createprop /Local/Default/Users/ossec UniqueID ${new_uid}
123 sudo ${DSCL} localhost -createprop /Local/Default/Users/ossec PrimaryGroupID ${new_gid}
124 sudo ${DSCL} localhost -append /Local/Default/Groups/ossec GroupMembership ossec
125 sudo ${DSCL} localhost -createprop /Local/Default/Users/ossec Password "*"