xref: /netbsd-src/external/bsd/openldap/dist/tests/scripts/test052-memberof (revision 76c7fc5f6b13ed0b1508e6b313e88e59977ed78e)
1#! /bin/sh
2# $OpenLDAP$
3## This work is part of OpenLDAP Software <http://www.openldap.org/>.
4##
5## Copyright 1998-2019 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
19if test $MEMBEROF = memberofno; then
20	echo "Memberof overlay not available, test skipped"
21	exit 0
22fi
23
24mkdir -p $TESTDIR $DBDIR1 $TESTDIR/confdir
25
26$SLAPPASSWD -g -n >$CONFIGPWF
27echo "rootpw `$SLAPPASSWD -T $CONFIGPWF`" >$TESTDIR/configpw.conf
28
29echo "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 &
32PID=$!
33if test $WAIT != 0 ; then
34    echo PID $PID
35    read foo
36fi
37KILLPIDS="$PID"
38
39sleep 1
40for 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
46	fi
47	echo "Waiting 5 seconds for slapd to start..."
48	sleep 5
49done
50if test $RC != 0 ; then
51	echo "ldapsearch failed ($RC)!"
52	test $KILLSERVERS != no && kill -HUP $KILLPIDS
53	exit $RC
54fi
55
56cat /dev/null > $TESTOUT
57
58if [ "$MEMBEROF" = memberofmod ]; then
59	echo "Inserting memberof overlay on provider..."
60	$LDAPADD -D cn=config -H $URI1 -y $CONFIGPWF <<EOF > $TESTOUT 2>&1
61dn: cn=module,cn=config
62objectClass: olcModuleList
63cn: module
64olcModulePath: ../servers/slapd/overlays
65olcModuleLoad: memberof.la
66EOF
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
72	fi
73fi
74
75indexInclude="" mainInclude="" bdbInclude="# " nullExclude=""
76test $INDEXDB = indexdb	|| indexInclude="# "
77test $MAINDB  = maindb	|| mainInclude="# "
78case $BACKEND in
79bdb | hdb) bdbInclude="" ;;
80null) nullExclude="# " ;;
81esac
82
83echo "Running ldapadd to build slapd config database..."
84$LDAPADD -h $LOCALHOST -p $PORT1 -D 'cn=config' -w `cat $CONFIGPWF` \
85	>> $TESTOUT 2>&1 <<EOF
86dn: cn=symas group example,cn=schema,cn=config
87objectClass: olcSchemaConfig
88cn: symas group example
89olcAttributeTypes: ( 1.3.6.1.4.1.4754.31.1.1 
90 NAME 'memberA' SUP distinguishedName )
91olcAttributeTypes: ( 1.3.6.1.4.1.4754.31.1.2
92 NAME 'memberOfA' SUP distinguishedName )
93olcAttributeTypes: ( 1.3.6.1.4.1.4754.31.1.3 
94 NAME 'memberB' SUP distinguishedName )
95olcAttributeTypes: ( 1.3.6.1.4.1.4754.31.1.4 
96 NAME 'memberOfB' SUP distinguishedName )
97olcAttributeTypes: ( 1.3.6.1.4.1.4754.31.1.5
98 NAME 'memberOfC' SUP distinguishedName )
99olcObjectClasses: ( 1.3.6.1.4.1.4754.31.2.1 
100 NAME 'groupA' SUP top STRUCTURAL MUST cn MAY memberA )
101olcObjectClasses: ( 1.3.6.1.4.1.4754.31.2.2 
102 NAME 'groupMemberA' SUP top AUXILIARY MAY ( memberOfA $ memberOfC ) )
103olcObjectClasses: ( 1.3.6.1.4.1.4754.31.2.3 
104 NAME 'groupB' SUP top STRUCTURAL MUST cn MAY memberB )
105olcObjectClasses: ( 1.3.6.1.4.1.4754.31.2.4 
106 NAME 'groupMemberB' SUP top AUXILIARY MAY memberOfB )
107
108dn: olcDatabase={1}$BACKEND,cn=config
109objectClass: olcDatabaseConfig
110${nullExclude}objectClass: olc${BACKEND}Config
111olcDatabase: {1}$BACKEND
112olcSuffix: $BASEDN
113olcRootDN: cn=Manager,$BASEDN
114olcRootPW:: c2VjcmV0
115olcMonitoring: TRUE
116${nullExclude}olcDbDirectory: $TESTDIR/db.1.a/
117${bdbInclude}olcDbCacheSize: 1000
118${indexInclude}olcDbIndex: objectClass eq
119${indexInclude}olcDbIndex: cn pres,eq,sub
120${indexInclude}olcDbIndex: uid pres,eq,sub
121${indexInclude}olcDbIndex: sn pres,eq,sub
122${mainInclude}olcDbMode: 384"
123
124dn: olcOverlay={0}memberof,olcDatabase={1}$BACKEND,cn=config
125objectClass: olcOverlayConfig
126objectClass: olcMemberOf
127olcOverlay: {0}memberof
128olcMemberOfRefInt: TRUE
129olcMemberOfGroupOC: groupOfNames
130olcMemberOfMemberAD: member
131olcMemberOfMemberOfAD: memberOf
132
133dn: olcOverlay={1}memberof,olcDatabase={1}$BACKEND,cn=config
134objectClass: olcOverlayConfig
135objectClass: olcMemberOf
136olcOverlay: {1}memberof
137olcMemberOfRefInt: TRUE
138olcMemberOfGroupOC: groupA
139olcMemberOfMemberAD: memberA
140olcMemberOfMemberOfAD: memberOfA
141
142dn: olcOverlay={2}memberof,olcDatabase={1}$BACKEND,cn=config
143objectClass: olcOverlayConfig
144objectClass: olcMemberOf
145olcOverlay: {2}memberof
146olcMemberOfRefInt: TRUE
147olcMemberOfGroupOC: groupB
148olcMemberOfMemberAD: memberB
149olcMemberOfMemberOfAD: memberOfB
150
151EOF
152RC=$?
153if test $RC != 0 ; then
154	echo "ldapadd failed ($RC)!"
155	test $KILLSERVERS != no && kill -HUP $KILLPIDS
156	exit $RC
157fi
158
159echo "Running ldapadd to build slapd database..."
160$LDAPADD -h $LOCALHOST -p $PORT1 \
161	-D "cn=Manager,$BASEDN" -w secret \
162	>> $TESTOUT 2>&1 << EOF
163dn: $BASEDN
164objectClass: organization
165objectClass: dcObject
166o: Example, Inc.
167dc: example
168
169dn: ou=People,$BASEDN
170objectClass: organizationalUnit
171ou: People
172
173dn: ou=Groups,$BASEDN
174objectClass: organizationalUnit
175ou: Groups
176
177dn: cn=Roger Rabbit,ou=People,$BASEDN
178objectClass: inetOrgPerson
179cn: Roger Rabbit
180sn: Rabbit
181
182dn: cn=Baby Herman,ou=People,$BASEDN
183objectClass: inetOrgPerson
184cn: Baby Herman
185sn: Herman
186
187dn: cn=Cartoonia,ou=Groups,$BASEDN
188objectClass: groupOfNames
189cn: Cartoonia
190member: cn=Roger Rabbit,ou=People,$BASEDN
191member: cn=Baby Herman,ou=People,$BASEDN
192EOF
193RC=$?
194if test $RC != 0 ; then
195	echo "ldapadd failed ($RC)!"
196	test $KILLSERVERS != no && kill -HUP $KILLPIDS
197	exit $RC
198fi
199
200echo "Search the entire database..."
201echo "# Search the entire database..." >> $SEARCHOUT
202$LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 \
203	'(objectClass=*)' '*' memberOf >> $SEARCHOUT 2>&1
204RC=$?
205if test $RC != 0 ; then
206	echo "ldapsearch failed ($RC)!"
207	test $KILLSERVERS != no && kill -HUP $KILLPIDS
208	exit $RC
209fi
210
211echo "Running ldapmodify to add a member..."
212$LDAPMODIFY -h $LOCALHOST -p $PORT1 \
213	-D "cn=Manager,$BASEDN" -w secret \
214	>> $TESTOUT 2>&1 << EOF
215dn: cn=Jessica Rabbit,ou=People,$BASEDN
216changetype: add
217objectClass: inetOrgPerson
218cn: Jessica Rabbit
219sn: Rabbit
220
221dn: cn=Cartoonia,ou=Groups,$BASEDN
222changetype: modify
223add: member
224member: cn=Jessica Rabbit,ou=People,$BASEDN
225EOF
226
227echo "Re-search the entire database..."
228echo "# Re-search the entire database after adding Jessica Rabbit and Cartoonia..." >> $SEARCHOUT
229$LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 \
230	'(objectClass=*)' '*' memberOf >> $SEARCHOUT 2>&1
231RC=$?
232if test $RC != 0 ; then
233	echo "ldapsearch failed ($RC)!"
234	test $KILLSERVERS != no && kill -HUP $KILLPIDS
235	exit $RC
236fi
237
238echo "Running ldapmodify to rename a member..."
239$LDAPMODIFY -h $LOCALHOST -p $PORT1 \
240	-D "cn=Manager,$BASEDN" -w secret \
241	>> $TESTOUT 2>&1 << EOF
242dn: cn=Baby Herman,ou=People,$BASEDN
243changetype: modrdn
244newrdn: cn=Baby Herman Jr
245deleteoldrdn: 1
246EOF
247
248echo "Re-search the entire database..."
249echo "# Re-search the entire database after renaming Baby Herman..." >> $SEARCHOUT
250$LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 \
251	'(objectClass=*)' '*' memberOf >> $SEARCHOUT 2>&1
252RC=$?
253if test $RC != 0 ; then
254	echo "ldapsearch failed ($RC)!"
255	test $KILLSERVERS != no && kill -HUP $KILLPIDS
256	exit $RC
257fi
258
259echo "Running ldapmodify to rename a group..."
260$LDAPMODIFY -h $LOCALHOST -p $PORT1 \
261	-D "cn=Manager,$BASEDN" -w secret \
262	>> $TESTOUT 2>&1 << EOF
263dn: cn=Cartoonia,ou=Groups,$BASEDN
264changetype: modrdn
265newrdn: cn=Toon town
266deleteoldrdn: 1
267
268dn: cn=Toon town,ou=Groups,$BASEDN
269changetype: modrdn
270newrdn: cn=Toon Town
271deleteoldrdn: 1
272EOF
273
274echo "Re-search the entire database..."
275echo "# Re-search the entire database after renaming Cartoonia..." >> $SEARCHOUT
276$LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 \
277	'(objectClass=*)' '*' memberOf >> $SEARCHOUT 2>&1
278RC=$?
279if test $RC != 0 ; then
280	echo "ldapsearch failed ($RC)!"
281	test $KILLSERVERS != no && kill -HUP $KILLPIDS
282	exit $RC
283fi
284
285echo "Running ldapmodify to add self..."
286$LDAPMODIFY -h $LOCALHOST -p $PORT1 \
287	-D "cn=Manager,$BASEDN" -w secret \
288	>> $TESTOUT 2>&1 << EOF
289dn: cn=Toon Town,ou=Groups,$BASEDN
290changetype: modify
291add: member
292member: cn=Toon Town,ou=Groups,$BASEDN
293EOF
294
295echo "Re-search the entire database..."
296echo "# Re-search the entire database after adding Toon Town to self..." >> $SEARCHOUT
297$LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 \
298	'(objectClass=*)' '*' memberOf >> $SEARCHOUT 2>&1
299RC=$?
300if test $RC != 0 ; then
301	echo "ldapsearch failed ($RC)!"
302	test $KILLSERVERS != no && kill -HUP $KILLPIDS
303	exit $RC
304fi
305
306echo "Running ldapdelete to remove a member..."
307$LDAPMODIFY -h $LOCALHOST -p $PORT1 \
308	-D "cn=Manager,$BASEDN" -w secret \
309	>> $TESTOUT 2>&1 << EOF
310dn: cn=Baby Herman Jr,ou=People,$BASEDN
311changetype: delete
312EOF
313
314echo "Re-search the entire database..."
315echo "# Re-search the entire database after deleting Baby Herman..." >> $SEARCHOUT
316$LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 \
317	'(objectClass=*)' '*' memberOf >> $SEARCHOUT 2>&1
318RC=$?
319if test $RC != 0 ; then
320	echo "ldapsearch failed ($RC)!"
321	test $KILLSERVERS != no && kill -HUP $KILLPIDS
322	exit $RC
323fi
324
325echo "Running ldapdelete to remove a group..."
326$LDAPMODIFY -h $LOCALHOST -p $PORT1 \
327	-D "cn=Manager,$BASEDN" -w secret \
328	>> $TESTOUT 2>&1 << EOF
329dn: cn=Toon Town,ou=Groups,$BASEDN
330changetype: delete
331EOF
332
333echo "Re-search the entire database..."
334echo "# Re-search the entire database after deleting Toon Town..." >> $SEARCHOUT
335$LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 \
336	'(objectClass=*)' '*' memberOf >> $SEARCHOUT 2>&1
337RC=$?
338if test $RC != 0 ; then
339	echo "ldapsearch failed ($RC)!"
340	test $KILLSERVERS != no && kill -HUP $KILLPIDS
341	exit $RC
342fi
343
344echo "Adding groups with MAY member type schemas..."
345$LDAPMODIFY -h $LOCALHOST -p $PORT1 \
346	-D "cn=Manager,$BASEDN" -w secret \
347	>> $TESTOUT 2>&1 <<EOF
348dn: cn=Roger Rabbit,ou=People,$BASEDN
349changetype: delete
350
351dn: cn=Jessica Rabbit,ou=People,$BASEDN
352changetype: delete
353
354dn: cn=person1,ou=People,$BASEDN
355changetype: add
356objectClass: person
357objectClass: groupMemberA
358objectClass: groupMemberB
359cn: person1
360sn: person1
361
362dn: cn=person2,ou=People,$BASEDN
363changetype: add
364objectClass: person
365objectClass: groupMemberA
366objectClass: groupMemberB
367cn: person2
368sn: person2
369
370dn: cn=group1,ou=Groups,$BASEDN
371changetype: add
372objectclass: groupA
373cn: group1
374memberA: cn=person1,ou=People,$BASEDN
375memberA: cn=person2,ou=People,$BASEDN
376
377dn: cn=group2,ou=Groups,$BASEDN
378changetype: add
379objectclass: groupB
380cn: group2
381memberB: cn=person1,ou=People,$BASEDN
382memberB: cn=person2,ou=People,$BASEDN
383
384dn: cn=group1,ou=Groups,$BASEDN
385changetype: modify
386delete: memberA
387
388EOF
389
390echo "Re-search the entire database..."
391echo "# Re-search the entire database after adding groups with MAY member type schemas..." >> $SEARCHOUT
392$LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 \
393	'(objectClass=*)' '*' memberOf >> $SEARCHOUT 2>&1
394RC=$?
395if test $RC != 0 ; then
396	echo "ldapsearch failed ($RC)!"
397	test $KILLSERVERS != no && kill -HUP $KILLPIDS
398	exit $RC
399fi
400
401echo "Running ldapmodify to reconfigure the schema used..."
402$LDAPADD -h $LOCALHOST -p $PORT1 -D 'cn=config' -w `cat $CONFIGPWF` \
403	>> $TESTOUT 2>&1 <<EOF
404dn: olcOverlay={1}memberof,olcDatabase={1}$BACKEND,cn=config
405changetype: modify
406replace: olcMemberOfMemberOfAD
407olcMemberOfMemberOfAD: memberOfC
408
409EOF
410RC=$?
411if test $RC != 0 ; then
412	echo "ldapadd failed ($RC)!"
413	test $KILLSERVERS != no && kill -HUP $KILLPIDS
414	exit $RC
415fi
416
417echo "Updating groups to expose the new setting..."
418$LDAPMODIFY -h $LOCALHOST -p $PORT1 \
419	-D "cn=Manager,$BASEDN" -w secret \
420	>> $TESTOUT 2>&1 <<EOF
421dn: cn=group1,ou=Groups,$BASEDN
422changetype: modify
423add: memberA
424memberA: cn=person1,ou=People,$BASEDN
425memberA: cn=person2,ou=People,$BASEDN
426
427EOF
428RC=$?
429if test $RC != 0 ; then
430	echo "ldapmodify failed ($RC)!"
431	test $KILLSERVERS != no && kill -HUP $KILLPIDS
432	exit $RC
433fi
434
435echo "Re-search the entire database..."
436echo "# Re-search the entire database after updating memberof configuration..." >> $SEARCHOUT
437$LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 \
438	'(objectClass=*)' '*' memberOf >> $SEARCHOUT 2>&1
439RC=$?
440if test $RC != 0 ; then
441	echo "ldapsearch failed ($RC)!"
442	test $KILLSERVERS != no && kill -HUP $KILLPIDS
443	exit $RC
444fi
445
446test $KILLSERVERS != no && kill -HUP $KILLPIDS
447
448LDIF=$MEMBEROFOUT
449
450echo "Filtering ldapsearch results..."
451$LDIFFILTER < $SEARCHOUT > $SEARCHFLT
452echo "Filtering original ldif used to create database..."
453$LDIFFILTER < $LDIF > $LDIFFLT
454echo "Comparing filter output..."
455$CMP $SEARCHFLT $LDIFFLT > $CMPOUT
456
457if test $? != 0 ; then
458	echo "Comparison failed"
459	exit 1
460fi
461
462echo ">>>>> Test succeeded"
463
464test $KILLSERVERS != no && wait
465
466exit 0
467