| 1 |
/* |
| 2 |
Unix SMB/CIFS implementation. |
| 3 |
|
| 4 |
test suite for netlogon rpc operations |
| 5 |
|
| 6 |
Copyright (C) Andrew Tridgell 2003 |
| 7 |
Copyright (C) Andrew Bartlett <[email protected]> 2003-2004 |
| 8 |
Copyright (C) Tim Potter 2003 |
| 9 |
Copyright (C) Matthias Dieter Wallnöfer 2009-2010 |
| 10 |
|
| 11 |
This program is free software; you can redistribute it and/or modify |
| 12 |
it under the terms of the GNU General Public License as published by |
| 13 |
the Free Software Foundation; either version 3 of the License, or |
| 14 |
(at your option) any later version. |
| 15 |
|
| 16 |
This program is distributed in the hope that it will be useful, |
| 17 |
but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 18 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 19 |
GNU General Public License for more details. |
| 20 |
|
| 21 |
You should have received a copy of the GNU General Public License |
| 22 |
along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 23 |
*/ |
| 24 |
|
| 25 |
#include "includes.h" |
| 26 |
#include "lib/events/events.h" |
| 27 |
#include "lib/cmdline/cmdline.h" |
| 28 |
#include "torture/rpc/torture_rpc.h" |
| 29 |
#include "../lib/crypto/crypto.h" |
| 30 |
#include "libcli/auth/libcli_auth.h" |
| 31 |
#include "librpc/gen_ndr/ndr_netlogon_c.h" |
| 32 |
#include "librpc/gen_ndr/ndr_lsa_c.h" |
| 33 |
#include "param/param.h" |
| 34 |
#include "libcli/security/security.h" |
| 35 |
#include <ldb.h> |
| 36 |
#include "lib/util/util_ldb.h" |
| 37 |
#include "ldb_wrap.h" |
| 38 |
#include "lib/replace/system/network.h" |
| 39 |
#include "dsdb/samdb/samdb.h" |
| 40 |
|
| 41 |
#undef strcasecmp |
| 42 |
|
| 43 |
#define TEST_MACHINE_NAME "torturetest" |
| 44 |
|
| 45 |
static bool test_netr_broken_binding_handle(struct torture_context *tctx, |
| 46 |
struct dcerpc_pipe *p) |
| 47 |
{ |
| 48 |
NTSTATUS status; |
| 49 |
struct netr_DsRGetSiteName r; |
| 50 |
const char *site = NULL; |
| 51 |
struct dcerpc_binding_handle *b = p->binding_handle; |
| 52 |
|
| 53 |
r.in.computer_name = talloc_asprintf(tctx, "\\\\%s", |
| 54 |
dcerpc_server_name(p)); |
| 55 |
r.out.site = &site; |
| 56 |
|
| 57 |
torture_comment(tctx, |
| 58 |
"Testing netlogon request with correct binding handle: %s\n", |
| 59 |
r.in.computer_name); |
| 60 |
|
| 61 |
status = dcerpc_netr_DsRGetSiteName_r(b, tctx, &r); |
| 62 |
torture_assert_ntstatus_ok(tctx, status, |
| 63 |
"Netlogon request with broken binding handle"); |
| 64 |
torture_assert_werr_ok(tctx, r.out.result, |
| 65 |
"Netlogon request with broken binding handle"); |
| 66 |
|
| 67 |
if (torture_setting_bool(tctx, "samba3", false) || |
| 68 |
torture_setting_bool(tctx, "samba4", false)) { |
| 69 |
torture_skip(tctx, |
| 70 |
"Skipping broken binding handle check against Samba"); |
| 71 |
} |
| 72 |
|
| 73 |
r.in.computer_name = talloc_asprintf(tctx, "\\\\\\\\%s", |
| 74 |
dcerpc_server_name(p)); |
| 75 |
|
| 76 |
torture_comment(tctx, |
| 77 |
"Testing netlogon request with broken binding handle: %s\n", |
| 78 |
r.in.computer_name); |
| 79 |
|
| 80 |
status = dcerpc_netr_DsRGetSiteName_r(b, tctx, &r); |
| 81 |
torture_assert_ntstatus_ok(tctx, status, |
| 82 |
"Netlogon request with broken binding handle"); |
| 83 |
torture_assert_werr_equal(tctx, r.out.result, |
| 84 |
WERR_INVALID_COMPUTERNAME, |
| 85 |
"Netlogon request with broken binding handle"); |
| 86 |
|
| 87 |
r.in.computer_name = "\\\\\\\\THIS_IS_NOT_VALID"; |
| 88 |
|
| 89 |
torture_comment(tctx, |
| 90 |
"Testing netlogon request with broken binding handle: %s\n", |
| 91 |
r.in.computer_name); |
| 92 |
|
| 93 |
status = dcerpc_netr_DsRGetSiteName_r(b, tctx, &r); |
| 94 |
torture_assert_ntstatus_ok(tctx, status, |
| 95 |
"Netlogon request with broken binding handle"); |
| 96 |
torture_assert_werr_equal(tctx, r.out.result, |
| 97 |
WERR_INVALID_COMPUTERNAME, |
| 98 |
"Netlogon request with broken binding handle"); |
| 99 |
|
| 100 |
return true; |
| 101 |
} |
| 102 |
|
| 103 |
static bool test_LogonUasLogon(struct torture_context *tctx, |
| 104 |
struct dcerpc_pipe *p) |
| 105 |
{ |
| 106 |
NTSTATUS status; |
| 107 |
struct netr_LogonUasLogon r; |
| 108 |
struct netr_UasInfo *info = NULL; |
| 109 |
struct dcerpc_binding_handle *b = p->binding_handle; |
| 110 |
|
| 111 |
r.in.server_name = NULL; |
| 112 |
r.in.account_name = cli_credentials_get_username( |
| 113 |
samba_cmdline_get_creds()); |
| 114 |
r.in.workstation = TEST_MACHINE_NAME; |
| 115 |
r.out.info = &info; |
| 116 |
|
| 117 |
status = dcerpc_netr_LogonUasLogon_r(b, tctx, &r); |
| 118 |
torture_assert_ntstatus_ok(tctx, status, "LogonUasLogon"); |
| 119 |
|
| 120 |
return true; |
| 121 |
} |
| 122 |
|
| 123 |
static bool test_LogonUasLogoff(struct torture_context *tctx, |
| 124 |
struct dcerpc_pipe *p) |
| 125 |
{ |
| 126 |
NTSTATUS status; |
| 127 |
struct netr_LogonUasLogoff r; |
| 128 |
struct netr_UasLogoffInfo info; |
| 129 |
struct dcerpc_binding_handle *b = p->binding_handle; |
| 130 |
|
| 131 |
r.in.server_name = NULL; |
| 132 |
r.in.account_name = cli_credentials_get_username( |
| 133 |
samba_cmdline_get_creds()); |
| 134 |
r.in.workstation = TEST_MACHINE_NAME; |
| 135 |
r.out.info = &info; |
| 136 |
|
| 137 |
status = dcerpc_netr_LogonUasLogoff_r(b, tctx, &r); |
| 138 |
torture_assert_ntstatus_ok(tctx, status, "LogonUasLogoff"); |
| 139 |
|
| 140 |
return true; |
| 141 |
} |
| 142 |
|
| 143 |
bool test_SetupCredentials(struct dcerpc_pipe *p, struct torture_context *tctx, |
| 144 |
struct cli_credentials *credentials, |
| 145 |
struct netlogon_creds_CredentialState **creds_out) |
| 146 |
{ |
| 147 |
struct netr_ServerReqChallenge r; |
| 148 |
struct netr_ServerAuthenticate a; |
| 149 |
struct netr_Credential credentials1, credentials2, credentials3; |
| 150 |
struct netlogon_creds_CredentialState *creds; |
| 151 |
const struct samr_Password *mach_password; |
| 152 |
const char *machine_name; |
| 153 |
struct dcerpc_binding_handle *b = p->binding_handle; |
| 154 |
|
| 155 |
mach_password = cli_credentials_get_nt_hash(credentials, tctx); |
| 156 |
machine_name = cli_credentials_get_workstation(credentials); |
| 157 |
|
| 158 |
torture_comment(tctx, "Testing ServerReqChallenge\n"); |
| 159 |
|
| 160 |
r.in.server_name = NULL; |
| 161 |
r.in.computer_name = machine_name; |
| 162 |
r.in.credentials = &credentials1; |
| 163 |
r.out.return_credentials = &credentials2; |
| 164 |
|
| 165 |
netlogon_creds_random_challenge(&credentials1); |
| 166 |
|
| 167 |
torture_assert_ntstatus_ok(tctx, dcerpc_netr_ServerReqChallenge_r(b, tctx, &r), |
| 168 |
"ServerReqChallenge failed"); |
| 169 |
torture_assert_ntstatus_ok(tctx, r.out.result, "ServerReqChallenge failed"); |
| 170 |
|
| 171 |
a.in.server_name = NULL; |
| 172 |
a.in.account_name = talloc_asprintf(tctx, "%s$", machine_name); |
| 173 |
a.in.secure_channel_type = cli_credentials_get_secure_channel_type(credentials); |
| 174 |
a.in.computer_name = machine_name; |
| 175 |
a.in.credentials = &credentials3; |
| 176 |
a.out.return_credentials = &credentials3; |
| 177 |
|
| 178 |
creds = netlogon_creds_client_init(tctx, a.in.account_name, |
| 179 |
a.in.computer_name, |
| 180 |
a.in.secure_channel_type, |
| 181 |
&credentials1, &credentials2, |
| 182 |
mach_password, &credentials3, |
| 183 |
0, |
| 184 |
0); |
| 185 |
torture_assert(tctx, creds != NULL, "memory allocation"); |
| 186 |
|
| 187 |
|
| 188 |
torture_comment(tctx, "Testing ServerAuthenticate\n"); |
| 189 |
|
| 190 |
torture_assert_ntstatus_ok(tctx, dcerpc_netr_ServerAuthenticate_r(b, tctx, &a), |
| 191 |
"ServerAuthenticate failed"); |
| 192 |
|
| 193 |
/* This allows the tests to continue against the more fussy windows 2008 */ |
| 194 |
if (NT_STATUS_EQUAL(a.out.result, NT_STATUS_DOWNGRADE_DETECTED)) { |
| 195 |
return test_SetupCredentials2(p, tctx, NETLOGON_NEG_AUTH2_ADS_FLAGS | NETLOGON_NEG_SUPPORTS_AES, |
| 196 |
credentials, |
| 197 |
cli_credentials_get_secure_channel_type(credentials), |
| 198 |
creds_out); |
| 199 |
} |
| 200 |
|
| 201 |
torture_assert_ntstatus_ok(tctx, a.out.result, "ServerAuthenticate"); |
| 202 |
|
| 203 |
torture_assert(tctx, netlogon_creds_client_check(creds, &credentials3), |
| 204 |
"Credential chaining failed"); |
| 205 |
|
| 206 |
*creds_out = creds; |
| 207 |
return true; |
| 208 |
} |
| 209 |
|
| 210 |
bool test_SetupCredentials2ex(struct dcerpc_pipe *p, struct torture_context *tctx, |
| 211 |
uint32_t negotiate_flags, |
| 212 |
struct cli_credentials *machine_credentials, |
| 213 |
const char *computer_name, |
| 214 |
enum netr_SchannelType sec_chan_type, |
| 215 |
NTSTATUS expected_result, |
| 216 |
struct netlogon_creds_CredentialState **creds_out) |
| 217 |
{ |
| 218 |
struct netr_ServerReqChallenge r; |
| 219 |
struct netr_ServerAuthenticate2 a; |
| 220 |
struct netr_Credential credentials1, credentials2, credentials3; |
| 221 |
struct netlogon_creds_CredentialState *creds; |
| 222 |
const struct samr_Password *mach_password; |
| 223 |
struct dcerpc_binding_handle *b = p->binding_handle; |
| 224 |
const char *account_name = cli_credentials_get_username(machine_credentials); |
| 225 |
|
| 226 |
mach_password = cli_credentials_get_nt_hash(machine_credentials, tctx); |
| 227 |
|
| 228 |
torture_comment(tctx, "Testing ServerReqChallenge\n"); |
| 229 |
|
| 230 |
r.in.server_name = NULL; |
| 231 |
r.in.computer_name = computer_name; |
| 232 |
r.in.credentials = &credentials1; |
| 233 |
r.out.return_credentials = &credentials2; |
| 234 |
|
| 235 |
netlogon_creds_random_challenge(&credentials1); |
| 236 |
|
| 237 |
torture_assert_ntstatus_ok(tctx, dcerpc_netr_ServerReqChallenge_r(b, tctx, &r), |
| 238 |
"ServerReqChallenge failed"); |
| 239 |
torture_assert_ntstatus_ok(tctx, r.out.result, "ServerReqChallenge failed"); |
| 240 |
|
| 241 |
a.in.server_name = NULL; |
| 242 |
a.in.account_name = account_name; |
| 243 |
a.in.secure_channel_type = sec_chan_type; |
| 244 |
a.in.computer_name = computer_name; |
| 245 |
a.in.negotiate_flags = &negotiate_flags; |
| 246 |
a.out.negotiate_flags = &negotiate_flags; |
| 247 |
a.in.credentials = &credentials3; |
| 248 |
a.out.return_credentials = &credentials3; |
| 249 |
|
| 250 |
creds = netlogon_creds_client_init(tctx, a.in.account_name, |
| 251 |
a.in.computer_name, |
| 252 |
a.in.secure_channel_type, |
| 253 |
&credentials1, &credentials2, |
| 254 |
mach_password, &credentials3, |
| 255 |
negotiate_flags, |
| 256 |
negotiate_flags); |
| 257 |
|
| 258 |
torture_assert(tctx, creds != NULL, "memory allocation"); |
| 259 |
|
| 260 |
torture_comment(tctx, "Testing ServerAuthenticate2\n"); |
| 261 |
|
| 262 |
torture_assert_ntstatus_ok(tctx, dcerpc_netr_ServerAuthenticate2_r(b, tctx, &a), |
| 263 |
"ServerAuthenticate2 failed"); |
| 264 |
torture_assert_ntstatus_equal(tctx, a.out.result, expected_result, |
| 265 |
"ServerAuthenticate2 unexpected"); |
| 266 |
|
| 267 |
if (NT_STATUS_IS_OK(expected_result)) { |
| 268 |
torture_assert(tctx, netlogon_creds_client_check(creds, &credentials3), |
| 269 |
"Credential chaining failed"); |
| 270 |
} else { |
| 271 |
torture_assert(tctx, !netlogon_creds_client_check(creds, &credentials3), |
| 272 |
"Credential chaining passed unexpected"); |
| 273 |
} |
| 274 |
|
| 275 |
torture_comment(tctx, "negotiate_flags=0x%08x\n", negotiate_flags); |
| 276 |
|
| 277 |
*creds_out = creds; |
| 278 |
return true; |
| 279 |
} |
| 280 |
|
| 281 |
bool test_SetupCredentials2(struct dcerpc_pipe *p, struct torture_context *tctx, |
| 282 |
uint32_t negotiate_flags, |
| 283 |
struct cli_credentials *machine_credentials, |
| 284 |
enum netr_SchannelType sec_chan_type, |
| 285 |
struct netlogon_creds_CredentialState **creds_out) |
| 286 |
{ |
| 287 |
const char *computer_name = |
| 288 |
cli_credentials_get_workstation(machine_credentials); |
| 289 |
|
| 290 |
return test_SetupCredentials2ex(p, tctx, negotiate_flags, |
| 291 |
machine_credentials, |
| 292 |
computer_name, |
| 293 |
sec_chan_type, |
| 294 |
NT_STATUS_OK, |
| 295 |
creds_out); |
| 296 |
} |
| 297 |
|
| 298 |
bool test_SetupCredentials3(struct dcerpc_pipe *p, struct torture_context *tctx, |
| 299 |
uint32_t negotiate_flags, |
| 300 |
struct cli_credentials *machine_credentials, |
| 301 |
struct netlogon_creds_CredentialState **creds_out) |
| 302 |
{ |
| 303 |
struct netr_ServerReqChallenge r; |
| 304 |
struct netr_ServerAuthenticate3 a; |
| 305 |
struct netr_Credential credentials1, credentials2, credentials3; |
| 306 |
struct netlogon_creds_CredentialState *creds; |
| 307 |
struct samr_Password mach_password; |
| 308 |
uint32_t rid; |
| 309 |
const char *machine_name; |
| 310 |
const char *plain_pass; |
| 311 |
struct dcerpc_binding_handle *b = NULL; |
| 312 |
|
| 313 |
if (p == NULL) { |
| 314 |
return false; |
| 315 |
} |
| 316 |
|
| 317 |
b = p->binding_handle; |
| 318 |
|
| 319 |
machine_name = cli_credentials_get_workstation(machine_credentials); |
| 320 |
torture_assert(tctx, machine_name != NULL, "machine_name"); |
| 321 |
plain_pass = cli_credentials_get_password(machine_credentials); |
| 322 |
torture_assert(tctx, plain_pass != NULL, "plain_pass"); |
| 323 |
|
| 324 |
torture_comment(tctx, "Testing ServerReqChallenge\n"); |
| 325 |
|
| 326 |
r.in.server_name = NULL; |
| 327 |
r.in.computer_name = machine_name; |
| 328 |
r.in.credentials = &credentials1; |
| 329 |
r.out.return_credentials = &credentials2; |
| 330 |
|
| 331 |
netlogon_creds_random_challenge(&credentials1); |
| 332 |
|
| 333 |
torture_assert_ntstatus_ok(tctx, dcerpc_netr_ServerReqChallenge_r(b, tctx, &r), |
| 334 |
"ServerReqChallenge failed"); |
| 335 |
torture_assert_ntstatus_ok(tctx, r.out.result, "ServerReqChallenge failed"); |
| 336 |
|
| 337 |
E_md4hash(plain_pass, mach_password.hash); |
| 338 |
|
| 339 |
a.in.server_name = NULL; |
| 340 |
a.in.account_name = talloc_asprintf(tctx, "%s$", machine_name); |
| 341 |
a.in.secure_channel_type = cli_credentials_get_secure_channel_type(machine_credentials); |
| 342 |
a.in.computer_name = machine_name; |
| 343 |
a.in.negotiate_flags = &negotiate_flags; |
| 344 |
a.in.credentials = &credentials3; |
| 345 |
a.out.return_credentials = &credentials3; |
| 346 |
a.out.negotiate_flags = &negotiate_flags; |
| 347 |
a.out.rid = &rid; |
| 348 |
|
| 349 |
creds = netlogon_creds_client_init(tctx, a.in.account_name, |
| 350 |
a.in.computer_name, |
| 351 |
a.in.secure_channel_type, |
| 352 |
&credentials1, &credentials2, |
| 353 |
&mach_password, &credentials3, |
| 354 |
negotiate_flags, |
| 355 |
negotiate_flags); |
| 356 |
|
| 357 |
torture_assert(tctx, creds != NULL, "memory allocation"); |
| 358 |
|
| 359 |
torture_comment(tctx, "Testing ServerAuthenticate3\n"); |
| 360 |
|
| 361 |
torture_assert_ntstatus_ok(tctx, dcerpc_netr_ServerAuthenticate3_r(b, tctx, &a), |
| 362 |
"ServerAuthenticate3 failed"); |
| 363 |
torture_assert_ntstatus_ok(tctx, a.out.result, "ServerAuthenticate3 failed"); |
| 364 |
torture_assert(tctx, netlogon_creds_client_check(creds, &credentials3), "Credential chaining failed"); |
| 365 |
|
| 366 |
torture_comment(tctx, "negotiate_flags=0x%08x\n", negotiate_flags); |
| 367 |
|
| 368 |
/* Prove that requesting a challenge again won't break it */ |
| 369 |
torture_assert_ntstatus_ok(tctx, dcerpc_netr_ServerReqChallenge_r(b, tctx, &r), |
| 370 |
"ServerReqChallenge failed"); |
| 371 |
torture_assert_ntstatus_ok(tctx, r.out.result, "ServerReqChallenge failed"); |
| 372 |
|
| 373 |
*creds_out = creds; |
| 374 |
return true; |
| 375 |
} |
| 376 |
|
| 377 |
bool test_SetupCredentialsDowngrade(struct torture_context *tctx, |
| 378 |
struct dcerpc_pipe *p, |
| 379 |
struct cli_credentials *machine_credentials) |
| 380 |
{ |
| 381 |
struct netr_ServerReqChallenge r; |
| 382 |
struct netr_ServerAuthenticate3 a; |
| 383 |
struct netr_Credential credentials1, credentials2, credentials3; |
| 384 |
struct netlogon_creds_CredentialState *creds; |
| 385 |
struct samr_Password mach_password; |
| 386 |
uint32_t rid; |
| 387 |
const char *machine_name; |
| 388 |
const char *plain_pass; |
| 389 |
struct dcerpc_binding_handle *b = p->binding_handle; |
| 390 |
uint32_t negotiate_flags = 0; |
| 391 |
|
| 392 |
machine_name = cli_credentials_get_workstation(machine_credentials); |
| 393 |
torture_assert(tctx, machine_name != NULL, "machine_name"); |
| 394 |
plain_pass = cli_credentials_get_password(machine_credentials); |
| 395 |
torture_assert(tctx, plain_pass != NULL, "plain_pass"); |
| 396 |
|
| 397 |
torture_comment(tctx, "Testing ServerReqChallenge\n"); |
| 398 |
|
| 399 |
r.in.server_name = NULL; |
| 400 |
r.in.computer_name = machine_name; |
| 401 |
r.in.credentials = &credentials1; |
| 402 |
r.out.return_credentials = &credentials2; |
| 403 |
|
| 404 |
netlogon_creds_random_challenge(&credentials1); |
| 405 |
|
| 406 |
torture_assert_ntstatus_ok(tctx, dcerpc_netr_ServerReqChallenge_r(b, tctx, &r), |
| 407 |
"ServerReqChallenge failed"); |
| 408 |
torture_assert_ntstatus_ok(tctx, r.out.result, "ServerReqChallenge failed"); |
| 409 |
|
| 410 |
E_md4hash(plain_pass, mach_password.hash); |
| 411 |
|
| 412 |
a.in.server_name = NULL; |
| 413 |
a.in.account_name = talloc_asprintf(tctx, "%s$", machine_name); |
| 414 |
a.in.secure_channel_type = cli_credentials_get_secure_channel_type(machine_credentials); |
| 415 |
a.in.computer_name = machine_name; |
| 416 |
a.in.negotiate_flags = &negotiate_flags; |
| 417 |
a.in.credentials = &credentials3; |
| 418 |
a.out.return_credentials = &credentials3; |
| 419 |
a.out.negotiate_flags = &negotiate_flags; |
| 420 |
a.out.rid = &rid; |
| 421 |
|
| 422 |
creds = netlogon_creds_client_init(tctx, a.in.account_name, |
| 423 |
a.in.computer_name, |
| 424 |
a.in.secure_channel_type, |
| 425 |
&credentials1, &credentials2, |
| 426 |
&mach_password, &credentials3, |
| 427 |
negotiate_flags, |
| 428 |
negotiate_flags); |
| 429 |
|
| 430 |
torture_assert(tctx, creds != NULL, "memory allocation"); |
| 431 |
|
| 432 |
torture_comment(tctx, "Testing ServerAuthenticate3\n"); |
| 433 |
|
| 434 |
torture_assert_ntstatus_ok(tctx, dcerpc_netr_ServerAuthenticate3_r(b, tctx, &a), |
| 435 |
"ServerAuthenticate3 failed"); |
| 436 |
torture_assert_ntstatus_equal(tctx, a.out.result, NT_STATUS_DOWNGRADE_DETECTED, "ServerAuthenticate3 should have failed"); |
| 437 |
|
| 438 |
negotiate_flags = NETLOGON_NEG_AUTH2_ADS_FLAGS | NETLOGON_NEG_SUPPORTS_AES; |
| 439 |
creds = netlogon_creds_client_init(tctx, a.in.account_name, |
| 440 |
a.in.computer_name, |
| 441 |
a.in.secure_channel_type, |
| 442 |
&credentials1, &credentials2, |
| 443 |
&mach_password, &credentials3, |
| 444 |
negotiate_flags, |
| 445 |
negotiate_flags); |
| 446 |
|
| 447 |
torture_assert(tctx, creds != NULL, "memory allocation"); |
| 448 |
|
| 449 |
torture_comment(tctx, "Testing ServerAuthenticate3\n"); |
| 450 |
|
| 451 |
torture_assert_ntstatus_ok(tctx, dcerpc_netr_ServerAuthenticate3_r(b, tctx, &a), |
| 452 |
"ServerAuthenticate3 failed"); |
| 453 |
torture_assert_ntstatus_ok(tctx, a.out.result, "ServerAuthenticate3 should succeed"); |
| 454 |
|
| 455 |
torture_assert(tctx, netlogon_creds_client_check(creds, &credentials3), "Credential chaining failed"); |
| 456 |
|
| 457 |
torture_comment(tctx, "negotiate_flags=0x%08x\n", negotiate_flags); |
| 458 |
|
| 459 |
/* Prove that requesting a challenge again won't break it */ |
| 460 |
torture_assert_ntstatus_ok(tctx, dcerpc_netr_ServerReqChallenge_r(b, tctx, &r), |
| 461 |
"ServerReqChallenge failed"); |
| 462 |
torture_assert_ntstatus_ok(tctx, r.out.result, "ServerReqChallenge failed"); |
| 463 |
|
| 464 |
return true; |
| 465 |
} |
| 466 |
|
| 467 |
bool test_SetupCredentialsPipe(const struct dcerpc_pipe *p1, |
| 468 |
struct torture_context *tctx, |
| 469 |
struct cli_credentials *machine_credentials, |
| 470 |
struct netlogon_creds_CredentialState *creds, |
| 471 |
uint32_t additional_flags, |
| 472 |
struct dcerpc_pipe **_p2) |
| 473 |
{ |
| 474 |
NTSTATUS status; |
| 475 |
const struct dcerpc_binding *b1 = |
| 476 |
dcerpc_binding_handle_get_binding(p1->binding_handle); |
| 477 |
struct dcerpc_binding *b2 = NULL; |
| 478 |
struct dcerpc_pipe *p2 = NULL; |
| 479 |
|
| 480 |
b2 = dcerpc_binding_dup(tctx, b1); |
| 481 |
torture_assert(tctx, b2 != NULL, "dcerpc_binding_dup"); |
| 482 |
dcerpc_binding_set_flags(b2, |
| 483 |
DCERPC_SCHANNEL | additional_flags, |
| 484 |
DCERPC_AUTH_OPTIONS); |
| 485 |
|
| 486 |
cli_credentials_set_netlogon_creds(machine_credentials, creds); |
| 487 |
status = dcerpc_pipe_connect_b(tctx, &p2, b2, |
| 488 |
&ndr_table_netlogon, |
| 489 |
machine_credentials, |
| 490 |
tctx->ev, tctx->lp_ctx); |
| 491 |
cli_credentials_set_netlogon_creds(machine_credentials, NULL); |
| 492 |
torture_assert_ntstatus_ok(tctx, status, "dcerpc_pipe_connect_b schannel"); |
| 493 |
|
| 494 |
*_p2 = p2; |
| 495 |
return true; |
| 496 |
} |
| 497 |
|
| 498 |
static bool test_ServerReqChallenge( |
| 499 |
struct torture_context *tctx, |
| 500 |
struct dcerpc_pipe *p, |
| 501 |
struct cli_credentials *credentials) |
| 502 |
{ |
| 503 |
struct netr_ServerReqChallenge r; |
| 504 |
struct netr_Credential credentials1, credentials2, credentials3; |
| 505 |
const char *machine_name; |
| 506 |
struct dcerpc_binding_handle *b = p->binding_handle; |
| 507 |
struct netr_ServerAuthenticate2 a; |
| 508 |
uint32_t in_negotiate_flags = NETLOGON_NEG_AUTH2_ADS_FLAGS | NETLOGON_NEG_SUPPORTS_AES; |
| 509 |
uint32_t out_negotiate_flags = 0; |
| 510 |
const struct samr_Password *mach_password = NULL; |
| 511 |
enum netr_SchannelType sec_chan_type = 0; |
| 512 |
struct netlogon_creds_CredentialState *creds = NULL; |
| 513 |
const char *account_name = NULL; |
| 514 |
|
| 515 |
machine_name = cli_credentials_get_workstation(credentials); |
| 516 |
mach_password = cli_credentials_get_nt_hash(credentials, tctx); |
| 517 |
account_name = cli_credentials_get_username(credentials); |
| 518 |
sec_chan_type = cli_credentials_get_secure_channel_type(credentials); |
| 519 |
|
| 520 |
torture_comment(tctx, "Testing ServerReqChallenge\n"); |
| 521 |
|
| 522 |
r.in.server_name = NULL; |
| 523 |
r.in.computer_name = machine_name; |
| 524 |
r.in.credentials = &credentials1; |
| 525 |
r.out.return_credentials = &credentials2; |
| 526 |
|
| 527 |
netlogon_creds_random_challenge(&credentials1); |
| 528 |
|
| 529 |
torture_assert_ntstatus_ok( |
| 530 |
tctx, |
| 531 |
dcerpc_netr_ServerReqChallenge_r(b, tctx, &r), |
| 532 |
"ServerReqChallenge failed"); |
| 533 |
torture_assert_ntstatus_ok( |
| 534 |
tctx, |
| 535 |
r.out.result, |
| 536 |
"ServerReqChallenge failed"); |
| 537 |
a.in.server_name = NULL; |
| 538 |
a.in.account_name = account_name; |
| 539 |
a.in.secure_channel_type = sec_chan_type; |
| 540 |
a.in.computer_name = machine_name; |
| 541 |
a.in.negotiate_flags = &in_negotiate_flags; |
| 542 |
a.out.negotiate_flags = &out_negotiate_flags; |
| 543 |
a.in.credentials = &credentials3; |
| 544 |
a.out.return_credentials = &credentials3; |
| 545 |
|
| 546 |
creds = netlogon_creds_client_init(tctx, a.in.account_name, |
| 547 |
a.in.computer_name, |
| 548 |
a.in.secure_channel_type, |
| 549 |
&credentials1, &credentials2, |
| 550 |
mach_password, &credentials3, |
| 551 |
in_negotiate_flags, |
| 552 |
in_negotiate_flags); |
| 553 |
|
| 554 |
torture_assert(tctx, creds != NULL, "memory allocation"); |
| 555 |
|
| 556 |
torture_comment(tctx, "Testing ServerAuthenticate2\n"); |
| 557 |
|
| 558 |
torture_assert_ntstatus_ok( |
| 559 |
tctx, |
| 560 |
dcerpc_netr_ServerAuthenticate2_r(b, tctx, &a), |
| 561 |
"ServerAuthenticate2 failed"); |
| 562 |
torture_assert_ntstatus_equal( |
| 563 |
tctx, |
| 564 |
a.out.result, |
| 565 |
NT_STATUS_OK, |
| 566 |
"ServerAuthenticate2 unexpected"); |
| 567 |
|
| 568 |
return true; |
| 569 |
} |
| 570 |
|
| 571 |
static bool test_ServerReqChallenge_zero_challenge( |
| 572 |
struct torture_context *tctx, |
| 573 |
struct dcerpc_pipe *p, |
| 574 |
struct cli_credentials *credentials) |
| 575 |
{ |
| 576 |
struct netr_ServerReqChallenge r; |
| 577 |
struct netr_Credential credentials1, credentials2, credentials3; |
| 578 |
const char *machine_name; |
| 579 |
struct dcerpc_binding_handle *b = p->binding_handle; |
| 580 |
struct netr_ServerAuthenticate2 a; |
| 581 |
uint32_t in_negotiate_flags = NETLOGON_NEG_AUTH2_ADS_FLAGS | NETLOGON_NEG_SUPPORTS_AES; |
| 582 |
uint32_t out_negotiate_flags = 0; |
| 583 |
const struct samr_Password *mach_password = NULL; |
| 584 |
enum netr_SchannelType sec_chan_type = 0; |
| 585 |
struct netlogon_creds_CredentialState *creds = NULL; |
| 586 |
const char *account_name = NULL; |
| 587 |
|
| 588 |
machine_name = cli_credentials_get_workstation(credentials); |
| 589 |
mach_password = cli_credentials_get_nt_hash(credentials, tctx); |
| 590 |
account_name = cli_credentials_get_username(credentials); |
| 591 |
sec_chan_type = cli_credentials_get_secure_channel_type(credentials); |
| 592 |
|
| 593 |
torture_comment(tctx, "Testing ServerReqChallenge\n"); |
| 594 |
|
| 595 |
r.in.server_name = NULL; |
| 596 |
r.in.computer_name = machine_name; |
| 597 |
r.in.credentials = &credentials1; |
| 598 |
r.out.return_credentials = &credentials2; |
| 599 |
|
| 600 |
/* |
| 601 |
* Set the client challenge to zero, this should fail |
| 602 |
* CVE-2020-1472(ZeroLogon) |
| 603 |
* BUG: https://bugzilla.samba.org/show_bug.cgi?id=14497 |
| 604 |
*/ |
| 605 |
ZERO_STRUCT(credentials1); |
| 606 |
|
| 607 |
torture_assert_ntstatus_ok( |
| 608 |
tctx, |
| 609 |
dcerpc_netr_ServerReqChallenge_r(b, tctx, &r), |
| 610 |
"ServerReqChallenge failed"); |
| 611 |
torture_assert_ntstatus_ok( |
| 612 |
tctx, |
| 613 |
r.out.result, |
| 614 |
"ServerReqChallenge failed"); |
| 615 |
a.in.server_name = NULL; |
| 616 |
a.in.account_name = account_name; |
| 617 |
a.in.secure_channel_type = sec_chan_type; |
| 618 |
a.in.computer_name = machine_name; |
| 619 |
a.in.negotiate_flags = &in_negotiate_flags; |
| 620 |
a.out.negotiate_flags = &out_negotiate_flags; |
| 621 |
a.in.credentials = &credentials3; |
| 622 |
a.out.return_credentials = &credentials3; |
| 623 |
|
| 624 |
creds = netlogon_creds_client_init(tctx, a.in.account_name, |
| 625 |
a.in.computer_name, |
| 626 |
a.in.secure_channel_type, |
| 627 |
&credentials1, &credentials2, |
| 628 |
mach_password, &credentials3, |
| 629 |
in_negotiate_flags, |
| 630 |
in_negotiate_flags); |
| 631 |
|
| 632 |
torture_assert(tctx, creds != NULL, "memory allocation"); |
| 633 |
|
| 634 |
torture_comment(tctx, "Testing ServerAuthenticate2\n"); |
| 635 |
|
| 636 |
torture_assert_ntstatus_ok( |
| 637 |
tctx, |
| 638 |
dcerpc_netr_ServerAuthenticate2_r(b, tctx, &a), |
| 639 |
"ServerAuthenticate2 failed"); |
| 640 |
torture_assert_ntstatus_equal( |
| 641 |
tctx, |
| 642 |
a.out.result, |
| 643 |
NT_STATUS_ACCESS_DENIED, |
| 644 |
"ServerAuthenticate2 unexpected"); |
| 645 |
|
| 646 |
return true; |
| 647 |
} |
| 648 |
|
| 649 |
static bool test_ServerReqChallenge_5_repeats( |
| 650 |
struct torture_context *tctx, |
| 651 |
struct dcerpc_pipe *p, |
| 652 |
struct cli_credentials *credentials) |
| 653 |
{ |
| 654 |
struct netr_ServerReqChallenge r; |
| 655 |
struct netr_Credential credentials1, credentials2, credentials3; |
| 656 |
const char *machine_name; |
| 657 |
struct dcerpc_binding_handle *b = p->binding_handle; |
| 658 |
struct netr_ServerAuthenticate2 a; |
| 659 |
uint32_t in_negotiate_flags = NETLOGON_NEG_AUTH2_ADS_FLAGS | NETLOGON_NEG_SUPPORTS_AES; |
| 660 |
uint32_t out_negotiate_flags = 0; |
| 661 |
const struct samr_Password *mach_password = NULL; |
| 662 |
enum netr_SchannelType sec_chan_type = 0; |
| 663 |
struct netlogon_creds_CredentialState *creds = NULL; |
| 664 |
const char *account_name = NULL; |
| 665 |
|
| 666 |
machine_name = cli_credentials_get_workstation(credentials); |
| 667 |
mach_password = cli_credentials_get_nt_hash(credentials, tctx); |
| 668 |
account_name = cli_credentials_get_username(credentials); |
| 669 |
sec_chan_type = cli_credentials_get_secure_channel_type(credentials); |
| 670 |
|
| 671 |
torture_comment(tctx, "Testing ServerReqChallenge\n"); |
| 672 |
|
| 673 |
r.in.server_name = NULL; |
| 674 |
r.in.computer_name = machine_name; |
| 675 |
r.in.credentials = &credentials1; |
| 676 |
r.out.return_credentials = &credentials2; |
| 677 |
|
| 678 |
/* |
| 679 |
* Set the first 5 bytes of the client challenge to the same value, |
| 680 |
* this should fail CVE-2020-1472(ZeroLogon) |
| 681 |
* BUG: https://bugzilla.samba.org/show_bug.cgi?id=14497 |
| 682 |
*/ |
| 683 |
credentials1.data[0] = 'A'; |
| 684 |
credentials1.data[1] = 'A'; |
| 685 |
credentials1.data[2] = 'A'; |
| 686 |
credentials1.data[3] = 'A'; |
| 687 |
credentials1.data[4] = 'A'; |
| 688 |
credentials1.data[5] = 'B'; |
| 689 |
credentials1.data[6] = 'C'; |
| 690 |
credentials1.data[7] = 'D'; |
| 691 |
|
| 692 |
torture_assert_ntstatus_ok( |
| 693 |
tctx, |
| 694 |
dcerpc_netr_ServerReqChallenge_r(b, tctx, &r), |
| 695 |
"ServerReqChallenge failed"); |
| 696 |
torture_assert_ntstatus_ok( |
| 697 |
tctx, |
| 698 |
r.out.result, |
| 699 |
"ServerReqChallenge failed"); |
| 700 |
a.in.server_name = NULL; |
| 701 |
a.in.account_name = account_name; |
| 702 |
a.in.secure_channel_type = sec_chan_type; |
| 703 |
a.in.computer_name = machine_name; |
| 704 |
a.in.negotiate_flags = &in_negotiate_flags; |
| 705 |
a.out.negotiate_flags = &out_negotiate_flags; |
| 706 |
a.in.credentials = &credentials3; |
| 707 |
a.out.return_credentials = &credentials3; |
| 708 |
|
| 709 |
creds = netlogon_creds_client_init(tctx, a.in.account_name, |
| 710 |
a.in.computer_name, |
| 711 |
a.in.secure_channel_type, |
| 712 |
&credentials1, &credentials2, |
| 713 |
mach_password, &credentials3, |
| 714 |
in_negotiate_flags, |
| 715 |
in_negotiate_flags); |
| 716 |
|
| 717 |
torture_assert(tctx, creds != NULL, "memory allocation"); |
| 718 |
|
| 719 |
torture_comment(tctx, "Testing ServerAuthenticate2\n"); |
| 720 |
|
| 721 |
torture_assert_ntstatus_ok( |
| 722 |
tctx, |
| 723 |
dcerpc_netr_ServerAuthenticate2_r(b, tctx, &a), |
| 724 |
"ServerAuthenticate2 failed"); |
| 725 |
torture_assert_ntstatus_equal( |
| 726 |
tctx, |
| 727 |
a.out.result, |
| 728 |
NT_STATUS_ACCESS_DENIED, |
| 729 |
"ServerAuthenticate2 unexpected"); |
| 730 |
|
| 731 |
return true; |
| 732 |
} |
| 733 |
|
| 734 |
static bool test_ServerReqChallenge_4_repeats( |
| 735 |
struct torture_context *tctx, |
| 736 |
struct dcerpc_pipe *p, |
| 737 |
struct cli_credentials *credentials) |
| 738 |
{ |
| 739 |
struct netr_ServerReqChallenge r; |
| 740 |
struct netr_Credential credentials1, credentials2, credentials3; |
| 741 |
const char *machine_name; |
| 742 |
struct dcerpc_binding_handle *b = p->binding_handle; |
| 743 |
struct netr_ServerAuthenticate2 a; |
| 744 |
uint32_t in_negotiate_flags = NETLOGON_NEG_AUTH2_ADS_FLAGS | NETLOGON_NEG_SUPPORTS_AES; |
| 745 |
uint32_t out_negotiate_flags = 0; |
| 746 |
const struct samr_Password *mach_password = NULL; |
| 747 |
enum netr_SchannelType sec_chan_type = 0; |
| 748 |
struct netlogon_creds_CredentialState *creds = NULL; |
| 749 |
const char *account_name = NULL; |
| 750 |
|
| 751 |
machine_name = cli_credentials_get_workstation(credentials); |
| 752 |
mach_password = cli_credentials_get_nt_hash(credentials, tctx); |
| 753 |
account_name = cli_credentials_get_username(credentials); |
| 754 |
sec_chan_type = cli_credentials_get_secure_channel_type(credentials); |
| 755 |
|
| 756 |
torture_comment(tctx, "Testing ServerReqChallenge\n"); |
| 757 |
|
| 758 |
r.in.server_name = NULL; |
| 759 |
r.in.computer_name = machine_name; |
| 760 |
r.in.credentials = &credentials1; |
| 761 |
r.out.return_credentials = &credentials2; |
| 762 |
|
| 763 |
/* |
| 764 |
* Set the first 4 bytes of the client challenge to the same |
| 765 |
* value, this should pass as 5 bytes identical are needed to |
| 766 |
* fail for CVE-2020-1472(ZeroLogon) |
| 767 |
* |
| 768 |
* BUG: https://bugzilla.samba.org/show_bug.cgi?id=14497 |
| 769 |
*/ |
| 770 |
credentials1.data[0] = 'A'; |
| 771 |
credentials1.data[1] = 'A'; |
| 772 |
credentials1.data[2] = 'A'; |
| 773 |
credentials1.data[3] = 'A'; |
| 774 |
credentials1.data[4] = 'B'; |
| 775 |
credentials1.data[5] = 'C'; |
| 776 |
credentials1.data[6] = 'D'; |
| 777 |
credentials1.data[7] = 'E'; |
| 778 |
|
| 779 |
torture_assert_ntstatus_ok( |
| 780 |
tctx, |
| 781 |
dcerpc_netr_ServerReqChallenge_r(b, tctx, &r), |
| 782 |
"ServerReqChallenge failed"); |
| 783 |
torture_assert_ntstatus_ok( |
| 784 |
tctx, |
| 785 |
r.out.result, |
| 786 |
"ServerReqChallenge failed"); |
| 787 |
a.in.server_name = NULL; |
| 788 |
a.in.account_name = account_name; |
| 789 |
a.in.secure_channel_type = sec_chan_type; |
| 790 |
a.in.computer_name = machine_name; |
| 791 |
a.in.negotiate_flags = &in_negotiate_flags; |
| 792 |
a.out.negotiate_flags = &out_negotiate_flags; |
| 793 |
a.in.credentials = &credentials3; |
| 794 |
a.out.return_credentials = &credentials3; |
| 795 |
|
| 796 |
creds = netlogon_creds_client_init(tctx, a.in.account_name, |
| 797 |
a.in.computer_name, |
| 798 |
a.in.secure_channel_type, |
| 799 |
&credentials1, &credentials2, |
| 800 |
mach_password, &credentials3, |
| 801 |
in_negotiate_flags, |
| 802 |
in_negotiate_flags); |
| 803 |
|
| 804 |
torture_assert(tctx, creds != NULL, "memory allocation"); |
| 805 |
|
| 806 |
torture_comment(tctx, "Testing ServerAuthenticate2\n"); |
| 807 |
|
| 808 |
torture_assert_ntstatus_ok( |
| 809 |
tctx, |
| 810 |
dcerpc_netr_ServerAuthenticate2_r(b, tctx, &a), |
| 811 |
"ServerAuthenticate2 failed"); |
| 812 |
torture_assert_ntstatus_equal( |
| 813 |
tctx, |
| 814 |
a.out.result, |
| 815 |
NT_STATUS_OK, |
| 816 |
"ServerAuthenticate2 unexpected"); |
| 817 |
|
| 818 |
return true; |
| 819 |
} |
| 820 |
|
| 821 |
/* |
| 822 |
* Establish a NetLogon session, using a session key that encrypts the |
| 823 |
* target character to zero |
| 824 |
*/ |
| 825 |
static bool test_ServerAuthenticate2_encrypts_to_zero( |
| 826 |
struct torture_context *tctx, |
| 827 |
struct dcerpc_pipe *p, |
| 828 |
struct cli_credentials *machine_credentials, |
| 829 |
const char target, |
| 830 |
struct netlogon_creds_CredentialState **creds_out) |
| 831 |
{ |
| 832 |
const char *computer_name = |
| 833 |
cli_credentials_get_workstation(machine_credentials); |
| 834 |
struct netr_ServerReqChallenge r; |
| 835 |
struct netr_ServerAuthenticate2 a; |
| 836 |
struct netr_Credential credentials1, credentials2, credentials3; |
| 837 |
struct netlogon_creds_CredentialState *creds = NULL; |
| 838 |
const struct samr_Password *mach_password; |
| 839 |
struct dcerpc_binding_handle *b = p->binding_handle; |
| 840 |
const char *account_name = cli_credentials_get_username( |
| 841 |
machine_credentials); |
| 842 |
uint32_t flags = |
| 843 |
NETLOGON_NEG_AUTH2_ADS_FLAGS | |
| 844 |
NETLOGON_NEG_SUPPORTS_AES; |
| 845 |
enum netr_SchannelType sec_chan_type = |
| 846 |
cli_credentials_get_secure_channel_type(machine_credentials); |
| 847 |
/* |
| 848 |
* Limit the number of attempts to generate a suitable session key. |
| 849 |
*/ |
| 850 |
const unsigned MAX_ITER = 4096; |
| 851 |
unsigned i = 0; |
| 852 |
|
| 853 |
mach_password = cli_credentials_get_nt_hash(machine_credentials, tctx); |
| 854 |
|
| 855 |
r.in.server_name = NULL; |
| 856 |
r.in.computer_name = computer_name; |
| 857 |
r.in.credentials = &credentials1; |
| 858 |
r.out.return_credentials = &credentials2; |
| 859 |
|
| 860 |
netlogon_creds_random_challenge(&credentials1); |
| 861 |
credentials1.data[0] = target; |
| 862 |
i = 0; |
| 863 |
torture_comment(tctx, "Generating candidate session keys\n"); |
| 864 |
do { |
| 865 |
TALLOC_FREE(creds); |
| 866 |
i++; |
| 867 |
|
| 868 |
torture_assert_ntstatus_ok( |
| 869 |
tctx, |
| 870 |
dcerpc_netr_ServerReqChallenge_r(b, tctx, &r), |
| 871 |
"ServerReqChallenge failed"); |
| 872 |
torture_assert_ntstatus_ok( |
| 873 |
tctx, |
| 874 |
r.out.result, |
| 875 |
"ServerReqChallenge failed"); |
| 876 |
|
| 877 |
a.in.server_name = NULL; |
| 878 |
a.in.account_name = account_name; |
| 879 |
a.in.secure_channel_type = sec_chan_type; |
| 880 |
a.in.computer_name = computer_name; |
| 881 |
a.in.negotiate_flags = &flags; |
| 882 |
a.out.negotiate_flags = &flags; |
| 883 |
a.in.credentials = &credentials3; |
| 884 |
a.out.return_credentials = &credentials3; |
| 885 |
|
| 886 |
creds = netlogon_creds_client_init( |
| 887 |
tctx, |
| 888 |
a.in.account_name, |
| 889 |
a.in.computer_name, |
| 890 |
a.in.secure_channel_type, |
| 891 |
&credentials1, |
| 892 |
&credentials2, |
| 893 |
mach_password, |
| 894 |
&credentials3, |
| 895 |
flags, |
| 896 |
flags); |
| 897 |
|
| 898 |
torture_assert(tctx, creds != NULL, "memory allocation"); |
| 899 |
} while (credentials3.data[0] != 0 && i < MAX_ITER); |
| 900 |
|
| 901 |
if (i >= MAX_ITER) { |
| 902 |
torture_comment( |
| 903 |
tctx, |
| 904 |
"Unable to obtain a suitable session key, " |
| 905 |
"after [%u] attempts\n", |
| 906 |
i); |
| 907 |
torture_fail(tctx, "Unable to obtain suitable session key"); |
| 908 |
} |
| 909 |
|
| 910 |
torture_assert_ntstatus_ok( |
| 911 |
tctx, |
| 912 |
dcerpc_netr_ServerAuthenticate2_r(b, tctx, &a), |
| 913 |
"ServerAuthenticate2 failed"); |
| 914 |
torture_assert_ntstatus_equal( |
| 915 |
tctx, |
| 916 |
a.out.result, |
| 917 |
NT_STATUS_OK, |
| 918 |
"ServerAuthenticate2 unexpected result code"); |
| 919 |
|
| 920 |
*creds_out = creds; |
| 921 |
return true; |
| 922 |
} |
| 923 |
|
| 924 |
/* |
| 925 |
try a change password for our machine account |
| 926 |
*/ |
| 927 |
static bool test_SetPassword(struct torture_context *tctx, |
| 928 |
struct dcerpc_pipe *p, |
| 929 |
struct cli_credentials *machine_credentials) |
| 930 |
{ |
| 931 |
struct netr_ServerPasswordSet r; |
| 932 |
const char *password; |
| 933 |
struct netlogon_creds_CredentialState *creds; |
| 934 |
struct netr_Authenticator credential, return_authenticator; |
| 935 |
struct samr_Password new_password; |
| 936 |
struct dcerpc_binding_handle *b = p->binding_handle; |
| 937 |
enum dcerpc_AuthType auth_type = DCERPC_AUTH_TYPE_NONE; |
| 938 |
enum dcerpc_AuthLevel auth_level = DCERPC_AUTH_LEVEL_NONE; |
| 939 |
NTSTATUS status; |
| 940 |
|
| 941 |
if (!test_SetupCredentials(p, tctx, machine_credentials, &creds)) { |
| 942 |
return false; |
| 943 |
} |
| 944 |
|
| 945 |
r.in.server_name = talloc_asprintf(tctx, "\\\\%s", dcerpc_server_name(p)); |
| 946 |
r.in.account_name = talloc_asprintf(tctx, "%s$", TEST_MACHINE_NAME); |
| 947 |
r.in.secure_channel_type = cli_credentials_get_secure_channel_type(machine_credentials); |
| 948 |
r.in.computer_name = TEST_MACHINE_NAME; |
| 949 |
r.in.credential = &credential; |
| 950 |
r.in.new_password = &new_password; |
| 951 |
r.out.return_authenticator = &return_authenticator; |
| 952 |
|
| 953 |
password = generate_random_password(tctx, 8, 255); |
| 954 |
E_md4hash(password, new_password.hash); |
| 955 |
|
| 956 |
dcerpc_binding_handle_auth_info(b, &auth_type, &auth_level); |
| 957 |
status = netlogon_creds_encrypt_samr_Password(creds, |
| 958 |
&new_password, |
| 959 |
auth_type, |
| 960 |
auth_level); |
| 961 |
torture_assert_ntstatus_ok(tctx, status, "encrypt_samr_Password"); |
| 962 |
|
| 963 |
torture_comment(tctx, "Testing ServerPasswordSet on machine account\n"); |
| 964 |
torture_comment(tctx, "Changing machine account password to '%s'\n", |
| 965 |
password); |
| 966 |
|
| 967 |
netlogon_creds_client_authenticator(creds, &credential); |
| 968 |
|
| 969 |
torture_assert_ntstatus_ok(tctx, dcerpc_netr_ServerPasswordSet_r(b, tctx, &r), |
| 970 |
"ServerPasswordSet failed"); |
| 971 |
torture_assert_ntstatus_ok(tctx, r.out.result, "ServerPasswordSet failed"); |
| 972 |
|
| 973 |
if (!netlogon_creds_client_check(creds, &r.out.return_authenticator->cred)) { |
| 974 |
torture_comment(tctx, "Credential chaining failed\n"); |
| 975 |
} |
| 976 |
|
| 977 |
/* by changing the machine password twice we test the |
| 978 |
credentials chaining fully, and we verify that the server |
| 979 |
allows the password to be set to the same value twice in a |
| 980 |
row (match win2k3) */ |
| 981 |
torture_comment(tctx, |
| 982 |
"Testing a second ServerPasswordSet on machine account\n"); |
| 983 |
torture_comment(tctx, |
| 984 |
"Changing machine account password to '%s' (same as previous run)\n", password); |
| 985 |
|
| 986 |
netlogon_creds_client_authenticator(creds, &credential); |
| 987 |
|
| 988 |
torture_assert_ntstatus_ok(tctx, dcerpc_netr_ServerPasswordSet_r(b, tctx, &r), |
| 989 |
"ServerPasswordSet (2) failed"); |
| 990 |
torture_assert_ntstatus_ok(tctx, r.out.result, "ServerPasswordSet (2) failed"); |
| 991 |
|
| 992 |
if (!netlogon_creds_client_check(creds, &r.out.return_authenticator->cred)) { |
| 993 |
torture_comment(tctx, "Credential chaining failed\n"); |
| 994 |
} |
| 995 |
|
| 996 |
cli_credentials_set_password(machine_credentials, password, CRED_SPECIFIED); |
| 997 |
|
| 998 |
torture_assert(tctx, |
| 999 |
test_SetupCredentials(p, tctx, machine_credentials, &creds), |
| 1000 |
"ServerPasswordSet failed to actually change the password"); |
| 1001 |
|
| 1002 |
return true; |
| 1003 |
} |
| 1004 |
|
| 1005 |
/* |
| 1006 |
try a change password for our machine account |
| 1007 |
*/ |
| 1008 |
static bool test_SetPassword_flags(struct torture_context *tctx, |
| 1009 |
struct dcerpc_pipe *p1, |
| 1010 |
struct cli_credentials *machine_credentials, |
| 1011 |
uint32_t negotiate_flags) |
| 1012 |
{ |
| 1013 |
struct netr_ServerPasswordSet r; |
| 1014 |
const char *password; |
| 1015 |
struct netlogon_creds_CredentialState *creds; |
| 1016 |
struct netr_Authenticator credential, return_authenticator; |
| 1017 |
struct samr_Password new_password; |
| 1018 |
struct dcerpc_pipe *p = NULL; |
| 1019 |
struct dcerpc_binding_handle *b = NULL; |
| 1020 |
enum dcerpc_AuthType auth_type; |
| 1021 |
enum dcerpc_AuthLevel auth_level; |
| 1022 |
NTSTATUS status; |
| 1023 |
|
| 1024 |
if (!test_SetupCredentials2(p1, tctx, negotiate_flags, |
| 1025 |
machine_credentials, |
| 1026 |
cli_credentials_get_secure_channel_type(machine_credentials), |
| 1027 |
&creds)) { |
| 1028 |
return false; |
| 1029 |
} |
| 1030 |
if (!test_SetupCredentialsPipe(p1, tctx, machine_credentials, creds, |
| 1031 |
DCERPC_SIGN | DCERPC_SEAL, &p)) { |
| 1032 |
return false; |
| 1033 |
} |
| 1034 |
b = p->binding_handle; |
| 1035 |
|
| 1036 |
r.in.server_name = talloc_asprintf(tctx, "\\\\%s", dcerpc_server_name(p)); |
| 1037 |
r.in.account_name = talloc_asprintf(tctx, "%s$", TEST_MACHINE_NAME); |
| 1038 |
r.in.secure_channel_type = cli_credentials_get_secure_channel_type(machine_credentials); |
| 1039 |
r.in.computer_name = TEST_MACHINE_NAME; |
| 1040 |
r.in.credential = &credential; |
| 1041 |
r.in.new_password = &new_password; |
| 1042 |
r.out.return_authenticator = &return_authenticator; |
| 1043 |
|
| 1044 |
password = generate_random_password(tctx, 8, 255); |
| 1045 |
E_md4hash(password, new_password.hash); |
| 1046 |
|
| 1047 |
dcerpc_binding_handle_auth_info(b, &auth_type, &auth_level); |
| 1048 |
status = netlogon_creds_encrypt_samr_Password(creds, |
| 1049 |
&new_password, |
| 1050 |
auth_type, |
| 1051 |
auth_level); |
| 1052 |
torture_assert_ntstatus_ok(tctx, status, "encrypt_samr_Password"); |
| 1053 |
|
| 1054 |
torture_comment(tctx, "Testing ServerPasswordSet on machine account\n"); |
| 1055 |
torture_comment(tctx, "Changing machine account password to '%s'\n", |
| 1056 |
password); |
| 1057 |
|
| 1058 |
netlogon_creds_client_authenticator(creds, &credential); |
| 1059 |
|
| 1060 |
torture_assert_ntstatus_ok(tctx, dcerpc_netr_ServerPasswordSet_r(b, tctx, &r), |
| 1061 |
"ServerPasswordSet failed"); |
| 1062 |
torture_assert_ntstatus_ok(tctx, r.out.result, "ServerPasswordSet failed"); |
| 1063 |
|
| 1064 |
if (!netlogon_creds_client_check(creds, &r.out.return_authenticator->cred)) { |
| 1065 |
torture_comment(tctx, "Credential chaining failed\n"); |
| 1066 |
} |
| 1067 |
|
| 1068 |
/* by changing the machine password twice we test the |
| 1069 |
credentials chaining fully, and we verify that the server |
| 1070 |
allows the password to be set to the same value twice in a |
| 1071 |
row (match win2k3) */ |
| 1072 |
torture_comment(tctx, |
| 1073 |
"Testing a second ServerPasswordSet on machine account\n"); |
| 1074 |
torture_comment(tctx, |
| 1075 |
"Changing machine account password to '%s' (same as previous run)\n", password); |
| 1076 |
|
| 1077 |
netlogon_creds_client_authenticator(creds, &credential); |
| 1078 |
|
| 1079 |
torture_assert_ntstatus_ok(tctx, dcerpc_netr_ServerPasswordSet_r(b, tctx, &r), |
| 1080 |
"ServerPasswordSet (2) failed"); |
| 1081 |
torture_assert_ntstatus_ok(tctx, r.out.result, "ServerPasswordSet (2) failed"); |
| 1082 |
|
| 1083 |
if (!netlogon_creds_client_check(creds, &r.out.return_authenticator->cred)) { |
| 1084 |
torture_comment(tctx, "Credential chaining failed\n"); |
| 1085 |
} |
| 1086 |
|
| 1087 |
cli_credentials_set_password(machine_credentials, password, CRED_SPECIFIED); |
| 1088 |
|
| 1089 |
torture_assert(tctx, |
| 1090 |
test_SetupCredentials(p, tctx, machine_credentials, &creds), |
| 1091 |
"ServerPasswordSet failed to actually change the password"); |
| 1092 |
|
| 1093 |
return true; |
| 1094 |
} |
| 1095 |
|
| 1096 |
|
| 1097 |
/* |
| 1098 |
generate a random password for password change tests |
| 1099 |
*/ |
| 1100 |
static DATA_BLOB netlogon_very_rand_pass(TALLOC_CTX *mem_ctx, int len) |
| 1101 |
{ |
| 1102 |
int i; |
| 1103 |
DATA_BLOB password = data_blob_talloc(mem_ctx, NULL, len * 2 /* number of unicode chars */); |
| 1104 |
generate_random_buffer(password.data, password.length); |
| 1105 |
|
| 1106 |
for (i=0; i < len; i++) { |
| 1107 |
if (((uint16_t *)password.data)[i] == 0) { |
| 1108 |
((uint16_t *)password.data)[i] = 1; |
| 1109 |
} |
| 1110 |
} |
| 1111 |
|
| 1112 |
return password; |
| 1113 |
} |
| 1114 |
|
| 1115 |
/* |
| 1116 |
try a change password for our machine account |
| 1117 |
*/ |
| 1118 |
static bool test_SetPassword2_with_flags(struct torture_context *tctx, |
| 1119 |
struct dcerpc_pipe *p1, |
| 1120 |
struct cli_credentials *machine_credentials, |
| 1121 |
uint32_t flags) |
| 1122 |
{ |
| 1123 |
struct netr_ServerPasswordSet2 r; |
| 1124 |
const char *password; |
| 1125 |
DATA_BLOB new_random_pass; |
| 1126 |
struct netlogon_creds_CredentialState *creds; |
| 1127 |
struct samr_CryptPassword password_buf; |
| 1128 |
struct samr_Password nt_hash; |
| 1129 |
struct netr_Authenticator credential, return_authenticator; |
| 1130 |
struct netr_CryptPassword new_password; |
| 1131 |
struct dcerpc_pipe *p = NULL; |
| 1132 |
struct dcerpc_binding_handle *b = NULL; |
| 1133 |
enum dcerpc_AuthType auth_type; |
| 1134 |
enum dcerpc_AuthLevel auth_level; |
| 1135 |
NTSTATUS status; |
| 1136 |
|
| 1137 |
if (!test_SetupCredentials2(p1, tctx, flags, machine_credentials, |
| 1138 |
cli_credentials_get_secure_channel_type(machine_credentials), |
| 1139 |
&creds)) { |
| 1140 |
return false; |
| 1141 |
} |
| 1142 |
if (!test_SetupCredentialsPipe(p1, tctx, machine_credentials, creds, |
| 1143 |
DCERPC_SIGN | DCERPC_SEAL, &p)) { |
| 1144 |
return false; |
| 1145 |
} |
| 1146 |
b = p->binding_handle; |
| 1147 |
|
| 1148 |
r.in.server_name = talloc_asprintf(tctx, "\\\\%s", dcerpc_server_name(p)); |
| 1149 |
r.in.account_name = talloc_asprintf(tctx, "%s$", TEST_MACHINE_NAME); |
| 1150 |
r.in.secure_channel_type = cli_credentials_get_secure_channel_type(machine_credentials); |
| 1151 |
r.in.computer_name = TEST_MACHINE_NAME; |
| 1152 |
r.in.credential = &credential; |
| 1153 |
r.in.new_password = &new_password; |
| 1154 |
r.out.return_authenticator = &return_authenticator; |
| 1155 |
|
| 1156 |
password = generate_random_password(tctx, 8, 255); |
| 1157 |
encode_pw_buffer(password_buf.data, password, STR_UNICODE); |
| 1158 |
dcerpc_binding_handle_auth_info(b, &auth_type, &auth_level); |
| 1159 |
status = netlogon_creds_encrypt_samr_CryptPassword(creds, |
| 1160 |
&password_buf, |
| 1161 |
auth_type, |
| 1162 |
auth_level); |
| 1163 |
torture_assert_ntstatus_ok(tctx, status, "encrypt_samr_CryptPassword"); |
| 1164 |
|
| 1165 |
memcpy(new_password.data, password_buf.data, 512); |
| 1166 |
new_password.length = IVAL(password_buf.data, 512); |
| 1167 |
|
| 1168 |
torture_comment(tctx, "Testing ServerPasswordSet2 on machine account\n"); |
| 1169 |
torture_comment(tctx, "Changing machine account password to '%s'\n", password); |
| 1170 |
|
| 1171 |
netlogon_creds_client_authenticator(creds, &credential); |
| 1172 |
|
| 1173 |
torture_assert_ntstatus_ok(tctx, dcerpc_netr_ServerPasswordSet2_r(b, tctx, &r), |
| 1174 |
"ServerPasswordSet2 failed"); |
| 1175 |
torture_assert_ntstatus_ok(tctx, r.out.result, "ServerPasswordSet2 failed"); |
| 1176 |
|
| 1177 |
if (!netlogon_creds_client_check(creds, &r.out.return_authenticator->cred)) { |
| 1178 |
torture_comment(tctx, "Credential chaining failed\n"); |
| 1179 |
} |
| 1180 |
|
| 1181 |
cli_credentials_set_password(machine_credentials, password, CRED_SPECIFIED); |
| 1182 |
|
| 1183 |
/* |
| 1184 |
* As a consequence of CVE-2020-1472(ZeroLogon) |
| 1185 |
* Samba explicitly disallows the setting of an empty machine account |
| 1186 |
* password. |
| 1187 |
* |
| 1188 |
* Note that this may fail against Windows, and leave a machine account |
| 1189 |
* with an empty password. |
| 1190 |
*/ |
| 1191 |
password = ""; |
| 1192 |
encode_pw_buffer(password_buf.data, password, STR_UNICODE); |
| 1193 |
dcerpc_binding_handle_auth_info(b, &auth_type, &auth_level); |
| 1194 |
status = netlogon_creds_encrypt_samr_CryptPassword(creds, |
| 1195 |
&password_buf, |
| 1196 |
auth_type, |
| 1197 |
auth_level); |
| 1198 |
torture_assert_ntstatus_ok(tctx, status, "encrypt_samr_CryptPassword"); |
| 1199 |
memcpy(new_password.data, password_buf.data, 512); |
| 1200 |
new_password.length = IVAL(password_buf.data, 512); |
| 1201 |
|
| 1202 |
torture_comment(tctx, |
| 1203 |
"Testing ServerPasswordSet2 on machine account\n"); |
| 1204 |
torture_comment(tctx, |
| 1205 |
"Changing machine account password to '%s'\n", password); |
| 1206 |
|
| 1207 |
netlogon_creds_client_authenticator(creds, &credential); |
| 1208 |
|
| 1209 |
torture_assert_ntstatus_ok( |
| 1210 |
tctx, dcerpc_netr_ServerPasswordSet2_r(b, tctx, &r), |
| 1211 |
"ServerPasswordSet2 failed"); |
| 1212 |
torture_assert_ntstatus_equal( |
| 1213 |
tctx, |
| 1214 |
r.out.result, |
| 1215 |
NT_STATUS_WRONG_PASSWORD, |
| 1216 |
"ServerPasswordSet2 did not return NT_STATUS_WRONG_PASSWORD"); |
| 1217 |
|
| 1218 |
/* now try a random password */ |
| 1219 |
password = generate_random_password(tctx, 8, 255); |
| 1220 |
encode_pw_buffer(password_buf.data, password, STR_UNICODE); |
| 1221 |
dcerpc_binding_handle_auth_info(b, &auth_type, &auth_level); |
| 1222 |
status = netlogon_creds_encrypt_samr_CryptPassword(creds, |
| 1223 |
&password_buf, |
| 1224 |
auth_type, |
| 1225 |
auth_level); |
| 1226 |
torture_assert_ntstatus_ok(tctx, status, "encrypt_samr_CryptPassword"); |
| 1227 |
memcpy(new_password.data, password_buf.data, 512); |
| 1228 |
new_password.length = IVAL(password_buf.data, 512); |
| 1229 |
|
| 1230 |
torture_comment(tctx, "Testing second ServerPasswordSet2 on machine account\n"); |
| 1231 |
torture_comment(tctx, "Changing machine account password to '%s'\n", password); |
| 1232 |
|
| 1233 |
netlogon_creds_client_authenticator(creds, &credential); |
| 1234 |
|
| 1235 |
torture_assert_ntstatus_ok(tctx, dcerpc_netr_ServerPasswordSet2_r(b, tctx, &r), |
| 1236 |
"ServerPasswordSet2 (2) failed"); |
| 1237 |
torture_assert_ntstatus_ok(tctx, r.out.result, "ServerPasswordSet2 (2) failed"); |
| 1238 |
|
| 1239 |
if (!netlogon_creds_client_check(creds, &r.out.return_authenticator->cred)) { |
| 1240 |
torture_comment(tctx, "Credential chaining failed\n"); |
| 1241 |
} |
| 1242 |
|
| 1243 |
/* by changing the machine password twice we test the |
| 1244 |
credentials chaining fully, and we verify that the server |
| 1245 |
allows the password to be set to the same value twice in a |
| 1246 |
row (match win2k3) */ |
| 1247 |
torture_comment(tctx, |
| 1248 |
"Testing a second ServerPasswordSet2 on machine account\n"); |
| 1249 |
torture_comment(tctx, |
| 1250 |
"Changing machine account password to '%s' (same as previous run)\n", password); |
| 1251 |
|
| 1252 |
netlogon_creds_client_authenticator(creds, &credential); |
| 1253 |
|
| 1254 |
torture_assert_ntstatus_ok(tctx, dcerpc_netr_ServerPasswordSet2_r(b, tctx, &r), |
| 1255 |
"ServerPasswordSet (3) failed"); |
| 1256 |
torture_assert_ntstatus_ok(tctx, r.out.result, "ServerPasswordSet (3) failed"); |
| 1257 |
|
| 1258 |
if (!netlogon_creds_client_check(creds, &r.out.return_authenticator->cred)) { |
| 1259 |
torture_comment(tctx, "Credential chaining failed\n"); |
| 1260 |
} |
| 1261 |
|
| 1262 |
cli_credentials_set_password(machine_credentials, password, CRED_SPECIFIED); |
| 1263 |
|
| 1264 |
torture_assert (tctx, |
| 1265 |
test_SetupCredentials(p, tctx, machine_credentials, &creds), |
| 1266 |
"ServerPasswordSet failed to actually change the password"); |
| 1267 |
|
| 1268 |
new_random_pass = netlogon_very_rand_pass(tctx, 128); |
| 1269 |
|
| 1270 |
/* now try a random stream of bytes for a password */ |
| 1271 |
set_pw_in_buffer(password_buf.data, &new_random_pass); |
| 1272 |
|
| 1273 |
dcerpc_binding_handle_auth_info(b, &auth_type, &auth_level); |
| 1274 |
status = netlogon_creds_encrypt_samr_CryptPassword(creds, |
| 1275 |
&password_buf, |
| 1276 |
auth_type, |
| 1277 |
auth_level); |
| 1278 |
torture_assert_ntstatus_ok(tctx, status, "encrypt_samr_CryptPassword"); |
| 1279 |
|
| 1280 |
memcpy(new_password.data, password_buf.data, 512); |
| 1281 |
new_password.length = IVAL(password_buf.data, 512); |
| 1282 |
|
| 1283 |
torture_comment(tctx, |
| 1284 |
"Testing a third ServerPasswordSet2 on machine account, with a completely random password\n"); |
| 1285 |
|
| 1286 |
netlogon_creds_client_authenticator(creds, &credential); |
| 1287 |
|
| 1288 |
torture_assert_ntstatus_ok(tctx, dcerpc_netr_ServerPasswordSet2_r(b, tctx, &r), |
| 1289 |
"ServerPasswordSet (3) failed"); |
| 1290 |
torture_assert_ntstatus_ok(tctx, r.out.result, "ServerPasswordSet (3) failed"); |
| 1291 |
|
| 1292 |
if (!netlogon_creds_client_check(creds, &r.out.return_authenticator->cred)) { |
| 1293 |
torture_comment(tctx, "Credential chaining failed\n"); |
| 1294 |
} |
| 1295 |
|
| 1296 |
mdfour(nt_hash.hash, new_random_pass.data, new_random_pass.length); |
| 1297 |
|
| 1298 |
cli_credentials_set_password(machine_credentials, NULL, CRED_UNINITIALISED); |
| 1299 |
cli_credentials_set_nt_hash(machine_credentials, &nt_hash, CRED_SPECIFIED); |
| 1300 |
|
| 1301 |
torture_assert (tctx, |
| 1302 |
test_SetupCredentials(p, tctx, machine_credentials, &creds), |
| 1303 |
"ServerPasswordSet failed to actually change the password"); |
| 1304 |
|
| 1305 |
return true; |
| 1306 |
} |
| 1307 |
|
| 1308 |
/* |
| 1309 |
try to change the password of our machine account using a buffer of all zeros, |
| 1310 |
and a session key that encrypts that to all zeros. |
| 1311 |
|
| 1312 |
Note: The test does use sign and seal, it's purpose is to exercise |
| 1313 |
the detection code in dcesrv_netr_ServerPasswordSet2 |
| 1314 |
*/ |
| 1315 |
static bool test_SetPassword2_encrypted_to_all_zeros( |
| 1316 |
struct torture_context *tctx, |
| 1317 |
struct dcerpc_pipe *p1, |
| 1318 |
struct cli_credentials *machine_credentials) |
| 1319 |
{ |
| 1320 |
struct netr_ServerPasswordSet2 r; |
| 1321 |
struct netlogon_creds_CredentialState *creds; |
| 1322 |
struct samr_CryptPassword password_buf; |
| 1323 |
struct netr_Authenticator credential, return_authenticator; |
| 1324 |
struct netr_CryptPassword new_password; |
| 1325 |
struct dcerpc_pipe *p = NULL; |
| 1326 |
struct dcerpc_binding_handle *b = NULL; |
| 1327 |
enum dcerpc_AuthType auth_type; |
| 1328 |
enum dcerpc_AuthLevel auth_level; |
| 1329 |
NTSTATUS status; |
| 1330 |
|
| 1331 |
if (!test_ServerAuthenticate2_encrypts_to_zero( |
| 1332 |
tctx, |
| 1333 |
p1, |
| 1334 |
machine_credentials, |
| 1335 |
'\0', |
| 1336 |
&creds)) { |
| 1337 |
|
| 1338 |
return false; |
| 1339 |
} |
| 1340 |
|
| 1341 |
if (!test_SetupCredentialsPipe( |
| 1342 |
p1, |
| 1343 |
tctx, |
| 1344 |
machine_credentials, |
| 1345 |
creds, |
| 1346 |
DCERPC_SIGN | DCERPC_SEAL, |
| 1347 |
&p)) |
| 1348 |
{ |
| 1349 |
return false; |
| 1350 |
} |
| 1351 |
b = p->binding_handle; |
| 1352 |
|
| 1353 |
r.in.server_name = talloc_asprintf( |
| 1354 |
tctx, |
| 1355 |
"\\\\%s", dcerpc_server_name(p)); |
| 1356 |
r.in.account_name = talloc_asprintf(tctx, "%s$", TEST_MACHINE_NAME); |
| 1357 |
r.in.secure_channel_type = |
| 1358 |
cli_credentials_get_secure_channel_type(machine_credentials); |
| 1359 |
r.in.computer_name = TEST_MACHINE_NAME; |
| 1360 |
r.in.credential = &credential; |
| 1361 |
r.in.new_password = &new_password; |
| 1362 |
r.out.return_authenticator = &return_authenticator; |
| 1363 |
|
| 1364 |
ZERO_STRUCT(password_buf); |
| 1365 |
|
| 1366 |
if (!(creds->negotiate_flags & NETLOGON_NEG_SUPPORTS_AES)) { |
| 1367 |
torture_fail(tctx, "NETLOGON_NEG_SUPPORTS_AES not set"); |
| 1368 |
} |
| 1369 |
dcerpc_binding_handle_auth_info(b, &auth_type, &auth_level); |
| 1370 |
status = netlogon_creds_encrypt_samr_CryptPassword(creds, |
| 1371 |
&password_buf, |
| 1372 |
auth_type, |
| 1373 |
auth_level); |
| 1374 |
torture_assert_ntstatus_ok(tctx, status, "encrypt_samr_CryptPassword"); |
| 1375 |
if(!all_zero(password_buf.data, 516)) { |
| 1376 |
torture_fail(tctx, "Password did not encrypt to all zeros\n"); |
| 1377 |
} |
| 1378 |
|
| 1379 |
memcpy(new_password.data, password_buf.data, 512); |
| 1380 |
new_password.length = IVAL(password_buf.data, 512); |
| 1381 |
torture_assert_int_equal( |
| 1382 |
tctx, |
| 1383 |
new_password.length, |
| 1384 |
0, |
| 1385 |
"Length should have encrypted to 0"); |
| 1386 |
|
| 1387 |
netlogon_creds_client_authenticator(creds, &credential); |
| 1388 |
|
| 1389 |
torture_assert_ntstatus_ok( |
| 1390 |
tctx, |
| 1391 |
dcerpc_netr_ServerPasswordSet2_r(b, tctx, &r), |
| 1392 |
"ServerPasswordSet2 zero length check failed"); |
| 1393 |
torture_assert_ntstatus_equal( |
| 1394 |
tctx, r.out.result, NT_STATUS_WRONG_PASSWORD, ""); |
| 1395 |
|
| 1396 |
return true; |
| 1397 |
} |
| 1398 |
|
| 1399 |
/* |
| 1400 |
* Choose a session key that encrypts a password of all zeros to all zeros. |
| 1401 |
* Then try to set the password, using a zeroed buffer, with a non zero |
| 1402 |
* length. |
| 1403 |
* |
| 1404 |
* This exercises the password self encryption check. |
| 1405 |
* |
| 1406 |
* Note: The test does use sign and seal, it's purpose is to exercise |
| 1407 |
* the detection code in dcesrv_netr_ServerPasswordSet2 |
| 1408 |
*/ |
| 1409 |
static bool test_SetPassword2_password_encrypts_to_zero( |
| 1410 |
struct torture_context *tctx, |
| 1411 |
struct dcerpc_pipe *p1, |
| 1412 |
struct cli_credentials *machine_credentials) |
| 1413 |
{ |
| 1414 |
struct netr_ServerPasswordSet2 r; |
| 1415 |
struct netlogon_creds_CredentialState *creds; |
| 1416 |
struct samr_CryptPassword password_buf; |
| 1417 |
struct netr_Authenticator credential, return_authenticator; |
| 1418 |
struct netr_CryptPassword new_password; |
| 1419 |
struct dcerpc_pipe *p = NULL; |
| 1420 |
struct dcerpc_binding_handle *b = NULL; |
| 1421 |
enum dcerpc_AuthType auth_type; |
| 1422 |
enum dcerpc_AuthLevel auth_level; |
| 1423 |
NTSTATUS status; |
| 1424 |
|
| 1425 |
if (!test_ServerAuthenticate2_encrypts_to_zero( |
| 1426 |
tctx, |
| 1427 |
p1, |
| 1428 |
machine_credentials, |
| 1429 |
0x00, |
| 1430 |
&creds)) { |
| 1431 |
|
| 1432 |
return false; |
| 1433 |
} |
| 1434 |
|
| 1435 |
if (!test_SetupCredentialsPipe( |
| 1436 |
p1, |
| 1437 |
tctx, |
| 1438 |
machine_credentials, |
| 1439 |
creds, |
| 1440 |
DCERPC_SIGN | DCERPC_SEAL, |
| 1441 |
&p)) |
| 1442 |
{ |
| 1443 |
return false; |
| 1444 |
} |
| 1445 |
b = p->binding_handle; |
| 1446 |
|
| 1447 |
r.in.server_name = talloc_asprintf( |
| 1448 |
tctx, |
| 1449 |
"\\\\%s", dcerpc_server_name(p)); |
| 1450 |
r.in.account_name = talloc_asprintf(tctx, "%s$", TEST_MACHINE_NAME); |
| 1451 |
r.in.secure_channel_type = |
| 1452 |
cli_credentials_get_secure_channel_type(machine_credentials); |
| 1453 |
r.in.computer_name = TEST_MACHINE_NAME; |
| 1454 |
r.in.credential = &credential; |
| 1455 |
r.in.new_password = &new_password; |
| 1456 |
r.out.return_authenticator = &return_authenticator; |
| 1457 |
|
| 1458 |
ZERO_STRUCT(password_buf); |
| 1459 |
SIVAL(password_buf.data, 512, 512); |
| 1460 |
|
| 1461 |
if (!(creds->negotiate_flags & NETLOGON_NEG_SUPPORTS_AES)) { |
| 1462 |
torture_fail(tctx, "NETLOGON_NEG_SUPPORTS_AES not set"); |
| 1463 |
} |
| 1464 |
dcerpc_binding_handle_auth_info(b, &auth_type, &auth_level); |
| 1465 |
status = netlogon_creds_encrypt_samr_CryptPassword(creds, |
| 1466 |
&password_buf, |
| 1467 |
auth_type, |
| 1468 |
auth_level); |
| 1469 |
torture_assert_ntstatus_ok(tctx, status, "encrypt_samr_CryptPassword"); |
| 1470 |
|
| 1471 |
memcpy(new_password.data, password_buf.data, 512); |
| 1472 |
new_password.length = IVAL(password_buf.data, 512); |
| 1473 |
|
| 1474 |
netlogon_creds_client_authenticator(creds, &credential); |
| 1475 |
|
| 1476 |
torture_assert_ntstatus_ok( |
| 1477 |
tctx, |
| 1478 |
dcerpc_netr_ServerPasswordSet2_r(b, tctx, &r), |
| 1479 |
"ServerPasswordSet2 password encrypts to zero check failed"); |
| 1480 |
torture_assert_ntstatus_equal( |
| 1481 |
tctx, r.out.result, NT_STATUS_WRONG_PASSWORD, ""); |
| 1482 |
|
| 1483 |
return true; |
| 1484 |
} |
| 1485 |
|
| 1486 |
/* |
| 1487 |
* Check that an all zero confounder, that encrypts to all zeros is |
| 1488 |
* rejected. |
| 1489 |
* |
| 1490 |
* Note: The test does use sign and seal, it's purpose is to exercise |
| 1491 |
* the detection code in dcesrv_netr_ServerPasswordSet2 |
| 1492 |
*/ |
| 1493 |
static bool test_SetPassword2_confounder( |
| 1494 |
struct torture_context *tctx, |
| 1495 |
struct dcerpc_pipe *p1, |
| 1496 |
struct cli_credentials *machine_credentials) |
| 1497 |
{ |
| 1498 |
struct netr_ServerPasswordSet2 r; |
| 1499 |
struct netlogon_creds_CredentialState *creds; |
| 1500 |
struct samr_CryptPassword password_buf; |
| 1501 |
struct netr_Authenticator credential, return_authenticator; |
| 1502 |
struct netr_CryptPassword new_password; |
| 1503 |
struct dcerpc_pipe *p = NULL; |
| 1504 |
struct dcerpc_binding_handle *b = NULL; |
| 1505 |
enum dcerpc_AuthType auth_type; |
| 1506 |
enum dcerpc_AuthLevel auth_level; |
| 1507 |
NTSTATUS status; |
| 1508 |
|
| 1509 |
if (!test_ServerAuthenticate2_encrypts_to_zero( |
| 1510 |
tctx, |
| 1511 |
p1, |
| 1512 |
machine_credentials, |
| 1513 |
'\0', |
| 1514 |
&creds)) { |
| 1515 |
|
| 1516 |
return false; |
| 1517 |
} |
| 1518 |
|
| 1519 |
if (!test_SetupCredentialsPipe( |
| 1520 |
p1, |
| 1521 |
tctx, |
| 1522 |
machine_credentials, |
| 1523 |
creds, |
| 1524 |
DCERPC_SIGN | DCERPC_SEAL, |
| 1525 |
&p)) |
| 1526 |
{ |
| 1527 |
return false; |
| 1528 |
} |
| 1529 |
b = p->binding_handle; |
| 1530 |
|
| 1531 |
r.in.server_name = talloc_asprintf( |
| 1532 |
tctx, |
| 1533 |
"\\\\%s", dcerpc_server_name(p)); |
| 1534 |
r.in.account_name = talloc_asprintf(tctx, "%s$", TEST_MACHINE_NAME); |
| 1535 |
r.in.secure_channel_type = |
| 1536 |
cli_credentials_get_secure_channel_type(machine_credentials); |
| 1537 |
r.in.computer_name = TEST_MACHINE_NAME; |
| 1538 |
r.in.credential = &credential; |
| 1539 |
r.in.new_password = &new_password; |
| 1540 |
r.out.return_authenticator = &return_authenticator; |
| 1541 |
|
| 1542 |
ZERO_STRUCT(password_buf); |
| 1543 |
password_buf.data[511] = 'A'; |
| 1544 |
SIVAL(password_buf.data, 512, 2); |
| 1545 |
|
| 1546 |
if (!(creds->negotiate_flags & NETLOGON_NEG_SUPPORTS_AES)) { |
| 1547 |
torture_fail(tctx, "NETLOGON_NEG_SUPPORTS_AES not set"); |
| 1548 |
} |
| 1549 |
dcerpc_binding_handle_auth_info(b, &auth_type, &auth_level); |
| 1550 |
status = netlogon_creds_encrypt_samr_CryptPassword(creds, |
| 1551 |
&password_buf, |
| 1552 |
auth_type, |
| 1553 |
auth_level); |
| 1554 |
torture_assert_ntstatus_ok(tctx, status, "encrypt_samr_CryptPassword"); |
| 1555 |
|
| 1556 |
memcpy(new_password.data, password_buf.data, 512); |
| 1557 |
new_password.length = IVAL(password_buf.data, 512); |
| 1558 |
|
| 1559 |
netlogon_creds_client_authenticator(creds, &credential); |
| 1560 |
|
| 1561 |
torture_assert_ntstatus_ok( |
| 1562 |
tctx, |
| 1563 |
dcerpc_netr_ServerPasswordSet2_r(b, tctx, &r), |
| 1564 |
"ServerPasswordSet2 confounder check failed"); |
| 1565 |
torture_assert_ntstatus_equal( |
| 1566 |
tctx, r.out.result, NT_STATUS_WRONG_PASSWORD, ""); |
| 1567 |
|
| 1568 |
return true; |
| 1569 |
} |
| 1570 |
|
| 1571 |
/* |
| 1572 |
* try a change password for our machine account, using an all zero |
| 1573 |
* request. This should fail on the zero length check. |
| 1574 |
* |
| 1575 |
* Note: This test uses ARC4 encryption to exercise the desired check. |
| 1576 |
*/ |
| 1577 |
static bool test_SetPassword2_all_zeros( |
| 1578 |
struct torture_context *tctx, |
| 1579 |
struct dcerpc_pipe *p1, |
| 1580 |
struct cli_credentials *machine_credentials) |
| 1581 |
{ |
| 1582 |
struct netr_ServerPasswordSet2 r; |
| 1583 |
struct netlogon_creds_CredentialState *creds; |
| 1584 |
struct samr_CryptPassword password_buf; |
| 1585 |
struct netr_Authenticator credential, return_authenticator; |
| 1586 |
struct netr_CryptPassword new_password; |
| 1587 |
struct dcerpc_pipe *p = NULL; |
| 1588 |
struct dcerpc_binding_handle *b = NULL; |
| 1589 |
uint32_t flags = NETLOGON_NEG_AUTH2_ADS_FLAGS; /* no AES desired here */ |
| 1590 |
enum dcerpc_AuthType auth_type; |
| 1591 |
enum dcerpc_AuthLevel auth_level; |
| 1592 |
NTSTATUS status; |
| 1593 |
|
| 1594 |
if (!test_SetupCredentials2( |
| 1595 |
p1, |
| 1596 |
tctx, |
| 1597 |
flags, |
| 1598 |
machine_credentials, |
| 1599 |
cli_credentials_get_secure_channel_type(machine_credentials), |
| 1600 |
&creds)) |
| 1601 |
{ |
| 1602 |
return false; |
| 1603 |
} |
| 1604 |
if (!test_SetupCredentialsPipe( |
| 1605 |
p1, |
| 1606 |
tctx, |
| 1607 |
machine_credentials, |
| 1608 |
creds, |
| 1609 |
DCERPC_SIGN | DCERPC_SEAL, |
| 1610 |
&p)) |
| 1611 |
{ |
| 1612 |
return false; |
| 1613 |
} |
| 1614 |
b = p->binding_handle; |
| 1615 |
|
| 1616 |
r.in.server_name = talloc_asprintf( |
| 1617 |
tctx, |
| 1618 |
"\\\\%s", dcerpc_server_name(p)); |
| 1619 |
r.in.account_name = talloc_asprintf(tctx, "%s$", TEST_MACHINE_NAME); |
| 1620 |
r.in.secure_channel_type = |
| 1621 |
cli_credentials_get_secure_channel_type(machine_credentials); |
| 1622 |
r.in.computer_name = TEST_MACHINE_NAME; |
| 1623 |
r.in.credential = &credential; |
| 1624 |
r.in.new_password = &new_password; |
| 1625 |
r.out.return_authenticator = &return_authenticator; |
| 1626 |
|
| 1627 |
ZERO_STRUCT(password_buf.data); |
| 1628 |
if (creds->negotiate_flags & NETLOGON_NEG_SUPPORTS_AES) { |
| 1629 |
torture_fail(tctx, "NETLOGON_NEG_SUPPORTS_AES enabled\n"); |
| 1630 |
} |
| 1631 |
dcerpc_binding_handle_auth_info(b, &auth_type, &auth_level); |
| 1632 |
status = netlogon_creds_encrypt_samr_CryptPassword(creds, |
| 1633 |
&password_buf, |
| 1634 |
auth_type, |
| 1635 |
auth_level); |
| 1636 |
torture_assert_ntstatus_ok(tctx, status, "encrypt_samr_CryptPassword"); |
| 1637 |
|
| 1638 |
memcpy(new_password.data, password_buf.data, 512); |
| 1639 |
new_password.length = IVAL(password_buf.data, 512); |
| 1640 |
|
| 1641 |
torture_comment( |
| 1642 |
tctx, |
| 1643 |
"Testing ServerPasswordSet2 on machine account\n"); |
| 1644 |
|
| 1645 |
netlogon_creds_client_authenticator(creds, &credential); |
| 1646 |
|
| 1647 |
torture_assert_ntstatus_ok( |
| 1648 |
tctx, |
| 1649 |
dcerpc_netr_ServerPasswordSet2_r(b, tctx, &r), |
| 1650 |
"ServerPasswordSet2 zero length check failed"); |
| 1651 |
torture_assert_ntstatus_equal( |
| 1652 |
tctx, r.out.result, NT_STATUS_WRONG_PASSWORD, ""); |
| 1653 |
|
| 1654 |
return true; |
| 1655 |
} |
| 1656 |
|
| 1657 |
/* |
| 1658 |
try a change password for our machine account, using a maximum length |
| 1659 |
password |
| 1660 |
*/ |
| 1661 |
static bool test_SetPassword2_maximum_length_password( |
| 1662 |
struct torture_context *tctx, |
| 1663 |
struct dcerpc_pipe *p1, |
| 1664 |
struct cli_credentials *machine_credentials) |
| 1665 |
{ |
| 1666 |
struct netr_ServerPasswordSet2 r; |
| 1667 |
struct netlogon_creds_CredentialState *creds; |
| 1668 |
struct samr_CryptPassword password_buf; |
| 1669 |
struct netr_Authenticator credential, return_authenticator; |
| 1670 |
struct netr_CryptPassword new_password; |
| 1671 |
struct dcerpc_pipe *p = NULL; |
| 1672 |
struct dcerpc_binding_handle *b = NULL; |
| 1673 |
uint32_t flags = NETLOGON_NEG_AUTH2_ADS_FLAGS | NETLOGON_NEG_SUPPORTS_AES; |
| 1674 |
DATA_BLOB new_random_pass = data_blob_null; |
| 1675 |
enum dcerpc_AuthType auth_type; |
| 1676 |
enum dcerpc_AuthLevel auth_level; |
| 1677 |
NTSTATUS status; |
| 1678 |
|
| 1679 |
if (!test_SetupCredentials2( |
| 1680 |
p1, |
| 1681 |
tctx, |
| 1682 |
flags, |
| 1683 |
machine_credentials, |
| 1684 |
cli_credentials_get_secure_channel_type(machine_credentials), |
| 1685 |
&creds)) |
| 1686 |
{ |
| 1687 |
return false; |
| 1688 |
} |
| 1689 |
if (!test_SetupCredentialsPipe( |
| 1690 |
p1, |
| 1691 |
tctx, |
| 1692 |
machine_credentials, |
| 1693 |
creds, |
| 1694 |
DCERPC_SIGN | DCERPC_SEAL, |
| 1695 |
&p)) |
| 1696 |
{ |
| 1697 |
return false; |
| 1698 |
} |
| 1699 |
b = p->binding_handle; |
| 1700 |
|
| 1701 |
r.in.server_name = talloc_asprintf( |
| 1702 |
tctx, |
| 1703 |
"\\\\%s", dcerpc_server_name(p)); |
| 1704 |
r.in.account_name = talloc_asprintf(tctx, "%s$", TEST_MACHINE_NAME); |
| 1705 |
r.in.secure_channel_type = |
| 1706 |
cli_credentials_get_secure_channel_type(machine_credentials); |
| 1707 |
r.in.computer_name = TEST_MACHINE_NAME; |
| 1708 |
r.in.credential = &credential; |
| 1709 |
r.in.new_password = &new_password; |
| 1710 |
r.out.return_authenticator = &return_authenticator; |
| 1711 |
|
| 1712 |
new_random_pass = netlogon_very_rand_pass(tctx, 256); |
| 1713 |
set_pw_in_buffer(password_buf.data, &new_random_pass); |
| 1714 |
SIVAL(password_buf.data, 512, 512); |
| 1715 |
dcerpc_binding_handle_auth_info(b, &auth_type, &auth_level); |
| 1716 |
status = netlogon_creds_encrypt_samr_CryptPassword(creds, |
| 1717 |
&password_buf, |
| 1718 |
auth_type, |
| 1719 |
auth_level); |
| 1720 |
torture_assert_ntstatus_ok(tctx, status, "encrypt_samr_CryptPassword"); |
| 1721 |
|
| 1722 |
memcpy(new_password.data, password_buf.data, 512); |
| 1723 |
new_password.length = IVAL(password_buf.data, 512); |
| 1724 |
|
| 1725 |
torture_comment( |
| 1726 |
tctx, |
| 1727 |
"Testing ServerPasswordSet2 on machine account\n"); |
| 1728 |
|
| 1729 |
netlogon_creds_client_authenticator(creds, &credential); |
| 1730 |
|
| 1731 |
torture_assert_ntstatus_ok( |
| 1732 |
tctx, |
| 1733 |
dcerpc_netr_ServerPasswordSet2_r(b, tctx, &r), |
| 1734 |
"ServerPasswordSet2 zero length check failed"); |
| 1735 |
torture_assert_ntstatus_equal( |
| 1736 |
tctx, r.out.result, NT_STATUS_OK, ""); |
| 1737 |
|
| 1738 |
return true; |
| 1739 |
} |
| 1740 |
|
| 1741 |
/* |
| 1742 |
try a change password for our machine account, using a password of |
| 1743 |
all zeros, and a non zero password length. |
| 1744 |
|
| 1745 |
This test relies on the buffer being encrypted with ARC4, to |
| 1746 |
trigger the appropriate check in the rpc server code |
| 1747 |
*/ |
| 1748 |
static bool test_SetPassword2_all_zero_password( |
| 1749 |
struct torture_context *tctx, |
| 1750 |
struct dcerpc_pipe *p1, |
| 1751 |
struct cli_credentials *machine_credentials) |
| 1752 |
{ |
| 1753 |
struct netr_ServerPasswordSet2 r; |
| 1754 |
struct netlogon_creds_CredentialState *creds; |
| 1755 |
struct samr_CryptPassword password_buf; |
| 1756 |
struct netr_Authenticator credential, return_authenticator; |
| 1757 |
struct netr_CryptPassword new_password; |
| 1758 |
struct dcerpc_pipe *p = NULL; |
| 1759 |
struct dcerpc_binding_handle *b = NULL; |
| 1760 |
uint32_t flags = NETLOGON_NEG_AUTH2_ADS_FLAGS; /* no AES desired here */ |
| 1761 |
enum dcerpc_AuthType auth_type; |
| 1762 |
enum dcerpc_AuthLevel auth_level; |
| 1763 |
NTSTATUS status; |
| 1764 |
|
| 1765 |
if (!test_SetupCredentials2( |
| 1766 |
p1, |
| 1767 |
tctx, |
| 1768 |
flags, |
| 1769 |
machine_credentials, |
| 1770 |
cli_credentials_get_secure_channel_type(machine_credentials), |
| 1771 |
&creds)) |
| 1772 |
{ |
| 1773 |
return false; |
| 1774 |
} |
| 1775 |
if (!test_SetupCredentialsPipe( |
| 1776 |
p1, |
| 1777 |
tctx, |
| 1778 |
machine_credentials, |
| 1779 |
creds, |
| 1780 |
DCERPC_SIGN | DCERPC_SEAL, |
| 1781 |
&p)) |
| 1782 |
{ |
| 1783 |
return false; |
| 1784 |
} |
| 1785 |
b = p->binding_handle; |
| 1786 |
|
| 1787 |
r.in.server_name = talloc_asprintf( |
| 1788 |
tctx, |
| 1789 |
"\\\\%s", dcerpc_server_name(p)); |
| 1790 |
r.in.account_name = talloc_asprintf(tctx, "%s$", TEST_MACHINE_NAME); |
| 1791 |
r.in.secure_channel_type = |
| 1792 |
cli_credentials_get_secure_channel_type(machine_credentials); |
| 1793 |
r.in.computer_name = TEST_MACHINE_NAME; |
| 1794 |
r.in.credential = &credential; |
| 1795 |
r.in.new_password = &new_password; |
| 1796 |
r.out.return_authenticator = &return_authenticator; |
| 1797 |
|
| 1798 |
ZERO_STRUCT(password_buf.data); |
| 1799 |
SIVAL(password_buf.data, 512, 128); |
| 1800 |
if (creds->negotiate_flags & NETLOGON_NEG_SUPPORTS_AES) { |
| 1801 |
torture_fail(tctx, "NETLOGON_NEG_SUPPORTS_AES set"); |
| 1802 |
} |
| 1803 |
dcerpc_binding_handle_auth_info(b, &auth_type, &auth_level); |
| 1804 |
status = netlogon_creds_encrypt_samr_CryptPassword(creds, |
| 1805 |
&password_buf, |
| 1806 |
auth_type, |
| 1807 |
auth_level); |
| 1808 |
torture_assert_ntstatus_ok(tctx, status, "encrypt_samr_CryptPassword"); |
| 1809 |
|
| 1810 |
memcpy(new_password.data, password_buf.data, 512); |
| 1811 |
new_password.length = IVAL(password_buf.data, 512); |
| 1812 |
|
| 1813 |
torture_comment( |
| 1814 |
tctx, |
| 1815 |
"Testing ServerPasswordSet2 on machine account\n"); |
| 1816 |
|
| 1817 |
netlogon_creds_client_authenticator(creds, &credential); |
| 1818 |
|
| 1819 |
torture_assert_ntstatus_ok( |
| 1820 |
tctx, |
| 1821 |
dcerpc_netr_ServerPasswordSet2_r(b, tctx, &r), |
| 1822 |
"ServerPasswordSet2 all zero password check failed"); |
| 1823 |
torture_assert_ntstatus_equal( |
| 1824 |
tctx, r.out.result, NT_STATUS_WRONG_PASSWORD, ""); |
| 1825 |
|
| 1826 |
return true; |
| 1827 |
} |
| 1828 |
|
| 1829 |
|
| 1830 |
static bool test_SetPassword2(struct torture_context *tctx, |
| 1831 |
struct dcerpc_pipe *p, |
| 1832 |
struct cli_credentials *machine_credentials) |
| 1833 |
{ |
| 1834 |
return test_SetPassword2_with_flags(tctx, p, machine_credentials, NETLOGON_NEG_AUTH2_ADS_FLAGS); |
| 1835 |
} |
| 1836 |
|
| 1837 |
static bool test_SetPassword2_AES(struct torture_context *tctx, |
| 1838 |
struct dcerpc_pipe *p, |
| 1839 |
struct cli_credentials *machine_credentials) |
| 1840 |
{ |
| 1841 |
return test_SetPassword2_with_flags(tctx, p, machine_credentials, NETLOGON_NEG_AUTH2_ADS_FLAGS | NETLOGON_NEG_SUPPORTS_AES); |
| 1842 |
} |
| 1843 |
|
| 1844 |
static bool test_GetPassword(struct torture_context *tctx, |
| 1845 |
struct dcerpc_pipe *p, |
| 1846 |
struct cli_credentials *machine_credentials) |
| 1847 |
{ |
| 1848 |
struct netr_ServerPasswordGet r; |
| 1849 |
struct netlogon_creds_CredentialState *creds; |
| 1850 |
struct netr_Authenticator credential; |
| 1851 |
NTSTATUS status; |
| 1852 |
struct netr_Authenticator return_authenticator; |
| 1853 |
struct samr_Password password; |
| 1854 |
struct dcerpc_binding_handle *b = p->binding_handle; |
| 1855 |
|
| 1856 |
if (!test_SetupCredentials(p, tctx, machine_credentials, &creds)) { |
| 1857 |
return false; |
| 1858 |
} |
| 1859 |
|
| 1860 |
netlogon_creds_client_authenticator(creds, &credential); |
| 1861 |
|
| 1862 |
r.in.server_name = talloc_asprintf(tctx, "\\\\%s", dcerpc_server_name(p)); |
| 1863 |
r.in.account_name = talloc_asprintf(tctx, "%s$", TEST_MACHINE_NAME); |
| 1864 |
r.in.secure_channel_type = cli_credentials_get_secure_channel_type(machine_credentials); |
| 1865 |
r.in.computer_name = TEST_MACHINE_NAME; |
| 1866 |
r.in.credential = &credential; |
| 1867 |
r.out.return_authenticator = &return_authenticator; |
| 1868 |
r.out.password = &password; |
| 1869 |
|
| 1870 |
status = dcerpc_netr_ServerPasswordGet_r(b, tctx, &r); |
| 1871 |
torture_assert_ntstatus_ok(tctx, status, "ServerPasswordGet"); |
| 1872 |
torture_assert_ntstatus_ok(tctx, r.out.result, "ServerPasswordGet"); |
| 1873 |
|
| 1874 |
return true; |
| 1875 |
} |
| 1876 |
|
| 1877 |
static bool test_GetTrustPasswords(struct torture_context *tctx, |
| 1878 |
struct dcerpc_pipe *p, |
| 1879 |
struct cli_credentials *machine_credentials) |
| 1880 |
{ |
| 1881 |
struct netr_ServerTrustPasswordsGet r; |
| 1882 |
struct netlogon_creds_CredentialState *creds; |
| 1883 |
struct netr_Authenticator credential; |
| 1884 |
struct netr_Authenticator return_authenticator; |
| 1885 |
struct samr_Password password, password2; |
| 1886 |
struct dcerpc_binding_handle *b = p->binding_handle; |
| 1887 |
|
| 1888 |
if (!test_SetupCredentials(p, tctx, machine_credentials, &creds)) { |
| 1889 |
return false; |
| 1890 |
} |
| 1891 |
|
| 1892 |
netlogon_creds_client_authenticator(creds, &credential); |
| 1893 |
|
| 1894 |
r.in.server_name = talloc_asprintf(tctx, "\\\\%s", dcerpc_server_name(p)); |
| 1895 |
r.in.account_name = talloc_asprintf(tctx, "%s$", TEST_MACHINE_NAME); |
| 1896 |
r.in.secure_channel_type = cli_credentials_get_secure_channel_type(machine_credentials); |
| 1897 |
r.in.computer_name = TEST_MACHINE_NAME; |
| 1898 |
r.in.credential = &credential; |
| 1899 |
r.out.return_authenticator = &return_authenticator; |
| 1900 |
r.out.new_owf_password = &password; |
| 1901 |
r.out.old_owf_password = &password2; |
| 1902 |
|
| 1903 |
torture_assert_ntstatus_ok(tctx, dcerpc_netr_ServerTrustPasswordsGet_r(b, tctx, &r), |
| 1904 |
"ServerTrustPasswordsGet failed"); |
| 1905 |
torture_assert_ntstatus_ok(tctx, r.out.result, "ServerTrustPasswordsGet failed"); |
| 1906 |
|
| 1907 |
return true; |
| 1908 |
} |
| 1909 |
|
| 1910 |
/* |
| 1911 |
try a netlogon SamLogon |
| 1912 |
*/ |
| 1913 |
static bool test_netlogon_ops_args(struct dcerpc_pipe *p, struct torture_context *tctx, |
| 1914 |
struct cli_credentials *credentials, |
| 1915 |
struct netlogon_creds_CredentialState *creds, |
| 1916 |
bool null_domain) |
| 1917 |
{ |
| 1918 |
NTSTATUS status; |
| 1919 |
struct netr_LogonSamLogon r; |
| 1920 |
struct netr_Authenticator auth, auth2; |
| 1921 |
union netr_LogonLevel logon; |
| 1922 |
union netr_Validation validation; |
| 1923 |
uint8_t authoritative; |
| 1924 |
struct netr_NetworkInfo ninfo; |
| 1925 |
DATA_BLOB names_blob, chal, lm_resp, nt_resp; |
| 1926 |
int i; |
| 1927 |
struct dcerpc_binding_handle *b = p->binding_handle; |
| 1928 |
enum dcerpc_AuthType auth_type = DCERPC_AUTH_TYPE_NONE; |
| 1929 |
enum dcerpc_AuthLevel auth_level = DCERPC_AUTH_LEVEL_NONE; |
| 1930 |
int flags = CLI_CRED_NTLM_AUTH; |
| 1931 |
if (lpcfg_client_lanman_auth(tctx->lp_ctx)) { |
| 1932 |
flags |= CLI_CRED_LANMAN_AUTH; |
| 1933 |
} |
| 1934 |
|
| 1935 |
if (lpcfg_client_ntlmv2_auth(tctx->lp_ctx) && !null_domain) { |
| 1936 |
flags |= CLI_CRED_NTLMv2_AUTH; |
| 1937 |
} |
| 1938 |
|
| 1939 |
dcerpc_binding_handle_auth_info(b, &auth_type, &auth_level); |
| 1940 |
|
| 1941 |
cli_credentials_get_ntlm_username_domain(samba_cmdline_get_creds(), |
| 1942 |
tctx, |
| 1943 |
&ninfo.identity_info.account_name.string, |
| 1944 |
&ninfo.identity_info.domain_name.string); |
| 1945 |
|
| 1946 |
if (null_domain) { |
| 1947 |
ninfo.identity_info.domain_name.string = NULL; |
| 1948 |
} |
| 1949 |
|
| 1950 |
generate_random_buffer(ninfo.challenge, |
| 1951 |
sizeof(ninfo.challenge)); |
| 1952 |
chal = data_blob_const(ninfo.challenge, |
| 1953 |
sizeof(ninfo.challenge)); |
| 1954 |
|
| 1955 |
names_blob = NTLMv2_generate_names_blob(tctx, cli_credentials_get_workstation(credentials), |
| 1956 |
cli_credentials_get_domain(credentials)); |
| 1957 |
|
| 1958 |
status = cli_credentials_get_ntlm_response( |
| 1959 |
samba_cmdline_get_creds(), tctx, |
| 1960 |
&flags, |
| 1961 |
chal, |
| 1962 |
NULL, /* server_timestamp */ |
| 1963 |
names_blob, |
| 1964 |
&lm_resp, &nt_resp, |
| 1965 |
NULL, NULL); |
| 1966 |
torture_assert_ntstatus_ok(tctx, status, "cli_credentials_get_ntlm_response failed"); |
| 1967 |
|
| 1968 |
ninfo.lm.data = lm_resp.data; |
| 1969 |
ninfo.lm.length = lm_resp.length; |
| 1970 |
|
| 1971 |
ninfo.nt.data = nt_resp.data; |
| 1972 |
ninfo.nt.length = nt_resp.length; |
| 1973 |
|
| 1974 |
ninfo.identity_info.parameter_control = 0; |
| 1975 |
ninfo.identity_info.logon_id = 0; |
| 1976 |
ninfo.identity_info.workstation.string = cli_credentials_get_workstation(credentials); |
| 1977 |
|
| 1978 |
logon.network = &ninfo; |
| 1979 |
|
| 1980 |
r.in.server_name = talloc_asprintf(tctx, "\\\\%s", dcerpc_server_name(p)); |
| 1981 |
r.in.computer_name = cli_credentials_get_workstation(credentials); |
| 1982 |
r.in.credential = &auth; |
| 1983 |
r.in.return_authenticator = &auth2; |
| 1984 |
r.in.logon_level = NetlogonNetworkInformation; |
| 1985 |
r.in.logon = &logon; |
| 1986 |
r.out.validation = &validation; |
| 1987 |
r.out.authoritative = &authoritative; |
| 1988 |
|
| 1989 |
d_printf("Testing LogonSamLogon with name %s\n", ninfo.identity_info.account_name.string); |
| 1990 |
|
| 1991 |
for (i=2;i<=3;i++) { |
| 1992 |
ZERO_STRUCT(auth2); |
| 1993 |
netlogon_creds_client_authenticator(creds, &auth); |
| 1994 |
|
| 1995 |
r.in.validation_level = i; |
| 1996 |
|
| 1997 |
torture_assert_ntstatus_ok(tctx, dcerpc_netr_LogonSamLogon_r(b, tctx, &r), |
| 1998 |
"LogonSamLogon failed"); |
| 1999 |
if (creds->authenticate_kerberos && |
| 2000 |
auth_type != DCERPC_AUTH_TYPE_KRB5 && |
| 2001 |
auth_level != DCERPC_AUTH_LEVEL_PRIVACY) |
| 2002 |
{ |
| 2003 |
torture_assert_ntstatus_equal(tctx, |
| 2004 |
r.out.result, |
| 2005 |
NT_STATUS_ACCESS_DENIED, |
| 2006 |
"LogonSamLogon auth none krb5"); |
| 2007 |
continue; |
| 2008 |
} |
| 2009 |
torture_assert_ntstatus_ok(tctx, r.out.result, "LogonSamLogon failed"); |
| 2010 |
|
| 2011 |
status = netlogon_creds_client_verify(creds, |
| 2012 |
&r.out.return_authenticator->cred, |
| 2013 |
auth_type, |
| 2014 |
auth_level); |
| 2015 |
torture_assert_ntstatus_ok(tctx, status, |
| 2016 |
"Credential chaining failed"); |
| 2017 |
torture_assert_int_equal(tctx, *r.out.authoritative, 1, |
| 2018 |
"LogonSamLogon invalid *r.out.authoritative"); |
| 2019 |
} |
| 2020 |
|
| 2021 |
/* this makes sure we get the unmarshalling right for invalid levels */ |
| 2022 |
for (i=52;i<53;i++) { |
| 2023 |
ZERO_STRUCT(auth2); |
| 2024 |
/* the authenticator should be ignored by the server */ |
| 2025 |
generate_random_buffer((uint8_t *) &auth, sizeof(auth)); |
| 2026 |
|
| 2027 |
r.in.validation_level = i; |
| 2028 |
|
| 2029 |
torture_assert_ntstatus_ok(tctx, dcerpc_netr_LogonSamLogon_r(b, tctx, &r), |
| 2030 |
"LogonSamLogon failed"); |
| 2031 |
torture_assert_ntstatus_equal(tctx, r.out.result, |
| 2032 |
NT_STATUS_INVALID_INFO_CLASS, |
| 2033 |
"LogonSamLogon failed"); |
| 2034 |
|
| 2035 |
torture_assert_int_equal(tctx, *r.out.authoritative, 1, |
| 2036 |
"LogonSamLogon invalid *r.out.authoritative"); |
| 2037 |
torture_assert(tctx, |
| 2038 |
all_zero((uint8_t *)&auth2, sizeof(auth2)), |
| 2039 |
"Return authenticator non zero"); |
| 2040 |
} |
| 2041 |
|
| 2042 |
for (i=2;i<=3;i++) { |
| 2043 |
ZERO_STRUCT(auth2); |
| 2044 |
netlogon_creds_client_authenticator(creds, &auth); |
| 2045 |
|
| 2046 |
r.in.validation_level = i; |
| 2047 |
|
| 2048 |
torture_assert_ntstatus_ok(tctx, dcerpc_netr_LogonSamLogon_r(b, tctx, &r), |
| 2049 |
"LogonSamLogon failed"); |
| 2050 |
if (creds->authenticate_kerberos && |
| 2051 |
auth_type != DCERPC_AUTH_TYPE_KRB5 && |
| 2052 |
auth_level != DCERPC_AUTH_LEVEL_PRIVACY) |
| 2053 |
{ |
| 2054 |
torture_assert_ntstatus_equal(tctx, |
| 2055 |
r.out.result, |
| 2056 |
NT_STATUS_ACCESS_DENIED, |
| 2057 |
"LogonSamLogon auth none krb5"); |
| 2058 |
continue; |
| 2059 |
} |
| 2060 |
torture_assert_ntstatus_ok(tctx, r.out.result, "LogonSamLogon failed"); |
| 2061 |
|
| 2062 |
status = netlogon_creds_client_verify(creds, |
| 2063 |
&r.out.return_authenticator->cred, |
| 2064 |
auth_type, |
| 2065 |
auth_level); |
| 2066 |
torture_assert_ntstatus_ok(tctx, status, |
| 2067 |
"Credential chaining failed"); |
| 2068 |
torture_assert_int_equal(tctx, *r.out.authoritative, 1, |
| 2069 |
"LogonSamLogon invalid *r.out.authoritative"); |
| 2070 |
} |
| 2071 |
|
| 2072 |
r.in.logon_level = 52; |
| 2073 |
|
| 2074 |
for (i=2;i<=3;i++) { |
| 2075 |
ZERO_STRUCT(auth2); |
| 2076 |
/* the authenticator should be ignored by the server */ |
| 2077 |
generate_random_buffer((uint8_t *) &auth, sizeof(auth)); |
| 2078 |
|
| 2079 |
r.in.validation_level = i; |
| 2080 |
|
| 2081 |
torture_comment(tctx, "Testing SamLogon with validation level %d and a NULL credential\n", i); |
| 2082 |
|
| 2083 |
torture_assert_ntstatus_ok(tctx, dcerpc_netr_LogonSamLogon_r(b, tctx, &r), |
| 2084 |
"LogonSamLogon failed"); |
| 2085 |
torture_assert_ntstatus_equal(tctx, r.out.result, NT_STATUS_INVALID_PARAMETER, |
| 2086 |
"LogonSamLogon expected INVALID_PARAMETER"); |
| 2087 |
|
| 2088 |
torture_assert(tctx, |
| 2089 |
all_zero((uint8_t *)&auth2, sizeof(auth2)), |
| 2090 |
"Return authenticator non zero"); |
| 2091 |
torture_assert_int_equal(tctx, *r.out.authoritative, 1, |
| 2092 |
"LogonSamLogon invalid *r.out.authoritative"); |
| 2093 |
} |
| 2094 |
|
| 2095 |
r.in.credential = NULL; |
| 2096 |
|
| 2097 |
for (i=2;i<=3;i++) { |
| 2098 |
ZERO_STRUCT(auth2); |
| 2099 |
|
| 2100 |
r.in.validation_level = i; |
| 2101 |
|
| 2102 |
torture_comment(tctx, "Testing SamLogon with validation level %d and a NULL credential\n", i); |
| 2103 |
|
| 2104 |
torture_assert_ntstatus_ok(tctx, dcerpc_netr_LogonSamLogon_r(b, tctx, &r), |
| 2105 |
"LogonSamLogon failed"); |
| 2106 |
torture_assert_ntstatus_equal(tctx, r.out.result, NT_STATUS_INVALID_PARAMETER, |
| 2107 |
"LogonSamLogon expected INVALID_PARAMETER"); |
| 2108 |
|
| 2109 |
torture_assert(tctx, |
| 2110 |
all_zero((uint8_t *)&auth2, sizeof(auth2)), |
| 2111 |
"Return authenticator non zero"); |
| 2112 |
torture_assert_int_equal(tctx, *r.out.authoritative, 1, |
| 2113 |
"LogonSamLogon invalid *r.out.authoritative"); |
| 2114 |
} |
| 2115 |
|
| 2116 |
r.in.logon_level = NetlogonNetworkInformation; |
| 2117 |
r.in.credential = &auth; |
| 2118 |
|
| 2119 |
for (i=2;i<=3;i++) { |
| 2120 |
ZERO_STRUCT(auth2); |
| 2121 |
netlogon_creds_client_authenticator(creds, &auth); |
| 2122 |
|
| 2123 |
r.in.validation_level = i; |
| 2124 |
|
| 2125 |
torture_assert_ntstatus_ok(tctx, dcerpc_netr_LogonSamLogon_r(b, tctx, &r), |
| 2126 |
"LogonSamLogon failed"); |
| 2127 |
if (creds->authenticate_kerberos && |
| 2128 |
auth_type != DCERPC_AUTH_TYPE_KRB5 && |
| 2129 |
auth_level != DCERPC_AUTH_LEVEL_PRIVACY) |
| 2130 |
{ |
| 2131 |
torture_assert_ntstatus_equal(tctx, |
| 2132 |
r.out.result, |
| 2133 |
NT_STATUS_ACCESS_DENIED, |
| 2134 |
"LogonSamLogon auth none krb5"); |
| 2135 |
continue; |
| 2136 |
} |
| 2137 |
torture_assert_ntstatus_ok(tctx, r.out.result, "LogonSamLogon failed"); |
| 2138 |
|
| 2139 |
status = netlogon_creds_client_verify(creds, |
| 2140 |
&r.out.return_authenticator->cred, |
| 2141 |
auth_type, |
| 2142 |
auth_level); |
| 2143 |
torture_assert_ntstatus_ok(tctx, status, |
| 2144 |
"Credential chaining failed"); |
| 2145 |
torture_assert_int_equal(tctx, *r.out.authoritative, 1, |
| 2146 |
"LogonSamLogon invalid *r.out.authoritative"); |
| 2147 |
} |
| 2148 |
|
| 2149 |
return true; |
| 2150 |
} |
| 2151 |
|
| 2152 |
bool test_netlogon_ops(struct dcerpc_pipe *p, struct torture_context *tctx, |
| 2153 |
struct cli_credentials *credentials, |
| 2154 |
struct netlogon_creds_CredentialState *creds) |
| 2155 |
{ |
| 2156 |
return test_netlogon_ops_args(p, tctx, credentials, creds, false); |
| 2157 |
} |
| 2158 |
|
| 2159 |
/* |
| 2160 |
try a netlogon GetCapabilities |
| 2161 |
*/ |
| 2162 |
bool test_netlogon_capabilities(struct dcerpc_pipe *p, struct torture_context *tctx, |
| 2163 |
struct cli_credentials *credentials, |
| 2164 |
uint32_t requested_flags, |
| 2165 |
struct netlogon_creds_CredentialState *creds) |
| 2166 |
{ |
| 2167 |
NTSTATUS status; |
| 2168 |
struct netr_LogonGetCapabilities r; |
| 2169 |
union netr_Capabilities capabilities; |
| 2170 |
struct netr_Authenticator auth, return_auth; |
| 2171 |
struct netlogon_creds_CredentialState tmp_creds; |
| 2172 |
struct dcerpc_binding_handle *b = p->binding_handle; |
| 2173 |
enum dcerpc_AuthType auth_type = DCERPC_AUTH_TYPE_NONE; |
| 2174 |
enum dcerpc_AuthLevel auth_level = DCERPC_AUTH_LEVEL_NONE; |
| 2175 |
|
| 2176 |
dcerpc_binding_handle_auth_info(b, &auth_type, &auth_level); |
| 2177 |
|
| 2178 |
r.in.server_name = talloc_asprintf(tctx, "\\\\%s", dcerpc_server_name(p)); |
| 2179 |
r.in.computer_name = cli_credentials_get_workstation(credentials); |
| 2180 |
r.in.credential = &auth; |
| 2181 |
r.in.return_authenticator = &return_auth; |
| 2182 |
r.in.query_level = 1; |
| 2183 |
r.out.capabilities = &capabilities; |
| 2184 |
r.out.return_authenticator = &return_auth; |
| 2185 |
|
| 2186 |
torture_comment(tctx, "Testing LogonGetCapabilities with query_level=0\n"); |
| 2187 |
|
| 2188 |
r.in.query_level = 0; |
| 2189 |
ZERO_STRUCT(return_auth); |
| 2190 |
|
| 2191 |
/* |
| 2192 |
* we need to operate on a temporary copy of creds |
| 2193 |
* because dcerpc_netr_LogonGetCapabilities with |
| 2194 |
* an unknown query level returns DCERPC_NCA_S_FAULT_INVALID_TAG |
| 2195 |
* => NT_STATUS_RPC_ENUM_VALUE_OUT_OF_RANGE |
| 2196 |
* without looking at the authenticator. |
| 2197 |
*/ |
| 2198 |
tmp_creds = *creds; |
| 2199 |
netlogon_creds_client_authenticator(&tmp_creds, &auth); |
| 2200 |
|
| 2201 |
status = dcerpc_netr_LogonGetCapabilities_r(b, tctx, &r); |
| 2202 |
torture_assert_ntstatus_equal(tctx, status, NT_STATUS_RPC_ENUM_VALUE_OUT_OF_RANGE, |
| 2203 |
"LogonGetCapabilities query_level=0 failed"); |
| 2204 |
|
| 2205 |
torture_comment(tctx, "Testing LogonGetCapabilities with query_level=3\n"); |
| 2206 |
|
| 2207 |
r.in.query_level = 3; |
| 2208 |
ZERO_STRUCT(return_auth); |
| 2209 |
|
| 2210 |
/* |
| 2211 |
* we need to operate on a temporary copy of creds |
| 2212 |
* because dcerpc_netr_LogonGetCapabilities with |
| 2213 |
* an unknown query level returns DCERPC_NCA_S_FAULT_INVALID_TAG |
| 2214 |
* => NT_STATUS_RPC_ENUM_VALUE_OUT_OF_RANGE |
| 2215 |
* without looking at the authenticator. |
| 2216 |
*/ |
| 2217 |
tmp_creds = *creds; |
| 2218 |
netlogon_creds_client_authenticator(&tmp_creds, &auth); |
| 2219 |
|
| 2220 |
status = dcerpc_netr_LogonGetCapabilities_r(b, tctx, &r); |
| 2221 |
torture_assert_ntstatus_equal(tctx, status, NT_STATUS_RPC_ENUM_VALUE_OUT_OF_RANGE, |
| 2222 |
"LogonGetCapabilities query_level=0 failed"); |
| 2223 |
|
| 2224 |
torture_comment(tctx, "Testing LogonGetCapabilities with query_level=1\n"); |
| 2225 |
|
| 2226 |
r.in.query_level = 1; |
| 2227 |
ZERO_STRUCT(return_auth); |
| 2228 |
|
| 2229 |
/* |
| 2230 |
* we need to operate on a temporary copy of creds |
| 2231 |
* because dcerpc_netr_LogonGetCapabilities was |
| 2232 |
* dcerpc_netr_DummyFunction and returns NT_STATUS_NOT_IMPLEMENTED |
| 2233 |
* without looking at the authenticator. |
| 2234 |
*/ |
| 2235 |
tmp_creds = *creds; |
| 2236 |
netlogon_creds_client_authenticator(&tmp_creds, &auth); |
| 2237 |
|
| 2238 |
status = dcerpc_netr_LogonGetCapabilities_r(b, tctx, &r); |
| 2239 |
torture_assert_ntstatus_ok(tctx, status, |
| 2240 |
"LogonGetCapabilities query_level=1 failed"); |
| 2241 |
torture_assert_ntstatus_ok(tctx, r.out.result, |
| 2242 |
"LogonGetCapabilities query_level=1 failed"); |
| 2243 |
|
| 2244 |
*creds = tmp_creds; |
| 2245 |
|
| 2246 |
status = netlogon_creds_client_verify(creds, |
| 2247 |
&r.out.return_authenticator->cred, |
| 2248 |
auth_type, |
| 2249 |
auth_level); |
| 2250 |
torture_assert_ntstatus_ok(tctx, status, |
| 2251 |
"Credential chaining failed"); |
| 2252 |
|
| 2253 |
torture_assert_int_equal(tctx, creds->negotiate_flags, |
| 2254 |
capabilities.server_capabilities, |
| 2255 |
"negotiate flags"); |
| 2256 |
|
| 2257 |
torture_comment(tctx, "Testing LogonGetCapabilities with query_level=2\n"); |
| 2258 |
|
| 2259 |
r.in.query_level = 2; |
| 2260 |
ZERO_STRUCT(return_auth); |
| 2261 |
|
| 2262 |
/* |
| 2263 |
* we need to operate on a temporary copy of creds |
| 2264 |
* because dcerpc_netr_LogonGetCapabilities with |
| 2265 |
* an query level 2 may returns DCERPC_NCA_S_FAULT_INVALID_TAG |
| 2266 |
* => NT_STATUS_RPC_ENUM_VALUE_OUT_OF_RANGE |
| 2267 |
* without looking at the authenticator. |
| 2268 |
*/ |
| 2269 |
tmp_creds = *creds; |
| 2270 |
netlogon_creds_client_authenticator(&tmp_creds, &auth); |
| 2271 |
|
| 2272 |
status = dcerpc_netr_LogonGetCapabilities_r(b, tctx, &r); |
| 2273 |
torture_assert_ntstatus_ok(tctx, status, |
| 2274 |
"LogonGetCapabilities query_level=2 failed"); |
| 2275 |
torture_assert_ntstatus_ok(tctx, r.out.result, |
| 2276 |
"LogonGetCapabilities query_level=2 failed"); |
| 2277 |
|
| 2278 |
*creds = tmp_creds; |
| 2279 |
|
| 2280 |
status = netlogon_creds_client_verify(creds, |
| 2281 |
&r.out.return_authenticator->cred, |
| 2282 |
auth_type, |
| 2283 |
auth_level); |
| 2284 |
torture_assert_ntstatus_ok(tctx, status, |
| 2285 |
"Credential chaining failed"); |
| 2286 |
|
| 2287 |
torture_assert_int_equal(tctx, requested_flags, |
| 2288 |
capabilities.requested_flags, |
| 2289 |
"negotiate flags"); |
| 2290 |
|
| 2291 |
return true; |
| 2292 |
} |
| 2293 |
|
| 2294 |
/* |
| 2295 |
try a netlogon SamLogon |
| 2296 |
*/ |
| 2297 |
static bool test_SamLogon(struct torture_context *tctx, |
| 2298 |
struct dcerpc_pipe *p, |
| 2299 |
struct cli_credentials *credentials) |
| 2300 |
{ |
| 2301 |
struct netlogon_creds_CredentialState *creds; |
| 2302 |
|
| 2303 |
if (!test_SetupCredentials(p, tctx, credentials, &creds)) { |
| 2304 |
return false; |
| 2305 |
} |
| 2306 |
|
| 2307 |
return test_netlogon_ops(p, tctx, credentials, creds); |
| 2308 |
} |
| 2309 |
|
| 2310 |
static bool test_invalidAuthenticate2(struct torture_context *tctx, |
| 2311 |
struct dcerpc_pipe *p, |
| 2312 |
struct cli_credentials *credentials) |
| 2313 |
{ |
| 2314 |
struct netlogon_creds_CredentialState *creds; |
| 2315 |
uint32_t flags = NETLOGON_NEG_AUTH2_FLAGS | NETLOGON_NEG_SUPPORTS_AES; |
| 2316 |
|
| 2317 |
torture_comment(tctx, "Testing invalidAuthenticate2\n"); |
| 2318 |
|
| 2319 |
if (!test_SetupCredentials2(p, tctx, flags, |
| 2320 |
credentials, |
| 2321 |
cli_credentials_get_secure_channel_type(credentials), |
| 2322 |
&creds)) { |
| 2323 |
return false; |
| 2324 |
} |
| 2325 |
|
| 2326 |
if (!test_SetupCredentials2ex(p, tctx, flags, |
| 2327 |
credentials, |
| 2328 |
"1234567890123456", |
| 2329 |
cli_credentials_get_secure_channel_type(credentials), |
| 2330 |
STATUS_BUFFER_OVERFLOW, |
| 2331 |
&creds)) { |
| 2332 |
return false; |
| 2333 |
} |
| 2334 |
|
| 2335 |
if (!test_SetupCredentials2ex(p, tctx, flags, |
| 2336 |
credentials, |
| 2337 |
"123456789012345", |
| 2338 |
cli_credentials_get_secure_channel_type(credentials), |
| 2339 |
NT_STATUS_OK, |
| 2340 |
&creds)) { |
| 2341 |
return false; |
| 2342 |
} |
| 2343 |
|
| 2344 |
return true; |
| 2345 |
} |
| 2346 |
|
| 2347 |
static bool test_ServerReqChallengeGlobal(struct torture_context *tctx, |
| 2348 |
struct dcerpc_pipe *p1, |
| 2349 |
struct cli_credentials *machine_credentials) |
| 2350 |
{ |
| 2351 |
uint32_t flags = NETLOGON_NEG_AUTH2_FLAGS | NETLOGON_NEG_SUPPORTS_AES; |
| 2352 |
struct netr_ServerReqChallenge r; |
| 2353 |
struct netr_ServerAuthenticate3 a; |
| 2354 |
struct netr_Credential credentials1, credentials2, credentials3; |
| 2355 |
struct netlogon_creds_CredentialState *creds; |
| 2356 |
struct samr_Password mach_password; |
| 2357 |
uint32_t rid; |
| 2358 |
const char *machine_name; |
| 2359 |
const char *plain_pass; |
| 2360 |
struct dcerpc_binding_handle *b1 = p1->binding_handle; |
| 2361 |
const struct dcerpc_binding *bd1 = dcerpc_binding_handle_get_binding(b1); |
| 2362 |
struct dcerpc_pipe *p2 = NULL; |
| 2363 |
struct dcerpc_binding_handle *b2 = NULL; |
| 2364 |
|
| 2365 |
machine_name = cli_credentials_get_workstation(machine_credentials); |
| 2366 |
torture_assert(tctx, machine_name != NULL, "machine_name"); |
| 2367 |
plain_pass = cli_credentials_get_password(machine_credentials); |
| 2368 |
torture_assert(tctx, plain_pass != NULL, "plain_pass"); |
| 2369 |
|
| 2370 |
torture_comment(tctx, "Testing ServerReqChallenge on b1\n"); |
| 2371 |
|
| 2372 |
torture_assert_ntstatus_ok(tctx, |
| 2373 |
dcerpc_pipe_connect_b(tctx, &p2, bd1, |
| 2374 |
&ndr_table_netlogon, |
| 2375 |
machine_credentials, |
| 2376 |
tctx->ev, tctx->lp_ctx), |
| 2377 |
"dcerpc_pipe_connect_b failed"); |
| 2378 |
b2 = p2->binding_handle; |
| 2379 |
|
| 2380 |
r.in.server_name = NULL; |
| 2381 |
r.in.computer_name = machine_name; |
| 2382 |
r.in.credentials = &credentials1; |
| 2383 |
r.out.return_credentials = &credentials2; |
| 2384 |
|
| 2385 |
netlogon_creds_random_challenge(&credentials1); |
| 2386 |
|
| 2387 |
torture_assert_ntstatus_ok(tctx, dcerpc_netr_ServerReqChallenge_r(b1, tctx, &r), |
| 2388 |
"ServerReqChallenge failed on b1"); |
| 2389 |
torture_assert_ntstatus_ok(tctx, r.out.result, "ServerReqChallenge failed on b1"); |
| 2390 |
|
| 2391 |
E_md4hash(plain_pass, mach_password.hash); |
| 2392 |
|
| 2393 |
a.in.server_name = NULL; |
| 2394 |
a.in.account_name = talloc_asprintf(tctx, "%s$", machine_name); |
| 2395 |
a.in.secure_channel_type = cli_credentials_get_secure_channel_type(machine_credentials); |
| 2396 |
a.in.computer_name = machine_name; |
| 2397 |
a.in.negotiate_flags = &flags; |
| 2398 |
a.in.credentials = &credentials3; |
| 2399 |
a.out.return_credentials = &credentials3; |
| 2400 |
a.out.negotiate_flags = &flags; |
| 2401 |
a.out.rid = &rid; |
| 2402 |
|
| 2403 |
creds = netlogon_creds_client_init(tctx, a.in.account_name, |
| 2404 |
a.in.computer_name, |
| 2405 |
a.in.secure_channel_type, |
| 2406 |
&credentials1, &credentials2, |
| 2407 |
&mach_password, &credentials3, |
| 2408 |
flags, |
| 2409 |
flags); |
| 2410 |
|
| 2411 |
torture_assert(tctx, creds != NULL, "memory allocation"); |
| 2412 |
|
| 2413 |
torture_comment(tctx, "Testing ServerAuthenticate3 on b2\n"); |
| 2414 |
|
| 2415 |
torture_assert_ntstatus_ok(tctx, dcerpc_netr_ServerAuthenticate3_r(b2, tctx, &a), |
| 2416 |
"ServerAuthenticate3 failed on b2"); |
| 2417 |
torture_assert_ntstatus_ok(tctx, a.out.result, "ServerAuthenticate3 failed on b2"); |
| 2418 |
torture_assert(tctx, netlogon_creds_client_check(creds, &credentials3), "Credential chaining failed"); |
| 2419 |
|
| 2420 |
return true; |
| 2421 |
} |
| 2422 |
|
| 2423 |
/* |
| 2424 |
* Test the re-use of the challenge is not possible on a third |
| 2425 |
* connection, after first using it second one. |
| 2426 |
*/ |
| 2427 |
|
| 2428 |
static bool test_ServerReqChallengeReuseGlobal(struct torture_context *tctx, |
| 2429 |
struct dcerpc_pipe *p1, |
| 2430 |
struct cli_credentials *machine_credentials) |
| 2431 |
{ |
| 2432 |
uint32_t flags = NETLOGON_NEG_AUTH2_FLAGS | NETLOGON_NEG_SUPPORTS_AES; |
| 2433 |
struct netr_ServerReqChallenge r; |
| 2434 |
struct netr_ServerAuthenticate3 a; |
| 2435 |
struct netr_Credential credentials1, credentials2, credentials3; |
| 2436 |
struct netlogon_creds_CredentialState *creds; |
| 2437 |
struct samr_Password mach_password; |
| 2438 |
uint32_t rid; |
| 2439 |
const char *machine_name; |
| 2440 |
const char *plain_pass; |
| 2441 |
struct dcerpc_binding_handle *b1 = p1->binding_handle; |
| 2442 |
const struct dcerpc_binding *bd1 = dcerpc_binding_handle_get_binding(b1); |
| 2443 |
struct dcerpc_pipe *p2 = NULL; |
| 2444 |
struct dcerpc_binding_handle *b2 = NULL; |
| 2445 |
struct dcerpc_pipe *p3 = NULL; |
| 2446 |
struct dcerpc_binding_handle *b3 = NULL; |
| 2447 |
|
| 2448 |
machine_name = cli_credentials_get_workstation(machine_credentials); |
| 2449 |
torture_assert(tctx, machine_name != NULL, "machine_name"); |
| 2450 |
plain_pass = cli_credentials_get_password(machine_credentials); |
| 2451 |
torture_assert(tctx, plain_pass != NULL, "plain_pass"); |
| 2452 |
|
| 2453 |
torture_comment(tctx, "Testing ServerReqChallenge on b1\n"); |
| 2454 |
|
| 2455 |
torture_assert_ntstatus_ok(tctx, |
| 2456 |
dcerpc_pipe_connect_b(tctx, &p2, bd1, |
| 2457 |
&ndr_table_netlogon, |
| 2458 |
machine_credentials, |
| 2459 |
tctx->ev, tctx->lp_ctx), |
| 2460 |
"dcerpc_pipe_connect_b failed"); |
| 2461 |
b2 = p2->binding_handle; |
| 2462 |
|
| 2463 |
torture_assert_ntstatus_ok(tctx, |
| 2464 |
dcerpc_pipe_connect_b(tctx, &p3, bd1, |
| 2465 |
&ndr_table_netlogon, |
| 2466 |
machine_credentials, |
| 2467 |
tctx->ev, tctx->lp_ctx), |
| 2468 |
"dcerpc_pipe_connect_b failed"); |
| 2469 |
b3 = p3->binding_handle; |
| 2470 |
|
| 2471 |
r.in.server_name = NULL; |
| 2472 |
r.in.computer_name = machine_name; |
| 2473 |
r.in.credentials = &credentials1; |
| 2474 |
r.out.return_credentials = &credentials2; |
| 2475 |
|
| 2476 |
netlogon_creds_random_challenge(&credentials1); |
| 2477 |
|
| 2478 |
torture_assert_ntstatus_ok(tctx, dcerpc_netr_ServerReqChallenge_r(b1, tctx, &r), |
| 2479 |
"ServerReqChallenge failed on b1"); |
| 2480 |
torture_assert_ntstatus_ok(tctx, r.out.result, "ServerReqChallenge failed on b1"); |
| 2481 |
|
| 2482 |
E_md4hash(plain_pass, mach_password.hash); |
| 2483 |
|
| 2484 |
a.in.server_name = NULL; |
| 2485 |
a.in.account_name = talloc_asprintf(tctx, "%s$", machine_name); |
| 2486 |
a.in.secure_channel_type = cli_credentials_get_secure_channel_type(machine_credentials); |
| 2487 |
a.in.computer_name = machine_name; |
| 2488 |
a.in.negotiate_flags = &flags; |
| 2489 |
a.in.credentials = &credentials3; |
| 2490 |
a.out.return_credentials = &credentials3; |
| 2491 |
a.out.negotiate_flags = &flags; |
| 2492 |
a.out.rid = &rid; |
| 2493 |
|
| 2494 |
creds = netlogon_creds_client_init(tctx, a.in.account_name, |
| 2495 |
a.in.computer_name, |
| 2496 |
a.in.secure_channel_type, |
| 2497 |
&credentials1, &credentials2, |
| 2498 |
&mach_password, &credentials3, |
| 2499 |
flags, |
| 2500 |
flags); |
| 2501 |
|
| 2502 |
torture_assert(tctx, creds != NULL, "memory allocation"); |
| 2503 |
|
| 2504 |
torture_comment(tctx, "Testing ServerAuthenticate3 on b2\n"); |
| 2505 |
|
| 2506 |
torture_assert_ntstatus_ok(tctx, dcerpc_netr_ServerAuthenticate3_r(b2, tctx, &a), |
| 2507 |
"ServerAuthenticate3 failed on b2"); |
| 2508 |
torture_assert_ntstatus_ok(tctx, a.out.result, "ServerAuthenticate3 failed on b2"); |
| 2509 |
torture_assert(tctx, netlogon_creds_client_check(creds, &credentials3), "Credential chaining failed"); |
| 2510 |
|
| 2511 |
/* We have to re-run this part */ |
| 2512 |
creds = netlogon_creds_client_init(tctx, a.in.account_name, |
| 2513 |
a.in.computer_name, |
| 2514 |
a.in.secure_channel_type, |
| 2515 |
&credentials1, &credentials2, |
| 2516 |
&mach_password, &credentials3, |
| 2517 |
flags, |
| 2518 |
flags); |
| 2519 |
|
| 2520 |
torture_assert_ntstatus_ok(tctx, dcerpc_netr_ServerAuthenticate3_r(b3, tctx, &a), |
| 2521 |
"ServerAuthenticate3 failed on b3"); |
| 2522 |
torture_assert_ntstatus_equal(tctx, a.out.result, NT_STATUS_ACCESS_DENIED, |
| 2523 |
"ServerAuthenticate3 should have failed on b3, due to credential reuse"); |
| 2524 |
return true; |
| 2525 |
} |
| 2526 |
|
| 2527 |
/* |
| 2528 |
* Test if use of the per-pipe challenge will wipe out the globally cached challenge |
| 2529 |
*/ |
| 2530 |
static bool test_ServerReqChallengeReuseGlobal2(struct torture_context *tctx, |
| 2531 |
struct dcerpc_pipe *p1, |
| 2532 |
struct cli_credentials *machine_credentials) |
| 2533 |
{ |
| 2534 |
uint32_t flags = NETLOGON_NEG_AUTH2_FLAGS | NETLOGON_NEG_SUPPORTS_AES; |
| 2535 |
struct netr_ServerReqChallenge r; |
| 2536 |
struct netr_ServerAuthenticate3 a; |
| 2537 |
struct netr_Credential credentials1, credentials2, credentials3; |
| 2538 |
struct netlogon_creds_CredentialState *creds; |
| 2539 |
struct samr_Password mach_password; |
| 2540 |
uint32_t rid; |
| 2541 |
const char *machine_name; |
| 2542 |
const char *plain_pass; |
| 2543 |
struct dcerpc_binding_handle *b1 = p1->binding_handle; |
| 2544 |
const struct dcerpc_binding *bd1 = dcerpc_binding_handle_get_binding(b1); |
| 2545 |
struct dcerpc_pipe *p2 = NULL; |
| 2546 |
struct dcerpc_binding_handle *b2 = NULL; |
| 2547 |
|
| 2548 |
machine_name = cli_credentials_get_workstation(machine_credentials); |
| 2549 |
torture_assert(tctx, machine_name != NULL, "machine_name"); |
| 2550 |
plain_pass = cli_credentials_get_password(machine_credentials); |
| 2551 |
torture_assert(tctx, plain_pass != NULL, "plain_pass"); |
| 2552 |
|
| 2553 |
torture_comment(tctx, "Testing ServerReqChallenge on b1\n"); |
| 2554 |
|
| 2555 |
torture_assert_ntstatus_ok(tctx, |
| 2556 |
dcerpc_pipe_connect_b(tctx, &p2, bd1, |
| 2557 |
&ndr_table_netlogon, |
| 2558 |
machine_credentials, |
| 2559 |
tctx->ev, tctx->lp_ctx), |
| 2560 |
"dcerpc_pipe_connect_b failed"); |
| 2561 |
b2 = p2->binding_handle; |
| 2562 |
|
| 2563 |
r.in.server_name = NULL; |
| 2564 |
r.in.computer_name = machine_name; |
| 2565 |
r.in.credentials = &credentials1; |
| 2566 |
r.out.return_credentials = &credentials2; |
| 2567 |
|
| 2568 |
netlogon_creds_random_challenge(&credentials1); |
| 2569 |
|
| 2570 |
torture_assert_ntstatus_ok(tctx, dcerpc_netr_ServerReqChallenge_r(b1, tctx, &r), |
| 2571 |
"ServerReqChallenge failed on b1"); |
| 2572 |
torture_assert_ntstatus_ok(tctx, r.out.result, "ServerReqChallenge failed on b1"); |
| 2573 |
|
| 2574 |
E_md4hash(plain_pass, mach_password.hash); |
| 2575 |
|
| 2576 |
a.in.server_name = NULL; |
| 2577 |
a.in.account_name = talloc_asprintf(tctx, "%s$", machine_name); |
| 2578 |
a.in.secure_channel_type = cli_credentials_get_secure_channel_type(machine_credentials); |
| 2579 |
a.in.computer_name = machine_name; |
| 2580 |
a.in.negotiate_flags = &flags; |
| 2581 |
a.in.credentials = &credentials3; |
| 2582 |
a.out.return_credentials = &credentials3; |
| 2583 |
a.out.negotiate_flags = &flags; |
| 2584 |
a.out.rid = &rid; |
| 2585 |
|
| 2586 |
creds = netlogon_creds_client_init(tctx, a.in.account_name, |
| 2587 |
a.in.computer_name, |
| 2588 |
a.in.secure_channel_type, |
| 2589 |
&credentials1, &credentials2, |
| 2590 |
&mach_password, &credentials3, |
| 2591 |
flags, |
| 2592 |
flags); |
| 2593 |
|
| 2594 |
torture_assert(tctx, creds != NULL, "memory allocation"); |
| 2595 |
|
| 2596 |
torture_comment(tctx, "Testing ServerAuthenticate3 on b2\n"); |
| 2597 |
|
| 2598 |
torture_assert_ntstatus_ok(tctx, dcerpc_netr_ServerAuthenticate3_r(b1, tctx, &a), |
| 2599 |
"ServerAuthenticate3 failed on b"); |
| 2600 |
torture_assert_ntstatus_ok(tctx, a.out.result, "ServerAuthenticate3 failed on b"); |
| 2601 |
torture_assert(tctx, netlogon_creds_client_check(creds, &credentials3), "Credential chaining failed"); |
| 2602 |
|
| 2603 |
/* We have to re-run this part */ |
| 2604 |
creds = netlogon_creds_client_init(tctx, a.in.account_name, |
| 2605 |
a.in.computer_name, |
| 2606 |
a.in.secure_channel_type, |
| 2607 |
&credentials1, &credentials2, |
| 2608 |
&mach_password, &credentials3, |
| 2609 |
flags, |
| 2610 |
flags); |
| 2611 |
|
| 2612 |
torture_assert_ntstatus_ok(tctx, dcerpc_netr_ServerAuthenticate3_r(b2, tctx, &a), |
| 2613 |
"ServerAuthenticate3 failed on b2"); |
| 2614 |
torture_assert_ntstatus_equal(tctx, a.out.result, NT_STATUS_ACCESS_DENIED, |
| 2615 |
"ServerAuthenticate3 should have failed on b2, due to credential reuse"); |
| 2616 |
return true; |
| 2617 |
} |
| 2618 |
|
| 2619 |
/* |
| 2620 |
* Test if use of the globally cached challenge will wipe out the |
| 2621 |
* per-pipe challenge |
| 2622 |
*/ |
| 2623 |
static bool test_ServerReqChallengeReuseGlobal3(struct torture_context *tctx, |
| 2624 |
struct dcerpc_pipe *p1, |
| 2625 |
struct cli_credentials *machine_credentials) |
| 2626 |
{ |
| 2627 |
uint32_t flags = NETLOGON_NEG_AUTH2_FLAGS | NETLOGON_NEG_SUPPORTS_AES; |
| 2628 |
struct netr_ServerReqChallenge r; |
| 2629 |
struct netr_ServerAuthenticate3 a; |
| 2630 |
struct netr_Credential credentials1, credentials2, credentials3; |
| 2631 |
struct netlogon_creds_CredentialState *creds; |
| 2632 |
struct samr_Password mach_password; |
| 2633 |
uint32_t rid; |
| 2634 |
const char *machine_name; |
| 2635 |
const char *plain_pass; |
| 2636 |
struct dcerpc_binding_handle *b1 = p1->binding_handle; |
| 2637 |
const struct dcerpc_binding *bd1 = dcerpc_binding_handle_get_binding(b1); |
| 2638 |
struct dcerpc_pipe *p2 = NULL; |
| 2639 |
struct dcerpc_binding_handle *b2 = NULL; |
| 2640 |
|
| 2641 |
machine_name = cli_credentials_get_workstation(machine_credentials); |
| 2642 |
torture_assert(tctx, machine_name != NULL, "machine_name"); |
| 2643 |
plain_pass = cli_credentials_get_password(machine_credentials); |
| 2644 |
torture_assert(tctx, plain_pass != NULL, "plain_pass"); |
| 2645 |
|
| 2646 |
torture_comment(tctx, "Testing ServerReqChallenge on b1\n"); |
| 2647 |
|
| 2648 |
torture_assert_ntstatus_ok(tctx, |
| 2649 |
dcerpc_pipe_connect_b(tctx, &p2, bd1, |
| 2650 |
&ndr_table_netlogon, |
| 2651 |
machine_credentials, |
| 2652 |
tctx->ev, tctx->lp_ctx), |
| 2653 |
"dcerpc_pipe_connect_b failed"); |
| 2654 |
b2 = p2->binding_handle; |
| 2655 |
|
| 2656 |
r.in.server_name = NULL; |
| 2657 |
r.in.computer_name = machine_name; |
| 2658 |
r.in.credentials = &credentials1; |
| 2659 |
r.out.return_credentials = &credentials2; |
| 2660 |
|
| 2661 |
netlogon_creds_random_challenge(&credentials1); |
| 2662 |
|
| 2663 |
torture_assert_ntstatus_ok(tctx, dcerpc_netr_ServerReqChallenge_r(b1, tctx, &r), |
| 2664 |
"ServerReqChallenge failed on b1"); |
| 2665 |
torture_assert_ntstatus_ok(tctx, r.out.result, "ServerReqChallenge failed on b1"); |
| 2666 |
|
| 2667 |
E_md4hash(plain_pass, mach_password.hash); |
| 2668 |
|
| 2669 |
a.in.server_name = NULL; |
| 2670 |
a.in.account_name = talloc_asprintf(tctx, "%s$", machine_name); |
| 2671 |
a.in.secure_channel_type = cli_credentials_get_secure_channel_type(machine_credentials); |
| 2672 |
a.in.computer_name = machine_name; |
| 2673 |
a.in.negotiate_flags = &flags; |
| 2674 |
a.in.credentials = &credentials3; |
| 2675 |
a.out.return_credentials = &credentials3; |
| 2676 |
a.out.negotiate_flags = &flags; |
| 2677 |
a.out.rid = &rid; |
| 2678 |
|
| 2679 |
creds = netlogon_creds_client_init(tctx, a.in.account_name, |
| 2680 |
a.in.computer_name, |
| 2681 |
a.in.secure_channel_type, |
| 2682 |
&credentials1, &credentials2, |
| 2683 |
&mach_password, &credentials3, |
| 2684 |
flags, |
| 2685 |
flags); |
| 2686 |
|
| 2687 |
torture_assert(tctx, creds != NULL, "memory allocation"); |
| 2688 |
|
| 2689 |
torture_comment(tctx, "Testing ServerAuthenticate3 on b2\n"); |
| 2690 |
|
| 2691 |
torture_assert_ntstatus_ok(tctx, dcerpc_netr_ServerAuthenticate3_r(b2, tctx, &a), |
| 2692 |
"ServerAuthenticate3 failed on b2"); |
| 2693 |
torture_assert_ntstatus_ok(tctx, a.out.result, "ServerAuthenticate3 failed on b"); |
| 2694 |
torture_assert(tctx, netlogon_creds_client_check(creds, &credentials3), "Credential chaining failed"); |
| 2695 |
|
| 2696 |
/* We have to re-run this part */ |
| 2697 |
creds = netlogon_creds_client_init(tctx, a.in.account_name, |
| 2698 |
a.in.computer_name, |
| 2699 |
a.in.secure_channel_type, |
| 2700 |
&credentials1, &credentials2, |
| 2701 |
&mach_password, &credentials3, |
| 2702 |
flags, |
| 2703 |
flags); |
| 2704 |
|
| 2705 |
torture_assert(tctx, creds != NULL, "memory allocation"); |
| 2706 |
|
| 2707 |
torture_assert_ntstatus_ok(tctx, dcerpc_netr_ServerAuthenticate3_r(b1, tctx, &a), |
| 2708 |
"ServerAuthenticate3 failed on b1"); |
| 2709 |
torture_assert_ntstatus_equal(tctx, a.out.result, NT_STATUS_ACCESS_DENIED, |
| 2710 |
"ServerAuthenticate3 should have failed on b1, due to credential reuse"); |
| 2711 |
return true; |
| 2712 |
} |
| 2713 |
|
| 2714 |
/* |
| 2715 |
* Test if more than one globally cached challenge works |
| 2716 |
*/ |
| 2717 |
static bool test_ServerReqChallengeReuseGlobal4(struct torture_context *tctx, |
| 2718 |
struct dcerpc_pipe *p1, |
| 2719 |
struct cli_credentials *machine_credentials) |
| 2720 |
{ |
| 2721 |
uint32_t flags = NETLOGON_NEG_AUTH2_FLAGS | NETLOGON_NEG_SUPPORTS_AES; |
| 2722 |
struct netr_ServerReqChallenge r; |
| 2723 |
struct netr_ServerAuthenticate3 a; |
| 2724 |
struct netr_Credential credentials1, credentials1_random, |
| 2725 |
credentials2, credentials3, credentials_discard; |
| 2726 |
struct netlogon_creds_CredentialState *creds; |
| 2727 |
struct samr_Password mach_password; |
| 2728 |
uint32_t rid; |
| 2729 |
const char *machine_name; |
| 2730 |
const char *plain_pass; |
| 2731 |
struct dcerpc_binding_handle *b1 = p1->binding_handle; |
| 2732 |
const struct dcerpc_binding *bd1 = dcerpc_binding_handle_get_binding(b1); |
| 2733 |
struct dcerpc_pipe *p2 = NULL; |
| 2734 |
struct dcerpc_binding_handle *b2 = NULL; |
| 2735 |
|
| 2736 |
machine_name = cli_credentials_get_workstation(machine_credentials); |
| 2737 |
torture_assert(tctx, machine_name != NULL, "machine_name"); |
| 2738 |
plain_pass = cli_credentials_get_password(machine_credentials); |
| 2739 |
torture_assert(tctx, plain_pass != NULL, "plain_pass"); |
| 2740 |
|
| 2741 |
torture_comment(tctx, "Testing ServerReqChallenge on b1\n"); |
| 2742 |
|
| 2743 |
torture_assert_ntstatus_ok(tctx, |
| 2744 |
dcerpc_pipe_connect_b(tctx, &p2, bd1, |
| 2745 |
&ndr_table_netlogon, |
| 2746 |
machine_credentials, |
| 2747 |
tctx->ev, tctx->lp_ctx), |
| 2748 |
"dcerpc_pipe_connect_b failed"); |
| 2749 |
b2 = p2->binding_handle; |
| 2750 |
|
| 2751 |
r.in.server_name = NULL; |
| 2752 |
r.in.computer_name = "CHALTEST1"; |
| 2753 |
r.in.credentials = &credentials1_random; |
| 2754 |
r.out.return_credentials = &credentials_discard; |
| 2755 |
|
| 2756 |
netlogon_creds_random_challenge(&credentials1_random); |
| 2757 |
|
| 2758 |
torture_assert_ntstatus_ok(tctx, dcerpc_netr_ServerReqChallenge_r(b1, tctx, &r), |
| 2759 |
"ServerReqChallenge failed on b1"); |
| 2760 |
torture_assert_ntstatus_ok(tctx, r.out.result, "ServerReqChallenge failed on b1"); |
| 2761 |
|
| 2762 |
/* Now ask for the actual client name */ |
| 2763 |
r.in.server_name = NULL; |
| 2764 |
r.in.computer_name = machine_name; |
| 2765 |
r.in.credentials = &credentials1; |
| 2766 |
r.out.return_credentials = &credentials2; |
| 2767 |
|
| 2768 |
netlogon_creds_random_challenge(&credentials1); |
| 2769 |
|
| 2770 |
torture_assert_ntstatus_ok(tctx, dcerpc_netr_ServerReqChallenge_r(b1, tctx, &r), |
| 2771 |
"ServerReqChallenge failed on b1"); |
| 2772 |
torture_assert_ntstatus_ok(tctx, r.out.result, "ServerReqChallenge failed on b1"); |
| 2773 |
|
| 2774 |
r.in.server_name = NULL; |
| 2775 |
r.in.computer_name = "CHALTEST2"; |
| 2776 |
r.in.credentials = &credentials1_random; |
| 2777 |
r.out.return_credentials = &credentials_discard; |
| 2778 |
|
| 2779 |
netlogon_creds_random_challenge(&credentials1_random); |
| 2780 |
|
| 2781 |
torture_assert_ntstatus_ok(tctx, dcerpc_netr_ServerReqChallenge_r(b1, tctx, &r), |
| 2782 |
"ServerReqChallenge failed on b1"); |
| 2783 |
torture_assert_ntstatus_ok(tctx, r.out.result, "ServerReqChallenge failed on b1"); |
| 2784 |
|
| 2785 |
E_md4hash(plain_pass, mach_password.hash); |
| 2786 |
|
| 2787 |
a.in.server_name = NULL; |
| 2788 |
a.in.account_name = talloc_asprintf(tctx, "%s$", machine_name); |
| 2789 |
a.in.secure_channel_type = cli_credentials_get_secure_channel_type(machine_credentials); |
| 2790 |
a.in.computer_name = machine_name; |
| 2791 |
a.in.negotiate_flags = &flags; |
| 2792 |
a.in.credentials = &credentials3; |
| 2793 |
a.out.return_credentials = &credentials3; |
| 2794 |
a.out.negotiate_flags = &flags; |
| 2795 |
a.out.rid = &rid; |
| 2796 |
|
| 2797 |
creds = netlogon_creds_client_init(tctx, a.in.account_name, |
| 2798 |
a.in.computer_name, |
| 2799 |
a.in.secure_channel_type, |
| 2800 |
&credentials1, &credentials2, |
| 2801 |
&mach_password, &credentials3, |
| 2802 |
flags, |
| 2803 |
flags); |
| 2804 |
|
| 2805 |
torture_assert(tctx, creds != NULL, "memory allocation"); |
| 2806 |
|
| 2807 |
torture_comment(tctx, "Testing ServerAuthenticate3 on b2 (must use global credentials)\n"); |
| 2808 |
|
| 2809 |
torture_assert_ntstatus_ok(tctx, dcerpc_netr_ServerAuthenticate3_r(b2, tctx, &a), |
| 2810 |
"ServerAuthenticate3 failed on b2"); |
| 2811 |
torture_assert_ntstatus_ok(tctx, a.out.result, "ServerAuthenticate3 failed on b2"); |
| 2812 |
torture_assert(tctx, netlogon_creds_client_check(creds, &credentials3), "Credential chaining failed"); |
| 2813 |
|
| 2814 |
/* We have to re-run this part */ |
| 2815 |
creds = netlogon_creds_client_init(tctx, a.in.account_name, |
| 2816 |
a.in.computer_name, |
| 2817 |
a.in.secure_channel_type, |
| 2818 |
&credentials1, &credentials2, |
| 2819 |
&mach_password, &credentials3, |
| 2820 |
flags, |
| 2821 |
flags); |
| 2822 |
|
| 2823 |
torture_assert_ntstatus_ok(tctx, dcerpc_netr_ServerAuthenticate3_r(b1, tctx, &a), |
| 2824 |
"ServerAuthenticate3 failed on b1"); |
| 2825 |
torture_assert_ntstatus_equal(tctx, a.out.result, NT_STATUS_ACCESS_DENIED, |
| 2826 |
"ServerAuthenticate3 should have failed on b1, due to credential reuse"); |
| 2827 |
return true; |
| 2828 |
} |
| 2829 |
|
| 2830 |
static bool test_ServerReqChallengeReuse(struct torture_context *tctx, |
| 2831 |
struct dcerpc_pipe *p, |
| 2832 |
struct cli_credentials *machine_credentials) |
| 2833 |
{ |
| 2834 |
uint32_t flags = NETLOGON_NEG_AUTH2_FLAGS | NETLOGON_NEG_SUPPORTS_AES; |
| 2835 |
struct netr_ServerReqChallenge r; |
| 2836 |
struct netr_ServerAuthenticate3 a; |
| 2837 |
struct netr_Credential credentials1, credentials2, credentials3; |
| 2838 |
struct netlogon_creds_CredentialState *creds; |
| 2839 |
struct samr_Password mach_password; |
| 2840 |
uint32_t rid; |
| 2841 |
const char *machine_name; |
| 2842 |
const char *plain_pass; |
| 2843 |
struct dcerpc_binding_handle *b = p->binding_handle; |
| 2844 |
|
| 2845 |
machine_name = cli_credentials_get_workstation(machine_credentials); |
| 2846 |
torture_assert(tctx, machine_name != NULL, "machine_name"); |
| 2847 |
plain_pass = cli_credentials_get_password(machine_credentials); |
| 2848 |
torture_assert(tctx, plain_pass != NULL, "plain_pass"); |
| 2849 |
|
| 2850 |
torture_comment(tctx, "Testing ServerReqChallenge on b1\n"); |
| 2851 |
|
| 2852 |
r.in.server_name = NULL; |
| 2853 |
r.in.computer_name = machine_name; |
| 2854 |
r.in.credentials = &credentials1; |
| 2855 |
r.out.return_credentials = &credentials2; |
| 2856 |
|
| 2857 |
netlogon_creds_random_challenge(&credentials1); |
| 2858 |
|
| 2859 |
torture_assert_ntstatus_ok(tctx, dcerpc_netr_ServerReqChallenge_r(b, tctx, &r), |
| 2860 |
"ServerReqChallenge"); |
| 2861 |
torture_assert_ntstatus_ok(tctx, r.out.result, "ServerReqChallenge failed on b1"); |
| 2862 |
|
| 2863 |
E_md4hash(plain_pass, mach_password.hash); |
| 2864 |
|
| 2865 |
a.in.server_name = NULL; |
| 2866 |
a.in.account_name = talloc_asprintf(tctx, "%s$", machine_name); |
| 2867 |
a.in.secure_channel_type = cli_credentials_get_secure_channel_type(machine_credentials); |
| 2868 |
a.in.computer_name = machine_name; |
| 2869 |
a.in.negotiate_flags = &flags; |
| 2870 |
a.in.credentials = &credentials3; |
| 2871 |
a.out.return_credentials = &credentials3; |
| 2872 |
a.out.negotiate_flags = &flags; |
| 2873 |
a.out.rid = &rid; |
| 2874 |
|
| 2875 |
creds = netlogon_creds_client_init(tctx, a.in.account_name, |
| 2876 |
a.in.computer_name, |
| 2877 |
a.in.secure_channel_type, |
| 2878 |
&credentials1, &credentials2, |
| 2879 |
&mach_password, &credentials3, |
| 2880 |
flags, |
| 2881 |
flags); |
| 2882 |
|
| 2883 |
torture_assert(tctx, creds != NULL, "memory allocation"); |
| 2884 |
|
| 2885 |
torture_comment(tctx, "Testing ServerAuthenticate3\n"); |
| 2886 |
|
| 2887 |
torture_assert_ntstatus_ok(tctx, dcerpc_netr_ServerAuthenticate3_r(b, tctx, &a), |
| 2888 |
"ServerAuthenticate3 failed"); |
| 2889 |
torture_assert_ntstatus_ok(tctx, a.out.result, "ServerAuthenticate3 failed"); |
| 2890 |
torture_assert(tctx, netlogon_creds_client_check(creds, &credentials3), "Credential chaining failed"); |
| 2891 |
|
| 2892 |
/* We have to re-run this part */ |
| 2893 |
creds = netlogon_creds_client_init(tctx, a.in.account_name, |
| 2894 |
a.in.computer_name, |
| 2895 |
a.in.secure_channel_type, |
| 2896 |
&credentials1, &credentials2, |
| 2897 |
&mach_password, &credentials3, |
| 2898 |
flags, |
| 2899 |
flags); |
| 2900 |
|
| 2901 |
torture_assert_ntstatus_ok(tctx, dcerpc_netr_ServerAuthenticate3_r(b, tctx, &a), |
| 2902 |
"ServerAuthenticate3 failed"); |
| 2903 |
torture_assert_ntstatus_equal(tctx, a.out.result, NT_STATUS_ACCESS_DENIED, |
| 2904 |
"ServerAuthenticate3 should have failed on b3, due to credential reuse"); |
| 2905 |
|
| 2906 |
ZERO_STRUCT(credentials1.data); |
| 2907 |
ZERO_STRUCT(credentials2.data); |
| 2908 |
creds = netlogon_creds_client_init(tctx, a.in.account_name, |
| 2909 |
a.in.computer_name, |
| 2910 |
a.in.secure_channel_type, |
| 2911 |
&credentials1, &credentials2, |
| 2912 |
&mach_password, &credentials3, |
| 2913 |
flags, |
| 2914 |
flags); |
| 2915 |
|
| 2916 |
torture_assert(tctx, creds != NULL, "memory allocation"); |
| 2917 |
|
| 2918 |
torture_comment(tctx, "Testing ServerAuthenticate3 with zero'ed challenge\n"); |
| 2919 |
|
| 2920 |
torture_assert_ntstatus_ok(tctx, dcerpc_netr_ServerAuthenticate3_r(b, tctx, &a), |
| 2921 |
"ServerAuthenticate3 failed"); |
| 2922 |
torture_assert_ntstatus_equal(tctx, a.out.result, NT_STATUS_ACCESS_DENIED, |
| 2923 |
"ServerAuthenticate3 should have failed on b3, due to credential reuse"); |
| 2924 |
return true; |
| 2925 |
} |
| 2926 |
|
| 2927 |
static bool test_SamLogon_NULL_domain(struct torture_context *tctx, |
| 2928 |
struct dcerpc_pipe *p, |
| 2929 |
struct cli_credentials *credentials) |
| 2930 |
{ |
| 2931 |
struct netlogon_creds_CredentialState *creds; |
| 2932 |
|
| 2933 |
if (!test_SetupCredentials(p, tctx, credentials, &creds)) { |
| 2934 |
return false; |
| 2935 |
} |
| 2936 |
|
| 2937 |
return test_netlogon_ops_args(p, tctx, credentials, creds, true); |
| 2938 |
} |
| 2939 |
|
| 2940 |
/* we remember the sequence numbers so we can easily do a DatabaseDelta */ |
| 2941 |
static uint64_t sequence_nums[3]; |
| 2942 |
|
| 2943 |
/* |
| 2944 |
try a netlogon DatabaseSync |
| 2945 |
*/ |
| 2946 |
static bool test_DatabaseSync(struct torture_context *tctx, |
| 2947 |
struct dcerpc_pipe *p, |
| 2948 |
struct cli_credentials *machine_credentials) |
| 2949 |
{ |
| 2950 |
struct netr_DatabaseSync r; |
| 2951 |
struct netlogon_creds_CredentialState *creds; |
| 2952 |
const uint32_t database_ids[] = {SAM_DATABASE_DOMAIN, SAM_DATABASE_BUILTIN, SAM_DATABASE_PRIVS}; |
| 2953 |
int i; |
| 2954 |
struct netr_DELTA_ENUM_ARRAY *delta_enum_array = NULL; |
| 2955 |
struct netr_Authenticator credential, return_authenticator; |
| 2956 |
struct dcerpc_binding_handle *b = p->binding_handle; |
| 2957 |
|
| 2958 |
if (!test_SetupCredentials(p, tctx, machine_credentials, &creds)) { |
| 2959 |
return false; |
| 2960 |
} |
| 2961 |
|
| 2962 |
ZERO_STRUCT(return_authenticator); |
| 2963 |
|
| 2964 |
r.in.logon_server = talloc_asprintf(tctx, "\\\\%s", dcerpc_server_name(p)); |
| 2965 |
r.in.computername = TEST_MACHINE_NAME; |
| 2966 |
r.in.preferredmaximumlength = (uint32_t)-1; |
| 2967 |
r.in.return_authenticator = &return_authenticator; |
| 2968 |
r.out.delta_enum_array = &delta_enum_array; |
| 2969 |
r.out.return_authenticator = &return_authenticator; |
| 2970 |
|
| 2971 |
for (i=0;i<ARRAY_SIZE(database_ids);i++) { |
| 2972 |
|
| 2973 |
uint32_t sync_context = 0; |
| 2974 |
|
| 2975 |
r.in.database_id = database_ids[i]; |
| 2976 |
r.in.sync_context = &sync_context; |
| 2977 |
r.out.sync_context = &sync_context; |
| 2978 |
|
| 2979 |
torture_comment(tctx, "Testing DatabaseSync of id %d\n", r.in.database_id); |
| 2980 |
|
| 2981 |
do { |
| 2982 |
netlogon_creds_client_authenticator(creds, &credential); |
| 2983 |
|
| 2984 |
r.in.credential = &credential; |
| 2985 |
|
| 2986 |
torture_assert_ntstatus_ok(tctx, dcerpc_netr_DatabaseSync_r(b, tctx, &r), |
| 2987 |
"DatabaseSync failed"); |
| 2988 |
if (NT_STATUS_EQUAL(r.out.result, STATUS_MORE_ENTRIES)) |
| 2989 |
break; |
| 2990 |
|
| 2991 |
/* Native mode servers don't do this */ |
| 2992 |
if (NT_STATUS_EQUAL(r.out.result, NT_STATUS_NOT_SUPPORTED)) { |
| 2993 |
return true; |
| 2994 |
} |
| 2995 |
torture_assert_ntstatus_ok(tctx, r.out.result, "DatabaseSync"); |
| 2996 |
|
| 2997 |
if (!netlogon_creds_client_check(creds, &r.out.return_authenticator->cred)) { |
| 2998 |
torture_comment(tctx, "Credential chaining failed\n"); |
| 2999 |
} |
| 3000 |
|
| 3001 |
if (delta_enum_array && |
| 3002 |
delta_enum_array->num_deltas > 0 && |
| 3003 |
delta_enum_array->delta_enum[0].delta_type == NETR_DELTA_DOMAIN && |
| 3004 |
delta_enum_array->delta_enum[0].delta_union.domain) { |
| 3005 |
sequence_nums[r.in.database_id] = |
| 3006 |
delta_enum_array->delta_enum[0].delta_union.domain->sequence_num; |
| 3007 |
torture_comment(tctx, "\tsequence_nums[%d]=%llu\n", |
| 3008 |
r.in.database_id, |
| 3009 |
(unsigned long long)sequence_nums[r.in.database_id]); |
| 3010 |
} |
| 3011 |
} while (NT_STATUS_EQUAL(r.out.result, STATUS_MORE_ENTRIES)); |
| 3012 |
} |
| 3013 |
|
| 3014 |
return true; |
| 3015 |
} |
| 3016 |
|
| 3017 |
|
| 3018 |
/* |
| 3019 |
try a netlogon DatabaseDeltas |
| 3020 |
*/ |
| 3021 |
static bool test_DatabaseDeltas(struct torture_context *tctx, |
| 3022 |
struct dcerpc_pipe *p, |
| 3023 |
struct cli_credentials *machine_credentials) |
| 3024 |
{ |
| 3025 |
struct netr_DatabaseDeltas r; |
| 3026 |
struct netlogon_creds_CredentialState *creds; |
| 3027 |
struct netr_Authenticator credential; |
| 3028 |
struct netr_Authenticator return_authenticator; |
| 3029 |
struct netr_DELTA_ENUM_ARRAY *delta_enum_array = NULL; |
| 3030 |
const uint32_t database_ids[] = {0, 1, 2}; |
| 3031 |
int i; |
| 3032 |
struct dcerpc_binding_handle *b = p->binding_handle; |
| 3033 |
|
| 3034 |
if (!test_SetupCredentials(p, tctx, machine_credentials, &creds)) { |
| 3035 |
return false; |
| 3036 |
} |
| 3037 |
|
| 3038 |
r.in.logon_server = talloc_asprintf(tctx, "\\\\%s", dcerpc_server_name(p)); |
| 3039 |
r.in.computername = TEST_MACHINE_NAME; |
| 3040 |
r.in.preferredmaximumlength = (uint32_t)-1; |
| 3041 |
ZERO_STRUCT(r.in.return_authenticator); |
| 3042 |
r.out.return_authenticator = &return_authenticator; |
| 3043 |
r.out.delta_enum_array = &delta_enum_array; |
| 3044 |
|
| 3045 |
for (i=0;i<ARRAY_SIZE(database_ids);i++) { |
| 3046 |
r.in.database_id = database_ids[i]; |
| 3047 |
r.in.sequence_num = &sequence_nums[r.in.database_id]; |
| 3048 |
|
| 3049 |
if (*r.in.sequence_num == 0) continue; |
| 3050 |
|
| 3051 |
*r.in.sequence_num -= 1; |
| 3052 |
|
| 3053 |
torture_comment(tctx, "Testing DatabaseDeltas of id %d at %llu\n", |
| 3054 |
r.in.database_id, (unsigned long long)*r.in.sequence_num); |
| 3055 |
|
| 3056 |
do { |
| 3057 |
netlogon_creds_client_authenticator(creds, &credential); |
| 3058 |
|
| 3059 |
torture_assert_ntstatus_ok(tctx, dcerpc_netr_DatabaseDeltas_r(b, tctx, &r), |
| 3060 |
"DatabaseDeltas failed"); |
| 3061 |
if (NT_STATUS_EQUAL(r.out.result, |
| 3062 |
NT_STATUS_SYNCHRONIZATION_REQUIRED)) { |
| 3063 |
torture_comment(tctx, "not considering %s to be an error\n", |
| 3064 |
nt_errstr(r.out.result)); |
| 3065 |
return true; |
| 3066 |
} |
| 3067 |
if (NT_STATUS_EQUAL(r.out.result, STATUS_MORE_ENTRIES)) |
| 3068 |
break; |
| 3069 |
|
| 3070 |
torture_assert_ntstatus_ok(tctx, r.out.result, "DatabaseDeltas"); |
| 3071 |
|
| 3072 |
if (!netlogon_creds_client_check(creds, &return_authenticator.cred)) { |
| 3073 |
torture_comment(tctx, "Credential chaining failed\n"); |
| 3074 |
} |
| 3075 |
|
| 3076 |
(*r.in.sequence_num)++; |
| 3077 |
} while (NT_STATUS_EQUAL(r.out.result, STATUS_MORE_ENTRIES)); |
| 3078 |
} |
| 3079 |
|
| 3080 |
return true; |
| 3081 |
} |
| 3082 |
|
| 3083 |
static bool test_DatabaseRedo(struct torture_context *tctx, |
| 3084 |
struct dcerpc_pipe *p, |
| 3085 |
struct cli_credentials *machine_credentials) |
| 3086 |
{ |
| 3087 |
struct netr_DatabaseRedo r; |
| 3088 |
struct netlogon_creds_CredentialState *creds; |
| 3089 |
struct netr_Authenticator credential; |
| 3090 |
struct netr_Authenticator return_authenticator; |
| 3091 |
struct netr_DELTA_ENUM_ARRAY *delta_enum_array = NULL; |
| 3092 |
struct netr_ChangeLogEntry e; |
| 3093 |
struct dom_sid null_sid, *sid; |
| 3094 |
int i,d; |
| 3095 |
struct dcerpc_binding_handle *b = p->binding_handle; |
| 3096 |
|
| 3097 |
ZERO_STRUCT(null_sid); |
| 3098 |
|
| 3099 |
sid = dom_sid_parse_talloc(tctx, "S-1-5-21-1111111111-2222222222-333333333-500"); |
| 3100 |
|
| 3101 |
{ |
| 3102 |
|
| 3103 |
struct { |
| 3104 |
uint32_t rid; |
| 3105 |
uint16_t flags; |
| 3106 |
uint8_t db_index; |
| 3107 |
uint8_t delta_type; |
| 3108 |
struct dom_sid sid; |
| 3109 |
const char *name; |
| 3110 |
NTSTATUS expected_error; |
| 3111 |
uint32_t expected_num_results; |
| 3112 |
uint8_t expected_delta_type_1; |
| 3113 |
uint8_t expected_delta_type_2; |
| 3114 |
const char *comment; |
| 3115 |
} changes[] = { |
| 3116 |
|
| 3117 |
/* SAM_DATABASE_DOMAIN */ |
| 3118 |
|
| 3119 |
{ |
| 3120 |
.rid = 0, |
| 3121 |
.flags = 0, |
| 3122 |
.db_index = SAM_DATABASE_DOMAIN, |
| 3123 |
.delta_type = NETR_DELTA_MODIFY_COUNT, |
| 3124 |
.sid = null_sid, |
| 3125 |
.name = NULL, |
| 3126 |
.expected_error = NT_STATUS_SYNCHRONIZATION_REQUIRED, |
| 3127 |
.expected_num_results = 0, |
| 3128 |
.comment = "NETR_DELTA_MODIFY_COUNT" |
| 3129 |
}, |
| 3130 |
{ |
| 3131 |
.rid = 0, |
| 3132 |
.flags = 0, |
| 3133 |
.db_index = SAM_DATABASE_DOMAIN, |
| 3134 |
.delta_type = 0, |
| 3135 |
.sid = null_sid, |
| 3136 |
.name = NULL, |
| 3137 |
.expected_error = NT_STATUS_OK, |
| 3138 |
.expected_num_results = 1, |
| 3139 |
.expected_delta_type_1 = NETR_DELTA_DOMAIN, |
| 3140 |
.comment = "NULL DELTA" |
| 3141 |
}, |
| 3142 |
{ |
| 3143 |
.rid = 0, |
| 3144 |
.flags = 0, |
| 3145 |
.db_index = SAM_DATABASE_DOMAIN, |
| 3146 |
.delta_type = NETR_DELTA_DOMAIN, |
| 3147 |
.sid = null_sid, |
| 3148 |
.name = NULL, |
| 3149 |
.expected_error = NT_STATUS_OK, |
| 3150 |
.expected_num_results = 1, |
| 3151 |
.expected_delta_type_1 = NETR_DELTA_DOMAIN, |
| 3152 |
.comment = "NETR_DELTA_DOMAIN" |
| 3153 |
}, |
| 3154 |
{ |
| 3155 |
.rid = DOMAIN_RID_ADMINISTRATOR, |
| 3156 |
.flags = 0, |
| 3157 |
.db_index = SAM_DATABASE_DOMAIN, |
| 3158 |
.delta_type = NETR_DELTA_USER, |
| 3159 |
.sid = null_sid, |
| 3160 |
.name = NULL, |
| 3161 |
.expected_error = NT_STATUS_OK, |
| 3162 |
.expected_num_results = 1, |
| 3163 |
.expected_delta_type_1 = NETR_DELTA_USER, |
| 3164 |
.comment = "NETR_DELTA_USER by rid 500" |
| 3165 |
}, |
| 3166 |
{ |
| 3167 |
.rid = DOMAIN_RID_GUEST, |
| 3168 |
.flags = 0, |
| 3169 |
.db_index = SAM_DATABASE_DOMAIN, |
| 3170 |
.delta_type = NETR_DELTA_USER, |
| 3171 |
.sid = null_sid, |
| 3172 |
.name = NULL, |
| 3173 |
.expected_error = NT_STATUS_OK, |
| 3174 |
.expected_num_results = 1, |
| 3175 |
.expected_delta_type_1 = NETR_DELTA_USER, |
| 3176 |
.comment = "NETR_DELTA_USER by rid 501" |
| 3177 |
}, |
| 3178 |
{ |
| 3179 |
.rid = 0, |
| 3180 |
.flags = NETR_CHANGELOG_SID_INCLUDED, |
| 3181 |
.db_index = SAM_DATABASE_DOMAIN, |
| 3182 |
.delta_type = NETR_DELTA_USER, |
| 3183 |
.sid = *sid, |
| 3184 |
.name = NULL, |
| 3185 |
.expected_error = NT_STATUS_OK, |
| 3186 |
.expected_num_results = 1, |
| 3187 |
.expected_delta_type_1 = NETR_DELTA_DELETE_USER, |
| 3188 |
.comment = "NETR_DELTA_USER by sid and flags" |
| 3189 |
}, |
| 3190 |
{ |
| 3191 |
.rid = 0, |
| 3192 |
.flags = NETR_CHANGELOG_SID_INCLUDED, |
| 3193 |
.db_index = SAM_DATABASE_DOMAIN, |
| 3194 |
.delta_type = NETR_DELTA_USER, |
| 3195 |
.sid = null_sid, |
| 3196 |
.name = NULL, |
| 3197 |
.expected_error = NT_STATUS_OK, |
| 3198 |
.expected_num_results = 1, |
| 3199 |
.expected_delta_type_1 = NETR_DELTA_DELETE_USER, |
| 3200 |
.comment = "NETR_DELTA_USER by null_sid and flags" |
| 3201 |
}, |
| 3202 |
{ |
| 3203 |
.rid = 0, |
| 3204 |
.flags = NETR_CHANGELOG_NAME_INCLUDED, |
| 3205 |
.db_index = SAM_DATABASE_DOMAIN, |
| 3206 |
.delta_type = NETR_DELTA_USER, |
| 3207 |
.sid = null_sid, |
| 3208 |
.name = "administrator", |
| 3209 |
.expected_error = NT_STATUS_OK, |
| 3210 |
.expected_num_results = 1, |
| 3211 |
.expected_delta_type_1 = NETR_DELTA_DELETE_USER, |
| 3212 |
.comment = "NETR_DELTA_USER by name 'administrator'" |
| 3213 |
}, |
| 3214 |
{ |
| 3215 |
.rid = DOMAIN_RID_ADMINS, |
| 3216 |
.flags = 0, |
| 3217 |
.db_index = SAM_DATABASE_DOMAIN, |
| 3218 |
.delta_type = NETR_DELTA_GROUP, |
| 3219 |
.sid = null_sid, |
| 3220 |
.name = NULL, |
| 3221 |
.expected_error = NT_STATUS_OK, |
| 3222 |
.expected_num_results = 2, |
| 3223 |
.expected_delta_type_1 = NETR_DELTA_GROUP, |
| 3224 |
.expected_delta_type_2 = NETR_DELTA_GROUP_MEMBER, |
| 3225 |
.comment = "NETR_DELTA_GROUP by rid 512" |
| 3226 |
}, |
| 3227 |
{ |
| 3228 |
.rid = DOMAIN_RID_ADMINS, |
| 3229 |
.flags = 0, |
| 3230 |
.db_index = SAM_DATABASE_DOMAIN, |
| 3231 |
.delta_type = NETR_DELTA_GROUP_MEMBER, |
| 3232 |
.sid = null_sid, |
| 3233 |
.name = NULL, |
| 3234 |
.expected_error = NT_STATUS_OK, |
| 3235 |
.expected_num_results = 2, |
| 3236 |
.expected_delta_type_1 = NETR_DELTA_GROUP, |
| 3237 |
.expected_delta_type_2 = NETR_DELTA_GROUP_MEMBER, |
| 3238 |
.comment = "NETR_DELTA_GROUP_MEMBER by rid 512" |
| 3239 |
}, |
| 3240 |
|
| 3241 |
|
| 3242 |
/* SAM_DATABASE_BUILTIN */ |
| 3243 |
|
| 3244 |
{ |
| 3245 |
.rid = 0, |
| 3246 |
.flags = 0, |
| 3247 |
.db_index = SAM_DATABASE_BUILTIN, |
| 3248 |
.delta_type = NETR_DELTA_MODIFY_COUNT, |
| 3249 |
.sid = null_sid, |
| 3250 |
.name = NULL, |
| 3251 |
.expected_error = NT_STATUS_SYNCHRONIZATION_REQUIRED, |
| 3252 |
.expected_num_results = 0, |
| 3253 |
.comment = "NETR_DELTA_MODIFY_COUNT" |
| 3254 |
}, |
| 3255 |
{ |
| 3256 |
.rid = 0, |
| 3257 |
.flags = 0, |
| 3258 |
.db_index = SAM_DATABASE_BUILTIN, |
| 3259 |
.delta_type = NETR_DELTA_DOMAIN, |
| 3260 |
.sid = null_sid, |
| 3261 |
.name = NULL, |
| 3262 |
.expected_error = NT_STATUS_OK, |
| 3263 |
.expected_num_results = 1, |
| 3264 |
.expected_delta_type_1 = NETR_DELTA_DOMAIN, |
| 3265 |
.comment = "NETR_DELTA_DOMAIN" |
| 3266 |
}, |
| 3267 |
{ |
| 3268 |
.rid = DOMAIN_RID_ADMINISTRATOR, |
| 3269 |
.flags = 0, |
| 3270 |
.db_index = SAM_DATABASE_BUILTIN, |
| 3271 |
.delta_type = NETR_DELTA_USER, |
| 3272 |
.sid = null_sid, |
| 3273 |
.name = NULL, |
| 3274 |
.expected_error = NT_STATUS_OK, |
| 3275 |
.expected_num_results = 1, |
| 3276 |
.expected_delta_type_1 = NETR_DELTA_DELETE_USER, |
| 3277 |
.comment = "NETR_DELTA_USER by rid 500" |
| 3278 |
}, |
| 3279 |
{ |
| 3280 |
.rid = 0, |
| 3281 |
.flags = 0, |
| 3282 |
.db_index = SAM_DATABASE_BUILTIN, |
| 3283 |
.delta_type = NETR_DELTA_USER, |
| 3284 |
.sid = null_sid, |
| 3285 |
.name = NULL, |
| 3286 |
.expected_error = NT_STATUS_OK, |
| 3287 |
.expected_num_results = 1, |
| 3288 |
.expected_delta_type_1 = NETR_DELTA_DELETE_USER, |
| 3289 |
.comment = "NETR_DELTA_USER" |
| 3290 |
}, |
| 3291 |
{ |
| 3292 |
.rid = 544, |
| 3293 |
.flags = 0, |
| 3294 |
.db_index = SAM_DATABASE_BUILTIN, |
| 3295 |
.delta_type = NETR_DELTA_ALIAS, |
| 3296 |
.sid = null_sid, |
| 3297 |
.name = NULL, |
| 3298 |
.expected_error = NT_STATUS_OK, |
| 3299 |
.expected_num_results = 2, |
| 3300 |
.expected_delta_type_1 = NETR_DELTA_ALIAS, |
| 3301 |
.expected_delta_type_2 = NETR_DELTA_ALIAS_MEMBER, |
| 3302 |
.comment = "NETR_DELTA_ALIAS by rid 544" |
| 3303 |
}, |
| 3304 |
{ |
| 3305 |
.rid = 544, |
| 3306 |
.flags = 0, |
| 3307 |
.db_index = SAM_DATABASE_BUILTIN, |
| 3308 |
.delta_type = NETR_DELTA_ALIAS_MEMBER, |
| 3309 |
.sid = null_sid, |
| 3310 |
.name = NULL, |
| 3311 |
.expected_error = NT_STATUS_OK, |
| 3312 |
.expected_num_results = 2, |
| 3313 |
.expected_delta_type_1 = NETR_DELTA_ALIAS, |
| 3314 |
.expected_delta_type_2 = NETR_DELTA_ALIAS_MEMBER, |
| 3315 |
.comment = "NETR_DELTA_ALIAS_MEMBER by rid 544" |
| 3316 |
}, |
| 3317 |
{ |
| 3318 |
.rid = 544, |
| 3319 |
.flags = 0, |
| 3320 |
.db_index = SAM_DATABASE_BUILTIN, |
| 3321 |
.delta_type = 0, |
| 3322 |
.sid = null_sid, |
| 3323 |
.name = NULL, |
| 3324 |
.expected_error = NT_STATUS_OK, |
| 3325 |
.expected_num_results = 1, |
| 3326 |
.expected_delta_type_1 = NETR_DELTA_DOMAIN, |
| 3327 |
.comment = "NULL DELTA by rid 544" |
| 3328 |
}, |
| 3329 |
{ |
| 3330 |
.rid = 544, |
| 3331 |
.flags = NETR_CHANGELOG_SID_INCLUDED, |
| 3332 |
.db_index = SAM_DATABASE_BUILTIN, |
| 3333 |
.delta_type = 0, |
| 3334 |
.sid = *dom_sid_parse_talloc(tctx, "S-1-5-32-544"), |
| 3335 |
.name = NULL, |
| 3336 |
.expected_error = NT_STATUS_OK, |
| 3337 |
.expected_num_results = 1, |
| 3338 |
.expected_delta_type_1 = NETR_DELTA_DOMAIN, |
| 3339 |
.comment = "NULL DELTA by rid 544 sid S-1-5-32-544 and flags" |
| 3340 |
}, |
| 3341 |
{ |
| 3342 |
.rid = 544, |
| 3343 |
.flags = NETR_CHANGELOG_SID_INCLUDED, |
| 3344 |
.db_index = SAM_DATABASE_BUILTIN, |
| 3345 |
.delta_type = NETR_DELTA_ALIAS, |
| 3346 |
.sid = *dom_sid_parse_talloc(tctx, "S-1-5-32-544"), |
| 3347 |
.name = NULL, |
| 3348 |
.expected_error = NT_STATUS_OK, |
| 3349 |
.expected_num_results = 2, |
| 3350 |
.expected_delta_type_1 = NETR_DELTA_ALIAS, |
| 3351 |
.expected_delta_type_2 = NETR_DELTA_ALIAS_MEMBER, |
| 3352 |
.comment = "NETR_DELTA_ALIAS by rid 544 and sid S-1-5-32-544 and flags" |
| 3353 |
}, |
| 3354 |
{ |
| 3355 |
.rid = 0, |
| 3356 |
.flags = NETR_CHANGELOG_SID_INCLUDED, |
| 3357 |
.db_index = SAM_DATABASE_BUILTIN, |
| 3358 |
.delta_type = NETR_DELTA_ALIAS, |
| 3359 |
.sid = *dom_sid_parse_talloc(tctx, "S-1-5-32-544"), |
| 3360 |
.name = NULL, |
| 3361 |
.expected_error = NT_STATUS_OK, |
| 3362 |
.expected_num_results = 1, |
| 3363 |
.expected_delta_type_1 = NETR_DELTA_DELETE_ALIAS, |
| 3364 |
.comment = "NETR_DELTA_ALIAS by sid S-1-5-32-544 and flags" |
| 3365 |
}, |
| 3366 |
|
| 3367 |
/* SAM_DATABASE_PRIVS */ |
| 3368 |
|
| 3369 |
{ |
| 3370 |
.rid = 0, |
| 3371 |
.flags = 0, |
| 3372 |
.db_index = SAM_DATABASE_PRIVS, |
| 3373 |
.delta_type = 0, |
| 3374 |
.sid = null_sid, |
| 3375 |
.name = NULL, |
| 3376 |
.expected_error = NT_STATUS_ACCESS_DENIED, |
| 3377 |
.expected_num_results = 0, |
| 3378 |
.comment = "NULL DELTA" |
| 3379 |
}, |
| 3380 |
{ |
| 3381 |
.rid = 0, |
| 3382 |
.flags = 0, |
| 3383 |
.db_index = SAM_DATABASE_PRIVS, |
| 3384 |
.delta_type = NETR_DELTA_MODIFY_COUNT, |
| 3385 |
.sid = null_sid, |
| 3386 |
.name = NULL, |
| 3387 |
.expected_error = NT_STATUS_SYNCHRONIZATION_REQUIRED, |
| 3388 |
.expected_num_results = 0, |
| 3389 |
.comment = "NETR_DELTA_MODIFY_COUNT" |
| 3390 |
}, |
| 3391 |
{ |
| 3392 |
.rid = 0, |
| 3393 |
.flags = 0, |
| 3394 |
.db_index = SAM_DATABASE_PRIVS, |
| 3395 |
.delta_type = NETR_DELTA_POLICY, |
| 3396 |
.sid = null_sid, |
| 3397 |
.name = NULL, |
| 3398 |
.expected_error = NT_STATUS_OK, |
| 3399 |
.expected_num_results = 1, |
| 3400 |
.expected_delta_type_1 = NETR_DELTA_POLICY, |
| 3401 |
.comment = "NETR_DELTA_POLICY" |
| 3402 |
}, |
| 3403 |
{ |
| 3404 |
.rid = 0, |
| 3405 |
.flags = NETR_CHANGELOG_SID_INCLUDED, |
| 3406 |
.db_index = SAM_DATABASE_PRIVS, |
| 3407 |
.delta_type = NETR_DELTA_POLICY, |
| 3408 |
.sid = null_sid, |
| 3409 |
.name = NULL, |
| 3410 |
.expected_error = NT_STATUS_OK, |
| 3411 |
.expected_num_results = 1, |
| 3412 |
.expected_delta_type_1 = NETR_DELTA_POLICY, |
| 3413 |
.comment = "NETR_DELTA_POLICY by null sid and flags" |
| 3414 |
}, |
| 3415 |
{ |
| 3416 |
.rid = 0, |
| 3417 |
.flags = NETR_CHANGELOG_SID_INCLUDED, |
| 3418 |
.db_index = SAM_DATABASE_PRIVS, |
| 3419 |
.delta_type = NETR_DELTA_POLICY, |
| 3420 |
.sid = *dom_sid_parse_talloc(tctx, "S-1-5-32"), |
| 3421 |
.name = NULL, |
| 3422 |
.expected_error = NT_STATUS_OK, |
| 3423 |
.expected_num_results = 1, |
| 3424 |
.expected_delta_type_1 = NETR_DELTA_POLICY, |
| 3425 |
.comment = "NETR_DELTA_POLICY by sid S-1-5-32 and flags" |
| 3426 |
}, |
| 3427 |
{ |
| 3428 |
.rid = DOMAIN_RID_ADMINISTRATOR, |
| 3429 |
.flags = 0, |
| 3430 |
.db_index = SAM_DATABASE_PRIVS, |
| 3431 |
.delta_type = NETR_DELTA_ACCOUNT, |
| 3432 |
.sid = null_sid, |
| 3433 |
.name = NULL, |
| 3434 |
.expected_error = NT_STATUS_SYNCHRONIZATION_REQUIRED, /* strange */ |
| 3435 |
.expected_num_results = 0, |
| 3436 |
.comment = "NETR_DELTA_ACCOUNT by rid 500" |
| 3437 |
}, |
| 3438 |
{ |
| 3439 |
.rid = 0, |
| 3440 |
.flags = NETR_CHANGELOG_SID_INCLUDED, |
| 3441 |
.db_index = SAM_DATABASE_PRIVS, |
| 3442 |
.delta_type = NETR_DELTA_ACCOUNT, |
| 3443 |
.sid = *dom_sid_parse_talloc(tctx, "S-1-1-0"), |
| 3444 |
.name = NULL, |
| 3445 |
.expected_error = NT_STATUS_OK, |
| 3446 |
.expected_num_results = 1, |
| 3447 |
.expected_delta_type_1 = NETR_DELTA_ACCOUNT, |
| 3448 |
.comment = "NETR_DELTA_ACCOUNT by sid S-1-1-0 and flags" |
| 3449 |
}, |
| 3450 |
{ |
| 3451 |
.rid = 0, |
| 3452 |
.flags = NETR_CHANGELOG_SID_INCLUDED | |
| 3453 |
NETR_CHANGELOG_IMMEDIATE_REPL_REQUIRED, |
| 3454 |
.db_index = SAM_DATABASE_PRIVS, |
| 3455 |
.delta_type = NETR_DELTA_ACCOUNT, |
| 3456 |
.sid = *dom_sid_parse_talloc(tctx, "S-1-1-0"), |
| 3457 |
.name = NULL, |
| 3458 |
.expected_error = NT_STATUS_OK, |
| 3459 |
.expected_num_results = 1, |
| 3460 |
.expected_delta_type_1 = NETR_DELTA_ACCOUNT, |
| 3461 |
.comment = "NETR_DELTA_ACCOUNT by sid S-1-1-0 and 2 flags" |
| 3462 |
}, |
| 3463 |
{ |
| 3464 |
.rid = 0, |
| 3465 |
.flags = NETR_CHANGELOG_SID_INCLUDED | |
| 3466 |
NETR_CHANGELOG_NAME_INCLUDED, |
| 3467 |
.db_index = SAM_DATABASE_PRIVS, |
| 3468 |
.delta_type = NETR_DELTA_ACCOUNT, |
| 3469 |
.sid = *dom_sid_parse_talloc(tctx, "S-1-1-0"), |
| 3470 |
.name = NULL, |
| 3471 |
.expected_error = NT_STATUS_INVALID_PARAMETER, |
| 3472 |
.expected_num_results = 0, |
| 3473 |
.comment = "NETR_DELTA_ACCOUNT by sid S-1-1-0 and invalid flags" |
| 3474 |
}, |
| 3475 |
{ |
| 3476 |
.rid = DOMAIN_RID_ADMINISTRATOR, |
| 3477 |
.flags = NETR_CHANGELOG_SID_INCLUDED, |
| 3478 |
.db_index = SAM_DATABASE_PRIVS, |
| 3479 |
.delta_type = NETR_DELTA_ACCOUNT, |
| 3480 |
.sid = *sid, |
| 3481 |
.name = NULL, |
| 3482 |
.expected_error = NT_STATUS_OK, |
| 3483 |
.expected_num_results = 1, |
| 3484 |
.expected_delta_type_1 = NETR_DELTA_DELETE_ACCOUNT, |
| 3485 |
.comment = "NETR_DELTA_ACCOUNT by rid 500, sid and flags" |
| 3486 |
}, |
| 3487 |
{ |
| 3488 |
.rid = 0, |
| 3489 |
.flags = NETR_CHANGELOG_NAME_INCLUDED, |
| 3490 |
.db_index = SAM_DATABASE_PRIVS, |
| 3491 |
.delta_type = NETR_DELTA_SECRET, |
| 3492 |
.sid = null_sid, |
| 3493 |
.name = "IsurelydontexistIhope", |
| 3494 |
.expected_error = NT_STATUS_OK, |
| 3495 |
.expected_num_results = 1, |
| 3496 |
.expected_delta_type_1 = NETR_DELTA_DELETE_SECRET, |
| 3497 |
.comment = "NETR_DELTA_SECRET by name 'IsurelydontexistIhope' and flags" |
| 3498 |
}, |
| 3499 |
{ |
| 3500 |
.rid = 0, |
| 3501 |
.flags = NETR_CHANGELOG_NAME_INCLUDED, |
| 3502 |
.db_index = SAM_DATABASE_PRIVS, |
| 3503 |
.delta_type = NETR_DELTA_SECRET, |
| 3504 |
.sid = null_sid, |
| 3505 |
.name = "G$BCKUPKEY_P", |
| 3506 |
.expected_error = NT_STATUS_OK, |
| 3507 |
.expected_num_results = 1, |
| 3508 |
.expected_delta_type_1 = NETR_DELTA_SECRET, |
| 3509 |
.comment = "NETR_DELTA_SECRET by name 'G$BCKUPKEY_P' and flags" |
| 3510 |
} |
| 3511 |
}; |
| 3512 |
|
| 3513 |
ZERO_STRUCT(return_authenticator); |
| 3514 |
|
| 3515 |
r.in.logon_server = talloc_asprintf(tctx, "\\\\%s", dcerpc_server_name(p)); |
| 3516 |
r.in.computername = TEST_MACHINE_NAME; |
| 3517 |
r.in.return_authenticator = &return_authenticator; |
| 3518 |
r.out.return_authenticator = &return_authenticator; |
| 3519 |
r.out.delta_enum_array = &delta_enum_array; |
| 3520 |
|
| 3521 |
for (d=0; d<3; d++) { |
| 3522 |
const char *database = NULL; |
| 3523 |
|
| 3524 |
switch (d) { |
| 3525 |
case 0: |
| 3526 |
database = "SAM"; |
| 3527 |
break; |
| 3528 |
case 1: |
| 3529 |
database = "BUILTIN"; |
| 3530 |
break; |
| 3531 |
case 2: |
| 3532 |
database = "LSA"; |
| 3533 |
break; |
| 3534 |
default: |
| 3535 |
break; |
| 3536 |
} |
| 3537 |
|
| 3538 |
torture_comment(tctx, "Testing DatabaseRedo\n"); |
| 3539 |
|
| 3540 |
if (!test_SetupCredentials(p, tctx, machine_credentials, &creds)) { |
| 3541 |
return false; |
| 3542 |
} |
| 3543 |
|
| 3544 |
for (i=0;i<ARRAY_SIZE(changes);i++) { |
| 3545 |
|
| 3546 |
if (d != changes[i].db_index) { |
| 3547 |
continue; |
| 3548 |
} |
| 3549 |
|
| 3550 |
netlogon_creds_client_authenticator(creds, &credential); |
| 3551 |
|
| 3552 |
r.in.credential = &credential; |
| 3553 |
|
| 3554 |
e.serial_number1 = 0; |
| 3555 |
e.serial_number2 = 0; |
| 3556 |
e.object_rid = changes[i].rid; |
| 3557 |
e.flags = changes[i].flags; |
| 3558 |
e.db_index = changes[i].db_index; |
| 3559 |
e.delta_type = changes[i].delta_type; |
| 3560 |
|
| 3561 |
switch (changes[i].flags & (NETR_CHANGELOG_NAME_INCLUDED | NETR_CHANGELOG_SID_INCLUDED)) { |
| 3562 |
case NETR_CHANGELOG_SID_INCLUDED: |
| 3563 |
e.object.object_sid = changes[i].sid; |
| 3564 |
break; |
| 3565 |
case NETR_CHANGELOG_NAME_INCLUDED: |
| 3566 |
e.object.object_name = changes[i].name; |
| 3567 |
break; |
| 3568 |
default: |
| 3569 |
break; |
| 3570 |
} |
| 3571 |
|
| 3572 |
r.in.change_log_entry = e; |
| 3573 |
|
| 3574 |
torture_comment(tctx, "Testing DatabaseRedo with database %s and %s\n", |
| 3575 |
database, changes[i].comment); |
| 3576 |
|
| 3577 |
torture_assert_ntstatus_ok(tctx, dcerpc_netr_DatabaseRedo_r(b, tctx, &r), |
| 3578 |
"DatabaseRedo failed"); |
| 3579 |
if (NT_STATUS_EQUAL(r.out.result, NT_STATUS_NOT_SUPPORTED)) { |
| 3580 |
return true; |
| 3581 |
} |
| 3582 |
|
| 3583 |
torture_assert_ntstatus_equal(tctx, r.out.result, changes[i].expected_error, changes[i].comment); |
| 3584 |
if (delta_enum_array) { |
| 3585 |
torture_assert_int_equal(tctx, |
| 3586 |
delta_enum_array->num_deltas, |
| 3587 |
changes[i].expected_num_results, |
| 3588 |
changes[i].comment); |
| 3589 |
if (delta_enum_array->num_deltas > 0) { |
| 3590 |
torture_assert_int_equal(tctx, |
| 3591 |
delta_enum_array->delta_enum[0].delta_type, |
| 3592 |
changes[i].expected_delta_type_1, |
| 3593 |
changes[i].comment); |
| 3594 |
} |
| 3595 |
if (delta_enum_array->num_deltas > 1) { |
| 3596 |
torture_assert_int_equal(tctx, |
| 3597 |
delta_enum_array->delta_enum[1].delta_type, |
| 3598 |
changes[i].expected_delta_type_2, |
| 3599 |
changes[i].comment); |
| 3600 |
} |
| 3601 |
} |
| 3602 |
|
| 3603 |
if (!netlogon_creds_client_check(creds, &return_authenticator.cred)) { |
| 3604 |
torture_comment(tctx, "Credential chaining failed\n"); |
| 3605 |
if (!test_SetupCredentials(p, tctx, machine_credentials, &creds)) { |
| 3606 |
return false; |
| 3607 |
} |
| 3608 |
} |
| 3609 |
} |
| 3610 |
} |
| 3611 |
} |
| 3612 |
|
| 3613 |
return true; |
| 3614 |
} |
| 3615 |
|
| 3616 |
/* |
| 3617 |
try a netlogon AccountDeltas |
| 3618 |
*/ |
| 3619 |
static bool test_AccountDeltas(struct torture_context *tctx, |
| 3620 |
struct dcerpc_pipe *p, |
| 3621 |
struct cli_credentials *machine_credentials) |
| 3622 |
{ |
| 3623 |
struct netr_AccountDeltas r; |
| 3624 |
struct netlogon_creds_CredentialState *creds; |
| 3625 |
|
| 3626 |
struct netr_AccountBuffer buffer; |
| 3627 |
uint32_t count_returned = 0; |
| 3628 |
uint32_t total_entries = 0; |
| 3629 |
struct netr_UAS_INFO_0 recordid; |
| 3630 |
struct netr_Authenticator return_authenticator; |
| 3631 |
struct dcerpc_binding_handle *b = p->binding_handle; |
| 3632 |
|
| 3633 |
if (!test_SetupCredentials(p, tctx, machine_credentials, &creds)) { |
| 3634 |
return false; |
| 3635 |
} |
| 3636 |
|
| 3637 |
ZERO_STRUCT(return_authenticator); |
| 3638 |
|
| 3639 |
r.in.logon_server = talloc_asprintf(tctx, "\\\\%s", dcerpc_server_name(p)); |
| 3640 |
r.in.computername = TEST_MACHINE_NAME; |
| 3641 |
r.in.return_authenticator = &return_authenticator; |
| 3642 |
netlogon_creds_client_authenticator(creds, &r.in.credential); |
| 3643 |
ZERO_STRUCT(r.in.uas); |
| 3644 |
r.in.count=10; |
| 3645 |
r.in.level=0; |
| 3646 |
r.in.buffersize=100; |
| 3647 |
r.out.buffer = &buffer; |
| 3648 |
r.out.count_returned = &count_returned; |
| 3649 |
r.out.total_entries = &total_entries; |
| 3650 |
r.out.recordid = &recordid; |
| 3651 |
r.out.return_authenticator = &return_authenticator; |
| 3652 |
|
| 3653 |
/* w2k3 returns "NOT IMPLEMENTED" for this call */ |
| 3654 |
torture_assert_ntstatus_ok(tctx, dcerpc_netr_AccountDeltas_r(b, tctx, &r), |
| 3655 |
"AccountDeltas failed"); |
| 3656 |
torture_assert_ntstatus_equal(tctx, r.out.result, NT_STATUS_NOT_IMPLEMENTED, "AccountDeltas"); |
| 3657 |
|
| 3658 |
return true; |
| 3659 |
} |
| 3660 |
|
| 3661 |
/* |
| 3662 |
try a netlogon AccountSync |
| 3663 |
*/ |
| 3664 |
static bool test_AccountSync(struct torture_context *tctx, struct dcerpc_pipe *p, |
| 3665 |
struct cli_credentials *machine_credentials) |
| 3666 |
{ |
| 3667 |
struct netr_AccountSync r; |
| 3668 |
struct netlogon_creds_CredentialState *creds; |
| 3669 |
|
| 3670 |
struct netr_AccountBuffer buffer; |
| 3671 |
uint32_t count_returned = 0; |
| 3672 |
uint32_t total_entries = 0; |
| 3673 |
uint32_t next_reference = 0; |
| 3674 |
struct netr_UAS_INFO_0 recordid; |
| 3675 |
struct netr_Authenticator return_authenticator; |
| 3676 |
struct dcerpc_binding_handle *b = p->binding_handle; |
| 3677 |
|
| 3678 |
ZERO_STRUCT(recordid); |
| 3679 |
ZERO_STRUCT(return_authenticator); |
| 3680 |
|
| 3681 |
if (!test_SetupCredentials(p, tctx, machine_credentials, &creds)) { |
| 3682 |
return false; |
| 3683 |
} |
| 3684 |
|
| 3685 |
r.in.logon_server = talloc_asprintf(tctx, "\\\\%s", dcerpc_server_name(p)); |
| 3686 |
r.in.computername = TEST_MACHINE_NAME; |
| 3687 |
r.in.return_authenticator = &return_authenticator; |
| 3688 |
netlogon_creds_client_authenticator(creds, &r.in.credential); |
| 3689 |
r.in.recordid = &recordid; |
| 3690 |
r.in.reference=0; |
| 3691 |
r.in.level=0; |
| 3692 |
r.in.buffersize=100; |
| 3693 |
r.out.buffer = &buffer; |
| 3694 |
r.out.count_returned = &count_returned; |
| 3695 |
r.out.total_entries = &total_entries; |
| 3696 |
r.out.next_reference = &next_reference; |
| 3697 |
r.out.recordid = &recordid; |
| 3698 |
r.out.return_authenticator = &return_authenticator; |
| 3699 |
|
| 3700 |
/* w2k3 returns "NOT IMPLEMENTED" for this call */ |
| 3701 |
torture_assert_ntstatus_ok(tctx, dcerpc_netr_AccountSync_r(b, tctx, &r), |
| 3702 |
"AccountSync failed"); |
| 3703 |
torture_assert_ntstatus_equal(tctx, r.out.result, NT_STATUS_NOT_IMPLEMENTED, "AccountSync"); |
| 3704 |
|
| 3705 |
return true; |
| 3706 |
} |
| 3707 |
|
| 3708 |
/* |
| 3709 |
try a netlogon GetDcName |
| 3710 |
*/ |
| 3711 |
static bool test_GetDcName(struct torture_context *tctx, |
| 3712 |
struct dcerpc_pipe *p) |
| 3713 |
{ |
| 3714 |
struct netr_GetDcName r; |
| 3715 |
const char *dcname = NULL; |
| 3716 |
struct dcerpc_binding_handle *b = p->binding_handle; |
| 3717 |
|
| 3718 |
r.in.logon_server = talloc_asprintf(tctx, "\\\\%s", dcerpc_server_name(p)); |
| 3719 |
r.in.domainname = lpcfg_workgroup(tctx->lp_ctx); |
| 3720 |
r.out.dcname = &dcname; |
| 3721 |
|
| 3722 |
torture_assert_ntstatus_ok(tctx, dcerpc_netr_GetDcName_r(b, tctx, &r), |
| 3723 |
"GetDcName failed"); |
| 3724 |
torture_assert_werr_ok(tctx, r.out.result, "GetDcName failed"); |
| 3725 |
|
| 3726 |
torture_comment(tctx, "\tDC is at '%s'\n", dcname); |
| 3727 |
|
| 3728 |
return true; |
| 3729 |
} |
| 3730 |
|
| 3731 |
static const char *function_code_str(TALLOC_CTX *mem_ctx, |
| 3732 |
enum netr_LogonControlCode function_code) |
| 3733 |
{ |
| 3734 |
switch (function_code) { |
| 3735 |
case NETLOGON_CONTROL_QUERY: |
| 3736 |
return "NETLOGON_CONTROL_QUERY"; |
| 3737 |
case NETLOGON_CONTROL_REPLICATE: |
| 3738 |
return "NETLOGON_CONTROL_REPLICATE"; |
| 3739 |
case NETLOGON_CONTROL_SYNCHRONIZE: |
| 3740 |
return "NETLOGON_CONTROL_SYNCHRONIZE"; |
| 3741 |
case NETLOGON_CONTROL_PDC_REPLICATE: |
| 3742 |
return "NETLOGON_CONTROL_PDC_REPLICATE"; |
| 3743 |
case NETLOGON_CONTROL_REDISCOVER: |
| 3744 |
return "NETLOGON_CONTROL_REDISCOVER"; |
| 3745 |
case NETLOGON_CONTROL_TC_QUERY: |
| 3746 |
return "NETLOGON_CONTROL_TC_QUERY"; |
| 3747 |
case NETLOGON_CONTROL_TRANSPORT_NOTIFY: |
| 3748 |
return "NETLOGON_CONTROL_TRANSPORT_NOTIFY"; |
| 3749 |
case NETLOGON_CONTROL_FIND_USER: |
| 3750 |
return "NETLOGON_CONTROL_FIND_USER"; |
| 3751 |
case NETLOGON_CONTROL_CHANGE_PASSWORD: |
| 3752 |
return "NETLOGON_CONTROL_CHANGE_PASSWORD"; |
| 3753 |
case NETLOGON_CONTROL_TC_VERIFY: |
| 3754 |
return "NETLOGON_CONTROL_TC_VERIFY"; |
| 3755 |
case NETLOGON_CONTROL_FORCE_DNS_REG: |
| 3756 |
return "NETLOGON_CONTROL_FORCE_DNS_REG"; |
| 3757 |
case NETLOGON_CONTROL_QUERY_DNS_REG: |
| 3758 |
return "NETLOGON_CONTROL_QUERY_DNS_REG"; |
| 3759 |
case NETLOGON_CONTROL_BACKUP_CHANGE_LOG: |
| 3760 |
return "NETLOGON_CONTROL_BACKUP_CHANGE_LOG"; |
| 3761 |
case NETLOGON_CONTROL_TRUNCATE_LOG: |
| 3762 |
return "NETLOGON_CONTROL_TRUNCATE_LOG"; |
| 3763 |
case NETLOGON_CONTROL_SET_DBFLAG: |
| 3764 |
return "NETLOGON_CONTROL_SET_DBFLAG"; |
| 3765 |
case NETLOGON_CONTROL_BREAKPOINT: |
| 3766 |
return "NETLOGON_CONTROL_BREAKPOINT"; |
| 3767 |
default: |
| 3768 |
return talloc_asprintf(mem_ctx, "unknown function code: %d", |
| 3769 |
function_code); |
| 3770 |
} |
| 3771 |
} |
| 3772 |
|
| 3773 |
|
| 3774 |
/* |
| 3775 |
try a netlogon LogonControl |
| 3776 |
*/ |
| 3777 |
static bool test_LogonControl(struct torture_context *tctx, |
| 3778 |
struct dcerpc_pipe *p, |
| 3779 |
struct cli_credentials *machine_credentials) |
| 3780 |
|
| 3781 |
{ |
| 3782 |
NTSTATUS status; |
| 3783 |
struct netr_LogonControl r; |
| 3784 |
union netr_CONTROL_QUERY_INFORMATION query; |
| 3785 |
int i,f; |
| 3786 |
enum netr_SchannelType secure_channel_type = SEC_CHAN_NULL; |
| 3787 |
struct dcerpc_binding_handle *b = p->binding_handle; |
| 3788 |
|
| 3789 |
uint32_t function_codes[] = { |
| 3790 |
NETLOGON_CONTROL_QUERY, |
| 3791 |
NETLOGON_CONTROL_REPLICATE, |
| 3792 |
NETLOGON_CONTROL_SYNCHRONIZE, |
| 3793 |
NETLOGON_CONTROL_PDC_REPLICATE, |
| 3794 |
NETLOGON_CONTROL_REDISCOVER, |
| 3795 |
NETLOGON_CONTROL_TC_QUERY, |
| 3796 |
NETLOGON_CONTROL_TRANSPORT_NOTIFY, |
| 3797 |
NETLOGON_CONTROL_FIND_USER, |
| 3798 |
NETLOGON_CONTROL_CHANGE_PASSWORD, |
| 3799 |
NETLOGON_CONTROL_TC_VERIFY, |
| 3800 |
NETLOGON_CONTROL_FORCE_DNS_REG, |
| 3801 |
NETLOGON_CONTROL_QUERY_DNS_REG, |
| 3802 |
NETLOGON_CONTROL_BACKUP_CHANGE_LOG, |
| 3803 |
NETLOGON_CONTROL_TRUNCATE_LOG, |
| 3804 |
NETLOGON_CONTROL_SET_DBFLAG, |
| 3805 |
NETLOGON_CONTROL_BREAKPOINT |
| 3806 |
}; |
| 3807 |
|
| 3808 |
if (machine_credentials) { |
| 3809 |
secure_channel_type = cli_credentials_get_secure_channel_type(machine_credentials); |
| 3810 |
} |
| 3811 |
|
| 3812 |
torture_comment(tctx, "Testing LogonControl with secure channel type: %d\n", |
| 3813 |
secure_channel_type); |
| 3814 |
|
| 3815 |
r.in.logon_server = talloc_asprintf(tctx, "\\\\%s", dcerpc_server_name(p)); |
| 3816 |
r.in.function_code = 1; |
| 3817 |
r.out.query = &query; |
| 3818 |
|
| 3819 |
for (f=0;f<ARRAY_SIZE(function_codes); f++) { |
| 3820 |
for (i=1;i<5;i++) { |
| 3821 |
|
| 3822 |
r.in.function_code = function_codes[f]; |
| 3823 |
r.in.level = i; |
| 3824 |
|
| 3825 |
torture_comment(tctx, "Testing LogonControl function code %s (%d) level %d\n", |
| 3826 |
function_code_str(tctx, r.in.function_code), r.in.function_code, r.in.level); |
| 3827 |
|
| 3828 |
status = dcerpc_netr_LogonControl_r(b, tctx, &r); |
| 3829 |
torture_assert_ntstatus_ok(tctx, status, "LogonControl"); |
| 3830 |
|
| 3831 |
switch (r.in.level) { |
| 3832 |
case 1: |
| 3833 |
switch (r.in.function_code) { |
| 3834 |
case NETLOGON_CONTROL_REPLICATE: |
| 3835 |
case NETLOGON_CONTROL_SYNCHRONIZE: |
| 3836 |
case NETLOGON_CONTROL_PDC_REPLICATE: |
| 3837 |
case NETLOGON_CONTROL_BREAKPOINT: |
| 3838 |
case NETLOGON_CONTROL_BACKUP_CHANGE_LOG: |
| 3839 |
if ((secure_channel_type == SEC_CHAN_BDC) || |
| 3840 |
(secure_channel_type == SEC_CHAN_WKSTA)) { |
| 3841 |
torture_assert_werr_equal(tctx, r.out.result, WERR_ACCESS_DENIED, |
| 3842 |
"LogonControl returned unexpected error code"); |
| 3843 |
} else { |
| 3844 |
torture_assert_werr_equal(tctx, r.out.result, WERR_NOT_SUPPORTED, |
| 3845 |
"LogonControl returned unexpected error code"); |
| 3846 |
} |
| 3847 |
break; |
| 3848 |
|
| 3849 |
case NETLOGON_CONTROL_REDISCOVER: |
| 3850 |
case NETLOGON_CONTROL_TC_QUERY: |
| 3851 |
case NETLOGON_CONTROL_TRANSPORT_NOTIFY: |
| 3852 |
case NETLOGON_CONTROL_FIND_USER: |
| 3853 |
case NETLOGON_CONTROL_CHANGE_PASSWORD: |
| 3854 |
case NETLOGON_CONTROL_TC_VERIFY: |
| 3855 |
case NETLOGON_CONTROL_FORCE_DNS_REG: |
| 3856 |
case NETLOGON_CONTROL_QUERY_DNS_REG: |
| 3857 |
case NETLOGON_CONTROL_SET_DBFLAG: |
| 3858 |
torture_assert_werr_equal(tctx, r.out.result, WERR_NOT_SUPPORTED, |
| 3859 |
"LogonControl returned unexpected error code"); |
| 3860 |
break; |
| 3861 |
case NETLOGON_CONTROL_TRUNCATE_LOG: |
| 3862 |
if ((secure_channel_type == SEC_CHAN_BDC) || |
| 3863 |
(secure_channel_type == SEC_CHAN_WKSTA)) { |
| 3864 |
torture_assert_werr_equal(tctx, r.out.result, WERR_ACCESS_DENIED, |
| 3865 |
"LogonControl returned unexpected error code"); |
| 3866 |
} else if (!W_ERROR_EQUAL(r.out.result, WERR_NOT_SUPPORTED)) { |
| 3867 |
torture_assert_werr_ok(tctx, r.out.result, |
| 3868 |
"LogonControl returned unexpected result"); |
| 3869 |
} |
| 3870 |
break; |
| 3871 |
default: |
| 3872 |
torture_assert_werr_ok(tctx, r.out.result, |
| 3873 |
"LogonControl returned unexpected result"); |
| 3874 |
break; |
| 3875 |
} |
| 3876 |
break; |
| 3877 |
case 2: |
| 3878 |
torture_assert_werr_equal(tctx, r.out.result, WERR_NOT_SUPPORTED, |
| 3879 |
"LogonControl returned unexpected error code"); |
| 3880 |
break; |
| 3881 |
default: |
| 3882 |
torture_assert_werr_equal(tctx, r.out.result, WERR_INVALID_LEVEL, |
| 3883 |
"LogonControl returned unexpected error code"); |
| 3884 |
break; |
| 3885 |
} |
| 3886 |
} |
| 3887 |
} |
| 3888 |
|
| 3889 |
r.in.level = 52; |
| 3890 |
torture_comment(tctx, "Testing LogonControl function code %s (%d) level %d\n", |
| 3891 |
function_code_str(tctx, r.in.function_code), r.in.function_code, r.in.level); |
| 3892 |
status = dcerpc_netr_LogonControl_r(b, tctx, &r); |
| 3893 |
torture_assert_ntstatus_ok(tctx, status, "LogonControl"); |
| 3894 |
torture_assert_werr_equal(tctx, r.out.result, WERR_INVALID_LEVEL, "LogonControl"); |
| 3895 |
|
| 3896 |
return true; |
| 3897 |
} |
| 3898 |
|
| 3899 |
|
| 3900 |
/* |
| 3901 |
try a netlogon GetAnyDCName |
| 3902 |
*/ |
| 3903 |
static bool test_GetAnyDCName(struct torture_context *tctx, |
| 3904 |
struct dcerpc_pipe *p) |
| 3905 |
{ |
| 3906 |
NTSTATUS status; |
| 3907 |
struct netr_GetAnyDCName r; |
| 3908 |
const char *dcname = NULL; |
| 3909 |
struct dcerpc_binding_handle *b = p->binding_handle; |
| 3910 |
|
| 3911 |
r.in.domainname = lpcfg_workgroup(tctx->lp_ctx); |
| 3912 |
r.in.logon_server = talloc_asprintf(tctx, "\\\\%s", dcerpc_server_name(p)); |
| 3913 |
r.out.dcname = &dcname; |
| 3914 |
|
| 3915 |
status = dcerpc_netr_GetAnyDCName_r(b, tctx, &r); |
| 3916 |
torture_assert_ntstatus_ok(tctx, status, "GetAnyDCName"); |
| 3917 |
if ((!W_ERROR_IS_OK(r.out.result)) && |
| 3918 |
(!W_ERROR_EQUAL(r.out.result, WERR_NO_SUCH_DOMAIN))) { |
| 3919 |
return false; |
| 3920 |
} |
| 3921 |
|
| 3922 |
if (dcname) { |
| 3923 |
torture_comment(tctx, "\tDC is at '%s'\n", dcname); |
| 3924 |
} |
| 3925 |
|
| 3926 |
r.in.domainname = NULL; |
| 3927 |
|
| 3928 |
status = dcerpc_netr_GetAnyDCName_r(b, tctx, &r); |
| 3929 |
torture_assert_ntstatus_ok(tctx, status, "GetAnyDCName"); |
| 3930 |
if ((!W_ERROR_IS_OK(r.out.result)) && |
| 3931 |
(!W_ERROR_EQUAL(r.out.result, WERR_NO_SUCH_DOMAIN))) { |
| 3932 |
return false; |
| 3933 |
} |
| 3934 |
|
| 3935 |
r.in.domainname = ""; |
| 3936 |
|
| 3937 |
status = dcerpc_netr_GetAnyDCName_r(b, tctx, &r); |
| 3938 |
torture_assert_ntstatus_ok(tctx, status, "GetAnyDCName"); |
| 3939 |
if ((!W_ERROR_IS_OK(r.out.result)) && |
| 3940 |
(!W_ERROR_EQUAL(r.out.result, WERR_NO_SUCH_DOMAIN))) { |
| 3941 |
return false; |
| 3942 |
} |
| 3943 |
|
| 3944 |
return true; |
| 3945 |
} |
| 3946 |
|
| 3947 |
|
| 3948 |
/* |
| 3949 |
try a netlogon LogonControl2 |
| 3950 |
*/ |
| 3951 |
static bool test_LogonControl2(struct torture_context *tctx, |
| 3952 |
struct dcerpc_pipe *p, |
| 3953 |
struct cli_credentials *machine_credentials) |
| 3954 |
|
| 3955 |
{ |
| 3956 |
NTSTATUS status; |
| 3957 |
struct netr_LogonControl2 r; |
| 3958 |
union netr_CONTROL_DATA_INFORMATION data; |
| 3959 |
union netr_CONTROL_QUERY_INFORMATION query; |
| 3960 |
enum netr_SchannelType secure_channel_type = SEC_CHAN_NULL; |
| 3961 |
int i; |
| 3962 |
struct dcerpc_binding_handle *b = p->binding_handle; |
| 3963 |
|
| 3964 |
data.domain = lpcfg_workgroup(tctx->lp_ctx); |
| 3965 |
|
| 3966 |
if (machine_credentials) { |
| 3967 |
secure_channel_type = cli_credentials_get_secure_channel_type(machine_credentials); |
| 3968 |
} |
| 3969 |
|
| 3970 |
torture_comment(tctx, "Testing LogonControl2 with secure channel type: %d\n", |
| 3971 |
secure_channel_type); |
| 3972 |
|
| 3973 |
r.in.logon_server = talloc_asprintf(tctx, "\\\\%s", dcerpc_server_name(p)); |
| 3974 |
|
| 3975 |
r.in.function_code = NETLOGON_CONTROL_REDISCOVER; |
| 3976 |
r.in.data = &data; |
| 3977 |
r.out.query = &query; |
| 3978 |
|
| 3979 |
for (i=1;i<4;i++) { |
| 3980 |
r.in.level = i; |
| 3981 |
|
| 3982 |
torture_comment(tctx, "Testing LogonControl2 function code %s (%d) level %d\n", |
| 3983 |
function_code_str(tctx, r.in.function_code), r.in.function_code, r.in.level); |
| 3984 |
|
| 3985 |
status = dcerpc_netr_LogonControl2_r(b, tctx, &r); |
| 3986 |
torture_assert_ntstatus_ok(tctx, status, "LogonControl2"); |
| 3987 |
} |
| 3988 |
|
| 3989 |
data.domain = lpcfg_workgroup(tctx->lp_ctx); |
| 3990 |
|
| 3991 |
r.in.function_code = NETLOGON_CONTROL_TC_QUERY; |
| 3992 |
r.in.data = &data; |
| 3993 |
|
| 3994 |
for (i=1;i<4;i++) { |
| 3995 |
r.in.level = i; |
| 3996 |
|
| 3997 |
torture_comment(tctx, "Testing LogonControl2 function code %s (%d) level %d\n", |
| 3998 |
function_code_str(tctx, r.in.function_code), r.in.function_code, r.in.level); |
| 3999 |
|
| 4000 |
status = dcerpc_netr_LogonControl2_r(b, tctx, &r); |
| 4001 |
torture_assert_ntstatus_ok(tctx, status, "LogonControl2"); |
| 4002 |
} |
| 4003 |
|
| 4004 |
data.domain = lpcfg_workgroup(tctx->lp_ctx); |
| 4005 |
|
| 4006 |
r.in.function_code = NETLOGON_CONTROL_TRANSPORT_NOTIFY; |
| 4007 |
r.in.data = &data; |
| 4008 |
|
| 4009 |
for (i=1;i<4;i++) { |
| 4010 |
r.in.level = i; |
| 4011 |
|
| 4012 |
torture_comment(tctx, "Testing LogonControl2 function code %s (%d) level %d\n", |
| 4013 |
function_code_str(tctx, r.in.function_code), r.in.function_code, r.in.level); |
| 4014 |
|
| 4015 |
status = dcerpc_netr_LogonControl2_r(b, tctx, &r); |
| 4016 |
torture_assert_ntstatus_ok(tctx, status, "LogonControl2"); |
| 4017 |
} |
| 4018 |
|
| 4019 |
data.debug_level = ~0; |
| 4020 |
|
| 4021 |
r.in.function_code = NETLOGON_CONTROL_SET_DBFLAG; |
| 4022 |
r.in.data = &data; |
| 4023 |
|
| 4024 |
for (i=1;i<4;i++) { |
| 4025 |
r.in.level = i; |
| 4026 |
|
| 4027 |
torture_comment(tctx, "Testing LogonControl2 function code %s (%d) level %d\n", |
| 4028 |
function_code_str(tctx, r.in.function_code), r.in.function_code, r.in.level); |
| 4029 |
|
| 4030 |
status = dcerpc_netr_LogonControl2_r(b, tctx, &r); |
| 4031 |
torture_assert_ntstatus_ok(tctx, status, "LogonControl2"); |
| 4032 |
} |
| 4033 |
|
| 4034 |
ZERO_STRUCT(data); |
| 4035 |
r.in.function_code = 52; |
| 4036 |
r.in.data = &data; |
| 4037 |
|
| 4038 |
torture_comment(tctx, "Testing LogonControl2 function code %s (%d) level %d\n", |
| 4039 |
function_code_str(tctx, r.in.function_code), r.in.function_code, r.in.level); |
| 4040 |
|
| 4041 |
status = dcerpc_netr_LogonControl2_r(b, tctx, &r); |
| 4042 |
torture_assert_ntstatus_ok(tctx, status, "LogonControl2"); |
| 4043 |
switch (secure_channel_type) { |
| 4044 |
case SEC_CHAN_NULL: |
| 4045 |
torture_assert_werr_equal(tctx, r.out.result, WERR_NOT_SUPPORTED, "LogonControl2"); |
| 4046 |
break; |
| 4047 |
default: |
| 4048 |
torture_assert_werr_equal(tctx, r.out.result, WERR_ACCESS_DENIED, "LogonControl2"); |
| 4049 |
break; |
| 4050 |
} |
| 4051 |
data.debug_level = ~0; |
| 4052 |
|
| 4053 |
r.in.function_code = NETLOGON_CONTROL_SET_DBFLAG; |
| 4054 |
r.in.data = &data; |
| 4055 |
|
| 4056 |
r.in.level = 52; |
| 4057 |
torture_comment(tctx, "Testing LogonControl2 function code %s (%d) level %d\n", |
| 4058 |
function_code_str(tctx, r.in.function_code), r.in.function_code, r.in.level); |
| 4059 |
|
| 4060 |
status = dcerpc_netr_LogonControl2_r(b, tctx, &r); |
| 4061 |
torture_assert_ntstatus_ok(tctx, status, "LogonControl2"); |
| 4062 |
torture_assert_werr_equal(tctx, r.out.result, WERR_INVALID_LEVEL, "LogonControl2"); |
| 4063 |
|
| 4064 |
return true; |
| 4065 |
} |
| 4066 |
|
| 4067 |
/* |
| 4068 |
try a netlogon DatabaseSync2 |
| 4069 |
*/ |
| 4070 |
static bool test_DatabaseSync2(struct torture_context *tctx, |
| 4071 |
struct dcerpc_pipe *p, |
| 4072 |
struct cli_credentials *machine_credentials) |
| 4073 |
{ |
| 4074 |
struct netr_DatabaseSync2 r; |
| 4075 |
struct netr_DELTA_ENUM_ARRAY *delta_enum_array = NULL; |
| 4076 |
struct netr_Authenticator return_authenticator, credential; |
| 4077 |
|
| 4078 |
struct netlogon_creds_CredentialState *creds; |
| 4079 |
const uint32_t database_ids[] = {0, 1, 2}; |
| 4080 |
int i; |
| 4081 |
struct dcerpc_binding_handle *b = p->binding_handle; |
| 4082 |
|
| 4083 |
if (!test_SetupCredentials2(p, tctx, NETLOGON_NEG_AUTH2_FLAGS, |
| 4084 |
machine_credentials, |
| 4085 |
cli_credentials_get_secure_channel_type(machine_credentials), |
| 4086 |
&creds)) { |
| 4087 |
return false; |
| 4088 |
} |
| 4089 |
|
| 4090 |
ZERO_STRUCT(return_authenticator); |
| 4091 |
|
| 4092 |
r.in.logon_server = talloc_asprintf(tctx, "\\\\%s", dcerpc_server_name(p)); |
| 4093 |
r.in.computername = TEST_MACHINE_NAME; |
| 4094 |
r.in.preferredmaximumlength = (uint32_t)-1; |
| 4095 |
r.in.return_authenticator = &return_authenticator; |
| 4096 |
r.out.return_authenticator = &return_authenticator; |
| 4097 |
r.out.delta_enum_array = &delta_enum_array; |
| 4098 |
|
| 4099 |
for (i=0;i<ARRAY_SIZE(database_ids);i++) { |
| 4100 |
|
| 4101 |
uint32_t sync_context = 0; |
| 4102 |
|
| 4103 |
r.in.database_id = database_ids[i]; |
| 4104 |
r.in.sync_context = &sync_context; |
| 4105 |
r.out.sync_context = &sync_context; |
| 4106 |
r.in.restart_state = 0; |
| 4107 |
|
| 4108 |
torture_comment(tctx, "Testing DatabaseSync2 of id %d\n", r.in.database_id); |
| 4109 |
|
| 4110 |
do { |
| 4111 |
netlogon_creds_client_authenticator(creds, &credential); |
| 4112 |
|
| 4113 |
r.in.credential = &credential; |
| 4114 |
|
| 4115 |
torture_assert_ntstatus_ok(tctx, dcerpc_netr_DatabaseSync2_r(b, tctx, &r), |
| 4116 |
"DatabaseSync2 failed"); |
| 4117 |
if (NT_STATUS_EQUAL(r.out.result, STATUS_MORE_ENTRIES)) |
| 4118 |
break; |
| 4119 |
|
| 4120 |
/* Native mode servers don't do this */ |
| 4121 |
if (NT_STATUS_EQUAL(r.out.result, NT_STATUS_NOT_SUPPORTED)) { |
| 4122 |
return true; |
| 4123 |
} |
| 4124 |
|
| 4125 |
torture_assert_ntstatus_ok(tctx, r.out.result, "DatabaseSync2"); |
| 4126 |
|
| 4127 |
if (!netlogon_creds_client_check(creds, &r.out.return_authenticator->cred)) { |
| 4128 |
torture_comment(tctx, "Credential chaining failed\n"); |
| 4129 |
} |
| 4130 |
|
| 4131 |
} while (NT_STATUS_EQUAL(r.out.result, STATUS_MORE_ENTRIES)); |
| 4132 |
} |
| 4133 |
|
| 4134 |
return true; |
| 4135 |
} |
| 4136 |
|
| 4137 |
|
| 4138 |
/* |
| 4139 |
try a netlogon LogonControl2Ex |
| 4140 |
*/ |
| 4141 |
|
| 4142 |
static bool test_LogonControl2Ex(struct torture_context *tctx, |
| 4143 |
struct dcerpc_pipe *p, |
| 4144 |
struct cli_credentials *machine_credentials) |
| 4145 |
|
| 4146 |
{ |
| 4147 |
NTSTATUS status; |
| 4148 |
struct netr_LogonControl2Ex r; |
| 4149 |
union netr_CONTROL_DATA_INFORMATION data; |
| 4150 |
union netr_CONTROL_QUERY_INFORMATION query; |
| 4151 |
enum netr_SchannelType secure_channel_type = SEC_CHAN_NULL; |
| 4152 |
int i; |
| 4153 |
struct dcerpc_binding_handle *b = p->binding_handle; |
| 4154 |
|
| 4155 |
data.domain = lpcfg_workgroup(tctx->lp_ctx); |
| 4156 |
|
| 4157 |
if (machine_credentials) { |
| 4158 |
secure_channel_type = cli_credentials_get_secure_channel_type(machine_credentials); |
| 4159 |
} |
| 4160 |
|
| 4161 |
torture_comment(tctx, "Testing LogonControl2Ex with secure channel type: %d\n", |
| 4162 |
secure_channel_type); |
| 4163 |
|
| 4164 |
r.in.logon_server = talloc_asprintf(tctx, "\\\\%s", dcerpc_server_name(p)); |
| 4165 |
|
| 4166 |
r.in.function_code = NETLOGON_CONTROL_REDISCOVER; |
| 4167 |
r.in.data = &data; |
| 4168 |
r.out.query = &query; |
| 4169 |
|
| 4170 |
for (i=1;i<4;i++) { |
| 4171 |
r.in.level = i; |
| 4172 |
|
| 4173 |
torture_comment(tctx, "Testing LogonControl2Ex function code %s (%d) level %d\n", |
| 4174 |
function_code_str(tctx, r.in.function_code), r.in.function_code, r.in.level); |
| 4175 |
|
| 4176 |
status = dcerpc_netr_LogonControl2Ex_r(b, tctx, &r); |
| 4177 |
torture_assert_ntstatus_ok(tctx, status, "LogonControl2Ex"); |
| 4178 |
} |
| 4179 |
|
| 4180 |
data.domain = lpcfg_workgroup(tctx->lp_ctx); |
| 4181 |
|
| 4182 |
r.in.function_code = NETLOGON_CONTROL_TC_QUERY; |
| 4183 |
r.in.data = &data; |
| 4184 |
|
| 4185 |
for (i=1;i<4;i++) { |
| 4186 |
r.in.level = i; |
| 4187 |
|
| 4188 |
torture_comment(tctx, "Testing LogonControl2Ex function code %s (%d) level %d\n", |
| 4189 |
function_code_str(tctx, r.in.function_code), r.in.function_code, r.in.level); |
| 4190 |
|
| 4191 |
status = dcerpc_netr_LogonControl2Ex_r(b, tctx, &r); |
| 4192 |
torture_assert_ntstatus_ok(tctx, status, "LogonControl2Ex"); |
| 4193 |
} |
| 4194 |
|
| 4195 |
data.domain = lpcfg_workgroup(tctx->lp_ctx); |
| 4196 |
|
| 4197 |
r.in.function_code = NETLOGON_CONTROL_TRANSPORT_NOTIFY; |
| 4198 |
r.in.data = &data; |
| 4199 |
|
| 4200 |
for (i=1;i<4;i++) { |
| 4201 |
r.in.level = i; |
| 4202 |
|
| 4203 |
torture_comment(tctx, "Testing LogonControl2Ex function code %s (%d) level %d\n", |
| 4204 |
function_code_str(tctx, r.in.function_code), r.in.function_code, r.in.level); |
| 4205 |
|
| 4206 |
status = dcerpc_netr_LogonControl2Ex_r(b, tctx, &r); |
| 4207 |
torture_assert_ntstatus_ok(tctx, status, "LogonControl2Ex"); |
| 4208 |
} |
| 4209 |
|
| 4210 |
data.debug_level = ~0; |
| 4211 |
|
| 4212 |
r.in.function_code = NETLOGON_CONTROL_SET_DBFLAG; |
| 4213 |
r.in.data = &data; |
| 4214 |
|
| 4215 |
for (i=1;i<=4;i++) { |
| 4216 |
r.in.level = i; |
| 4217 |
|
| 4218 |
torture_comment(tctx, "Testing LogonControl2Ex function code %s (%d) level %d\n", |
| 4219 |
function_code_str(tctx, r.in.function_code), r.in.function_code, r.in.level); |
| 4220 |
|
| 4221 |
status = dcerpc_netr_LogonControl2Ex_r(b, tctx, &r); |
| 4222 |
torture_assert_ntstatus_ok(tctx, status, "LogonControl2Ex"); |
| 4223 |
} |
| 4224 |
|
| 4225 |
ZERO_STRUCT(data); |
| 4226 |
r.in.function_code = 52; |
| 4227 |
r.in.data = &data; |
| 4228 |
|
| 4229 |
torture_comment(tctx, "Testing LogonControl2Ex function code %s (%d) level %d\n", |
| 4230 |
function_code_str(tctx, r.in.function_code), r.in.function_code, r.in.level); |
| 4231 |
|
| 4232 |
status = dcerpc_netr_LogonControl2Ex_r(b, tctx, &r); |
| 4233 |
torture_assert_ntstatus_ok(tctx, status, "LogonControl2Ex"); |
| 4234 |
switch (secure_channel_type) { |
| 4235 |
case SEC_CHAN_NULL: |
| 4236 |
torture_assert(tctx, |
| 4237 |
W_ERROR_EQUAL(r.out.result, WERR_NOT_SUPPORTED) || |
| 4238 |
W_ERROR_EQUAL(r.out.result, WERR_INVALID_PARAMETER), |
| 4239 |
"LogonControl2Ex"); |
| 4240 |
break; |
| 4241 |
default: |
| 4242 |
torture_assert_werr_equal(tctx, r.out.result, WERR_ACCESS_DENIED, "LogonControl2Ex"); |
| 4243 |
break; |
| 4244 |
} |
| 4245 |
data.debug_level = ~0; |
| 4246 |
|
| 4247 |
r.in.function_code = NETLOGON_CONTROL_SET_DBFLAG; |
| 4248 |
r.in.data = &data; |
| 4249 |
|
| 4250 |
r.in.level = 52; |
| 4251 |
torture_comment(tctx, "Testing LogonControl2Ex function code %s (%d) level %d\n", |
| 4252 |
function_code_str(tctx, r.in.function_code), r.in.function_code, r.in.level); |
| 4253 |
|
| 4254 |
status = dcerpc_netr_LogonControl2Ex_r(b, tctx, &r); |
| 4255 |
torture_assert_ntstatus_ok(tctx, status, "LogonControl2Ex"); |
| 4256 |
torture_assert_werr_equal(tctx, r.out.result, WERR_INVALID_LEVEL, "LogonControl2Ex"); |
| 4257 |
|
| 4258 |
return true; |
| 4259 |
} |
| 4260 |
|
| 4261 |
static bool test_netr_GetForestTrustInformation(struct torture_context *tctx, |
| 4262 |
struct dcerpc_pipe *p1, |
| 4263 |
struct cli_credentials *machine_credentials) |
| 4264 |
{ |
| 4265 |
struct netr_GetForestTrustInformation r; |
| 4266 |
struct netlogon_creds_CredentialState *creds; |
| 4267 |
struct netr_Authenticator a; |
| 4268 |
struct netr_Authenticator return_authenticator; |
| 4269 |
struct lsa_ForestTrustInformation *forest_trust_info; |
| 4270 |
struct dcerpc_pipe *p = NULL; |
| 4271 |
struct dcerpc_binding_handle *b = NULL; |
| 4272 |
|
| 4273 |
if (!test_SetupCredentials3(p1, tctx, NETLOGON_NEG_AUTH2_ADS_FLAGS | NETLOGON_NEG_SUPPORTS_AES, |
| 4274 |
machine_credentials, &creds)) { |
| 4275 |
return false; |
| 4276 |
} |
| 4277 |
if (!test_SetupCredentialsPipe(p1, tctx, machine_credentials, creds, |
| 4278 |
DCERPC_SIGN | DCERPC_SEAL, &p)) { |
| 4279 |
return false; |
| 4280 |
} |
| 4281 |
b = p->binding_handle; |
| 4282 |
|
| 4283 |
netlogon_creds_client_authenticator(creds, &a); |
| 4284 |
|
| 4285 |
r.in.server_name = talloc_asprintf(tctx, "\\\\%s", dcerpc_server_name(p)); |
| 4286 |
r.in.computer_name = TEST_MACHINE_NAME; |
| 4287 |
r.in.credential = &a; |
| 4288 |
r.in.flags = 0; |
| 4289 |
r.out.return_authenticator = &return_authenticator; |
| 4290 |
r.out.forest_trust_info = &forest_trust_info; |
| 4291 |
|
| 4292 |
torture_assert_ntstatus_ok(tctx, |
| 4293 |
dcerpc_netr_GetForestTrustInformation_r(b, tctx, &r), |
| 4294 |
"netr_GetForestTrustInformation failed"); |
| 4295 |
if (NT_STATUS_EQUAL(r.out.result, NT_STATUS_NOT_IMPLEMENTED)) { |
| 4296 |
torture_comment(tctx, "not considering NT_STATUS_NOT_IMPLEMENTED as an error\n"); |
| 4297 |
} else { |
| 4298 |
torture_assert_ntstatus_ok(tctx, r.out.result, |
| 4299 |
"netr_GetForestTrustInformation failed"); |
| 4300 |
} |
| 4301 |
|
| 4302 |
torture_assert(tctx, |
| 4303 |
netlogon_creds_client_check(creds, &return_authenticator.cred), |
| 4304 |
"Credential chaining failed"); |
| 4305 |
|
| 4306 |
return true; |
| 4307 |
} |
| 4308 |
|
| 4309 |
static bool test_netr_DsRGetForestTrustInformation(struct torture_context *tctx, |
| 4310 |
struct dcerpc_pipe *p, const char *trusted_domain_name) |
| 4311 |
{ |
| 4312 |
NTSTATUS status; |
| 4313 |
struct netr_DsRGetForestTrustInformation r; |
| 4314 |
struct lsa_ForestTrustInformation info, *info_ptr; |
| 4315 |
struct dcerpc_binding_handle *b = p->binding_handle; |
| 4316 |
|
| 4317 |
info_ptr = &info; |
| 4318 |
|
| 4319 |
r.in.server_name = talloc_asprintf(tctx, "\\\\%s", dcerpc_server_name(p)); |
| 4320 |
r.in.trusted_domain_name = trusted_domain_name; |
| 4321 |
r.in.flags = 0; |
| 4322 |
r.out.forest_trust_info = &info_ptr; |
| 4323 |
|
| 4324 |
torture_comment(tctx ,"Testing netr_DsRGetForestTrustInformation\n"); |
| 4325 |
|
| 4326 |
status = dcerpc_netr_DsRGetForestTrustInformation_r(b, tctx, &r); |
| 4327 |
torture_assert_ntstatus_ok(tctx, status, "DsRGetForestTrustInformation"); |
| 4328 |
torture_assert_werr_ok(tctx, r.out.result, "DsRGetForestTrustInformation"); |
| 4329 |
|
| 4330 |
return true; |
| 4331 |
} |
| 4332 |
|
| 4333 |
/* |
| 4334 |
try a netlogon netr_DsrEnumerateDomainTrusts |
| 4335 |
*/ |
| 4336 |
static bool test_DsrEnumerateDomainTrusts(struct torture_context *tctx, |
| 4337 |
struct dcerpc_pipe *p) |
| 4338 |
{ |
| 4339 |
NTSTATUS status; |
| 4340 |
struct netr_DsrEnumerateDomainTrusts r; |
| 4341 |
struct netr_DomainTrustList trusts; |
| 4342 |
int i; |
| 4343 |
struct dcerpc_binding_handle *b = p->binding_handle; |
| 4344 |
|
| 4345 |
r.in.server_name = talloc_asprintf(tctx, "\\\\%s", dcerpc_server_name(p)); |
| 4346 |
r.in.trust_flags = 0x3f; |
| 4347 |
r.out.trusts = &trusts; |
| 4348 |
|
| 4349 |
status = dcerpc_netr_DsrEnumerateDomainTrusts_r(b, tctx, &r); |
| 4350 |
torture_assert_ntstatus_ok(tctx, status, "DsrEnumerateDomaintrusts"); |
| 4351 |
torture_assert_werr_ok(tctx, r.out.result, "DsrEnumerateDomaintrusts"); |
| 4352 |
|
| 4353 |
/* when trusted_domain_name is NULL, netr_DsRGetForestTrustInformation |
| 4354 |
* will show non-forest trusts and all UPN suffixes of the own forest |
| 4355 |
* as LSA_FOREST_TRUST_TOP_LEVEL_NAME types */ |
| 4356 |
|
| 4357 |
if (r.out.trusts->count) { |
| 4358 |
if (!test_netr_DsRGetForestTrustInformation(tctx, p, NULL)) { |
| 4359 |
return false; |
| 4360 |
} |
| 4361 |
} |
| 4362 |
|
| 4363 |
for (i=0; i<r.out.trusts->count; i++) { |
| 4364 |
|
| 4365 |
/* get info for transitive forest trusts */ |
| 4366 |
|
| 4367 |
if (r.out.trusts->array[i].trust_attributes & LSA_TRUST_ATTRIBUTE_FOREST_TRANSITIVE) { |
| 4368 |
if (!test_netr_DsRGetForestTrustInformation(tctx, p, |
| 4369 |
r.out.trusts->array[i].dns_name)) { |
| 4370 |
return false; |
| 4371 |
} |
| 4372 |
} |
| 4373 |
} |
| 4374 |
|
| 4375 |
return true; |
| 4376 |
} |
| 4377 |
|
| 4378 |
static bool test_netr_NetrEnumerateTrustedDomains(struct torture_context *tctx, |
| 4379 |
struct dcerpc_pipe *p) |
| 4380 |
{ |
| 4381 |
NTSTATUS status; |
| 4382 |
struct netr_NetrEnumerateTrustedDomains r; |
| 4383 |
struct netr_Blob trusted_domains_blob; |
| 4384 |
struct dcerpc_binding_handle *b = p->binding_handle; |
| 4385 |
|
| 4386 |
r.in.server_name = talloc_asprintf(tctx, "\\\\%s", dcerpc_server_name(p)); |
| 4387 |
r.out.trusted_domains_blob = &trusted_domains_blob; |
| 4388 |
|
| 4389 |
status = dcerpc_netr_NetrEnumerateTrustedDomains_r(b, tctx, &r); |
| 4390 |
torture_assert_ntstatus_ok(tctx, status, "netr_NetrEnumerateTrustedDomains"); |
| 4391 |
torture_assert_ntstatus_ok(tctx, r.out.result, "NetrEnumerateTrustedDomains"); |
| 4392 |
|
| 4393 |
return true; |
| 4394 |
} |
| 4395 |
|
| 4396 |
static bool test_netr_NetrEnumerateTrustedDomainsEx(struct torture_context *tctx, |
| 4397 |
struct dcerpc_pipe *p) |
| 4398 |
{ |
| 4399 |
NTSTATUS status; |
| 4400 |
struct netr_NetrEnumerateTrustedDomainsEx r; |
| 4401 |
struct netr_DomainTrustList dom_trust_list; |
| 4402 |
struct dcerpc_binding_handle *b = p->binding_handle; |
| 4403 |
|
| 4404 |
r.in.server_name = talloc_asprintf(tctx, "\\\\%s", dcerpc_server_name(p)); |
| 4405 |
r.out.dom_trust_list = &dom_trust_list; |
| 4406 |
|
| 4407 |
status = dcerpc_netr_NetrEnumerateTrustedDomainsEx_r(b, tctx, &r); |
| 4408 |
torture_assert_ntstatus_ok(tctx, status, "netr_NetrEnumerateTrustedDomainsEx"); |
| 4409 |
torture_assert_werr_ok(tctx, r.out.result, "NetrEnumerateTrustedDomainsEx"); |
| 4410 |
|
| 4411 |
return true; |
| 4412 |
} |
| 4413 |
|
| 4414 |
|
| 4415 |
static bool test_netr_DsRGetSiteName(struct dcerpc_pipe *p, struct torture_context *tctx, |
| 4416 |
const char *computer_name, |
| 4417 |
const char *expected_site) |
| 4418 |
{ |
| 4419 |
NTSTATUS status; |
| 4420 |
struct netr_DsRGetSiteName r; |
| 4421 |
const char *site = NULL; |
| 4422 |
struct dcerpc_binding_handle *b = p->binding_handle; |
| 4423 |
|
| 4424 |
r.in.computer_name = computer_name; |
| 4425 |
r.out.site = &site; |
| 4426 |
torture_comment(tctx, "Testing netr_DsRGetSiteName\n"); |
| 4427 |
|
| 4428 |
status = dcerpc_netr_DsRGetSiteName_r(b, tctx, &r); |
| 4429 |
torture_assert_ntstatus_ok(tctx, status, "DsRGetSiteName"); |
| 4430 |
torture_assert_werr_ok(tctx, r.out.result, "DsRGetSiteName"); |
| 4431 |
torture_assert_str_equal(tctx, expected_site, site, "netr_DsRGetSiteName"); |
| 4432 |
|
| 4433 |
return true; |
| 4434 |
} |
| 4435 |
|
| 4436 |
/* |
| 4437 |
try a netlogon netr_DsRGetDCName |
| 4438 |
*/ |
| 4439 |
static bool test_netr_DsRGetDCName(struct torture_context *tctx, |
| 4440 |
struct dcerpc_pipe *p) |
| 4441 |
{ |
| 4442 |
NTSTATUS status; |
| 4443 |
struct netr_DsRGetDCName r; |
| 4444 |
struct netr_DsRGetDCNameInfo *info = NULL; |
| 4445 |
struct dcerpc_binding_handle *b = p->binding_handle; |
| 4446 |
|
| 4447 |
r.in.server_unc = talloc_asprintf(tctx, "\\\\%s", dcerpc_server_name(p)); |
| 4448 |
r.in.domain_name = lpcfg_dnsdomain(tctx->lp_ctx); |
| 4449 |
r.in.domain_guid = NULL; |
| 4450 |
r.in.site_guid = NULL; |
| 4451 |
r.in.flags = DS_RETURN_DNS_NAME; |
| 4452 |
r.out.info = &info; |
| 4453 |
|
| 4454 |
status = dcerpc_netr_DsRGetDCName_r(b, tctx, &r); |
| 4455 |
torture_assert_ntstatus_ok(tctx, status, "DsRGetDCName"); |
| 4456 |
torture_assert_werr_ok(tctx, r.out.result, "DsRGetDCName"); |
| 4457 |
|
| 4458 |
torture_assert_int_equal(tctx, |
| 4459 |
(info->dc_flags & (DS_DNS_CONTROLLER)), |
| 4460 |
DS_DNS_CONTROLLER, |
| 4461 |
"DsRGetDCName"); |
| 4462 |
torture_assert_int_equal(tctx, |
| 4463 |
(info->dc_flags & (DS_DNS_DOMAIN)), |
| 4464 |
DS_DNS_DOMAIN, |
| 4465 |
"DsRGetDCName"); |
| 4466 |
torture_assert_int_equal(tctx, |
| 4467 |
(info->dc_flags & (DS_DNS_FOREST_ROOT)), |
| 4468 |
DS_DNS_FOREST_ROOT, |
| 4469 |
"DsRGetDCName"); |
| 4470 |
|
| 4471 |
r.in.domain_name = lpcfg_workgroup(tctx->lp_ctx); |
| 4472 |
r.in.flags = 0; |
| 4473 |
|
| 4474 |
status = dcerpc_netr_DsRGetDCName_r(b, tctx, &r); |
| 4475 |
torture_assert_ntstatus_ok(tctx, status, "DsRGetDCName"); |
| 4476 |
torture_assert_werr_ok(tctx, r.out.result, "DsRGetDCName"); |
| 4477 |
|
| 4478 |
torture_assert_int_equal(tctx, |
| 4479 |
(info->dc_flags & (DS_DNS_CONTROLLER)), 0, |
| 4480 |
"DsRGetDCName"); |
| 4481 |
torture_assert_int_equal(tctx, |
| 4482 |
(info->dc_flags & (DS_DNS_DOMAIN)), 0, |
| 4483 |
"DsRGetDCName"); |
| 4484 |
torture_assert_int_equal(tctx, |
| 4485 |
(info->dc_flags & (DS_DNS_FOREST_ROOT)), |
| 4486 |
DS_DNS_FOREST_ROOT, |
| 4487 |
"DsRGetDCName"); |
| 4488 |
|
| 4489 |
if (strcasecmp(info->dc_site_name, info->client_site_name) == 0) { |
| 4490 |
torture_assert_int_equal(tctx, |
| 4491 |
(info->dc_flags & (DS_SERVER_CLOSEST)), |
| 4492 |
DS_SERVER_CLOSEST, |
| 4493 |
"DsRGetDCName"); |
| 4494 |
} |
| 4495 |
|
| 4496 |
return test_netr_DsRGetSiteName(p, tctx, |
| 4497 |
info->dc_unc, |
| 4498 |
info->dc_site_name); |
| 4499 |
} |
| 4500 |
|
| 4501 |
/* |
| 4502 |
try a netlogon netr_DsRGetDCNameEx |
| 4503 |
*/ |
| 4504 |
static bool test_netr_DsRGetDCNameEx(struct torture_context *tctx, |
| 4505 |
struct dcerpc_pipe *p) |
| 4506 |
{ |
| 4507 |
NTSTATUS status; |
| 4508 |
struct netr_DsRGetDCNameEx r; |
| 4509 |
struct netr_DsRGetDCNameInfo *info = NULL; |
| 4510 |
struct dcerpc_binding_handle *b = p->binding_handle; |
| 4511 |
|
| 4512 |
r.in.server_unc = talloc_asprintf(tctx, "\\\\%s", dcerpc_server_name(p)); |
| 4513 |
r.in.domain_name = lpcfg_dnsdomain(tctx->lp_ctx); |
| 4514 |
r.in.domain_guid = NULL; |
| 4515 |
r.in.site_name = NULL; |
| 4516 |
r.in.flags = DS_RETURN_DNS_NAME; |
| 4517 |
r.out.info = &info; |
| 4518 |
|
| 4519 |
status = dcerpc_netr_DsRGetDCNameEx_r(b, tctx, &r); |
| 4520 |
torture_assert_ntstatus_ok(tctx, status, "netr_DsRGetDCNameEx"); |
| 4521 |
torture_assert_werr_ok(tctx, r.out.result, "netr_DsRGetDCNameEx"); |
| 4522 |
|
| 4523 |
torture_assert_int_equal(tctx, |
| 4524 |
(info->dc_flags & (DS_DNS_CONTROLLER)), |
| 4525 |
DS_DNS_CONTROLLER, |
| 4526 |
"DsRGetDCNameEx"); |
| 4527 |
torture_assert_int_equal(tctx, |
| 4528 |
(info->dc_flags & (DS_DNS_DOMAIN)), |
| 4529 |
DS_DNS_DOMAIN, |
| 4530 |
"DsRGetDCNameEx"); |
| 4531 |
torture_assert_int_equal(tctx, |
| 4532 |
(info->dc_flags & (DS_DNS_FOREST_ROOT)), |
| 4533 |
DS_DNS_FOREST_ROOT, |
| 4534 |
"DsRGetDCNameEx"); |
| 4535 |
|
| 4536 |
r.in.domain_name = lpcfg_workgroup(tctx->lp_ctx); |
| 4537 |
r.in.flags = 0; |
| 4538 |
|
| 4539 |
status = dcerpc_netr_DsRGetDCNameEx_r(b, tctx, &r); |
| 4540 |
torture_assert_ntstatus_ok(tctx, status, "netr_DsRGetDCNameEx"); |
| 4541 |
torture_assert_werr_ok(tctx, r.out.result, "netr_DsRGetDCNameEx"); |
| 4542 |
|
| 4543 |
torture_assert_int_equal(tctx, |
| 4544 |
(info->dc_flags & (DS_DNS_CONTROLLER)), 0, |
| 4545 |
"DsRGetDCNameEx"); |
| 4546 |
torture_assert_int_equal(tctx, |
| 4547 |
(info->dc_flags & (DS_DNS_DOMAIN)), 0, |
| 4548 |
"DsRGetDCNameEx"); |
| 4549 |
torture_assert_int_equal(tctx, |
| 4550 |
(info->dc_flags & (DS_DNS_FOREST_ROOT)), |
| 4551 |
DS_DNS_FOREST_ROOT, |
| 4552 |
"DsRGetDCNameEx"); |
| 4553 |
|
| 4554 |
if (strcasecmp(info->dc_site_name, info->client_site_name) == 0) { |
| 4555 |
torture_assert_int_equal(tctx, |
| 4556 |
(info->dc_flags & (DS_SERVER_CLOSEST)), |
| 4557 |
DS_SERVER_CLOSEST, |
| 4558 |
"DsRGetDCNameEx"); |
| 4559 |
} |
| 4560 |
|
| 4561 |
return test_netr_DsRGetSiteName(p, tctx, info->dc_unc, |
| 4562 |
info->dc_site_name); |
| 4563 |
} |
| 4564 |
|
| 4565 |
/* |
| 4566 |
try a netlogon netr_DsRGetDCNameEx2 |
| 4567 |
*/ |
| 4568 |
static bool test_netr_DsRGetDCNameEx2(struct torture_context *tctx, |
| 4569 |
struct dcerpc_pipe *p) |
| 4570 |
{ |
| 4571 |
NTSTATUS status; |
| 4572 |
struct netr_DsRGetDCNameEx2 r; |
| 4573 |
struct netr_DsRGetDCNameInfo *info = NULL; |
| 4574 |
struct dcerpc_binding_handle *b = p->binding_handle; |
| 4575 |
|
| 4576 |
torture_comment(tctx, "Testing netr_DsRGetDCNameEx2 with no inputs\n"); |
| 4577 |
ZERO_STRUCT(r.in); |
| 4578 |
r.in.flags = DS_RETURN_DNS_NAME; |
| 4579 |
r.out.info = &info; |
| 4580 |
|
| 4581 |
status = dcerpc_netr_DsRGetDCNameEx2_r(b, tctx, &r); |
| 4582 |
torture_assert_ntstatus_ok(tctx, status, "netr_DsRGetDCNameEx2"); |
| 4583 |
torture_assert_werr_ok(tctx, r.out.result, "netr_DsRGetDCNameEx2"); |
| 4584 |
|
| 4585 |
torture_assert_int_equal(tctx, |
| 4586 |
(info->dc_flags & (DS_DNS_CONTROLLER)), |
| 4587 |
DS_DNS_CONTROLLER, |
| 4588 |
"DsRGetDCNameEx2"); |
| 4589 |
torture_assert_int_equal(tctx, |
| 4590 |
(info->dc_flags & (DS_DNS_DOMAIN)), |
| 4591 |
DS_DNS_DOMAIN, |
| 4592 |
"DsRGetDCNameEx2"); |
| 4593 |
torture_assert_int_equal(tctx, |
| 4594 |
(info->dc_flags & (DS_DNS_FOREST_ROOT)), |
| 4595 |
DS_DNS_FOREST_ROOT, |
| 4596 |
"DsRGetDCNameEx2"); |
| 4597 |
|
| 4598 |
r.in.server_unc = talloc_asprintf(tctx, "\\\\%s", dcerpc_server_name(p)); |
| 4599 |
r.in.client_account = NULL; |
| 4600 |
r.in.mask = 0x00000000; |
| 4601 |
r.in.domain_name = lpcfg_dnsdomain(tctx->lp_ctx); |
| 4602 |
r.in.domain_guid = NULL; |
| 4603 |
r.in.site_name = NULL; |
| 4604 |
r.in.flags = DS_RETURN_DNS_NAME; |
| 4605 |
r.out.info = &info; |
| 4606 |
|
| 4607 |
torture_comment(tctx, "Testing netr_DsRGetDCNameEx2 without client account\n"); |
| 4608 |
|
| 4609 |
status = dcerpc_netr_DsRGetDCNameEx2_r(b, tctx, &r); |
| 4610 |
torture_assert_ntstatus_ok(tctx, status, "netr_DsRGetDCNameEx2"); |
| 4611 |
torture_assert_werr_ok(tctx, r.out.result, "netr_DsRGetDCNameEx2"); |
| 4612 |
|
| 4613 |
r.in.domain_name = lpcfg_workgroup(tctx->lp_ctx); |
| 4614 |
r.in.flags = 0; |
| 4615 |
|
| 4616 |
status = dcerpc_netr_DsRGetDCNameEx2_r(b, tctx, &r); |
| 4617 |
torture_assert_ntstatus_ok(tctx, status, "netr_DsRGetDCNameEx2"); |
| 4618 |
torture_assert_werr_ok(tctx, r.out.result, "netr_DsRGetDCNameEx2"); |
| 4619 |
|
| 4620 |
torture_assert_int_equal(tctx, |
| 4621 |
(info->dc_flags & (DS_DNS_CONTROLLER)), 0, |
| 4622 |
"DsRGetDCNameEx2"); |
| 4623 |
torture_assert_int_equal(tctx, |
| 4624 |
(info->dc_flags & (DS_DNS_DOMAIN)), 0, |
| 4625 |
"DsRGetDCNameEx2"); |
| 4626 |
torture_assert_int_equal(tctx, |
| 4627 |
(info->dc_flags & (DS_DNS_FOREST_ROOT)), |
| 4628 |
DS_DNS_FOREST_ROOT, |
| 4629 |
"DsRGetDCNameEx2"); |
| 4630 |
|
| 4631 |
if (strcasecmp(info->dc_site_name, info->client_site_name) == 0) { |
| 4632 |
torture_assert_int_equal(tctx, |
| 4633 |
(info->dc_flags & (DS_SERVER_CLOSEST)), |
| 4634 |
DS_SERVER_CLOSEST, |
| 4635 |
"DsRGetDCNameEx2"); |
| 4636 |
} |
| 4637 |
|
| 4638 |
torture_comment(tctx, "Testing netr_DsRGetDCNameEx2 with client account\n"); |
| 4639 |
r.in.client_account = TEST_MACHINE_NAME"$"; |
| 4640 |
r.in.mask = ACB_SVRTRUST; |
| 4641 |
r.in.flags = DS_RETURN_FLAT_NAME; |
| 4642 |
r.out.info = &info; |
| 4643 |
|
| 4644 |
status = dcerpc_netr_DsRGetDCNameEx2_r(b, tctx, &r); |
| 4645 |
torture_assert_ntstatus_ok(tctx, status, "netr_DsRGetDCNameEx2"); |
| 4646 |
torture_assert_werr_ok(tctx, r.out.result, "netr_DsRGetDCNameEx2"); |
| 4647 |
|
| 4648 |
return test_netr_DsRGetSiteName(p, tctx, info->dc_unc, |
| 4649 |
info->dc_site_name); |
| 4650 |
} |
| 4651 |
|
| 4652 |
/* This is a substitution for "samdb_server_site_name" which relies on the |
| 4653 |
* correct "lp_ctx" and therefore can't be used here. */ |
| 4654 |
static const char *server_site_name(struct torture_context *tctx, |
| 4655 |
struct ldb_context *ldb) |
| 4656 |
{ |
| 4657 |
TALLOC_CTX *tmp_ctx; |
| 4658 |
struct ldb_dn *dn, *server_dn; |
| 4659 |
const struct ldb_val *site_name_val; |
| 4660 |
const char *server_dn_str, *site_name; |
| 4661 |
|
| 4662 |
tmp_ctx = talloc_new(ldb); |
| 4663 |
if (tmp_ctx == NULL) { |
| 4664 |
goto failed; |
| 4665 |
} |
| 4666 |
|
| 4667 |
dn = ldb_dn_new(tmp_ctx, ldb, ""); |
| 4668 |
if (dn == NULL) { |
| 4669 |
goto failed; |
| 4670 |
} |
| 4671 |
|
| 4672 |
server_dn_str = samdb_search_string(ldb, tmp_ctx, dn, "serverName", |
| 4673 |
NULL); |
| 4674 |
if (server_dn_str == NULL) { |
| 4675 |
goto failed; |
| 4676 |
} |
| 4677 |
|
| 4678 |
server_dn = ldb_dn_new(tmp_ctx, ldb, server_dn_str); |
| 4679 |
if (server_dn == NULL) { |
| 4680 |
goto failed; |
| 4681 |
} |
| 4682 |
|
| 4683 |
/* CN=<Server name>, CN=Servers, CN=<Site name>, CN=Sites, ... */ |
| 4684 |
site_name_val = ldb_dn_get_component_val(server_dn, 2); |
| 4685 |
if (site_name_val == NULL) { |
| 4686 |
goto failed; |
| 4687 |
} |
| 4688 |
|
| 4689 |
site_name = (const char *) site_name_val->data; |
| 4690 |
|
| 4691 |
talloc_steal(tctx, site_name); |
| 4692 |
talloc_free(tmp_ctx); |
| 4693 |
|
| 4694 |
return site_name; |
| 4695 |
|
| 4696 |
failed: |
| 4697 |
talloc_free(tmp_ctx); |
| 4698 |
return NULL; |
| 4699 |
} |
| 4700 |
|
| 4701 |
static bool test_netr_DsrGetDcSiteCoverageW(struct torture_context *tctx, |
| 4702 |
struct dcerpc_pipe *p) |
| 4703 |
{ |
| 4704 |
char *url; |
| 4705 |
struct ldb_context *sam_ctx = NULL; |
| 4706 |
NTSTATUS status; |
| 4707 |
struct netr_DsrGetDcSiteCoverageW r; |
| 4708 |
struct DcSitesCtr *ctr = NULL; |
| 4709 |
struct dcerpc_binding_handle *b = p->binding_handle; |
| 4710 |
|
| 4711 |
torture_comment(tctx, "This does only pass with the default site\n"); |
| 4712 |
|
| 4713 |
/* We won't double-check this when we are over 'local' transports */ |
| 4714 |
if (dcerpc_server_name(p)) { |
| 4715 |
/* Set up connection to SAMDB on DC */ |
| 4716 |
url = talloc_asprintf(tctx, "ldap://%s", dcerpc_server_name(p)); |
| 4717 |
sam_ctx = ldb_wrap_connect(tctx, tctx->ev, tctx->lp_ctx, url, |
| 4718 |
NULL, |
| 4719 |
samba_cmdline_get_creds(), |
| 4720 |
0); |
| 4721 |
|
| 4722 |
torture_assert(tctx, sam_ctx, "Connection to the SAMDB on DC failed!"); |
| 4723 |
} |
| 4724 |
|
| 4725 |
r.in.server_name = talloc_asprintf(tctx, "\\\\%s", dcerpc_server_name(p)); |
| 4726 |
r.out.ctr = &ctr; |
| 4727 |
|
| 4728 |
status = dcerpc_netr_DsrGetDcSiteCoverageW_r(b, tctx, &r); |
| 4729 |
torture_assert_ntstatus_ok(tctx, status, "failed"); |
| 4730 |
torture_assert_werr_ok(tctx, r.out.result, "failed"); |
| 4731 |
|
| 4732 |
torture_assert(tctx, ctr->num_sites == 1, |
| 4733 |
"we should per default only get the default site"); |
| 4734 |
if (sam_ctx != NULL) { |
| 4735 |
torture_assert_casestr_equal(tctx, ctr->sites[0].string, |
| 4736 |
server_site_name(tctx, sam_ctx), |
| 4737 |
"didn't return default site"); |
| 4738 |
} |
| 4739 |
|
| 4740 |
return true; |
| 4741 |
} |
| 4742 |
|
| 4743 |
static bool test_netr_DsRAddressToSitenamesW(struct torture_context *tctx, |
| 4744 |
struct dcerpc_pipe *p) |
| 4745 |
{ |
| 4746 |
char *url; |
| 4747 |
struct ldb_context *sam_ctx = NULL; |
| 4748 |
NTSTATUS status; |
| 4749 |
struct netr_DsRAddressToSitenamesW r; |
| 4750 |
struct netr_DsRAddress addrs[6]; |
| 4751 |
struct sockaddr_in *addr; |
| 4752 |
#ifdef HAVE_IPV6 |
| 4753 |
struct sockaddr_in6 *addr6; |
| 4754 |
#endif |
| 4755 |
struct netr_DsRAddressToSitenamesWCtr *ctr; |
| 4756 |
struct dcerpc_binding_handle *b = p->binding_handle; |
| 4757 |
uint32_t i; |
| 4758 |
int ret; |
| 4759 |
|
| 4760 |
torture_comment(tctx, "This does only pass with the default site\n"); |
| 4761 |
|
| 4762 |
/* We won't double-check this when we are over 'local' transports */ |
| 4763 |
if (dcerpc_server_name(p)) { |
| 4764 |
/* Set up connection to SAMDB on DC */ |
| 4765 |
url = talloc_asprintf(tctx, "ldap://%s", dcerpc_server_name(p)); |
| 4766 |
sam_ctx = ldb_wrap_connect(tctx, tctx->ev, tctx->lp_ctx, url, |
| 4767 |
NULL, |
| 4768 |
samba_cmdline_get_creds(), |
| 4769 |
0); |
| 4770 |
|
| 4771 |
torture_assert(tctx, sam_ctx, "Connection to the SAMDB on DC failed!"); |
| 4772 |
} |
| 4773 |
|
| 4774 |
/* First try valid IP addresses */ |
| 4775 |
|
| 4776 |
addrs[0].size = sizeof(struct sockaddr_in); |
| 4777 |
addrs[0].buffer = talloc_zero_array(tctx, uint8_t, addrs[0].size); |
| 4778 |
addr = (struct sockaddr_in *) addrs[0].buffer; |
| 4779 |
addrs[0].buffer[0] = AF_INET; |
| 4780 |
ret = inet_pton(AF_INET, "127.0.0.1", &addr->sin_addr); |
| 4781 |
torture_assert(tctx, ret > 0, "inet_pton failed"); |
| 4782 |
|
| 4783 |
addrs[1].size = sizeof(struct sockaddr_in); |
| 4784 |
addrs[1].buffer = talloc_zero_array(tctx, uint8_t, addrs[1].size); |
| 4785 |
addr = (struct sockaddr_in *) addrs[1].buffer; |
| 4786 |
addrs[1].buffer[0] = AF_INET; |
| 4787 |
ret = inet_pton(AF_INET, "0.0.0.0", &addr->sin_addr); |
| 4788 |
torture_assert(tctx, ret > 0, "inet_pton failed"); |
| 4789 |
|
| 4790 |
addrs[2].size = sizeof(struct sockaddr_in); |
| 4791 |
addrs[2].buffer = talloc_zero_array(tctx, uint8_t, addrs[2].size); |
| 4792 |
addr = (struct sockaddr_in *) addrs[2].buffer; |
| 4793 |
addrs[2].buffer[0] = AF_INET; |
| 4794 |
ret = inet_pton(AF_INET, "255.255.255.255", &addr->sin_addr); |
| 4795 |
torture_assert(tctx, ret > 0, "inet_pton failed"); |
| 4796 |
|
| 4797 |
#ifdef HAVE_IPV6 |
| 4798 |
addrs[3].size = sizeof(struct sockaddr_in6); |
| 4799 |
addrs[3].buffer = talloc_zero_array(tctx, uint8_t, addrs[3].size); |
| 4800 |
addr6 = (struct sockaddr_in6 *) addrs[3].buffer; |
| 4801 |
addrs[3].buffer[0] = AF_INET6; |
| 4802 |
ret = inet_pton(AF_INET6, "::1", &addr6->sin6_addr); |
| 4803 |
torture_assert(tctx, ret > 0, "inet_pton failed"); |
| 4804 |
|
| 4805 |
addrs[4].size = sizeof(struct sockaddr_in6); |
| 4806 |
addrs[4].buffer = talloc_zero_array(tctx, uint8_t, addrs[4].size); |
| 4807 |
addr6 = (struct sockaddr_in6 *) addrs[4].buffer; |
| 4808 |
addrs[4].buffer[0] = AF_INET6; |
| 4809 |
ret = inet_pton(AF_INET6, "::", &addr6->sin6_addr); |
| 4810 |
torture_assert(tctx, ret > 0, "inet_pton failed"); |
| 4811 |
|
| 4812 |
addrs[5].size = sizeof(struct sockaddr_in6); |
| 4813 |
addrs[5].buffer = talloc_zero_array(tctx, uint8_t, addrs[5].size); |
| 4814 |
addr6 = (struct sockaddr_in6 *) addrs[5].buffer; |
| 4815 |
addrs[5].buffer[0] = AF_INET6; |
| 4816 |
ret = inet_pton(AF_INET6, "ff02::1", &addr6->sin6_addr); |
| 4817 |
torture_assert(tctx, ret > 0, "inet_pton failed"); |
| 4818 |
#else |
| 4819 |
/* the test cases are repeated to have exactly 6. This is for |
| 4820 |
* compatibility with IPv4-only machines */ |
| 4821 |
addrs[3].size = sizeof(struct sockaddr_in); |
| 4822 |
addrs[3].buffer = talloc_zero_array(tctx, uint8_t, addrs[3].size); |
| 4823 |
addr = (struct sockaddr_in *) addrs[3].buffer; |
| 4824 |
addrs[3].buffer[0] = AF_INET; |
| 4825 |
ret = inet_pton(AF_INET, "127.0.0.1", &addr->sin_addr); |
| 4826 |
torture_assert(tctx, ret > 0, "inet_pton failed"); |
| 4827 |
|
| 4828 |
addrs[4].size = sizeof(struct sockaddr_in); |
| 4829 |
addrs[4].buffer = talloc_zero_array(tctx, uint8_t, addrs[4].size); |
| 4830 |
addr = (struct sockaddr_in *) addrs[4].buffer; |
| 4831 |
addrs[4].buffer[0] = AF_INET; |
| 4832 |
ret = inet_pton(AF_INET, "0.0.0.0", &addr->sin_addr); |
| 4833 |
torture_assert(tctx, ret > 0, "inet_pton failed"); |
| 4834 |
|
| 4835 |
addrs[5].size = sizeof(struct sockaddr_in); |
| 4836 |
addrs[5].buffer = talloc_zero_array(tctx, uint8_t, addrs[5].size); |
| 4837 |
addr = (struct sockaddr_in *) addrs[5].buffer; |
| 4838 |
addrs[5].buffer[0] = AF_INET; |
| 4839 |
ret = inet_pton(AF_INET, "255.255.255.255", &addr->sin_addr); |
| 4840 |
torture_assert(tctx, ret > 0, "inet_pton failed"); |
| 4841 |
#endif |
| 4842 |
|
| 4843 |
ctr = talloc(tctx, struct netr_DsRAddressToSitenamesWCtr); |
| 4844 |
|
| 4845 |
r.in.server_name = talloc_asprintf(tctx, "\\\\%s", dcerpc_server_name(p)); |
| 4846 |
r.in.count = 6; |
| 4847 |
r.in.addresses = addrs; |
| 4848 |
r.out.ctr = &ctr; |
| 4849 |
|
| 4850 |
status = dcerpc_netr_DsRAddressToSitenamesW_r(b, tctx, &r); |
| 4851 |
torture_assert_ntstatus_ok(tctx, status, "failed"); |
| 4852 |
torture_assert_werr_ok(tctx, r.out.result, "failed"); |
| 4853 |
|
| 4854 |
if (sam_ctx != NULL) { |
| 4855 |
for (i = 0; i < 3; i++) { |
| 4856 |
torture_assert_casestr_equal(tctx, |
| 4857 |
ctr->sitename[i].string, |
| 4858 |
server_site_name(tctx, sam_ctx), |
| 4859 |
"didn't return default site"); |
| 4860 |
} |
| 4861 |
for (i = 3; i < 6; i++) { |
| 4862 |
/* Windows returns "NULL" for the sitename if it isn't |
| 4863 |
* IPv6 configured */ |
| 4864 |
if (torture_setting_bool(tctx, "samba4", false)) { |
| 4865 |
torture_assert_casestr_equal(tctx, |
| 4866 |
ctr->sitename[i].string, |
| 4867 |
server_site_name(tctx, sam_ctx), |
| 4868 |
"didn't return default site"); |
| 4869 |
} |
| 4870 |
} |
| 4871 |
} |
| 4872 |
|
| 4873 |
/* Now try invalid ones (too short buffers) */ |
| 4874 |
|
| 4875 |
addrs[0].size = 0; |
| 4876 |
addrs[1].size = 1; |
| 4877 |
addrs[2].size = 4; |
| 4878 |
|
| 4879 |
addrs[3].size = 0; |
| 4880 |
addrs[4].size = 1; |
| 4881 |
addrs[5].size = 4; |
| 4882 |
|
| 4883 |
status = dcerpc_netr_DsRAddressToSitenamesW_r(b, tctx, &r); |
| 4884 |
torture_assert_ntstatus_ok(tctx, status, "failed"); |
| 4885 |
torture_assert_werr_ok(tctx, r.out.result, "failed"); |
| 4886 |
|
| 4887 |
for (i = 0; i < 6; i++) { |
| 4888 |
torture_assert(tctx, ctr->sitename[i].string == NULL, |
| 4889 |
"sitename should be null"); |
| 4890 |
} |
| 4891 |
|
| 4892 |
/* Now try invalid ones (wrong address types) */ |
| 4893 |
|
| 4894 |
addrs[0].size = 10; |
| 4895 |
addrs[0].buffer[0] = AF_UNSPEC; |
| 4896 |
addrs[1].size = 10; |
| 4897 |
addrs[1].buffer[0] = AF_UNIX; /* AF_LOCAL = AF_UNIX */ |
| 4898 |
addrs[2].size = 10; |
| 4899 |
addrs[2].buffer[0] = AF_UNIX; |
| 4900 |
|
| 4901 |
addrs[3].size = 10; |
| 4902 |
addrs[3].buffer[0] = 250; |
| 4903 |
addrs[4].size = 10; |
| 4904 |
addrs[4].buffer[0] = 251; |
| 4905 |
addrs[5].size = 10; |
| 4906 |
addrs[5].buffer[0] = 252; |
| 4907 |
|
| 4908 |
status = dcerpc_netr_DsRAddressToSitenamesW_r(b, tctx, &r); |
| 4909 |
torture_assert_ntstatus_ok(tctx, status, "failed"); |
| 4910 |
torture_assert_werr_ok(tctx, r.out.result, "failed"); |
| 4911 |
|
| 4912 |
for (i = 0; i < 6; i++) { |
| 4913 |
torture_assert(tctx, ctr->sitename[i].string == NULL, |
| 4914 |
"sitename should be null"); |
| 4915 |
} |
| 4916 |
|
| 4917 |
return true; |
| 4918 |
} |
| 4919 |
|
| 4920 |
static bool test_netr_DsRAddressToSitenamesExW(struct torture_context *tctx, |
| 4921 |
struct dcerpc_pipe *p) |
| 4922 |
{ |
| 4923 |
char *url; |
| 4924 |
struct ldb_context *sam_ctx = NULL; |
| 4925 |
NTSTATUS status; |
| 4926 |
struct netr_DsRAddressToSitenamesExW r; |
| 4927 |
struct netr_DsRAddress addrs[6]; |
| 4928 |
struct sockaddr_in *addr; |
| 4929 |
#ifdef HAVE_IPV6 |
| 4930 |
struct sockaddr_in6 *addr6; |
| 4931 |
#endif |
| 4932 |
struct netr_DsRAddressToSitenamesExWCtr *ctr; |
| 4933 |
struct dcerpc_binding_handle *b = p->binding_handle; |
| 4934 |
uint32_t i; |
| 4935 |
int ret; |
| 4936 |
|
| 4937 |
torture_comment(tctx, "This does pass with the default site\n"); |
| 4938 |
|
| 4939 |
/* We won't double-check this when we are over 'local' transports */ |
| 4940 |
if (dcerpc_server_name(p)) { |
| 4941 |
/* Set up connection to SAMDB on DC */ |
| 4942 |
url = talloc_asprintf(tctx, "ldap://%s", dcerpc_server_name(p)); |
| 4943 |
sam_ctx = ldb_wrap_connect(tctx, tctx->ev, tctx->lp_ctx, url, |
| 4944 |
NULL, |
| 4945 |
samba_cmdline_get_creds(), |
| 4946 |
0); |
| 4947 |
|
| 4948 |
torture_assert(tctx, sam_ctx, "Connection to the SAMDB on DC failed!"); |
| 4949 |
} |
| 4950 |
|
| 4951 |
/* First try valid IP addresses */ |
| 4952 |
|
| 4953 |
addrs[0].size = sizeof(struct sockaddr_in); |
| 4954 |
addrs[0].buffer = talloc_zero_array(tctx, uint8_t, addrs[0].size); |
| 4955 |
addr = (struct sockaddr_in *) addrs[0].buffer; |
| 4956 |
addrs[0].buffer[0] = AF_INET; |
| 4957 |
ret = inet_pton(AF_INET, "127.0.0.1", &addr->sin_addr); |
| 4958 |
torture_assert(tctx, ret > 0, "inet_pton failed"); |
| 4959 |
|
| 4960 |
addrs[1].size = sizeof(struct sockaddr_in); |
| 4961 |
addrs[1].buffer = talloc_zero_array(tctx, uint8_t, addrs[1].size); |
| 4962 |
addr = (struct sockaddr_in *) addrs[1].buffer; |
| 4963 |
addrs[1].buffer[0] = AF_INET; |
| 4964 |
ret = inet_pton(AF_INET, "0.0.0.0", &addr->sin_addr); |
| 4965 |
torture_assert(tctx, ret > 0, "inet_pton failed"); |
| 4966 |
|
| 4967 |
addrs[2].size = sizeof(struct sockaddr_in); |
| 4968 |
addrs[2].buffer = talloc_zero_array(tctx, uint8_t, addrs[2].size); |
| 4969 |
addr = (struct sockaddr_in *) addrs[2].buffer; |
| 4970 |
addrs[2].buffer[0] = AF_INET; |
| 4971 |
ret = inet_pton(AF_INET, "255.255.255.255", &addr->sin_addr); |
| 4972 |
torture_assert(tctx, ret > 0, "inet_pton failed"); |
| 4973 |
|
| 4974 |
#ifdef HAVE_IPV6 |
| 4975 |
addrs[3].size = sizeof(struct sockaddr_in6); |
| 4976 |
addrs[3].buffer = talloc_zero_array(tctx, uint8_t, addrs[3].size); |
| 4977 |
addr6 = (struct sockaddr_in6 *) addrs[3].buffer; |
| 4978 |
addrs[3].buffer[0] = AF_INET6; |
| 4979 |
ret = inet_pton(AF_INET6, "::1", &addr6->sin6_addr); |
| 4980 |
torture_assert(tctx, ret > 0, "inet_pton failed"); |
| 4981 |
|
| 4982 |
addrs[4].size = sizeof(struct sockaddr_in6); |
| 4983 |
addrs[4].buffer = talloc_zero_array(tctx, uint8_t, addrs[4].size); |
| 4984 |
addr6 = (struct sockaddr_in6 *) addrs[4].buffer; |
| 4985 |
addrs[4].buffer[0] = AF_INET6; |
| 4986 |
ret = inet_pton(AF_INET6, "::", &addr6->sin6_addr); |
| 4987 |
torture_assert(tctx, ret > 0, "inet_pton failed"); |
| 4988 |
|
| 4989 |
addrs[5].size = sizeof(struct sockaddr_in6); |
| 4990 |
addrs[5].buffer = talloc_zero_array(tctx, uint8_t, addrs[5].size); |
| 4991 |
addr6 = (struct sockaddr_in6 *) addrs[5].buffer; |
| 4992 |
addrs[5].buffer[0] = AF_INET6; |
| 4993 |
ret = inet_pton(AF_INET6, "ff02::1", &addr6->sin6_addr); |
| 4994 |
torture_assert(tctx, ret > 0, "inet_pton failed"); |
| 4995 |
#else |
| 4996 |
/* the test cases are repeated to have exactly 6. This is for |
| 4997 |
* compatibility with IPv4-only machines */ |
| 4998 |
addrs[3].size = sizeof(struct sockaddr_in); |
| 4999 |
addrs[3].buffer = talloc_zero_array(tctx, uint8_t, addrs[3].size); |
| 5000 |
addr = (struct sockaddr_in *) addrs[3].buffer; |
| 5001 |
addrs[3].buffer[0] = AF_INET; |
| 5002 |
ret = inet_pton(AF_INET, "127.0.0.1", &addr->sin_addr); |
| 5003 |
torture_assert(tctx, ret > 0, "inet_pton failed"); |
| 5004 |
|
| 5005 |
addrs[4].size = sizeof(struct sockaddr_in); |
| 5006 |
addrs[4].buffer = talloc_zero_array(tctx, uint8_t, addrs[4].size); |
| 5007 |
addr = (struct sockaddr_in *) addrs[4].buffer; |
| 5008 |
addrs[4].buffer[0] = AF_INET; |
| 5009 |
ret = inet_pton(AF_INET, "0.0.0.0", &addr->sin_addr); |
| 5010 |
torture_assert(tctx, ret > 0, "inet_pton failed"); |
| 5011 |
|
| 5012 |
addrs[5].size = sizeof(struct sockaddr_in); |
| 5013 |
addrs[5].buffer = talloc_zero_array(tctx, uint8_t, addrs[5].size); |
| 5014 |
addr = (struct sockaddr_in *) addrs[5].buffer; |
| 5015 |
addrs[5].buffer[0] = AF_INET; |
| 5016 |
ret = inet_pton(AF_INET, "255.255.255.255", &addr->sin_addr); |
| 5017 |
torture_assert(tctx, ret > 0, "inet_pton failed"); |
| 5018 |
#endif |
| 5019 |
|
| 5020 |
ctr = talloc(tctx, struct netr_DsRAddressToSitenamesExWCtr); |
| 5021 |
|
| 5022 |
r.in.server_name = talloc_asprintf(tctx, "\\\\%s", dcerpc_server_name(p)); |
| 5023 |
r.in.count = 6; |
| 5024 |
r.in.addresses = addrs; |
| 5025 |
r.out.ctr = &ctr; |
| 5026 |
|
| 5027 |
status = dcerpc_netr_DsRAddressToSitenamesExW_r(b, tctx, &r); |
| 5028 |
torture_assert_ntstatus_ok(tctx, status, "failed"); |
| 5029 |
torture_assert_werr_ok(tctx, r.out.result, "failed"); |
| 5030 |
|
| 5031 |
if (sam_ctx != NULL) { |
| 5032 |
for (i = 0; i < 3; i++) { |
| 5033 |
torture_assert_casestr_equal(tctx, |
| 5034 |
ctr->sitename[i].string, |
| 5035 |
server_site_name(tctx, sam_ctx), |
| 5036 |
"didn't return default site"); |
| 5037 |
torture_assert(tctx, ctr->subnetname[i].string == NULL, |
| 5038 |
"subnet should be null"); |
| 5039 |
} |
| 5040 |
for (i = 3; i < 6; i++) { |
| 5041 |
/* Windows returns "NULL" for the sitename if it isn't |
| 5042 |
* IPv6 configured */ |
| 5043 |
if (torture_setting_bool(tctx, "samba4", false)) { |
| 5044 |
torture_assert_casestr_equal(tctx, |
| 5045 |
ctr->sitename[i].string, |
| 5046 |
server_site_name(tctx, sam_ctx), |
| 5047 |
"didn't return default site"); |
| 5048 |
} |
| 5049 |
torture_assert(tctx, ctr->subnetname[i].string == NULL, |
| 5050 |
"subnet should be null"); |
| 5051 |
} |
| 5052 |
} |
| 5053 |
|
| 5054 |
/* Now try invalid ones (too short buffers) */ |
| 5055 |
|
| 5056 |
addrs[0].size = 0; |
| 5057 |
addrs[1].size = 1; |
| 5058 |
addrs[2].size = 4; |
| 5059 |
|
| 5060 |
addrs[3].size = 0; |
| 5061 |
addrs[4].size = 1; |
| 5062 |
addrs[5].size = 4; |
| 5063 |
|
| 5064 |
status = dcerpc_netr_DsRAddressToSitenamesExW_r(b, tctx, &r); |
| 5065 |
torture_assert_ntstatus_ok(tctx, status, "failed"); |
| 5066 |
torture_assert_werr_ok(tctx, r.out.result, "failed"); |
| 5067 |
|
| 5068 |
for (i = 0; i < 6; i++) { |
| 5069 |
torture_assert(tctx, ctr->sitename[i].string == NULL, |
| 5070 |
"sitename should be null"); |
| 5071 |
torture_assert(tctx, ctr->subnetname[i].string == NULL, |
| 5072 |
"subnet should be null"); |
| 5073 |
} |
| 5074 |
|
| 5075 |
addrs[0].size = 10; |
| 5076 |
addrs[0].buffer[0] = AF_UNSPEC; |
| 5077 |
addrs[1].size = 10; |
| 5078 |
addrs[1].buffer[0] = AF_UNIX; /* AF_LOCAL = AF_UNIX */ |
| 5079 |
addrs[2].size = 10; |
| 5080 |
addrs[2].buffer[0] = AF_UNIX; |
| 5081 |
|
| 5082 |
addrs[3].size = 10; |
| 5083 |
addrs[3].buffer[0] = 250; |
| 5084 |
addrs[4].size = 10; |
| 5085 |
addrs[4].buffer[0] = 251; |
| 5086 |
addrs[5].size = 10; |
| 5087 |
addrs[5].buffer[0] = 252; |
| 5088 |
|
| 5089 |
status = dcerpc_netr_DsRAddressToSitenamesExW_r(b, tctx, &r); |
| 5090 |
torture_assert_ntstatus_ok(tctx, status, "failed"); |
| 5091 |
torture_assert_werr_ok(tctx, r.out.result, "failed"); |
| 5092 |
|
| 5093 |
for (i = 0; i < 6; i++) { |
| 5094 |
torture_assert(tctx, ctr->sitename[i].string == NULL, |
| 5095 |
"sitename should be null"); |
| 5096 |
torture_assert(tctx, ctr->subnetname[i].string == NULL, |
| 5097 |
"subnet should be null"); |
| 5098 |
} |
| 5099 |
|
| 5100 |
return true; |
| 5101 |
} |
| 5102 |
|
| 5103 |
static bool test_netr_ServerGetTrustInfo_flags(struct torture_context *tctx, |
| 5104 |
struct dcerpc_pipe *p1, |
| 5105 |
struct cli_credentials *machine_credentials, |
| 5106 |
uint32_t negotiate_flags) |
| 5107 |
{ |
| 5108 |
struct netr_ServerGetTrustInfo r; |
| 5109 |
|
| 5110 |
struct netr_Authenticator a; |
| 5111 |
struct netr_Authenticator return_authenticator; |
| 5112 |
struct samr_Password new_owf_password; |
| 5113 |
struct samr_Password old_owf_password; |
| 5114 |
struct netr_TrustInfo *trust_info; |
| 5115 |
|
| 5116 |
struct netlogon_creds_CredentialState *creds; |
| 5117 |
struct dcerpc_pipe *p = NULL; |
| 5118 |
struct dcerpc_binding_handle *b = NULL; |
| 5119 |
|
| 5120 |
struct samr_Password nt_hash; |
| 5121 |
enum dcerpc_AuthType auth_type = DCERPC_AUTH_TYPE_NONE; |
| 5122 |
enum dcerpc_AuthLevel auth_level = DCERPC_AUTH_LEVEL_NONE; |
| 5123 |
NTSTATUS status; |
| 5124 |
|
| 5125 |
if (!test_SetupCredentials3(p1, tctx, negotiate_flags, |
| 5126 |
machine_credentials, &creds)) { |
| 5127 |
return false; |
| 5128 |
} |
| 5129 |
if (!test_SetupCredentialsPipe(p1, tctx, machine_credentials, creds, |
| 5130 |
DCERPC_SIGN | DCERPC_SEAL, &p)) { |
| 5131 |
return false; |
| 5132 |
} |
| 5133 |
b = p->binding_handle; |
| 5134 |
|
| 5135 |
netlogon_creds_client_authenticator(creds, &a); |
| 5136 |
|
| 5137 |
r.in.server_name = talloc_asprintf(tctx, "\\\\%s", dcerpc_server_name(p)); |
| 5138 |
r.in.account_name = talloc_asprintf(tctx, "%s$", TEST_MACHINE_NAME); |
| 5139 |
r.in.secure_channel_type = cli_credentials_get_secure_channel_type(machine_credentials); |
| 5140 |
r.in.computer_name = TEST_MACHINE_NAME; |
| 5141 |
r.in.credential = &a; |
| 5142 |
|
| 5143 |
r.out.return_authenticator = &return_authenticator; |
| 5144 |
r.out.new_owf_password = &new_owf_password; |
| 5145 |
r.out.old_owf_password = &old_owf_password; |
| 5146 |
r.out.trust_info = &trust_info; |
| 5147 |
|
| 5148 |
torture_assert_ntstatus_ok(tctx, dcerpc_netr_ServerGetTrustInfo_r(b, tctx, &r), |
| 5149 |
"ServerGetTrustInfo failed"); |
| 5150 |
torture_assert_ntstatus_ok(tctx, r.out.result, "ServerGetTrustInfo failed"); |
| 5151 |
torture_assert(tctx, netlogon_creds_client_check(creds, &return_authenticator.cred), "Credential chaining failed"); |
| 5152 |
|
| 5153 |
E_md4hash(cli_credentials_get_password(machine_credentials), nt_hash.hash); |
| 5154 |
|
| 5155 |
dcerpc_binding_handle_auth_info(b, &auth_type, &auth_level); |
| 5156 |
status = netlogon_creds_decrypt_samr_Password(creds, |
| 5157 |
&new_owf_password, |
| 5158 |
auth_type, |
| 5159 |
auth_level); |
| 5160 |
torture_assert_ntstatus_ok(tctx, status, "decrypt_samr_Password"); |
| 5161 |
status = netlogon_creds_decrypt_samr_Password(creds, |
| 5162 |
&old_owf_password, |
| 5163 |
auth_type, |
| 5164 |
auth_level); |
| 5165 |
torture_assert_ntstatus_ok(tctx, status, "decrypt_samr_Password"); |
| 5166 |
|
| 5167 |
dump_data(1, new_owf_password.hash, 16); |
| 5168 |
dump_data(1, nt_hash.hash, 16); |
| 5169 |
|
| 5170 |
torture_assert_mem_equal(tctx, new_owf_password.hash, nt_hash.hash, 16, |
| 5171 |
"received unexpected owf password\n"); |
| 5172 |
|
| 5173 |
return true; |
| 5174 |
} |
| 5175 |
|
| 5176 |
static bool test_netr_ServerGetTrustInfo(struct torture_context *tctx, |
| 5177 |
struct dcerpc_pipe *p, |
| 5178 |
struct cli_credentials *machine_credentials) |
| 5179 |
{ |
| 5180 |
return test_netr_ServerGetTrustInfo_flags(tctx, p, machine_credentials, |
| 5181 |
NETLOGON_NEG_AUTH2_ADS_FLAGS); |
| 5182 |
} |
| 5183 |
|
| 5184 |
static bool test_netr_ServerGetTrustInfo_AES(struct torture_context *tctx, |
| 5185 |
struct dcerpc_pipe *p, |
| 5186 |
struct cli_credentials *machine_credentials) |
| 5187 |
{ |
| 5188 |
return test_netr_ServerGetTrustInfo_flags(tctx, p, machine_credentials, |
| 5189 |
NETLOGON_NEG_AUTH2_ADS_FLAGS | NETLOGON_NEG_SUPPORTS_AES); |
| 5190 |
} |
| 5191 |
|
| 5192 |
static bool test_GetDomainInfo(struct torture_context *tctx, |
| 5193 |
struct dcerpc_pipe *p1, |
| 5194 |
struct cli_credentials *machine_credentials) |
| 5195 |
{ |
| 5196 |
struct netr_LogonGetDomainInfo r; |
| 5197 |
struct netr_WorkstationInformation q1; |
| 5198 |
struct netr_Authenticator a; |
| 5199 |
struct netlogon_creds_CredentialState *creds; |
| 5200 |
struct netr_OsVersion os; |
| 5201 |
union netr_WorkstationInfo query; |
| 5202 |
union netr_DomainInfo info; |
| 5203 |
const char* const attrs[] = { "dNSHostName", "operatingSystem", |
| 5204 |
"operatingSystemServicePack", "operatingSystemVersion", |
| 5205 |
"servicePrincipalName", NULL }; |
| 5206 |
char *url; |
| 5207 |
struct ldb_context *sam_ctx = NULL; |
| 5208 |
struct ldb_message **res; |
| 5209 |
struct ldb_message_element *spn_el; |
| 5210 |
int ret, i; |
| 5211 |
char *version_str; |
| 5212 |
const char *old_dnsname = NULL; |
| 5213 |
char **spns = NULL; |
| 5214 |
int num_spns = 0; |
| 5215 |
char *temp_str = NULL; |
| 5216 |
char *temp_str2 = NULL; |
| 5217 |
struct dcerpc_pipe *p = NULL; |
| 5218 |
struct dcerpc_binding_handle *b = NULL; |
| 5219 |
struct netr_OneDomainInfo *odi1 = NULL; |
| 5220 |
struct netr_OneDomainInfo *odi2 = NULL; |
| 5221 |
struct netr_trust_extension_info *tex2 = NULL; |
| 5222 |
|
| 5223 |
torture_comment(tctx, "Testing netr_LogonGetDomainInfo\n"); |
| 5224 |
|
| 5225 |
if (!test_SetupCredentials3(p1, tctx, NETLOGON_NEG_AUTH2_ADS_FLAGS | NETLOGON_NEG_SUPPORTS_AES, |
| 5226 |
machine_credentials, &creds)) { |
| 5227 |
return false; |
| 5228 |
} |
| 5229 |
if (!test_SetupCredentialsPipe(p1, tctx, machine_credentials, creds, |
| 5230 |
DCERPC_SIGN | DCERPC_SEAL, &p)) { |
| 5231 |
return false; |
| 5232 |
} |
| 5233 |
b = p->binding_handle; |
| 5234 |
|
| 5235 |
/* We won't double-check this when we are over 'local' transports */ |
| 5236 |
if (dcerpc_server_name(p)) { |
| 5237 |
/* Set up connection to SAMDB on DC */ |
| 5238 |
url = talloc_asprintf(tctx, "ldap://%s", dcerpc_server_name(p)); |
| 5239 |
sam_ctx = ldb_wrap_connect(tctx, tctx->ev, tctx->lp_ctx, url, |
| 5240 |
NULL, |
| 5241 |
samba_cmdline_get_creds(), |
| 5242 |
0); |
| 5243 |
|
| 5244 |
torture_assert(tctx, sam_ctx, "Connection to the SAMDB on DC failed!"); |
| 5245 |
} |
| 5246 |
|
| 5247 |
torture_comment(tctx, "Testing netr_LogonGetDomainInfo 1st call (no variation of DNS hostname)\n"); |
| 5248 |
netlogon_creds_client_authenticator(creds, &a); |
| 5249 |
|
| 5250 |
ZERO_STRUCT(r); |
| 5251 |
r.in.server_name = talloc_asprintf(tctx, "\\\\%s", dcerpc_server_name(p)); |
| 5252 |
r.in.computer_name = TEST_MACHINE_NAME; |
| 5253 |
r.in.credential = &a; |
| 5254 |
r.in.level = 1; |
| 5255 |
r.in.return_authenticator = &a; |
| 5256 |
r.in.query = &query; |
| 5257 |
r.out.return_authenticator = &a; |
| 5258 |
r.out.info = &info; |
| 5259 |
|
| 5260 |
ZERO_STRUCT(os); |
| 5261 |
os.os.MajorVersion = 123; |
| 5262 |
os.os.MinorVersion = 456; |
| 5263 |
os.os.BuildNumber = 789; |
| 5264 |
os.os.CSDVersion = "Service Pack 10"; |
| 5265 |
os.os.ServicePackMajor = 10; |
| 5266 |
os.os.ServicePackMinor = 1; |
| 5267 |
os.os.SuiteMask = NETR_VER_SUITE_SINGLEUSERTS; |
| 5268 |
os.os.ProductType = NETR_VER_NT_SERVER; |
| 5269 |
os.os.Reserved = 0; |
| 5270 |
|
| 5271 |
version_str = talloc_asprintf(tctx, "%d.%d (%d)", os.os.MajorVersion, |
| 5272 |
os.os.MinorVersion, os.os.BuildNumber); |
| 5273 |
|
| 5274 |
ZERO_STRUCT(q1); |
| 5275 |
q1.dns_hostname = talloc_asprintf(tctx, "%s.%s", TEST_MACHINE_NAME, |
| 5276 |
lpcfg_dnsdomain(tctx->lp_ctx)); |
| 5277 |
q1.sitename = "Default-First-Site-Name"; |
| 5278 |
q1.os_version.os = &os; |
| 5279 |
q1.os_name.string = talloc_asprintf(tctx, |
| 5280 |
"Tortured by Samba4 RPC-NETLOGON: %s", |
| 5281 |
timestring(tctx, time(NULL))); |
| 5282 |
|
| 5283 |
/* The workstation handles the "servicePrincipalName" and DNS hostname |
| 5284 |
updates */ |
| 5285 |
q1.workstation_flags = NETR_WS_FLAG_HANDLES_SPN_UPDATE; |
| 5286 |
|
| 5287 |
query.workstation_info = &q1; |
| 5288 |
|
| 5289 |
if (sam_ctx) { |
| 5290 |
/* Gets back the old DNS hostname in AD */ |
| 5291 |
ret = gendb_search(sam_ctx, tctx, NULL, &res, attrs, |
| 5292 |
"(sAMAccountName=%s$)", TEST_MACHINE_NAME); |
| 5293 |
old_dnsname = |
| 5294 |
ldb_msg_find_attr_as_string(res[0], "dNSHostName", NULL); |
| 5295 |
|
| 5296 |
/* Gets back the "servicePrincipalName"s in AD */ |
| 5297 |
spn_el = ldb_msg_find_element(res[0], "servicePrincipalName"); |
| 5298 |
if (spn_el != NULL) { |
| 5299 |
for (i=0; i < spn_el->num_values; i++) { |
| 5300 |
spns = talloc_realloc(tctx, spns, char *, i + 1); |
| 5301 |
spns[i] = (char *) spn_el->values[i].data; |
| 5302 |
} |
| 5303 |
num_spns = i; |
| 5304 |
} |
| 5305 |
} |
| 5306 |
|
| 5307 |
torture_assert_ntstatus_ok(tctx, dcerpc_netr_LogonGetDomainInfo_r(b, tctx, &r), |
| 5308 |
"LogonGetDomainInfo failed"); |
| 5309 |
torture_assert_ntstatus_ok(tctx, r.out.result, "LogonGetDomainInfo failed"); |
| 5310 |
torture_assert(tctx, netlogon_creds_client_check(creds, &a.cred), "Credential chaining failed"); |
| 5311 |
|
| 5312 |
smb_msleep(250); |
| 5313 |
|
| 5314 |
if (sam_ctx) { |
| 5315 |
/* AD workstation infos entry check */ |
| 5316 |
ret = gendb_search(sam_ctx, tctx, NULL, &res, attrs, |
| 5317 |
"(sAMAccountName=%s$)", TEST_MACHINE_NAME); |
| 5318 |
torture_assert(tctx, ret == 1, "Test machine account not found in SAMDB on DC! Has the workstation been joined?"); |
| 5319 |
torture_assert_str_equal(tctx, |
| 5320 |
ldb_msg_find_attr_as_string(res[0], "operatingSystem", NULL), |
| 5321 |
q1.os_name.string, "'operatingSystem' wrong!"); |
| 5322 |
torture_assert_str_equal(tctx, |
| 5323 |
ldb_msg_find_attr_as_string(res[0], "operatingSystemServicePack", NULL), |
| 5324 |
os.os.CSDVersion, "'operatingSystemServicePack' wrong!"); |
| 5325 |
torture_assert_str_equal(tctx, |
| 5326 |
ldb_msg_find_attr_as_string(res[0], "operatingSystemVersion", NULL), |
| 5327 |
version_str, "'operatingSystemVersion' wrong!"); |
| 5328 |
|
| 5329 |
if (old_dnsname != NULL) { |
| 5330 |
/* If before a DNS hostname was set then it should remain |
| 5331 |
the same in combination with the "servicePrincipalName"s. |
| 5332 |
The DNS hostname should also be returned by our |
| 5333 |
"LogonGetDomainInfo" call (in the domain info structure). */ |
| 5334 |
|
| 5335 |
torture_assert_str_equal(tctx, |
| 5336 |
ldb_msg_find_attr_as_string(res[0], "dNSHostName", NULL), |
| 5337 |
old_dnsname, "'DNS hostname' was not set!"); |
| 5338 |
|
| 5339 |
spn_el = ldb_msg_find_element(res[0], "servicePrincipalName"); |
| 5340 |
torture_assert(tctx, ((spns != NULL) && (spn_el != NULL)), |
| 5341 |
"'servicePrincipalName's not set!"); |
| 5342 |
torture_assert(tctx, spn_el->num_values == num_spns, |
| 5343 |
"'servicePrincipalName's incorrect!"); |
| 5344 |
for (i=0; (i < spn_el->num_values) && (i < num_spns); i++) |
| 5345 |
torture_assert_str_equal(tctx, |
| 5346 |
(char *) spn_el->values[i].data, |
| 5347 |
spns[i], "'servicePrincipalName's incorrect!"); |
| 5348 |
|
| 5349 |
torture_assert_str_equal(tctx, |
| 5350 |
info.domain_info->dns_hostname.string, |
| 5351 |
old_dnsname, |
| 5352 |
"Out 'DNS hostname' doesn't match the old one!"); |
| 5353 |
} else { |
| 5354 |
/* If no DNS hostname was set then also now none should be set, |
| 5355 |
the "servicePrincipalName"s should remain empty and no DNS |
| 5356 |
hostname should be returned by our "LogonGetDomainInfo" |
| 5357 |
call (in the domain info structure). */ |
| 5358 |
|
| 5359 |
torture_assert(tctx, |
| 5360 |
ldb_msg_find_attr_as_string(res[0], "dNSHostName", NULL) == NULL, |
| 5361 |
"'DNS hostname' was set!"); |
| 5362 |
|
| 5363 |
spn_el = ldb_msg_find_element(res[0], "servicePrincipalName"); |
| 5364 |
torture_assert(tctx, ((spns == NULL) && (spn_el == NULL)), |
| 5365 |
"'servicePrincipalName's were set!"); |
| 5366 |
|
| 5367 |
torture_assert(tctx, |
| 5368 |
info.domain_info->dns_hostname.string == NULL, |
| 5369 |
"Out 'DNS host name' was set!"); |
| 5370 |
} |
| 5371 |
} |
| 5372 |
|
| 5373 |
/* Checks "workstation flags" */ |
| 5374 |
torture_assert(tctx, |
| 5375 |
info.domain_info->workstation_flags |
| 5376 |
== NETR_WS_FLAG_HANDLES_SPN_UPDATE, |
| 5377 |
"Out 'workstation flags' don't match!"); |
| 5378 |
|
| 5379 |
|
| 5380 |
torture_comment(tctx, "Testing netr_LogonGetDomainInfo 2nd call (variation of DNS hostname doesn't work)\n"); |
| 5381 |
netlogon_creds_client_authenticator(creds, &a); |
| 5382 |
|
| 5383 |
/* Wipe out the CSDVersion, and prove which values still 'stick' */ |
| 5384 |
os.os.CSDVersion = ""; |
| 5385 |
|
| 5386 |
/* Change also the DNS hostname to test differences in behaviour */ |
| 5387 |
talloc_free(discard_const_p(char, q1.dns_hostname)); |
| 5388 |
q1.dns_hostname = talloc_asprintf(tctx, "%s2.%s", TEST_MACHINE_NAME, |
| 5389 |
lpcfg_dnsdomain(tctx->lp_ctx)); |
| 5390 |
|
| 5391 |
/* The workstation handles the "servicePrincipalName" and DNS hostname |
| 5392 |
updates */ |
| 5393 |
q1.workstation_flags = NETR_WS_FLAG_HANDLES_SPN_UPDATE; |
| 5394 |
|
| 5395 |
torture_assert_ntstatus_ok(tctx, dcerpc_netr_LogonGetDomainInfo_r(b, tctx, &r), |
| 5396 |
"LogonGetDomainInfo failed"); |
| 5397 |
torture_assert_ntstatus_ok(tctx, r.out.result, "LogonGetDomainInfo failed"); |
| 5398 |
|
| 5399 |
torture_assert(tctx, netlogon_creds_client_check(creds, &a.cred), "Credential chaining failed"); |
| 5400 |
|
| 5401 |
smb_msleep(250); |
| 5402 |
|
| 5403 |
if (sam_ctx) { |
| 5404 |
/* AD workstation infos entry check */ |
| 5405 |
ret = gendb_search(sam_ctx, tctx, NULL, &res, attrs, |
| 5406 |
"(sAMAccountName=%s$)", TEST_MACHINE_NAME); |
| 5407 |
torture_assert(tctx, ret == 1, "Test machine account not found in SAMDB on DC! Has the workstation been joined?"); |
| 5408 |
|
| 5409 |
torture_assert_str_equal(tctx, |
| 5410 |
ldb_msg_find_attr_as_string(res[0], "operatingSystem", NULL), |
| 5411 |
q1.os_name.string, "'operatingSystem' should stick!"); |
| 5412 |
torture_assert(tctx, |
| 5413 |
ldb_msg_find_attr_as_string(res[0], "operatingSystemServicePack", NULL) == NULL, |
| 5414 |
"'operatingSystemServicePack' shouldn't stick!"); |
| 5415 |
torture_assert_str_equal(tctx, |
| 5416 |
ldb_msg_find_attr_as_string(res[0], "operatingSystemVersion", NULL), |
| 5417 |
version_str, "'operatingSystemVersion' wrong!"); |
| 5418 |
|
| 5419 |
/* The DNS host name shouldn't have been updated by the server */ |
| 5420 |
|
| 5421 |
torture_assert_str_equal(tctx, |
| 5422 |
ldb_msg_find_attr_as_string(res[0], "dNSHostName", NULL), |
| 5423 |
old_dnsname, "'DNS host name' did change!"); |
| 5424 |
|
| 5425 |
/* Find the two "servicePrincipalName"s which the DC shouldn't have been |
| 5426 |
updated (HOST/<Netbios name> and HOST/<FQDN name>) - see MS-NRPC |
| 5427 |
3.5.4.3.9 */ |
| 5428 |
spn_el = ldb_msg_find_element(res[0], "servicePrincipalName"); |
| 5429 |
torture_assert(tctx, spn_el != NULL, |
| 5430 |
"There should exist 'servicePrincipalName's in AD!"); |
| 5431 |
temp_str = talloc_asprintf(tctx, "HOST/%s", TEST_MACHINE_NAME); |
| 5432 |
for (i=0; i < spn_el->num_values; i++) |
| 5433 |
if (strcasecmp((char *) spn_el->values[i].data, temp_str) == 0) |
| 5434 |
break; |
| 5435 |
torture_assert(tctx, i != spn_el->num_values, |
| 5436 |
"'servicePrincipalName' HOST/<Netbios name> not found!"); |
| 5437 |
temp_str = talloc_asprintf(tctx, "HOST/%s", old_dnsname); |
| 5438 |
for (i=0; i < spn_el->num_values; i++) |
| 5439 |
if (strcasecmp((char *) spn_el->values[i].data, temp_str) == 0) |
| 5440 |
break; |
| 5441 |
torture_assert(tctx, i != spn_el->num_values, |
| 5442 |
"'servicePrincipalName' HOST/<FQDN name> not found!"); |
| 5443 |
|
| 5444 |
/* Check that the out DNS hostname was set properly */ |
| 5445 |
torture_assert_str_equal(tctx, info.domain_info->dns_hostname.string, |
| 5446 |
old_dnsname, "Out 'DNS hostname' doesn't match the old one!"); |
| 5447 |
} |
| 5448 |
|
| 5449 |
/* Checks "workstation flags" */ |
| 5450 |
torture_assert(tctx, |
| 5451 |
info.domain_info->workstation_flags == NETR_WS_FLAG_HANDLES_SPN_UPDATE, |
| 5452 |
"Out 'workstation flags' don't match!"); |
| 5453 |
|
| 5454 |
|
| 5455 |
/* Now try the same but the workstation flags set to 0 */ |
| 5456 |
|
| 5457 |
torture_comment(tctx, "Testing netr_LogonGetDomainInfo 3rd call (variation of DNS hostname doesn't work)\n"); |
| 5458 |
netlogon_creds_client_authenticator(creds, &a); |
| 5459 |
|
| 5460 |
/* Change also the DNS hostname to test differences in behaviour */ |
| 5461 |
talloc_free(discard_const_p(char, q1.dns_hostname)); |
| 5462 |
q1.dns_hostname = talloc_asprintf(tctx, "%s2.%s", TEST_MACHINE_NAME, |
| 5463 |
lpcfg_dnsdomain(tctx->lp_ctx)); |
| 5464 |
|
| 5465 |
/* Wipe out the osVersion, and prove which values still 'stick' */ |
| 5466 |
q1.os_version.os = NULL; |
| 5467 |
|
| 5468 |
/* Let the DC handle the "servicePrincipalName" and DNS hostname |
| 5469 |
updates */ |
| 5470 |
q1.workstation_flags = 0; |
| 5471 |
|
| 5472 |
torture_assert_ntstatus_ok(tctx, dcerpc_netr_LogonGetDomainInfo_r(b, tctx, &r), |
| 5473 |
"LogonGetDomainInfo failed"); |
| 5474 |
torture_assert_ntstatus_ok(tctx, r.out.result, "LogonGetDomainInfo failed"); |
| 5475 |
torture_assert(tctx, netlogon_creds_client_check(creds, &a.cred), "Credential chaining failed"); |
| 5476 |
|
| 5477 |
smb_msleep(250); |
| 5478 |
|
| 5479 |
if (sam_ctx) { |
| 5480 |
/* AD workstation infos entry check */ |
| 5481 |
ret = gendb_search(sam_ctx, tctx, NULL, &res, attrs, |
| 5482 |
"(sAMAccountName=%s$)", TEST_MACHINE_NAME); |
| 5483 |
torture_assert(tctx, ret == 1, "Test machine account not found in SAMDB on DC! Has the workstation been joined?"); |
| 5484 |
|
| 5485 |
torture_assert_str_equal(tctx, |
| 5486 |
ldb_msg_find_attr_as_string(res[0], "operatingSystem", NULL), |
| 5487 |
q1.os_name.string, "'operatingSystem' should stick!"); |
| 5488 |
torture_assert(tctx, |
| 5489 |
ldb_msg_find_attr_as_string(res[0], "operatingSystemServicePack", NULL) == NULL, |
| 5490 |
"'operatingSystemServicePack' shouldn't stick!"); |
| 5491 |
torture_assert_str_equal(tctx, |
| 5492 |
ldb_msg_find_attr_as_string(res[0], "operatingSystemVersion", NULL), |
| 5493 |
version_str, "'operatingSystemVersion' wrong!"); |
| 5494 |
|
| 5495 |
/* The DNS host name shouldn't have been updated by the server */ |
| 5496 |
|
| 5497 |
torture_assert_str_equal(tctx, |
| 5498 |
ldb_msg_find_attr_as_string(res[0], "dNSHostName", NULL), |
| 5499 |
old_dnsname, "'DNS host name' did change!"); |
| 5500 |
|
| 5501 |
/* Find the two "servicePrincipalName"s which the DC shouldn't have been |
| 5502 |
updated (HOST/<Netbios name> and HOST/<FQDN name>) - see MS-NRPC |
| 5503 |
3.5.4.3.9 */ |
| 5504 |
spn_el = ldb_msg_find_element(res[0], "servicePrincipalName"); |
| 5505 |
torture_assert(tctx, spn_el != NULL, |
| 5506 |
"There should exist 'servicePrincipalName's in AD!"); |
| 5507 |
temp_str = talloc_asprintf(tctx, "HOST/%s", TEST_MACHINE_NAME); |
| 5508 |
for (i=0; i < spn_el->num_values; i++) |
| 5509 |
if (strcasecmp((char *) spn_el->values[i].data, temp_str) == 0) |
| 5510 |
break; |
| 5511 |
torture_assert(tctx, i != spn_el->num_values, |
| 5512 |
"'servicePrincipalName' HOST/<Netbios name> not found!"); |
| 5513 |
temp_str = talloc_asprintf(tctx, "HOST/%s", old_dnsname); |
| 5514 |
for (i=0; i < spn_el->num_values; i++) |
| 5515 |
if (strcasecmp((char *) spn_el->values[i].data, temp_str) == 0) |
| 5516 |
break; |
| 5517 |
torture_assert(tctx, i != spn_el->num_values, |
| 5518 |
"'servicePrincipalName' HOST/<FQDN name> not found!"); |
| 5519 |
|
| 5520 |
/* Here the server gives us NULL as the out DNS hostname */ |
| 5521 |
torture_assert(tctx, info.domain_info->dns_hostname.string == NULL, |
| 5522 |
"Out 'DNS hostname' should be NULL!"); |
| 5523 |
} |
| 5524 |
|
| 5525 |
/* Checks "workstation flags" */ |
| 5526 |
torture_assert(tctx, |
| 5527 |
info.domain_info->workstation_flags == 0, |
| 5528 |
"Out 'workstation flags' don't match!"); |
| 5529 |
|
| 5530 |
|
| 5531 |
torture_comment(tctx, "Testing netr_LogonGetDomainInfo 4th call (verification of DNS hostname and check for trusted domains)\n"); |
| 5532 |
netlogon_creds_client_authenticator(creds, &a); |
| 5533 |
|
| 5534 |
/* Put the DNS hostname back */ |
| 5535 |
talloc_free(discard_const_p(char, q1.dns_hostname)); |
| 5536 |
q1.dns_hostname = talloc_asprintf(tctx, "%s.%s", TEST_MACHINE_NAME, |
| 5537 |
lpcfg_dnsdomain(tctx->lp_ctx)); |
| 5538 |
|
| 5539 |
/* The workstation handles the "servicePrincipalName" and DNS hostname |
| 5540 |
updates */ |
| 5541 |
q1.workstation_flags = NETR_WS_FLAG_HANDLES_SPN_UPDATE; |
| 5542 |
|
| 5543 |
torture_assert_ntstatus_ok(tctx, dcerpc_netr_LogonGetDomainInfo_r(b, tctx, &r), |
| 5544 |
"LogonGetDomainInfo failed"); |
| 5545 |
torture_assert_ntstatus_ok(tctx, r.out.result, "LogonGetDomainInfo failed"); |
| 5546 |
torture_assert(tctx, netlogon_creds_client_check(creds, &a.cred), "Credential chaining failed"); |
| 5547 |
|
| 5548 |
smb_msleep(250); |
| 5549 |
|
| 5550 |
/* Now the in/out DNS hostnames should be the same */ |
| 5551 |
torture_assert_str_equal(tctx, |
| 5552 |
info.domain_info->dns_hostname.string, |
| 5553 |
query.workstation_info->dns_hostname, |
| 5554 |
"In/Out 'DNS hostnames' don't match!"); |
| 5555 |
old_dnsname = info.domain_info->dns_hostname.string; |
| 5556 |
|
| 5557 |
/* Checks "workstation flags" */ |
| 5558 |
torture_assert(tctx, |
| 5559 |
info.domain_info->workstation_flags |
| 5560 |
== NETR_WS_FLAG_HANDLES_SPN_UPDATE, |
| 5561 |
"Out 'workstation flags' don't match!"); |
| 5562 |
|
| 5563 |
/* Checks for trusted domains */ |
| 5564 |
torture_assert(tctx, |
| 5565 |
(info.domain_info->trusted_domain_count != 0) |
| 5566 |
&& (info.domain_info->trusted_domains != NULL), |
| 5567 |
"Trusted domains have been requested!"); |
| 5568 |
|
| 5569 |
|
| 5570 |
torture_comment(tctx, "Testing netr_LogonGetDomainInfo 5th call (check for trusted domains)\n"); |
| 5571 |
netlogon_creds_client_authenticator(creds, &a); |
| 5572 |
|
| 5573 |
/* The workstation handles the "servicePrincipalName" and DNS hostname |
| 5574 |
updates and requests inbound trusts */ |
| 5575 |
q1.workstation_flags = NETR_WS_FLAG_HANDLES_SPN_UPDATE |
| 5576 |
| NETR_WS_FLAG_HANDLES_INBOUND_TRUSTS; |
| 5577 |
|
| 5578 |
torture_assert_ntstatus_ok(tctx, dcerpc_netr_LogonGetDomainInfo_r(b, tctx, &r), |
| 5579 |
"LogonGetDomainInfo failed"); |
| 5580 |
torture_assert_ntstatus_ok(tctx, r.out.result, "LogonGetDomainInfo failed"); |
| 5581 |
torture_assert(tctx, netlogon_creds_client_check(creds, &a.cred), "Credential chaining failed"); |
| 5582 |
|
| 5583 |
smb_msleep(250); |
| 5584 |
|
| 5585 |
/* Checks "workstation flags" */ |
| 5586 |
torture_assert(tctx, |
| 5587 |
info.domain_info->workstation_flags |
| 5588 |
== (NETR_WS_FLAG_HANDLES_SPN_UPDATE |
| 5589 |
| NETR_WS_FLAG_HANDLES_INBOUND_TRUSTS), |
| 5590 |
"Out 'workstation flags' don't match!"); |
| 5591 |
|
| 5592 |
/* Checks for trusted domains */ |
| 5593 |
torture_assert(tctx, |
| 5594 |
(info.domain_info->trusted_domain_count != 0) |
| 5595 |
&& (info.domain_info->trusted_domains != NULL), |
| 5596 |
"Trusted domains have been requested!"); |
| 5597 |
|
| 5598 |
odi1 = &info.domain_info->primary_domain; |
| 5599 |
|
| 5600 |
torture_assert(tctx, !GUID_all_zero(&odi1->domain_guid), |
| 5601 |
"primary domain_guid needs to be valid"); |
| 5602 |
|
| 5603 |
for (i=0; i < info.domain_info->trusted_domain_count; i++) { |
| 5604 |
struct netr_OneDomainInfo *odiT = |
| 5605 |
&info.domain_info->trusted_domains[i]; |
| 5606 |
struct netr_trust_extension_info *texT = NULL; |
| 5607 |
|
| 5608 |
torture_assert_int_equal(tctx, odiT->trust_extension.length, 16, |
| 5609 |
"trust_list should have extension"); |
| 5610 |
torture_assert(tctx, odiT->trust_extension.info != NULL, |
| 5611 |
"trust_list should have extension"); |
| 5612 |
texT = &odiT->trust_extension.info->info; |
| 5613 |
|
| 5614 |
if (GUID_equal(&odiT->domain_guid, &odi1->domain_guid)) { |
| 5615 |
odi2 = odiT; |
| 5616 |
tex2 = texT; |
| 5617 |
continue; |
| 5618 |
} |
| 5619 |
|
| 5620 |
torture_assert_int_equal(tctx, |
| 5621 |
texT->flags & NETR_TRUST_FLAG_PRIMARY, |
| 5622 |
0, |
| 5623 |
"trust_list flags should not have PRIMARY"); |
| 5624 |
|
| 5625 |
torture_assert(tctx, odiT->domainname.string != NULL, |
| 5626 |
"trust_list domainname should be valid"); |
| 5627 |
if (texT->trust_type == LSA_TRUST_TYPE_DOWNLEVEL || |
| 5628 |
texT->trust_type == LSA_TRUST_TYPE_MIT) |
| 5629 |
{ |
| 5630 |
torture_assert(tctx, odiT->dns_domainname.string == NULL, |
| 5631 |
"trust_list dns_domainname should be NULL for downlevel or MIT"); |
| 5632 |
} else { |
| 5633 |
torture_assert(tctx, odiT->dns_domainname.string != NULL, |
| 5634 |
"trust_list dns_domainname should be valid for uplevel"); |
| 5635 |
} |
| 5636 |
torture_assert(tctx, odiT->dns_forestname.string == NULL, |
| 5637 |
"trust_list dns_forestname needs to be NULL"); |
| 5638 |
|
| 5639 |
torture_assert(tctx, odiT->domain_sid != NULL, |
| 5640 |
"trust_list domain_sid needs to be valid"); |
| 5641 |
} |
| 5642 |
|
| 5643 |
torture_assert(tctx, odi2 != NULL, |
| 5644 |
"trust_list primary domain not found."); |
| 5645 |
|
| 5646 |
torture_assert_str_equal(tctx, |
| 5647 |
odi1->domainname.string, |
| 5648 |
odi2->domainname.string, |
| 5649 |
"netbios name should match"); |
| 5650 |
|
| 5651 |
temp_str = talloc_strdup(tctx, odi1->dns_domainname.string); |
| 5652 |
torture_assert(tctx, temp_str != NULL, |
| 5653 |
"primary_domain dns_domainname copy"); |
| 5654 |
temp_str2 = strrchr(temp_str, '.'); |
| 5655 |
torture_assert(tctx, temp_str2 != NULL && temp_str2[1] == '\0', |
| 5656 |
"primary_domain dns_domainname needs trailing '.'"); |
| 5657 |
temp_str2[0] = '\0'; |
| 5658 |
torture_assert_str_equal(tctx, |
| 5659 |
temp_str, |
| 5660 |
odi2->dns_domainname.string, |
| 5661 |
"dns domainname should match " |
| 5662 |
"(without trailing '.')"); |
| 5663 |
|
| 5664 |
temp_str = talloc_strdup(tctx, odi1->dns_forestname.string); |
| 5665 |
torture_assert(tctx, temp_str != NULL, |
| 5666 |
"primary_domain dns_forestname copy"); |
| 5667 |
temp_str2 = strrchr(temp_str, '.'); |
| 5668 |
torture_assert(tctx, temp_str2 != NULL && temp_str2[1] == '\0', |
| 5669 |
"primary_domain dns_forestname needs trailing '.'"); |
| 5670 |
temp_str2[0] = '\0'; |
| 5671 |
torture_assert(tctx, odi2->dns_forestname.string == NULL, |
| 5672 |
"trust_list dns_forestname needs to be NULL"); |
| 5673 |
|
| 5674 |
torture_assert_guid_equal(tctx, odi1->domain_guid, odi2->domain_guid, |
| 5675 |
"domain_guid should match"); |
| 5676 |
torture_assert(tctx, odi1->domain_sid != NULL, |
| 5677 |
"primary domain_sid needs to be valid"); |
| 5678 |
torture_assert(tctx, odi2->domain_sid != NULL, |
| 5679 |
"trust_list domain_sid needs to be valid"); |
| 5680 |
torture_assert_sid_equal(tctx, odi1->domain_sid, odi2->domain_sid, |
| 5681 |
"domain_sid should match"); |
| 5682 |
|
| 5683 |
torture_assert_int_equal(tctx, odi1->trust_extension.length, 0, |
| 5684 |
"primary_domain should not have extension"); |
| 5685 |
torture_assert_int_equal(tctx, odi2->trust_extension.length, 16, |
| 5686 |
"trust_list should have extension"); |
| 5687 |
torture_assert(tctx, odi2->trust_extension.info != NULL, |
| 5688 |
"trust_list should have extension"); |
| 5689 |
tex2 = &odi2->trust_extension.info->info; |
| 5690 |
torture_assert_int_equal(tctx, |
| 5691 |
tex2->flags & NETR_TRUST_FLAG_PRIMARY, |
| 5692 |
NETR_TRUST_FLAG_PRIMARY, |
| 5693 |
"trust_list flags should have PRIMARY"); |
| 5694 |
torture_assert_int_equal(tctx, |
| 5695 |
tex2->flags & NETR_TRUST_FLAG_IN_FOREST, |
| 5696 |
NETR_TRUST_FLAG_IN_FOREST, |
| 5697 |
"trust_list flags should have IN_FOREST"); |
| 5698 |
torture_assert_int_equal(tctx, |
| 5699 |
tex2->flags & NETR_TRUST_FLAG_NATIVE, |
| 5700 |
NETR_TRUST_FLAG_NATIVE, |
| 5701 |
"trust_list flags should have NATIVE"); |
| 5702 |
torture_assert_int_equal(tctx, |
| 5703 |
tex2->flags & ~NETR_TRUST_FLAG_TREEROOT, |
| 5704 |
NETR_TRUST_FLAG_IN_FOREST | |
| 5705 |
NETR_TRUST_FLAG_PRIMARY | |
| 5706 |
NETR_TRUST_FLAG_NATIVE, |
| 5707 |
"trust_list flags IN_FOREST, PRIMARY, NATIVE " |
| 5708 |
"(TREEROOT optional)"); |
| 5709 |
if (strcmp(odi1->dns_domainname.string, odi1->dns_forestname.string) == 0) { |
| 5710 |
torture_assert_int_equal(tctx, |
| 5711 |
tex2->flags & NETR_TRUST_FLAG_TREEROOT, |
| 5712 |
NETR_TRUST_FLAG_TREEROOT, |
| 5713 |
"trust_list flags TREEROOT on forest root"); |
| 5714 |
torture_assert_int_equal(tctx, |
| 5715 |
tex2->parent_index, 0, |
| 5716 |
"trust_list no parent on forest root"); |
| 5717 |
} |
| 5718 |
torture_assert_int_equal(tctx, |
| 5719 |
tex2->trust_type, LSA_TRUST_TYPE_UPLEVEL, |
| 5720 |
"trust_list uplevel"); |
| 5721 |
torture_assert_int_equal(tctx, |
| 5722 |
tex2->trust_attributes, 0, |
| 5723 |
"trust_list no attributes"); |
| 5724 |
|
| 5725 |
torture_comment(tctx, "Testing netr_LogonGetDomainInfo 6th call (no DNS hostname)\n"); |
| 5726 |
netlogon_creds_client_authenticator(creds, &a); |
| 5727 |
|
| 5728 |
query.workstation_info->dns_hostname = NULL; |
| 5729 |
|
| 5730 |
torture_assert_ntstatus_ok(tctx, dcerpc_netr_LogonGetDomainInfo_r(b, tctx, &r), |
| 5731 |
"LogonGetDomainInfo failed"); |
| 5732 |
torture_assert_ntstatus_ok(tctx, r.out.result, "LogonGetDomainInfo failed"); |
| 5733 |
torture_assert(tctx, netlogon_creds_client_check(creds, &a.cred), "Credential chaining failed"); |
| 5734 |
|
| 5735 |
/* The old DNS hostname should stick */ |
| 5736 |
torture_assert_str_equal(tctx, |
| 5737 |
info.domain_info->dns_hostname.string, |
| 5738 |
old_dnsname, |
| 5739 |
"'DNS hostname' changed!"); |
| 5740 |
|
| 5741 |
torture_comment(tctx, "Testing netr_LogonGetDomainInfo 7th call (extra workstation flags)\n"); |
| 5742 |
netlogon_creds_client_authenticator(creds, &a); |
| 5743 |
|
| 5744 |
q1.workstation_flags = NETR_WS_FLAG_HANDLES_SPN_UPDATE |
| 5745 |
| NETR_WS_FLAG_HANDLES_INBOUND_TRUSTS | 0x4; |
| 5746 |
|
| 5747 |
/* Put the DNS hostname back */ |
| 5748 |
talloc_free(discard_const_p(char, q1.dns_hostname)); |
| 5749 |
q1.dns_hostname = talloc_asprintf(tctx, "%s.%s", TEST_MACHINE_NAME, |
| 5750 |
lpcfg_dnsdomain(tctx->lp_ctx)); |
| 5751 |
|
| 5752 |
torture_assert_ntstatus_ok(tctx, dcerpc_netr_LogonGetDomainInfo_r(b, tctx, &r), |
| 5753 |
"LogonGetDomainInfo failed"); |
| 5754 |
torture_assert_ntstatus_ok(tctx, r.out.result, "LogonGetDomainInfo failed"); |
| 5755 |
torture_assert(tctx, netlogon_creds_client_check(creds, &a.cred), "Credential chaining failed"); |
| 5756 |
|
| 5757 |
/* Checks "workstation flags" */ |
| 5758 |
torture_assert(tctx, |
| 5759 |
info.domain_info->workstation_flags |
| 5760 |
== (NETR_WS_FLAG_HANDLES_SPN_UPDATE |
| 5761 |
| NETR_WS_FLAG_HANDLES_INBOUND_TRUSTS), |
| 5762 |
"Out 'workstation flags' don't match!"); |
| 5763 |
|
| 5764 |
if (!torture_setting_bool(tctx, "dangerous", false)) { |
| 5765 |
torture_comment(tctx, "Not testing netr_LogonGetDomainInfo 8th call (no workstation info) - enable dangerous tests in order to do so\n"); |
| 5766 |
} else { |
| 5767 |
/* Try a call without the workstation information structure */ |
| 5768 |
|
| 5769 |
torture_comment(tctx, "Testing netr_LogonGetDomainInfo 8th call (no workstation info)\n"); |
| 5770 |
netlogon_creds_client_authenticator(creds, &a); |
| 5771 |
|
| 5772 |
query.workstation_info = NULL; |
| 5773 |
|
| 5774 |
torture_assert_ntstatus_ok(tctx, dcerpc_netr_LogonGetDomainInfo_r(b, tctx, &r), |
| 5775 |
"LogonGetDomainInfo failed"); |
| 5776 |
torture_assert_ntstatus_ok(tctx, r.out.result, "LogonGetDomainInfo failed"); |
| 5777 |
torture_assert(tctx, netlogon_creds_client_check(creds, &a.cred), "Credential chaining failed"); |
| 5778 |
} |
| 5779 |
|
| 5780 |
return true; |
| 5781 |
} |
| 5782 |
|
| 5783 |
static bool test_GetDomainInfo_async(struct torture_context *tctx, |
| 5784 |
struct dcerpc_pipe *p1, |
| 5785 |
struct cli_credentials *machine_credentials) |
| 5786 |
{ |
| 5787 |
NTSTATUS status; |
| 5788 |
struct netr_LogonGetDomainInfo r; |
| 5789 |
struct netr_WorkstationInformation q1; |
| 5790 |
struct netr_Authenticator a; |
| 5791 |
#define ASYNC_COUNT 100 |
| 5792 |
struct netlogon_creds_CredentialState *creds; |
| 5793 |
struct netlogon_creds_CredentialState *creds_async[ASYNC_COUNT]; |
| 5794 |
struct tevent_req *req[ASYNC_COUNT]; |
| 5795 |
int i; |
| 5796 |
union netr_WorkstationInfo query; |
| 5797 |
union netr_DomainInfo info; |
| 5798 |
struct dcerpc_pipe *p = NULL; |
| 5799 |
|
| 5800 |
torture_comment(tctx, "Testing netr_LogonGetDomainInfo - async count %d\n", ASYNC_COUNT); |
| 5801 |
|
| 5802 |
if (!test_SetupCredentials3(p, tctx, NETLOGON_NEG_AUTH2_ADS_FLAGS | NETLOGON_NEG_SUPPORTS_AES, |
| 5803 |
machine_credentials, &creds)) { |
| 5804 |
return false; |
| 5805 |
} |
| 5806 |
if (!test_SetupCredentialsPipe(p1, tctx, machine_credentials, creds, |
| 5807 |
DCERPC_SIGN | DCERPC_SEAL, &p)) { |
| 5808 |
return false; |
| 5809 |
} |
| 5810 |
|
| 5811 |
ZERO_STRUCT(r); |
| 5812 |
r.in.server_name = talloc_asprintf(tctx, "\\\\%s", dcerpc_server_name(p)); |
| 5813 |
r.in.computer_name = TEST_MACHINE_NAME; |
| 5814 |
r.in.credential = &a; |
| 5815 |
r.in.level = 1; |
| 5816 |
r.in.return_authenticator = &a; |
| 5817 |
r.in.query = &query; |
| 5818 |
r.out.return_authenticator = &a; |
| 5819 |
r.out.info = &info; |
| 5820 |
|
| 5821 |
ZERO_STRUCT(q1); |
| 5822 |
q1.dns_hostname = talloc_asprintf(tctx, "%s.%s", TEST_MACHINE_NAME, |
| 5823 |
lpcfg_dnsdomain(tctx->lp_ctx)); |
| 5824 |
q1.sitename = "Default-First-Site-Name"; |
| 5825 |
q1.os_name.string = "UNIX/Linux or similar"; |
| 5826 |
|
| 5827 |
query.workstation_info = &q1; |
| 5828 |
|
| 5829 |
for (i=0;i<ASYNC_COUNT;i++) { |
| 5830 |
netlogon_creds_client_authenticator(creds, &a); |
| 5831 |
|
| 5832 |
creds_async[i] = (struct netlogon_creds_CredentialState *)talloc_memdup(creds, creds, sizeof(*creds)); |
| 5833 |
req[i] = dcerpc_netr_LogonGetDomainInfo_r_send(tctx, tctx->ev, p->binding_handle, &r); |
| 5834 |
|
| 5835 |
/* even with this flush per request a w2k3 server seems to |
| 5836 |
clag with multiple outstanding requests. bleergh. */ |
| 5837 |
torture_assert_int_equal(tctx, tevent_loop_once(tctx->ev), 0, |
| 5838 |
"tevent_loop_once failed"); |
| 5839 |
} |
| 5840 |
|
| 5841 |
for (i=0;i<ASYNC_COUNT;i++) { |
| 5842 |
torture_assert_int_equal(tctx, tevent_req_poll(req[i], tctx->ev), true, |
| 5843 |
"tevent_req_poll() failed"); |
| 5844 |
|
| 5845 |
status = dcerpc_netr_LogonGetDomainInfo_r_recv(req[i], tctx); |
| 5846 |
|
| 5847 |
torture_assert_ntstatus_ok(tctx, status, "netr_LogonGetDomainInfo_async"); |
| 5848 |
torture_assert_ntstatus_ok(tctx, r.out.result, "netr_LogonGetDomainInfo_async"); |
| 5849 |
|
| 5850 |
torture_assert(tctx, netlogon_creds_client_check(creds_async[i], &a.cred), |
| 5851 |
"Credential chaining failed at async"); |
| 5852 |
} |
| 5853 |
|
| 5854 |
torture_comment(tctx, |
| 5855 |
"Testing netr_LogonGetDomainInfo - async count %d OK\n", ASYNC_COUNT); |
| 5856 |
|
| 5857 |
return true; |
| 5858 |
} |
| 5859 |
|
| 5860 |
static bool test_ManyGetDCName(struct torture_context *tctx, |
| 5861 |
struct dcerpc_pipe *p) |
| 5862 |
{ |
| 5863 |
NTSTATUS status; |
| 5864 |
struct cli_credentials *anon_creds; |
| 5865 |
struct dcerpc_binding *binding2; |
| 5866 |
struct dcerpc_pipe *p2; |
| 5867 |
struct lsa_ObjectAttribute attr; |
| 5868 |
struct lsa_QosInfo qos; |
| 5869 |
struct lsa_OpenPolicy2 o; |
| 5870 |
struct policy_handle lsa_handle; |
| 5871 |
struct lsa_DomainList domains; |
| 5872 |
|
| 5873 |
struct lsa_EnumTrustDom t; |
| 5874 |
uint32_t resume_handle = 0; |
| 5875 |
struct netr_GetAnyDCName d; |
| 5876 |
const char *dcname = NULL; |
| 5877 |
struct dcerpc_binding_handle *b = p->binding_handle; |
| 5878 |
const struct dcerpc_binding *bd = dcerpc_binding_handle_get_binding(b); |
| 5879 |
struct dcerpc_binding_handle *b2; |
| 5880 |
|
| 5881 |
int i; |
| 5882 |
|
| 5883 |
if (dcerpc_binding_handle_get_transport(b) != NCACN_NP) { |
| 5884 |
torture_skip(tctx, "test_ManyGetDCName works only with NCACN_NP"); |
| 5885 |
} |
| 5886 |
|
| 5887 |
torture_comment(tctx, "Torturing GetDCName\n"); |
| 5888 |
|
| 5889 |
anon_creds = cli_credentials_init_anon(tctx); |
| 5890 |
torture_assert(tctx, anon_creds != NULL, "cli_credentials_init_anon failed"); |
| 5891 |
|
| 5892 |
binding2 = dcerpc_binding_dup(tctx, bd); |
| 5893 |
/* Swap the binding details from NETLOGON to LSA */ |
| 5894 |
status = dcerpc_epm_map_binding(tctx, binding2, &ndr_table_lsarpc, tctx->ev, tctx->lp_ctx); |
| 5895 |
dcerpc_binding_set_assoc_group_id(binding2, 0); |
| 5896 |
torture_assert_ntstatus_ok(tctx, status, "epm map"); |
| 5897 |
|
| 5898 |
status = dcerpc_secondary_auth_connection(p, binding2, &ndr_table_lsarpc, |
| 5899 |
anon_creds, tctx->lp_ctx, |
| 5900 |
tctx, &p2); |
| 5901 |
torture_assert_ntstatus_ok(tctx, status, "Failed to create secondary connection"); |
| 5902 |
b2 = p2->binding_handle; |
| 5903 |
|
| 5904 |
qos.len = 0; |
| 5905 |
qos.impersonation_level = 2; |
| 5906 |
qos.context_mode = 1; |
| 5907 |
qos.effective_only = 0; |
| 5908 |
|
| 5909 |
attr.len = 0; |
| 5910 |
attr.root_dir = NULL; |
| 5911 |
attr.object_name = NULL; |
| 5912 |
attr.attributes = 0; |
| 5913 |
attr.sec_desc = NULL; |
| 5914 |
attr.sec_qos = &qos; |
| 5915 |
|
| 5916 |
o.in.system_name = "\\"; |
| 5917 |
o.in.attr = &attr; |
| 5918 |
o.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED; |
| 5919 |
o.out.handle = &lsa_handle; |
| 5920 |
|
| 5921 |
torture_assert_ntstatus_ok(tctx, dcerpc_lsa_OpenPolicy2_r(b2, tctx, &o), |
| 5922 |
"OpenPolicy2 failed"); |
| 5923 |
torture_assert_ntstatus_ok(tctx, o.out.result, "OpenPolicy2 failed"); |
| 5924 |
|
| 5925 |
t.in.handle = &lsa_handle; |
| 5926 |
t.in.resume_handle = &resume_handle; |
| 5927 |
t.in.max_size = 1000; |
| 5928 |
t.out.domains = &domains; |
| 5929 |
t.out.resume_handle = &resume_handle; |
| 5930 |
|
| 5931 |
torture_assert_ntstatus_ok(tctx, dcerpc_lsa_EnumTrustDom_r(b2, tctx, &t), |
| 5932 |
"EnumTrustDom failed"); |
| 5933 |
|
| 5934 |
if ((!NT_STATUS_IS_OK(t.out.result) && |
| 5935 |
(!NT_STATUS_EQUAL(t.out.result, NT_STATUS_NO_MORE_ENTRIES)))) |
| 5936 |
torture_fail(tctx, "Could not list domains"); |
| 5937 |
|
| 5938 |
talloc_free(p2); |
| 5939 |
|
| 5940 |
d.in.logon_server = talloc_asprintf(tctx, "\\\\%s", |
| 5941 |
dcerpc_server_name(p)); |
| 5942 |
d.out.dcname = &dcname; |
| 5943 |
|
| 5944 |
for (i=0; i<domains.count * 4; i++) { |
| 5945 |
struct lsa_DomainInfo *info = |
| 5946 |
&domains.domains[rand()%domains.count]; |
| 5947 |
|
| 5948 |
d.in.domainname = info->name.string; |
| 5949 |
|
| 5950 |
status = dcerpc_netr_GetAnyDCName_r(b, tctx, &d); |
| 5951 |
torture_assert_ntstatus_ok(tctx, status, "GetAnyDCName"); |
| 5952 |
|
| 5953 |
torture_comment(tctx, "\tDC for domain %s is %s\n", info->name.string, |
| 5954 |
dcname ? dcname : "unknown"); |
| 5955 |
} |
| 5956 |
|
| 5957 |
return true; |
| 5958 |
} |
| 5959 |
|
| 5960 |
static bool test_lsa_over_netlogon(struct torture_context *tctx, |
| 5961 |
struct dcerpc_pipe *p) |
| 5962 |
{ |
| 5963 |
NTSTATUS status; |
| 5964 |
struct cli_credentials *anon_creds; |
| 5965 |
const struct dcerpc_binding *binding2; |
| 5966 |
struct dcerpc_pipe *p2; |
| 5967 |
struct lsa_ObjectAttribute attr; |
| 5968 |
struct lsa_QosInfo qos; |
| 5969 |
struct lsa_OpenPolicy2 o; |
| 5970 |
struct policy_handle lsa_handle; |
| 5971 |
|
| 5972 |
struct dcerpc_binding_handle *b2; |
| 5973 |
|
| 5974 |
|
| 5975 |
if (dcerpc_binding_handle_get_transport(p->binding_handle) != NCACN_NP) { |
| 5976 |
torture_skip(tctx, "test_lsa_over_netlogon works only with NCACN_NP"); |
| 5977 |
} |
| 5978 |
|
| 5979 |
torture_comment(tctx, "Testing if we can access the LSA server over\n" |
| 5980 |
" \\\\pipe\\netlogon rather than \\\\pipe\\lsarpc\n"); |
| 5981 |
|
| 5982 |
anon_creds = cli_credentials_init_anon(tctx); |
| 5983 |
torture_assert(tctx, anon_creds != NULL, "cli_credentials_init_anon failed"); |
| 5984 |
|
| 5985 |
binding2 = dcerpc_binding_handle_get_binding(p->binding_handle); |
| 5986 |
|
| 5987 |
status = dcerpc_secondary_auth_connection(p, binding2, &ndr_table_lsarpc, |
| 5988 |
anon_creds, tctx->lp_ctx, |
| 5989 |
tctx, &p2); |
| 5990 |
torture_assert_ntstatus_ok(tctx, status, "Failed to create secondary connection"); |
| 5991 |
b2 = p2->binding_handle; |
| 5992 |
|
| 5993 |
qos.len = 0; |
| 5994 |
qos.impersonation_level = 2; |
| 5995 |
qos.context_mode = 1; |
| 5996 |
qos.effective_only = 0; |
| 5997 |
|
| 5998 |
attr.len = 0; |
| 5999 |
attr.root_dir = NULL; |
| 6000 |
attr.object_name = NULL; |
| 6001 |
attr.attributes = 0; |
| 6002 |
attr.sec_desc = NULL; |
| 6003 |
attr.sec_qos = &qos; |
| 6004 |
|
| 6005 |
o.in.system_name = "\\"; |
| 6006 |
o.in.attr = &attr; |
| 6007 |
o.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED; |
| 6008 |
o.out.handle = &lsa_handle; |
| 6009 |
|
| 6010 |
torture_assert_ntstatus_ok(tctx, dcerpc_lsa_OpenPolicy2_r(b2, tctx, &o), |
| 6011 |
"OpenPolicy2 failed"); |
| 6012 |
torture_assert_ntstatus_ok(tctx, o.out.result, "OpenPolicy2 failed"); |
| 6013 |
|
| 6014 |
talloc_free(p2); |
| 6015 |
|
| 6016 |
return true; |
| 6017 |
} |
| 6018 |
|
| 6019 |
static bool test_SetPassword_with_flags(struct torture_context *tctx, |
| 6020 |
struct dcerpc_pipe *p, |
| 6021 |
struct cli_credentials *machine_credentials) |
| 6022 |
{ |
| 6023 |
uint32_t flags[] = { 0, NETLOGON_NEG_STRONG_KEYS }; |
| 6024 |
struct netlogon_creds_CredentialState *creds; |
| 6025 |
int i; |
| 6026 |
|
| 6027 |
if (!test_SetupCredentials2(p, tctx, 0, |
| 6028 |
machine_credentials, |
| 6029 |
cli_credentials_get_secure_channel_type(machine_credentials), |
| 6030 |
&creds)) { |
| 6031 |
torture_skip(tctx, "DC does not support negotiation of 64bit session keys"); |
| 6032 |
} |
| 6033 |
|
| 6034 |
for (i=0; i < ARRAY_SIZE(flags); i++) { |
| 6035 |
torture_assert(tctx, |
| 6036 |
test_SetPassword_flags(tctx, p, machine_credentials, flags[i]), |
| 6037 |
talloc_asprintf(tctx, "failed to test SetPassword negotiating with 0x%08x flags", flags[i])); |
| 6038 |
} |
| 6039 |
|
| 6040 |
return true; |
| 6041 |
} |
| 6042 |
|
| 6043 |
struct torture_suite *torture_rpc_netlogon(TALLOC_CTX *mem_ctx) |
| 6044 |
{ |
| 6045 |
struct torture_suite *suite = torture_suite_create(mem_ctx, "netlogon"); |
| 6046 |
struct torture_rpc_tcase *tcase; |
| 6047 |
struct torture_test *test; |
| 6048 |
|
| 6049 |
tcase = torture_suite_add_machine_bdc_rpc_iface_tcase(suite, "netlogon", |
| 6050 |
&ndr_table_netlogon, TEST_MACHINE_NAME); |
| 6051 |
|
| 6052 |
torture_rpc_tcase_add_test_creds(tcase, "SetupCredentialsDowngrade", test_SetupCredentialsDowngrade); |
| 6053 |
torture_rpc_tcase_add_test(tcase, "lsa_over_netlogon", test_lsa_over_netlogon); |
| 6054 |
|
| 6055 |
torture_rpc_tcase_add_test_creds(tcase, "GetForestTrustInformation", test_netr_GetForestTrustInformation); |
| 6056 |
torture_rpc_tcase_add_test_creds(tcase, "ServerGetTrustInfo_AES", test_netr_ServerGetTrustInfo_AES); |
| 6057 |
torture_rpc_tcase_add_test_creds(tcase, "ServerGetTrustInfo", test_netr_ServerGetTrustInfo); |
| 6058 |
torture_rpc_tcase_add_test(tcase, "DsRAddressToSitenamesExW", test_netr_DsRAddressToSitenamesExW); |
| 6059 |
torture_rpc_tcase_add_test(tcase, "DsRAddressToSitenamesW", test_netr_DsRAddressToSitenamesW); |
| 6060 |
torture_rpc_tcase_add_test(tcase, "DsrGetDcSiteCoverageW", test_netr_DsrGetDcSiteCoverageW); |
| 6061 |
torture_rpc_tcase_add_test(tcase, "DsRGetDCNameEx2", test_netr_DsRGetDCNameEx2); |
| 6062 |
torture_rpc_tcase_add_test(tcase, "DsRGetDCNameEx", test_netr_DsRGetDCNameEx); |
| 6063 |
torture_rpc_tcase_add_test(tcase, "DsRGetDCName", test_netr_DsRGetDCName); |
| 6064 |
test = torture_rpc_tcase_add_test_creds(tcase, "GetDomainInfo_async", test_GetDomainInfo_async); |
| 6065 |
test->dangerous = true; |
| 6066 |
torture_rpc_tcase_add_test(tcase, "NetrEnumerateTrustedDomainsEx", test_netr_NetrEnumerateTrustedDomainsEx); |
| 6067 |
torture_rpc_tcase_add_test(tcase, "NetrEnumerateTrustedDomains", test_netr_NetrEnumerateTrustedDomains); |
| 6068 |
torture_rpc_tcase_add_test(tcase, "DsrEnumerateDomainTrusts", test_DsrEnumerateDomainTrusts); |
| 6069 |
torture_rpc_tcase_add_test_creds(tcase, "DatabaseSync2", test_DatabaseSync2); |
| 6070 |
torture_rpc_tcase_add_test(tcase, "GetAnyDCName", test_GetAnyDCName); |
| 6071 |
torture_rpc_tcase_add_test(tcase, "ManyGetDCName", test_ManyGetDCName); |
| 6072 |
torture_rpc_tcase_add_test(tcase, "GetDcName", test_GetDcName); |
| 6073 |
torture_rpc_tcase_add_test_creds(tcase, "AccountSync", test_AccountSync); |
| 6074 |
torture_rpc_tcase_add_test_creds(tcase, "AccountDeltas", test_AccountDeltas); |
| 6075 |
torture_rpc_tcase_add_test_creds(tcase, "DatabaseRedo", test_DatabaseRedo); |
| 6076 |
torture_rpc_tcase_add_test_creds(tcase, "DatabaseDeltas", test_DatabaseDeltas); |
| 6077 |
torture_rpc_tcase_add_test_creds(tcase, "DatabaseSync", test_DatabaseSync); |
| 6078 |
torture_rpc_tcase_add_test_creds(tcase, "GetDomainInfo", test_GetDomainInfo); |
| 6079 |
torture_rpc_tcase_add_test_creds(tcase, "GetTrustPasswords", test_GetTrustPasswords); |
| 6080 |
torture_rpc_tcase_add_test_creds(tcase, "GetPassword", test_GetPassword); |
| 6081 |
torture_rpc_tcase_add_test_creds(tcase, "SetPassword2_AES", test_SetPassword2_AES); |
| 6082 |
torture_rpc_tcase_add_test_creds(tcase, "SetPassword2", test_SetPassword2); |
| 6083 |
torture_rpc_tcase_add_test_creds(tcase, "SetPassword", test_SetPassword); |
| 6084 |
torture_rpc_tcase_add_test_creds(tcase, "ServerReqChallengeReuse", test_ServerReqChallengeReuse); |
| 6085 |
torture_rpc_tcase_add_test_creds(tcase, "ServerReqChallengeReuseGlobal4", test_ServerReqChallengeReuseGlobal4); |
| 6086 |
torture_rpc_tcase_add_test_creds(tcase, "ServerReqChallengeReuseGlobal3", test_ServerReqChallengeReuseGlobal3); |
| 6087 |
torture_rpc_tcase_add_test_creds(tcase, "ServerReqChallengeReuseGlobal2", test_ServerReqChallengeReuseGlobal2); |
| 6088 |
torture_rpc_tcase_add_test_creds(tcase, "ServerReqChallengeReuseGlobal", test_ServerReqChallengeReuseGlobal); |
| 6089 |
torture_rpc_tcase_add_test_creds(tcase, "ServerReqChallengeGlobal", test_ServerReqChallengeGlobal); |
| 6090 |
torture_rpc_tcase_add_test_creds(tcase, "invalidAuthenticate2", test_invalidAuthenticate2); |
| 6091 |
torture_rpc_tcase_add_test_creds(tcase, "SamLogon", test_SamLogon); |
| 6092 |
torture_rpc_tcase_add_test(tcase, "LogonUasLogoff", test_LogonUasLogoff); |
| 6093 |
torture_rpc_tcase_add_test(tcase, "LogonUasLogon", test_LogonUasLogon); |
| 6094 |
|
| 6095 |
torture_rpc_tcase_add_test(tcase, "Broken RPC binding handle", |
| 6096 |
test_netr_broken_binding_handle); |
| 6097 |
|
| 6098 |
return suite; |
| 6099 |
} |
| 6100 |
|
| 6101 |
struct torture_suite *torture_rpc_netlogon_s3(TALLOC_CTX *mem_ctx) |
| 6102 |
{ |
| 6103 |
struct torture_suite *suite = torture_suite_create(mem_ctx, "netlogon-s3"); |
| 6104 |
struct torture_rpc_tcase *tcase; |
| 6105 |
|
| 6106 |
tcase = torture_suite_add_machine_bdc_rpc_iface_tcase(suite, "netlogon", |
| 6107 |
&ndr_table_netlogon, TEST_MACHINE_NAME); |
| 6108 |
|
| 6109 |
torture_rpc_tcase_add_test_creds(tcase, "SamLogon", test_SamLogon); |
| 6110 |
torture_rpc_tcase_add_test_creds(tcase, "SamLogon_NULL_domain", test_SamLogon_NULL_domain); |
| 6111 |
torture_rpc_tcase_add_test_creds(tcase, "SetPassword", test_SetPassword); |
| 6112 |
torture_rpc_tcase_add_test_creds(tcase, "SetPassword_with_flags", test_SetPassword_with_flags); |
| 6113 |
torture_rpc_tcase_add_test_creds(tcase, "SetPassword2", test_SetPassword2); |
| 6114 |
torture_rpc_tcase_add_test_creds(tcase, "SetPassword2_AES", test_SetPassword2_AES); |
| 6115 |
torture_rpc_tcase_add_test(tcase, "NetrEnumerateTrustedDomains", test_netr_NetrEnumerateTrustedDomains); |
| 6116 |
|
| 6117 |
return suite; |
| 6118 |
} |
| 6119 |
|
| 6120 |
struct torture_suite *torture_rpc_netlogon_zerologon(TALLOC_CTX *mem_ctx) |
| 6121 |
{ |
| 6122 |
struct torture_suite *suite = torture_suite_create( |
| 6123 |
mem_ctx, |
| 6124 |
"netlogon.zerologon"); |
| 6125 |
struct torture_rpc_tcase *tcase; |
| 6126 |
|
| 6127 |
tcase = torture_suite_add_machine_bdc_rpc_iface_tcase( |
| 6128 |
suite, |
| 6129 |
"netlogon", |
| 6130 |
&ndr_table_netlogon, |
| 6131 |
TEST_MACHINE_NAME); |
| 6132 |
|
| 6133 |
torture_rpc_tcase_add_test_creds( |
| 6134 |
tcase, |
| 6135 |
"ServerReqChallenge", |
| 6136 |
test_ServerReqChallenge); |
| 6137 |
torture_rpc_tcase_add_test_creds( |
| 6138 |
tcase, |
| 6139 |
"ServerReqChallenge_zero_challenge", |
| 6140 |
test_ServerReqChallenge_zero_challenge); |
| 6141 |
torture_rpc_tcase_add_test_creds( |
| 6142 |
tcase, |
| 6143 |
"ServerReqChallenge_5_repeats", |
| 6144 |
test_ServerReqChallenge_5_repeats); |
| 6145 |
torture_rpc_tcase_add_test_creds( |
| 6146 |
tcase, |
| 6147 |
"ServerReqChallenge_4_repeats", |
| 6148 |
test_ServerReqChallenge_4_repeats); |
| 6149 |
torture_rpc_tcase_add_test_creds( |
| 6150 |
tcase, |
| 6151 |
"test_SetPassword2_encrypted_to_all_zeros", |
| 6152 |
test_SetPassword2_encrypted_to_all_zeros); |
| 6153 |
torture_rpc_tcase_add_test_creds( |
| 6154 |
tcase, |
| 6155 |
"test_SetPassword2_password_encrypts_to_zero", |
| 6156 |
test_SetPassword2_password_encrypts_to_zero); |
| 6157 |
torture_rpc_tcase_add_test_creds( |
| 6158 |
tcase, |
| 6159 |
"test_SetPassword2_confounder", |
| 6160 |
test_SetPassword2_confounder); |
| 6161 |
torture_rpc_tcase_add_test_creds( |
| 6162 |
tcase, |
| 6163 |
"test_SetPassword2_all_zeros", |
| 6164 |
test_SetPassword2_all_zeros); |
| 6165 |
torture_rpc_tcase_add_test_creds( |
| 6166 |
tcase, |
| 6167 |
"test_SetPassword2_all_zero_password", |
| 6168 |
test_SetPassword2_all_zero_password); |
| 6169 |
torture_rpc_tcase_add_test_creds( |
| 6170 |
tcase, |
| 6171 |
"test_SetPassword2_maximum_length_password", |
| 6172 |
test_SetPassword2_maximum_length_password); |
| 6173 |
|
| 6174 |
return suite; |
| 6175 |
} |
| 6176 |
|
| 6177 |
struct torture_suite *torture_rpc_netlogon_admin(TALLOC_CTX *mem_ctx) |
| 6178 |
{ |
| 6179 |
struct torture_suite *suite = torture_suite_create(mem_ctx, "netlogon.admin"); |
| 6180 |
struct torture_rpc_tcase *tcase; |
| 6181 |
|
| 6182 |
tcase = torture_suite_add_machine_bdc_rpc_iface_tcase(suite, "bdc", |
| 6183 |
&ndr_table_netlogon, TEST_MACHINE_NAME); |
| 6184 |
torture_rpc_tcase_add_test_creds(tcase, "LogonControl", test_LogonControl); |
| 6185 |
torture_rpc_tcase_add_test_creds(tcase, "LogonControl2", test_LogonControl2); |
| 6186 |
torture_rpc_tcase_add_test_creds(tcase, "LogonControl2Ex", test_LogonControl2Ex); |
| 6187 |
|
| 6188 |
tcase = torture_suite_add_machine_workstation_rpc_iface_tcase(suite, "wkst", |
| 6189 |
&ndr_table_netlogon, TEST_MACHINE_NAME); |
| 6190 |
torture_rpc_tcase_add_test_creds(tcase, "LogonControl", test_LogonControl); |
| 6191 |
torture_rpc_tcase_add_test_creds(tcase, "LogonControl2", test_LogonControl2); |
| 6192 |
torture_rpc_tcase_add_test_creds(tcase, "LogonControl2Ex", test_LogonControl2Ex); |
| 6193 |
|
| 6194 |
tcase = torture_suite_add_rpc_iface_tcase(suite, "admin", |
| 6195 |
&ndr_table_netlogon); |
| 6196 |
torture_rpc_tcase_add_test_creds(tcase, "LogonControl", test_LogonControl); |
| 6197 |
torture_rpc_tcase_add_test_creds(tcase, "LogonControl2", test_LogonControl2); |
| 6198 |
torture_rpc_tcase_add_test_creds(tcase, "LogonControl2Ex", test_LogonControl2Ex); |
| 6199 |
|
| 6200 |
return suite; |
| 6201 |
} |