test062-config-delete revision 1.1.1.2 1 #! /bin/sh
2 # $OpenLDAP$
3 ## This work is part of OpenLDAP Software <http://www.openldap.org/>.
4 ##
5 ## Copyright 1998-2024 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 echo "running defines.sh"
17 . $SRCDIR/scripts/defines.sh
18
19 if test $SYNCPROV = syncprovno; then
20 echo "Syncrepl provider overlay not available, test skipped"
21 exit 0
22 fi
23
24 CONFDIR=$TESTDIR/slapd.d
25 DBDIR=$TESTDIR/db
26 RCOUT=$TESTDIR/rcout
27
28 mkdir -p $TESTDIR $CONFDIR $DBDIR
29
30 $SLAPPASSWD -g -n >$CONFIGPWF
31
32 #
33 # Test dynamic add/delete of syncprov overlay:
34 # - Create minimal back-conf setup
35 # - Add syncprov overlay to the cn=config database
36 # - Remove the overlay again
37 #
38
39 echo "Starting slapd on TCP/IP port $PORT1... $PWD"
40 . $CONFFILTER $BACKEND < $DYNAMICCONF > $CONFLDIF
41 $SLAPADD -F $CONFDIR -n 0 -l $CONFLDIF
42 RC=$?
43 if test $RC != 0 ; then
44 echo "slapadd failed ($RC)!"
45 exit $RC
46 fi
47
48 cd $TESTDIR
49 $SLAPD -F ./slapd.d -h $URI1 -d $LVL > $LOG1 2>&1 &
50 PID=$!
51 if test $WAIT != 0 ; then
52 echo PID $PID
53 read foo
54 fi
55 KILLPIDS="$PID"
56 cd $TESTWD
57
58 sleep 1
59
60 echo "Using ldapsearch to check that slapd is running..."
61 for i in 0 1 2 3 4 5; do
62 $LDAPSEARCH -s base -b "" -H $URI1 \
63 'objectclass=*' > /dev/null 2>&1
64 RC=$?
65 if test $RC = 0 ; then
66 break
67 fi
68 echo "Waiting 5 seconds for slapd to start..."
69 sleep 5
70 done
71
72 if test $RC != 0 ; then
73 echo "ldapsearch failed ($RC)!"
74 test $KILLSERVERS != no && kill -HUP $KILLPIDS
75 exit $RC
76 fi
77
78 echo "Inserting syncprov overlay ..."
79 if [ "$SYNCPROV" = syncprovmod ]; then
80 $LDAPADD -D cn=config -H $URI1 -y $CONFIGPWF <<EOF > $TESTOUT 2>&1
81 dn: cn=module,cn=config
82 objectClass: olcModuleList
83 cn: module
84 olcModulePath: $TESTWD/../servers/slapd/overlays
85 olcModuleLoad: syncprov.la
86 EOF
87 RC=$?
88 if test $RC != 0 ; then
89 echo "ldapadd failed for moduleLoad ($RC)!"
90 test $KILLSERVERS != no && kill -HUP $KILLPIDS
91 exit $RC
92 fi
93 fi
94 read CONFIGPW < $CONFIGPWF
95 $LDAPMODIFY -D cn=config -H $URI1 -y $CONFIGPWF <<EOF >> $TESTOUT 2>&1
96 dn: olcOverlay=syncprov,olcDatabase={0}config,cn=config
97 changetype: add
98 objectClass: olcOverlayConfig
99 objectClass: olcSyncProvConfig
100 olcOverlay: syncprov
101 EOF
102
103 RC=$?
104 if test $RC != 0 ; then
105 echo "ldapmodify failed for syncrepl config ($RC)!"
106 test $KILLSERVERS != no && kill -HUP $KILLPIDS
107 exit $RC
108 fi
109
110 echo "Starting a refreshAndPersist search in background"
111 rm -f $RCOUT
112 (
113 $LDAPSEARCH -D cn=config -H $URI1 -y $CONFIGPWF -bcn=config -E \!sync=rp >/dev/null 2>&1
114 RC=$?
115 echo $RC > $RCOUT
116 exit $RC
117 ) &
118
119 SEARCHPID=$!
120
121 sleep 2
122
123 echo "Removing syncprov overlay again ..."
124 $LDAPDELETE -D cn=config -H $URI1 -y $CONFIGPWF <<EOF >> $TESTOUT 2>&1
125 olcOverlay={0}syncprov,olcDatabase={0}config,cn=config
126 EOF
127 RC=$?
128
129 if test $RC != 0 ; then
130 echo "ldapmodify failed for syncrepl config ($RC)!"
131 test $KILLSERVERS != no && kill -HUP $KILLPIDS
132 exit $RC
133 fi
134
135 for i in 0 1 2 3 4; do
136 if test -f "$RCOUT" ; then
137 break
138 else
139 echo "Waiting 2 seconds for RefreshAndPersist search to end ..."
140 sleep 2
141 fi
142 done
143
144 if test -f "$RCOUT" ; then
145 wait $SEARCHPID
146 SEARCHRC=`cat $RCOUT`
147 echo "Checking return code of backgrounded RefreshAndPersist search ..."
148 if test 52 != "$SEARCHRC" ; then
149 echo "Error: Backgrounded ldapsearch returned the wrong error code: $SEARCHRC"
150 RC=1
151 else
152 echo "Exit code correct."
153 fi
154 else
155 echo "Backgrounded ldapsearch did not exit after overlay removal."
156 kill -HUP $SEARCHPID
157 RC=2
158 fi
159 if test $RC != 0 ; then
160 test $KILLSERVERS != no && kill -HUP $KILLPIDS
161 exit $RC
162 fi
163
164 echo "Running a refreshOnly search, should fail..."
165 $LDAPSEARCH -D cn=config -H $URI1 -y $CONFIGPWF -bcn=config -E \!sync=ro > /dev/null 2>&1
166
167 RC=$?
168 if test $RC != 12 ; then
169 echo "ldapsearch should have failed with Critical extension is unavailable (12)!"
170 test $KILLSERVERS != no && kill -HUP $KILLPIDS
171 exit $RC
172 else
173 echo "Failed with \"Critical extension is unavailable (12)\". Ok."
174 fi
175
176
177 test $KILLSERVERS != no && kill -HUP $KILLPIDS
178
179 echo ">>>>> Test succeeded"
180
181 test $KILLSERVERS != no && wait
182
183 exit 0
184