Blame SOURCES/libexec-check-config.sh

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