Advertisement
Guest User

Untitled

a guest
Mar 9th, 2019
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.74 KB | None | 0 0
  1. #!/usr/bin/env bash
  2.  
  3. set -euo pipefail
  4.  
  5. USERNAME="omgUser2"
  6. USERPASS="omgPass123%"
  7. OUNAME="OU=OmgOU1"
  8.  
  9. if [[ -d ./mnt/${OUNAME} ]]; then
  10. echo -n "delete ${OUNAME}..."
  11. rm -rf ./mnt/${OUNAME}
  12. echo "[OK]"
  13. fi
  14.  
  15. echo -n "create new org unit..."
  16. mkdir ./mnt/${OUNAME}
  17. cat <<EOD > ./mnt/${OUNAME}/.attributes
  18. dn: ${OUNAME},DC=domain,DC=alt
  19. objectCategory: CN=Organizational-Unit,CN=Schema,CN=Configuration,DC=domain,DC=alt
  20. objectClass: organizationalUnit
  21. objectClass: top
  22. EOD
  23.  
  24. echo "[OK]"
  25.  
  26. USER_PATH="./mnt/CN=Users/CN=${USERNAME}"
  27. USER_PATH_IN_OU="./mnt/${OUNAME}/CN=${USERNAME}"
  28. if [[ -d ${USER_PATH} ]]; then
  29. echo -n "delete ${USERNAME}..."
  30. rm -rf "${USER_PATH}"
  31. echo "[OK]"
  32. fi
  33.  
  34. if [[ -d ${USER_PATH_IN_OU} ]]; then
  35. echo -n "delete ${USERNAME}..."
  36. rm -rf "${USER_PATH}"
  37. echo "[OK]"
  38. fi
  39. echo -n "create user ${USERNAME}..."
  40. mkdir "${USER_PATH}"
  41. cat <<EOD > ${USER_PATH}/.attributes
  42. dn: CN=${USERNAME},CN=Users,DC=domain,DC=alt
  43. accountExpires: 9223372036854775807
  44. codePage: 0
  45. countryCode: 0
  46. lastLogoff: 0
  47. lastLogon: 0
  48. logonCount: 0
  49. memberOf: CN=Domain Admins,CN=Users,DC=domain,DC=alt
  50. objectCategory: CN=Person,CN=Schema,CN=Configuration,DC=domain,DC=alt
  51. objectClass: organizationalPerson
  52. objectClass: person
  53. objectClass: top
  54. objectClass: user
  55. sAMAccountName: ${USERNAME}
  56. userAccountControl: 512
  57. userPrincipalName: ${USERNAME}@domain.alt
  58. EOD
  59. echo "[OK]"
  60.  
  61. echo -n "set user password..."
  62. ls -la ${USER_PATH} >/dev/null 2>&1
  63. echo -n "${USERPASS}" > ${USER_PATH}/.chpwd
  64. echo "[OK]"
  65.  
  66. echo -n "move ${USERNAME} to ${OUNAME}"
  67. mv "${USER_PATH}" "${USER_PATH_IN_OU}"
  68. echo "[OK]"
  69.  
  70. sleep 1
  71.  
  72. echo "getting attributes of the new user..."
  73. find ./mnt/${OUNAME}
  74.  
  75. echo "try to authenticate as a $USERNAME with $USERPASS as password..."
  76. echo "${USERPASS}" | kinit "${USERNAME}"
  77.  
  78. echo "DONE!"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement