xref: /netbsd-src/external/bsd/openldap/dist/tests/scripts/test004-modify (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 > $CONF1
23$SLAPADD -f $CONF1 -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$SLAPD -f $CONF1 -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 1
40
41echo "Testing slapd modify operations..."
42for i in 0 1 2 3 4 5; do
43	$LDAPSEARCH -s base -b "$MONITOR" -H $URI1 \
44		'objectclass=*' > /dev/null 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 "Testing modify, add, and delete..."
60$LDAPMODIFY -v -D "$MANAGERDN" -H $URI1 -w $PASSWD > \
61	$TESTOUT -f $LDIFMODIFY
62RC=$?
63if test $RC != 0 ; then
64	echo "ldapmodify failed ($RC)!"
65	test $KILLSERVERS != no && kill -HUP $KILLPIDS
66	exit $RC
67fi
68
69echo "Using ldapmodify to add an empty entry (should fail with protocolError)..."
70$LDAPMODIFY -D "$MANAGERDN" -H $URI1 -w $PASSWD \
71	 >> $TESTOUT 2>&1 << EOMODS
72dn: cn=Foo Bar,dc=example,dc=com
73changetype: add
74# EMPTY SEQUENCE OF ATTRS
75EOMODS
76
77RC=$?
78case $RC in
792)
80	echo "	ldapmodify failed ($RC)"
81	;;
820)
83	echo "	ldapmodify should have failed ($RC)!"
84	test $KILLSERVERS != no && kill -HUP $KILLPIDS
85	exit -1
86	;;
87*)
88	echo "	ldapmodify failed ($RC)!"
89	test $KILLSERVERS != no && kill -HUP $KILLPIDS
90	exit $RC
91	;;
92esac
93
94echo "Using ldapsearch to retrieve all the entries..."
95$LDAPSEARCH -S "" -b "$BASEDN" -H $URI1 \
96	    'objectClass=*' > $SEARCHOUT 2>&1
97RC=$?
98test $KILLSERVERS != no && kill -HUP $KILLPIDS
99if test $RC != 0 ; then
100	echo "ldapsearch failed ($RC)!"
101	exit $RC
102fi
103
104LDIF=$MODIFYOUTPROVIDER
105
106echo "Filtering ldapsearch results..."
107$LDIFFILTER < $SEARCHOUT > $SEARCHFLT
108echo "Filtering original ldif used to create database..."
109$LDIFFILTER < $LDIF > $LDIFFLT
110echo "Comparing filter output..."
111$CMP $SEARCHFLT $LDIFFLT > $CMPOUT
112
113if test $? != 0 ; then
114	echo "comparison failed - modify operations did not complete correctly"
115	exit 1
116fi
117
118echo ">>>>> Test succeeded"
119
120test $KILLSERVERS != no && wait
121
122exit 0
123