Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env bash
- set -euo pipefail
- USERNAME="omgUser2"
- USERPASS="omgPass123%"
- OUNAME="OU=OmgOU1"
- if [[ -d ./mnt/${OUNAME} ]]; then
- echo -n "delete ${OUNAME}..."
- rm -rf ./mnt/${OUNAME}
- echo "[OK]"
- fi
- echo -n "create new org unit..."
- mkdir ./mnt/${OUNAME}
- cat <<EOD > ./mnt/${OUNAME}/.attributes
- dn: ${OUNAME},DC=domain,DC=alt
- objectCategory: CN=Organizational-Unit,CN=Schema,CN=Configuration,DC=domain,DC=alt
- objectClass: organizationalUnit
- objectClass: top
- EOD
- echo "[OK]"
- USER_PATH="./mnt/CN=Users/CN=${USERNAME}"
- USER_PATH_IN_OU="./mnt/${OUNAME}/CN=${USERNAME}"
- if [[ -d ${USER_PATH} ]]; then
- echo -n "delete ${USERNAME}..."
- rm -rf "${USER_PATH}"
- echo "[OK]"
- fi
- if [[ -d ${USER_PATH_IN_OU} ]]; then
- echo -n "delete ${USERNAME}..."
- rm -rf "${USER_PATH}"
- echo "[OK]"
- fi
- echo -n "create user ${USERNAME}..."
- mkdir "${USER_PATH}"
- cat <<EOD > ${USER_PATH}/.attributes
- dn: CN=${USERNAME},CN=Users,DC=domain,DC=alt
- accountExpires: 9223372036854775807
- codePage: 0
- countryCode: 0
- lastLogoff: 0
- lastLogon: 0
- logonCount: 0
- memberOf: CN=Domain Admins,CN=Users,DC=domain,DC=alt
- objectCategory: CN=Person,CN=Schema,CN=Configuration,DC=domain,DC=alt
- objectClass: organizationalPerson
- objectClass: person
- objectClass: top
- objectClass: user
- sAMAccountName: ${USERNAME}
- userAccountControl: 512
- userPrincipalName: ${USERNAME}@domain.alt
- EOD
- echo "[OK]"
- echo -n "set user password..."
- ls -la ${USER_PATH} >/dev/null 2>&1
- echo -n "${USERPASS}" > ${USER_PATH}/.chpwd
- echo "[OK]"
- echo -n "move ${USERNAME} to ${OUNAME}"
- mv "${USER_PATH}" "${USER_PATH_IN_OU}"
- echo "[OK]"
- sleep 1
- echo "getting attributes of the new user..."
- find ./mnt/${OUNAME}
- echo "try to authenticate as a $USERNAME with $USERPASS as password..."
- echo "${USERPASS}" | kinit "${USERNAME}"
- echo "DONE!"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement