diff --git a/tests/ldap/.cvsignore b/tests/ldap/.cvsignore new file mode 100644 index 000000000..70845e08e --- /dev/null +++ b/tests/ldap/.cvsignore @@ -0,0 +1 @@ +Makefile.in diff --git a/tests/ldap/Makefile.am b/tests/ldap/Makefile.am new file mode 100644 index 000000000..963880fca --- /dev/null +++ b/tests/ldap/Makefile.am @@ -0,0 +1,48 @@ +# $Id$ + +include $(top_srcdir)/Makefile.am.common + +noinst_DATA = krb5.conf + +check_SCRIPTS = $(TESTS) slapd-init + +TESTS = check-ldap + +port = 49188 + +do_subst = sed -e 's,[@]srcdir[@],$(srcdir),g' \ + -e 's,[@]port[@],$(port),g' \ + -e 's,[@]objdir[@],$(top_builddir)/tests/ldap,g' \ + -e 's,[@]EGREP[@],$(EGREP),g' + +check-ldap: check-ldap.in Makefile + $(do_subst) < $(srcdir)/check-ldap.in > check-ldap.tmp + chmod +x check-ldap.tmp + mv check-ldap.tmp check-ldap + +slapd-init: slapd-init.in Makefile + $(do_subst) < $(srcdir)/slapd-init.in > slapd-init.tmp + chmod +x slapd-init.tmp + mv slapd-init.tmp slapd-init + +krb5.conf: krb5.conf.in Makefile + $(do_subst) < $(srcdir)/krb5.conf.in > krb5.conf.tmp + mv krb5.conf.tmp krb5.conf + +CLEANFILES= \ + $(TESTS) \ + check-ldap.tmp \ + slapd-init.tmp \ + current-db* \ + krb5.conf krb5.conf.tmp \ + modules.conf \ + cache.krb5 \ + slapd-init \ + foopassword \ + messages.log \ + slapd.pid + +EXTRA_DIST = \ + check-ldap.in \ + init.ldif \ + krb5.conf.in diff --git a/tests/ldap/check-ldap.in b/tests/ldap/check-ldap.in new file mode 100644 index 000000000..0c8f0774b --- /dev/null +++ b/tests/ldap/check-ldap.in @@ -0,0 +1,131 @@ +#!/bin/sh +# +# Copyright (c) 2006 Kungliga Tekniska Högskolan +# (Royal Institute of Technology, Stockholm, Sweden). +# All rights reserved. +# +# Redistribution and use in source and binary forms, with or without +# modification, are permitted provided that the following conditions +# are met: +# +# 1. Redistributions of source code must retain the above copyright +# notice, this list of conditions and the following disclaimer. +# +# 2. Redistributions in binary form must reproduce the above copyright +# notice, this list of conditions and the following disclaimer in the +# documentation and/or other materials provided with the distribution. +# +# 3. Neither the name of the Institute nor the names of its contributors +# may be used to endorse or promote products derived from this software +# without specific prior written permission. +# +# THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND +# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +# ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE +# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +# SUCH DAMAGE. +# +# $Id$ +# + +srcdir="@srcdir@" +objdir="@objdir@" +EGREP="@EGREP@" + +R=TEST.H5L.SE + +port=@port@ + +cache="FILE:${objdir}/cache.krb5" + +kinit="${TESTS_ENVIRONMENT} ../../kuser/kinit -c $cache --no-afslog" +kadmin="${TESTS_ENVIRONMENT} ../../kadmin/kadmin -l -r $R" +kdc="${TESTS_ENVIRONMENT} ../../kdc/kdc --addresses=localhost -P $port" + +testfailed="echo test failed; exit 1" + +# If there is no ldap support compile in, disable test +if ${kdc} --builtin-hdb | grep ldap > /dev/null ; then + : +else + echo "no ldap support" + exit 77 +fi + +#search for all ldap tools + +PATH=/usr/local/sbin:/usr/sbin:/sbin:/usr/libexec:$PATH +export PATH + +oldifs=$IFS +IFS=: +set -- $PATH +IFS=$oldifs +for j in slapd slapadd; do + for i in $*; do + test -n "$i" || i="." + if test -x $i/$j; then + continue 2 + fi + done + echo "$j missing, not running test" + exit 77 +done + +sh ${objdir}/slapd-init || exit 1 + +trap "sh ${srcdir}/slapd-stop ; exit 1;" EXIT + +KRB5_CONFIG="${objdir}/krb5.conf" +export KRB5_CONFIG + +rm -f current-db* + +echo Creating database +${kadmin} \ + init \ + --realm-max-ticket-life=1day \ + --realm-max-renewable-life=1month \ + ${R} || exit 1 + +${kadmin} add -p foo --use-defaults foo@${R} || exit 1 + +echo foo > ${objdir}/foopassword + +echo Starting kdc +${kdc} & +kdcpid=$! + +sh ${srcdir}/../kdc/wait-kdc.sh +if [ "$?" != 0 ] ; then + kill ${kdcpid} + sh ${srcdir}/slapd-stop + exit 1 +fi + +trap "kill ${kdcpid}; echo signal killing kdc; sh ${srcdir}/slapd-stop ; exit 1;" EXIT + +ec=0 + +echo "Getting client initial tickets"; +${kinit} --password-file=${objdir}/foopassword foo@$R || \ + { ec=1 ; eval "${testfailed}"; } + + +echo "killing kdc (${kdcpid})" +kill $kdcpid || exit 1 + +trap "" EXIT + +# kill of old slapd +sh ${srcdir}/slapd-stop + +rm -rf db schema + +exit $ec diff --git a/tests/ldap/init.ldif b/tests/ldap/init.ldif new file mode 100644 index 000000000..b277202d3 --- /dev/null +++ b/tests/ldap/init.ldif @@ -0,0 +1,8 @@ +dn: o=TEST,dc=H5L,dc=SE +objectclass: organization +o: Test + +dn: ou=kerberosPrincipals,o=TEST,dc=H5L,dc=SE +objectclass: organizationalUnit +ou: kerberosPrincipals + diff --git a/tests/ldap/krb5.conf.in b/tests/ldap/krb5.conf.in new file mode 100644 index 000000000..0bd3abbd9 --- /dev/null +++ b/tests/ldap/krb5.conf.in @@ -0,0 +1,21 @@ +# $Id$ + +[libdefaults] + default_realm = TEST.H5L.SE + no-addresses = TRUE + +[realms] + TEST.H5L.SE = { + kdc = localhost:@port@ + } + +[kdc] + database = { + dbname = ldapi://ldap-socket:OU=KerberosPrincipals,o=test,DC=h5l,DC=se + realm = TEST.H5L.SE + mkey_file = @objdir@/mkey.file + } + +[logging] + kdc = 0-/FILE:@objdir@/messages.log + default = 0-/FILE:@objdir@/messages.log diff --git a/tests/ldap/slapd-init.in b/tests/ldap/slapd-init.in new file mode 100644 index 000000000..e68c612fd --- /dev/null +++ b/tests/ldap/slapd-init.in @@ -0,0 +1,38 @@ +#!/bin/sh + +srcdir=@srcdir@ + +rm -rf db +mkdir db + +# kill of old slapd if running +sh ${srcdir}/slapd-stop > /dev/null + +SCHEMA_NEEDED="hdb core nis cosine inetorgperson openldap" + +SCHEMA_PATHS="${srcdir}/../../lib/hdb /etc/ldap/schema /etc/openldap/schema /private/etc/openldap/schema" + +test -d schema || mkdir schema + +# setup needed schema files +for f in $SCHEMA_NEEDED; do + if [ ! -r schema/$f.schema ]; then + for d in $SCHEMA_PATHS ; do + if [ -r $d/$f.schema ] ; then + cp $d/$f.schema schema/$f.schema + continue 2 + fi + done + echo "SKIPPING TESTS: you need the following schema file: $f.schema" + exit 1 + fi +done + +touch modules.conf || exit 1 + +slapadd -f ${srcdir}/slapd.conf < ${srcdir}/init.ldif || exit 0 + +echo "starting slapd" +slapd -d0 -f ${srcdir}/slapd.conf -h ldapi://.%2Fldap-socket & + +sleep 4 diff --git a/tests/ldap/slapd-stop b/tests/ldap/slapd-stop new file mode 100644 index 000000000..278d98ae1 --- /dev/null +++ b/tests/ldap/slapd-stop @@ -0,0 +1,18 @@ +#!/bin/sh +# $Id$ + +echo stoping slapd + +# kill of old slapd +if [ -f slapd.pid ]; then + kill `cat slapd.pid` + sleep 5 +fi +if [ -f slapd.pid ]; then + kill -9 `cat slapd.pid` + rm -f slapd.pid + sleep 5 +fi + +exit 0 + diff --git a/tests/ldap/slapd.conf b/tests/ldap/slapd.conf new file mode 100644 index 000000000..b6d22697c --- /dev/null +++ b/tests/ldap/slapd.conf @@ -0,0 +1,27 @@ +loglevel 0 + +include schema/core.schema +include schema/cosine.schema +include schema/inetorgperson.schema +include schema/openldap.schema +include schema/nis.schema +include schema/hdb.schema + + +pidfile slapd.pid +argsfile slapd.args + +access to * by * write + +allow update_anon bind_anon_dn + +include modules.conf + +defaultsearchbase "ou=TEST,dc=H5L,dc=SE" + +backend bdb +database bdb +suffix "o=TEST,dc=H5L,dc=SE" +directory db +index objectClass eq +index uid eq