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