s3:param: add a utility function lp_idmap_range() to get the configured range for...
[Samba/gebeck_regimport.git] / testprogs / blackbox / test_ldb.sh
blobf326672670306524557a9f2d5e3d228898dabcda
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()
126 guid=$1
127 object=$2
128 failed=0
130 basedns="<WKGUID=${guid},${BASEDN}> <wkGuId=${guid},${BASEDN}>"
131 for dn in ${basedns}; do
132 echo "Test ${dn} => ${object}"
133 r=`$ldbsearch $options $CONFIGURATION -H $p://$SERVER '(objectClass=*)' -b "${dn}" | grep 'dn: '`
134 n=`echo "${r}" | grep 'dn: ' | wc -l`
135 c=`echo "${r}" | grep "${object}" | wc -l`
137 if [ $n -lt 1 ]; then
138 echo "Object not found by WKGUID"
139 failed=`expr $failed + 1`
140 continue
142 if [ $c -lt 1 ]; then
143 echo "Wrong object found by WKGUID: [${r}]"
144 failed=`expr $failed + 1`
145 continue
147 done
149 return $failed
152 wellknown_object_test 22B70C67D56E4EFB91E9300FCA3DC1AA ForeignSecurityPrincipals
153 st=$?
154 if [ x"$st" != x"0" ]; then
155 failed=`expr $failed + $st`
157 wellknown_object_test 2FBAC1870ADE11D297C400C04FD8D5CD Infrastructure
158 st=$?
159 if [ x"$st" != x"0" ]; then
160 failed=`expr $failed + $st`
162 wellknown_object_test AB1D30F3768811D1ADED00C04FD8D5CD System
163 st=$?
164 if [ x"$st" != x"0" ]; then
165 failed=`expr $failed + $st`
167 wellknown_object_test A361B2FFFFD211D1AA4B00C04FD7D83A Domain Controllers
168 st=$?
169 if [ x"$st" != x"0" ]; then
170 failed=`expr $failed + $st`
172 wellknown_object_test AA312825768811D1ADED00C04FD8D5CD Computers
173 st=$?
174 if [ x"$st" != x"0" ]; then
175 failed=`expr $failed + $st`
177 wellknown_object_test A9D1CA15768811D1ADED00C04FD8D5CD Users
178 st=$?
179 if [ x"$st" != x"0" ]; then
180 failed=`expr $failed + $st`
183 echo "Getting HEX GUID/SID of $BASEDN"
184 HEXDN=`$ldbsearch $CONFIGURATION $options -b "$BASEDN" -H $p://$SERVER -s base "(objectClass=*)" --controls=extended_dn:1:0 distinguishedName | grep 'distinguishedName: ' | cut -d ' ' -f2-`
185 HEXGUID=`echo "$HEXDN" | cut -d ';' -f1`
186 echo "HEXGUID[$HEXGUID]"
188 echo "Getting STR GUID/SID of $BASEDN"
189 STRDN=`$ldbsearch $CONFIGURATION $options -b "$BASEDN" -H $p://$SERVER -s base "(objectClass=*)" --controls=extended_dn:1:1 distinguishedName | grep 'distinguishedName: ' | cut -d ' ' -f2-`
190 echo "STRDN: $STRDN"
191 STRGUID=`echo "$STRDN" | cut -d ';' -f1`
192 echo "STRGUID[$STRGUID]"
194 echo "Getting STR GUID/SID of $BASEDN"
195 STRDN=`$ldbsearch $CONFIGURATION $options -b "$BASEDN" -H $p://$SERVER -s base "(objectClass=*)" --controls=extended_dn:1:1 | grep 'dn: ' | cut -d ' ' -f2-`
196 echo "STRDN: $STRDN"
197 STRSID=`echo "$STRDN" | cut -d ';' -f2`
198 echo "STRSID[$STRSID]"
200 SPECIALDNS="$HEXGUID $STRGUID $STRSID"
201 for SPDN in $SPECIALDNS; do
202 echo "Search for $SPDN"
203 nentries=`$ldbsearch $options $CONFIGURATION -H $p://$SERVER -s base -b "$SPDN" '(objectClass=*)' | grep "dn: $BASEDN" | wc -l`
204 if [ $nentries -lt 1 ]; then
205 echo "Special search returned 0 items"
206 failed=`expr $failed + 1`
208 done
210 echo "Search using OIDs instead of names"
211 nentries1=`$ldbsearch $options $CONFIGURATION -H $p://$SERVER '(objectClass=user)' name | grep "^name: " | wc -l`
212 nentries2=`$ldbsearch $options $CONFIGURATION -H $p://$SERVER '(2.5.4.0=1.2.840.113556.1.5.9)' name | grep "^name: " | wc -l`
213 if [ $nentries1 -lt 1 ]; then
214 echo "Error: Searching user via (objectClass=user): '$nentries1' < 1"
215 failed=`expr $failed + 1`
217 if [ $nentries2 -lt 1 ]; then
218 echo "Error: Searching user via (2.5.4.0=1.2.840.113556.1.5.9) '$nentries2' < 1"
219 failed=`expr $failed + 1`
221 if [ x"$nentries1" != x"$nentries2" ]; then
222 echo "Error: Searching user with OIDS[$nentries1] doesn't return the same as STRINGS[$nentries2]"
223 failed=`expr $failed + 1`
226 exit $failed