| 1 |
/* |
| 2 |
Unix SMB/CIFS Implementation. |
| 3 |
|
| 4 |
test CLDAP/LDAP netlogon operations |
| 5 |
|
| 6 |
Copyright (C) Andrew Tridgell 2005 |
| 7 |
Copyright (C) Matthias Dieter Wallnöfer 2009 |
| 8 |
|
| 9 |
This program is free software; you can redistribute it and/or modify |
| 10 |
it under the terms of the GNU General Public License as published by |
| 11 |
the Free Software Foundation; either version 3 of the License, or |
| 12 |
(at your option) any later version. |
| 13 |
|
| 14 |
This program is distributed in the hope that it will be useful, |
| 15 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 17 |
GNU General Public License for more details. |
| 18 |
|
| 19 |
You should have received a copy of the GNU General Public License |
| 20 |
along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 21 |
|
| 22 |
*/ |
| 23 |
|
| 24 |
#include "includes.h" |
| 25 |
#include "libcli/cldap/cldap.h" |
| 26 |
#include "libcli/ldap/ldap_client.h" |
| 27 |
#include "libcli/ldap/ldap_ndr.h" |
| 28 |
#include "libcli/resolve/resolve.h" |
| 29 |
#include "librpc/gen_ndr/netlogon.h" |
| 30 |
#include "param/param.h" |
| 31 |
#include "../lib/tsocket/tsocket.h" |
| 32 |
#include "source3/libads/netlogon_ping.h" |
| 33 |
#include "libcli/security/dom_sid.h" |
| 34 |
|
| 35 |
#include "torture/torture.h" |
| 36 |
#include "torture/ldap/proto.h" |
| 37 |
|
| 38 |
#undef strcasecmp |
| 39 |
|
| 40 |
#define CHECK_STATUS(status, correct) torture_assert_ntstatus_equal(tctx, status, correct, "incorrect status") |
| 41 |
|
| 42 |
#define CHECK_VAL(v, correct) torture_assert_int_equal(tctx, (v), (correct), "incorrect value"); |
| 43 |
|
| 44 |
#define CHECK_STRING(v, correct) torture_assert_str_equal(tctx, v, correct, "incorrect value"); |
| 45 |
|
| 46 |
struct cldap_netlogon { |
| 47 |
struct { |
| 48 |
const char *dest_address; |
| 49 |
uint16_t dest_port; |
| 50 |
const char *realm; |
| 51 |
const char *host; |
| 52 |
const char *user; |
| 53 |
const char *domain_guid; |
| 54 |
const char *domain_sid; |
| 55 |
int acct_control; |
| 56 |
uint32_t version; |
| 57 |
} in; |
| 58 |
struct { |
| 59 |
struct netlogon_samlogon_response *netlogon; |
| 60 |
} out; |
| 61 |
}; |
| 62 |
|
| 63 |
typedef NTSTATUS (*request_netlogon_t)(void *con, |
| 64 |
TALLOC_CTX *mem_ctx, |
| 65 |
struct cldap_netlogon *io); |
| 66 |
|
| 67 |
typedef NTSTATUS (*request_rootdse_t)(void *con, |
| 68 |
TALLOC_CTX *mem_ctx, |
| 69 |
struct cldap_search *io); |
| 70 |
|
| 71 |
/* |
| 72 |
test netlogon operations |
| 73 |
*/ |
| 74 |
static bool test_ldap_netlogon(struct torture_context *tctx, |
| 75 |
request_netlogon_t request_netlogon, |
| 76 |
void *cldap, |
| 77 |
const char *dest) |
| 78 |
{ |
| 79 |
NTSTATUS status; |
| 80 |
struct cldap_netlogon search, empty_search; |
| 81 |
struct netlogon_samlogon_response n1; |
| 82 |
struct GUID guid; |
| 83 |
int i; |
| 84 |
|
| 85 |
ZERO_STRUCT(search); |
| 86 |
search.in.dest_address = NULL; |
| 87 |
search.in.dest_port = 0; |
| 88 |
search.in.acct_control = -1; |
| 89 |
search.in.version = NETLOGON_NT_VERSION_5 | NETLOGON_NT_VERSION_5EX; |
| 90 |
|
| 91 |
empty_search = search; |
| 92 |
|
| 93 |
printf("Trying without any attributes\n"); |
| 94 |
search = empty_search; |
| 95 |
status = request_netlogon(cldap, tctx, &search); |
| 96 |
CHECK_STATUS(status, NT_STATUS_OK); |
| 97 |
|
| 98 |
n1 = *search.out.netlogon; |
| 99 |
|
| 100 |
search.in.user = "Administrator"; |
| 101 |
search.in.realm = n1.data.nt5_ex.dns_domain; |
| 102 |
search.in.host = "__cldap_torture__"; |
| 103 |
|
| 104 |
printf("Scanning for netlogon levels\n"); |
| 105 |
for (i=0;i<256;i++) { |
| 106 |
search.in.version = i; |
| 107 |
printf("Trying netlogon level %d\n", i); |
| 108 |
status = request_netlogon(cldap, tctx, &search); |
| 109 |
CHECK_STATUS(status, NT_STATUS_OK); |
| 110 |
} |
| 111 |
|
| 112 |
printf("Scanning for netlogon level bits\n"); |
| 113 |
for (i=0;i<31;i++) { |
| 114 |
search.in.version = (1<<i); |
| 115 |
printf("Trying netlogon level 0x%x\n", i); |
| 116 |
status = request_netlogon(cldap, tctx, &search); |
| 117 |
CHECK_STATUS(status, NT_STATUS_OK); |
| 118 |
} |
| 119 |
|
| 120 |
search.in.version = NETLOGON_NT_VERSION_5|NETLOGON_NT_VERSION_5EX|NETLOGON_NT_VERSION_IP; |
| 121 |
status = request_netlogon(cldap, tctx, &search); |
| 122 |
CHECK_STATUS(status, NT_STATUS_OK); |
| 123 |
|
| 124 |
printf("Trying with User=NULL\n"); |
| 125 |
search.in.user = NULL; |
| 126 |
status = request_netlogon(cldap, tctx, &search); |
| 127 |
CHECK_STATUS(status, NT_STATUS_OK); |
| 128 |
CHECK_VAL(search.out.netlogon->data.nt5_ex.command, |
| 129 |
LOGON_SAM_LOGON_RESPONSE_EX); |
| 130 |
CHECK_STRING(search.out.netlogon->data.nt5_ex.user_name, ""); |
| 131 |
torture_assert(tctx, |
| 132 |
strstr(search.out.netlogon->data.nt5_ex.pdc_name, |
| 133 |
"\\\\") == NULL, |
| 134 |
"PDC name should not be in UNC form"); |
| 135 |
|
| 136 |
printf("Trying with User=Administrator\n"); |
| 137 |
search.in.user = "Administrator"; |
| 138 |
status = request_netlogon(cldap, tctx, &search); |
| 139 |
CHECK_STATUS(status, NT_STATUS_OK); |
| 140 |
CHECK_VAL(search.out.netlogon->data.nt5_ex.command, |
| 141 |
LOGON_SAM_LOGON_USER_UNKNOWN_EX); |
| 142 |
CHECK_STRING(search.out.netlogon->data.nt5_ex.user_name, |
| 143 |
search.in.user); |
| 144 |
torture_assert(tctx, |
| 145 |
strstr(search.out.netlogon->data.nt5_ex.pdc_name, |
| 146 |
"\\\\") == NULL, |
| 147 |
"PDC name should not be in UNC form"); |
| 148 |
|
| 149 |
search.in.version = NETLOGON_NT_VERSION_5; |
| 150 |
status = request_netlogon(cldap, tctx, &search); |
| 151 |
CHECK_STATUS(status, NT_STATUS_OK); |
| 152 |
|
| 153 |
printf("Trying with User=NULL\n"); |
| 154 |
search.in.user = NULL; |
| 155 |
status = request_netlogon(cldap, tctx, &search); |
| 156 |
CHECK_STATUS(status, NT_STATUS_OK); |
| 157 |
CHECK_VAL(search.out.netlogon->data.nt5_ex.command, |
| 158 |
LOGON_SAM_LOGON_RESPONSE); |
| 159 |
CHECK_STRING(search.out.netlogon->data.nt5_ex.user_name, ""); |
| 160 |
torture_assert(tctx, |
| 161 |
strstr(search.out.netlogon->data.nt5_ex.pdc_name, |
| 162 |
"\\\\") != NULL, |
| 163 |
"PDC name should be in UNC form"); |
| 164 |
|
| 165 |
printf("Trying with User=Administrator\n"); |
| 166 |
search.in.user = "Administrator"; |
| 167 |
status = request_netlogon(cldap, tctx, &search); |
| 168 |
CHECK_STATUS(status, NT_STATUS_OK); |
| 169 |
CHECK_VAL(search.out.netlogon->data.nt5_ex.command, |
| 170 |
LOGON_SAM_LOGON_USER_UNKNOWN); |
| 171 |
CHECK_STRING(search.out.netlogon->data.nt5_ex.user_name, |
| 172 |
search.in.user); |
| 173 |
torture_assert(tctx, |
| 174 |
strstr(search.out.netlogon->data.nt5_ex.pdc_name, |
| 175 |
"\\\\") != NULL, |
| 176 |
"PDC name should be in UNC form"); |
| 177 |
|
| 178 |
search.in.version = NETLOGON_NT_VERSION_5 | NETLOGON_NT_VERSION_5EX; |
| 179 |
|
| 180 |
printf("Trying with a GUID\n"); |
| 181 |
search.in.realm = NULL; |
| 182 |
search.in.domain_guid = GUID_string(tctx, &n1.data.nt5_ex.domain_uuid); |
| 183 |
status = request_netlogon(cldap, tctx, &search); |
| 184 |
CHECK_STATUS(status, NT_STATUS_OK); |
| 185 |
CHECK_VAL(search.out.netlogon->data.nt5_ex.command, |
| 186 |
LOGON_SAM_LOGON_USER_UNKNOWN_EX); |
| 187 |
CHECK_STRING(GUID_string(tctx, |
| 188 |
&search.out.netlogon->data.nt5_ex.domain_uuid), |
| 189 |
search.in.domain_guid); |
| 190 |
torture_assert(tctx, |
| 191 |
strstr(search.out.netlogon->data.nt5_ex.pdc_name, |
| 192 |
"\\\\") == NULL, |
| 193 |
"PDC name should not be in UNC form"); |
| 194 |
|
| 195 |
printf("Trying with a incorrect GUID\n"); |
| 196 |
guid = GUID_random(); |
| 197 |
search.in.user = NULL; |
| 198 |
search.in.domain_guid = GUID_string(tctx, &guid); |
| 199 |
status = request_netlogon(cldap, tctx, &search); |
| 200 |
CHECK_STATUS(status, NT_STATUS_NOT_FOUND); |
| 201 |
|
| 202 |
printf("Trying with a AAC\n"); |
| 203 |
search.in.acct_control = ACB_WSTRUST|ACB_SVRTRUST; |
| 204 |
search.in.realm = n1.data.nt5_ex.dns_domain; |
| 205 |
status = request_netlogon(cldap, tctx, &search); |
| 206 |
CHECK_STATUS(status, NT_STATUS_OK); |
| 207 |
CHECK_VAL(search.out.netlogon->data.nt5_ex.command, |
| 208 |
LOGON_SAM_LOGON_RESPONSE_EX); |
| 209 |
CHECK_STRING(search.out.netlogon->data.nt5_ex.user_name, ""); |
| 210 |
|
| 211 |
printf("Trying with a zero AAC\n"); |
| 212 |
search.in.acct_control = 0x0; |
| 213 |
search.in.realm = n1.data.nt5_ex.dns_domain; |
| 214 |
status = request_netlogon(cldap, tctx, &search); |
| 215 |
CHECK_STATUS(status, NT_STATUS_OK); |
| 216 |
CHECK_VAL(search.out.netlogon->data.nt5_ex.command, |
| 217 |
LOGON_SAM_LOGON_RESPONSE_EX); |
| 218 |
CHECK_STRING(search.out.netlogon->data.nt5_ex.user_name, ""); |
| 219 |
|
| 220 |
printf("Trying with a zero AAC and user=Administrator\n"); |
| 221 |
search.in.acct_control = 0x0; |
| 222 |
search.in.user = "Administrator"; |
| 223 |
search.in.realm = n1.data.nt5_ex.dns_domain; |
| 224 |
status = request_netlogon(cldap, tctx, &search); |
| 225 |
CHECK_STATUS(status, NT_STATUS_OK); |
| 226 |
CHECK_VAL(search.out.netlogon->data.nt5_ex.command, |
| 227 |
LOGON_SAM_LOGON_USER_UNKNOWN_EX); |
| 228 |
CHECK_STRING(search.out.netlogon->data.nt5_ex.user_name, |
| 229 |
"Administrator"); |
| 230 |
|
| 231 |
printf("Trying with a bad AAC\n"); |
| 232 |
search.in.user = NULL; |
| 233 |
search.in.acct_control = 0xFF00FF00; |
| 234 |
search.in.realm = n1.data.nt5_ex.dns_domain; |
| 235 |
status = request_netlogon(cldap, tctx, &search); |
| 236 |
CHECK_STATUS(status, NT_STATUS_OK); |
| 237 |
CHECK_VAL(search.out.netlogon->data.nt5_ex.command, |
| 238 |
LOGON_SAM_LOGON_RESPONSE_EX); |
| 239 |
CHECK_STRING(search.out.netlogon->data.nt5_ex.user_name, ""); |
| 240 |
|
| 241 |
printf("Trying with a user only\n"); |
| 242 |
search = empty_search; |
| 243 |
search.in.user = "Administrator"; |
| 244 |
status = request_netlogon(cldap, tctx, &search); |
| 245 |
CHECK_STATUS(status, NT_STATUS_OK); |
| 246 |
CHECK_STRING(search.out.netlogon->data.nt5_ex.forest, |
| 247 |
n1.data.nt5_ex.dns_domain); |
| 248 |
CHECK_STRING(search.out.netlogon->data.nt5_ex.dns_domain, |
| 249 |
n1.data.nt5_ex.dns_domain); |
| 250 |
CHECK_STRING(search.out.netlogon->data.nt5_ex.domain_name, |
| 251 |
n1.data.nt5_ex.domain_name); |
| 252 |
CHECK_STRING(search.out.netlogon->data.nt5_ex.pdc_name, |
| 253 |
n1.data.nt5_ex.pdc_name); |
| 254 |
CHECK_STRING(search.out.netlogon->data.nt5_ex.user_name, |
| 255 |
search.in.user); |
| 256 |
CHECK_STRING(search.out.netlogon->data.nt5_ex.server_site, |
| 257 |
n1.data.nt5_ex.server_site); |
| 258 |
CHECK_STRING(search.out.netlogon->data.nt5_ex.client_site, |
| 259 |
n1.data.nt5_ex.client_site); |
| 260 |
|
| 261 |
printf("Trying with just a bad username\n"); |
| 262 |
search.in.user = "___no_such_user___"; |
| 263 |
status = request_netlogon(cldap, tctx, &search); |
| 264 |
CHECK_STATUS(status, NT_STATUS_OK); |
| 265 |
CHECK_VAL(search.out.netlogon->data.nt5_ex.command, |
| 266 |
LOGON_SAM_LOGON_USER_UNKNOWN_EX); |
| 267 |
CHECK_STRING(search.out.netlogon->data.nt5_ex.forest, |
| 268 |
n1.data.nt5_ex.dns_domain); |
| 269 |
CHECK_STRING(search.out.netlogon->data.nt5_ex.dns_domain, |
| 270 |
n1.data.nt5_ex.dns_domain); |
| 271 |
CHECK_STRING(search.out.netlogon->data.nt5_ex.domain_name, |
| 272 |
n1.data.nt5_ex.domain_name); |
| 273 |
CHECK_STRING(search.out.netlogon->data.nt5_ex.pdc_name, |
| 274 |
n1.data.nt5_ex.pdc_name); |
| 275 |
CHECK_STRING(search.out.netlogon->data.nt5_ex.user_name, |
| 276 |
search.in.user); |
| 277 |
CHECK_STRING(search.out.netlogon->data.nt5_ex.server_site, |
| 278 |
n1.data.nt5_ex.server_site); |
| 279 |
CHECK_STRING(search.out.netlogon->data.nt5_ex.client_site, |
| 280 |
n1.data.nt5_ex.client_site); |
| 281 |
|
| 282 |
printf("Trying with just a bad domain\n"); |
| 283 |
search = empty_search; |
| 284 |
search.in.realm = "___no_such_domain___"; |
| 285 |
status = request_netlogon(cldap, tctx, &search); |
| 286 |
CHECK_STATUS(status, NT_STATUS_NOT_FOUND); |
| 287 |
|
| 288 |
printf("Trying with a incorrect domain and correct guid\n"); |
| 289 |
search.in.domain_guid = GUID_string(tctx, &n1.data.nt5_ex.domain_uuid); |
| 290 |
status = request_netlogon(cldap, tctx, &search); |
| 291 |
CHECK_STATUS(status, NT_STATUS_OK); |
| 292 |
CHECK_VAL(search.out.netlogon->data.nt5_ex.command, |
| 293 |
LOGON_SAM_LOGON_RESPONSE_EX); |
| 294 |
CHECK_STRING(search.out.netlogon->data.nt5_ex.forest, |
| 295 |
n1.data.nt5_ex.dns_domain); |
| 296 |
CHECK_STRING(search.out.netlogon->data.nt5_ex.dns_domain, |
| 297 |
n1.data.nt5_ex.dns_domain); |
| 298 |
CHECK_STRING(search.out.netlogon->data.nt5_ex.domain_name, |
| 299 |
n1.data.nt5_ex.domain_name); |
| 300 |
CHECK_STRING(search.out.netlogon->data.nt5_ex.pdc_name, |
| 301 |
n1.data.nt5_ex.pdc_name); |
| 302 |
CHECK_STRING(search.out.netlogon->data.nt5_ex.user_name, ""); |
| 303 |
CHECK_STRING(search.out.netlogon->data.nt5_ex.server_site, |
| 304 |
n1.data.nt5_ex.server_site); |
| 305 |
CHECK_STRING(search.out.netlogon->data.nt5_ex.client_site, |
| 306 |
n1.data.nt5_ex.client_site); |
| 307 |
|
| 308 |
printf("Trying with a incorrect domain and incorrect guid\n"); |
| 309 |
search.in.domain_guid = GUID_string(tctx, &guid); |
| 310 |
status = request_netlogon(cldap, tctx, &search); |
| 311 |
CHECK_STATUS(status, NT_STATUS_NOT_FOUND); |
| 312 |
CHECK_VAL(search.out.netlogon->data.nt5_ex.command, |
| 313 |
LOGON_SAM_LOGON_RESPONSE_EX); |
| 314 |
CHECK_STRING(search.out.netlogon->data.nt5_ex.forest, |
| 315 |
n1.data.nt5_ex.dns_domain); |
| 316 |
CHECK_STRING(search.out.netlogon->data.nt5_ex.dns_domain, |
| 317 |
n1.data.nt5_ex.dns_domain); |
| 318 |
CHECK_STRING(search.out.netlogon->data.nt5_ex.domain_name, |
| 319 |
n1.data.nt5_ex.domain_name); |
| 320 |
CHECK_STRING(search.out.netlogon->data.nt5_ex.pdc_name, |
| 321 |
n1.data.nt5_ex.pdc_name); |
| 322 |
CHECK_STRING(search.out.netlogon->data.nt5_ex.user_name, ""); |
| 323 |
CHECK_STRING(search.out.netlogon->data.nt5_ex.server_site, |
| 324 |
n1.data.nt5_ex.server_site); |
| 325 |
CHECK_STRING(search.out.netlogon->data.nt5_ex.client_site, |
| 326 |
n1.data.nt5_ex.client_site); |
| 327 |
|
| 328 |
printf("Trying with a incorrect GUID and correct domain\n"); |
| 329 |
search.in.domain_guid = GUID_string(tctx, &guid); |
| 330 |
search.in.realm = n1.data.nt5_ex.dns_domain; |
| 331 |
status = request_netlogon(cldap, tctx, &search); |
| 332 |
CHECK_STATUS(status, NT_STATUS_OK); |
| 333 |
CHECK_VAL(search.out.netlogon->data.nt5_ex.command, |
| 334 |
LOGON_SAM_LOGON_RESPONSE_EX); |
| 335 |
CHECK_STRING(search.out.netlogon->data.nt5_ex.forest, |
| 336 |
n1.data.nt5_ex.dns_domain); |
| 337 |
CHECK_STRING(search.out.netlogon->data.nt5_ex.dns_domain, |
| 338 |
n1.data.nt5_ex.dns_domain); |
| 339 |
CHECK_STRING(search.out.netlogon->data.nt5_ex.domain_name, |
| 340 |
n1.data.nt5_ex.domain_name); |
| 341 |
CHECK_STRING(search.out.netlogon->data.nt5_ex.pdc_name, |
| 342 |
n1.data.nt5_ex.pdc_name); |
| 343 |
CHECK_STRING(search.out.netlogon->data.nt5_ex.user_name, ""); |
| 344 |
CHECK_STRING(search.out.netlogon->data.nt5_ex.server_site, |
| 345 |
n1.data.nt5_ex.server_site); |
| 346 |
CHECK_STRING(search.out.netlogon->data.nt5_ex.client_site, |
| 347 |
n1.data.nt5_ex.client_site); |
| 348 |
|
| 349 |
printf("Proof other results\n"); |
| 350 |
search.in.user = "Administrator"; |
| 351 |
status = request_netlogon(cldap, tctx, &search); |
| 352 |
CHECK_STATUS(status, NT_STATUS_OK); |
| 353 |
CHECK_STRING(search.out.netlogon->data.nt5_ex.forest, |
| 354 |
n1.data.nt5_ex.dns_domain); |
| 355 |
CHECK_STRING(search.out.netlogon->data.nt5_ex.dns_domain, |
| 356 |
n1.data.nt5_ex.dns_domain); |
| 357 |
CHECK_STRING(search.out.netlogon->data.nt5_ex.domain_name, |
| 358 |
n1.data.nt5_ex.domain_name); |
| 359 |
CHECK_STRING(search.out.netlogon->data.nt5_ex.pdc_name, |
| 360 |
n1.data.nt5_ex.pdc_name); |
| 361 |
CHECK_STRING(search.out.netlogon->data.nt5_ex.user_name, |
| 362 |
search.in.user); |
| 363 |
CHECK_STRING(search.out.netlogon->data.nt5_ex.server_site, |
| 364 |
n1.data.nt5_ex.server_site); |
| 365 |
CHECK_STRING(search.out.netlogon->data.nt5_ex.client_site, |
| 366 |
n1.data.nt5_ex.client_site); |
| 367 |
|
| 368 |
return true; |
| 369 |
} |
| 370 |
|
| 371 |
/* |
| 372 |
test cldap netlogon server type flags |
| 373 |
*/ |
| 374 |
static bool test_ldap_netlogon_flags(struct torture_context *tctx, |
| 375 |
request_netlogon_t request_netlogon, |
| 376 |
void *cldap, |
| 377 |
const char *dest) |
| 378 |
{ |
| 379 |
NTSTATUS status; |
| 380 |
struct cldap_netlogon search; |
| 381 |
struct netlogon_samlogon_response n1; |
| 382 |
uint32_t server_type = 0; |
| 383 |
|
| 384 |
printf("Printing out netlogon server type flags: %s\n", dest); |
| 385 |
|
| 386 |
ZERO_STRUCT(search); |
| 387 |
search.in.dest_address = NULL; |
| 388 |
search.in.dest_port = 0; |
| 389 |
search.in.acct_control = -1; |
| 390 |
search.in.version = NETLOGON_NT_VERSION_5 | NETLOGON_NT_VERSION_5EX; |
| 391 |
|
| 392 |
status = request_netlogon(cldap, tctx, &search); |
| 393 |
CHECK_STATUS(status, NT_STATUS_OK); |
| 394 |
|
| 395 |
n1 = *search.out.netlogon; |
| 396 |
if (n1.ntver == NETLOGON_NT_VERSION_5) |
| 397 |
server_type = n1.data.nt5.server_type; |
| 398 |
else if (n1.ntver == NETLOGON_NT_VERSION_5EX) |
| 399 |
server_type = n1.data.nt5_ex.server_type; |
| 400 |
|
| 401 |
printf("The word is: %i\n", server_type); |
| 402 |
if (server_type & NBT_SERVER_PDC) |
| 403 |
printf("NBT_SERVER_PDC "); |
| 404 |
if (server_type & NBT_SERVER_GC) |
| 405 |
printf("NBT_SERVER_GC "); |
| 406 |
if (server_type & NBT_SERVER_LDAP) |
| 407 |
printf("NBT_SERVER_LDAP "); |
| 408 |
if (server_type & NBT_SERVER_DS) |
| 409 |
printf("NBT_SERVER_DS "); |
| 410 |
if (server_type & NBT_SERVER_KDC) |
| 411 |
printf("NBT_SERVER_KDC "); |
| 412 |
if (server_type & NBT_SERVER_TIMESERV) |
| 413 |
printf("NBT_SERVER_TIMESERV "); |
| 414 |
if (server_type & NBT_SERVER_CLOSEST) |
| 415 |
printf("NBT_SERVER_CLOSEST "); |
| 416 |
if (server_type & NBT_SERVER_WRITABLE) |
| 417 |
printf("NBT_SERVER_WRITABLE "); |
| 418 |
if (server_type & NBT_SERVER_GOOD_TIMESERV) |
| 419 |
printf("NBT_SERVER_GOOD_TIMESERV "); |
| 420 |
if (server_type & NBT_SERVER_NDNC) |
| 421 |
printf("NBT_SERVER_NDNC "); |
| 422 |
if (server_type & NBT_SERVER_SELECT_SECRET_DOMAIN_6) |
| 423 |
printf("NBT_SERVER_SELECT_SECRET_DOMAIN_6"); |
| 424 |
if (server_type & NBT_SERVER_FULL_SECRET_DOMAIN_6) |
| 425 |
printf("NBT_SERVER_FULL_SECRET_DOMAIN_6"); |
| 426 |
if (server_type & NBT_SERVER_ADS_WEB_SERVICE) |
| 427 |
printf("NBT_SERVER_ADS_WEB_SERVICE "); |
| 428 |
if (server_type & NBT_SERVER_DS_8) |
| 429 |
printf("NBT_SERVER_DS_8 "); |
| 430 |
if (server_type & NBT_SERVER_DS_9) |
| 431 |
printf("NBT_SERVER_DS_9 "); |
| 432 |
if (server_type & NBT_SERVER_DS_10) |
| 433 |
printf("NBT_SERVER_DS_10 "); |
| 434 |
if (server_type & NBT_SERVER_HAS_DNS_NAME) |
| 435 |
printf("NBT_SERVER_HAS_DNS_NAME "); |
| 436 |
if (server_type & NBT_SERVER_IS_DEFAULT_NC) |
| 437 |
printf("NBT_SERVER_IS_DEFAULT_NC "); |
| 438 |
if (server_type & NBT_SERVER_FOREST_ROOT) |
| 439 |
printf("NBT_SERVER_FOREST_ROOT "); |
| 440 |
|
| 441 |
printf("\n"); |
| 442 |
|
| 443 |
return true; |
| 444 |
} |
| 445 |
|
| 446 |
static NTSTATUS tcp_ldap_rootdse(void *data, |
| 447 |
TALLOC_CTX *mem_ctx, |
| 448 |
struct cldap_search *io) |
| 449 |
{ |
| 450 |
struct ldap_connection *conn = talloc_get_type(data, |
| 451 |
struct ldap_connection); |
| 452 |
struct ldap_message *msg, *result; |
| 453 |
struct ldap_request *req; |
| 454 |
int i; |
| 455 |
NTSTATUS status; |
| 456 |
|
| 457 |
msg = new_ldap_message(mem_ctx); |
| 458 |
if (!msg) { |
| 459 |
return NT_STATUS_NO_MEMORY; |
| 460 |
} |
| 461 |
|
| 462 |
msg->type = LDAP_TAG_SearchRequest; |
| 463 |
msg->r.SearchRequest.basedn = ""; |
| 464 |
msg->r.SearchRequest.scope = LDAP_SEARCH_SCOPE_BASE; |
| 465 |
msg->r.SearchRequest.deref = LDAP_DEREFERENCE_NEVER; |
| 466 |
msg->r.SearchRequest.timelimit = 0; |
| 467 |
msg->r.SearchRequest.sizelimit = 0; |
| 468 |
msg->r.SearchRequest.attributesonly = false; |
| 469 |
msg->r.SearchRequest.tree = ldb_parse_tree(msg, io->in.filter); |
| 470 |
msg->r.SearchRequest.num_attributes = str_list_length(io->in.attributes); |
| 471 |
msg->r.SearchRequest.attributes = io->in.attributes; |
| 472 |
|
| 473 |
req = ldap_request_send(conn, msg); |
| 474 |
if (req == NULL) { |
| 475 |
printf("Could not setup ldap search\n"); |
| 476 |
return NT_STATUS_UNSUCCESSFUL; |
| 477 |
} |
| 478 |
|
| 479 |
ZERO_STRUCT(io->out); |
| 480 |
for (i = 0; i < 2; ++i) { |
| 481 |
status = ldap_result_n(req, i, &result); |
| 482 |
if (!NT_STATUS_IS_OK(status)) { |
| 483 |
return status; |
| 484 |
} |
| 485 |
switch (result->type) { |
| 486 |
case LDAP_TAG_SearchResultEntry: |
| 487 |
if (i != 0) { |
| 488 |
return NT_STATUS_LDAP(LDAP_PROTOCOL_ERROR); |
| 489 |
} |
| 490 |
io->out.response = &result->r.SearchResultEntry; |
| 491 |
break; |
| 492 |
case LDAP_TAG_SearchResultDone: |
| 493 |
io->out.result = &result->r.SearchResultDone; |
| 494 |
if (io->out.result->resultcode != LDAP_SUCCESS) { |
| 495 |
return NT_STATUS_LDAP(io->out.result->resultcode); |
| 496 |
} |
| 497 |
|
| 498 |
return NT_STATUS_OK; |
| 499 |
default: |
| 500 |
return NT_STATUS_LDAP(LDAP_PROTOCOL_ERROR); |
| 501 |
} |
| 502 |
} |
| 503 |
|
| 504 |
return NT_STATUS_OK; |
| 505 |
} |
| 506 |
|
| 507 |
static NTSTATUS udp_ldap_rootdse(void *data, TALLOC_CTX *mem_ctx, |
| 508 |
struct cldap_search *io) |
| 509 |
{ |
| 510 |
struct cldap_socket *cldap = talloc_get_type(data, |
| 511 |
struct cldap_socket); |
| 512 |
|
| 513 |
return cldap_search(cldap, mem_ctx, io); |
| 514 |
} |
| 515 |
|
| 516 |
static bool test_netlogon_extra_attrs(struct torture_context *tctx, |
| 517 |
request_rootdse_t request_rootdse, |
| 518 |
void *conn) |
| 519 |
{ |
| 520 |
struct cldap_search io; |
| 521 |
NTSTATUS status; |
| 522 |
const char *attrs[] = { |
| 523 |
"netlogon", |
| 524 |
"supportedCapabilities", |
| 525 |
NULL |
| 526 |
}; |
| 527 |
const char *attrs2[] = { "netlogon", "*", NULL }; |
| 528 |
struct ldb_message ldbmsg = { NULL, 0, NULL }; |
| 529 |
|
| 530 |
ZERO_STRUCT(io); |
| 531 |
io.in.dest_address = NULL; |
| 532 |
io.in.dest_port = 0; |
| 533 |
io.in.timeout = 2; |
| 534 |
io.in.retries = 2; |
| 535 |
/* Additional attributes may be requested next to netlogon */ |
| 536 |
torture_comment(tctx, "Requesting netlogon with additional attribute\n"); |
| 537 |
io.in.filter = |
| 538 |
talloc_asprintf(tctx, "(&" |
| 539 |
"(NtVer=%s)(AAC=%s)" |
| 540 |
/* Query for LDAP_CAP_ACTIVE_DIRECTORY_OID */ |
| 541 |
"(supportedCapabilities=1.2.840.113556.1.4.800)" |
| 542 |
")", |
| 543 |
ldap_encode_ndr_uint32(tctx, |
| 544 |
NETLOGON_NT_VERSION_5EX), |
| 545 |
ldap_encode_ndr_uint32(tctx, 0)); |
| 546 |
torture_assert(tctx, io.in.filter != NULL, "OOM"); |
| 547 |
io.in.attributes = attrs; |
| 548 |
status = request_rootdse(conn, tctx, &io); |
| 549 |
CHECK_STATUS(status, NT_STATUS_OK); |
| 550 |
torture_assert(tctx, io.out.response != NULL, "No Entries found."); |
| 551 |
CHECK_VAL(io.out.response->num_attributes, 2); |
| 552 |
|
| 553 |
/* netlogon + '*' attr return zero results */ |
| 554 |
torture_comment(tctx, "Requesting netlogon and '*' attributes\n"); |
| 555 |
io.in.attributes = attrs2; |
| 556 |
status = request_rootdse(conn, tctx, &io); |
| 557 |
CHECK_STATUS(status, NT_STATUS_OK); |
| 558 |
torture_assert(tctx, io.out.response != NULL, "No Entries found."); |
| 559 |
ldbmsg.num_elements = io.out.response->num_attributes; |
| 560 |
ldbmsg.elements = io.out.response->attributes; |
| 561 |
torture_assert(tctx, ldb_msg_find_element(&ldbmsg, "netlogon") != NULL, |
| 562 |
"Attribute netlogon not found in Result Entry\n"); |
| 563 |
|
| 564 |
/* Wildcards are not allowed in filters when netlogon is requested. */ |
| 565 |
torture_comment(tctx, "Requesting netlogon with invalid attr filter\n"); |
| 566 |
io.in.filter = |
| 567 |
talloc_asprintf(tctx, |
| 568 |
"(&(NtVer=%s)(AAC=%s)(supportedCapabilities=*))", |
| 569 |
ldap_encode_ndr_uint32(tctx, |
| 570 |
NETLOGON_NT_VERSION_5EX), |
| 571 |
ldap_encode_ndr_uint32(tctx, 0)); |
| 572 |
torture_assert(tctx, io.in.filter != NULL, "OOM"); |
| 573 |
io.in.attributes = attrs; |
| 574 |
status = request_rootdse(conn, tctx, &io); |
| 575 |
CHECK_STATUS(status, NT_STATUS_OK); |
| 576 |
torture_assert(tctx, io.out.response == NULL, |
| 577 |
"A wildcard filter should return no entries."); |
| 578 |
|
| 579 |
return true; |
| 580 |
} |
| 581 |
|
| 582 |
/* |
| 583 |
Bug #11392: Huawei Unified Storage System S5500 V3 sends no NtVer |
| 584 |
[MS-ADTS] Section 7.3.3.2 "Domain Controller Response to an LDAP Ping" |
| 585 |
*/ |
| 586 |
static bool test_netlogon_huawei(struct torture_context *tctx, |
| 587 |
request_rootdse_t request_rootdse, |
| 588 |
void *conn) |
| 589 |
{ |
| 590 |
struct cldap_search io; |
| 591 |
struct netlogon_samlogon_response n1; |
| 592 |
NTSTATUS status; |
| 593 |
const char *attrs[] = { |
| 594 |
"netlogon", |
| 595 |
NULL |
| 596 |
}; |
| 597 |
struct ldb_message ldbmsg = { NULL, 0, NULL }; |
| 598 |
|
| 599 |
ZERO_STRUCT(io); |
| 600 |
io.in.dest_address = NULL; |
| 601 |
io.in.dest_port = 0; |
| 602 |
io.in.timeout = 2; |
| 603 |
io.in.retries = 2; |
| 604 |
|
| 605 |
torture_comment(tctx, "Requesting netlogon without NtVer filter\n"); |
| 606 |
io.in.filter = talloc_asprintf(tctx, "(&(DnsDomain=%s))", |
| 607 |
lpcfg_dnsdomain(tctx->lp_ctx)); |
| 608 |
torture_assert(tctx, io.in.filter != NULL, "OOM"); |
| 609 |
io.in.attributes = attrs; |
| 610 |
status = request_rootdse(conn, tctx, &io); |
| 611 |
CHECK_STATUS(status, NT_STATUS_OK); |
| 612 |
torture_assert(tctx, io.out.response != NULL, "No Entries found."); |
| 613 |
CHECK_VAL(io.out.response->num_attributes, 1); |
| 614 |
|
| 615 |
ldbmsg.num_elements = io.out.response->num_attributes; |
| 616 |
ldbmsg.elements = io.out.response->attributes; |
| 617 |
torture_assert(tctx, ldb_msg_find_element(&ldbmsg, "netlogon") != NULL, |
| 618 |
"Attribute netlogon not found in Result Entry\n"); |
| 619 |
|
| 620 |
status = pull_netlogon_samlogon_response( |
| 621 |
io.out.response->attributes[0].values, |
| 622 |
tctx, |
| 623 |
&n1); |
| 624 |
CHECK_STATUS(status, NT_STATUS_OK); |
| 625 |
CHECK_VAL(n1.ntver, NETLOGON_NT_VERSION_5); |
| 626 |
|
| 627 |
return true; |
| 628 |
} |
| 629 |
|
| 630 |
bool torture_netlogon_tcp(struct torture_context *tctx) |
| 631 |
{ |
| 632 |
const char *host = torture_setting_string(tctx, "host", NULL); |
| 633 |
bool ret = true; |
| 634 |
NTSTATUS status; |
| 635 |
struct ldap_connection *conn; |
| 636 |
TALLOC_CTX *mem_ctx; |
| 637 |
const char *url; |
| 638 |
|
| 639 |
mem_ctx = talloc_init("torture_ldap_netlogon"); |
| 640 |
|
| 641 |
url = talloc_asprintf(mem_ctx, "ldap://%s/", host); |
| 642 |
|
| 643 |
status = torture_ldap_connection(tctx, &conn, url); |
| 644 |
if (!NT_STATUS_IS_OK(status)) { |
| 645 |
return false; |
| 646 |
} |
| 647 |
|
| 648 |
ret &= test_netlogon_extra_attrs(tctx, tcp_ldap_rootdse, conn); |
| 649 |
|
| 650 |
return ret; |
| 651 |
} |
| 652 |
|
| 653 |
bool torture_netlogon_udp(struct torture_context *tctx) |
| 654 |
{ |
| 655 |
const char *host = torture_setting_string(tctx, "host", NULL); |
| 656 |
const char *ip; |
| 657 |
struct nbt_name nbt_name; |
| 658 |
bool ret = true; |
| 659 |
int r; |
| 660 |
struct cldap_socket *cldap; |
| 661 |
NTSTATUS status; |
| 662 |
struct tsocket_address *dest_addr; |
| 663 |
|
| 664 |
make_nbt_name_server(&nbt_name, host); |
| 665 |
|
| 666 |
status = resolve_name_ex(lpcfg_resolve_context(tctx->lp_ctx), |
| 667 |
0, 0, &nbt_name, tctx, &ip, tctx->ev); |
| 668 |
torture_assert_ntstatus_ok(tctx, status, |
| 669 |
talloc_asprintf(tctx,"Failed to resolve %s: %s", |
| 670 |
nbt_name.name, nt_errstr(status))); |
| 671 |
|
| 672 |
r = tsocket_address_inet_from_strings(tctx, "ip", ip, 389, &dest_addr); |
| 673 |
CHECK_VAL(r, 0); |
| 674 |
|
| 675 |
/* cldap_socket_init should now know about the dest. address */ |
| 676 |
status = cldap_socket_init(tctx, NULL, dest_addr, &cldap); |
| 677 |
CHECK_STATUS(status, NT_STATUS_OK); |
| 678 |
|
| 679 |
ret &= test_netlogon_extra_attrs(tctx, udp_ldap_rootdse, cldap); |
| 680 |
ret &= test_netlogon_huawei(tctx, udp_ldap_rootdse, cldap); |
| 681 |
|
| 682 |
return ret; |
| 683 |
} |
| 684 |
|
| 685 |
struct test_netlogon_ping_state { |
| 686 |
struct tsocket_address *dest; |
| 687 |
enum client_netlogon_ping_protocol proto; |
| 688 |
}; |
| 689 |
|
| 690 |
static NTSTATUS test_netlogon_ping(void *data, |
| 691 |
TALLOC_CTX *mem_ctx, |
| 692 |
struct cldap_netlogon *io) |
| 693 |
{ |
| 694 |
struct test_netlogon_ping_state *state = data; |
| 695 |
struct netlogon_samlogon_response **responses = NULL; |
| 696 |
struct GUID guid; |
| 697 |
struct GUID *pguid = NULL; |
| 698 |
struct dom_sid sid; |
| 699 |
struct dom_sid *psid = NULL; |
| 700 |
NTSTATUS status; |
| 701 |
|
| 702 |
if (io->in.domain_guid != NULL) { |
| 703 |
GUID_from_string(io->in.domain_guid, &guid); |
| 704 |
pguid = &guid; |
| 705 |
} |
| 706 |
if (io->in.domain_sid != NULL) { |
| 707 |
dom_sid_parse(io->in.domain_sid, &sid); |
| 708 |
psid = &sid; |
| 709 |
} |
| 710 |
|
| 711 |
status = netlogon_pings(mem_ctx, |
| 712 |
state->proto, |
| 713 |
&state->dest, |
| 714 |
1, |
| 715 |
(struct netlogon_ping_filter){ |
| 716 |
.acct_ctrl = io->in.acct_control, |
| 717 |
.ntversion = io->in.version, |
| 718 |
.domain = io->in.realm, |
| 719 |
.hostname = io->in.host, |
| 720 |
.user = io->in.user, |
| 721 |
.domain_sid = psid, |
| 722 |
.domain_guid = pguid, |
| 723 |
}, |
| 724 |
1, |
| 725 |
tevent_timeval_current_ofs(2, 0), |
| 726 |
&responses); |
| 727 |
if (!NT_STATUS_IS_OK(status)) { |
| 728 |
return status; |
| 729 |
} |
| 730 |
map_netlogon_samlogon_response(responses[0]); |
| 731 |
io->out.netlogon = responses[0]; |
| 732 |
return NT_STATUS_OK; |
| 733 |
} |
| 734 |
|
| 735 |
bool torture_netlogon_ping(struct torture_context *tctx) |
| 736 |
{ |
| 737 |
const char *host = torture_setting_string(tctx, "host", NULL); |
| 738 |
struct test_netlogon_ping_state state = {}; |
| 739 |
const char *ip; |
| 740 |
struct nbt_name nbt_name; |
| 741 |
bool ret = true; |
| 742 |
int r; |
| 743 |
NTSTATUS status; |
| 744 |
|
| 745 |
make_nbt_name_server(&nbt_name, host); |
| 746 |
|
| 747 |
status = resolve_name_ex(lpcfg_resolve_context(tctx->lp_ctx), |
| 748 |
0, |
| 749 |
0, |
| 750 |
&nbt_name, |
| 751 |
tctx, |
| 752 |
&ip, |
| 753 |
tctx->ev); |
| 754 |
torture_assert_ntstatus_ok(tctx, |
| 755 |
status, |
| 756 |
talloc_asprintf(tctx, |
| 757 |
"Failed to resolve %s: %s", |
| 758 |
nbt_name.name, |
| 759 |
nt_errstr(status))); |
| 760 |
|
| 761 |
r = tsocket_address_inet_from_strings( |
| 762 |
tctx, "ip", ip, 389, &state.dest); |
| 763 |
CHECK_VAL(r, 0); |
| 764 |
|
| 765 |
state.proto = CLIENT_NETLOGON_PING_CLDAP; |
| 766 |
ret &= test_ldap_netlogon(tctx, test_netlogon_ping, &state, host); |
| 767 |
ret &= test_ldap_netlogon_flags(tctx, |
| 768 |
test_netlogon_ping, |
| 769 |
&state, |
| 770 |
host); |
| 771 |
|
| 772 |
state.proto = CLIENT_NETLOGON_PING_LDAP; |
| 773 |
ret &= test_ldap_netlogon(tctx, test_netlogon_ping, &state, host); |
| 774 |
ret &= test_ldap_netlogon_flags(tctx, |
| 775 |
test_netlogon_ping, |
| 776 |
&state, |
| 777 |
host); |
| 778 |
return ret; |
| 779 |
} |