Sync usage with man page.
[netbsd-mini2440.git] / external / bsd / openldap / dist / tests / scripts / test003-search
blob8a472b50aeb98ac9569750f3836fc3e45d2456dd
1 #! /bin/sh
2 # $OpenLDAP: pkg/ldap/tests/scripts/test003-search,v 1.61.2.3 2008/02/11 23:26:51 kurt Exp $
3 ## This work is part of OpenLDAP Software <http://www.openldap.org/>.
4 ##
5 ## Copyright 1998-2008 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.
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>.
16 echo "running defines.sh"
17 . $SRCDIR/scripts/defines.sh
19 mkdir -p $TESTDIR $DBDIR1
21 echo "Running slapadd to build slapd database..."
22 . $CONFFILTER $BACKEND $MONITORDB < $MCONF > $ADDCONF
23 $SLAPADD -f $ADDCONF -l $LDIFORDERED
24 RC=$?
25 if test $RC != 0 ; then
26 echo "slapadd failed ($RC)!"
27 exit $RC
30 echo "Running slapindex to index slapd database..."
31 . $CONFFILTER $BACKEND $MONITORDB < $CONF > $CONF1
32 $SLAPINDEX -f $CONF1
33 RC=$?
34 if test $RC != 0 ; then
35 echo "warning: slapindex failed ($RC)"
36 echo " assuming no indexing support"
39 echo "Starting slapd on TCP/IP port $PORT1..."
40 $SLAPD -f $CONF1 -h $URI1 -d $LVL $TIMING > $LOG1 2>&1 &
41 PID=$!
42 if test $WAIT != 0 ; then
43 echo PID $PID
44 read foo
46 KILLPIDS="$PID"
48 sleep 1
50 echo "Testing slapd searching..."
51 for i in 0 1 2 3 4 5; do
52 $LDAPSEARCH -s base -b "$MONITOR" -h $LOCALHOST -p $PORT1 \
53 '(objectclass=*)' > /dev/null 2>&1
54 RC=$?
55 if test $RC = 0 ; then
56 break
58 echo "Waiting 5 seconds for slapd to start..."
59 sleep 5
60 done
62 if test $RC != 0 ; then
63 echo "ldapsearch failed ($RC)!"
64 test $KILLSERVERS != no && kill -HUP $KILLPIDS
65 exit $RC
68 cat /dev/null > $SEARCHOUT
70 echo "Testing exact searching..."
71 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 \
72 '(sn=jENSEN)' >> $SEARCHOUT 2>&1
73 RC=$?
74 if test $RC != 0 ; then
75 echo "ldapsearch failed ($RC)!"
76 test $KILLSERVERS != no && kill -HUP $KILLPIDS
77 exit $RC
80 echo "Testing approximate searching..."
81 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 \
82 '(sn~=jENSEN)' name >> $SEARCHOUT 2>&1
83 RC=$?
84 if test $RC != 0 ; then
85 echo "ldapsearch failed ($RC)!"
86 test $KILLSERVERS != no && kill -HUP $KILLPIDS
87 exit $RC
90 echo "Testing OR searching..."
91 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 \
92 '(|(givenname=Xx*yY*Z)(cn=)(undef=*)(objectclass=groupofnames)(sn=jones)(member=cn=Manager,dc=example,dc=com)(uniqueMember=cn=Manager,dc=example,dc=com))' >> $SEARCHOUT 2>&1
93 RC=$?
94 if test $RC != 0 ; then
95 echo "ldapsearch failed ($RC)!"
96 test $KILLSERVERS != no && kill -HUP $KILLPIDS
97 exit $RC
100 echo "Testing AND matching and ends-with searching..."
101 $LDAPSEARCH -S "" -b "ou=groups,$BASEDN" -s one -h $LOCALHOST -p $PORT1 \
102 '(&(objectclass=groupofnames)(cn=A*)(member=cn=Mark Elliot,ou=Alumni Association,ou=People,dc=example,dc=com))' >> $SEARCHOUT 2>&1
103 RC=$?
104 if test $RC != 0 ; then
105 echo "ldapsearch failed ($RC)!"
106 test $KILLSERVERS != no && kill -HUP $KILLPIDS
107 exit $RC
110 echo "Testing NOT searching..."
111 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 \
112 '(!(objectclass=pilotPerson))' >> $SEARCHOUT 2>&1
113 RC=$?
114 if test $RC != 0 ; then
115 echo "ldapsearch failed ($RC)!"
116 test $KILLSERVERS != no && kill -HUP $KILLPIDS
117 exit $RC
120 echo "Testing objectClass/attributeType inheritance ..."
121 $LDAPSEARCH -M -a never -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 \
122 '(&(objectClass=inetorgperson)(userid=uham))' \
123 "2.5.4.0" "userid" >> $SEARCHOUT 2>&1
124 RC=$?
125 if test $RC != 0 ; then
126 echo "ldapsearch failed ($RC)!"
127 test $KILLSERVERS != no && kill -HUP $KILLPIDS
128 exit $RC
131 test $KILLSERVERS != no && kill -HUP $KILLPIDS
133 LDIF=$SEARCHOUTMASTER
135 echo "Filtering ldapsearch results..."
136 . $LDIFFILTER < $SEARCHOUT > $SEARCHFLT
137 echo "Filtering original ldif used to create database..."
138 . $LDIFFILTER < $LDIF > $LDIFFLT
139 echo "Comparing filter output..."
140 $CMP $SEARCHFLT $LDIFFLT > $CMPOUT
142 if test $? != 0 ; then
143 echo "Comparison failed"
144 exit 1
147 echo ">>>>> Test succeeded"
149 test $KILLSERVERS != no && wait
151 exit 0