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 mkdir -p $TESTDIR $DBDIR1A $DBDIR1B 20 21 echo "Running slapadd to build slapd database..." 22 . $CONFFILTER $BACKEND < $CONF2DB > $CONF1 23 $SLAPADD -f $CONF1 -b "$BASEDN" -l $LDIFORDERED 24 RC=$? 25 if test $RC != 0 ; then 26 echo "slapadd failed ($RC)!" 27 exit $RC 28 fi 29 30 echo "Starting slapd on TCP/IP port $PORT1..." 31 $SLAPD -f $CONF1 -h $URI1 -d $LVL > $LOG1 2>&1 & 32 PID=$! 33 if test $WAIT != 0 ; then 34 echo PID $PID 35 read foo 36 fi 37 KILLPIDS="$PID" 38 39 sleep 1 40 41 echo "Testing slapd modrdn operations..." 42 43 # Make sure we can search the database 44 for i in 0 1 2 3 4 5; do 45 $LDAPSEARCH -S "" -b "$BASEDN" -H $URI1 \ 46 'objectClass=*' > $INITOUT 2>&1 47 RC=$? 48 if test $RC = 0 ; then 49 break 50 fi 51 echo "Waiting 5 seconds for slapd to start..." 52 sleep 5 53 done 54 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 # -r used to do remove of old rdn 62 63 echo "Testing modrdn(deleteoldrdn=0)..." 64 $LDAPMODRDN -D "$MANAGERDN" -H $URI1 -w $PASSWD > \ 65 $TESTOUT 2>&1 'cn=James A Jones 1, ou=Alumni Association, ou=People, dc=example, dc=com' 'cn=James A Jones III' 66 67 RC=$? 68 if test $RC != 0 ; then 69 echo "ldapmodrdn failed ($RC)!" 70 test $KILLSERVERS != no && kill -HUP $KILLPIDS 71 exit $RC 72 fi 73 74 echo "Testing modrdn(deleteoldrdn=1)..." 75 $LDAPMODRDN -D "$MANAGERDN" -r -H $URI1 -w $PASSWD >> \ 76 $TESTOUT 2>&1 'cn=James A Jones 2, ou=Information Technology Division, ou=People, dc=example, dc=com' 'cn=James A Jones II' 77 78 RC=$? 79 if test $RC != 0 ; then 80 echo "ldapmodrdn failed ($RC)!" 81 test $KILLSERVERS != no && kill -HUP $KILLPIDS 82 exit $RC 83 fi 84 85 # Ensure the new rdn's can be found 86 87 echo "Using ldapsearch to retrieve entries using new rdn (cn=James A Jones III)..." 88 $LDAPSEARCH -S "" -b "$BASEDN" -H $URI1 \ 89 'cn=James A Jones III' > $SEARCHOUT 2>&1 90 RC=$? 91 if test $RC != 0 ; then 92 echo "ldapsearch failed ($RC)!" 93 test $KILLSERVERS != no && kill -HUP $KILLPIDS 94 exit $RC 95 fi 96 97 98 LDIF=$MODRDNOUTPROVIDER1 99 100 echo "Filtering ldapsearch results..." 101 $LDIFFILTER < $SEARCHOUT > $SEARCHFLT 102 echo "Filtering original ldif used to create database..." 103 $LDIFFILTER < $LDIF > $LDIFFLT 104 echo "Comparing filter output..." 105 $CMP $SEARCHFLT $LDIFFLT > $CMPOUT 106 107 if test $? != 0 ; then 108 echo "comparison failed - modrdn operations did not complete correctly" 109 test $KILLSERVERS != no && kill -HUP $KILLPIDS 110 exit 1 111 fi 112 113 114 echo "Using ldapsearch to retrieve entries using new rdn (cn=James A Jones II)..." 115 $LDAPSEARCH -S "" -b "$BASEDN" -H $URI1 \ 116 'cn=James A Jones II' > $SEARCHOUT 2>&1 117 RC=$? 118 if test $RC != 0 ; then 119 echo "ldapsearch failed ($RC)!" 120 test $KILLSERVERS != no && kill -HUP $KILLPIDS 121 exit $RC 122 fi 123 124 125 LDIF=$MODRDNOUTPROVIDER2 126 127 echo "Filtering ldapsearch results..." 128 $LDIFFILTER < $SEARCHOUT > $SEARCHFLT 129 echo "Filtering original ldif used to create database..." 130 $LDIFFILTER < $LDIF > $LDIFFLT 131 echo "Comparing filter output..." 132 $CMP $SEARCHFLT $LDIFFLT > $CMPOUT 133 134 if test $? != 0 ; then 135 echo "comparison failed - modrdn operations did not complete correctly" 136 test $KILLSERVERS != no && kill -HUP $KILLPIDS 137 exit 1 138 fi 139 140 # Ensure that you cannot find the entry for which the rdn was deleted as 141 # an attribute. 142 143 echo "Using ldapsearch to retrieve entries using removed rdn (cn=James A Jones 2)..." 144 $LDAPSEARCH -S "" -b "$BASEDN" -H $URI1 \ 145 'cn=James A Jones 2' > $SEARCHOUT 2>&1 146 RC=$? 147 if test $RC != 0 ; then 148 test $KILLSERVERS != no && kill -HUP $KILLPIDS 149 echo "ldapsearch failed ($RC)!" 150 exit $RC 151 fi 152 $CMP $SEARCHOUT - < /dev/null > $CMPOUT 153 if test $? != 0 ; then 154 echo "failure: ldapsearch found attribute that was to be removed!" 155 test $KILLSERVERS != no && kill -HUP $KILLPIDS 156 exit 1 157 fi 158 159 echo "Using ldapsearch to retrieve all the entries..." 160 $LDAPSEARCH -S "" -b "$BASEDN" -H $URI1 \ 161 'objectClass=*' > $SEARCHOUT 2>&1 162 RC=$? 163 if test $RC != 0 ; then 164 test $KILLSERVERS != no && kill -HUP $KILLPIDS 165 echo "ldapsearch failed ($RC)!" 166 exit $RC 167 fi 168 169 LDIF=$MODRDNOUTPROVIDER0 170 171 echo "Filtering ldapsearch results..." 172 $LDIFFILTER < $SEARCHOUT > $SEARCHFLT 173 echo "Filtering original ldif used to create database..." 174 $LDIFFILTER < $LDIF > $LDIFFLT 175 echo "Comparing filter output..." 176 $CMP $SEARCHFLT $LDIFFLT > $CMPOUT 177 178 if test $? != 0 ; then 179 echo "comparison failed - modrdn operations did not complete correctly" 180 test $KILLSERVERS != no && kill -HUP $KILLPIDS 181 exit 1 182 fi 183 184 # Test that you can use modrdn with an attribute value which was previously 185 # present 186 187 echo "Testing modrdn(deleteoldrdn=1), modrdn with new rdn already an att val..." 188 $LDAPMODRDN -D "$MANAGERDN" -r -H $URI1 -w $PASSWD > \ 189 /dev/null 2>&1 'cn=James A Jones III, ou=Alumni Association, ou=People, dc=example, dc=com' 'cn=James A Jones 1' 190 191 RC=$? 192 if test $RC != 0 ; then 193 echo "ldapmodrdn failed ($RC)!" 194 test $KILLSERVERS != no && kill -HUP $KILLPIDS 195 exit $RC 196 fi 197 198 echo "Using ldapsearch to retrieve entries using new rdn (cn=James A Jones 1)..." 199 $LDAPSEARCH -S "" -b "$BASEDN" -H $URI1 \ 200 'cn=James A Jones 1' > $SEARCHOUT 2>&1 201 RC=$? 202 203 if test $RC != 0 ; then 204 echo "ldapsearch failed ($RC)!" 205 test $KILLSERVERS != no && kill -HUP $KILLPIDS 206 exit $RC 207 fi 208 209 LDIF=$MODRDNOUTPROVIDER3 210 211 echo "Filtering ldapsearch results..." 212 $LDIFFILTER < $SEARCHOUT > $SEARCHFLT 213 echo "Filtering original ldif used to create database..." 214 $LDIFFILTER < $LDIF > $LDIFFLT 215 echo "Comparing filter output..." 216 $CMP $SEARCHFLT $LDIFFLT > $CMPOUT 217 218 if test $? != 0 ; then 219 echo "comparison failed - modrdn operations did not complete correctly" 220 test $KILLSERVERS != no && kill -HUP $KILLPIDS 221 exit 1 222 fi 223 224 echo "Testing modrdn to another database (should fail with affectsMultipleDSAs)" 225 $LDAPMODRDN -D "$MANAGERDN" -H $URI1 -w $PASSWD > \ 226 $TESTOUT 2>&1 'cn=All Staff,ou=Groups,dc=example,dc=com' 'cn=Everyone' 227 RC=$? 228 case $RC in 229 0) 230 echo "ldapmodrdn succeeded, should have failed!" 231 test $KILLSERVERS != no && kill -HUP $KILLPIDS 232 exit 1 233 ;; 234 71) 235 ;; 236 *) 237 echo "ldapmodrdn failed ($RC)!" 238 test $KILLSERVERS != no && kill -HUP $KILLPIDS 239 exit $RC 240 ;; 241 esac 242 243 echo "Testing modrdn with newSuperior = target (should fail with unwillingToPerform)" 244 $LDAPMODRDN -D "$MANAGERDN" -H $URI1 -w $PASSWD > \ 245 $TESTOUT 2>&1 -s 'cn=James A Jones 1, ou=Alumni Association, ou=People, dc=example, dc=com' \ 246 'cn=James A Jones 1, ou=Alumni Association, ou=People, dc=example, dc=com' 'cn=James A Jones 1' 247 248 RC=$? 249 case $RC in 250 0) 251 echo "ldapmodrdn succeeded, should have failed!" 252 test $KILLSERVERS != no && kill -HUP $KILLPIDS 253 exit 1 254 ;; 255 53) 256 ;; 257 *) 258 echo "ldapmodrdn failed ($RC)!" 259 test $KILLSERVERS != no && kill -HUP $KILLPIDS 260 exit $RC 261 ;; 262 esac 263 264 echo "Testing modrdn with newRdn exact same as target..." 265 $LDAPMODRDN -D "$MANAGERDN" -H $URI1 -w $PASSWD > \ 266 $TESTOUT 2>&1 'cn=James A Jones 1, ou=Alumni Association, ou=People, dc=example, dc=com' 'cn=James A Jones 1' 267 268 RC=$? 269 case $RC in 270 0) 271 ;; 272 *) 273 echo "ldapmodrdn failed ($RC)!" 274 test $KILLSERVERS != no && kill -HUP $KILLPIDS 275 exit $RC 276 ;; 277 esac 278 279 echo "Testing modrdn with newRdn same as target, changed case..." 280 $LDAPMODRDN -D "$MANAGERDN" -H $URI1 -w $PASSWD > \ 281 $TESTOUT 2>&1 'cn=James A Jones 1, ou=Alumni Association, ou=People, dc=example, dc=com' 'cn=James A JONES 1' 282 283 RC=$? 284 case $RC in 285 0) 286 ;; 287 *) 288 echo "ldapmodrdn failed ($RC)!" 289 test $KILLSERVERS != no && kill -HUP $KILLPIDS 290 exit $RC 291 ;; 292 esac 293 294 test $KILLSERVERS != no && kill -HUP $KILLPIDS 295 296 echo ">>>>> Test succeeded" 297 298 test $KILLSERVERS != no && wait 299 300 exit 0 301