pidl: Change PyGetSetDef in generated python bindings to use C99 initialisers
[obnox/samba/samba-obnox.git] / testprogs / blackbox / test_ldb.sh
1 #!/bin/sh
2
3 if [ $# -lt 2 ]; then
4 cat <<EOF
5 Usage: test_ldb.sh PROTOCOL SERVER [OPTIONS]
6 EOF
7 exit 1;
8 fi
9
10
11 p=$1
12 SERVER=$2
13 PREFIX=$3
14 shift 2
15 options="$*"
16
17 . `dirname $0`/subunit.sh
18
19 check() {
20         name="$1"
21         shift
22         cmdline="$*"
23         echo "test: $name"
24         $cmdline
25         status=$?
26         if [ x$status = x0 ]; then
27                 echo "success: $name"
28         else
29                 echo "failure: $name"
30                 failed=`expr $failed + 1`
31         fi
32         return $status
33 }
34
35 export PATH="$BINDIR:$PATH"
36
37 ldbsearch="$VALGRIND ldbsearch"
38
39 check "RootDSE" $ldbsearch $CONFIGURATION $options --basedn='' -H $p://$SERVER -s base DUMMY=x dnsHostName highestCommittedUSN || failed=`expr $failed + 1`
40 check "RootDSE (full)" $ldbsearch $CONFIGURATION $options --basedn='' -H $p://$SERVER -s base '(objectClass=*)' || failed=`expr $failed + 1`
41 check "RootDSE (extended)" $ldbsearch $CONFIGURATION $options --basedn='' -H $p://$SERVER -s base '(objectClass=*)' --extended-dn || failed=`expr $failed + 1`
42 if [ x$p = x"ldaps" ]; then
43    testit_expect_failure "RootDSE over SSLv3 should fail" $ldbsearch $CONFIGURATION $options --basedn='' -H $p://$SERVER -s base DUMMY=x dnsHostName highestCommittedUSN --option='tlspriority=NONE:+VERS-SSL3.0:+MAC-ALL:+CIPHER-ALL:+RSA:+SIGN-ALL:+COMP-NULL' && failed=`expr $failed + 1`
44 fi
45
46 echo "Getting defaultNamingContext"
47 BASEDN=`$ldbsearch $CONFIGURATION $options --basedn='' -H $p://$SERVER -s base DUMMY=x defaultNamingContext | grep defaultNamingContext | awk '{print $2}'`
48 echo "BASEDN is $BASEDN"
49
50 check "Listing Users" $ldbsearch $options $CONFIGURATION -H $p://$SERVER '(objectclass=user)' sAMAccountName || failed=`expr $failed + 1`
51
52 check "Listing Users (sorted)" $ldbsearch -S $options $CONFIGURATION -H $p://$SERVER '(objectclass=user)' sAMAccountName || failed=`expr $failed + 1`
53
54 check "Listing Groups" $ldbsearch $options $CONFIGURATION -H $p://$SERVER '(objectclass=group)' sAMAccountName || failed=`expr $failed + 1`
55
56 nentries=`$ldbsearch $options -H $p://$SERVER $CONFIGURATION '(|(|(&(!(groupType:1.2.840.113556.1.4.803:=1))(groupType:1.2.840.113556.1.4.803:=2147483648)(groupType:1.2.840.113556.1.4.804:=10))(samAccountType=805306368))(samAccountType=805306369))' sAMAccountName | grep sAMAccountName | wc -l`
57 echo "Found $nentries entries"
58 if [ $nentries -lt 10 ]; then
59 echo "Should have found at least 10 entries"
60 failed=`expr $failed + 1`
61 fi
62
63 echo "Check rootDSE for Controls"
64 nentries=`$ldbsearch $options $CONFIGURATION -H $p://$SERVER -s base -b "" '(objectclass=*)' | grep -i supportedControl | wc -l`
65 if [ $nentries -lt 4 ]; then
66 echo "Should have found at least 4 entries"
67 failed=`expr $failed + 1`
68 fi
69
70 echo "Test Paged Results Control"
71 nentries=`$ldbsearch $options $CONFIGURATION -H $p://$SERVER --controls=paged_results:1:5 '(objectclass=user)' | grep sAMAccountName | wc -l`
72 if [ $nentries -lt 1 ]; then
73 echo "Paged Results Control test returned 0 items"
74 failed=`expr $failed + 1`
75 fi
76
77 echo "Test Server Sort Control"
78 nentries=`$ldbsearch $options $CONFIGURATION -H $p://$SERVER --controls=server_sort:1:0:sAMAccountName '(objectclass=user)' | grep sAMAccountName | wc -l`
79 if [ $nentries -lt 1 ]; then
80 echo "Server Sort Control test returned 0 items"
81 failed=`expr $failed + 1`
82 fi
83
84 echo "Test Extended DN Control"
85 nentries=`$ldbsearch $options $CONFIGURATION -H $p://$SERVER --controls=extended_dn:1 '(objectclass=user)' | grep sAMAccountName | wc -l`
86 if [ $nentries -lt 1 ]; then
87 echo "Extended DN Control test returned 0 items"
88 failed=`expr $failed + 1`
89 fi
90 nentries=`$ldbsearch $options $CONFIGURATION -H $p://$SERVER --controls=extended_dn:1:0 '(objectclass=user)' | grep sAMAccountName | wc -l`
91 if [ $nentries -lt 1 ]; then
92 echo "Extended DN Control test returned 0 items"
93 failed=`expr $failed + 1`
94 fi
95 nentries=`$ldbsearch $options $CONFIGURATION -H $p://$SERVER --controls=extended_dn:1:1 '(objectclass=user)' | grep sAMAccountName | wc -l`
96 if [ $nentries -lt 1 ]; then
97 echo "Extended DN Control test returned 0 items"
98 failed=`expr $failed + 1`
99 fi
100
101 echo "Test Domain scope Control"
102 nentries=`$ldbsearch $options $CONFIGURATION -H $p://$SERVER --controls=domain_scope:1 '(objectclass=user)' | grep sAMAccountName | wc -l`
103 if [ $nentries -lt 1 ]; then
104 echo "Extended Domain scope Control test returned 0 items"
105 failed=`expr $failed + 1`
106 fi
107
108 echo "Test Attribute Scope Query Control"
109 nentries=`$ldbsearch $options $CONFIGURATION -H $p://$SERVER --controls=asq:1:member -s base -b "CN=Administrators,CN=Builtin,$BASEDN" | grep sAMAccountName | wc -l`
110 if [ $nentries -lt 1 ]; then
111 echo "Attribute Scope Query test returned 0 items"
112 failed=`expr $failed + 1`
113 fi
114
115 echo "Test Search Options Control"
116 nentries=`$ldbsearch $options $CONFIGURATION -H $p://$SERVER --controls=search_options:1:2 '(objectclass=crossRef)' | grep crossRef | wc -l`
117 if [ $nentries -lt 1 ]; then
118 echo "Search Options Control Query test returned 0 items"
119 failed=`expr $failed + 1`
120 fi
121
122 echo "Test Search Options Control with Domain Scope Control"
123 nentries=`$ldbsearch $options $CONFIGURATION -H $p://$SERVER --controls=search_options:1:2,domain_scope:1 '(objectclass=crossRef)' | grep crossRef | wc -l`
124 if [ $nentries -lt 1 ]; then
125 echo "Search Options Control Query test returned 0 items"
126 failed=`expr $failed + 1`
127 fi
128
129 wellknown_object_test()
130 (
131         guid=$1
132         object=$2
133         failed=0
134
135         basedns="<WKGUID=${guid},${BASEDN}> <wkGuId=${guid},${BASEDN}>"
136         for dn in ${basedns}; do
137                 echo "Test ${dn} => ${object}"
138                 r=`$ldbsearch $options $CONFIGURATION -H $p://$SERVER '(objectClass=*)' -b "${dn}" | grep 'dn: '`
139                 n=`echo "${r}" | grep 'dn: ' | wc -l`
140                 c=`echo "${r}" | grep "${object}" | wc -l`
141
142                 if [ $n -lt 1 ]; then
143                         echo "Object not found by WKGUID"
144                         failed=`expr $failed + 1`
145                         continue
146                 fi
147                 if [ $c -lt 1 ]; then
148                         echo "Wrong object found by WKGUID: [${r}]"
149                         failed=`expr $failed + 1`
150                         continue
151                 fi
152         done
153
154         return $failed
155 )
156
157 wellknown_object_test 22B70C67D56E4EFB91E9300FCA3DC1AA ForeignSecurityPrincipals
158 st=$?
159 if [ x"$st" != x"0" ]; then
160         failed=`expr $failed + $st`
161 fi
162 wellknown_object_test 2FBAC1870ADE11D297C400C04FD8D5CD Infrastructure
163 st=$?
164 if [ x"$st" != x"0" ]; then
165         failed=`expr $failed + $st`
166 fi
167 wellknown_object_test AB1D30F3768811D1ADED00C04FD8D5CD System
168 st=$?
169 if [ x"$st" != x"0" ]; then
170         failed=`expr $failed + $st`
171 fi
172 wellknown_object_test A361B2FFFFD211D1AA4B00C04FD7D83A Domain Controllers
173 st=$?
174 if [ x"$st" != x"0" ]; then
175         failed=`expr $failed + $st`
176 fi
177 wellknown_object_test AA312825768811D1ADED00C04FD8D5CD Computers
178 st=$?
179 if [ x"$st" != x"0" ]; then
180         failed=`expr $failed + $st`
181 fi
182 wellknown_object_test A9D1CA15768811D1ADED00C04FD8D5CD Users
183 st=$?
184 if [ x"$st" != x"0" ]; then
185         failed=`expr $failed + $st`
186 fi
187
188 echo "Getting HEX GUID/SID of $BASEDN"
189 HEXDN=`$ldbsearch $CONFIGURATION $options -b "$BASEDN" -H $p://$SERVER -s base "(objectClass=*)" --controls=extended_dn:1:0 distinguishedName | grep 'distinguishedName: ' | cut -d ' ' -f2-`
190 HEXGUID=`echo "$HEXDN" | cut -d ';' -f1`
191 echo "HEXGUID[$HEXGUID]"
192
193 echo "Getting STR GUID/SID of $BASEDN"
194 STRDN=`$ldbsearch $CONFIGURATION $options -b "$BASEDN" -H $p://$SERVER -s base "(objectClass=*)" --controls=extended_dn:1:1 distinguishedName | grep 'distinguishedName: ' | cut -d ' ' -f2-`
195 echo "STRDN: $STRDN"
196 STRGUID=`echo "$STRDN" | cut -d ';' -f1`
197 echo "STRGUID[$STRGUID]"
198
199 echo "Getting STR GUID/SID of $BASEDN"
200 STRDN=`$ldbsearch $CONFIGURATION $options -b "$BASEDN" -H $p://$SERVER -s base "(objectClass=*)" --controls=extended_dn:1:1 | grep 'dn: ' | cut -d ' ' -f2-`
201 echo "STRDN: $STRDN"
202 STRSID=`echo "$STRDN" | cut -d ';' -f2`
203 echo "STRSID[$STRSID]"
204
205 SPECIALDNS="$HEXGUID $STRGUID $STRSID"
206 for SPDN in $SPECIALDNS; do
207         echo "Search for $SPDN"
208         nentries=`$ldbsearch $options $CONFIGURATION -H $p://$SERVER -s base -b "$SPDN" '(objectClass=*)' | grep "dn: $BASEDN"  | wc -l`
209         if [ $nentries -lt 1 ]; then
210                 echo "Special search returned 0 items"
211                 failed=`expr $failed + 1`
212         fi
213 done
214
215 echo "Search using OIDs instead of names"
216 nentries1=`$ldbsearch $options $CONFIGURATION -H $p://$SERVER '(objectClass=user)' name | grep "^name: "  | wc -l`
217 nentries2=`$ldbsearch $options $CONFIGURATION -H $p://$SERVER '(2.5.4.0=1.2.840.113556.1.5.9)' name | grep "^name: "  | wc -l`
218 if [ $nentries1 -lt 1 ]; then
219         echo "Error: Searching user via (objectClass=user): '$nentries1' < 1"
220         failed=`expr $failed + 1`
221 fi
222 if [ $nentries2 -lt 1 ]; then
223         echo "Error: Searching user via (2.5.4.0=1.2.840.113556.1.5.9) '$nentries2' < 1"
224         failed=`expr $failed + 1`
225 fi
226 if [ x"$nentries1" != x"$nentries2" ]; then
227         echo "Error: Searching user with OIDS[$nentries1] doesn't return the same as STRINGS[$nentries2]"
228         failed=`expr $failed + 1`
229 fi
230
231 exit $failed