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 < $MCONF > $ADDCONF 23$SLAPADD -f $ADDCONF -l $LDIFORDERED 24RC=$? 25if test $RC != 0 ; then 26 echo "slapadd failed ($RC)!" 27 exit $RC 28fi 29 30echo "Running slapindex to index slapd database..." 31. $CONFFILTER $BACKEND < $CONF > $CONF1 32$SLAPINDEX -f $CONF1 33RC=$? 34if test $RC != 0 ; then 35 echo "warning: slapindex failed ($RC)" 36 echo " assuming no indexing support" 37fi 38 39echo "Starting slapd on TCP/IP port $PORT1..." 40$SLAPD -f $CONF1 -h $URI1 -d $LVL > $LOG1 2>&1 & 41PID=$! 42if test $WAIT != 0 ; then 43 echo PID $PID 44 read foo 45fi 46KILLPIDS="$PID" 47 48sleep 1 49 50echo "Testing slapd searching..." 51for i in 0 1 2 3 4 5; do 52 $LDAPSEARCH -s base -b "$MONITOR" -H $URI1 \ 53 'objectclass=*' > /dev/null 2>&1 54 RC=$? 55 if test $RC = 0 ; then 56 break 57 fi 58 echo "Waiting 5 seconds for slapd to start..." 59 sleep 5 60done 61 62if test $RC != 0 ; then 63 echo "ldapsearch failed ($RC)!" 64 test $KILLSERVERS != no && kill -HUP $KILLPIDS 65 exit $RC 66fi 67 68cat /dev/null > $SEARCHOUT 69 70echo "Testing exact searching..." 71echo "# Testing exact searching..." >> $SEARCHOUT 72$LDAPSEARCH -S "" -b "$BASEDN" -H $URI1 \ 73 '(sn:=jensen)' >> $SEARCHOUT 2>&1 74RC=$? 75if test $RC != 0 ; then 76 echo "ldapsearch failed ($RC)!" 77 test $KILLSERVERS != no && kill -HUP $KILLPIDS 78 exit $RC 79fi 80 81echo "Testing approximate searching..." 82echo "# Testing approximate searching..." >> $SEARCHOUT 83$LDAPSEARCH -S "" -b "$BASEDN" -H $URI1 \ 84 '(sn~=jensen)' name >> $SEARCHOUT 2>&1 85RC=$? 86if test $RC != 0 ; then 87 echo "ldapsearch failed ($RC)!" 88 test $KILLSERVERS != no && kill -HUP $KILLPIDS 89 exit $RC 90fi 91 92echo "Testing OR searching..." 93echo "# Testing OR searching..." >> $SEARCHOUT 94$LDAPSEARCH -S "" -b "$BASEDN" -H $URI1 \ 95 '(|(givenName=XX*YY*Z)(cn=)(undef=*)(objectclass=groupofnames)(objectclass=groupofuniquenames)(sn:caseExactMatch:=Jones))' >> $SEARCHOUT 2>&1 96RC=$? 97if test $RC != 0 ; then 98 echo "ldapsearch failed ($RC)!" 99 test $KILLSERVERS != no && kill -HUP $KILLPIDS 100 exit $RC 101fi 102 103echo "Testing AND matching and ends-with searching..." 104echo "# Testing AND matching and ends-with searching..." >> $SEARCHOUT 105$LDAPSEARCH -S "" -b "ou=groups,$BASEDN" -s one -H $URI1 \ 106 '(&(|(objectclass=groupofnames)(objectclass=groupofuniquenames))(cn=A*))' >> $SEARCHOUT 2>&1 107RC=$? 108if test $RC != 0 ; then 109 echo "ldapsearch failed ($RC)!" 110 test $KILLSERVERS != no && kill -HUP $KILLPIDS 111 exit $RC 112fi 113 114echo "Testing NOT searching..." 115echo "# Testing NOT searching..." >> $SEARCHOUT 116$LDAPSEARCH -S "" -b "$BASEDN" -H $URI1 \ 117 '(!(objectclass=pilotPerson))' >> $SEARCHOUT 2>&1 118RC=$? 119if test $RC != 0 ; then 120 echo "ldapsearch failed ($RC)!" 121 test $KILLSERVERS != no && kill -HUP $KILLPIDS 122 exit $RC 123fi 124 125echo "Testing objectClass/attributeType inheritance ..." 126echo "# Testing objectClass/attributeType inheritance ..." >> $SEARCHOUT 127$LDAPSEARCH -M -a never -S "" -b "$BASEDN" -H $URI1 \ 128 '(&(objectClass=inetorgperson)(userid=uham))' \ 129 "2.5.4.0" "userid" >> $SEARCHOUT 2>&1 130RC=$? 131if test $RC != 0 ; then 132 echo "ldapsearch failed ($RC)!" 133 test $KILLSERVERS != no && kill -HUP $KILLPIDS 134 exit $RC 135fi 136 137echo "Testing extended RFC2254 searching:" 138echo "# Testing extended RFC2254 searching:" >> $SEARCHOUT 139 140FILTER="(:dn:caseIgnoreIA5Match:=example)" 141echo " f=$FILTER ..." 142echo "# f=$FILTER ..." >> $SEARCHOUT 143$LDAPSEARCH -S "" -b "$BASEDN" -H $URI1 \ 144 "$FILTER" >> $SEARCHOUT 2>&1 145 146RC=$? 147if test $RC != 0 ; then 148 echo "ldapsearch failed ($RC)!" 149 test $KILLSERVERS != no && kill -HUP $KILLPIDS 150 exit $RC 151fi 152 153FILTER="(:dn:caseExactMatch:=Information Technology Division)" 154echo " f=$FILTER ..." 155echo "# f=$FILTER ..." >> $SEARCHOUT 156$LDAPSEARCH -S "" -b "$BASEDN" -H $URI1 \ 157 "$FILTER" >> $SEARCHOUT 2>&1 158 159# ITS#4380: don't crash when a matchingRule without pretty/validate is used 160FILTER="(:dn:caseIgnoreSubstringsMatch:=Information Technology Division)" 161echo " f=$FILTER ..." 162echo "# f=$FILTER ..." >> $SEARCHOUT 163$LDAPSEARCH -S "" -b "$BASEDN" -H $URI1 \ 164 "$FILTER" >> $SEARCHOUT 2>&1 165 166RC=$? 167if test $RC != 0 ; then 168 echo "ldapsearch failed ($RC)!" 169 test $KILLSERVERS != no && kill -HUP $KILLPIDS 170 exit $RC 171fi 172 173FILTER="(name:dn:=whatever)" 174echo " f=$FILTER ..." 175echo "# f=$FILTER ..." >> $SEARCHOUT 176$LDAPSEARCH -S "" -b "" -s base -H $URI1 \ 177 "$FILTER" >> $SEARCHOUT 2>&1 178 179RC=$? 180if test $RC != 0 ; then 181 echo "ldapsearch failed ($RC)!" 182 test $KILLSERVERS != no && kill -HUP $KILLPIDS 183 exit $RC 184fi 185 186echo "Testing values return filter searching:" 187echo "# Testing values return filter searching:" >> $SEARCHOUT 188 189FILTER="(o=Example, Inc.)" 190echo " f=$FILTER ..." 191echo "# f=$FILTER ..." >> $SEARCHOUT 192$LDAPSEARCH -S "" -b "$BASEDN" -H $URI1 \ 193 -E '!mv='"$FILTER" "$FILTER" >> $SEARCHOUT 2>&1 194RC=$? 195if test $RC != 0 ; then 196 echo "ldapsearch failed ($RC)!" 197 test $KILLSERVERS != no && kill -HUP $KILLPIDS 198 exit $RC 199fi 200 201FILTER="(dc=example)" 202VRFILTER="((o:caseExactMatch:=Example, Inc.)(dc=example))" 203echo " f=$FILTER mv=$VRFILTER ..." 204echo "# f=$FILTER mv=$VRFILTER ..." >> $SEARCHOUT 205$LDAPSEARCH -S "" -b "$BASEDN" -H $URI1 \ 206 -E '!mv='"$VRFILTER" "$FILTER" >> $SEARCHOUT 2>&1 207RC=$? 208if test $RC != 0 ; then 209 echo "ldapsearch failed ($RC)!" 210 test $KILLSERVERS != no && kill -HUP $KILLPIDS 211 exit $RC 212fi 213 214FILTER="(dc=example)" 215VRFILTER="((o={*)(dc=*))" 216echo " f=$FILTER mv=$VRFILTER ..." 217echo "# f=$FILTER mv=$VRFILTER ..." >> $SEARCHOUT 218$LDAPSEARCH -S "" -b "$BASEDN" -H $URI1 \ 219 -E '!mv='"$VRFILTER" "$FILTER" >> $SEARCHOUT 2>&1 220RC=$? 221if test $RC != 0 ; then 222 echo "ldapsearch failed ($RC)!" 223 test $KILLSERVERS != no && kill -HUP $KILLPIDS 224 exit $RC 225fi 226 227FILTER="(attributeTypes=0.9.2342.19200300.100.1.25)" 228echo " f=$FILTER ..." 229echo "# f=$FILTER ..." >> $SEARCHOUT 230$LDAPSEARCH -S "" -b "cn=Subschema" -s "base" -H $URI1 \ 231 -E '!mv='"$FILTER" "$FILTER" "attributeTypes" >> $SEARCHOUT 2>&1 232RC=$? 233if test $RC != 0 ; then 234 echo "ldapsearch failed ($RC)!" 235 test $KILLSERVERS != no && kill -HUP $KILLPIDS 236 exit $RC 237fi 238 239echo "Testing list substring searching..." 240echo "# Testing list substring searching..." >> $SEARCHOUT 241$LDAPSEARCH -S "" -b "$BASEDN" -H $URI1 \ 242 '(postalAddress=*Anytown*)' postalAddress >> $SEARCHOUT 2>&1 243RC=$? 244if test $RC != 0 ; then 245 echo "ldapsearch failed ($RC)!" 246 test $KILLSERVERS != no && kill -HUP $KILLPIDS 247 exit $RC 248fi 249 250test $KILLSERVERS != no && kill -HUP $KILLPIDS 251 252LDIF=$SEARCHOUTPROVIDER 253LDIF2=$SEARCHOUTX 254 255echo "Filtering ldapsearch results..." 256$LDIFFILTER < $SEARCHOUT > $SEARCHFLT 257echo "Filtering original ldif used to create database..." 258$LDIFFILTER < $LDIF > $LDIFFLT 259$LDIFFILTER < $LDIF2 >> $LDIFFLT 260echo "Comparing filter output..." 261$CMP $SEARCHFLT $LDIFFLT > $CMPOUT 262 263if test $? != 0 ; then 264 echo "Comparison failed" 265 exit 1 266fi 267 268echo ">>>>> Test succeeded" 269 270test $KILLSERVERS != no && wait 271 272exit 0 273