Blame SOURCES/libexec-functions

d0db73
# Author: Jan Vcelak <jvcelak@redhat.com>
d0db73
d0db73
SLAPD_USER=
d0db73
SLAPD_CONFIG_FILE=
d0db73
SLAPD_CONFIG_DIR=
d0db73
SLAPD_CONFIG_CUSTOM=
d0db73
SLAPD_GLOBAL_OPTIONS=
d0db73
SLAPD_SYSCONFIG_FILE=
d0db73
d0db73
function default_config()
d0db73
{
d0db73
	SLAPD_USER=ldap
d0db73
	SLAPD_CONFIG_FILE=/etc/openldap/slapd.conf
d0db73
	SLAPD_CONFIG_DIR=/etc/openldap/slapd.d
d0db73
	SLAPD_CONFIG_CUSTOM=
d0db73
	SLAPD_GLOBAL_OPTIONS=
d0db73
	SLAPD_SYSCONFIG_FILE=/etc/sysconfig/slapd
d0db73
}
d0db73
d0db73
function parse_config_options()
d0db73
{
d0db73
	user=
d0db73
	config_file=
d0db73
	config_dir=
d0db73
	while getopts :u:f:F: opt; do
d0db73
		case "$opt" in
d0db73
		u)
d0db73
			user="$OPTARG"
d0db73
			;;
d0db73
		f)
d0db73
			config_file="$OPTARG"
d0db73
			;;
d0db73
		F)
d0db73
			config_dir="$OPTARG"
d0db73
			;;
d0db73
		esac
d0db73
	done
d0db73
d0db73
	if [ -n "$user" ]; then
d0db73
		SLAPD_USER="$user"
d0db73
	fi
d0db73
d0db73
	if [ -n "$config_dir" ]; then
d0db73
		SLAPD_CONFIG_DIR="$config_dir"
d0db73
		SLAPD_CONFIG_FILE=
d0db73
		SLAPD_CONFIG_CUSTOM=1
d0db73
		SLAPD_GLOBAL_OPTIONS="-F '$config_dir'"
d0db73
	elif [ -n "$config_file" ]; then
d0db73
		SLAPD_CONFIG_DIR=
d0db73
		SLAPD_CONFIG_FILE="$config_file"
d0db73
		SLAPD_CONFIG_CUSTOM=1
d0db73
		SLAPD_GLOBAL_OPTIONS="-f '$config_file'"
d0db73
	fi
d0db73
}
d0db73
d0db73
function uses_new_config()
d0db73
{
d0db73
	[ -n "$SLAPD_CONFIG_DIR" ]
d0db73
	return $?
d0db73
}
d0db73
d0db73
function run_as_ldap()
d0db73
{
d0db73
	/sbin/runuser --shell /bin/sh --session-command "$1" "$SLAPD_USER"
d0db73
	return $?
d0db73
}
d0db73
d0db73
function ldif_unbreak()
d0db73
{
d0db73
	sed ':a;N;s/\n //;ta;P;D'
d0db73
}
d0db73
d0db73
function ldif_value()
d0db73
{
d0db73
	sed 's/^[^:]*: //'
d0db73
}
d0db73
d0db73
function databases_new()
d0db73
{
d0db73
	slapcat $SLAPD_GLOBAL_OPTIONS -c \
d0db73
	-H 'ldap:///cn=config???(|(objectClass=olcBdbConfig)(objectClass=olcHdbConfig))' 2>/dev/null | \
d0db73
		ldif_unbreak | \
d0db73
		grep '^olcDbDirectory: ' | \
d0db73
		ldif_value
d0db73
}
d0db73
d0db73
function certificates_new()
d0db73
{
d0db73
	slapcat $SLAPD_GLOBAL_OPTIONS -c -H 'ldap:///cn=config???(cn=config)' 2>/dev/null | \
d0db73
		ldif_unbreak | \
d0db73
		grep '^olcTLS\(CACertificateFile\|CACertificatePath\|CertificateFile\|CertificateKeyFile\): ' | \
d0db73
		ldif_value
d0db73
}
d0db73
d0db73
function certificates()
d0db73
{
b11fe1
	uses_new_config && certificates_new
d0db73
}
d0db73
d0db73
function databases()
d0db73
{
b11fe1
	uses_new_config && databases_new
d0db73
}
d0db73
d0db73
d0db73
function error()
d0db73
{
d0db73
	format="$1\n"; shift
d0db73
	printf "$format" $@ >&2
d0db73
}
d0db73
d0db73
function load_sysconfig()
d0db73
{
d0db73
	[ -r "$SLAPD_SYSCONFIG_FILE" ] || return
d0db73
d0db73
	. "$SLAPD_SYSCONFIG_FILE"
d0db73
	[ -n "$SLAPD_OPTIONS" ] && parse_config_options $SLAPD_OPTIONS
d0db73
}
d0db73
d0db73
default_config