Blame SOURCES/libexec-check-config.sh

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