mrc0mmand / rpms / openldap

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