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