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