Blame SOURCES/libexec-check-config.sh

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