mrc0mmand / rpms / openldap

Forked from rpms/openldap 3 years ago
Clone

Blame SOURCES/libexec-check-config.sh

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