1#! /bin/sh 2# OpenLDAP: pkg/ldap/tests/scripts/test032-chain,v 1.11.2.5 2009/01/22 00:01:19 kurt Exp 3## This work is part of OpenLDAP Software <http://www.openldap.org/>. 4## 5## Copyright 1998-2009 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 $BACKLDAP = "ldapno" ; then 20 echo "LDAP backend not available, test skipped" 21 exit 0 22fi 23 24rm -rf $TESTDIR 25 26mkdir -p $TESTDIR $DBDIR1 $DBDIR2 27 28echo "Running slapadd to build slapd database..." 29. $CONFFILTER $BACKEND $MONITORDB < $CHAINCONF1 > $ADDCONF 30. $CONFFILTER < $LDIFCHAIN1 > $SEARCHOUT 31$SLAPADD -f $ADDCONF -l $SEARCHOUT 32RC=$? 33if test $RC != 0 ; then 34 echo "slapadd 1 failed ($RC)!" 35 exit $RC 36fi 37 38. $CONFFILTER $BACKEND $MONITORDB < $CHAINCONF2 > $ADDCONF 39. $CONFFILTER < $LDIFCHAIN2 > $SEARCHOUT 40$SLAPADD -f $ADDCONF -l $SEARCHOUT 41RC=$? 42if test $RC != 0 ; then 43 echo "slapadd 2 failed ($RC)!" 44 exit $RC 45fi 46 47echo "Starting first slapd on TCP/IP port $PORT1..." 48. $CONFFILTER $BACKEND $MONITORDB < $CHAINCONF1 > $CONF1 49$SLAPD -f $CONF1 -h $URI1 -d $LVL $TIMING > $LOG1 2>&1 & 50PID1=$! 51if test $WAIT != 0 ; then 52 echo PID $PID1 53 read foo 54fi 55KILLPIDS="$PID1" 56 57echo "Starting second slapd on TCP/IP port $PORT2..." 58. $CONFFILTER $BACKEND $MONITORDB < $CHAINCONF2 > $CONF2 59$SLAPD -f $CONF2 -h $URI2 -d $LVL $TIMING > $LOG2 2>&1 & 60PID2=$! 61if test $WAIT != 0 ; then 62 echo PID $PID2 63 read foo 64fi 65 66KILLPIDS="$KILLPIDS $PID2" 67 68sleep 1 69 70echo "Using ldapsearch to check that first slapd is running..." 71for i in 0 1 2 3 4 5; do 72 $LDAPSEARCH -s base -b "$MONITOR" -h $LOCALHOST -p $PORT1 \ 73 'objectclass=*' > /dev/null 2>&1 74 RC=$? 75 if test $RC = 0 ; then 76 break 77 fi 78 echo "Waiting 5 seconds for slapd to start..." 79 sleep 5 80done 81 82if test $RC != 0 ; then 83 echo "ldapsearch failed ($RC)!" 84 test $KILLSERVERS != no && kill -HUP $KILLPIDS 85 exit $RC 86fi 87 88echo "Using ldapsearch to check that second slapd is running..." 89for i in 0 1 2 3 4 5; do 90 $LDAPSEARCH -s base -b "$MONITOR" -h $LOCALHOST -p $PORT2 \ 91 'objectclass=*' > /dev/null 2>&1 92 RC=$? 93 if test $RC = 0 ; then 94 break 95 fi 96 echo "Waiting 5 seconds for slapd to start..." 97 sleep 5 98done 99 100if test $RC != 0 ; then 101 echo "ldapsearch failed ($RC)!" 102 test $KILLSERVERS != no && kill -HUP $KILLPIDS 103 exit $RC 104fi 105 106for P in $PORT1 $PORT2 ; do 107 echo "Testing ldapsearch as anonymous for \"$BASEDN\" on port $P..." 108 $LDAPSEARCH -h $LOCALHOST -p $P -b "$BASEDN" -S "" \ 109 > $SEARCHOUT 2>&1 110 111 RC=$? 112 if test $RC != 0 ; then 113 echo "ldapsearch failed ($RC)!" 114 test $KILLSERVERS != no && kill -HUP $KILLPIDS 115 exit $RC 116 fi 117 118 echo "Filtering ldapsearch results..." 119 . $LDIFFILTER < $SEARCHOUT > $SEARCHFLT 120 echo "Filtering original ldif used to create database..." 121 . $LDIFFILTER < $CHAINOUT > $LDIFFLT 122 echo "Comparing filter output..." 123 $CMP $SEARCHFLT $LDIFFLT > $CMPOUT 124 125 if test $? != 0 ; then 126 echo "comparison failed - chained search didn't succeed" 127 test $KILLSERVERS != no && kill -HUP $KILLPIDS 128 exit 1 129 fi 130 131 echo "Reading the referral entry \"ou=Other,$BASEDN\" as anonymous on port $P..." 132 $LDAPSEARCH -h $LOCALHOST -p $P -b "ou=Other,$BASEDN" -S "" \ 133 > $SEARCHOUT 2>&1 134 135 RC=$? 136 if test $RC != 0 ; then 137 echo "ldapsearch failed ($RC)!" 138 test $KILLSERVERS != no && kill -HUP $KILLPIDS 139 exit $RC 140 fi 141 142 echo "Filtering ldapsearch results..." 143 . $LDIFFILTER < $SEARCHOUT > $SEARCHFLT 144 echo "Filtering original ldif used to create database..." 145 . $LDIFFILTER < $CHAINREFOUT > $LDIFFLT 146 echo "Comparing filter output..." 147 $CMP $SEARCHFLT $LDIFFLT > $CMPOUT 148 149 if test $? != 0 ; then 150 echo "comparison failed - chained search didn't succeed" 151 test $KILLSERVERS != no && kill -HUP $KILLPIDS 152 exit 1 153 fi 154 155 DN="cn=Mark Elliot,ou=Alumni Association,ou=People,$BASEDN" 156 echo "Comparing \"$DN\" on port $P..." 157 $LDAPCOMPARE -h $LOCALHOST -p $P "$DN" "cn:Mark Elliot" \ 158 > $TESTOUT 2>&1 159 160 RC=$? 161 if test $RC != 6 ; then 162 echo "ldapcompare failed ($RC)!" 163 test $KILLSERVERS != no && kill -HUP $KILLPIDS 164 exit $RC 165 fi 166 167 DN="ou=Other,$BASEDN" 168 echo "Comparing \"$DN\" on port $P with manageDSAit control..." 169 $LDAPCOMPARE -h $LOCALHOST -p $P -M "$DN" "ou:Other" \ 170 > $TESTOUT 2>&1 171 172 RC=$? 173 if test $RC != 6 ; then 174 echo "ldapcompare failed ($RC)!" 175 test $KILLSERVERS != no && kill -HUP $KILLPIDS 176 exit $RC 177 fi 178done 179 180# 181# Testing writes to first server 182# 183echo "Writing to first server with scope on second server..." 184$LDAPMODIFY -v -D "$MANAGERDN" -h $LOCALHOST -p $PORT1 -w $PASSWD > \ 185 $TESTOUT 2>&1 << EOMODS 186dn: cn=New Group,ou=Groups,dc=example,dc=com 187changetype: add 188objectClass: groupOfNames 189cn: New Group 190member: 191 192dn: cn=New Group,ou=Groups,dc=example,dc=com 193changetype: modify 194add: description 195description: testing chain overlay writes... 196- 197replace: member 198member: cn=New Group,ou=Groups,dc=example,dc=com 199member: cn=Manager,dc=example,dc=com 200- 201add: owner 202owner: cn=Manager,dc=example,dc=com 203- 204 205dn: cn=New Group,ou=Groups,dc=example,dc=com 206changetype: modrdn 207newrdn: cn=Renamed Group 208deleteoldrdn: 1 209 210dn: cn=All Staff,ou=Groups,dc=example,dc=com 211changetype: delete 212EOMODS 213 214RC=$? 215if test $RC != 0 ; then 216 echo "ldapmodify failed ($RC)!" 217 test $KILLSERVERS != no && kill -HUP $KILLPIDS 218 exit $RC 219fi 220 221# 222# Testing writes to second server 223# 224echo "Writing to second server with scope on first server..." 225$LDAPMODIFY -v -D "$MANAGERDN" -h $LOCALHOST -p $PORT2 -w $PASSWD > \ 226 $TESTOUT 2>&1 << EOMODS 227dn: cn=New User,ou=People,dc=example,dc=com 228changetype: add 229objectClass: person 230cn: New User 231sn: User 232seeAlso: cn=New Group,ou=Groups,dc=example,dc=com 233 234dn: cn=New User,ou=People,dc=example,dc=com 235changetype: modify 236add: description 237description: testing chain overlay writes... 238- 239replace: seeAlso 240seeAlso: cn=Renamed Group,ou=Groups,dc=example,dc=com 241- 242 243dn: cn=New User,ou=People,dc=example,dc=com 244changetype: modrdn 245newrdn: cn=Renamed User 246deleteoldrdn: 1 247 248dn: cn=Ursula Hampster,ou=Alumni Association,ou=People,dc=example,dc=com 249changetype: delete 250EOMODS 251 252RC=$? 253if test $RC != 0 ; then 254 echo "ldapmodify failed ($RC)!" 255 test $KILLSERVERS != no && kill -HUP $KILLPIDS 256 exit $RC 257fi 258 259for P in $PORT1 $PORT2 ; do 260 echo "Testing ldapsearch as anonymous for \"$BASEDN\" on port $P..." 261 $LDAPSEARCH -h $LOCALHOST -p $P -b "$BASEDN" -S "" \ 262 > $SEARCHOUT 2>&1 263 264 RC=$? 265 if test $RC != 0 ; then 266 echo "ldapsearch failed ($RC)!" 267 test $KILLSERVERS != no && kill -HUP $KILLPIDS 268 exit $RC 269 fi 270 271 echo "Filtering ldapsearch results..." 272 . $LDIFFILTER < $SEARCHOUT > $SEARCHFLT 273 echo "Filtering original ldif used to create database..." 274 . $LDIFFILTER < $CHAINMODOUT > $LDIFFLT 275 echo "Comparing filter output..." 276 $CMP $SEARCHFLT $LDIFFLT > $CMPOUT 277 278 if test $? != 0 ; then 279 echo "comparison failed - chained search didn't succeed" 280 test $KILLSERVERS != no && kill -HUP $KILLPIDS 281 exit 1 282 fi 283done 284 285NEWPW=newsecret 286echo "Using ldappasswd on second server with scope on first server..." 287$LDAPPASSWD -h $LOCALHOST -p $PORT2 \ 288 -w secret -s $NEWPW \ 289 -D "$MANAGERDN" "$BJORNSDN" >> $TESTOUT 2>&1 290RC=$? 291if test $RC != 0 ; then 292 echo "ldappasswd failed ($RC)!" 293 test $KILLSERVERS != no && kill -HUP $KILLPIDS 294 exit $RC 295fi 296 297echo "Binding with newly changed password on first server..." 298$LDAPWHOAMI -h $LOCALHOST -p $PORT1 \ 299 -D "$BJORNSDN" -w $NEWPW 300RC=$? 301if test $RC != 0 ; then 302 echo "ldapwhoami failed ($RC)!" 303 test $KILLSERVERS != no && kill -HUP $KILLPIDS 304 exit $RC 305fi 306 307# ITS#57?? 308$LDAPADD -h $LOCALHOST -p $PORT1 \ 309 -D "$MANAGERDN" -w secret \ 310 >> $TESTOUT 2>&1 \ 311 << EOMODS 312dn: ou=Can't Contact,dc=example,dc=com 313changetype: add 314objectclass: referral 315objectclass: extensibleobject 316ou: Can't Contact 317# invalid URI to test broken connectivity handling (search only) 318ref: ${URI3}ou=Can't%20Contact,dc=example,dc=com 319EOMODS 320 321echo "Reading the referral entry \"ou=Can't Contact,$BASEDN\" as anonymous on port $PORT1..." 322$LDAPSEARCH -h $LOCALHOST -p $PORT1 -b "$BASEDN" -S "" "(cn=Can't Contact)" \ 323 > $SEARCHOUT 2>&1 324 325RC=$? 326if test $RC != 0 ; then 327 echo "ldapsearch failed ($RC)!" 328 test $KILLSERVERS != no && kill -HUP $KILLPIDS 329 exit $RC 330fi 331 332test $KILLSERVERS != no && kill -HUP $KILLPIDS 333 334echo ">>>>> Test succeeded" 335 336test $KILLSERVERS != no && wait 337 338exit 0 339