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