WHATSNEW: Add release notes for Samba 4.19.5.
[Samba.git] / testprogs / blackbox / test_ldb.sh
blobe35d66ee0b3eb5aa54f7761b8b38f9f2221c880b
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
10 p=$1
11 SERVER=$2
12 PREFIX=$3
13 shift 2
14 options="$*"
16 . $(dirname $0)/subunit.sh
17 . "$(dirname "${0}")/common_test_fns.inc"
19 check()
21 name="$1"
22 shift
23 cmdline="$*"
24 echo "test: $name"
25 $cmdline
26 status=$?
27 if [ x$status = x0 ]; then
28 echo "success: $name"
29 else
30 echo "failure: $name"
31 failed=$(expr $failed + 1)
33 return $status
36 ldbsearch="${VALGRIND} $(system_or_builddir_binary ldbsearch "${BINDIR}")"
38 check "RootDSE" $ldbsearch $CONFIGURATION $options --basedn='' -H $p://$SERVER --scope=base DUMMY=x dnsHostName highestCommittedUSN || failed=$(expr $failed + 1)
39 check "RootDSE (full)" $ldbsearch $CONFIGURATION $options --basedn='' -H $p://$SERVER --scope=base '(objectClass=*)' || failed=$(expr $failed + 1)
40 check "RootDSE (extended)" $ldbsearch $CONFIGURATION $options --basedn='' -H $p://$SERVER --scope=base '(objectClass=*)' --extended-dn || failed=$(expr $failed + 1)
41 if [ x$p = x"ldaps" ]; then
42 testit_expect_failure "RootDSE over SSLv3 should fail" $ldbsearch $CONFIGURATION $options --basedn='' -H $p://$SERVER --scope=base DUMMY=x dnsHostName highestCommittedUSN --option='tlspriority=NONE:+VERS-SSL3.0:+MAC-ALL:+CIPHER-ALL:+RSA:+SIGN-ALL:+COMP-NULL' || failed=$(expr $failed + 1)
45 echo "Getting defaultNamingContext"
46 BASEDN=$($ldbsearch $CONFIGURATION $options --basedn='' -H $p://$SERVER --scope=base DUMMY=x defaultNamingContext | grep defaultNamingContext | awk '{print $2}')
47 echo "BASEDN is $BASEDN"
49 check "Listing Users" $ldbsearch $options $CONFIGURATION -H $p://$SERVER '(objectclass=user)' sAMAccountName || failed=$(expr $failed + 1)
51 check "Listing Users (sorted)" $ldbsearch -S $options $CONFIGURATION -H $p://$SERVER '(objectclass=user)' sAMAccountName || failed=$(expr $failed + 1)
53 check "Listing Groups" $ldbsearch $options $CONFIGURATION -H $p://$SERVER '(objectclass=group)' sAMAccountName || failed=$(expr $failed + 1)
55 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)
56 echo "Found $nentries entries"
57 if [ $nentries -lt 10 ]; then
58 echo "Should have found at least 10 entries"
59 failed=$(expr $failed + 1)
62 echo "Check rootDSE for Controls"
63 nentries=$($ldbsearch $options $CONFIGURATION -H $p://$SERVER --scope=base -b "" '(objectclass=*)' | grep -i supportedControl | wc -l)
64 if [ $nentries -lt 4 ]; then
65 echo "Should have found at least 4 entries"
66 failed=$(expr $failed + 1)
69 echo "Test Paged Results Control"
70 nentries=$($ldbsearch $options $CONFIGURATION -H $p://$SERVER --controls=paged_results:1:5 '(objectclass=user)' | grep sAMAccountName | wc -l)
71 if [ $nentries -lt 1 ]; then
72 echo "Paged Results Control test returned 0 items"
73 failed=$(expr $failed + 1)
76 echo "Test Server Sort Control"
77 nentries=$($ldbsearch $options $CONFIGURATION -H $p://$SERVER --controls=server_sort:1:0:sAMAccountName '(objectclass=user)' | grep sAMAccountName | wc -l)
78 if [ $nentries -lt 1 ]; then
79 echo "Server Sort Control test returned 0 items"
80 failed=$(expr $failed + 1)
83 echo "Test Extended DN Control"
84 nentries=$($ldbsearch $options $CONFIGURATION -H $p://$SERVER --controls=extended_dn:1 '(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:0 '(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)
94 nentries=$($ldbsearch $options $CONFIGURATION -H $p://$SERVER --controls=extended_dn:1:1 '(objectclass=user)' | grep sAMAccountName | wc -l)
95 if [ $nentries -lt 1 ]; then
96 echo "Extended DN Control test returned 0 items"
97 failed=$(expr $failed + 1)
100 echo "Test Domain scope Control"
101 nentries=$($ldbsearch $options $CONFIGURATION -H $p://$SERVER --controls=domain_scope:1 '(objectclass=user)' | grep sAMAccountName | wc -l)
102 if [ $nentries -lt 1 ]; then
103 echo "Extended Domain scope Control test returned 0 items"
104 failed=$(expr $failed + 1)
107 echo "Test Attribute Scope Query Control"
108 nentries=$($ldbsearch $options $CONFIGURATION -H $p://$SERVER --controls=asq:1:member --scope=base -b "CN=Administrators,CN=Builtin,$BASEDN" | grep sAMAccountName | wc -l)
109 if [ $nentries -lt 1 ]; then
110 echo "Attribute Scope Query test returned 0 items"
111 failed=$(expr $failed + 1)
114 echo "Test Search Options Control"
115 nentries=$($ldbsearch $options $CONFIGURATION -H $p://$SERVER --controls=search_options:1:2 '(objectclass=crossRef)' | grep crossRef | wc -l)
116 if [ $nentries -lt 1 ]; then
117 echo "Search Options Control Query test returned 0 items"
118 failed=$(expr $failed + 1)
121 echo "Test Search Options Control with Domain Scope Control"
122 nentries=$($ldbsearch $options $CONFIGURATION -H $p://$SERVER --controls=search_options:1:2,domain_scope:1 '(objectclass=crossRef)' | grep crossRef | wc -l)
123 if [ $nentries -lt 1 ]; then
124 echo "Search Options Control Query test returned 0 items"
125 failed=$(expr $failed + 1)
128 wellknown_object_test()
130 guid=$1
131 object=$2
132 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 --scope=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 --scope=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 --scope=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 --scope=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