mrc0mmand / rpms / openldap

Forked from rpms/openldap 3 years ago
Clone

Blame SOURCES/libexec-functions

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