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 19mkdir -p $TESTDIR $DBDIR1 20 21echo "Starting slapd on TCP/IP port $PORT1..." 22. $CONFFILTER $BACKEND < $CONF > $CONF1 23$SLAPD -f $CONF1 -h $URI1 -d $LVL > $LOG1 2>&1 & 24PID=$! 25if test $WAIT != 0 ; then 26 echo PID $PID 27 read foo 28fi 29KILLPIDS="$PID" 30 31sleep 1 32 33echo "Testing slapd searching..." 34for i in 0 1 2 3 4 5; do 35 $LDAPSEARCH -s base -b "$MONITOR" -H $URI1 \ 36 '(objectclass=*)' > /dev/null 2>&1 37 RC=$? 38 if test $RC = 0 ; then 39 break 40 fi 41 echo "Waiting 5 seconds for slapd to start..." 42 sleep 5 43done 44 45if test $RC != 0 ; then 46 echo "ldapsearch failed ($RC)!" 47 test $KILLSERVERS != no && kill -HUP $KILLPIDS 48 exit $RC 49fi 50 51cat /dev/null > $TESTOUT 52cat /dev/null > $SEARCHOUT 53 54# Add 55echo "Populating the database..." 56echo "# Populating the database..." >> $TESTOUT 57$LDAPADD -v -D "$MANAGERDN" -H $URI1 -w $PASSWD \ 58 >> $TESTOUT 2>&1 << EOMODS0 59dn: dc=example,dc=com 60objectClass: organization 61objectClass: dcObject 62o: Example, Inc. 63dc: example 64 65dn: ou=Parent,dc=example,dc=com 66objectClass: organizationalUnit 67ou: Parent 68 69dn: ou=Another parent,dc=example,dc=com 70objectClass: organizationalUnit 71ou: Another parent 72 73dn: ou=Child,ou=Parent,dc=example,dc=com 74objectClass: organizationalUnit 75ou: Child 76 77dn: ou=Grandchild,ou=Child,ou=Parent,dc=example,dc=com 78objectClass: organizationalUnit 79ou: Grandchild 80EOMODS0 81RC=$? 82if test $RC != 0 ; then 83 echo "ldapadd failed ($RC)!" 84 test $KILLSERVERS != no && kill -HUP $KILLPIDS 85 exit $RC 86fi 87 88echo "Searching all database..." 89echo "# Searching all database (after add)..." >> $SEARCHOUT 90$LDAPSEARCH -S "" -b "$BASEDN" -H $URI1 \ 91 '(objectClass=*)' >> $SEARCHOUT 2>&1 92RC=$? 93if test $RC != 0 ; then 94 echo "ldapsearch failed ($RC)!" 95 test $KILLSERVERS != no && kill -HUP $KILLPIDS 96 exit $RC 97fi 98 99# Rename (PASS1) 100echo "Renaming (PASS1)..." 101echo "# Renaming (PASS1)..." >> $TESTOUT 102$LDAPMODIFY -v -D "$MANAGERDN" -H $URI1 -w $PASSWD \ 103 >> $TESTOUT 2>&1 << EOMODS1 104dn: ou=Child,ou=Parent,dc=example,dc=com 105changetype: modrdn 106newrdn: ou=Renamed child 107deleteoldrdn: 0 108EOMODS1 109RC=$? 110if test $RC != 0 ; then 111 echo "ldapadd failed ($RC)!" 112 test $KILLSERVERS != no && kill -HUP $KILLPIDS 113 exit $RC 114fi 115 116echo "Searching all database..." 117echo "# Searching all database (after PASS1)..." >> $SEARCHOUT 118$LDAPSEARCH -S "" -b "$BASEDN" -H $URI1 \ 119 '(objectClass=*)' >> $SEARCHOUT 2>&1 120RC=$? 121if test $RC != 0 ; then 122 echo "ldapsearch failed ($RC)!" 123 test $KILLSERVERS != no && kill -HUP $KILLPIDS 124 exit $RC 125fi 126 127# Rename (PASS2) 128echo "Renaming (PASS2)..." 129echo "# Renaming (PASS2)..." >> $TESTOUT 130$LDAPMODIFY -v -D "$MANAGERDN" -H $URI1 -w $PASSWD \ 131 >> $TESTOUT 2>&1 << EOMODS2 132dn: ou=Parent,dc=example,dc=com 133changetype: modrdn 134newrdn: ou=Renamed parent 135deleteoldrdn: 0 136EOMODS2 137RC=$? 138if test $RC != 0 ; then 139 echo "ldapadd failed ($RC)!" 140 test $KILLSERVERS != no && kill -HUP $KILLPIDS 141 exit $RC 142fi 143 144echo "Searching all database..." 145echo "# Searching all database (after PASS2)..." >> $SEARCHOUT 146$LDAPSEARCH -S "" -b "$BASEDN" -H $URI1 \ 147 '(objectClass=*)' >> $SEARCHOUT 2>&1 148RC=$? 149if test $RC != 0 ; then 150 echo "ldapsearch failed ($RC)!" 151 test $KILLSERVERS != no && kill -HUP $KILLPIDS 152 exit $RC 153fi 154 155# Rename (PASS3) 156echo "Renaming (PASS3)..." 157echo "# Renaming (PASS3)..." >> $TESTOUT 158$LDAPMODIFY -v -D "$MANAGERDN" -H $URI1 -w $PASSWD \ 159 >> $TESTOUT 2>&1 << EOMODS3 160dn: ou=Renamed child,ou=Renamed parent,dc=example,dc=com 161changetype: modrdn 162newrdn: ou=Renamed child 163deleteoldrdn: 0 164newsuperior: ou=Another parent,dc=example,dc=com 165EOMODS3 166RC=$? 167if test $RC != 0 ; then 168 echo "ldapadd failed ($RC)!" 169 test $KILLSERVERS != no && kill -HUP $KILLPIDS 170 exit $RC 171fi 172 173echo "Searching all database..." 174echo "# Searching all database (after PASS3)..." >> $SEARCHOUT 175$LDAPSEARCH -S "" -b "$BASEDN" -H $URI1 \ 176 '(objectClass=*)' >> $SEARCHOUT 2>&1 177RC=$? 178if test $RC != 0 ; then 179 echo "ldapsearch failed ($RC)!" 180 test $KILLSERVERS != no && kill -HUP $KILLPIDS 181 exit $RC 182fi 183 184test $KILLSERVERS != no && kill -HUP $KILLPIDS 185 186LDIF=$SUBTREERENAMEOUT 187 188echo "Filtering ldapsearch results..." 189$LDIFFILTER < $SEARCHOUT > $SEARCHFLT 190echo "Filtering original ldif used to create database..." 191$LDIFFILTER < $LDIF > $LDIFFLT 192echo "Comparing filter output..." 193$CMP $SEARCHFLT $LDIFFLT > $CMPOUT 194 195if test $? != 0 ; then 196 echo "Comparison failed" 197 exit 1 198fi 199 200echo ">>>>> Test succeeded" 201 202test $KILLSERVERS != no && wait 203 204exit 0 205