xref: /netbsd-src/external/bsd/openldap/dist/tests/scripts/test084-deref (revision e670fd5c413e99c2f6a37901bb21c537fcd322d2)
1#! /bin/sh
2# $OpenLDAP$
3## This work is part of OpenLDAP Software <http://www.openldap.org/>.
4##
5## Copyright 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 $DEREF = derefno; then
20	echo "Deref overlay not available, test skipped"
21	exit 0
22fi
23
24mkdir -p $TESTDIR $DBDIR1
25
26$SLAPPASSWD -g -n >$CONFIGPWF
27echo "rootpw `$SLAPPASSWD -T $CONFIGPWF`" >$TESTDIR/configpw.conf
28
29echo "Running slapadd to build slapd database..."
30. $CONFFILTER $BACKEND < $DEREFCONF > $CONF1
31$SLAPADD -f $CONF1 -l $LDIFDEREF
32RC=$?
33if test $RC != 0 ; then
34	echo "slapadd failed ($RC)!"
35	exit $RC
36fi
37
38echo "Starting slapd on TCP/IP port $PORT1..."
39$SLAPD -f $CONF1 -h $URI1 -d $LVL > $LOG1 2>&1 &
40PID=$!
41if test $WAIT != 0 ; then
42    echo PID $PID
43    read foo
44fi
45KILLPIDS="$PID"
46
47sleep 1
48
49echo "Testing slapd deref control operations..."
50for i in 0 1 2 3 4 5; do
51	$LDAPSEARCH -s base -b "$MONITOR" -H $URI1 \
52		'objectclass=*' > /dev/null 2>&1
53	RC=$?
54	if test $RC = 0 ; then
55		break
56	fi
57	echo "Waiting 5 seconds for slapd to start..."
58	sleep 5
59done
60
61if test $RC != 0 ; then
62	echo "ldapsearch failed ($RC)!"
63	test $KILLSERVERS != no && kill -HUP $KILLPIDS
64	exit $RC
65fi
66
67echo "Sending deref control..."
68
69$LDAPSEARCH -b "$DEREFBASEDN" -H $URI1 \
70	-E 'deref=member:uid' > $SEARCHOUT 2>&1
71
72RC=$?
73if test $RC != 0 ; then
74	echo "ldapsearch failed ($RC)!"
75	test $KILLSERVERS != no && kill -HUP $KILLPIDS
76	exit $RC
77fi
78
79echo "Comparing output..."
80$CMP $SEARCHOUT $DEREFOUT > $CMPOUT
81
82if test $? != 0 ; then
83	echo "Comparison failed"
84	test $KILLSERVERS != no && kill -HUP $KILLPIDS
85	exit 1
86fi
87
88test $KILLSERVERS != no && kill -HUP $KILLPIDS
89
90test $KILLSERVERS != no && wait
91
92echo ">>>>> Test succeeded"
93
94exit 0
95