BASH   60

add_user sh

Guest on 28th July 2022 01:59:23 AM

  1. #!/bin/bash
  2. set -o nounset
  3. set -o errexit
  4.  
  5. LDAP_ACCMAKER_PASSWORD_FILE=/afs/service/ldap/secret/ldap_accmaker_password
  6.  
  7. LDAP_URL=ldap://ldap1.$host
  8. LDAP_ADMIN_DN="cn=accmaker,ou=Administrators,ou=TopologyManagement,o=NetscapeRoot"
  9.  
  10. if [[ -z "$(klist | grep admin)" ]]; then
  11.     echo "You need admin kerb credentials"
  12.     exit 1
  13. fi
  14.  
  15. if [[ "$#" == "0" ]]; then
  16.     # automagically try to add the most recent user
  17.     PASSWD_LINE=$(tail -n 1 /afs/service/etc/passwd.user)
  18.     echo "Will try to add the following user to LDAP"
  19.     echo "$PASSWD_LINE"
  20.     echo "If this is incorrect, press Ctrl-c now."
  21.     echo "Then find the correct etc/passwd line for the user you wish"
  22.     echo "to add to LDAP and provide it as an argument to this script."
  23.     echo "It should be in /afs/service/etc/passwd.user maybe?"
  24.     echo "Otherwise, if this is correct, press enter."
  25.     read
  26. elif [[ $# -ne 1 ]]; then
  27.     echo "Provide a single /etc/passwd line as an argument."
  28.     echo "You'll need to quote it."
  29.     exit 1
  30. else
  31.     PASSWD_LINE=$1
  32. fi
  33.  
  34. # convert passwd format to LDIF format
  35. # we use our own version of migrate_passwd.pl because we've modified migrate_common.ph with cclub defaults
  36. TMP_LDIF=$(mktemp)
  37. cd $(dirname $(readlink -f $0))
  38. ./migrate_passwd.pl <(echo "$PASSWD_LINE") $TMP_LDIF
  39.  
  40. # load LDIF format file into LDAP
  41. ldapadd -x -y $LDAP_ACCMAKER_PASSWORD_FILE -D $LDAP_ADMIN_DN -c -f $TMP_LDIF -H $LDAP_URL
  42.  
  43. echo "Successfully added user to LDAP, probably"
  44.  
  45. ### I might use this later, it's a template similar to what's generated by migrate_passwd.pl
  46. ### template:
  47. # cat <<_HEREDOC_
  48. # dn: uid=$NEWUSER_USERNAME,ou=users,dc=club,dc=cc,dc=cmu,dc=edu
  49. # uid: $NEWUSER_USERNAME
  50. # cn: $NEWUSER_REALNAME
  51. # sn: $NEWUSER_SURNAME
  52. # objectClass: person
  53. # objectClass: organizationalPerson
  54. # objectClass: inetOrgPerson
  55. # objectClass: account
  56. # objectClass: posixAccount
  57. # objectClass: top
  58. # userPassword: {crypt}K
  59. # loginShell: $NEWUSER_SHELL
  60. # uidNumber: $NEWUSER_UID
  61. # gidNumber: $NEWUSER_GID
  62. # homeDirectory: /afs/usr/$NEWUSER_USERNAME
  63. # gecos: $NEWUSER_REALNAME
  64. # _HEREDOC_

Raw Paste


Login or Register to edit or fork this paste. It's free.