1#!/bin/sh 2 3if [ $# -lt 2 ]; then 4cat <<EOF 5Usage: test_ldb.sh PROTOCOL SERVER [OPTIONS] 6EOF 7exit 1; 8fi 9 10 11p=$1 12SERVER=$2 13PREFIX=$3 14shift 2 15options="$*" 16 17. `dirname $0`/subunit.sh 18 19check() { 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 36ldbsearch="$VALGRIND $BUILDDIR/bin/ldbsearch$EXEEXT" 37 38check "RootDSE" $ldbsearch $CONFIGURATION $options --basedn='' -H $p://$SERVER -s base DUMMY=x dnsHostName highestCommittedUSN || failed=`expr $failed + 1` 39 40echo "Getting defaultNamingContext" 41BASEDN=`$ldbsearch $CONFIGURATION $options --basedn='' -H $p://$SERVER -s base DUMMY=x defaultNamingContext | grep defaultNamingContext | awk '{print $2}'` 42echo "BASEDN is $BASEDN" 43 44check "Listing Users" $ldbsearch $options $CONFIGURATION -H $p://$SERVER '(objectclass=user)' sAMAccountName || failed=`expr $failed + 1` 45 46check "Listing Users (sorted)" $ldbsearch -S $options $CONFIGURATION -H $p://$SERVER '(objectclass=user)' sAMAccountName || failed=`expr $failed + 1` 47 48check "Listing Groups" $ldbsearch $options $CONFIGURATION -H $p://$SERVER '(objectclass=group)' sAMAccountName || failed=`expr $failed + 1` 49 50nentries=`$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` 51echo "Found $nentries entries" 52if [ $nentries -lt 10 ]; then 53echo "Should have found at least 10 entries" 54failed=`expr $failed + 1` 55fi 56 57echo "Check rootDSE for Controls" 58nentries=`$ldbsearch $options $CONFIGURATION -H $p://$SERVER -s base -b "" '(objectclass=*)' | grep -i supportedControl | wc -l` 59if [ $nentries -lt 4 ]; then 60echo "Should have found at least 4 entries" 61failed=`expr $failed + 1` 62fi 63 64echo "Test Paged Results Control" 65nentries=`$ldbsearch $options $CONFIGURATION -H $p://$SERVER --controls=paged_results:1:5 '(objectclass=user)' | grep sAMAccountName | wc -l` 66if [ $nentries -lt 1 ]; then 67echo "Paged Results Control test returned 0 items" 68failed=`expr $failed + 1` 69fi 70 71echo "Test Server Sort Control" 72nentries=`$ldbsearch $options $CONFIGURATION -H $p://$SERVER --controls=server_sort:1:0:sAMAccountName '(objectclass=user)' | grep sAMAccountName | wc -l` 73if [ $nentries -lt 1 ]; then 74echo "Server Sort Control test returned 0 items" 75failed=`expr $failed + 1` 76fi 77 78echo "Test Extended DN Control" 79nentries=`$ldbsearch $options $CONFIGURATION -H $p://$SERVER --controls=extended_dn:1 '(objectclass=user)' | grep sAMAccountName | wc -l` 80if [ $nentries -lt 1 ]; then 81echo "Extended DN Control test returned 0 items" 82failed=`expr $failed + 1` 83fi 84nentries=`$ldbsearch $options $CONFIGURATION -H $p://$SERVER --controls=extended_dn:1:0 '(objectclass=user)' | grep sAMAccountName | wc -l` 85if [ $nentries -lt 1 ]; then 86echo "Extended DN Control test returned 0 items" 87failed=`expr $failed + 1` 88fi 89nentries=`$ldbsearch $options $CONFIGURATION -H $p://$SERVER --controls=extended_dn:1:1 '(objectclass=user)' | grep sAMAccountName | wc -l` 90if [ $nentries -lt 1 ]; then 91echo "Extended DN Control test returned 0 items" 92failed=`expr $failed + 1` 93fi 94 95echo "Test Domain scope Control" 96nentries=`$ldbsearch $options $CONFIGURATION -H $p://$SERVER --controls=domain_scope:1 '(objectclass=user)' | grep sAMAccountName | wc -l` 97if [ $nentries -lt 1 ]; then 98echo "Extended Domain scope Control test returned 0 items" 99failed=`expr $failed + 1` 100fi 101 102echo "Test Attribute Scope Query Control" 103nentries=`$ldbsearch $options $CONFIGURATION -H $p://$SERVER --controls=asq:1:member -s base -b "CN=Administrators,CN=Builtin,$BASEDN" | grep sAMAccountName | wc -l` 104if [ $nentries -lt 1 ]; then 105echo "Attribute Scope Query test returned 0 items" 106failed=`expr $failed + 1` 107fi 108 109echo "Test Search Options Control" 110nentries=`$ldbsearch $options $CONFIGURATION -H $p://$SERVER --controls=search_options:1:2 '(objectclass=crossRef)' | grep crossRef | wc -l` 111if [ $nentries -lt 1 ]; then 112echo "Search Options Control Query test returned 0 items" 113failed=`expr $failed + 1` 114fi 115 116echo "Test Search Options Control with Domain Scope Control" 117nentries=`$ldbsearch $options $CONFIGURATION -H $p://$SERVER --controls=search_options:1:2,domain_scope:1 '(objectclass=crossRef)' | grep crossRef | wc -l` 118if [ $nentries -lt 1 ]; then 119echo "Search Options Control Query test returned 0 items" 120failed=`expr $failed + 1` 121fi 122 123wellknown_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 132 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` 139 140 if [ $n -lt 1 ]; then 141 echo "Object not found by WKGUID" 142 failed=`expr $failed + 1` 143 continue 144 fi 145 if [ $c -lt 1 ]; then 146 echo "Wrong object found by WKGUID: [${r}]" 147 failed=`expr $failed + 1` 148 continue 149 fi 150 done 151 152 return $failed 153} 154 155wellknown_object_test 22B70C67D56E4EFB91E9300FCA3DC1AA ForeignSecurityPrincipals 156st=$? 157if [ x"$st" != x"0" ]; then 158 failed=`expr $failed + $st` 159fi 160wellknown_object_test 2FBAC1870ADE11D297C400C04FD8D5CD Infrastructure 161st=$? 162if [ x"$st" != x"0" ]; then 163 failed=`expr $failed + $st` 164fi 165wellknown_object_test AB1D30F3768811D1ADED00C04FD8D5CD System 166st=$? 167if [ x"$st" != x"0" ]; then 168 failed=`expr $failed + $st` 169fi 170wellknown_object_test A361B2FFFFD211D1AA4B00C04FD7D83A Domain Controllers 171st=$? 172if [ x"$st" != x"0" ]; then 173 failed=`expr $failed + $st` 174fi 175wellknown_object_test AA312825768811D1ADED00C04FD8D5CD Computers 176st=$? 177if [ x"$st" != x"0" ]; then 178 failed=`expr $failed + $st` 179fi 180wellknown_object_test A9D1CA15768811D1ADED00C04FD8D5CD Users 181st=$? 182if [ x"$st" != x"0" ]; then 183 failed=`expr $failed + $st` 184fi 185 186echo "Getting HEX GUID/SID of $BASEDN" 187HEXDN=`$ldbsearch $CONFIGURATION $options -b "$BASEDN" -H $p://$SERVER -s base "(objectClass=*)" --controls=extended_dn:1:0 distinguishedName | grep 'distinguishedName: ' | cut -d ' ' -f2-` 188HEXGUID=`echo "$HEXDN" | cut -d ';' -f1` 189echo "HEXGUID[$HEXGUID]" 190 191echo "Getting STR GUID/SID of $BASEDN" 192STRDN=`$ldbsearch $CONFIGURATION $options -b "$BASEDN" -H $p://$SERVER -s base "(objectClass=*)" --controls=extended_dn:1:1 distinguishedName | grep 'distinguishedName: ' | cut -d ' ' -f2-` 193echo "STRDN: $STRDN" 194STRGUID=`echo "$STRDN" | cut -d ';' -f1` 195echo "STRGUID[$STRGUID]" 196 197echo "Getting STR GUID/SID of $BASEDN" 198STRDN=`$ldbsearch $CONFIGURATION $options -b "$BASEDN" -H $p://$SERVER -s base "(objectClass=*)" --controls=extended_dn:1:1 | grep 'dn: ' | cut -d ' ' -f2-` 199echo "STRDN: $STRDN" 200STRSID=`echo "$STRDN" | cut -d ';' -f2` 201echo "STRSID[$STRSID]" 202 203SPECIALDNS="$HEXGUID $STRGUID $STRSID" 204for 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` 210 fi 211done 212 213echo "Search using OIDs instead of names" 214nentries1=`$ldbsearch $options $CONFIGURATION -H $p://$SERVER '(objectClass=user)' name | grep "^name: " | wc -l` 215nentries2=`$ldbsearch $options $CONFIGURATION -H $p://$SERVER '(2.5.4.0=1.2.840.113556.1.5.9)' name | grep "^name: " | wc -l` 216if [ $nentries1 -lt 1 ]; then 217 echo "Error: Searching user via (objectClass=user): '$nentries1' < 1" 218 failed=`expr $failed + 1` 219fi 220if [ $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` 223fi 224if [ 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` 227fi 228 229exit $failed 230