2 Unix SMB/CIFS implementation.
4 DsGetNCChanges replication test
6 Copyright (C) Stefan (metze) Metzmacher 2005
7 Copyright (C) Brad Henry 2005
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25 #include "lib/cmdline/popt_common.h"
26 #include "librpc/gen_ndr/ndr_drsuapi_c.h"
27 #include "libcli/cldap/cldap.h"
28 #include "libcli/ldap/ldap_client.h"
29 #include "torture/torture.h"
30 #include "torture/ldap/proto.h"
31 #include "libcli/auth/libcli_auth.h"
32 #include "lib/crypto/crypto.h"
33 #include "auth/credentials/credentials.h"
34 #include "libcli/auth/libcli_auth.h"
35 #include "auth/gensec/gensec.h"
37 struct DsSyncBindInfo {
38 struct dcerpc_pipe *pipe;
39 struct drsuapi_DsBind req;
40 struct GUID bind_guid;
41 struct drsuapi_DsBindInfoCtr our_bind_info_ctr;
42 struct drsuapi_DsBindInfo28 our_bind_info28;
43 struct drsuapi_DsBindInfo28 peer_bind_info28;
44 struct policy_handle bind_handle;
47 struct samr_Password nthash;
50 struct DsSyncLDAPInfo {
51 struct ldap_connection *conn;
55 struct dcerpc_binding *drsuapi_binding;
58 const char *site_name;
60 const char *domain_dn;
62 /* what we need to do as 'Administrator' */
64 struct cli_credentials *credentials;
65 struct DsSyncBindInfo drsuapi;
66 struct DsSyncLDAPInfo ldap;
69 /* what we need to do as the new dc machine account */
71 struct cli_credentials *credentials;
72 struct DsSyncBindInfo drsuapi;
73 struct drsuapi_DsGetDCInfo2 dc_info2;
74 struct GUID invocation_id;
75 struct GUID object_guid;
78 /* info about the old dc */
80 struct drsuapi_DsGetDomainControllerInfo dc_info;
84 static struct DsSyncTest *test_create_context(TALLOC_CTX *mem_ctx)
87 struct DsSyncTest *ctx;
88 struct drsuapi_DsBindInfo28 *our_bind_info28;
89 struct drsuapi_DsBindInfoCtr *our_bind_info_ctr;
90 const char *binding = lp_parm_string(-1, "torture", "binding");
91 ctx = talloc_zero(mem_ctx, struct DsSyncTest);
92 if (!ctx) return NULL;
94 status = dcerpc_parse_binding(ctx, binding, &ctx->drsuapi_binding);
95 if (!NT_STATUS_IS_OK(status)) {
96 printf("Bad binding string %s\n", binding);
99 ctx->drsuapi_binding->flags |= DCERPC_SIGN | DCERPC_SEAL;
101 ctx->ldap_url = talloc_asprintf(ctx, "ldap://%s/", ctx->drsuapi_binding->host);
104 ctx->admin.credentials = cmdline_credentials;
106 our_bind_info28 = &ctx->admin.drsuapi.our_bind_info28;
107 our_bind_info28->supported_extensions = 0xFFFFFFFF;
108 our_bind_info28->supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_ADDENTRYREPLY_V3;
109 our_bind_info28->site_guid = GUID_zero();
110 our_bind_info28->u1 = 0;
111 our_bind_info28->repl_epoch = 1;
113 our_bind_info_ctr = &ctx->admin.drsuapi.our_bind_info_ctr;
114 our_bind_info_ctr->length = 28;
115 our_bind_info_ctr->info.info28 = *our_bind_info28;
117 GUID_from_string(DRSUAPI_DS_BIND_GUID, &ctx->admin.drsuapi.bind_guid);
119 ctx->admin.drsuapi.req.in.bind_guid = &ctx->admin.drsuapi.bind_guid;
120 ctx->admin.drsuapi.req.in.bind_info = our_bind_info_ctr;
121 ctx->admin.drsuapi.req.out.bind_handle = &ctx->admin.drsuapi.bind_handle;
124 ctx->new_dc.credentials = cmdline_credentials;
126 our_bind_info28 = &ctx->new_dc.drsuapi.our_bind_info28;
127 our_bind_info28->supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_BASE;
128 our_bind_info28->supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_ASYNC_REPLICATION;
129 our_bind_info28->supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_REMOVEAPI;
130 our_bind_info28->supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_MOVEREQ_V2;
131 our_bind_info28->supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_GETCHG_COMPRESS;
132 our_bind_info28->supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_DCINFO_V1;
133 our_bind_info28->supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_RESTORE_USN_OPTIMIZATION;
134 our_bind_info28->supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_KCC_EXECUTE;
135 our_bind_info28->supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_ADDENTRY_V2;
136 our_bind_info28->supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_LINKED_VALUE_REPLICATION;
137 our_bind_info28->supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_DCINFO_V2;
138 our_bind_info28->supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_INSTANCE_TYPE_NOT_REQ_ON_MOD;
139 our_bind_info28->supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_CRYPTO_BIND;
140 our_bind_info28->supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_GET_REPL_INFO;
141 our_bind_info28->supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_STRONG_ENCRYPTION;
142 our_bind_info28->supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_DCINFO_V01;
143 our_bind_info28->supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_TRANSITIVE_MEMBERSHIP;
144 our_bind_info28->supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_ADD_SID_HISTORY;
145 our_bind_info28->supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_POST_BETA3;
146 our_bind_info28->supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_GET_MEMBERSHIPS2;
147 our_bind_info28->supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_GETCHGREQ_V6;
148 our_bind_info28->supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_NONDOMAIN_NCS;
149 our_bind_info28->supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_GETCHGREQ_V8;
150 our_bind_info28->supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_GETCHGREPLY_V5;
151 our_bind_info28->supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_GETCHGREPLY_V6;
152 our_bind_info28->supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_ADDENTRYREPLY_V3;
153 our_bind_info28->supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_GETCHGREPLY_V7;
154 our_bind_info28->supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_VERIFY_OBJECT;
155 if (lp_parm_bool(-1,"dssync","xpress",False)) {
156 our_bind_info28->supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_XPRESS_COMPRESS;
158 our_bind_info28->site_guid = GUID_zero();
159 our_bind_info28->u1 = 508;
160 our_bind_info28->repl_epoch = 0;
162 our_bind_info_ctr = &ctx->new_dc.drsuapi.our_bind_info_ctr;
163 our_bind_info_ctr->length = 28;
164 our_bind_info_ctr->info.info28 = *our_bind_info28;
166 GUID_from_string(DRSUAPI_DS_BIND_GUID_W2K3, &ctx->new_dc.drsuapi.bind_guid);
168 ctx->new_dc.drsuapi.req.in.bind_guid = &ctx->new_dc.drsuapi.bind_guid;
169 ctx->new_dc.drsuapi.req.in.bind_info = our_bind_info_ctr;
170 ctx->new_dc.drsuapi.req.out.bind_handle = &ctx->new_dc.drsuapi.bind_handle;
172 ctx->new_dc.invocation_id = ctx->new_dc.drsuapi.bind_guid;
179 static BOOL _test_DsBind(struct DsSyncTest *ctx, struct cli_credentials *credentials, struct DsSyncBindInfo *b)
183 struct event_context *event = NULL;
184 const struct samr_Password *nthash;
186 status = dcerpc_pipe_connect_b(ctx,
187 &b->pipe, ctx->drsuapi_binding,
188 &dcerpc_table_drsuapi,
191 if (!NT_STATUS_IS_OK(status)) {
192 printf("Failed to connect to server as a BDC: %s\n", nt_errstr(status));
196 status = dcerpc_drsuapi_DsBind(b->pipe, ctx, &b->req);
197 if (!NT_STATUS_IS_OK(status)) {
198 const char *errstr = nt_errstr(status);
199 if (NT_STATUS_EQUAL(status, NT_STATUS_NET_WRITE_FAULT)) {
200 errstr = dcerpc_errstr(ctx, b->pipe->last_fault_code);
202 printf("dcerpc_drsuapi_DsBind failed - %s\n", errstr);
204 } else if (!W_ERROR_IS_OK(b->req.out.result)) {
205 printf("DsBind failed - %s\n", win_errstr(b->req.out.result));
209 ZERO_STRUCT(b->peer_bind_info28);
210 if (b->req.out.bind_info) {
211 switch (b->req.out.bind_info->length) {
213 struct drsuapi_DsBindInfo24 *info24;
214 info24 = &b->req.out.bind_info->info.info24;
215 b->peer_bind_info28.supported_extensions= info24->supported_extensions;
216 b->peer_bind_info28.site_guid = info24->site_guid;
217 b->peer_bind_info28.u1 = info24->u1;
218 b->peer_bind_info28.repl_epoch = 0;
222 b->peer_bind_info28 = b->req.out.bind_info->info.info28;
227 dcerpc_fetch_session_key(b->pipe, &b->dce_key);
228 gensec_session_key(b->pipe->conn->security_state.generic_state, &b->gen_key);
229 nthash = cli_credentials_get_nt_hash(credentials, NULL);
230 if (nthash) b->nthash = *nthash;
232 if (lp_parm_bool(-1,"dssync","print_pwd_blobs",False)) {
233 DEBUG(0,("DCERPC session key:\n"));
234 dump_data(0, b->dce_key.data, b->dce_key.length);
235 DEBUG(0,("GENSEC session key:\n"));
236 dump_data(0, b->gen_key.data, b->gen_key.length);
237 DEBUG(0,("CREDENTIALS nthash:\n"));
238 dump_data(0, b->nthash.hash, sizeof(b->nthash.hash));
244 static BOOL test_LDAPBind(struct DsSyncTest *ctx, struct cli_credentials *credentials, struct DsSyncLDAPInfo *l)
249 status = torture_ldap_connection(ctx, &l->conn, ctx->ldap_url);
250 if (!NT_STATUS_IS_OK(status)) {
251 printf("failed to connect to LDAP: %s\n", ctx->ldap_url);
255 printf("connected to LDAP: %s\n", ctx->ldap_url);
257 status = torture_ldap_bind_sasl(l->conn, credentials);
258 if (!NT_STATUS_IS_OK(status)) {
259 printf("failed to bind to LDAP:\n");
262 printf("bound to LDAP.\n");
267 static BOOL test_GetInfo(struct DsSyncTest *ctx)
270 struct drsuapi_DsCrackNames r;
271 struct drsuapi_DsNameString names[1];
274 struct cldap_socket *cldap = cldap_socket_init(ctx, NULL);
275 struct cldap_netlogon search;
277 r.in.bind_handle = &ctx->admin.drsuapi.bind_handle;
279 r.in.req.req1.codepage = 1252; /* western european */
280 r.in.req.req1.language = 0x00000407; /* german */
281 r.in.req.req1.count = 1;
282 r.in.req.req1.names = names;
283 r.in.req.req1.format_flags = DRSUAPI_DS_NAME_FLAG_NO_FLAGS;
284 r.in.req.req1.format_offered = DRSUAPI_DS_NAME_FORMAT_NT4_ACCOUNT;
285 r.in.req.req1.format_desired = DRSUAPI_DS_NAME_FORMAT_FQDN_1779;
286 names[0].str = talloc_asprintf(ctx, "%s\\", lp_workgroup());
288 status = dcerpc_drsuapi_DsCrackNames(ctx->admin.drsuapi.pipe, ctx, &r);
289 if (!NT_STATUS_IS_OK(status)) {
290 const char *errstr = nt_errstr(status);
291 if (NT_STATUS_EQUAL(status, NT_STATUS_NET_WRITE_FAULT)) {
292 errstr = dcerpc_errstr(ctx, ctx->admin.drsuapi.pipe->last_fault_code);
294 printf("dcerpc_drsuapi_DsCrackNames failed - %s\n", errstr);
296 } else if (!W_ERROR_IS_OK(r.out.result)) {
297 printf("DsCrackNames failed - %s\n", win_errstr(r.out.result));
301 ctx->domain_dn = r.out.ctr.ctr1->array[0].result_name;
304 search.in.dest_address = ctx->drsuapi_binding->host;
305 search.in.acct_control = -1;
306 search.in.version = 6;
307 status = cldap_netlogon(cldap, ctx, &search);
308 if (!NT_STATUS_IS_OK(status)) {
309 const char *errstr = nt_errstr(status);
310 ctx->site_name = talloc_asprintf(ctx, "%s", "Default-First-Site-Name");
311 printf("cldap_netlogon() returned %s. Defaulting to Site-Name: %s\n", errstr, ctx->site_name);
313 ctx->site_name = talloc_steal(ctx, search.out.netlogon.logon5.client_site);
314 printf("cldap_netlogon() returned Client Site-Name: %s.\n",ctx->site_name);
315 printf("cldap_netlogon() returned Server Site-Name: %s.\n",search.out.netlogon.logon5.server_site);
321 static void choose_confounder_v01(TALLOC_CTX *mem_ctx,
322 struct DsSyncBindInfo *b,
323 struct drsuapi_DsReplicaObjectIdentifier *id,
325 const DATA_BLOB *buffer,
326 uint32_t confounder_len,
327 DATA_BLOB *confounder,
328 DATA_BLOB *enc_buffer)
330 *confounder = data_blob_talloc(mem_ctx, buffer->data, confounder_len);
331 *enc_buffer = data_blob_talloc(mem_ctx, buffer->data+confounder_len, buffer->length - confounder_len);
334 static void choose_confounder_v02(TALLOC_CTX *mem_ctx,
335 struct DsSyncBindInfo *b,
336 struct drsuapi_DsReplicaObjectIdentifier *id,
338 const DATA_BLOB *buffer,
339 uint32_t confounder_len,
340 DATA_BLOB *confounder,
341 DATA_BLOB *enc_buffer)
343 *confounder = data_blob_talloc(mem_ctx, buffer->data + buffer->length - confounder_len, confounder_len);
344 *enc_buffer = data_blob_talloc(mem_ctx, buffer->data, buffer->length - confounder_len);
347 static const struct {
349 void (*fn)(TALLOC_CTX *mem_ctx,
350 struct DsSyncBindInfo *b,
351 struct drsuapi_DsReplicaObjectIdentifier *id,
353 const DATA_BLOB *buffer,
354 uint32_t confounder_len,
355 DATA_BLOB *confounder,
356 DATA_BLOB *enc_buffer);
357 } choose_confounder_fns[] = {
360 .fn = choose_confounder_v01,
364 .fn = choose_confounder_v01,
368 .fn = choose_confounder_v01,
372 .fn = choose_confounder_v01,
376 .fn = choose_confounder_v02,
380 .fn = choose_confounder_v02,
384 .fn = choose_confounder_v02,
388 .fn = choose_confounder_v02,
392 static void choose_session_key_v01(TALLOC_CTX *mem_ctx,
393 struct DsSyncBindInfo *b,
394 struct drsuapi_DsReplicaObjectIdentifier *id,
396 const DATA_BLOB *buffer,
397 DATA_BLOB *session_key)
399 *session_key = data_blob_talloc(mem_ctx, b->dce_key.data, b->dce_key.length);
402 static void choose_session_key_v02(TALLOC_CTX *mem_ctx,
403 struct DsSyncBindInfo *b,
404 struct drsuapi_DsReplicaObjectIdentifier *id,
406 const DATA_BLOB *buffer,
407 DATA_BLOB *session_key)
409 *session_key = data_blob_talloc(mem_ctx, b->gen_key.data, b->gen_key.length);
412 static const struct {
413 void (*fn)(TALLOC_CTX *mem_ctx,
414 struct DsSyncBindInfo *b,
415 struct drsuapi_DsReplicaObjectIdentifier *id,
417 const DATA_BLOB *buffer,
418 DATA_BLOB *session_key);
419 } choose_session_key_fns[] = {
421 .fn = choose_session_key_v01,
424 .fn = choose_session_key_v02,
428 static void create_enc_key_v01(TALLOC_CTX *mem_ctx,
429 struct DsSyncBindInfo *b,
430 struct drsuapi_DsReplicaObjectIdentifier *id,
432 const DATA_BLOB *buffer,
433 const DATA_BLOB *confounder,
434 const DATA_BLOB *session_key,
437 struct MD5Context md5;
440 enc_key = data_blob_talloc(mem_ctx, NULL, 16);
442 MD5Update(&md5, confounder->data, confounder->length);
443 MD5Update(&md5, session_key->data, session_key->length);
444 MD5Final(enc_key.data, &md5);
449 static void create_enc_key_v02(TALLOC_CTX *mem_ctx,
450 struct DsSyncBindInfo *b,
451 struct drsuapi_DsReplicaObjectIdentifier *id,
453 const DATA_BLOB *buffer,
454 const DATA_BLOB *confounder,
455 const DATA_BLOB *session_key,
458 struct MD5Context md5;
461 enc_key = data_blob_talloc(mem_ctx, NULL, 16);
463 MD5Update(&md5, session_key->data, session_key->length);
464 MD5Update(&md5, confounder->data, confounder->length);
465 MD5Final(enc_key.data, &md5);
470 static const struct {
471 void (*fn)(TALLOC_CTX *mem_ctx,
472 struct DsSyncBindInfo *b,
473 struct drsuapi_DsReplicaObjectIdentifier *id,
475 const DATA_BLOB *buffer,
476 const DATA_BLOB *confounder,
477 const DATA_BLOB *session_key,
478 DATA_BLOB *_enc_key);
479 } create_enc_key_fns[] = {
481 .fn = create_enc_key_v01,
484 .fn = create_enc_key_v02,
488 static void do_decryption_v01(TALLOC_CTX *mem_ctx,
489 struct DsSyncBindInfo *b,
490 struct drsuapi_DsReplicaObjectIdentifier *id,
492 const DATA_BLOB *buffer,
493 const DATA_BLOB *enc_key,
494 const DATA_BLOB *enc_buffer,
495 DATA_BLOB *_plain_buffer)
497 DATA_BLOB plain_buffer;
499 plain_buffer = data_blob_talloc(mem_ctx, enc_buffer->data, enc_buffer->length);
501 arcfour_crypt_blob(plain_buffer.data, plain_buffer.length, enc_key);
503 *_plain_buffer = plain_buffer;
506 static const struct {
507 void (*fn)(TALLOC_CTX *mem_ctx,
508 struct DsSyncBindInfo *b,
509 struct drsuapi_DsReplicaObjectIdentifier *id,
511 const DATA_BLOB *buffer,
512 const DATA_BLOB *enc_key,
513 const DATA_BLOB *enc_buffer,
514 DATA_BLOB *plain_buffer);
515 } do_decryption_fns[] = {
517 .fn = do_decryption_v01,
521 static DATA_BLOB decrypt_blob(TALLOC_CTX *mem_ctx,
522 struct DsSyncBindInfo *b,
523 struct drsuapi_DsReplicaObjectIdentifier *id,
525 const DATA_BLOB *buffer)
533 for (conf_i = 0; conf_i < ARRAY_SIZE(choose_confounder_fns); conf_i++) {
534 DATA_BLOB confounder;
535 DATA_BLOB enc_buffer;
537 choose_confounder_fns[conf_i].fn(mem_ctx, b, id, rid, buffer,
538 choose_confounder_fns[conf_i].len,
539 &confounder, &enc_buffer);
541 for (skey_i = 0; skey_i < ARRAY_SIZE(choose_session_key_fns); skey_i++) {
542 DATA_BLOB session_key;
544 choose_session_key_fns[skey_i].fn(mem_ctx, b, id, rid, buffer,
547 for (ekey_i = 0; ekey_i < ARRAY_SIZE(create_enc_key_fns); ekey_i++) {
550 create_enc_key_fns[ekey_i].fn(mem_ctx, b, id, rid, buffer,
551 &confounder, &session_key,
554 for (crypt_i = 0; crypt_i < ARRAY_SIZE(do_decryption_fns); crypt_i++) {
555 DATA_BLOB plain_buffer;
557 do_decryption_fns[crypt_i].fn(mem_ctx, b, id, rid, buffer,
558 &enc_key, &enc_buffer,
561 DEBUGADD(0,("c[%u] s[%u] e[%u] d[%u] len[%u]:\n",
562 conf_i, skey_i, ekey_i, crypt_i,
563 plain_buffer.length));
564 dump_data(0, confounder.data, confounder.length);
565 dump_data(0, session_key.data, session_key.length);
566 dump_data(0, enc_key.data, enc_key.length);
567 dump_data(0, enc_buffer.data, enc_buffer.length);
568 dump_data(0, plain_buffer.data, plain_buffer.length);
574 return data_blob(NULL, 0);
577 static void test_analyse_objects(struct DsSyncTest *ctx,
578 struct drsuapi_DsReplicaObjectListItemEx *cur)
580 if (!lp_parm_bool(-1,"dssync","print_pwd_blobs",False)) {
584 for (; cur; cur = cur->next_object) {
586 struct dom_sid *sid = NULL;
588 BOOL dn_printed = False;
591 if (!cur->object.identifier) continue;
593 dn = cur->object.identifier->dn;
594 if (cur->object.identifier->sid.num_auths > 0) {
595 sid = &cur->object.identifier->sid;
596 rid = sid->sub_auths[sid->num_auths - 1];
599 for (i=0; i < cur->object.attribute_ctr.num_attributes; i++) {
600 const char *name = NULL;
601 DATA_BLOB *enc_data = NULL;
602 DATA_BLOB plain_data;
603 struct drsuapi_DsReplicaAttribute *attr;
604 attr = &cur->object.attribute_ctr.attributes[i];
606 switch (attr->attid) {
607 case DRSUAPI_ATTRIBUTE_dBCSPwd:
610 case DRSUAPI_ATTRIBUTE_unicodePwd:
613 case DRSUAPI_ATTRIBUTE_ntPwdHistory:
614 name = "ntPwdHistory";
616 case DRSUAPI_ATTRIBUTE_lmPwdHistory:
617 name = "lmPwdHistory";
619 case DRSUAPI_ATTRIBUTE_supplementalCredentials:
620 name = "supplementalCredentials";
622 case DRSUAPI_ATTRIBUTE_priorValue:
625 case DRSUAPI_ATTRIBUTE_currentValue:
626 name = "currentValue";
628 case DRSUAPI_ATTRIBUTE_trustAuthOutgoing:
629 name = "trustAuthOutgoing";
631 case DRSUAPI_ATTRIBUTE_trustAuthIncoming:
632 name = "trustAuthIncoming";
634 case DRSUAPI_ATTRIBUTE_initialAuthOutgoing:
635 name = "initialAuthOutgoing";
637 case DRSUAPI_ATTRIBUTE_initialAuthIncoming:
638 name = "initialAuthIncoming";
644 if (attr->value_ctr.num_values != 1) continue;
646 if (!attr->value_ctr.values[0].blob) continue;
648 enc_data = attr->value_ctr.values[0].blob;
649 ZERO_STRUCT(plain_data);
651 plain_data = decrypt_blob(ctx, &ctx->new_dc.drsuapi,
652 cur->object.identifier, rid,
655 DEBUG(0,("DN: %s\n", dn));
658 DEBUGADD(0,("ATTR: %s enc.length=%lu plain.length=%lu\n",
659 name, (long)enc_data->length, (long)plain_data.length));
660 dump_data(0, enc_data->data, enc_data->length);
661 if (plain_data.length) {
662 dump_data(0, plain_data.data, plain_data.length);
668 static BOOL test_FetchData(struct DsSyncTest *ctx)
673 uint64_t highest_usn = 0;
674 const char *partition = NULL;
675 struct drsuapi_DsGetNCChanges r;
676 struct drsuapi_DsReplicaObjectIdentifier nc;
677 struct drsuapi_DsGetNCChangesCtr1 *ctr1 = NULL;
678 struct drsuapi_DsGetNCChangesCtr6 *ctr6 = NULL;
679 int32_t out_level = 0;
680 struct GUID null_guid;
681 struct dom_sid null_sid;
693 ZERO_STRUCT(null_guid);
694 ZERO_STRUCT(null_sid);
696 partition = lp_parm_string(-1, "dssync", "partition");
697 if (partition == NULL) {
698 partition = ctx->domain_dn;
699 printf("dssync:partition not specified, defaulting to %s.\n", ctx->domain_dn);
702 highest_usn = lp_parm_int(-1, "dssync", "highest_usn", 0);
704 for (i=0; i < ARRAY_SIZE(array); i++) {
705 printf("testing DsGetNCChanges level %d\n",
708 r.in.bind_handle = &ctx->new_dc.drsuapi.bind_handle;
709 r.in.level = &array[i].level;
711 switch (*r.in.level) {
717 r.in.req.req5.destination_dsa_guid = ctx->new_dc.invocation_id;
718 r.in.req.req5.source_dsa_invocation_id = null_guid;
719 r.in.req.req5.naming_context = &nc;
720 r.in.req.req5.highwatermark.tmp_highest_usn = highest_usn;
721 r.in.req.req5.highwatermark.reserved_usn = 0;
722 r.in.req.req5.highwatermark.highest_usn = highest_usn;
723 r.in.req.req5.uptodateness_vector = NULL;
724 r.in.req.req5.replica_flags = 0;
725 if (lp_parm_bool(-1,"dssync","compression",False)) {
726 r.in.req.req5.replica_flags |= DRSUAPI_DS_REPLICA_NEIGHBOUR_COMPRESS_CHANGES;
728 if (lp_parm_bool(-1,"dssync","neighbour_writeable",True)) {
729 r.in.req.req5.replica_flags |= DRSUAPI_DS_REPLICA_NEIGHBOUR_WRITEABLE;
731 r.in.req.req5.replica_flags |= DRSUAPI_DS_REPLICA_NEIGHBOUR_SYNC_ON_STARTUP
732 | DRSUAPI_DS_REPLICA_NEIGHBOUR_DO_SCHEDULED_SYNCS
733 | DRSUAPI_DS_REPLICA_NEIGHBOUR_RETURN_OBJECT_PARENTS
734 | DRSUAPI_DS_REPLICA_NEIGHBOUR_NEVER_SYNCED
736 r.in.req.req5.max_object_count = 133;
737 r.in.req.req5.max_ndr_size = 1336770;
738 r.in.req.req5.unknown4 = 0;
739 r.in.req.req5.h1 = 0;
746 /* nc.dn can be set to any other ad partition */
748 r.in.req.req8.destination_dsa_guid = ctx->new_dc.invocation_id;
749 r.in.req.req8.source_dsa_invocation_id = null_guid;
750 r.in.req.req8.naming_context = &nc;
751 r.in.req.req8.highwatermark.tmp_highest_usn = highest_usn;
752 r.in.req.req8.highwatermark.reserved_usn = 0;
753 r.in.req.req8.highwatermark.highest_usn = highest_usn;
754 r.in.req.req8.uptodateness_vector = NULL;
755 r.in.req.req8.replica_flags = 0;
756 if (lp_parm_bool(-1,"dssync","compression",False)) {
757 r.in.req.req8.replica_flags |= DRSUAPI_DS_REPLICA_NEIGHBOUR_COMPRESS_CHANGES;
759 if (lp_parm_bool(-1,"dssync","neighbour_writeable",True)) {
760 r.in.req.req8.replica_flags |= DRSUAPI_DS_REPLICA_NEIGHBOUR_WRITEABLE;
762 r.in.req.req8.replica_flags |= DRSUAPI_DS_REPLICA_NEIGHBOUR_SYNC_ON_STARTUP
763 | DRSUAPI_DS_REPLICA_NEIGHBOUR_DO_SCHEDULED_SYNCS
764 | DRSUAPI_DS_REPLICA_NEIGHBOUR_RETURN_OBJECT_PARENTS
765 | DRSUAPI_DS_REPLICA_NEIGHBOUR_NEVER_SYNCED
767 r.in.req.req8.max_object_count = 402;
768 r.in.req.req8.max_ndr_size = 402116;
770 r.in.req.req8.unknown4 = 0;
771 r.in.req.req8.h1 = 0;
772 r.in.req.req8.unique_ptr1 = 0;
773 r.in.req.req8.unique_ptr2 = 0;
774 r.in.req.req8.mapping_ctr.num_mappings = 0;
775 r.in.req.req8.mapping_ctr.mappings = NULL;
780 printf("Dumping AD partition: %s\n", nc.dn);
784 r.out.level = &_level;
786 if (*r.in.level == 5) {
787 DEBUG(0,("start[%d] tmp_higest_usn: %llu , highest_usn: %llu\n",y,
788 (long long)r.in.req.req5.highwatermark.tmp_highest_usn,
789 (long long)r.in.req.req5.highwatermark.highest_usn));
792 if (*r.in.level == 8) {
793 DEBUG(0,("start[%d] tmp_higest_usn: %llu , highest_usn: %llu\n",y,
794 (long long)r.in.req.req8.highwatermark.tmp_highest_usn,
795 (long long)r.in.req.req8.highwatermark.highest_usn));
798 status = dcerpc_drsuapi_DsGetNCChanges(ctx->new_dc.drsuapi.pipe, ctx, &r);
799 if (!NT_STATUS_IS_OK(status)) {
800 const char *errstr = nt_errstr(status);
801 if (NT_STATUS_EQUAL(status, NT_STATUS_NET_WRITE_FAULT)) {
802 errstr = dcerpc_errstr(ctx, ctx->new_dc.drsuapi.pipe->last_fault_code);
804 printf("dcerpc_drsuapi_DsGetNCChanges failed - %s\n", errstr);
806 } else if (!W_ERROR_IS_OK(r.out.result)) {
807 printf("DsGetNCChanges failed - %s\n", win_errstr(r.out.result));
811 if (ret == True && *r.out.level == 1) {
813 ctr1 = &r.out.ctr.ctr1;
814 } else if (ret == True && *r.out.level == 2) {
816 ctr1 = r.out.ctr.ctr2.ctr.mszip1.ctr1;
819 if (out_level == 1) {
820 DEBUG(0,("end[%d] tmp_highest_usn: %llu , highest_usn: %llu\n",y,
821 (long long)ctr1->new_highwatermark.tmp_highest_usn,
822 (long long)ctr1->new_highwatermark.highest_usn));
824 test_analyse_objects(ctx, ctr1->first_object);
826 if (ctr1->new_highwatermark.tmp_highest_usn > ctr1->new_highwatermark.highest_usn) {
827 r.in.req.req5.highwatermark = ctr1->new_highwatermark;
832 if (ret == True && *r.out.level == 6) {
834 ctr6 = &r.out.ctr.ctr6;
835 } else if (ret == True && *r.out.level == 7
836 && r.out.ctr.ctr7.level == 6
837 && r.out.ctr.ctr7.type == DRSUAPI_COMPRESSION_TYPE_MSZIP) {
839 ctr6 = r.out.ctr.ctr7.ctr.mszip6.ctr6;
842 if (out_level == 6) {
843 DEBUG(0,("end[%d] tmp_highest_usn: %llu , highest_usn: %llu\n",y,
844 (long long)ctr6->new_highwatermark.tmp_highest_usn,
845 (long long)ctr6->new_highwatermark.highest_usn));
847 test_analyse_objects(ctx, ctr6->first_object);
849 if (ctr6->new_highwatermark.tmp_highest_usn > ctr6->new_highwatermark.highest_usn) {
850 r.in.req.req8.highwatermark = ctr6->new_highwatermark;
862 static BOOL test_FetchNT4Data(struct DsSyncTest *ctx)
867 uint64_t highest_usn = 0;
868 const char *partition = NULL;
869 struct drsuapi_DsGetNT4ChangeLog r;
870 int32_t out_level = 0;
871 struct GUID null_guid;
872 struct dom_sid null_sid;
875 ZERO_STRUCT(null_guid);
876 ZERO_STRUCT(null_sid);
880 r.in.bind_handle = &ctx->new_dc.drsuapi.bind_handle;
883 r.in.req.req1.unknown1 = lp_parm_int(-1, "dssync", "nt4-1", 3);
884 r.in.req.req1.unknown2 = lp_parm_int(-1, "dssync", "nt4-2", 0x00004000);
887 r.in.req.req1.length = cookie.length;
888 r.in.req.req1.data = cookie.data;
890 status = dcerpc_drsuapi_DsGetNT4ChangeLog(ctx->new_dc.drsuapi.pipe, ctx, &r);
891 if (!NT_STATUS_IS_OK(status)) {
892 const char *errstr = nt_errstr(status);
893 if (NT_STATUS_EQUAL(status, NT_STATUS_NET_WRITE_FAULT)) {
894 errstr = dcerpc_errstr(ctx, ctx->new_dc.drsuapi.pipe->last_fault_code);
896 printf("dcerpc_drsuapi_DsGetNT4ChangeLog failed - %s\n", errstr);
898 } else if (!W_ERROR_IS_OK(r.out.result)) {
899 printf("DsGetNT4ChangeLog failed - %s\n", win_errstr(r.out.result));
901 } else if (r.out.level != 1) {
902 printf("DsGetNT4ChangeLog unknown level - %u\n", r.out.level);
904 } else if (NT_STATUS_IS_OK(r.out.info.info1.status)) {
905 } else if (NT_STATUS_EQUAL(r.out.info.info1.status, STATUS_MORE_ENTRIES)) {
906 cookie.length = r.out.info.info1.length1;
907 cookie.data = r.out.info.info1.data1;
910 printf("DsGetNT4ChangeLog failed - %s\n", nt_errstr(r.out.info.info1.status));
920 BOOL torture_rpc_dssync(struct torture_context *torture)
924 struct DsSyncTest *ctx;
926 mem_ctx = talloc_init("torture_rpc_dssync");
927 ctx = test_create_context(mem_ctx);
929 ret &= _test_DsBind(ctx, ctx->admin.credentials, &ctx->admin.drsuapi);
930 ret &= test_LDAPBind(ctx, ctx->admin.credentials, &ctx->admin.ldap);
931 ret &= test_GetInfo(ctx);
932 ret &= _test_DsBind(ctx, ctx->new_dc.credentials, &ctx->new_dc.drsuapi);
933 ret &= test_FetchData(ctx);
934 ret &= test_FetchNT4Data(ctx);