blob: 5cb4534765dcafb94eeef5b4887d6ea986265db7 [file] [log] [blame]
Brad Topolf127e2f2013-01-22 10:17:50 -06001# lib/ldap
2# Functions to control the installation and configuration of **ldap**
3
4# ``stack.sh`` calls the entry points in this order:
5#
6
7# Save trace setting
8XTRACE=$(set +o | grep xtrace)
9set +o xtrace
10
11# install_ldap
12# install_ldap() - Collect source and prepare
13function install_ldap() {
14 echo "Installing LDAP inside function"
15 echo "LDAP_PASSWORD is $LDAP_PASSWORD"
16 echo "os_VENDOR is $os_VENDOR"
17 printf "installing"
18 if is_ubuntu; then
19 echo "os vendor is Ubuntu"
20 LDAP_OLCDB_NUMBER=1
21 LDAP_ROOTPW_COMMAND=replace
22 sudo DEBIAN_FRONTEND=noninteractive apt-get install slapd ldap-utils
23 #automatically starts LDAP on ubuntu so no need to call start_ldap
24 elif is_fedora; then
25 echo "os vendor is Fedora"
26 LDAP_OLCDB_NUMBER=2
27 LDAP_ROOTPW_COMMAND=add
28 start_ldap
29 fi
30
31 printf "generate password file"
32 SLAPPASS=`slappasswd -s $LDAP_PASSWORD`
33
34 printf "secret is $SLAPPASS\n"
35 #create manager.ldif
36 TMP_MGR_DIFF_FILE=`mktemp -t manager_ldiff.$$.XXXXXXXXXX.ldif`
37 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
38
39 #update ldap olcdb
40 sudo ldapmodify -Y EXTERNAL -H ldapi:/// -f $TMP_MGR_DIFF_FILE
41
42 # add our top level ldap nodes
43 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
44 printf "LDAP already configured for OpenStack\n"
45 if [[ "$KEYSTONE_CLEAR_LDAP" == "yes" ]]; then
46 # clear LDAP state
47 clear_ldap_state
48 # reconfigure LDAP for OpenStack
49 ldapadd -c -x -H ldap://localhost -D dc=Manager,dc=openstack,dc=org -w $LDAP_PASSWORD -f $FILES/ldap/openstack.ldif
50 fi
51 else
52 printf "Configuring LDAP for OpenStack\n"
53 ldapadd -c -x -H ldap://localhost -D dc=Manager,dc=openstack,dc=org -w $LDAP_PASSWORD -f $FILES/ldap/openstack.ldif
54 fi
55}
56
57# start_ldap() - Start LDAP
58function start_ldap() {
59 sudo service slapd restart
60}
61
62
63# stop_ldap() - Stop LDAP
64function stop_ldap() {
65 sudo service slapd stop
66}
67
68# clear_ldap_state() - Clear LDAP State
69function clear_ldap_state() {
70 ldapdelete -x -w $LDAP_PASSWORD -H ldap://localhost -D dc=Manager,dc=openstack,dc=org -x -r "dc=openstack,dc=org"
71}
72
73# Restore xtrace
74$XTRACE