blob: 80992a7a09d654e843ae1995be4dd972a224b41c [file] [log] [blame]
Brad Topolf127e2f2013-01-22 10:17:50 -06001# lib/ldap
2# Functions to control the installation and configuration of **ldap**
3
Dean Troyercc6b4432013-04-08 15:38:03 -05004# ``lib/keystone`` calls the entry points in this order:
Adam Spiers6a5aa7c2013-10-24 11:27:02 +01005#
6# - install_ldap()
Brad Topolf127e2f2013-01-22 10:17:50 -06007
8# Save trace setting
9XTRACE=$(set +o | grep xtrace)
10set +o xtrace
11
Ralf Haferkamp704106a2013-09-12 14:24:47 +020012LDAP_SERVICE_NAME=slapd
Dean Troyercc6b4432013-04-08 15:38:03 -050013
14# Functions
15# ---------
16
Brad Topolf127e2f2013-01-22 10:17:50 -060017# install_ldap
18# install_ldap() - Collect source and prepare
19function 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 Topolf127e2f2013-01-22 10:17:50 -060025 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 Haferkamp704106a2013-09-12 14:24:47 +020029 elif is_fedora; then
Brad Topolf127e2f2013-01-22 10:17:50 -060030 LDAP_OLCDB_NUMBER=2
31 LDAP_ROOTPW_COMMAND=add
32 start_ldap
Ralf Haferkamp704106a2013-09-12 14:24:47 +020033 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 Topolf127e2f2013-01-22 10:17:50 -060042 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 Topol0c2c3fc2013-03-19 03:01:30 -050055 # On fedora we need to manually add cosine and inetorgperson schemas
Ralf Haferkamp704106a2013-09-12 14:24:47 +020056 if is_fedora || is_suse; then
Brad Topol0c2c3fc2013-03-19 03:01:30 -050057 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 Topolf127e2f2013-01-22 10:17:50 -060061 # add our top level ldap nodes
Dean Troyercc6b4432013-04-08 15:38:03 -050062 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 Topolf127e2f2013-01-22 10:17:50 -060063 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
77function start_ldap() {
Ralf Haferkamp704106a2013-09-12 14:24:47 +020078 sudo service $LDAP_SERVICE_NAME restart
Brad Topolf127e2f2013-01-22 10:17:50 -060079}
80
81
82# stop_ldap() - Stop LDAP
83function stop_ldap() {
Ralf Haferkamp704106a2013-09-12 14:24:47 +020084 sudo service $LDAP_SERVICE_NAME stop
Brad Topolf127e2f2013-01-22 10:17:50 -060085}
86
87# clear_ldap_state() - Clear LDAP State
88function 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 Dague584d90e2013-03-29 14:34:53 -040094
Adam Spiers6a5aa7c2013-10-24 11:27:02 +010095# Tell emacs to use shell-script-mode
96## Local variables:
97## mode: shell-script
98## End: