1#! /bin/sh 2# OpenLDAP: pkg/ldap/tests/scripts/test057-memberof-refint,v 1.3.2.4 2009/10/30 23:56:26 quanah Exp 3## This work is part of OpenLDAP Software <http://www.openldap.org/>. 4## 5## Copyright 1998-2009 The OpenLDAP Foundation. 6## Portions Copyright 2008 Red Hat, Inc. 7## All rights reserved. 8## 9## Redistribution and use in source and binary forms, with or without 10## modification, are permitted only as authorized by the OpenLDAP 11## Public License. 12## 13## A copy of this license is available in the file LICENSE in the 14## top-level directory of the distribution or, alternatively, at 15## <http://www.OpenLDAP.org/license.html>. 16 17echo "running defines.sh" 18. $SRCDIR/scripts/defines.sh 19 20if test $MEMBEROF = memberofno; then 21 echo "Memberof overlay not available, test skipped" 22 exit 0 23fi 24 25if test $REFINT = refintno; then 26 echo "Referential Integrity overlay not available, test skipped" 27 exit 0 28fi 29 30if test "$BACKEND" != "hdb" ; then 31 echo "Test does not support $BACKEND" 32 exit 0 33fi 34 35mkdir -p $TESTDIR $DBDIR1 $TESTDIR/confdir 36 37$SLAPPASSWD -g -n >$CONFIGPWF 38echo "rootpw `$SLAPPASSWD -T $CONFIGPWF`" >$TESTDIR/configpw.conf 39 40echo "Starting slapd on TCP/IP port $PORT1..." 41. $CONFFILTER $BACKEND $MONITORDB < $NAKEDCONF > $CONF1 42$SLAPD -f $CONF1 -F $TESTDIR/confdir -h $URI1 -d $LVL $TIMING > $LOG1 2>&1 & 43PID=$! 44if test $WAIT != 0 ; then 45 echo PID $PID 46 read foo 47fi 48KILLPIDS="$PID" 49 50sleep 1 51for 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 57 fi 58 echo "Waiting 5 seconds for slapd to start..." 59 sleep 5 60done 61if test $RC != 0 ; then 62 echo "ldapsearch failed ($RC)!" 63 test $KILLSERVERS != no && kill -HUP $KILLPIDS 64 exit $RC 65fi 66 67cat /dev/null > $TESTOUT 68 69if [ "$MEMBEROF" = memberofmod ]; then 70 echo "Inserting memberof overlay on producer..." 71 $LDAPADD -D cn=config -H $URI1 -y $CONFIGPWF <<EOF > $TESTOUT 2>&1 72dn: cn=module,cn=config 73objectClass: olcModuleList 74cn: module 75olcModulePath: ../servers/slapd/overlays 76olcModuleLoad: memberof.la 77olcModuleLoad: refint.la 78EOF 79 RC=$? 80 if test $RC != 0 ; then 81 echo "ldapadd failed for moduleLoad ($RC)!" 82 test $KILLSERVERS != no && kill -HUP $KILLPIDS 83 exit $RC 84 fi 85fi 86 87echo "Running ldapadd to build slapd config database..." 88$LDAPADD -h $LOCALHOST -p $PORT1 -D 'cn=config' -w `cat $CONFIGPWF` \ 89 >> $TESTOUT 2>&1 <<EOF 90dn: olcDatabase={1}$BACKEND,cn=config 91objectClass: olcDatabaseConfig 92objectClass: olc${BACKEND}Config 93olcDatabase: {1}$BACKEND 94olcSuffix: $BASEDN 95olcRootDN: cn=Manager,$BASEDN 96olcRootPW:: c2VjcmV0 97olcMonitoring: TRUE 98olcDbDirectory: $TESTDIR/db.1.a/ 99olcDbCacheSize: 1000 100olcDbIndex: objectClass eq 101olcDbIndex: cn pres,eq,sub 102olcDbIndex: uid pres,eq,sub 103olcDbIndex: sn pres,eq,sub 104olcDbMode: 384 105 106# {0}memberof, {1}$BACKEND, config 107dn: olcOverlay={0}memberof,olcDatabase={1}$BACKEND,cn=config 108objectClass: olcOverlayConfig 109objectClass: olcMemberOf 110olcOverlay: {0}memberof 111olcMemberOfRefInt: TRUE 112olcMemberOfGroupOC: groupOfNames 113olcMemberOfMemberAD: member 114olcMemberOfMemberOfAD: memberOf 115 116# {1}refint, {1}$BACKEND, config 117dn: olcOverlay={1}refint,olcDatabase={1}$BACKEND,cn=config 118objectClass: olcOverlayConfig 119objectClass: olcRefintConfig 120olcOverlay: {1}refint 121olcRefintAttribute: member 122olcRefintAttribute: memberOf 123EOF 124RC=$? 125if test $RC != 0 ; then 126 echo "ldapadd failed ($RC)!" 127 test $KILLSERVERS != no && kill -HUP $KILLPIDS 128 exit $RC 129fi 130 131echo "Running ldapadd to build slapd database..." 132$LDAPADD -h $LOCALHOST -p $PORT1 \ 133 -D "cn=Manager,$BASEDN" -w secret \ 134 >> $TESTOUT 2>&1 << EOF 135dn: $BASEDN 136objectClass: organization 137objectClass: dcObject 138o: Example, Inc. 139dc: example 140 141dn: ou=People,$BASEDN 142objectClass: organizationalUnit 143ou: People 144 145dn: ou=Groups,$BASEDN 146objectClass: organizationalUnit 147ou: Groups 148 149dn: cn=Roger Rabbit,ou=People,$BASEDN 150objectClass: inetOrgPerson 151cn: Roger Rabbit 152sn: Rabbit 153 154dn: cn=Baby Herman,ou=People,$BASEDN 155objectClass: inetOrgPerson 156cn: Baby Herman 157sn: Herman 158 159dn: cn=Cartoonia,ou=Groups,$BASEDN 160objectClass: groupOfNames 161cn: Cartoonia 162member: cn=Roger Rabbit,ou=People,$BASEDN 163member: cn=Baby Herman,ou=People,$BASEDN 164EOF 165RC=$? 166if test $RC != 0 ; then 167 echo "ldapadd failed ($RC)!" 168 test $KILLSERVERS != no && kill -HUP $KILLPIDS 169 exit $RC 170fi 171 172echo "Search the entire database..." 173echo "# Search the entire database..." >> $SEARCHOUT 174$LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 \ 175 '(objectClass=*)' '*' memberOf >> $SEARCHOUT 2>&1 176RC=$? 177if test $RC != 0 ; then 178 echo "ldapsearch failed ($RC)!" 179 test $KILLSERVERS != no && kill -HUP $KILLPIDS 180 exit $RC 181fi 182 183echo "Running ldapmodify to rename subtree..." 184$LDAPMODIFY -h $LOCALHOST -p $PORT1 \ 185 -D "cn=Manager,$BASEDN" -w secret \ 186 >> $TESTOUT 2>&1 << EOF 187dn: ou=People,$BASEDN 188changetype: modrdn 189newrdn: ou=Toons 190deleteoldrdn:1 191newsuperior: $BASEDN 192EOF 193 194# refint runs in a background thread, so it most likely won't complete 195# before the modify returns. Give it some time to execute. 196sleep 1 197 198echo "Re-search the entire database..." 199echo "# Re-search the entire database..." >> $SEARCHOUT 200$LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 \ 201 '(objectClass=*)' '*' memberOf >> $SEARCHOUT 2>&1 202RC=$? 203if test $RC != 0 ; then 204 echo "ldapsearch failed ($RC)!" 205 test $KILLSERVERS != no && kill -HUP $KILLPIDS 206 exit $RC 207fi 208 209echo "Running ldapmodify to rename subtree..." 210$LDAPMODIFY -h $LOCALHOST -p $PORT1 \ 211 -D "cn=Manager,$BASEDN" -w secret \ 212 >> $TESTOUT 2>&1 << EOF 213dn: ou=Groups,$BASEDN 214changetype: modrdn 215newrdn: ou=Studios 216deleteoldrdn:1 217newsuperior: $BASEDN 218EOF 219 220sleep 1 221 222echo "Re-search the entire database..." 223echo "# Re-search the entire database..." >> $SEARCHOUT 224$LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 \ 225 '(objectClass=*)' '*' memberOf >> $SEARCHOUT 2>&1 226RC=$? 227if test $RC != 0 ; then 228 echo "ldapsearch failed ($RC)!" 229 test $KILLSERVERS != no && kill -HUP $KILLPIDS 230 exit $RC 231fi 232 233echo "Running ldapdelete to remove a member..." 234$LDAPMODIFY -h $LOCALHOST -p $PORT1 \ 235 -D "cn=Manager,$BASEDN" -w secret \ 236 >> $TESTOUT 2>&1 << EOF 237dn: cn=Baby Herman,ou=Toons,$BASEDN 238changetype: delete 239EOF 240 241sleep 1 242 243echo "Re-search the entire database..." 244echo "# Re-search the entire database..." >> $SEARCHOUT 245$LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 \ 246 '(objectClass=*)' '*' memberOf >> $SEARCHOUT 2>&1 247RC=$? 248if test $RC != 0 ; then 249 echo "ldapsearch failed ($RC)!" 250 test $KILLSERVERS != no && kill -HUP $KILLPIDS 251 exit $RC 252fi 253 254test $KILLSERVERS != no && kill -HUP $KILLPIDS 255 256LDIF=$MEMBEROFREFINTOUT 257 258echo "Filtering ldapsearch results..." 259. $LDIFFILTER < $SEARCHOUT > $SEARCHFLT 260echo "Filtering original ldif used to create database..." 261. $LDIFFILTER < $LDIF > $LDIFFLT 262echo "Comparing filter output..." 263$CMP $SEARCHFLT $LDIFFLT > $CMPOUT 264 265if test $? != 0 ; then 266 echo "Comparison failed" 267 exit 1 268fi 269 270echo ">>>>> Test succeeded" 271 272test $KILLSERVERS != no && wait 273 274exit 0 275