1#! /bin/sh 2# $OpenLDAP$ 3## This work is part of OpenLDAP Software <http://www.openldap.org/>. 4## 5## Copyright 1998-2020 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 = bdb; then 31 echo "$BACKEND backend does not support subtree rename, test skipped" 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 69indexInclude="" mainInclude="" bdbInclude="# " nullExclude="" 70test $INDEXDB = indexdb || indexInclude="# " 71test $MAINDB = maindb || mainInclude="# " 72case $BACKEND in 73bdb | hdb) bdbInclude="" ;; 74null) nullExclude="# " ;; 75esac 76 77if [ "$MEMBEROF" = memberofmod ]; then 78 echo "Inserting memberof overlay on provider..." 79 $LDAPADD -D cn=config -H $URI1 -y $CONFIGPWF <<EOF > $TESTOUT 2>&1 80dn: cn=module,cn=config 81objectClass: olcModuleList 82cn: module 83olcModulePath: ../servers/slapd/overlays 84olcModuleLoad: memberof.la 85olcModuleLoad: refint.la 86EOF 87 RC=$? 88 if test $RC != 0 ; then 89 echo "ldapadd failed for moduleLoad ($RC)!" 90 test $KILLSERVERS != no && kill -HUP $KILLPIDS 91 exit $RC 92 fi 93fi 94 95echo "Running ldapadd to build slapd config database..." 96$LDAPADD -h $LOCALHOST -p $PORT1 -D 'cn=config' -w `cat $CONFIGPWF` \ 97 >> $TESTOUT 2>&1 <<EOF 98dn: olcDatabase={1}$BACKEND,cn=config 99objectClass: olcDatabaseConfig 100${nullExclude}objectClass: olc${BACKEND}Config 101olcDatabase: {1}$BACKEND 102olcSuffix: $BASEDN 103olcRootDN: cn=Manager,$BASEDN 104olcRootPW:: c2VjcmV0 105olcMonitoring: TRUE 106${nullExclude}olcDbDirectory: $TESTDIR/db.1.a/ 107${bdbInclude}olcDbCacheSize: 1000 108${indexInclude}olcDbIndex: objectClass eq 109${indexInclude}olcDbIndex: cn pres,eq,sub 110${indexInclude}olcDbIndex: uid pres,eq,sub 111${indexInclude}olcDbIndex: sn pres,eq,sub 112${mainInclude}olcDbMode: 384 113 114# {0}memberof, {1}$BACKEND, config 115dn: olcOverlay={0}memberof,olcDatabase={1}$BACKEND,cn=config 116objectClass: olcOverlayConfig 117objectClass: olcMemberOf 118olcOverlay: {0}memberof 119olcMemberOfRefInt: TRUE 120olcMemberOfGroupOC: groupOfNames 121olcMemberOfMemberAD: member 122olcMemberOfMemberOfAD: memberOf 123 124# {1}refint, {1}$BACKEND, config 125dn: olcOverlay={1}refint,olcDatabase={1}$BACKEND,cn=config 126objectClass: olcOverlayConfig 127objectClass: olcRefintConfig 128olcOverlay: {1}refint 129olcRefintAttribute: member 130olcRefintAttribute: memberOf 131EOF 132RC=$? 133if test $RC != 0 ; then 134 echo "ldapadd failed ($RC)!" 135 test $KILLSERVERS != no && kill -HUP $KILLPIDS 136 exit $RC 137fi 138 139echo "Running ldapadd to build slapd database..." 140$LDAPADD -h $LOCALHOST -p $PORT1 \ 141 -D "cn=Manager,$BASEDN" -w secret \ 142 >> $TESTOUT 2>&1 << EOF 143dn: $BASEDN 144objectClass: organization 145objectClass: dcObject 146o: Example, Inc. 147dc: example 148 149dn: ou=People,$BASEDN 150objectClass: organizationalUnit 151ou: People 152 153dn: ou=Groups,$BASEDN 154objectClass: organizationalUnit 155ou: Groups 156 157dn: cn=Roger Rabbit,ou=People,$BASEDN 158objectClass: inetOrgPerson 159cn: Roger Rabbit 160sn: Rabbit 161 162dn: cn=Baby Herman,ou=People,$BASEDN 163objectClass: inetOrgPerson 164cn: Baby Herman 165sn: Herman 166 167dn: cn=Cartoonia,ou=Groups,$BASEDN 168objectClass: groupOfNames 169cn: Cartoonia 170member: cn=Roger Rabbit,ou=People,$BASEDN 171member: cn=Baby Herman,ou=People,$BASEDN 172EOF 173RC=$? 174if test $RC != 0 ; then 175 echo "ldapadd failed ($RC)!" 176 test $KILLSERVERS != no && kill -HUP $KILLPIDS 177 exit $RC 178fi 179 180echo "Search the entire database..." 181echo "# Search the entire database..." >> $SEARCHOUT 182$LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 \ 183 '(objectClass=*)' '*' memberOf >> $SEARCHOUT 2>&1 184RC=$? 185if test $RC != 0 ; then 186 echo "ldapsearch failed ($RC)!" 187 test $KILLSERVERS != no && kill -HUP $KILLPIDS 188 exit $RC 189fi 190 191echo "Running ldapmodify to rename subtree..." 192$LDAPMODIFY -h $LOCALHOST -p $PORT1 \ 193 -D "cn=Manager,$BASEDN" -w secret \ 194 >> $TESTOUT 2>&1 << EOF 195dn: ou=People,$BASEDN 196changetype: modrdn 197newrdn: ou=Toons 198deleteoldrdn:1 199newsuperior: $BASEDN 200EOF 201 202# refint runs in a background thread, so it most likely won't complete 203# before the modify returns. Give it some time to execute. 204sleep $SLEEP0 205 206echo "Re-search the entire database..." 207echo "# Re-search the entire database..." >> $SEARCHOUT 208$LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 \ 209 '(objectClass=*)' '*' memberOf >> $SEARCHOUT 2>&1 210RC=$? 211if test $RC != 0 ; then 212 echo "ldapsearch failed ($RC)!" 213 test $KILLSERVERS != no && kill -HUP $KILLPIDS 214 exit $RC 215fi 216 217echo "Running ldapmodify to rename subtree..." 218$LDAPMODIFY -h $LOCALHOST -p $PORT1 \ 219 -D "cn=Manager,$BASEDN" -w secret \ 220 >> $TESTOUT 2>&1 << EOF 221dn: ou=Groups,$BASEDN 222changetype: modrdn 223newrdn: ou=Studios 224deleteoldrdn:1 225newsuperior: $BASEDN 226EOF 227 228sleep $SLEEP0 229 230echo "Re-search the entire database..." 231echo "# Re-search the entire database..." >> $SEARCHOUT 232$LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 \ 233 '(objectClass=*)' '*' memberOf >> $SEARCHOUT 2>&1 234RC=$? 235if test $RC != 0 ; then 236 echo "ldapsearch failed ($RC)!" 237 test $KILLSERVERS != no && kill -HUP $KILLPIDS 238 exit $RC 239fi 240 241echo "Running ldapdelete to remove a member..." 242$LDAPMODIFY -h $LOCALHOST -p $PORT1 \ 243 -D "cn=Manager,$BASEDN" -w secret \ 244 >> $TESTOUT 2>&1 << EOF 245dn: cn=Baby Herman,ou=Toons,$BASEDN 246changetype: delete 247EOF 248 249sleep $SLEEP0 250 251echo "Re-search the entire database..." 252echo "# Re-search the entire database..." >> $SEARCHOUT 253$LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 \ 254 '(objectClass=*)' '*' memberOf >> $SEARCHOUT 2>&1 255RC=$? 256if test $RC != 0 ; then 257 echo "ldapsearch failed ($RC)!" 258 test $KILLSERVERS != no && kill -HUP $KILLPIDS 259 exit $RC 260fi 261 262test $KILLSERVERS != no && kill -HUP $KILLPIDS 263 264LDIF=$MEMBEROFREFINTOUT 265 266echo "Filtering ldapsearch results..." 267$LDIFFILTER < $SEARCHOUT > $SEARCHFLT 268echo "Filtering original ldif used to create database..." 269$LDIFFILTER < $LDIF > $LDIFFLT 270echo "Comparing filter output..." 271$CMP $SEARCHFLT $LDIFFLT > $CMPOUT 272 273if test $? != 0 ; then 274 echo "Comparison failed" 275 exit 1 276fi 277 278echo ">>>>> Test succeeded" 279 280test $KILLSERVERS != no && wait 281 282exit 0 283