1 #! /bin/sh 2 ## $OpenLDAP$ 3 ## This work is part of OpenLDAP Software <http://www.openldap.org/>. 4 ## 5 ## Copyright 2016-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 ## ACKNOWLEDGEMENTS: 17 ## This module was written in 2016 by Ondej Kuznk for Symas Corp. 18 19 echo "running defines.sh" 20 . $SRCDIR/scripts/defines.sh 21 22 . ${SCRIPTDIR}/common.sh 23 24 echo "Applying invalid changes to config (should fail)..." 25 for CHANGE in data/test001-*.ldif; do 26 echo "... $CHANGE" 27 . $CONFFILTER $BACKEND $MONITORDB < $CHANGE | \ 28 $LDAPMODIFY -D cn=config -H $URI1 -y $CONFIGPWF \ 29 >> $TESTOUT 2>&1 30 RC=$? 31 case $RC in 32 0) 33 echo "ldapmodify should have failed ($RC)!" 34 test $KILLSERVERS != no && kill -HUP $KILLPIDS 35 exit 1 36 ;; 37 80) 38 echo "ldapmodify failed ($RC)" 39 ;; 40 *) 41 echo "ldapmodify failed ($RC)!" 42 test $KILLSERVERS != no && kill -HUP $KILLPIDS 43 exit $RC 44 ;; 45 esac 46 done 47 48 # We run this search after the changes above and before restart so we can also 49 # check the reconfiguration attempts actually had no side effects 50 echo "Saving search output before server restart..." 51 echo "# search output from dynamically configured server..." >> $SERVER3OUT 52 $LDAPSEARCH -b "$BASEDN" -H $URI1 \ 53 >> $SERVER3OUT 2>&1 54 RC=$? 55 if test $RC != 0 ; then 56 echo "ldapsearch failed ($RC)!" 57 test $KILLSERVERS != no && kill -HUP $KILLPIDS 58 exit $RC 59 fi 60 61 echo "Stopping slapd on TCP/IP port $PORT1..." 62 kill -HUP $KILLPIDS 63 KILLPIDS="" 64 sleep $SLEEP0 65 echo "Starting slapd on TCP/IP port $PORT1..." 66 $SLAPD -F $TESTDIR/confdir -h $URI1 -d $LVL >> $LOG1 2>&1 & 67 PID=$! 68 if test $WAIT != 0 ; then 69 echo PID $PID 70 read foo 71 fi 72 KILLPIDS="$PID" 73 74 sleep $SLEEP0 75 76 for i in 0 1 2 3 4 5; do 77 $LDAPSEARCH -s base -b "$MONITOR" -H $URI1 \ 78 'objectclass=*' > /dev/null 2>&1 79 RC=$? 80 if test $RC = 0 ; then 81 break 82 fi 83 echo "Waiting ${SLEEP1} seconds for slapd to start..." 84 sleep ${SLEEP1} 85 done 86 87 echo "Testing slapd.conf support..." 88 mkdir $TESTDIR/conftest $DBDIR2 89 . $CONFFILTER $BACKEND $MONITORDB < $CONFTWO \ 90 | sed -e '/^argsfile.*/a\ 91 moduleload ../variant.la' \ 92 -e '/database.*monitor/i\ 93 include data/variant.conf' \ 94 > $CONF2 95 echo "database config" >>$CONF2 96 echo "rootpw `$SLAPPASSWD -T $CONFIGPWF`" >>$CONF2 97 98 $SLAPADD -f $CONF2 -l $LDIFORDERED 99 $SLAPD -Tt -f $CONF2 -F $TESTDIR/conftest -d $LVL >> $LOG2 2>&1 100 RC=$? 101 if test $RC != 0 ; then 102 echo "slaptest failed ($RC)!" 103 test $KILLSERVERS != no && kill -HUP $KILLPIDS 104 exit $RC 105 fi 106 107 echo "Starting slapd on TCP/IP port $PORT2..." 108 $SLAPD -F $TESTDIR/conftest -h $URI2 -d $LVL >> $LOG2 2>&1 & 109 PID=$! 110 if test $WAIT != 0 ; then 111 echo PID $PID 112 read foo 113 fi 114 KILLPIDS="$KILLPIDS $PID" 115 116 sleep $SLEEP0 117 118 for i in 0 1 2 3 4 5; do 119 $LDAPSEARCH -s base -b "$MONITOR" -H $URI2 \ 120 'objectclass=*' > /dev/null 2>&1 121 RC=$? 122 if test $RC = 0 ; then 123 break 124 fi 125 echo "Waiting ${SLEEP1} seconds for slapd to start..." 126 sleep ${SLEEP1} 127 done 128 129 echo "Gathering overlay configuration from both servers..." 130 echo "# overlay configuration from dynamically configured server..." >> $SERVER1OUT 131 $LDAPSEARCH -D cn=config -H $URI1 -y $CONFIGPWF \ 132 -b "olcOverlay={0}variant,olcDatabase={1}$BACKEND,cn=config" \ 133 >> $SERVER1OUT 2>&1 134 RC=$? 135 if test $RC != 0 ; then 136 echo "ldapsearch failed ($RC)!" 137 test $KILLSERVERS != no && kill -HUP $KILLPIDS 138 exit $RC 139 fi 140 141 echo "# overlay configuration from server configured from slapd.conf..." >> $SERVER2OUT 142 $LDAPSEARCH -D cn=config -H $URI2 -y $CONFIGPWF \ 143 -b "olcOverlay={0}variant,olcDatabase={1}$BACKEND,cn=config" \ 144 >> $SERVER2OUT 2>&1 145 RC=$? 146 if test $RC != 0 ; then 147 echo "ldapsearch failed ($RC)!" 148 test $KILLSERVERS != no && kill -HUP $KILLPIDS 149 exit $RC 150 fi 151 152 # We've already filtered out the ordering markers, now sort the entries 153 echo "Filtering ldapsearch results..." 154 $LDIFFILTER -s a < $SERVER2OUT > $SERVER2FLT 155 echo "Filtering expected entries..." 156 $LDIFFILTER -s a < $SERVER1OUT > $SERVER1FLT 157 echo "Comparing filter output..." 158 $CMP $SERVER2FLT $SERVER1FLT > $CMPOUT 159 160 if test $? != 0 ; then 161 echo "Comparison failed" 162 test $KILLSERVERS != no && kill -HUP $KILLPIDS 163 exit 1 164 fi 165 166 rm $SERVER1OUT $SERVER2OUT 167 168 echo "Comparing search output on both servers..." 169 echo "# search output from dynamically configured server..." >> $SERVER1OUT 170 $LDAPSEARCH -b "$BASEDN" -H $URI1 \ 171 >> $SERVER1OUT 2>&1 172 RC=$? 173 if test $RC != 0 ; then 174 echo "ldapsearch failed ($RC)!" 175 test $KILLSERVERS != no && kill -HUP $KILLPIDS 176 exit $RC 177 fi 178 179 echo "# search output from server configured from slapd.conf..." >> $SERVER2OUT 180 $LDAPSEARCH -b "$BASEDN" -H $URI2 \ 181 >> $SERVER2OUT 2>&1 182 RC=$? 183 if test $RC != 0 ; then 184 echo "ldapsearch failed ($RC)!" 185 test $KILLSERVERS != no && kill -HUP $KILLPIDS 186 exit $RC 187 fi 188 189 test $KILLSERVERS != no && kill -HUP $KILLPIDS 190 191 echo "Filtering ldapsearch results..." 192 $LDIFFILTER -s e < $SERVER1OUT > $SERVER1FLT 193 $LDIFFILTER -s e < $SERVER2OUT > $SERVER2FLT 194 echo "Filtering expected entries..." 195 $LDIFFILTER -s e < $SERVER3OUT > $SERVER3FLT 196 echo "Comparing filter output..." 197 $CMP $SERVER3FLT $SERVER1FLT > $CMPOUT && \ 198 $CMP $SERVER3FLT $SERVER2FLT > $CMPOUT 199 200 if test $? != 0 ; then 201 echo "Comparison failed" 202 exit 1 203 fi 204 205 echo ">>>>> Test succeeded" 206 207 test $KILLSERVERS != no && wait 208 209 exit 0 210