1#! /bin/sh
2# $OpenLDAP$
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 $BACKPERL = perlno; then
20	echo "Perl backend not available, test skipped"
21	exit 0
22fi
23
24CONFDIR=$TESTDIR/slapd.d
25PERLPM=$TOPSRCDIR/servers/slapd/back-perl/SampleLDAP.pm
26PERLMOD=SampleLDAP
27
28mkdir -p $TESTDIR $CONFDIR $DBDIR1
29cp $PERLPM $TESTDIR
30
31$SLAPPASSWD -g -n >$CONFIGPWF
32
33echo "Starting slapd on TCP/IP port $PORT1... $PWD"
34. $CONFFILTER $BACKEND < $DYNAMICCONF > $CONFLDIF
35$SLAPADD -F $CONFDIR -n 0 -l $CONFLDIF
36cd $TESTDIR
37$SLAPD -F ./slapd.d -h $URI1 -d $LVL > $LOG1 2>&1 &
38PID=$!
39if test $WAIT != 0 ; then
40    echo PID $PID
41    read foo
42fi
43KILLPIDS="$PID"
44cd $TESTWD
45
46sleep 1
47
48echo "Using ldapsearch to check that slapd is running..."
49for i in 0 1 2 3 4 5; do
50	$LDAPSEARCH -s base -b "" -H $URI1 \
51		'objectclass=*' > /dev/null 2>&1
52	RC=$?
53	if test $RC = 0 ; then
54		break
55	fi
56	echo "Waiting 5 seconds for slapd to start..."
57	sleep 5
58done
59
60if test $RC != 0 ; then
61	echo "ldapsearch failed ($RC)!"
62	test $KILLSERVERS != no && kill -HUP $KILLPIDS
63	exit $RC
64fi
65
66echo "Adding schema..."
67$LDAPADD -H $URI1 -D cn=config -y $CONFIGPWF <<EOF >>$TESTOUT 2>&1
68include: file://$ABS_SCHEMADIR/core.ldif
69
70include: file://$ABS_SCHEMADIR/cosine.ldif
71EOF
72RC=$?
73if test $RC != 0 ; then
74	echo "ldapadd failed for schema config ($RC)!"
75	test $KILLSERVERS != no && kill -HUP $KILLPIDS
76	exit $RC
77fi
78
79if test $BACKPERL = perlmod; then
80	echo "Loading back-perl module..."
81	$LDAPADD -H $URI1 -D cn=config -y $CONFIGPWF <<EOF >>$TESTOUT 2>&1
82dn: cn=module,cn=config
83objectClass: olcModuleList
84cn: module
85olcModulePath: $TESTWD/../servers/slapd/back-perl
86olcModuleLoad: back_perl.la
87EOF
88	RC=$?
89	if test $RC != 0 ; then
90		echo "ldapadd failed for module config ($RC)!"
91		test $KILLSERVERS != no && kill -HUP $KILLPIDS
92		exit $RC
93	fi
94fi
95
96echo "Adding database..."
97$LDAPADD -H $URI1 -D cn=config -y $CONFIGPWF <<EOF >>$TESTOUT 2>&1
98dn: olcDatabase=perl,cn=config
99objectClass: olcDatabaseConfig
100objectClass: olcDbPerlConfig
101olcDatabase: perl
102olcSuffix: $BASEDN
103olcRootDN: $MANAGERDN
104olcRootPW: $PASSWD
105olcPerlModulePath: $TESTDIR
106olcPerlModule: $PERLMOD
107EOF
108RC=$?
109if test $RC != 0 ; then
110	echo "ldapadd failed for database config ($RC)!"
111	test $KILLSERVERS != no && kill -HUP $KILLPIDS
112	exit $RC
113fi
114
115test $KILLSERVERS != no && kill -HUP $KILLPIDS
116
117echo ">>>>> Test succeeded"
118
119test $KILLSERVERS != no && wait
120
121exit 0
122