Home | History | Annotate | Line # | Download | only in scripts
      1       1.1     lukem #! /bin/sh
      2   1.1.1.4      tron # $OpenLDAP$
      3       1.1     lukem ## This work is part of OpenLDAP Software <http://www.openldap.org/>.
      4       1.1     lukem ##
      5  1.1.1.10  christos ## Copyright 1998-2024 The OpenLDAP Foundation.
      6       1.1     lukem ## All rights reserved.
      7       1.1     lukem ##
      8       1.1     lukem ## Redistribution and use in source and binary forms, with or without
      9       1.1     lukem ## modification, are permitted only as authorized by the OpenLDAP
     10       1.1     lukem ## Public License.
     11       1.1     lukem ##
     12       1.1     lukem ## A copy of this license is available in the file LICENSE in the
     13       1.1     lukem ## top-level directory of the distribution or, alternatively, at
     14       1.1     lukem ## <http://www.OpenLDAP.org/license.html>.
     15       1.1     lukem 
     16       1.1     lukem echo "running defines.sh"
     17       1.1     lukem . $SRCDIR/scripts/defines.sh
     18       1.1     lukem 
     19       1.1     lukem echo "### This test requires the ldap backend and glue overlay."
     20       1.1     lukem echo "### If available, and explicitly requested, it can use SASL bind;"
     21       1.1     lukem echo "### note that SASL must be properly set up, and the requested"
     22       1.1     lukem echo "### mechanism must be available.  Define SLAPD_USE_SASL={yes|<mech>},"
     23  1.1.1.10  christos echo "### with \"yes\" defaulting to SCRAM-SHA-256 to enable SASL authc[/authz]."
     24       1.1     lukem 
     25       1.1     lukem if test $BACKLDAP = "ldapno" ; then 
     26       1.1     lukem 	echo "LDAP backend not available, test skipped"
     27       1.1     lukem 	exit 0
     28       1.1     lukem fi 
     29       1.1     lukem 
     30       1.1     lukem if test $WITH_SASL = "yes" ; then
     31       1.1     lukem 	if test $USE_SASL != "no" ; then
     32       1.1     lukem 		if test $USE_SASL = "yes" ; then
     33  1.1.1.10  christos 			MECH="SCRAM-SHA-256"
     34       1.1     lukem 		else
     35       1.1     lukem 			MECH="$USE_SASL"
     36       1.1     lukem 		fi
     37       1.1     lukem 		echo "Using SASL authc[/authz] with mech=$MECH; unset SLAPD_USE_SASL to disable"
     38       1.1     lukem 	else
     39       1.1     lukem 		echo "Using proxyAuthz with simple authc..."
     40       1.1     lukem 	fi
     41       1.1     lukem else
     42       1.1     lukem 	echo "SASL not available; using proxyAuthz with simple authc..."
     43       1.1     lukem fi
     44       1.1     lukem 
     45       1.1     lukem mkdir -p $TESTDIR $DBDIR1 $DBDIR2 $DBDIR3
     46       1.1     lukem 
     47       1.1     lukem echo "Running slapadd to build slapd database..."
     48   1.1.1.9  christos . $CONFFILTER $BACKEND < $LDAPGLUECONF1 > $ADDCONF
     49       1.1     lukem $SLAPADD -f $ADDCONF -l $LDIFLDAPGLUE1
     50       1.1     lukem RC=$?
     51       1.1     lukem if test $RC != 0 ; then
     52       1.1     lukem 	echo "slapadd 1 failed ($RC)!"
     53       1.1     lukem 	exit $RC
     54       1.1     lukem fi
     55       1.1     lukem 
     56   1.1.1.9  christos . $CONFFILTER $BACKEND < $LDAPGLUECONF2 > $ADDCONF
     57       1.1     lukem $SLAPADD -f $ADDCONF -l $LDIFLDAPGLUE2
     58       1.1     lukem RC=$?
     59       1.1     lukem if test $RC != 0 ; then
     60       1.1     lukem 	echo "slapadd 2 failed ($RC)!"
     61       1.1     lukem 	exit $RC
     62       1.1     lukem fi
     63       1.1     lukem 
     64   1.1.1.9  christos . $CONFFILTER $BACKEND < $LDAPGLUECONF3 > $ADDCONF
     65       1.1     lukem $SLAPADD -f $ADDCONF -l $LDIFLDAPGLUE3
     66       1.1     lukem RC=$?
     67       1.1     lukem if test $RC != 0 ; then
     68       1.1     lukem 	echo "slapadd 3 failed ($RC)!"
     69       1.1     lukem 	exit $RC
     70       1.1     lukem fi
     71       1.1     lukem 
     72       1.1     lukem echo "Starting local slapd on TCP/IP port $PORT1..."
     73   1.1.1.9  christos . $CONFFILTER $BACKEND < $LDAPGLUECONF1 > $CONF1
     74   1.1.1.9  christos $SLAPD -f $CONF1 -h $URI1 -d $LVL > $LOG1 2>&1 &
     75       1.1     lukem PID1=$!
     76       1.1     lukem if test $WAIT != 0 ; then
     77       1.1     lukem     echo PID $PID1
     78       1.1     lukem     read foo
     79       1.1     lukem fi
     80       1.1     lukem 
     81       1.1     lukem echo "Starting remote slapd 1 on TCP/IP port $PORT2..."
     82   1.1.1.9  christos . $CONFFILTER $BACKEND < $LDAPGLUECONF2 > $CONF2
     83   1.1.1.9  christos $SLAPD -f $CONF2 -h $URI2 -d $LVL > $LOG2 2>&1 &
     84       1.1     lukem PID2=$!
     85       1.1     lukem if test $WAIT != 0 ; then
     86       1.1     lukem     echo PID $PID2
     87       1.1     lukem     read foo
     88       1.1     lukem fi
     89       1.1     lukem 
     90       1.1     lukem echo "Starting remote slapd 2 on TCP/IP port $PORT3..."
     91   1.1.1.9  christos . $CONFFILTER $BACKEND < $LDAPGLUECONF3 > $CONF3
     92   1.1.1.9  christos $SLAPD -f $CONF3 -h $URI3 -d $LVL > $LOG3 2>&1 &
     93       1.1     lukem PID3=$!
     94       1.1     lukem if test $WAIT != 0 ; then
     95       1.1     lukem     echo PID $PID3
     96       1.1     lukem     read foo
     97       1.1     lukem fi
     98       1.1     lukem KILLPIDS="$PID1 $PID2 $PID3"
     99       1.1     lukem 
    100       1.1     lukem sleep 1
    101       1.1     lukem 
    102       1.1     lukem echo "Using ldapsearch to check that slapd is running..."
    103       1.1     lukem for i in 0 1 2 3 4 5; do
    104   1.1.1.9  christos 	$LDAPSEARCH -s base -b "$MONITOR" -H $URI1 \
    105       1.1     lukem 		'objectclass=*' > /dev/null 2>&1
    106       1.1     lukem 	RC=$?
    107       1.1     lukem 	if test $RC = 0 ; then
    108       1.1     lukem 		break
    109       1.1     lukem 	fi
    110       1.1     lukem 	echo "Waiting 5 seconds for slapd to start..."
    111       1.1     lukem 	sleep 5
    112       1.1     lukem done
    113       1.1     lukem 
    114       1.1     lukem echo "Using ldapsearch to check that slapd is running..."
    115       1.1     lukem for i in 0 1 2 3 4 5; do
    116   1.1.1.9  christos 	$LDAPSEARCH -s base -b "$MONITOR" -H $URI2 \
    117       1.1     lukem 		'objectclass=*' > /dev/null 2>&1
    118       1.1     lukem 	RC=$?
    119       1.1     lukem 	if test $RC = 0 ; then
    120       1.1     lukem 		break
    121       1.1     lukem 	fi
    122       1.1     lukem 	echo "Waiting 5 seconds for slapd to start..."
    123       1.1     lukem 	sleep 5
    124       1.1     lukem done
    125       1.1     lukem 
    126       1.1     lukem echo "Using ldapsearch to check that slapd is running..."
    127       1.1     lukem for i in 0 1 2 3 4 5; do
    128   1.1.1.9  christos 	$LDAPSEARCH -s base -b "$MONITOR" -H $URI3 \
    129       1.1     lukem 		'objectclass=*' > /dev/null 2>&1
    130       1.1     lukem 	RC=$?
    131       1.1     lukem 	if test $RC = 0 ; then
    132       1.1     lukem 		break
    133       1.1     lukem 	fi
    134       1.1     lukem 	echo "Waiting 5 seconds for slapd to start..."
    135       1.1     lukem 	sleep 5
    136       1.1     lukem done
    137       1.1     lukem 
    138       1.1     lukem ID="uid=bjorn,ou=People,dc=example,dc=com"
    139       1.1     lukem BASE="dc=example,dc=com"
    140       1.1     lukem echo "Testing ldapsearch as $ID for \"$BASE\"..."
    141   1.1.1.9  christos $LDAPSEARCH -H $URI1 -b "$BASE" \
    142       1.1     lukem 	-D "$ID" -w bjorn > $SEARCHOUT 2>&1
    143       1.1     lukem 
    144       1.1     lukem RC=$?
    145       1.1     lukem if test $RC != 0 ; then
    146       1.1     lukem 	echo "ldapsearch failed ($RC)!"
    147       1.1     lukem 	test $KILLSERVERS != no && kill -HUP $KILLPIDS
    148       1.1     lukem 	exit $RC
    149       1.1     lukem fi
    150       1.1     lukem 
    151       1.1     lukem echo "Filtering ldapsearch results..."
    152   1.1.1.3      adam $LDIFFILTER -s ldif=e < $SEARCHOUT > $SEARCHFLT
    153       1.1     lukem echo "Filtering original ldif used to create database..."
    154   1.1.1.3      adam $LDIFFILTER -s ldif=e < $LDAPGLUEOUT > $LDIFFLT
    155       1.1     lukem echo "Comparing filter output..."
    156       1.1     lukem $CMP $SEARCHFLT $LDIFFLT > $CMPOUT
    157       1.1     lukem 	
    158       1.1     lukem if test $? != 0 ; then
    159       1.1     lukem 	echo "comparison failed - glued search with identity assertion didn't succeed"
    160       1.1     lukem 	test $KILLSERVERS != no && kill -HUP $KILLPIDS
    161       1.1     lukem 	exit 1
    162       1.1     lukem fi
    163       1.1     lukem 
    164       1.1     lukem BASE="dc=example,dc=com"
    165       1.1     lukem echo "Testing ldapsearch as anonymous for \"$BASE\"..."
    166   1.1.1.9  christos $LDAPSEARCH -H $URI1 -b "$BASE" \
    167       1.1     lukem 	 > $SEARCHOUT 2>&1
    168       1.1     lukem 
    169       1.1     lukem RC=$?
    170       1.1     lukem if test $RC != 0 ; then
    171       1.1     lukem 	echo "ldapsearch failed ($RC)!"
    172       1.1     lukem 	test $KILLSERVERS != no && kill -HUP $KILLPIDS
    173       1.1     lukem 	exit $RC
    174       1.1     lukem fi
    175       1.1     lukem 
    176       1.1     lukem echo "Filtering ldapsearch results..."
    177   1.1.1.3      adam $LDIFFILTER < $SEARCHOUT > $SEARCHFLT
    178       1.1     lukem echo "Filtering original ldif used to create database..."
    179   1.1.1.3      adam $LDIFFILTER < $LDAPGLUEANONYMOUSOUT > $LDIFFLT
    180       1.1     lukem echo "Comparing filter output..."
    181       1.1     lukem $CMP $SEARCHFLT $LDIFFLT > $CMPOUT
    182       1.1     lukem 	
    183       1.1     lukem if test $? != 0 ; then
    184       1.1     lukem 	echo "comparison failed - anonymous glued search with identity assertion didn't succeed"
    185       1.1     lukem 	test $KILLSERVERS != no && kill -HUP $KILLPIDS
    186       1.1     lukem 	exit 1
    187       1.1     lukem fi
    188       1.1     lukem 
    189       1.1     lukem # FIXME: this cannot work as is, because SASL bind cannot be proxied!
    190       1.1     lukem if test $USE_SASL != "no" ; then
    191       1.1     lukem 	ID="bjorn"
    192       1.1     lukem 	BASE="dc=example,dc=com"
    193       1.1     lukem 	echo "Testing ldapsearch as $ID for \"$BASE\" with SASL bind and identity assertion..."
    194   1.1.1.9  christos 	$LDAPSASLSEARCH -H $URI1 -b "$BASE" \
    195       1.1     lukem 		-Q -U "$ID" -w bjorn -Y $MECH > $SEARCHOUT 2>&1
    196       1.1     lukem 
    197       1.1     lukem 	RC=$?
    198       1.1     lukem 	if test $RC != 0 ; then
    199       1.1     lukem 		echo "ldapsearch failed ($RC)!"
    200       1.1     lukem 		test $KILLSERVERS != no && kill -HUP $KILLPIDS
    201       1.1     lukem 		exit $RC
    202       1.1     lukem 	fi
    203       1.1     lukem 
    204       1.1     lukem 	echo "Filtering ldapsearch results..."
    205   1.1.1.3      adam 	$LDIFFILTER < $SEARCHOUT > $SEARCHFLT
    206       1.1     lukem 	echo "Filtering original ldif used to create database..."
    207   1.1.1.3      adam 	$LDIFFILTER < $LDAPGLUEOUT > $LDIFFLT
    208       1.1     lukem 	echo "Comparing filter output..."
    209       1.1     lukem 	$CMP $SEARCHFLT $LDIFFLT > $CMPOUT
    210       1.1     lukem 	
    211       1.1     lukem 	if test $? != 0 ; then
    212       1.1     lukem 		echo "comparison failed - glued search with SASL bind and identity assertion didn't succeed"
    213       1.1     lukem 		test $KILLSERVERS != no && kill -HUP $KILLPIDS
    214       1.1     lukem 		exit 1
    215       1.1     lukem 	fi
    216       1.1     lukem fi
    217       1.1     lukem 
    218       1.1     lukem test $KILLSERVERS != no && kill -HUP $KILLPIDS
    219       1.1     lukem 
    220       1.1     lukem echo ">>>>> Test succeeded"
    221       1.1     lukem 
    222       1.1     lukem test $KILLSERVERS != no && wait
    223       1.1     lukem 
    224       1.1     lukem exit 0
    225