1*e670fd5cSchristos#! /bin/sh 2*e670fd5cSchristos# $OpenLDAP$ 3*e670fd5cSchristos## This work is part of OpenLDAP Software <http://www.openldap.org/>. 4*e670fd5cSchristos## 5*e670fd5cSchristos## Copyright 1998-2021 The OpenLDAP Foundation. 6*e670fd5cSchristos## All rights reserved. 7*e670fd5cSchristos## 8*e670fd5cSchristos## Redistribution and use in source and binary forms, with or without 9*e670fd5cSchristos## modification, are permitted only as authorized by the OpenLDAP 10*e670fd5cSchristos## Public License. 11*e670fd5cSchristos## 12*e670fd5cSchristos## A copy of this license is available in the file LICENSE in the 13*e670fd5cSchristos## top-level directory of the distribution or, alternatively, at 14*e670fd5cSchristos## <http://www.OpenLDAP.org/license.html>. 15*e670fd5cSchristos 16*e670fd5cSchristosecho "running defines.sh" 17*e670fd5cSchristos. $SRCDIR/scripts/defines.sh 18*e670fd5cSchristos 19*e670fd5cSchristosif test $SYNCPROV = syncprovno; then 20*e670fd5cSchristos echo "Syncrepl provider overlay not available, test skipped" 21*e670fd5cSchristos exit 0 22*e670fd5cSchristosfi 23*e670fd5cSchristos 24*e670fd5cSchristosCONFDIR=$TESTDIR/slapd.d 25*e670fd5cSchristosDBDIR=$TESTDIR/db 26*e670fd5cSchristosRCOUT=$TESTDIR/rcout 27*e670fd5cSchristos 28*e670fd5cSchristosmkdir -p $TESTDIR $CONFDIR $DBDIR 29*e670fd5cSchristos 30*e670fd5cSchristos$SLAPPASSWD -g -n >$CONFIGPWF 31*e670fd5cSchristos 32*e670fd5cSchristos# 33*e670fd5cSchristos# Test dynamic add/delete of syncprov overlay: 34*e670fd5cSchristos# - Create minimal back-conf setup 35*e670fd5cSchristos# - Add syncprov overlay to the cn=config database 36*e670fd5cSchristos# - Remove the overlay again 37*e670fd5cSchristos# 38*e670fd5cSchristos 39*e670fd5cSchristosecho "Starting slapd on TCP/IP port $PORT1... $PWD" 40*e670fd5cSchristos. $CONFFILTER $BACKEND < $DYNAMICCONF > $CONFLDIF 41*e670fd5cSchristos$SLAPADD -F $CONFDIR -n 0 -l $CONFLDIF 42*e670fd5cSchristoscd $TESTDIR 43*e670fd5cSchristos$SLAPD -F ./slapd.d -h $URI1 -d $LVL > $LOG1 2>&1 & 44*e670fd5cSchristosPID=$! 45*e670fd5cSchristosif test $WAIT != 0 ; then 46*e670fd5cSchristos echo PID $PID 47*e670fd5cSchristos read foo 48*e670fd5cSchristosfi 49*e670fd5cSchristosKILLPIDS="$PID" 50*e670fd5cSchristoscd $TESTWD 51*e670fd5cSchristos 52*e670fd5cSchristossleep 1 53*e670fd5cSchristos 54*e670fd5cSchristosecho "Using ldapsearch to check that slapd is running..." 55*e670fd5cSchristosfor i in 0 1 2 3 4 5; do 56*e670fd5cSchristos $LDAPSEARCH -s base -b "" -H $URI1 \ 57*e670fd5cSchristos 'objectclass=*' > /dev/null 2>&1 58*e670fd5cSchristos RC=$? 59*e670fd5cSchristos if test $RC = 0 ; then 60*e670fd5cSchristos break 61*e670fd5cSchristos fi 62*e670fd5cSchristos echo "Waiting 5 seconds for slapd to start..." 63*e670fd5cSchristos sleep 5 64*e670fd5cSchristosdone 65*e670fd5cSchristos 66*e670fd5cSchristosif test $RC != 0 ; then 67*e670fd5cSchristos echo "ldapsearch failed ($RC)!" 68*e670fd5cSchristos test $KILLSERVERS != no && kill -HUP $KILLPIDS 69*e670fd5cSchristos exit $RC 70*e670fd5cSchristosfi 71*e670fd5cSchristos 72*e670fd5cSchristosecho "Inserting syncprov overlay ..." 73*e670fd5cSchristosif [ "$SYNCPROV" = syncprovmod ]; then 74*e670fd5cSchristos $LDAPADD -D cn=config -H $URI1 -y $CONFIGPWF <<EOF > $TESTOUT 2>&1 75*e670fd5cSchristosdn: cn=module,cn=config 76*e670fd5cSchristosobjectClass: olcModuleList 77*e670fd5cSchristoscn: module 78*e670fd5cSchristosolcModulePath: $TESTWD/../servers/slapd/overlays 79*e670fd5cSchristosolcModuleLoad: syncprov.la 80*e670fd5cSchristosEOF 81*e670fd5cSchristos RC=$? 82*e670fd5cSchristos if test $RC != 0 ; then 83*e670fd5cSchristos echo "ldapadd failed for moduleLoad ($RC)!" 84*e670fd5cSchristos test $KILLSERVERS != no && kill -HUP $KILLPIDS 85*e670fd5cSchristos exit $RC 86*e670fd5cSchristos fi 87*e670fd5cSchristosfi 88*e670fd5cSchristosread CONFIGPW < $CONFIGPWF 89*e670fd5cSchristos$LDAPMODIFY -D cn=config -H $URI1 -y $CONFIGPWF <<EOF >> $TESTOUT 2>&1 90*e670fd5cSchristosdn: olcOverlay=syncprov,olcDatabase={0}config,cn=config 91*e670fd5cSchristoschangetype: add 92*e670fd5cSchristosobjectClass: olcOverlayConfig 93*e670fd5cSchristosobjectClass: olcSyncProvConfig 94*e670fd5cSchristosolcOverlay: syncprov 95*e670fd5cSchristosEOF 96*e670fd5cSchristos 97*e670fd5cSchristosRC=$? 98*e670fd5cSchristosif test $RC != 0 ; then 99*e670fd5cSchristos echo "ldapmodify failed for syncrepl config ($RC)!" 100*e670fd5cSchristos test $KILLSERVERS != no && kill -HUP $KILLPIDS 101*e670fd5cSchristos exit $RC 102*e670fd5cSchristosfi 103*e670fd5cSchristos 104*e670fd5cSchristosecho "Starting a refreshAndPersist search in background" 105*e670fd5cSchristosrm -f $RCOUT 106*e670fd5cSchristos( 107*e670fd5cSchristos $LDAPSEARCH -D cn=config -H $URI1 -y $CONFIGPWF -bcn=config -E \!sync=rp >/dev/null 2>&1 108*e670fd5cSchristos RC=$? 109*e670fd5cSchristos echo $RC > $RCOUT 110*e670fd5cSchristos exit $RC 111*e670fd5cSchristos) & 112*e670fd5cSchristos 113*e670fd5cSchristosSEARCHPID=$! 114*e670fd5cSchristos 115*e670fd5cSchristossleep 2 116*e670fd5cSchristos 117*e670fd5cSchristosecho "Removing syncprov overlay again ..." 118*e670fd5cSchristos$LDAPDELETE -D cn=config -H $URI1 -y $CONFIGPWF <<EOF >> $TESTOUT 2>&1 119*e670fd5cSchristosolcOverlay={0}syncprov,olcDatabase={0}config,cn=config 120*e670fd5cSchristosEOF 121*e670fd5cSchristosRC=$? 122*e670fd5cSchristos 123*e670fd5cSchristosif test $RC != 0 ; then 124*e670fd5cSchristos echo "ldapmodify failed for syncrepl config ($RC)!" 125*e670fd5cSchristos test $KILLSERVERS != no && kill -HUP $KILLPIDS 126*e670fd5cSchristos exit $RC 127*e670fd5cSchristosfi 128*e670fd5cSchristos 129*e670fd5cSchristosfor i in 0 1 2 3 4; do 130*e670fd5cSchristos if test -f "$RCOUT" ; then 131*e670fd5cSchristos break 132*e670fd5cSchristos else 133*e670fd5cSchristos echo "Waiting 2 seconds for RefreshAndPersist search to end ..." 134*e670fd5cSchristos sleep 2 135*e670fd5cSchristos fi 136*e670fd5cSchristosdone 137*e670fd5cSchristos 138*e670fd5cSchristosif test -f "$RCOUT" ; then 139*e670fd5cSchristos wait $SEARCHPID 140*e670fd5cSchristos SEARCHRC=`cat $RCOUT` 141*e670fd5cSchristos echo "Checking return code of backgrounded RefreshAndPersist search ..." 142*e670fd5cSchristos if test 52 != "$SEARCHRC" ; then 143*e670fd5cSchristos echo "Error: Backgrounded ldapsearch returned the wrong error code: $SEARCHRC" 144*e670fd5cSchristos RC=1 145*e670fd5cSchristos else 146*e670fd5cSchristos echo "Exit code correct." 147*e670fd5cSchristos fi 148*e670fd5cSchristoselse 149*e670fd5cSchristos echo "Backgrounded ldapsearch did not exit after overlay removal." 150*e670fd5cSchristos kill -HUP $SEARCHPID 151*e670fd5cSchristos RC=2 152*e670fd5cSchristosfi 153*e670fd5cSchristosif test $RC != 0 ; then 154*e670fd5cSchristos test $KILLSERVERS != no && kill -HUP $KILLPIDS 155*e670fd5cSchristos exit $RC 156*e670fd5cSchristosfi 157*e670fd5cSchristos 158*e670fd5cSchristosecho "Running a refreshOnly search, should fail..." 159*e670fd5cSchristos$LDAPSEARCH -D cn=config -H $URI1 -y $CONFIGPWF -bcn=config -E \!sync=ro > /dev/null 2>&1 160*e670fd5cSchristos 161*e670fd5cSchristosRC=$? 162*e670fd5cSchristosif test $RC != 12 ; then 163*e670fd5cSchristos echo "ldapsearch should have failed with Critical extension is unavailable (12)!" 164*e670fd5cSchristos test $KILLSERVERS != no && kill -HUP $KILLPIDS 165*e670fd5cSchristos exit $RC 166*e670fd5cSchristoselse 167*e670fd5cSchristos echo "Failed with \"Critical extension is unavailable (12)\". Ok." 168*e670fd5cSchristosfi 169*e670fd5cSchristos 170*e670fd5cSchristos 171*e670fd5cSchristostest $KILLSERVERS != no && kill -HUP $KILLPIDS 172*e670fd5cSchristos 173*e670fd5cSchristosecho ">>>>> Test succeeded" 174*e670fd5cSchristos 175*e670fd5cSchristostest $KILLSERVERS != no && wait 176*e670fd5cSchristos 177*e670fd5cSchristosexit 0 178