Merge commit 'master/master'
[ira/wip.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 check "RootDSE" bin/ldbsearch $CONFIGURATION $options --basedn='' -H $p://$SERVER -s base DUMMY=x dnsHostName highestCommittedUSN || failed=`expr $failed + 1`
36
37 echo "Getting defaultNamingContext"
38 BASEDN=`bin/ldbsearch $CONFIGURATION $options --basedn='' -H $p://$SERVER -s base DUMMY=x defaultNamingContext | grep defaultNamingContext | awk '{print $2}'`
39 echo "BASEDN is $BASEDN"
40
41 check "Listing Users" bin/ldbsearch $options $CONFIGURATION -H $p://$SERVER '(objectclass=user)' sAMAccountName || failed=`expr $failed + 1`
42
43 check "Listing Users (sorted)" bin/ldbsearch -S $options $CONFIGURATION -H $p://$SERVER '(objectclass=user)' sAMAccountName || failed=`expr $failed + 1`
44
45 check "Listing Groups" bin/ldbsearch $options $CONFIGURATION -H $p://$SERVER '(objectclass=group)' sAMAccountName || failed=`expr $failed + 1`
46
47 nentries=`bin/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`
48 echo "Found $nentries entries"
49 if [ $nentries -lt 10 ]; then
50 echo "Should have found at least 10 entries"
51 failed=`expr $failed + 1`
52 fi
53
54 echo "Check rootDSE for Controls"
55 nentries=`bin/ldbsearch $options $CONFIGURATION -H $p://$SERVER -s base -b "" '(objectclass=*)' | grep -i supportedControl | wc -l`
56 if [ $nentries -lt 4 ]; then
57 echo "Should have found at least 4 entries"
58 failed=`expr $failed + 1`
59 fi
60
61 echo "Test Paged Results Control"
62 nentries=`bin/ldbsearch $options $CONFIGURATION -H $p://$SERVER --controls=paged_results:1:5 '(objectclass=user)' | grep sAMAccountName | wc -l`
63 if [ $nentries -lt 1 ]; then
64 echo "Paged Results Control test returned 0 items"
65 failed=`expr $failed + 1`
66 fi
67
68 echo "Test Server Sort Control"
69 nentries=`bin/ldbsearch $options $CONFIGURATION -H $p://$SERVER --controls=server_sort:1:0:sAMAccountName '(objectclass=user)' | grep sAMAccountName | wc -l`
70 if [ $nentries -lt 1 ]; then
71 echo "Server Sort Control test returned 0 items"
72 failed=`expr $failed + 1`
73 fi
74
75 echo "Test Extended DN Control"
76 nentries=`bin/ldbsearch $options $CONFIGURATION -H $p://$SERVER --controls=extended_dn:1 '(objectclass=user)' | grep sAMAccountName | wc -l`
77 if [ $nentries -lt 1 ]; then
78 echo "Extended DN Control test returned 0 items"
79 failed=`expr $failed + 1`
80 fi
81 nentries=`bin/ldbsearch $options $CONFIGURATION -H $p://$SERVER --controls=extended_dn:1:0 '(objectclass=user)' | grep sAMAccountName | wc -l`
82 if [ $nentries -lt 1 ]; then
83 echo "Extended DN Control test returned 0 items"
84 failed=`expr $failed + 1`
85 fi
86 nentries=`bin/ldbsearch $options $CONFIGURATION -H $p://$SERVER --controls=extended_dn:1:1 '(objectclass=user)' | grep sAMAccountName | wc -l`
87 if [ $nentries -lt 1 ]; then
88 echo "Extended DN Control test returned 0 items"
89 failed=`expr $failed + 1`
90 fi
91
92 echo "Test Domain scope Control"
93 nentries=`bin/ldbsearch $options $CONFIGURATION -H $p://$SERVER --controls=domain_scope:1 '(objectclass=user)' | grep sAMAccountName | wc -l`
94 if [ $nentries -lt 1 ]; then
95 echo "Extended Domain scope Control test returned 0 items"
96 failed=`expr $failed + 1`
97 fi
98
99 echo "Test Attribute Scope Query Control"
100 nentries=`bin/ldbsearch $options $CONFIGURATION -H $p://$SERVER --controls=asq:1:member -s base -b "CN=Administrators,CN=Builtin,$BASEDN" | grep sAMAccountName | wc -l`
101 if [ $nentries -lt 1 ]; then
102 echo "Attribute Scope Query test returned 0 items"
103 failed=`expr $failed + 1`
104 fi
105
106 echo "Test Search Options Control"
107 nentries=`bin/ldbsearch $options $CONFIGURATION -H $p://$SERVER --controls=search_options:1:2 '(objectclass=crossRef)' | grep crossRef | wc -l`
108 if [ $nentries -lt 1 ]; then
109 echo "Search Options Control Query test returned 0 items"
110 failed=`expr $failed + 1`
111 fi
112
113 echo "Test Search Options Control with Domain Scope Control"
114 nentries=`bin/ldbsearch $options $CONFIGURATION -H $p://$SERVER --controls=search_options:1:2,domain_scope:1 '(objectclass=crossRef)' | grep crossRef | wc -l`
115 if [ $nentries -lt 1 ]; then
116 echo "Search Options Control Query test returned 0 items"
117 failed=`expr $failed + 1`
118 fi
119
120 function wellkown_object_test() {
121         local guid=$1
122         local object=$2
123         local basedns
124         local dn
125         local r
126         local c
127         local n
128         local failed=0
129
130         basedns="<WKGUID=${guid},${BASEDN}> <wkGuId=${guid},${BASEDN}>"
131         for dn in ${basedns}; do
132                 echo "Test ${dn} => ${object}"
133                 r=`bin/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`
136
137                 if [ $n -lt 1 ]; then
138                         echo "Object not found by WKGUID"
139                         failed=`expr $failed + 1`
140                         continue
141                 fi
142                 if [ $c -lt 1 ]; then
143                         echo "Wrong object found by WKGUID: [${r}]"
144                         failed=`expr $failed + 1`
145                         continue
146                 fi
147         done
148
149         return $failed
150 }
151
152 wellkown_object_test 22B70C67D56E4EFB91E9300FCA3DC1AA ForeignSecurityPrincipals
153 st=$?
154 if [ x"$st" != x"0" ]; then
155         failed=`expr $failed + $st`
156 fi
157 wellkown_object_test 2FBAC1870ADE11D297C400C04FD8D5CD Infrastructure
158 st=$?
159 if [ x"$st" != x"0" ]; then
160         failed=`expr $failed + $st`
161 fi
162 wellkown_object_test AB1D30F3768811D1ADED00C04FD8D5CD System
163 st=$?
164 if [ x"$st" != x"0" ]; then
165         failed=`expr $failed + $st`
166 fi
167 wellkown_object_test A361B2FFFFD211D1AA4B00C04FD7D83A Domain Controllers
168 st=$?
169 if [ x"$st" != x"0" ]; then
170         failed=`expr $failed + $st`
171 fi
172 wellkown_object_test AA312825768811D1ADED00C04FD8D5CD Computers
173 st=$?
174 if [ x"$st" != x"0" ]; then
175         failed=`expr $failed + $st`
176 fi
177 wellkown_object_test A9D1CA15768811D1ADED00C04FD8D5CD Users
178 st=$?
179 if [ x"$st" != x"0" ]; then
180         failed=`expr $failed + $st`
181 fi
182
183 exit $failed