1 # Author: Jan Vcelak <jvcelak@redhat.com>
10 function default_config()
13 SLAPD_CONFIG_FILE=/etc/openldap/slapd.conf
14 SLAPD_CONFIG_DIR=/etc/openldap/slapd.d
17 SLAPD_SYSCONFIG_FILE=/etc/sysconfig/slapd
20 function parse_config_options()
25 while getopts :u:f:F: opt; do
41 if [ -n "$user" ]; then
45 if [ -n "$config_dir" ]; then
46 SLAPD_CONFIG_DIR="$config_dir"
49 SLAPD_GLOBAL_OPTIONS="-F '$config_dir'"
50 elif [ -n "$config_file" ]; then
52 SLAPD_CONFIG_FILE="$config_file"
54 SLAPD_GLOBAL_OPTIONS="-f '$config_file'"
58 function uses_new_config()
60 [ -n "$SLAPD_CONFIG_DIR" ]
64 function run_as_ldap()
66 /sbin/runuser --shell /bin/sh --session-command "$1" "$SLAPD_USER"
70 function ldif_unbreak()
72 sed ':a;N;s/\n //;ta;P;D'
80 function databases_new()
82 slapcat $SLAPD_GLOBAL_OPTIONS -c \
83 -H 'ldap:///cn=config???(|(objectClass=olcBdbConfig)(objectClass=olcHdbConfig))' 2>/dev/null | \
85 grep '^olcDbDirectory: ' | \
89 function databases_old()
91 awk 'begin { database="" }
92 $1 == "database" { database=$2 }
93 $1 == "directory" { if (database == "bdb" || database == "hdb") print $2}' \
97 function certificates_new()
99 slapcat $SLAPD_GLOBAL_OPTIONS -c -H 'ldap:///cn=config???(cn=config)' 2>/dev/null | \
101 grep '^olcTLS\(CACertificateFile\|CACertificatePath\|CertificateFile\|CertificateKeyFile\): ' | \
105 function certificates_old()
107 awk '$1 ~ "^TLS(CACertificate(File|Path)|CertificateFile|CertificateKeyFile)$" { print $2 } ' \
111 function certificates()
113 uses_new_config && certificates_new || certificates_old
118 uses_new_config && databases_new || databases_old
125 printf "$format" $@ >&2
128 function load_sysconfig()
130 [ -r "$SLAPD_SYSCONFIG_FILE" ] || return
132 . "$SLAPD_SYSCONFIG_FILE"
133 [ -n "$SLAPD_OPTIONS" ] && parse_config_options $SLAPD_OPTIONS