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/>.
5 ## Copyright 1998-2008 The OpenLDAP Foundation.
6 ## All rights reserved.
8 ## Redistribution and use in source and binary forms, with or without
9 ## modification, are permitted only as authorized by the OpenLDAP
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"
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 &
33 if test $WAIT != 0 ; then
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
44 if test $RC = 0 ; then
47 echo "Waiting 5 seconds for slapd to start..."
50 if test $RC != 0 ; then
51 echo "ldapsearch failed ($RC)!"
52 test $KILLSERVERS != no
&& kill -HUP $KILLPIDS
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
64 olcModulePath: ../servers/slapd/overlays
65 olcModuleLoad: memberof.la
68 if test $RC != 0 ; then
69 echo "ldapadd failed for moduleLoad ($RC)!"
70 test $KILLSERVERS != no
&& kill -HUP $KILLPIDS
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
83 olcRootDN: cn=Manager,$BASEDN
86 olcDbDirectory: $TESTDIR/db.1.a/
88 olcDbIndex: objectClass eq
89 olcDbIndex: cn pres,eq,sub
90 olcDbIndex: uid pres,eq,sub
91 olcDbIndex: sn pres,eq,sub
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
105 if test $RC != 0 ; then
106 echo "ldapadd failed ($RC)!"
107 test $KILLSERVERS != no
&& kill -HUP $KILLPIDS
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
116 objectClass: organization
117 objectClass: dcObject
121 dn: ou=People,$BASEDN
122 objectClass: organizationalUnit
125 dn: ou=Groups,$BASEDN
126 objectClass: organizationalUnit
129 dn: cn=Roger Rabbit,ou=People,$BASEDN
130 objectClass: inetOrgPerson
134 dn: cn=Baby Herman,ou=People,$BASEDN
135 objectClass: inetOrgPerson
139 dn: cn=Cartoonia,ou=Groups,$BASEDN
140 objectClass: groupOfNames
142 member: cn=Roger Rabbit,ou=People,$BASEDN
143 member: cn=Baby Herman,ou=People,$BASEDN
146 if test $RC != 0 ; then
147 echo "ldapadd failed ($RC)!"
148 test $KILLSERVERS != no
&& kill -HUP $KILLPIDS
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
157 if test $RC != 0 ; then
158 echo "ldapsearch failed ($RC)!"
159 test $KILLSERVERS != no
&& kill -HUP $KILLPIDS
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
169 objectClass: inetOrgPerson
173 dn: cn=Cartoonia,ou=Groups,$BASEDN
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
184 if test $RC != 0 ; then
185 echo "ldapsearch failed ($RC)!"
186 test $KILLSERVERS != no
&& kill -HUP $KILLPIDS
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
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
205 if test $RC != 0 ; then
206 echo "ldapsearch failed ($RC)!"
207 test $KILLSERVERS != no
&& kill -HUP $KILLPIDS
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
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
224 if test $RC != 0 ; then
225 echo "ldapsearch failed ($RC)!"
226 test $KILLSERVERS != no
&& kill -HUP $KILLPIDS
230 test $KILLSERVERS != no
&& kill -HUP $KILLPIDS
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"
246 echo ">>>>> Test succeeded"
248 test $KILLSERVERS != no
&& wait