]> git.sur5r.net Git - openldap/blob - tests/scripts/test006-acls
Use ordered input to slapadd(8) as required by back-bdb
[openldap] / tests / scripts / test006-acls
1 #! /bin/sh
2 # $OpenLDAP$
3
4 if test $# -eq 0 ; then
5         SRCDIR="."
6 else
7         SRCDIR=$1; shift
8 fi
9 if test $# -eq 1 ; then
10         BACKEND=$1; shift
11 fi
12
13 echo "running defines.sh $SRCDIR $BACKEND"
14 . $SRCDIR/scripts/defines.sh
15
16 echo "Cleaning up in $DBDIR..."
17
18 rm -f $DBDIR/[!C]*
19
20 echo "Running slapadd to build slapd database..."
21 $SLAPADD -f $CONF -l $LDIFORDERED
22 RC=$?
23 if test $RC != 0 ; then
24         echo "slapadd failed ($RC)!"
25         exit $RC
26 fi
27
28 echo "Starting slapd on TCP/IP port $PORT..."
29 $SLAPD -f $ACLCONF -h $MASTERURI -d $LVL $TIMING > $MASTERLOG 2>&1 &
30 PID=$!
31
32 echo "Testing slapd access control..."
33 for i in 0 1 2 3 4 5; do
34         $LDAPSEARCH -s base -b "$MONITOR" -h localhost -p $PORT \
35                 'objectclass=*' > /dev/null 2>&1
36         RC=$?
37         if test $RC = 1 ; then
38                 echo "Waiting 5 seconds for slapd to start..."
39                 sleep 5
40         fi
41 done
42
43 if test $RC != 0 ; then
44         echo "ldapsearch failed ($RC)!"
45         kill -HUP $PID
46         exit $RC
47 fi
48
49 cat /dev/null > $SEARCHOUT
50
51 #
52 # Try to read an entry inside the Alumni Association container.  It should
53 # give us nothing if we're not bound, and should return all attributes
54 # if we're bound as anyone under UM.
55 #
56 $LDAPSEARCH -b "$JAJDN" -h localhost -p $PORT "objectclass=*" \
57         >> $SEARCHOUT 2>&1
58
59 $LDAPSEARCH -b "$JAJDN" -h localhost -p $PORT \
60         -D "$BABSDN" -w bjensen "objectclass=*"  >> $SEARCHOUT 2>&1
61
62
63 #
64 # Try to add a "member" attribute to the "All Staff" group.  It should
65 # fail when we add some DN other than our own, and should succeed when
66 # we add our own DN.
67 # bjensen
68 $LDAPMODIFY -D "$JAJDN" -h localhost -p $PORT -w jaj > \
69         $TESTOUT 2>&1 << EOMODS1
70 version: 1
71 dn: cn=ITD Staff, ou=Groups, o=University of Michigan, c=US
72 changetype: modify
73 add: member
74 member: cn=Barbara Jensen, ou=Information Technology Division, ou=People, o=University of Michigan, c=US
75
76 EOMODS1
77
78 $LDAPMODIFY -D "$JAJDN" -h localhost -p $PORT -w jaj >> \
79         $TESTOUT 2>&1 << EOMODS2
80 version: 1
81
82 dn: cn=ITD Staff, ou=Groups, o=University of Michigan, c=US
83 changetype: modify
84 add: member
85 member: cn=James A Jones 1, ou=Alumni Association, ou=People, o=University of Michigan, c=US
86 EOMODS2
87
88 #
89 # Try to modify the "All Staff" group.  Two attempts are made:
90 # 1) bound as "James A Jones 1" - should fail
91 # 2) bound as "Barbara Jensen" - should succeed
92 #
93 $LDAPMODIFY -D "$JAJDN" -h localhost -p $PORT -w jaj >> \
94         $TESTOUT 2>&1 << EOMODS3
95
96 dn: cn=ITD Staff, ou=Groups, o=University of Michigan, c=US
97 changetype: modify
98 delete: member
99
100 EOMODS3
101
102 $LDAPMODIFY -D "$BJORNSDN" -h localhost -p $PORT -w bjorn >> \
103         $TESTOUT 2>&1 << EOMODS4
104 # COMMENT
105 version: 1
106 # comment
107 dn: cn=ITD Staff, ou=Groups, o=University of Michigan, c=US
108 # comment
109 changetype: modify
110 # comment
111 add: ou
112 # comment
113 ou: Groups
114 # comment
115 EOMODS4
116
117 echo "Using ldapsearch to retrieve all the entries..."
118 $LDAPSEARCH -S "" -b "$BASEDN" -h localhost -p $PORT \
119             'objectClass=*' | . $SRCDIR/scripts/acfilter.sh >> $SEARCHOUT 2>&1
120 RC=$?
121 kill -HUP $PID
122 if test $RC != 0 ; then
123         echo "ldapsearch failed ($RC)!"
124         exit $RC
125 fi
126
127 LDIF=$ACLOUTMASTER
128
129 echo "Filtering ldapsearch results..."
130 . $SRCDIR/scripts/acfilter.sh < $SEARCHOUT > $SEARCHFLT
131 echo "Filtering original ldif used to create database..."
132 . $SRCDIR/scripts/acfilter.sh < $LDIF > $LDIFFLT
133 echo "Comparing filter output..."
134 $CMP $SEARCHFLT $LDIFFLT > $CMPOUT
135
136 if test $? != 0 ; then
137         echo "comparison failed - modify operations did not complete correctly"
138         exit 1
139 fi
140
141 echo ">>>>> Test succeeded"
142
143
144 exit 0