xref: /netbsd-src/external/bsd/openldap/dist/tests/scripts/test001-slapadd (revision e670fd5c413e99c2f6a37901bb21c537fcd322d2)
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
19mkdir -p $TESTDIR $DBDIR1
20
21echo "Running slapadd to build slapd database..."
22. $CONFFILTER $BACKEND < $CONF > $ADDCONF
23$SLAPADD -f $ADDCONF -l $LDIFORDERED
24RC=$?
25if test $RC != 0 ; then
26	echo "slapadd failed ($RC)!"
27	exit $RC
28fi
29
30echo "Starting slapd on TCP/IP port $PORT1..."
31. $CONFFILTER $BACKEND < $CONF > $CONF1
32$SLAPD -f $CONF1 -h $URI1 -d $LVL > $LOG1 2>&1 &
33PID=$!
34if test $WAIT != 0 ; then
35    echo PID $PID
36    read foo
37fi
38KILLPIDS="$PID"
39
40sleep 1
41
42echo "Using ldapsearch to retrieve all the entries..."
43for i in 0 1 2 3 4 5; do
44	$LDAPSEARCH -S "" -b "$BASEDN" -H $URI1 > $SEARCHOUT 2>&1
45	RC=$?
46	if test $RC = 0 ; then
47		break
48	fi
49	echo "Waiting 5 seconds for slapd to start..."
50	sleep 5
51done
52
53if test $RC != 0 ; then
54	echo "ldapsearch failed ($RC)!"
55	test $KILLSERVERS != no && kill -HUP $KILLPIDS
56	exit $RC
57fi
58
59echo "Filtering ldapsearch results..."
60$LDIFFILTER < $SEARCHOUT > $SEARCHFLT
61echo "Filtering original ldif used to create database..."
62$LDIFFILTER < $LDIF > $LDIFFLT
63echo "Comparing filter output..."
64$CMP $SEARCHFLT $LDIFFLT > $CMPOUT
65
66if test $? != 0 ; then
67	echo "comparison failed - database was not created correctly"
68	echo $SEARCHFLT $LDIFFLT
69	$DIFF $SEARCHFLT $LDIFFLT
70	test $KILLSERVERS != no && kill -HUP $KILLPIDS
71	exit 1
72fi
73
74if test $BACKEND = ldif ; then
75	echo "Skipping test of unordered slapadd (unsupported in ldif backend)"
76else
77
78kill -HUP $KILLPIDS
79
80rm -f $DBDIR1/*
81
82BASE2="ou=test,dc=example,dc=com"
83sed -e "s;$BASEDN;$BASE2;" $ADDCONF > ${ADDCONF}2
84mv ${ADDCONF}2 $ADDCONF
85sed -e "s;$BASEDN;$BASE2;" $CONF1 > ${CONF1}2
86mv ${CONF1}2 $CONF1
87echo "Running slapadd with unordered LDIF..."
88$SLAPADD -f $ADDCONF -l $LDIFUNORDERED
89RC=$?
90if test $RC != 0 ; then
91	echo "slapadd failed ($RC)!"
92	exit $RC
93fi
94
95echo "Starting slapd on TCP/IP port $PORT1..."
96$SLAPD -f $CONF1 -h $URI1 -d $LVL > $LOG1 2>&1 &
97PID=$!
98if test $WAIT != 0 ; then
99    echo PID $PID
100    read foo
101fi
102KILLPIDS="$PID"
103
104sleep 1
105
106echo "Using ldapsearch to retrieve all the entries..."
107for i in 0 1 2 3 4 5; do
108	$LDAPSEARCH -b "$BASE2" -H $URI1 > $SEARCHOUT 2>&1
109	RC=$?
110	if test $RC = 0 ; then
111		break
112	fi
113	echo "Waiting 5 seconds for slapd to start..."
114	sleep 5
115done
116
117if test $RC != 0 ; then
118	echo "ldapsearch failed ($RC)!"
119	test $KILLSERVERS != no && kill -HUP $KILLPIDS
120	exit $RC
121fi
122
123echo "Filtering ldapsearch results..."
124$LDIFFILTER < $SEARCHOUT > $SEARCHFLT
125echo "Filtering original ldif used to create database..."
126$LDIFFILTER < $LDIFREORDERED > $LDIFFLT
127echo "Comparing filter output..."
128$CMP $SEARCHFLT $LDIFFLT > $CMPOUT
129
130if test $? != 0 ; then
131	echo "comparison failed - database was not created correctly"
132	echo $SEARCHFLT $LDIFFLT
133	$DIFF $SEARCHFLT $LDIFFLT
134	test $KILLSERVERS != no && kill -HUP $KILLPIDS
135	exit 1
136fi
137
138fi
139
140test $KILLSERVERS != no && kill -HUP $KILLPIDS
141
142echo ">>>>> Test succeeded"
143
144test $KILLSERVERS != no && wait
145
146exit 0
147