1#! /bin/sh
2# Header
3## This work is part of OpenLDAP Software <http://www.openldap.org/>.
4##
5## Copyright 1998-2021 The OpenLDAP Foundation.
6## All rights reserved.
7##
8## Redistribution and use in source and binary forms, with or without
9## modification, are permitted only as authorized by the OpenLDAP
10## Public License.
11##
12## A copy of this license is available in the file LICENSE in the
13## top-level directory of the distribution or, alternatively, at
14## <http://www.OpenLDAP.org/license.html>.
15
16echo "running defines.sh"
17. $SRCDIR/scripts/defines.sh
18
19if test $RETCODE = retcodeno; then 
20	echo "Retcode overlay not available, test skipped"
21	exit 0
22fi 
23
24mkdir -p $TESTDIR $DBDIR1
25
26echo "Running slapadd to build slapd database..."
27. $CONFFILTER $BACKEND < $MCONF > $ADDCONF
28$SLAPADD -f $ADDCONF -l $LDIFORDERED
29RC=$?
30if test $RC != 0 ; then
31	echo "slapadd failed ($RC)!"
32	exit $RC
33fi
34
35echo "Running slapindex to index slapd database..."
36. $CONFFILTER $BACKEND < $RETCODECONF > $CONF1
37$SLAPINDEX -f $CONF1
38RC=$?
39if test $RC != 0 ; then
40	echo "warning: slapindex failed ($RC)"
41	echo "  assuming no indexing support"
42fi
43
44echo "Starting slapd on TCP/IP port $PORT1..."
45$SLAPD -f $CONF1 -h $URI1 -d $LVL > $LOG1 2>&1 &
46PID=$!
47if test $WAIT != 0 ; then
48    echo PID $PID
49    read foo
50fi
51KILLPIDS="$PID"
52
53sleep 1
54
55echo "Testing slapd searching..."
56for i in 0 1 2 3 4 5; do
57	$LDAPSEARCH -s base -b "$MONITOR" -H $URI1 \
58		'(objectclass=*)' > /dev/null 2>&1
59	RC=$?
60	if test $RC = 0 ; then
61		break
62	fi
63	echo "Waiting 5 seconds for slapd to start..."
64	sleep 5
65done
66
67if test $RC != 0 ; then
68	echo "ldapsearch failed ($RC)!"
69	test $KILLSERVERS != no && kill -HUP $KILLPIDS
70	exit $RC
71fi
72
73echo "Testing search for timelimitExceeded..."
74$LDAPSEARCH -b "cn=timelimitExceeded,ou=RetCodes,$BASEDN" \
75	-H $URI1 '(objectClass=*)' >> $TESTOUT 2>&1
76RC=$?
77if test $RC != 3 ; then
78	echo "ldapsearch failed ($RC)!"
79	test $KILLSERVERS != no && kill -HUP $KILLPIDS
80	exit 1
81fi
82
83echo "Testing modify for unwillingToPerform..."
84$LDAPMODIFY -D "$MANAGERDN" -w $PASSWD \
85	-H $URI1 >> $TESTOUT 2>&1 << EOMODS
86dn: cn=unwillingToPerform,ou=RetCodes,$BASEDN
87changetype: delete
88EOMODS
89RC=$?
90if test $RC != 53 ; then
91	echo "ldapmodify failed ($RC)!"
92	test $KILLSERVERS != no && kill -HUP $KILLPIDS
93	exit 1
94fi
95
96echo "Testing compare for success after sleep (2 s)..."
97$LDAPCOMPARE -H $URI1 \
98	"cn=Success w/ Delay,ou=RetCodes,$BASEDN" "cn:foo" >> $TESTOUT 2>&1
99RC=$?
100if test $RC != 0 ; then
101	echo "ldapcompare failed ($RC)!"
102	test $KILLSERVERS != no && kill -HUP $KILLPIDS
103	exit $RC
104fi
105
106test $KILLSERVERS != no && kill -HUP $KILLPIDS
107
108echo ">>>>> Test succeeded"
109
110test $KILLSERVERS != no && wait
111
112exit 0
113