Sync usage with man page.
[netbsd-mini2440.git] / external / bsd / openldap / dist / tests / scripts / test052-memberof
blob49ea5a53c3ea82e6d17dd2fa38caf7aee35bf056
1 #! /bin/sh
2 # $OpenLDAP: pkg/ldap/tests/scripts/test052-memberof,v 1.4.2.2 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 if test $MEMBEROF = memberofno; then
20 echo "Memberof overlay not available, test skipped"
21 exit 0
22 fi
24 mkdir -p $TESTDIR $DBDIR1 $TESTDIR/confdir
26 $SLAPPASSWD -g -n >$CONFIGPWF
27 echo "rootpw `$SLAPPASSWD -T $CONFIGPWF`" >$TESTDIR/configpw.conf
29 echo "Starting slapd on TCP/IP port $PORT1..."
30 . $CONFFILTER $BACKEND $MONITORDB < $NAKEDCONF > $CONF1
31 $SLAPD -f $CONF1 -F $TESTDIR/confdir -h $URI1 -d $LVL $TIMING > $LOG1 2>&1 &
32 PID=$!
33 if test $WAIT != 0 ; then
34 echo PID $PID
35 read foo
37 KILLPIDS="$PID"
39 sleep 1
40 for i in 0 1 2 3 4 5; do
41 $LDAPSEARCH -s base -b "$MONITOR" -h $LOCALHOST -p $PORT1 \
42 'objectclass=*' > /dev/null 2>&1
43 RC=$?
44 if test $RC = 0 ; then
45 break
47 echo "Waiting 5 seconds for slapd to start..."
48 sleep 5
49 done
50 if test $RC != 0 ; then
51 echo "ldapsearch failed ($RC)!"
52 test $KILLSERVERS != no && kill -HUP $KILLPIDS
53 exit $RC
56 cat /dev/null > $TESTOUT
58 if [ "$MEMBEROF" = memberofmod ]; then
59 echo "Inserting memberof overlay on producer..."
60 $LDAPADD -D cn=config -H $URI1 -y $CONFIGPWF <<EOF > $TESTOUT 2>&1
61 dn: cn=module,cn=config
62 objectClass: olcModuleList
63 cn: module
64 olcModulePath: ../servers/slapd/overlays
65 olcModuleLoad: memberof.la
66 EOF
67 RC=$?
68 if test $RC != 0 ; then
69 echo "ldapadd failed for moduleLoad ($RC)!"
70 test $KILLSERVERS != no && kill -HUP $KILLPIDS
71 exit $RC
75 echo "Running ldapadd to build slapd config database..."
76 $LDAPADD -h $LOCALHOST -p $PORT1 -D 'cn=config' -w `cat $CONFIGPWF` \
77 >> $TESTOUT 2>&1 <<EOF
78 dn: olcDatabase={1}$BACKEND,cn=config
79 objectClass: olcDatabaseConfig
80 objectClass: olc${BACKEND}Config
81 olcDatabase: {1}$BACKEND
82 olcSuffix: $BASEDN
83 olcRootDN: cn=Manager,$BASEDN
84 olcRootPW:: c2VjcmV0
85 olcMonitoring: TRUE
86 olcDbDirectory: $TESTDIR/db.1.a/
87 olcDbCacheSize: 1000
88 olcDbIndex: objectClass eq
89 olcDbIndex: cn pres,eq,sub
90 olcDbIndex: uid pres,eq,sub
91 olcDbIndex: sn pres,eq,sub
92 olcDbMode: 384
94 # {0}memberof, {1}$BACKEND, config
95 dn: olcOverlay={0}memberof,olcDatabase={1}$BACKEND,cn=config
96 objectClass: olcOverlayConfig
97 objectClass: olcMemberOf
98 olcOverlay: {0}memberof
99 olcMemberOfRefInt: TRUE
100 olcMemberOfGroupOC: groupOfNames
101 olcMemberOfMemberAD: member
102 olcMemberOfMemberOfAD: memberOf
104 RC=$?
105 if test $RC != 0 ; then
106 echo "ldapadd failed ($RC)!"
107 test $KILLSERVERS != no && kill -HUP $KILLPIDS
108 exit $RC
111 echo "Running ldapadd to build slapd database..."
112 $LDAPADD -h $LOCALHOST -p $PORT1 \
113 -D "cn=Manager,$BASEDN" -w secret \
114 >> $TESTOUT 2>&1 << EOF
115 dn: $BASEDN
116 objectClass: organization
117 objectClass: dcObject
118 o: Example, Inc.
119 dc: example
121 dn: ou=People,$BASEDN
122 objectClass: organizationalUnit
123 ou: People
125 dn: ou=Groups,$BASEDN
126 objectClass: organizationalUnit
127 ou: Groups
129 dn: cn=Roger Rabbit,ou=People,$BASEDN
130 objectClass: inetOrgPerson
131 cn: Roger Rabbit
132 sn: Rabbit
134 dn: cn=Baby Herman,ou=People,$BASEDN
135 objectClass: inetOrgPerson
136 cn: Baby Herman
137 sn: Herman
139 dn: cn=Cartoonia,ou=Groups,$BASEDN
140 objectClass: groupOfNames
141 cn: Cartoonia
142 member: cn=Roger Rabbit,ou=People,$BASEDN
143 member: cn=Baby Herman,ou=People,$BASEDN
145 RC=$?
146 if test $RC != 0 ; then
147 echo "ldapadd failed ($RC)!"
148 test $KILLSERVERS != no && kill -HUP $KILLPIDS
149 exit $RC
152 echo "Search the entire database..."
153 echo "# Search the entire database..." >> $SEARCHOUT
154 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 \
155 '(objectClass=*)' '*' memberOf >> $SEARCHOUT 2>&1
156 RC=$?
157 if test $RC != 0 ; then
158 echo "ldapsearch failed ($RC)!"
159 test $KILLSERVERS != no && kill -HUP $KILLPIDS
160 exit $RC
163 echo "Running ldapmodify to add a member..."
164 $LDAPMODIFY -h $LOCALHOST -p $PORT1 \
165 -D "cn=Manager,$BASEDN" -w secret \
166 >> $TESTOUT 2>&1 << EOF
167 dn: cn=Jessica Rabbit,ou=People,$BASEDN
168 changetype: add
169 objectClass: inetOrgPerson
170 cn: Jessica Rabbit
171 sn: Rabbit
173 dn: cn=Cartoonia,ou=Groups,$BASEDN
174 changetype: modify
175 add: member
176 member: cn=Jessica Rabbit,ou=People,$BASEDN
179 echo "Re-search the entire database..."
180 echo "# Re-search the entire database..." >> $SEARCHOUT
181 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 \
182 '(objectClass=*)' '*' memberOf >> $SEARCHOUT 2>&1
183 RC=$?
184 if test $RC != 0 ; then
185 echo "ldapsearch failed ($RC)!"
186 test $KILLSERVERS != no && kill -HUP $KILLPIDS
187 exit $RC
190 echo "Running ldapmodify to add self..."
191 $LDAPMODIFY -h $LOCALHOST -p $PORT1 \
192 -D "cn=Manager,$BASEDN" -w secret \
193 >> $TESTOUT 2>&1 << EOF
194 dn: cn=Cartoonia,ou=Groups,$BASEDN
195 changetype: modify
196 add: member
197 member: cn=Cartoonia,ou=Groups,$BASEDN
200 echo "Re-search the entire database..."
201 echo "# Re-search the entire database..." >> $SEARCHOUT
202 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 \
203 '(objectClass=*)' '*' memberOf >> $SEARCHOUT 2>&1
204 RC=$?
205 if test $RC != 0 ; then
206 echo "ldapsearch failed ($RC)!"
207 test $KILLSERVERS != no && kill -HUP $KILLPIDS
208 exit $RC
211 echo "Running ldapdelete to remove a member..."
212 $LDAPMODIFY -h $LOCALHOST -p $PORT1 \
213 -D "cn=Manager,$BASEDN" -w secret \
214 >> $TESTOUT 2>&1 << EOF
215 dn: cn=Baby Herman,ou=People,$BASEDN
216 changetype: delete
219 echo "Re-search the entire database..."
220 echo "# Re-search the entire database..." >> $SEARCHOUT
221 $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 \
222 '(objectClass=*)' '*' memberOf >> $SEARCHOUT 2>&1
223 RC=$?
224 if test $RC != 0 ; then
225 echo "ldapsearch failed ($RC)!"
226 test $KILLSERVERS != no && kill -HUP $KILLPIDS
227 exit $RC
230 test $KILLSERVERS != no && kill -HUP $KILLPIDS
232 LDIF=$MEMBEROFOUT
234 echo "Filtering ldapsearch results..."
235 . $LDIFFILTER < $SEARCHOUT > $SEARCHFLT
236 echo "Filtering original ldif used to create database..."
237 . $LDIFFILTER < $LDIF > $LDIFFLT
238 echo "Comparing filter output..."
239 $CMP $SEARCHFLT $LDIFFLT > $CMPOUT
241 if test $? != 0 ; then
242 echo "Comparison failed"
243 exit 1
246 echo ">>>>> Test succeeded"
248 test $KILLSERVERS != no && wait
250 exit 0