Blame SOURCES/libexec-check-config.sh

adf540
#!/bin/sh
adf540
# Author: Jan Vcelak <jvcelak@redhat.com>
adf540
adf540
. /usr/libexec/openldap/functions
adf540
adf540
function check_config_syntax()
adf540
{
adf540
	retcode=0
adf540
	tmp_slaptest=`mktemp --tmpdir=/var/run/openldap`
adf540
	run_as_ldap "/usr/sbin/slaptest $SLAPD_GLOBAL_OPTIONS -u" &>$tmp_slaptest
adf540
	if [ $? -ne 0 ]; then
adf540
		error "Checking configuration file failed:"
adf540
		cat $tmp_slaptest >&2
adf540
		retcode=1
adf540
	fi
adf540
	rm $tmp_slaptest
adf540
	return $retcode
adf540
}
adf540
adf540
function check_certs_perms()
adf540
{
adf540
	retcode=0
adf540
	for cert in `certificates`; do
adf540
		run_as_ldap "/usr/bin/test -e \"$cert\""
adf540
		if [ $? -ne 0 ]; then
adf540
			error "TLS certificate/key/DB '%s' was not found." "$cert"
adf540
			retcoder=1
adf540
			continue
adf540
		fi
adf540
		run_as_ldap "/usr/bin/test -r \"$cert\""
adf540
		if [ $? -ne 0 ]; then
adf540
			error "TLS certificate/key/DB '%s' is not readable." "$cert"
adf540
			retcode=1
adf540
		fi
adf540
	done
adf540
	return $retcode
adf540
}
adf540
adf540
function check_db_perms()
adf540
{
adf540
	retcode=0
adf540
	for dbdir in `databases`; do
adf540
		[ -d "$dbdir" ] || continue
adf540
		for dbfile in `find ${dbdir} -maxdepth 1 -name "*.dbb" -or -name "*.gdbm" -or -name "*.bdb" -or -name "__db.*" -or -name "log.*" -or -name "alock"`; do
adf540
			run_as_ldap "/usr/bin/test -r \"$dbfile\" -a -w \"$dbfile\""
adf540
			if [ $? -ne 0 ]; then
adf540
				error "Read/write permissions for DB file '%s' are required." "$dbfile"
adf540
				retcode=1
adf540
			fi
adf540
		done
adf540
	done
adf540
	return $retcode
adf540
}
adf540
adf540
function check_everything()
adf540
{
adf540
	retcode=0
adf540
	check_config_syntax || retcode=1
adf540
	# TODO: need support for Mozilla NSS, disabling temporarily
adf540
	#check_certs_perms || retcode=1
adf540
	check_db_perms || retcode=1
adf540
	return $retcode
adf540
}
adf540
adf540
if [ `id -u` -ne 0 ]; then
adf540
	error "You have to be root to run this script."
adf540
	exit 4
adf540
fi
adf540
adf540
load_sysconfig
adf540
adf540
if [ -n "$SLAPD_CONFIG_DIR" ]; then
adf540
	if [ ! -d "$SLAPD_CONFIG_DIR" ]; then
adf540
		error "Configuration directory '%s' does not exist." "$SLAPD_CONFIG_DIR"
adf540
	else
adf540
		check_everything
adf540
		exit $?
adf540
	fi
adf540
fi
adf540
adf540
if [ -n "$SLAPD_CONFIG_FILE" ]; then
adf540
	if [ ! -f "$SLAPD_CONFIG_FILE" ]; then
adf540
		error "Configuration file '%s' does not exist." "$SLAPD_CONFIG_FILE"
adf540
	else
adf540
		error "Warning: Usage of a configuration file is obsolete!"
adf540
		check_everything
adf540
		exit $?
adf540
	fi
adf540
fi
adf540
adf540
exit 1