xref: /netbsd-src/external/bsd/openldap/dist/tests/scripts/test051-config-undo (revision e670fd5c413e99c2f6a37901bb21c537fcd322d2)
12de962bdSlukem#! /bin/sh
2d11b170bStron# $OpenLDAP$
32de962bdSlukem## This work is part of OpenLDAP Software <http://www.openldap.org/>.
42de962bdSlukem##
5*e670fd5cSchristos## Copyright 1998-2021 The OpenLDAP Foundation.
62de962bdSlukem## All rights reserved.
72de962bdSlukem##
82de962bdSlukem## Redistribution and use in source and binary forms, with or without
92de962bdSlukem## modification, are permitted only as authorized by the OpenLDAP
102de962bdSlukem## Public License.
112de962bdSlukem##
122de962bdSlukem## A copy of this license is available in the file LICENSE in the
132de962bdSlukem## top-level directory of the distribution or, alternatively, at
142de962bdSlukem## <http://www.OpenLDAP.org/license.html>.
152de962bdSlukem
162de962bdSlukemecho "running defines.sh"
172de962bdSlukem. $SRCDIR/scripts/defines.sh
182de962bdSlukem
192de962bdSlukemmkdir -p $TESTDIR $DBDIR1
202de962bdSlukem
212de962bdSlukem$SLAPPASSWD -g -n >$CONFIGPWF
222de962bdSlukemecho "rootpw `$SLAPPASSWD -T $CONFIGPWF`" >$TESTDIR/configpw.conf
232de962bdSlukem
242de962bdSlukemecho "Running slapadd to build slapd database..."
25*e670fd5cSchristos. $CONFFILTER $BACKEND < $UNDOCONF > $CONF1
262de962bdSlukem$SLAPADD -f $CONF1 <<EOF
272de962bdSlukemdn: o=undo
282de962bdSlukemobjectClass: organization
292de962bdSlukemo: undo
302de962bdSlukem
312de962bdSlukemEOF
322de962bdSlukemRC=$?
332de962bdSlukemif test $RC != 0 ; then
342de962bdSlukem	echo "slapadd failed ($RC)!"
352de962bdSlukem	exit $RC
362de962bdSlukemfi
372de962bdSlukem
382de962bdSlukemecho "Starting slapd on TCP/IP port $PORT1..."
392de962bdSlukemmkdir $TESTDIR/confdir
40*e670fd5cSchristos$SLAPD -f $CONF1 -F $TESTDIR/confdir -h $URI1 -d $LVL > $LOG1 2>&1 &
412de962bdSlukemPID=$!
422de962bdSlukemif test $WAIT != 0 ; then
432de962bdSlukem    echo PID $PID
442de962bdSlukem    read foo
452de962bdSlukemfi
462de962bdSlukemKILLPIDS="$PID"
472de962bdSlukem
482de962bdSlukemsleep 1
492de962bdSlukemfor i in 0 1 2 3 4 5; do
50*e670fd5cSchristos	$LDAPSEARCH -s base -b "$MONITOR" -H $URI1 \
512de962bdSlukem		'objectclass=*' > /dev/null 2>&1
522de962bdSlukem	RC=$?
532de962bdSlukem	if test $RC = 0 ; then
542de962bdSlukem		break
552de962bdSlukem	fi
562de962bdSlukem	echo "Waiting 5 seconds for slapd to start..."
572de962bdSlukem	sleep 5
582de962bdSlukemdone
592de962bdSlukemif test $RC != 0 ; then
602de962bdSlukem	echo "ldapsearch failed ($RC)!"
612de962bdSlukem	test $KILLSERVERS != no && kill -HUP $KILLPIDS
622de962bdSlukem	exit $RC
632de962bdSlukemfi
642de962bdSlukem
652de962bdSlukemecho Dynamically assaulting the schema
66*e670fd5cSchristos$LDAPMODIFY -D cn=config -H $URI1 -y $CONFIGPWF \
672de962bdSlukem    > $TESTOUT 2>&1 <<EOF
682de962bdSlukemdn: cn={0}core,cn=schema,cn=config
692de962bdSlukemchangetype: modify
702de962bdSlukemreplace: olcObjectClasses
712de962bdSlukemolcObjectClasses: ( rawr )
722de962bdSlukem-
732de962bdSlukemEOF
742de962bdSlukemRC=$?
752de962bdSlukemif test $RC != 80 ; then
762de962bdSlukem	echo "invalid objectclass modify allowed ($RC)"
772de962bdSlukem	test $KILLSERVERS != no && kill -HUP $KILLPIDS
782de962bdSlukem	exit -1
792de962bdSlukemfi
802de962bdSlukem
81*e670fd5cSchristos$LDAPMODIFY -D cn=config -H $URI1 -y $CONFIGPWF \
822de962bdSlukem    > $TESTOUT 2>&1 <<EOF
832de962bdSlukemdn: cn={0}core,cn=schema,cn=config
842de962bdSlukemchangetype: modify
852de962bdSlukemreplace: olcAttributeTypes
862de962bdSlukemolcAttributeTypes: ( rawr )
872de962bdSlukem-
882de962bdSlukemEOF
892de962bdSlukemRC=$?
902de962bdSlukemif test $RC != 80 ; then
912de962bdSlukem	echo "invalid attributeType modify allowed ($RC)"
922de962bdSlukem	test $KILLSERVERS != no && kill -HUP $KILLPIDS
932de962bdSlukem	exit -1
942de962bdSlukemfi
952de962bdSlukem
962de962bdSlukemecho Surveying the damage
97*e670fd5cSchristos$LDAPMODIFY -D "cn=manager,o=undo" -w secret -H $URI1 <<EOF
982de962bdSlukemdn: o=foo,o=undo
992de962bdSlukemchangetype: add
1002de962bdSlukemobjectClass: organization
1012de962bdSlukemo: foo
1022de962bdSlukem
1032de962bdSlukemEOF
1042de962bdSlukemRC=$?
1052de962bdSlukemif test $RC != 0 ; then
1062de962bdSlukem    echo "schema destroyed by an unsuccessful operation"
1072de962bdSlukem    test $KILLSERVERS != no && kill -HUP $KILLPIDS
1082de962bdSlukem    exit -1
1092de962bdSlukemfi
1102de962bdSlukem
1112de962bdSlukemtest $KILLSERVERS != no && kill -HUP $KILLPIDS
1122de962bdSlukem
1132de962bdSlukemecho ">>>>> Test succeeded"
1142de962bdSlukem
1152de962bdSlukemtest $KILLSERVERS != no && wait
1162de962bdSlukem
1172de962bdSlukemexit 0
118