blob: 0a0d197df2b329a4ebf47fe7ff0f3d07bb890e94 [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
Brad Topolf127e2f2013-01-22 10:17:50 -060019 LDAP_OLCDB_NUMBER=1
20 LDAP_ROOTPW_COMMAND=replace
21 sudo DEBIAN_FRONTEND=noninteractive apt-get install slapd ldap-utils
22 #automatically starts LDAP on ubuntu so no need to call start_ldap
Vincent Untz3f34d9a2013-03-12 17:57:36 +010023 elif is_fedora || is_suse; then
Brad Topolf127e2f2013-01-22 10:17:50 -060024 LDAP_OLCDB_NUMBER=2
25 LDAP_ROOTPW_COMMAND=add
26 start_ldap
27 fi
28
29 printf "generate password file"
30 SLAPPASS=`slappasswd -s $LDAP_PASSWORD`
31
32 printf "secret is $SLAPPASS\n"
33 #create manager.ldif
34 TMP_MGR_DIFF_FILE=`mktemp -t manager_ldiff.$$.XXXXXXXXXX.ldif`
35 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
36
37 #update ldap olcdb
38 sudo ldapmodify -Y EXTERNAL -H ldapi:/// -f $TMP_MGR_DIFF_FILE
39
40 # add our top level ldap nodes
41 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
42 printf "LDAP already configured for OpenStack\n"
43 if [[ "$KEYSTONE_CLEAR_LDAP" == "yes" ]]; then
44 # clear LDAP state
45 clear_ldap_state
46 # reconfigure LDAP for OpenStack
47 ldapadd -c -x -H ldap://localhost -D dc=Manager,dc=openstack,dc=org -w $LDAP_PASSWORD -f $FILES/ldap/openstack.ldif
48 fi
49 else
50 printf "Configuring LDAP for OpenStack\n"
51 ldapadd -c -x -H ldap://localhost -D dc=Manager,dc=openstack,dc=org -w $LDAP_PASSWORD -f $FILES/ldap/openstack.ldif
52 fi
53}
54
55# start_ldap() - Start LDAP
56function start_ldap() {
57 sudo service slapd restart
58}
59
60
61# stop_ldap() - Stop LDAP
62function stop_ldap() {
63 sudo service slapd stop
64}
65
66# clear_ldap_state() - Clear LDAP State
67function clear_ldap_state() {
68 ldapdelete -x -w $LDAP_PASSWORD -H ldap://localhost -D dc=Manager,dc=openstack,dc=org -x -r "dc=openstack,dc=org"
69}
70
71# Restore xtrace
72$XTRACE