person2posix 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. #!/bin/bash
  2. . /etc/ldap-utils.conf
  3. . /usr/local/lib/ldap-utils/funcs
  4. uid=$1
  5. if user_exists $uid; then
  6. true
  7. else
  8. echo "User $uid does not exist."
  9. exit 1
  10. fi
  11. if user_is_posix $uid; then
  12. echo "User $uid is already a posixAccount"
  13. exit 1
  14. fi
  15. user="dn: uid=%UID%,$PEOPLEDN
  16. changeType: modify
  17. add: objectClass
  18. objectClass: posixAccount
  19. -
  20. add: uidNumber
  21. uidNumber: %NUMBER%
  22. -
  23. add: gidNumber
  24. gidNumber: %NUMBER%
  25. -
  26. add: homeDirectory
  27. homeDirectory: /home/%UID%
  28. -
  29. add: loginShell
  30. loginShell: /bin/bash
  31. -
  32. add: objectClass
  33. objectClass: shadowAccount
  34. -
  35. add: objectClass
  36. objectClass: ldapPublicKey"
  37. group="dn: cn=%UID%,$GROUPSDN
  38. objectClass: top
  39. objectClass: posixGroup
  40. cn: %UID%
  41. gidNumber: %NUMBER%
  42. memberUid: %UID%"
  43. uidnumber=$(get_posix_number)
  44. # add the necessary attribbute for a posixAccount
  45. echo "$user" | sed \
  46. -e "s/%NUMBER%/$uidnumber/" \
  47. -e "s/%UID%/$uid/" | ldapmodify $LDAPOPTS
  48. # create a posix group with the same name and uid as the user
  49. # and add them to it
  50. echo "$group" | sed \
  51. -e "s/%NUMBER%/$uidnumber/" \
  52. -e "s/%UID%/$uid/" | ldapadd $LDAPOPTS