Brad Topol | f127e2f | 2013-01-22 10:17:50 -0600 | [diff] [blame] | 1 | # lib/ldap |
| 2 | # Functions to control the installation and configuration of **ldap** |
| 3 | |
Dean Troyer | cc6b443 | 2013-04-08 15:38:03 -0500 | [diff] [blame] | 4 | # ``lib/keystone`` calls the entry points in this order: |
Adam Spiers | 6a5aa7c | 2013-10-24 11:27:02 +0100 | [diff] [blame] | 5 | # |
| 6 | # - install_ldap() |
Brad Topol | f127e2f | 2013-01-22 10:17:50 -0600 | [diff] [blame] | 7 | |
| 8 | # Save trace setting |
| 9 | XTRACE=$(set +o | grep xtrace) |
| 10 | set +o xtrace |
| 11 | |
Ralf Haferkamp | 704106a | 2013-09-12 14:24:47 +0200 | [diff] [blame] | 12 | LDAP_SERVICE_NAME=slapd |
Dean Troyer | cc6b443 | 2013-04-08 15:38:03 -0500 | [diff] [blame] | 13 | |
| 14 | # Functions |
| 15 | # --------- |
| 16 | |
Brad Topol | f127e2f | 2013-01-22 10:17:50 -0600 | [diff] [blame] | 17 | # install_ldap |
| 18 | # install_ldap() - Collect source and prepare |
| 19 | function install_ldap() { |
| 20 | echo "Installing LDAP inside function" |
| 21 | echo "LDAP_PASSWORD is $LDAP_PASSWORD" |
| 22 | echo "os_VENDOR is $os_VENDOR" |
| 23 | printf "installing" |
| 24 | if is_ubuntu; then |
Brad Topol | f127e2f | 2013-01-22 10:17:50 -0600 | [diff] [blame] | 25 | LDAP_OLCDB_NUMBER=1 |
| 26 | LDAP_ROOTPW_COMMAND=replace |
| 27 | sudo DEBIAN_FRONTEND=noninteractive apt-get install slapd ldap-utils |
| 28 | #automatically starts LDAP on ubuntu so no need to call start_ldap |
Ralf Haferkamp | 704106a | 2013-09-12 14:24:47 +0200 | [diff] [blame] | 29 | elif is_fedora; then |
Brad Topol | f127e2f | 2013-01-22 10:17:50 -0600 | [diff] [blame] | 30 | LDAP_OLCDB_NUMBER=2 |
| 31 | LDAP_ROOTPW_COMMAND=add |
| 32 | start_ldap |
Ralf Haferkamp | 704106a | 2013-09-12 14:24:47 +0200 | [diff] [blame] | 33 | elif is_suse; then |
| 34 | LDAP_OLCDB_NUMBER=1 |
| 35 | LDAP_ROOTPW_COMMAND=add |
| 36 | LDAP_SERVICE_NAME=ldap |
| 37 | # SUSE has slappasswd in /usr/sbin/ |
| 38 | PATH=$PATH:/usr/sbin/ |
| 39 | sudo slapadd -F /etc/openldap/slapd.d/ -bcn=config -l $FILES/ldap/base-config.ldif |
| 40 | sudo sed -i '/^OPENLDAP_START_LDAPI=/s/"no"/"yes"/g' /etc/sysconfig/openldap |
| 41 | start_ldap |
Brad Topol | f127e2f | 2013-01-22 10:17:50 -0600 | [diff] [blame] | 42 | fi |
| 43 | |
| 44 | printf "generate password file" |
| 45 | SLAPPASS=`slappasswd -s $LDAP_PASSWORD` |
| 46 | |
| 47 | printf "secret is $SLAPPASS\n" |
| 48 | #create manager.ldif |
| 49 | TMP_MGR_DIFF_FILE=`mktemp -t manager_ldiff.$$.XXXXXXXXXX.ldif` |
| 50 | sed -e "s|\${LDAP_OLCDB_NUMBER}|$LDAP_OLCDB_NUMBER|" -e "s|\${SLAPPASS}|$SLAPPASS|" -e "s|\${LDAP_ROOTPW_COMMAND}|$LDAP_ROOTPW_COMMAND|" $FILES/ldap/manager.ldif.in >> $TMP_MGR_DIFF_FILE |
| 51 | |
| 52 | #update ldap olcdb |
| 53 | sudo ldapmodify -Y EXTERNAL -H ldapi:/// -f $TMP_MGR_DIFF_FILE |
| 54 | |
Brad Topol | 0c2c3fc | 2013-03-19 03:01:30 -0500 | [diff] [blame] | 55 | # On fedora we need to manually add cosine and inetorgperson schemas |
Ralf Haferkamp | 704106a | 2013-09-12 14:24:47 +0200 | [diff] [blame] | 56 | if is_fedora || is_suse; then |
Brad Topol | 0c2c3fc | 2013-03-19 03:01:30 -0500 | [diff] [blame] | 57 | sudo ldapadd -Y EXTERNAL -H ldapi:/// -f /etc/openldap/schema/cosine.ldif |
| 58 | sudo ldapadd -Y EXTERNAL -H ldapi:/// -f /etc/openldap/schema/inetorgperson.ldif |
| 59 | fi |
| 60 | |
Brad Topol | f127e2f | 2013-01-22 10:17:50 -0600 | [diff] [blame] | 61 | # add our top level ldap nodes |
Dean Troyer | cc6b443 | 2013-04-08 15:38:03 -0500 | [diff] [blame] | 62 | if ldapsearch -x -w $LDAP_PASSWORD -H ldap://localhost -D dc=Manager,dc=openstack,dc=org -x -b dc=openstack,dc=org | grep -q "Success"; then |
Brad Topol | f127e2f | 2013-01-22 10:17:50 -0600 | [diff] [blame] | 63 | printf "LDAP already configured for OpenStack\n" |
| 64 | if [[ "$KEYSTONE_CLEAR_LDAP" == "yes" ]]; then |
| 65 | # clear LDAP state |
| 66 | clear_ldap_state |
| 67 | # reconfigure LDAP for OpenStack |
| 68 | ldapadd -c -x -H ldap://localhost -D dc=Manager,dc=openstack,dc=org -w $LDAP_PASSWORD -f $FILES/ldap/openstack.ldif |
| 69 | fi |
| 70 | else |
| 71 | printf "Configuring LDAP for OpenStack\n" |
| 72 | ldapadd -c -x -H ldap://localhost -D dc=Manager,dc=openstack,dc=org -w $LDAP_PASSWORD -f $FILES/ldap/openstack.ldif |
| 73 | fi |
| 74 | } |
| 75 | |
| 76 | # start_ldap() - Start LDAP |
| 77 | function start_ldap() { |
Ralf Haferkamp | 704106a | 2013-09-12 14:24:47 +0200 | [diff] [blame] | 78 | sudo service $LDAP_SERVICE_NAME restart |
Brad Topol | f127e2f | 2013-01-22 10:17:50 -0600 | [diff] [blame] | 79 | } |
| 80 | |
| 81 | |
| 82 | # stop_ldap() - Stop LDAP |
| 83 | function stop_ldap() { |
Ralf Haferkamp | 704106a | 2013-09-12 14:24:47 +0200 | [diff] [blame] | 84 | sudo service $LDAP_SERVICE_NAME stop |
Brad Topol | f127e2f | 2013-01-22 10:17:50 -0600 | [diff] [blame] | 85 | } |
| 86 | |
| 87 | # clear_ldap_state() - Clear LDAP State |
| 88 | function clear_ldap_state() { |
| 89 | ldapdelete -x -w $LDAP_PASSWORD -H ldap://localhost -D dc=Manager,dc=openstack,dc=org -x -r "dc=openstack,dc=org" |
| 90 | } |
| 91 | |
| 92 | # Restore xtrace |
| 93 | $XTRACE |
Sean Dague | 584d90e | 2013-03-29 14:34:53 -0400 | [diff] [blame] | 94 | |
Adam Spiers | 6a5aa7c | 2013-10-24 11:27:02 +0100 | [diff] [blame] | 95 | # Tell emacs to use shell-script-mode |
| 96 | ## Local variables: |
| 97 | ## mode: shell-script |
| 98 | ## End: |