s4-smbtorture: add test_SetPrinter to RPC-SPOOLSS.
[Samba.git] / testprogs / blackbox / test_ldb.sh
blob9a4780f10b866b22409af81bfeb9bffdafe1eb86
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
36 ldbsearch="$VALGRIND $BUILDDIR/bin/ldbsearch$EXEEXT"
38 check "RootDSE" $ldbsearch $CONFIGURATION $options --basedn='' -H $p://$SERVER -s base DUMMY=x dnsHostName highestCommittedUSN || failed=`expr $failed + 1`
40 echo "Getting defaultNamingContext"
41 BASEDN=`$ldbsearch $CONFIGURATION $options --basedn='' -H $p://$SERVER -s base DUMMY=x defaultNamingContext | grep defaultNamingContext | awk '{print $2}'`
42 echo "BASEDN is $BASEDN"
44 check "Listing Users" $ldbsearch $options $CONFIGURATION -H $p://$SERVER '(objectclass=user)' sAMAccountName || failed=`expr $failed + 1`
46 check "Listing Users (sorted)" $ldbsearch -S $options $CONFIGURATION -H $p://$SERVER '(objectclass=user)' sAMAccountName || failed=`expr $failed + 1`
48 check "Listing Groups" $ldbsearch $options $CONFIGURATION -H $p://$SERVER '(objectclass=group)' sAMAccountName || failed=`expr $failed + 1`
50 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`
51 echo "Found $nentries entries"
52 if [ $nentries -lt 10 ]; then
53 echo "Should have found at least 10 entries"
54 failed=`expr $failed + 1`
57 echo "Check rootDSE for Controls"
58 nentries=`$ldbsearch $options $CONFIGURATION -H $p://$SERVER -s base -b "" '(objectclass=*)' | grep -i supportedControl | wc -l`
59 if [ $nentries -lt 4 ]; then
60 echo "Should have found at least 4 entries"
61 failed=`expr $failed + 1`
64 echo "Test Paged Results Control"
65 nentries=`$ldbsearch $options $CONFIGURATION -H $p://$SERVER --controls=paged_results:1:5 '(objectclass=user)' | grep sAMAccountName | wc -l`
66 if [ $nentries -lt 1 ]; then
67 echo "Paged Results Control test returned 0 items"
68 failed=`expr $failed + 1`
71 echo "Test Server Sort Control"
72 nentries=`$ldbsearch $options $CONFIGURATION -H $p://$SERVER --controls=server_sort:1:0:sAMAccountName '(objectclass=user)' | grep sAMAccountName | wc -l`
73 if [ $nentries -lt 1 ]; then
74 echo "Server Sort Control test returned 0 items"
75 failed=`expr $failed + 1`
78 echo "Test Extended DN Control"
79 nentries=`$ldbsearch $options $CONFIGURATION -H $p://$SERVER --controls=extended_dn:1 '(objectclass=user)' | grep sAMAccountName | wc -l`
80 if [ $nentries -lt 1 ]; then
81 echo "Extended DN Control test returned 0 items"
82 failed=`expr $failed + 1`
84 nentries=`$ldbsearch $options $CONFIGURATION -H $p://$SERVER --controls=extended_dn:1:0 '(objectclass=user)' | grep sAMAccountName | wc -l`
85 if [ $nentries -lt 1 ]; then
86 echo "Extended DN Control test returned 0 items"
87 failed=`expr $failed + 1`
89 nentries=`$ldbsearch $options $CONFIGURATION -H $p://$SERVER --controls=extended_dn:1:1 '(objectclass=user)' | grep sAMAccountName | wc -l`
90 if [ $nentries -lt 1 ]; then
91 echo "Extended DN Control test returned 0 items"
92 failed=`expr $failed + 1`
95 echo "Test Domain scope Control"
96 nentries=`$ldbsearch $options $CONFIGURATION -H $p://$SERVER --controls=domain_scope:1 '(objectclass=user)' | grep sAMAccountName | wc -l`
97 if [ $nentries -lt 1 ]; then
98 echo "Extended Domain scope Control test returned 0 items"
99 failed=`expr $failed + 1`
102 echo "Test Attribute Scope Query Control"
103 nentries=`$ldbsearch $options $CONFIGURATION -H $p://$SERVER --controls=asq:1:member -s base -b "CN=Administrators,CN=Builtin,$BASEDN" | grep sAMAccountName | wc -l`
104 if [ $nentries -lt 1 ]; then
105 echo "Attribute Scope Query test returned 0 items"
106 failed=`expr $failed + 1`
109 echo "Test Search Options Control"
110 nentries=`$ldbsearch $options $CONFIGURATION -H $p://$SERVER --controls=search_options:1:2 '(objectclass=crossRef)' | grep crossRef | wc -l`
111 if [ $nentries -lt 1 ]; then
112 echo "Search Options Control Query test returned 0 items"
113 failed=`expr $failed + 1`
116 echo "Test Search Options Control with Domain Scope Control"
117 nentries=`$ldbsearch $options $CONFIGURATION -H $p://$SERVER --controls=search_options:1:2,domain_scope:1 '(objectclass=crossRef)' | grep crossRef | wc -l`
118 if [ $nentries -lt 1 ]; then
119 echo "Search Options Control Query test returned 0 items"
120 failed=`expr $failed + 1`
123 wellknown_object_test() {
124 local guid=$1
125 local object=$2
126 local basedns
127 local dn
128 local r
129 local c
130 local n
131 local failed=0
133 basedns="<WKGUID=${guid},${BASEDN}> <wkGuId=${guid},${BASEDN}>"
134 for dn in ${basedns}; do
135 echo "Test ${dn} => ${object}"
136 r=`$ldbsearch $options $CONFIGURATION -H $p://$SERVER '(objectClass=*)' -b "${dn}" | grep 'dn: '`
137 n=`echo "${r}" | grep 'dn: ' | wc -l`
138 c=`echo "${r}" | grep "${object}" | wc -l`
140 if [ $n -lt 1 ]; then
141 echo "Object not found by WKGUID"
142 failed=`expr $failed + 1`
143 continue
145 if [ $c -lt 1 ]; then
146 echo "Wrong object found by WKGUID: [${r}]"
147 failed=`expr $failed + 1`
148 continue
150 done
152 return $failed
155 wellknown_object_test 22B70C67D56E4EFB91E9300FCA3DC1AA ForeignSecurityPrincipals
156 st=$?
157 if [ x"$st" != x"0" ]; then
158 failed=`expr $failed + $st`
160 wellknown_object_test 2FBAC1870ADE11D297C400C04FD8D5CD Infrastructure
161 st=$?
162 if [ x"$st" != x"0" ]; then
163 failed=`expr $failed + $st`
165 wellknown_object_test AB1D30F3768811D1ADED00C04FD8D5CD System
166 st=$?
167 if [ x"$st" != x"0" ]; then
168 failed=`expr $failed + $st`
170 wellknown_object_test A361B2FFFFD211D1AA4B00C04FD7D83A Domain Controllers
171 st=$?
172 if [ x"$st" != x"0" ]; then
173 failed=`expr $failed + $st`
175 wellknown_object_test AA312825768811D1ADED00C04FD8D5CD Computers
176 st=$?
177 if [ x"$st" != x"0" ]; then
178 failed=`expr $failed + $st`
180 wellknown_object_test A9D1CA15768811D1ADED00C04FD8D5CD Users
181 st=$?
182 if [ x"$st" != x"0" ]; then
183 failed=`expr $failed + $st`
186 echo "Getting HEX GUID/SID of $BASEDN"
187 HEXDN=`$ldbsearch $CONFIGURATION $options -b "$BASEDN" -H $p://$SERVER -s base "(objectClass=*)" --controls=extended_dn:1:0 distinguishedName | grep 'distinguishedName: ' | cut -d ' ' -f2-`
188 HEXGUID=`echo "$HEXDN" | cut -d ';' -f1`
189 echo "HEXGUID[$HEXGUID]"
191 echo "Getting STR GUID/SID of $BASEDN"
192 STRDN=`$ldbsearch $CONFIGURATION $options -b "$BASEDN" -H $p://$SERVER -s base "(objectClass=*)" --controls=extended_dn:1:1 distinguishedName | grep 'distinguishedName: ' | cut -d ' ' -f2-`
193 echo "STRDN: $STRDN"
194 STRGUID=`echo "$STRDN" | cut -d ';' -f1`
195 echo "STRGUID[$STRGUID]"
197 echo "Getting STR GUID/SID of $BASEDN"
198 STRDN=`$ldbsearch $CONFIGURATION $options -b "$BASEDN" -H $p://$SERVER -s base "(objectClass=*)" --controls=extended_dn:1:1 | grep 'dn: ' | cut -d ' ' -f2-`
199 echo "STRDN: $STRDN"
200 STRSID=`echo "$STRDN" | cut -d ';' -f2`
201 echo "STRSID[$STRSID]"
203 SPECIALDNS="$HEXGUID $STRGUID $STRSID"
204 for SPDN in $SPECIALDNS; do
205 echo "Search for $SPDN"
206 nentries=`$ldbsearch $options $CONFIGURATION -H $p://$SERVER -s base -b "$SPDN" '(objectClass=*)' | grep "dn: $BASEDN" | wc -l`
207 if [ $nentries -lt 1 ]; then
208 echo "Special search returned 0 items"
209 failed=`expr $failed + 1`
211 done
213 echo "Search using OIDs instead of names"
214 nentries1=`$ldbsearch $options $CONFIGURATION -H $p://$SERVER '(objectClass=user)' name | grep "^name: " | wc -l`
215 nentries2=`$ldbsearch $options $CONFIGURATION -H $p://$SERVER '(2.5.4.0=1.2.840.113556.1.5.9)' name | grep "^name: " | wc -l`
216 if [ $nentries1 -lt 1 ]; then
217 echo "Error: Searching user via (objectClass=user): '$nentries1' < 1"
218 failed=`expr $failed + 1`
220 if [ $nentries2 -lt 1 ]; then
221 echo "Error: Searching user via (2.5.4.0=1.2.840.113556.1.5.9) '$nentries2' < 1"
222 failed=`expr $failed + 1`
224 if [ x"$nentries1" != x"$nentries2" ]; then
225 echo "Error: Searching user with OIDS[$nentries1] doesn't return the same as STRINGS[$nentries2]"
226 failed=`expr $failed + 1`
229 exit $failed