Home | History | Annotate | Line # | Download | only in scripts
      1 #! /bin/sh
      2 ## This work is part of OpenLDAP Software <http://www.openldap.org/>.
      3 ##
      4 ## Copyright 2004-2024 The OpenLDAP Foundation.
      5 ## All rights reserved.
      6 ##
      7 ## Redistribution and use in source and binary forms, with or without
      8 ## modification, are permitted only as authorized by the OpenLDAP
      9 ## Public License.
     10 ##
     11 ## A copy of this license is available in the file LICENSE in the
     12 ## top-level directory of the distribution or, alternatively, at
     13 ## <http://www.OpenLDAP.org/license.html>.
     14 
     15 echo "running defines.sh"
     16 . $SRCDIR/scripts/defines.sh
     17 
     18 mkdir -p $TESTDIR $DBDIR1 $DBDIR2
     19 
     20 . $CONFFILTER $BACKEND < $EMPTYDNCONF > $CONF1
     21 
     22 echo "Running slapadd to build \"dc=example,dc=com\" slapd database..."
     23 $SLAPADD -f $CONF1 -n 1 -l $LDIFEMPTYDN1
     24 RC=$?
     25 if test $RC != 0 ; then
     26 	echo "slapadd failed ($RC)!"
     27 	exit $RC
     28 fi
     29 
     30 echo "Running slapadd to build empty DN slapd database..."
     31 $SLAPADD -f $CONF1 -b "" -l $LDIFEMPTYDN2
     32 RC=$?
     33 if test $RC != 0 ; then
     34 	echo "slapadd failed ($RC)!"
     35 	exit $RC
     36 fi
     37 
     38 echo "Starting slapd on TCP/IP port $PORT1..."
     39 $SLAPD -f $CONF1 -h $URI1 -d $LVL > $LOG1 2>&1 &
     40 PID=$!
     41 if test $WAIT != 0 ; then
     42     echo PID $PID
     43     read foo
     44 fi
     45 KILLPIDS="$PID"
     46 
     47 sleep 1
     48 
     49 echo "Testing slapd empty DN handling..."
     50 for i in 0 1 2 3 4 5; do
     51 	$LDAPSEARCH -s base -b "$MONITOR" -H $URI1 \
     52 		'objectclass=*' > /dev/null 2>&1
     53 	RC=$?
     54 	if test $RC = 0 ; then
     55 		break
     56 	fi
     57 	echo "Waiting 5 seconds for slapd to start..."
     58 	sleep 5
     59 done
     60 
     61 if test $RC != 0 ; then
     62 	echo "ldapsearch failed ($RC)!"
     63 	test $KILLSERVERS != no && kill -HUP $KILLPIDS
     64 	exit $RC
     65 fi
     66 
     67 echo "Searching database..."
     68 
     69 $LDAPSEARCH -S "" -b "" -H $URI1 > $SEARCHOUT 2>&1
     70 
     71 RC=$?
     72 if test $RC != 0 ; then
     73 	echo "ldapsearch failed ($RC)!"
     74 	test $KILLSERVERS != no && kill -HUP $KILLPIDS
     75 	exit $RC
     76 fi
     77 
     78 kill -HUP $KILLPIDS
     79 wait
     80 
     81 echo "Filtering ldapsearch results..."
     82 $LDIFFILTER < $SEARCHOUT > $SEARCHFLT
     83 echo "Filtering expected results..."
     84 $LDIFFILTER < $EMPTYDNOUT1 > $LDIFFLT
     85 echo "Comparing ldapsearch results against original..."
     86 $CMP $SEARCHFLT $LDIFFLT > $CMPOUT
     87 
     88 if test $? != 0 ; then
     89 	echo "comparison failed - empty DN write operations did not complete correctly"
     90 	exit 1
     91 fi
     92 
     93 echo "Comparison of database generated via slapadd succeeded"
     94 
     95 echo "Cleaning up database directories..."
     96 /bin/rm -rf $TESTDIR/db.*
     97 
     98 mkdir -p $TESTDIR $DBDIR1 $DBDIR2
     99 
    100 echo "Starting slapd on TCP/IP port $PORT1..."
    101 $SLAPD -f $CONF1 -h $URI1 -d $LVL > $LOG1 2>&1 &
    102 PID=$!
    103 if test $WAIT != 0 ; then
    104     echo PID $PID
    105     read foo
    106 fi
    107 KILLPIDS="$PID"
    108 
    109 sleep 1
    110 
    111 echo "Testing slapd empty DN handling..."
    112 for i in 0 1 2 3 4 5; do
    113 	$LDAPSEARCH -s base -b "$MONITOR" -H $URI1 \
    114 		'objectclass=*' > /dev/null 2>&1
    115 	RC=$?
    116 	if test $RC = 0 ; then
    117 		break
    118 	fi
    119 	echo "Waiting 5 seconds for slapd to start..."
    120 	sleep 5
    121 done
    122 
    123 if test $RC != 0 ; then
    124 	echo "ldapsearch failed ($RC)!"
    125 	test $KILLSERVERS != no && kill -HUP $KILLPIDS
    126 	exit $RC
    127 fi
    128 
    129 echo "Loading database..."
    130 $LDAPADD -D "$MANAGERDN" -H $URI1 -w $PASSWD \
    131 	-f $LDIFEMPTYDN1 > /dev/null 2>&1
    132 $LDAPADD -D "$EMPTYDNDN" -H $URI1 -w $PASSWD \
    133 	-f $LDIFEMPTYDN2 > /dev/null 2>&1
    134 
    135 $LDAPMODIFY -D "$EMPTYDNDN" -H $URI1 -w $PASSWD \
    136 	> /dev/null 2>&1 << EOF
    137 dn: o=Beispiel,c=DE
    138 changetype: delete
    139 
    140 dn: c=DE
    141 changetype: delete
    142 EOF
    143 
    144 echo "Searching database..."
    145 
    146 $LDAPSEARCH -S "" -b "" -H $URI1 > $SEARCHOUT 2>&1
    147 
    148 RC=$?
    149 if test $RC != 0 ; then
    150 	echo "ldapsearch failed ($RC)!"
    151 	test $KILLSERVERS != no && kill -HUP $KILLPIDS
    152 	exit $RC
    153 fi
    154 
    155 test $KILLSERVERS != no && kill -HUP $KILLPIDS
    156 
    157 echo "Filtering ldapsearch results..."
    158 $LDIFFILTER < $SEARCHOUT > $SEARCHFLT
    159 echo "Filtering expected results..."
    160 $LDIFFILTER < $EMPTYDNOUT2 > $LDIFFLT
    161 echo "Comparing ldapsearch results against original..."
    162 $CMP $SEARCHFLT $LDIFFLT > $CMPOUT
    163 
    164 if test $? != 0 ; then
    165 	echo "comparison failed - empty DN write operations did not complete correctly"
    166 	exit 1
    167 fi
    168 
    169 #####
    170 
    171 echo ">>>>> Test succeeded"
    172 
    173 test $KILLSERVERS != no && wait
    174 
    175 exit 0
    176