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