s3:smb2_break: make use of file_fsp_smb2()
[Samba/gebeck_regimport.git] / testprogs / blackbox / test_ldb.sh
blob1609a95d062b085c3ba18f283a3f5c3fdee63b87
1 #!/bin/sh
3 if [ $# -lt 2 ]; then
4 cat <<EOF
5 Usage: test_ldb.sh PROTOCOL SERVER [OPTIONS]
6 EOF
7 exit 1;
8 fi
11 p=$1
12 SERVER=$2
13 PREFIX=$3
14 shift 2
15 options="$*"
17 . `dirname $0`/subunit.sh
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`
32 return $status
35 export PATH="$BINDIR:$PATH"
37 ldbsearch="$VALGRIND ldbsearch"
39 check "RootDSE" $ldbsearch $CONFIGURATION $options --basedn='' -H $p://$SERVER -s base DUMMY=x dnsHostName highestCommittedUSN || failed=`expr $failed + 1`
41 echo "Getting defaultNamingContext"
42 BASEDN=`$ldbsearch $CONFIGURATION $options --basedn='' -H $p://$SERVER -s base DUMMY=x defaultNamingContext | grep defaultNamingContext | awk '{print $2}'`
43 echo "BASEDN is $BASEDN"
45 check "Listing Users" $ldbsearch $options $CONFIGURATION -H $p://$SERVER '(objectclass=user)' sAMAccountName || failed=`expr $failed + 1`
47 check "Listing Users (sorted)" $ldbsearch -S $options $CONFIGURATION -H $p://$SERVER '(objectclass=user)' sAMAccountName || failed=`expr $failed + 1`
49 check "Listing Groups" $ldbsearch $options $CONFIGURATION -H $p://$SERVER '(objectclass=group)' sAMAccountName || failed=`expr $failed + 1`
51 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`
52 echo "Found $nentries entries"
53 if [ $nentries -lt 10 ]; then
54 echo "Should have found at least 10 entries"
55 failed=`expr $failed + 1`
58 echo "Check rootDSE for Controls"
59 nentries=`$ldbsearch $options $CONFIGURATION -H $p://$SERVER -s base -b "" '(objectclass=*)' | grep -i supportedControl | wc -l`
60 if [ $nentries -lt 4 ]; then
61 echo "Should have found at least 4 entries"
62 failed=`expr $failed + 1`
65 echo "Test Paged Results Control"
66 nentries=`$ldbsearch $options $CONFIGURATION -H $p://$SERVER --controls=paged_results:1:5 '(objectclass=user)' | grep sAMAccountName | wc -l`
67 if [ $nentries -lt 1 ]; then
68 echo "Paged Results Control test returned 0 items"
69 failed=`expr $failed + 1`
72 echo "Test Server Sort Control"
73 nentries=`$ldbsearch $options $CONFIGURATION -H $p://$SERVER --controls=server_sort:1:0:sAMAccountName '(objectclass=user)' | grep sAMAccountName | wc -l`
74 if [ $nentries -lt 1 ]; then
75 echo "Server Sort Control test returned 0 items"
76 failed=`expr $failed + 1`
79 echo "Test Extended DN Control"
80 nentries=`$ldbsearch $options $CONFIGURATION -H $p://$SERVER --controls=extended_dn:1 '(objectclass=user)' | grep sAMAccountName | wc -l`
81 if [ $nentries -lt 1 ]; then
82 echo "Extended DN Control test returned 0 items"
83 failed=`expr $failed + 1`
85 nentries=`$ldbsearch $options $CONFIGURATION -H $p://$SERVER --controls=extended_dn:1:0 '(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`
90 nentries=`$ldbsearch $options $CONFIGURATION -H $p://$SERVER --controls=extended_dn:1:1 '(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`
96 echo "Test Domain scope Control"
97 nentries=`$ldbsearch $options $CONFIGURATION -H $p://$SERVER --controls=domain_scope:1 '(objectclass=user)' | grep sAMAccountName | wc -l`
98 if [ $nentries -lt 1 ]; then
99 echo "Extended Domain scope Control test returned 0 items"
100 failed=`expr $failed + 1`
103 echo "Test Attribute Scope Query Control"
104 nentries=`$ldbsearch $options $CONFIGURATION -H $p://$SERVER --controls=asq:1:member -s base -b "CN=Administrators,CN=Builtin,$BASEDN" | grep sAMAccountName | wc -l`
105 if [ $nentries -lt 1 ]; then
106 echo "Attribute Scope Query test returned 0 items"
107 failed=`expr $failed + 1`
110 echo "Test Search Options Control"
111 nentries=`$ldbsearch $options $CONFIGURATION -H $p://$SERVER --controls=search_options:1:2 '(objectclass=crossRef)' | grep crossRef | wc -l`
112 if [ $nentries -lt 1 ]; then
113 echo "Search Options Control Query test returned 0 items"
114 failed=`expr $failed + 1`
117 echo "Test Search Options Control with Domain Scope Control"
118 nentries=`$ldbsearch $options $CONFIGURATION -H $p://$SERVER --controls=search_options:1:2,domain_scope:1 '(objectclass=crossRef)' | grep crossRef | wc -l`
119 if [ $nentries -lt 1 ]; then
120 echo "Search Options Control Query test returned 0 items"
121 failed=`expr $failed + 1`
124 wellknown_object_test() {
125 local guid=$1
126 local object=$2
127 local basedns
128 local dn
129 local r
130 local c
131 local n
132 local failed=0
134 basedns="<WKGUID=${guid},${BASEDN}> <wkGuId=${guid},${BASEDN}>"
135 for dn in ${basedns}; do
136 echo "Test ${dn} => ${object}"
137 r=`$ldbsearch $options $CONFIGURATION -H $p://$SERVER '(objectClass=*)' -b "${dn}" | grep 'dn: '`
138 n=`echo "${r}" | grep 'dn: ' | wc -l`
139 c=`echo "${r}" | grep "${object}" | wc -l`
141 if [ $n -lt 1 ]; then
142 echo "Object not found by WKGUID"
143 failed=`expr $failed + 1`
144 continue
146 if [ $c -lt 1 ]; then
147 echo "Wrong object found by WKGUID: [${r}]"
148 failed=`expr $failed + 1`
149 continue
151 done
153 return $failed
156 wellknown_object_test 22B70C67D56E4EFB91E9300FCA3DC1AA ForeignSecurityPrincipals
157 st=$?
158 if [ x"$st" != x"0" ]; then
159 failed=`expr $failed + $st`
161 wellknown_object_test 2FBAC1870ADE11D297C400C04FD8D5CD Infrastructure
162 st=$?
163 if [ x"$st" != x"0" ]; then
164 failed=`expr $failed + $st`
166 wellknown_object_test AB1D30F3768811D1ADED00C04FD8D5CD System
167 st=$?
168 if [ x"$st" != x"0" ]; then
169 failed=`expr $failed + $st`
171 wellknown_object_test A361B2FFFFD211D1AA4B00C04FD7D83A Domain Controllers
172 st=$?
173 if [ x"$st" != x"0" ]; then
174 failed=`expr $failed + $st`
176 wellknown_object_test AA312825768811D1ADED00C04FD8D5CD Computers
177 st=$?
178 if [ x"$st" != x"0" ]; then
179 failed=`expr $failed + $st`
181 wellknown_object_test A9D1CA15768811D1ADED00C04FD8D5CD Users
182 st=$?
183 if [ x"$st" != x"0" ]; then
184 failed=`expr $failed + $st`
187 echo "Getting HEX GUID/SID of $BASEDN"
188 HEXDN=`$ldbsearch $CONFIGURATION $options -b "$BASEDN" -H $p://$SERVER -s base "(objectClass=*)" --controls=extended_dn:1:0 distinguishedName | grep 'distinguishedName: ' | cut -d ' ' -f2-`
189 HEXGUID=`echo "$HEXDN" | cut -d ';' -f1`
190 echo "HEXGUID[$HEXGUID]"
192 echo "Getting STR GUID/SID of $BASEDN"
193 STRDN=`$ldbsearch $CONFIGURATION $options -b "$BASEDN" -H $p://$SERVER -s base "(objectClass=*)" --controls=extended_dn:1:1 distinguishedName | grep 'distinguishedName: ' | cut -d ' ' -f2-`
194 echo "STRDN: $STRDN"
195 STRGUID=`echo "$STRDN" | cut -d ';' -f1`
196 echo "STRGUID[$STRGUID]"
198 echo "Getting STR GUID/SID of $BASEDN"
199 STRDN=`$ldbsearch $CONFIGURATION $options -b "$BASEDN" -H $p://$SERVER -s base "(objectClass=*)" --controls=extended_dn:1:1 | grep 'dn: ' | cut -d ' ' -f2-`
200 echo "STRDN: $STRDN"
201 STRSID=`echo "$STRDN" | cut -d ';' -f2`
202 echo "STRSID[$STRSID]"
204 SPECIALDNS="$HEXGUID $STRGUID $STRSID"
205 for SPDN in $SPECIALDNS; do
206 echo "Search for $SPDN"
207 nentries=`$ldbsearch $options $CONFIGURATION -H $p://$SERVER -s base -b "$SPDN" '(objectClass=*)' | grep "dn: $BASEDN" | wc -l`
208 if [ $nentries -lt 1 ]; then
209 echo "Special search returned 0 items"
210 failed=`expr $failed + 1`
212 done
214 echo "Search using OIDs instead of names"
215 nentries1=`$ldbsearch $options $CONFIGURATION -H $p://$SERVER '(objectClass=user)' name | grep "^name: " | wc -l`
216 nentries2=`$ldbsearch $options $CONFIGURATION -H $p://$SERVER '(2.5.4.0=1.2.840.113556.1.5.9)' name | grep "^name: " | wc -l`
217 if [ $nentries1 -lt 1 ]; then
218 echo "Error: Searching user via (objectClass=user): '$nentries1' < 1"
219 failed=`expr $failed + 1`
221 if [ $nentries2 -lt 1 ]; then
222 echo "Error: Searching user via (2.5.4.0=1.2.840.113556.1.5.9) '$nentries2' < 1"
223 failed=`expr $failed + 1`
225 if [ x"$nentries1" != x"$nentries2" ]; then
226 echo "Error: Searching user with OIDS[$nentries1] doesn't return the same as STRINGS[$nentries2]"
227 failed=`expr $failed + 1`
230 exit $failed