]> git.sur5r.net Git - openldap/blob - tests/scripts/test051-config-undo
Happy new year (belated)
[openldap] / tests / scripts / test051-config-undo
1 #! /bin/sh
2 # $OpenLDAP$
3 ## This work is part of OpenLDAP Software <http://www.openldap.org/>.
4 ##
5 ## Copyright 1998-2014 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 $DBDIR1
20
21 $SLAPPASSWD -g -n >$CONFIGPWF
22 echo "rootpw `$SLAPPASSWD -T $CONFIGPWF`" >$TESTDIR/configpw.conf
23
24 echo "Running slapadd to build slapd database..."
25 . $CONFFILTER $BACKEND $MONITORDB < $UNDOCONF > $CONF1
26 $SLAPADD -f $CONF1 <<EOF
27 dn: o=undo
28 objectClass: organization
29 o: undo
30
31 EOF
32 RC=$?
33 if test $RC != 0 ; then
34         echo "slapadd failed ($RC)!"
35         exit $RC
36 fi
37
38 echo "Starting slapd on TCP/IP port $PORT1..."
39 mkdir $TESTDIR/confdir
40 $SLAPD -f $CONF1 -F $TESTDIR/confdir -h $URI1 -d $LVL $TIMING > $LOG1 2>&1 &
41 PID=$!
42 if test $WAIT != 0 ; then
43     echo PID $PID
44     read foo
45 fi
46 KILLPIDS="$PID"
47
48 sleep 1
49 for 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
58 done
59 if test $RC != 0 ; then
60         echo "ldapsearch failed ($RC)!"
61         test $KILLSERVERS != no && kill -HUP $KILLPIDS
62         exit $RC
63 fi
64
65 echo Dynamically assaulting the schema
66 $LDAPMODIFY -D cn=config -h $LOCALHOST -p $PORT1 -y $CONFIGPWF \
67     > $TESTOUT 2>&1 <<EOF
68 dn: cn={0}core,cn=schema,cn=config
69 changetype: modify
70 replace: olcObjectClasses
71 olcObjectClasses: ( rawr )
72 -
73 EOF
74 RC=$?
75 if test $RC != 80 ; then
76         echo "invalid objectclass modify allowed ($RC)"
77         test $KILLSERVERS != no && kill -HUP $KILLPIDS
78         exit -1
79 fi
80
81 $LDAPMODIFY -D cn=config -h $LOCALHOST -p $PORT1 -y $CONFIGPWF \
82     > $TESTOUT 2>&1 <<EOF
83 dn: cn={0}core,cn=schema,cn=config
84 changetype: modify
85 replace: olcAttributeTypes
86 olcAttributeTypes: ( rawr )
87 -
88 EOF
89 RC=$?
90 if test $RC != 80 ; then
91         echo "invalid attributeType modify allowed ($RC)"
92         test $KILLSERVERS != no && kill -HUP $KILLPIDS
93         exit -1
94 fi
95
96 echo Surveying the damage
97 $LDAPMODIFY -D "cn=manager,o=undo" -w secret -h $LOCALHOST -p $PORT1 <<EOF
98 dn: o=foo,o=undo
99 changetype: add
100 objectClass: organization
101 o: foo
102
103 EOF
104 RC=$?
105 if test $RC != 0 ; then
106     echo "schema destroyed by an unsuccessful operation"
107     test $KILLSERVERS != no && kill -HUP $KILLPIDS
108     exit -1
109 fi
110
111 test $KILLSERVERS != no && kill -HUP $KILLPIDS
112
113 echo ">>>>> Test succeeded"
114
115 test $KILLSERVERS != no && wait
116
117 exit 0