Home | History | Annotate | Line # | Download | only in scripts
      1 #! /bin/sh
      2 # $OpenLDAP$
      3 ## This work is part of OpenLDAP Software <http://www.openldap.org/>.
      4 ##
      5 ## Copyright 2022-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 2019 by Tamim Ziai for DAASI International
     18 
     19 echo "running defines.sh"
     20 . $SRCDIR/scripts/defines.sh
     21 
     22 LDIF=${TOPDIR}/tests/data/test001.out
     23 
     24 if test $ACCESSLOG = accesslogno; then
     25 	echo "Accesslog overlay not available, test skipped"
     26 	exit 0
     27 fi
     28 
     29 mkdir -p $TESTDIR $DBDIR1A $DBDIR1B
     30 
     31 . $CONFFILTER $BACKEND < "${TOPDIR}/tests/data/emptyds.conf" > $CONF1
     32 
     33 echo "Running slapadd to build slapd database... "
     34 $SLAPADD -f $CONF1 -l $LDIFORDERED
     35 RC=$?
     36 if test $RC != 0 ; then
     37 	echo "slapadd failed ($RC)!"
     38 	exit $RC
     39 fi
     40 
     41 echo "Starting slapd on TCP/IP port $PORT1..."
     42 $SLAPD -f $CONF1 -h $URI1 -d $LVL >> $LOG1 2>&1 &
     43 PID=$!
     44 if test $WAIT != 0 ; then
     45 	echo PID $PID
     46 	read foo
     47 fi
     48 KILLPIDS="$PID"
     49 
     50 sleep $SLEEP0
     51 
     52 for i in 0 1 2 3 4 5; do
     53 	$LDAPSEARCH -s base -b "$MONITOR" -H $URI1 \
     54 		'objectclass=*' > /dev/null 2>&1
     55 	RC=$?
     56 	if test $RC = 0 ; then
     57 		break
     58 	fi
     59 	echo "Waiting ${SLEEP1} seconds for slapd to start..."
     60 	sleep ${SLEEP1}
     61 done
     62 
     63 echo "Checking add/modify handling... "
     64 
     65 $LDAPMODIFY -D "$MANAGERDN" -H $URI1 -w $PASSWD \
     66 	> $TESTOUT -f "${TOPDIR}/tests/data/test001.ldif"
     67 RC=$?
     68 if test $RC != 0 ; then
     69 	echo "ldapmodify failed ($RC)!"
     70 	test $KILLSERVERS != no && kill -HUP $KILLPIDS
     71 	exit $RC
     72 fi
     73 
     74 echo "Checking modrdn handling (should still fail with invalidDNSyntax)... "
     75 
     76 $LDAPMODIFY -D "$MANAGERDN" -H $URI1 -w $PASSWD \
     77 	>> $TESTOUT 2>&1 <<EOMOD
     78 dn: cn=Ursula Hampster,ou=Alumni Association,ou=People,dc=example,dc=com
     79 changetype: modrdn
     80 newrdn: cn=
     81 deleteoldrdn: 0
     82 EOMOD
     83 RC=$?
     84 case $RC in
     85 34)
     86 	echo "	ldapmodify failed ($RC)"
     87 	;;
     88 0)
     89 	echo "	ldapmodify should have failed ($RC)!"
     90 	test $KILLSERVERS != no && kill -HUP $KILLPIDS
     91 	exit 1
     92 	;;
     93 *)
     94 	echo "	ldapmodify failed ($RC)!"
     95 	test $KILLSERVERS != no && kill -HUP $KILLPIDS
     96 	exit $RC
     97 	;;
     98 esac
     99 
    100 echo "Dumping accesslog..."
    101 
    102 $LDAPSEARCH -b "cn=log" -H $URI1 \
    103 	'objectClass=auditWriteObject' reqDN reqMod | \
    104 	grep -v -e 'entryCSN' -e '\(create\|modify\)Timestamp' \
    105 		-e '\(modifier\|creator\)sName' -e 'entryUUID' | \
    106 	sed -e 's/reqStart=[^,]*,/reqStart=timestamp,/' \
    107 	> $SEARCHOUT 2>&1
    108 RC=$?
    109 if test $RC != 0 ; then
    110 	echo "ldapsearch failed ($RC)!"
    111 	exit $RC
    112 fi
    113 
    114 test $KILLSERVERS != no && kill -HUP $KILLPIDS
    115 
    116 # Expectations:
    117 # - all empty values for directoryString pruned
    118 # - empty adds/deletes removed, empty replaces kept
    119 # - remaining values keep the same order as submitted
    120 # - other syntaxes (especially DNs) are kept intact
    121 echo "Filtering ldapsearch results..."
    122 $LDIFFILTER < $SEARCHOUT > $SEARCHFLT
    123 $LDIFFILTER < $LDIF > $LDIFFLT
    124 
    125 echo "Comparing filter output..."
    126 $CMP $LDIFFLT $SEARCHFLT > $CMPOUT
    127 
    128 if test $? != 0 ; then
    129 	echo "Comparison failed"
    130 	exit 1
    131 fi
    132 
    133 echo ">>>>> Test succeeded"
    134 
    135 test $KILLSERVERS != no && wait
    136 
    137 exit 0
    138