Home | History | Annotate | Line # | Download | only in scripts
test062-config-delete revision 1.1.1.1
      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 
     16 echo "running defines.sh"
     17 . $SRCDIR/scripts/defines.sh
     18 
     19 if test $SYNCPROV = syncprovno; then
     20 	echo "Syncrepl provider overlay not available, test skipped"
     21 	exit 0
     22 fi
     23 
     24 CONFDIR=$TESTDIR/slapd.d
     25 DBDIR=$TESTDIR/db
     26 RCOUT=$TESTDIR/rcout
     27 
     28 mkdir -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 
     39 echo "Starting slapd on TCP/IP port $PORT1... $PWD"
     40 . $CONFFILTER $BACKEND < $DYNAMICCONF > $CONFLDIF
     41 $SLAPADD -F $CONFDIR -n 0 -l $CONFLDIF
     42 cd $TESTDIR
     43 $SLAPD -F ./slapd.d -h $URI1 -d $LVL > $LOG1 2>&1 &
     44 PID=$!
     45 if test $WAIT != 0 ; then
     46     echo PID $PID
     47     read foo
     48 fi
     49 KILLPIDS="$PID"
     50 cd $TESTWD
     51 
     52 sleep 1
     53 
     54 echo "Using ldapsearch to check that slapd is running..."
     55 for 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
     64 done
     65 
     66 if test $RC != 0 ; then
     67 	echo "ldapsearch failed ($RC)!"
     68 	test $KILLSERVERS != no && kill -HUP $KILLPIDS
     69 	exit $RC
     70 fi
     71 
     72 echo "Inserting syncprov overlay ..."
     73 if [ "$SYNCPROV" = syncprovmod ]; then
     74 	$LDAPADD -D cn=config -H $URI1 -y $CONFIGPWF <<EOF > $TESTOUT 2>&1
     75 dn: cn=module,cn=config
     76 objectClass: olcModuleList
     77 cn: module
     78 olcModulePath: $TESTWD/../servers/slapd/overlays
     79 olcModuleLoad: syncprov.la
     80 EOF
     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
     87 fi
     88 read CONFIGPW < $CONFIGPWF
     89 $LDAPMODIFY -D cn=config -H $URI1 -y $CONFIGPWF <<EOF >> $TESTOUT 2>&1
     90 dn: olcOverlay=syncprov,olcDatabase={0}config,cn=config
     91 changetype: add
     92 objectClass: olcOverlayConfig
     93 objectClass: olcSyncProvConfig
     94 olcOverlay: syncprov
     95 EOF
     96 
     97 RC=$?
     98 if test $RC != 0 ; then
     99 	echo "ldapmodify failed for syncrepl config ($RC)!"
    100 	test $KILLSERVERS != no && kill -HUP $KILLPIDS
    101 	exit $RC
    102 fi
    103 
    104 echo "Starting a refreshAndPersist search in background"
    105 rm -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 
    113 SEARCHPID=$!
    114 
    115 sleep 2
    116 
    117 echo "Removing syncprov overlay again ..."
    118 $LDAPDELETE -D cn=config -H $URI1 -y $CONFIGPWF <<EOF >> $TESTOUT 2>&1
    119 olcOverlay={0}syncprov,olcDatabase={0}config,cn=config
    120 EOF
    121 RC=$?
    122 
    123 if test $RC != 0 ; then
    124 	echo "ldapmodify failed for syncrepl config ($RC)!"
    125 	test $KILLSERVERS != no && kill -HUP $KILLPIDS
    126 	exit $RC
    127 fi
    128 
    129 for 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
    136 done
    137 
    138 if 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
    148 else
    149 	echo "Backgrounded ldapsearch did not exit after overlay removal."
    150 	kill -HUP $SEARCHPID
    151 	RC=2
    152 fi
    153 if test $RC != 0 ; then
    154 	test $KILLSERVERS != no && kill -HUP $KILLPIDS
    155 	exit $RC
    156 fi
    157 
    158 echo "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 
    161 RC=$?
    162 if 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
    166 else
    167 	echo "Failed with \"Critical extension is unavailable (12)\". Ok."
    168 fi
    169 
    170 
    171 test $KILLSERVERS != no && kill -HUP $KILLPIDS
    172 
    173 echo ">>>>> Test succeeded"
    174 
    175 test $KILLSERVERS != no && wait
    176 
    177 exit 0
    178