Test the behaviour of mixed domain_scope and search_options controls.
[samba.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 check() {
18         name="$1"
19         shift
20         cmdline="$*"
21         echo "test: $name"
22         $cmdline
23         status=$?
24         if [ x$status = x0 ]; then
25                 echo "success: $name"
26         else
27                 echo "failure: $name"
28                 failed=`expr $failed + 1`
29         fi
30         return $status
31 }
32
33 check "RootDSE" bin/ldbsearch $CONFIGURATION $options --basedn='' -H $p://$SERVER -s base DUMMY=x dnsHostName highestCommittedUSN || failed=`expr $failed + 1`
34
35 echo "Getting defaultNamingContext"
36 BASEDN=`bin/ldbsearch $CONFIGURATION $options --basedn='' -H $p://$SERVER -s base DUMMY=x defaultNamingContext | grep defaultNamingContext | awk '{print $2}'`
37 echo "BASEDN is $BASEDN"
38
39 check "Listing Users" bin/ldbsearch $options $CONFIGURATION -H $p://$SERVER '(objectclass=user)' sAMAccountName || failed=`expr $failed + 1`
40
41 check "Listing Users (sorted)" bin/ldbsearch -S $options $CONFIGURATION -H $p://$SERVER '(objectclass=user)' sAMAccountName || failed=`expr $failed + 1`
42
43 check "Listing Groups" bin/ldbsearch $options $CONFIGURATION -H $p://$SERVER '(objectclass=group)' sAMAccountName || failed=`expr $failed + 1`
44
45 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`
46 echo "Found $nentries entries"
47 if [ $nentries -lt 10 ]; then
48 echo "Should have found at least 10 entries"
49 failed=`expr $failed + 1`
50 fi
51
52 echo "Check rootDSE for Controls"
53 nentries=`bin/ldbsearch $options $CONFIGURATION -H $p://$SERVER -s base -b "" '(objectclass=*)' | grep -i supportedControl | wc -l`
54 if [ $nentries -lt 4 ]; then
55 echo "Should have found at least 4 entries"
56 failed=`expr $failed + 1`
57 fi
58
59 echo "Test Paged Results Control"
60 nentries=`bin/ldbsearch $options $CONFIGURATION -H $p://$SERVER --controls=paged_results:1:5 '(objectclass=user)' | grep sAMAccountName | wc -l`
61 if [ $nentries -lt 1 ]; then
62 echo "Paged Results Control test returned 0 items"
63 failed=`expr $failed + 1`
64 fi
65
66 echo "Test Server Sort Control"
67 nentries=`bin/ldbsearch $options $CONFIGURATION -H $p://$SERVER --controls=server_sort:1:0:sAMAccountName '(objectclass=user)' | grep sAMAccountName | wc -l`
68 if [ $nentries -lt 1 ]; then
69 echo "Server Sort Control test returned 0 items"
70 failed=`expr $failed + 1`
71 fi
72
73 echo "Test Extended DN Control"
74 nentries=`bin/ldbsearch $options $CONFIGURATION -H $p://$SERVER --controls=extended_dn:1 '(objectclass=user)' | grep sAMAccountName | wc -l`
75 if [ $nentries -lt 1 ]; then
76 echo "Extended DN Control test returned 0 items"
77 failed=`expr $failed + 1`
78 fi
79 nentries=`bin/ldbsearch $options $CONFIGURATION -H $p://$SERVER --controls=extended_dn:1:0 '(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`
83 fi
84 nentries=`bin/ldbsearch $options $CONFIGURATION -H $p://$SERVER --controls=extended_dn:1: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`
88 fi
89
90 echo "Test Domain scope Control"
91 nentries=`bin/ldbsearch $options $CONFIGURATION -H $p://$SERVER --controls=domain_scope:1 '(objectclass=user)' | grep sAMAccountName | wc -l`
92 if [ $nentries -lt 1 ]; then
93 echo "Extended Domain scope Control test returned 0 items"
94 failed=`expr $failed + 1`
95 fi
96
97 echo "Test Attribute Scope Query Control"
98 nentries=`bin/ldbsearch $options $CONFIGURATION -H $p://$SERVER --controls=asq:1:member -s base -b "CN=Administrators,CN=Builtin,$BASEDN" | grep sAMAccountName | wc -l`
99 if [ $nentries -lt 1 ]; then
100 echo "Attribute Scope Query test returned 0 items"
101 failed=`expr $failed + 1`
102 fi
103
104 echo "Test Search Options Control"
105 nentries=`bin/ldbsearch $options $CONFIGURATION -H $p://$SERVER --controls=search_options:1:2 '(objectclass=crossRef)' | grep crossRef | wc -l`
106 if [ $nentries -lt 1 ]; then
107 echo "Search Options Control Query test returned 0 items"
108 failed=`expr $failed + 1`
109 fi
110
111 echo "Test Search Options Control with Domain Scope Control"
112 nentries=`bin/ldbsearch $options $CONFIGURATION -H $p://$SERVER --controls=search_options:1:2,domain_scope:1 '(objectclass=crossRef)' | grep crossRef | wc -l`
113 if [ $nentries -lt 1 ]; then
114 echo "Search Options Control Query test returned 0 items"
115 failed=`expr $failed + 1`
116 fi
117
118
119 exit $failed