1#! /bin/sh
2## $OpenLDAP$
3## This work is part of OpenLDAP Software <http://www.openldap.org/>.
4##
5## Copyright 2016-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##
16## ACKNOWLEDGEMENTS:
17## This module was written in 2016 by Ond��ej Kuzn��k for Symas Corp.
18
19OVERLAY_CONFIG=${OVERLAY_CONFIG-data/config.ldif}
20
21mkdir -p $TESTDIR $DBDIR1
22
23mkdir $TESTDIR/confdir
24. $CONFFILTER $BACKEND $MONITORDB < $CONF > $CONF1
25
26$SLAPPASSWD -g -n >$CONFIGPWF
27echo "database config" >>$CONF1
28echo "rootpw `$SLAPPASSWD -T $CONFIGPWF`" >>$CONF1
29
30echo "Starting slapd on TCP/IP port $PORT1 for configuration..."
31$SLAPD -f $CONF1 -F $TESTDIR/confdir -h $URI1 -d $LVL > $LOG1 2>&1 &
32PID=$!
33if test $WAIT != 0 ; then
34	echo PID $PID
35	read foo
36fi
37KILLPIDS="$PID"
38
39sleep $SLEEP0
40
41for i in 0 1 2 3 4 5; do
42	$LDAPSEARCH -s base -b "$MONITOR" -H $URI1 \
43		'objectclass=*' > /dev/null 2>&1
44	RC=$?
45	if test $RC = 0 ; then
46		break
47	fi
48	echo "Waiting ${SLEEP1} seconds for slapd to start..."
49	sleep ${SLEEP1}
50done
51
52$LDAPSEARCH -D cn=config -H $URI1 -y $CONFIGPWF \
53	-s base -b 'cn=module{0},cn=config' 1.1 >$TESTOUT 2>&1
54RC=$?
55case $RC in
560)
57	$LDAPMODIFY -v -D cn=config -H $URI1 -y $CONFIGPWF \
58	>> $TESTOUT 2>&1 <<EOMOD
59dn: cn=module{0},cn=config
60changetype: modify
61add: olcModuleLoad
62olcModuleLoad: `pwd`/../datamorph.la
63EOMOD
64	;;
6532)
66	$LDAPMODIFY -v -D cn=config -H $URI1 -y $CONFIGPWF \
67	>> $TESTOUT 2>&1 <<EOMOD
68dn: cn=module,cn=config
69changetype: add
70objectClass: olcModuleList
71olcModuleLoad: `pwd`/../datamorph.la
72EOMOD
73	;;
74*)
75	echo "Failed testing for module load entry"
76	exit $RC;
77	;;
78esac
79
80RC=$?
81if test $RC != 0 ; then
82	echo "ldapmodify failed ($RC)!"
83	test $KILLSERVERS != no && kill -HUP $KILLPIDS
84	exit $RC
85fi
86
87echo "Loading test datamorph configuration..."
88. $CONFFILTER $BACKEND $MONITORDB < $OVERLAY_CONFIG | \
89$LDAPMODIFY -v -D cn=config -H $URI1 -y $CONFIGPWF \
90	> $TESTOUT 2>&1
91RC=$?
92if test $RC != 0 ; then
93	echo "ldapmodify failed ($RC)!"
94	test $KILLSERVERS != no && kill -HUP $KILLPIDS
95	exit $RC
96fi
97
98if test $INDEXDB = indexdb ; then
99	echo "Configure indexing for transformed attributes..."
100	$LDAPMODIFY -v -D cn=config -H $URI1 -y $CONFIGPWF \
101		>> $TESTOUT 2>&1 <<EOMOD
102dn: olcDatabase={1}$BACKEND,cn=config
103changetype: modify
104add: olcDbIndex
105olcDbIndex: enumerated pres,eq
106olcDbIndex: number pres,eq
107olcDbIndex: signed pres,eq
108EOMOD
109	RC=$?
110	if test $RC != 0 ; then
111		echo "ldapmodify failed ($RC)!"
112		test $KILLSERVERS != no && kill -HUP $KILLPIDS
113		exit $RC
114	fi
115else
116	echo "Skipping indexing setup for this database"
117fi
118
119echo "Stopping slapd on TCP/IP port $PORT1..."
120kill -HUP $KILLPIDS
121KILLPIDS=""
122sleep $SLEEP0
123
124echo "Running slapadd to build slapd database..."
125$SLAPADD -F $TESTDIR/confdir -l data/test.ldif
126RC=$?
127if test $RC != 0 ; then
128	echo "slapadd failed ($RC)!"
129	exit $RC
130fi
131
132echo "Starting slapd on TCP/IP port $PORT1..."
133$SLAPD -F $TESTDIR/confdir -h $URI1 -d $LVL >> $LOG1 2>&1 &
134PID=$!
135if test $WAIT != 0 ; then
136	echo PID $PID
137	read foo
138fi
139KILLPIDS="$PID"
140
141sleep $SLEEP0
142
143for i in 0 1 2 3 4 5; do
144	$LDAPSEARCH -s base -b "$MONITOR" -H $URI1 \
145		'objectclass=*' > /dev/null 2>&1
146	RC=$?
147	if test $RC = 0 ; then
148		break
149	fi
150	echo "Waiting ${SLEEP1} seconds for slapd to start..."
151	sleep ${SLEEP1}
152done
153