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. 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 producer..." 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 75echo "Running ldapadd to build slapd config database..." 76$LDAPADD -h $LOCALHOST -p $PORT1 -D 'cn=config' -w `cat $CONFIGPWF` \ 77 >> $TESTOUT 2>&1 <<EOF 78dn: olcDatabase={1}$BACKEND,cn=config 79objectClass: olcDatabaseConfig 80objectClass: olc${BACKEND}Config 81olcDatabase: {1}$BACKEND 82olcSuffix: $BASEDN 83olcRootDN: cn=Manager,$BASEDN 84olcRootPW:: c2VjcmV0 85olcMonitoring: TRUE 86olcDbDirectory: $TESTDIR/db.1.a/ 87olcDbCacheSize: 1000 88olcDbIndex: objectClass eq 89olcDbIndex: cn pres,eq,sub 90olcDbIndex: uid pres,eq,sub 91olcDbIndex: sn pres,eq,sub 92olcDbMode: 384 93 94# {0}memberof, {1}$BACKEND, config 95dn: olcOverlay={0}memberof,olcDatabase={1}$BACKEND,cn=config 96objectClass: olcOverlayConfig 97objectClass: olcMemberOf 98olcOverlay: {0}memberof 99olcMemberOfRefInt: TRUE 100olcMemberOfGroupOC: groupOfNames 101olcMemberOfMemberAD: member 102olcMemberOfMemberOfAD: memberOf 103EOF 104RC=$? 105if test $RC != 0 ; then 106 echo "ldapadd failed ($RC)!" 107 test $KILLSERVERS != no && kill -HUP $KILLPIDS 108 exit $RC 109fi 110 111echo "Running ldapadd to build slapd database..." 112$LDAPADD -h $LOCALHOST -p $PORT1 \ 113 -D "cn=Manager,$BASEDN" -w secret \ 114 >> $TESTOUT 2>&1 << EOF 115dn: $BASEDN 116objectClass: organization 117objectClass: dcObject 118o: Example, Inc. 119dc: example 120 121dn: ou=People,$BASEDN 122objectClass: organizationalUnit 123ou: People 124 125dn: ou=Groups,$BASEDN 126objectClass: organizationalUnit 127ou: Groups 128 129dn: cn=Roger Rabbit,ou=People,$BASEDN 130objectClass: inetOrgPerson 131cn: Roger Rabbit 132sn: Rabbit 133 134dn: cn=Baby Herman,ou=People,$BASEDN 135objectClass: inetOrgPerson 136cn: Baby Herman 137sn: Herman 138 139dn: cn=Cartoonia,ou=Groups,$BASEDN 140objectClass: groupOfNames 141cn: Cartoonia 142member: cn=Roger Rabbit,ou=People,$BASEDN 143member: cn=Baby Herman,ou=People,$BASEDN 144EOF 145RC=$? 146if test $RC != 0 ; then 147 echo "ldapadd failed ($RC)!" 148 test $KILLSERVERS != no && kill -HUP $KILLPIDS 149 exit $RC 150fi 151 152echo "Search the entire database..." 153echo "# Search the entire database..." >> $SEARCHOUT 154$LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 \ 155 '(objectClass=*)' '*' memberOf >> $SEARCHOUT 2>&1 156RC=$? 157if test $RC != 0 ; then 158 echo "ldapsearch failed ($RC)!" 159 test $KILLSERVERS != no && kill -HUP $KILLPIDS 160 exit $RC 161fi 162 163echo "Running ldapmodify to add a member..." 164$LDAPMODIFY -h $LOCALHOST -p $PORT1 \ 165 -D "cn=Manager,$BASEDN" -w secret \ 166 >> $TESTOUT 2>&1 << EOF 167dn: cn=Jessica Rabbit,ou=People,$BASEDN 168changetype: add 169objectClass: inetOrgPerson 170cn: Jessica Rabbit 171sn: Rabbit 172 173dn: cn=Cartoonia,ou=Groups,$BASEDN 174changetype: modify 175add: member 176member: cn=Jessica Rabbit,ou=People,$BASEDN 177EOF 178 179echo "Re-search the entire database..." 180echo "# Re-search the entire database..." >> $SEARCHOUT 181$LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 \ 182 '(objectClass=*)' '*' memberOf >> $SEARCHOUT 2>&1 183RC=$? 184if test $RC != 0 ; then 185 echo "ldapsearch failed ($RC)!" 186 test $KILLSERVERS != no && kill -HUP $KILLPIDS 187 exit $RC 188fi 189 190echo "Running ldapmodify to add self..." 191$LDAPMODIFY -h $LOCALHOST -p $PORT1 \ 192 -D "cn=Manager,$BASEDN" -w secret \ 193 >> $TESTOUT 2>&1 << EOF 194dn: cn=Cartoonia,ou=Groups,$BASEDN 195changetype: modify 196add: member 197member: cn=Cartoonia,ou=Groups,$BASEDN 198EOF 199 200echo "Re-search the entire database..." 201echo "# Re-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 ldapdelete to remove a member..." 212$LDAPMODIFY -h $LOCALHOST -p $PORT1 \ 213 -D "cn=Manager,$BASEDN" -w secret \ 214 >> $TESTOUT 2>&1 << EOF 215dn: cn=Baby Herman,ou=People,$BASEDN 216changetype: delete 217EOF 218 219echo "Re-search the entire database..." 220echo "# Re-search the entire database..." >> $SEARCHOUT 221$LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 \ 222 '(objectClass=*)' '*' memberOf >> $SEARCHOUT 2>&1 223RC=$? 224if test $RC != 0 ; then 225 echo "ldapsearch failed ($RC)!" 226 test $KILLSERVERS != no && kill -HUP $KILLPIDS 227 exit $RC 228fi 229 230test $KILLSERVERS != no && kill -HUP $KILLPIDS 231 232LDIF=$MEMBEROFOUT 233 234echo "Filtering ldapsearch results..." 235. $LDIFFILTER < $SEARCHOUT > $SEARCHFLT 236echo "Filtering original ldif used to create database..." 237. $LDIFFILTER < $LDIF > $LDIFFLT 238echo "Comparing filter output..." 239$CMP $SEARCHFLT $LDIFFLT > $CMPOUT 240 241if test $? != 0 ; then 242 echo "Comparison failed" 243 exit 1 244fi 245 246echo ">>>>> Test succeeded" 247 248test $KILLSERVERS != no && wait 249 250exit 0 251