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