1#! /bin/sh
2# OpenLDAP: pkg/ldap/tests/scripts/test051-config-undo,v 1.2.2.5 2010/04/13 20:24:06 kurt 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
21$SLAPPASSWD -g -n >$CONFIGPWF
22echo "rootpw `$SLAPPASSWD -T $CONFIGPWF`" >$TESTDIR/configpw.conf
23
24echo "Running slapadd to build slapd database..."
25. $CONFFILTER $BACKEND $MONITORDB < $UNDOCONF > $CONF1
26$SLAPADD -f $CONF1 <<EOF
27dn: o=undo
28objectClass: organization
29o: undo
30
31EOF
32RC=$?
33if test $RC != 0 ; then
34	echo "slapadd failed ($RC)!"
35	exit $RC
36fi
37
38echo "Starting slapd on TCP/IP port $PORT1..."
39mkdir $TESTDIR/confdir
40$SLAPD -f $CONF1 -F $TESTDIR/confdir -h $URI1 -d $LVL $TIMING > $LOG1 2>&1 &
41PID=$!
42if test $WAIT != 0 ; then
43    echo PID $PID
44    read foo
45fi
46KILLPIDS="$PID"
47
48sleep 1
49for i in 0 1 2 3 4 5; do
50	$LDAPSEARCH -s base -b "$MONITOR" -h $LOCALHOST -p $PORT1 \
51		'objectclass=*' > /dev/null 2>&1
52	RC=$?
53	if test $RC = 0 ; then
54		break
55	fi
56	echo "Waiting 5 seconds for slapd to start..."
57	sleep 5
58done
59if test $RC != 0 ; then
60	echo "ldapsearch failed ($RC)!"
61	test $KILLSERVERS != no && kill -HUP $KILLPIDS
62	exit $RC
63fi
64
65echo Dynamically assaulting the schema
66$LDAPMODIFY -D cn=config -h $LOCALHOST -p $PORT1 -y $CONFIGPWF \
67    > $TESTOUT 2>&1 <<EOF
68dn: cn={0}core,cn=schema,cn=config
69changetype: modify
70replace: olcObjectClasses
71olcObjectClasses: ( rawr )
72-
73EOF
74RC=$?
75if test $RC != 80 ; then
76	echo "invalid objectclass modify allowed ($RC)"
77	test $KILLSERVERS != no && kill -HUP $KILLPIDS
78	exit -1
79fi
80
81$LDAPMODIFY -D cn=config -h $LOCALHOST -p $PORT1 -y $CONFIGPWF \
82    > $TESTOUT 2>&1 <<EOF
83dn: cn={0}core,cn=schema,cn=config
84changetype: modify
85replace: olcAttributeTypes
86olcAttributeTypes: ( rawr )
87-
88EOF
89RC=$?
90if test $RC != 80 ; then
91	echo "invalid attributeType modify allowed ($RC)"
92	test $KILLSERVERS != no && kill -HUP $KILLPIDS
93	exit -1
94fi
95
96echo Surveying the damage
97$LDAPMODIFY -D "cn=manager,o=undo" -w secret -h $LOCALHOST -p $PORT1 <<EOF
98dn: o=foo,o=undo
99changetype: add
100objectClass: organization
101o: foo
102
103EOF
104RC=$?
105if test $RC != 0 ; then
106    echo "schema destroyed by an unsuccessful operation"
107    test $KILLSERVERS != no && kill -HUP $KILLPIDS
108    exit -1
109fi
110
111test $KILLSERVERS != no && kill -HUP $KILLPIDS
112
113echo ">>>>> Test succeeded"
114
115test $KILLSERVERS != no && wait
116
117exit 0
118