Blame SOURCES/libexec-functions

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