1#! /bin/sh 2# OpenLDAP: pkg/ldap/tests/scripts/test004-modify,v 1.60.2.6 2010/04/19 19:14:32 quanah Exp 3## This work is part of OpenLDAP Software <http://www.openldap.org/>. 4## 5## Copyright 1998-2010 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 "Running slapadd to build slapd database..." 22. $CONFFILTER $BACKEND $MONITORDB < $CONF > $CONF1 23$SLAPADD -f $CONF1 -l $LDIFORDERED 24RC=$? 25if test $RC != 0 ; then 26 echo "slapadd failed ($RC)!" 27 exit $RC 28fi 29 30echo "Starting slapd on TCP/IP port $PORT1..." 31$SLAPD -f $CONF1 -h $URI1 -d $LVL $TIMING > $LOG1 2>&1 & 32PID=$! 33if test $WAIT != 0 ; then 34 echo PID $PID 35 read foo 36fi 37KILLPIDS="$PID" 38 39sleep 1 40 41echo "Testing slapd modify operations..." 42for i in 0 1 2 3 4 5; do 43 $LDAPSEARCH -s base -b "$MONITOR" -h $LOCALHOST -p $PORT1 \ 44 'objectclass=*' > /dev/null 2>&1 45 RC=$? 46 if test $RC = 0 ; then 47 break 48 fi 49 echo "Waiting 5 seconds for slapd to start..." 50 sleep 5 51done 52 53if test $RC != 0 ; then 54 echo "ldapsearch failed ($RC)!" 55 test $KILLSERVERS != no && kill -HUP $KILLPIDS 56 exit $RC 57fi 58 59echo "Testing modify, add, and delete..." 60$LDAPMODIFY -v -D "$MANAGERDN" -h $LOCALHOST -p $PORT1 -w $PASSWD > \ 61 $TESTOUT 2>&1 << EOMODS 62version: 1 63 64# LEADING COMMENT AND WHITE SPACE 65 66dn: cn=James A Jones 1,ou=Alumni Association,ou=People,dc=example,dc=com 67# EMBEDDED COMMENT 68changetype: modify 69add: drink 70drink: Pils 71- 72add: drink 73drink: Orange Juice 74- 75delete: drink 76drink: Pils 77- 78delete: sn 79sn: Jones 80- 81add: sn 82sn: Jones 83 84dn: cn=Bjorn Jensen,ou=Information Technology Division,ou=People,dc=example,dc=com 85changetype: modify 86# EMBEDDED COMMENT 87 CONTINUED 88replace: description 89description: The replaced multiLineDescription $ Blah Woof. 90- 91replace: drink 92drink: Iced Tea 93drink: Mad Dog 20/20 94 95dn: cn=ITD Staff,ou=Groups,dc=example,dc=com 96changetype: modify 97delete: uniquemember 98uniquemember: cn=James A Jones 2,ou=Information Technology Division, 99 ou=People,dc=example,dc=com 100uniquemember: cn=Bjorn Jensen,ou=Information Technology Division, 101 ou=People,dc=example,dc=com 102- 103add: uniquemember 104uniquemember: cn=Dorothy Stevens,ou=Alumni Association, 105 ou=People,dc=example,dc=com 106uniquemember: cn=James A Jones 1,ou=Alumni Association, 107 ou=People,dc=example,dc=com 108- 109add: objectClass 110objectClass: OpenLDAPdisplayableObject 111objectClass: pkiUser 112objectClass: userSecurityInformation 113- 114delete: objectClass 115objectClass: userSecurityInformation 116objectClass: pkiUser 117objectClass: OpenLDAPdisplayableObject 118 119dn: cn=All Staff,ou=Groups,dc=example,dc=com 120changetype: modify 121delete: member 122- 123add: member 124member: cn=Dorothy Stevens,ou=Alumni Association,ou=People,dc=example,dc=com 125- 126delete: description 127- 128add: objectClass 129objectClass: OpenLDAPdisplayableObject 130objectClass: pkiUser 131objectClass: userSecurityInformation 132- 133delete: objectClass 134objectClass: OpenLDAPdisplayableObject 135objectClass: pkiUser 136objectClass: userSecurityInformation 137 138dn: cn=Gern Jensen,ou=Information Technology Division,ou=People,dc=example,dc=com 139changetype: add 140objectclass: testPerson 141cn: Gern Jensen 142sn: Jensen 143uid: gjensen 144title: Chief Investigator, ITD 145postaladdress: ITD $ 535 W. William St $ Anytown, MI 48103 146seealso: cn=All Staff,ou=Groups,dc=example,dc=com 147drink: Coffee 148homepostaladdress: 844 Brown St. Apt. 4 $ Anytown, MI 48104 149description: Very odd 150facsimiletelephonenumber: +1 313 555 7557 151telephonenumber: +1 313 555 8343 152mail: gjensen@mailgw.example.com 153homephone: +1 313 555 8844 154testTime: 20050304001801.234Z 155 156dn: cn=James A Jones 2,ou=Information Technology Division,ou=People,dc=example,dc=com 157changetype: delete 158# TRAILING COMMENT AND WHITE SPACE 159 160dn: ou=People,dc=example,dc=com 161changetype: modify 162increment: uidNumber 163uidNumber: 1 164- 165increment: gidNumber 166gidNumber: -1 167 168dn: dc=example,dc=com 169changetype: modify 170# EMPTY SEQUENCE OF CHANGE 171 172EOMODS 173 174RC=$? 175if test $RC != 0 ; then 176 echo "ldapmodify failed ($RC)!" 177 test $KILLSERVERS != no && kill -HUP $KILLPIDS 178 exit $RC 179fi 180 181echo "Using ldapmodify to add an empty entry (should fail with protocolError)..." 182$LDAPMODIFY -D "$MANAGERDN" -h $LOCALHOST -p $PORT1 -w $PASSWD \ 183 >> $TESTOUT 2>&1 << EOMODS 184dn: cn=Foo Bar,dc=example,dc=com 185changetype: add 186# EMPTY SEQUENCE OF ATTRS 187EOMODS 188 189RC=$? 190case $RC in 1912) 192 echo " ldapmodify failed ($RC)" 193 ;; 1940) 195 echo " ldapmodify should have failed ($RC)!" 196 test $KILLSERVERS != no && kill -HUP $KILLPIDS 197 exit -1 198 ;; 199*) 200 echo " ldapmodify failed ($RC)!" 201 test $KILLSERVERS != no && kill -HUP $KILLPIDS 202 exit $RC 203 ;; 204esac 205 206echo "Using ldapsearch to retrieve all the entries..." 207$LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT1 \ 208 'objectClass=*' > $SEARCHOUT 2>&1 209RC=$? 210test $KILLSERVERS != no && kill -HUP $KILLPIDS 211if test $RC != 0 ; then 212 echo "ldapsearch failed ($RC)!" 213 exit $RC 214fi 215 216LDIF=$MODIFYOUTMASTER 217 218echo "Filtering ldapsearch results..." 219$LDIFFILTER < $SEARCHOUT > $SEARCHFLT 220echo "Filtering original ldif used to create database..." 221$LDIFFILTER < $LDIF > $LDIFFLT 222echo "Comparing filter output..." 223$CMP $SEARCHFLT $LDIFFLT > $CMPOUT 224 225if test $? != 0 ; then 226 echo "comparison failed - modify operations did not complete correctly" 227 exit 1 228fi 229 230echo ">>>>> Test succeeded" 231 232test $KILLSERVERS != no && wait 233 234exit 0 235