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 3 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, see <http://www.gnu.org/licenses/>.
24 #include "lib/cmdline/popt_common.h"
25 #include "librpc/gen_ndr/ndr_drsuapi_c.h"
26 #include "libcli/cldap/cldap.h"
27 #include "libcli/ldap/ldap_client.h"
28 #include "torture/torture.h"
29 #include "torture/ldap/proto.h"
30 #include "libcli/auth/libcli_auth.h"
31 #include "lib/crypto/crypto.h"
32 #include "auth/credentials/credentials.h"
33 #include "libcli/auth/libcli_auth.h"
34 #include "auth/gensec/gensec.h"
35 #include "param/param.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 DsSyncLDAPInfo {
48 struct ldap_connection *conn;
52 struct dcerpc_binding *drsuapi_binding;
55 const char *site_name;
57 const char *domain_dn;
59 /* what we need to do as 'Administrator' */
61 struct cli_credentials *credentials;
62 struct DsSyncBindInfo drsuapi;
63 struct DsSyncLDAPInfo ldap;
66 /* what we need to do as the new dc machine account */
68 struct cli_credentials *credentials;
69 struct DsSyncBindInfo drsuapi;
70 struct drsuapi_DsGetDCInfo2 dc_info2;
71 struct GUID invocation_id;
72 struct GUID object_guid;
75 /* info about the old dc */
77 struct drsuapi_DsGetDomainControllerInfo dc_info;
81 static struct DsSyncTest *test_create_context(TALLOC_CTX *mem_ctx)
84 struct DsSyncTest *ctx;
85 struct drsuapi_DsBindInfo28 *our_bind_info28;
86 struct drsuapi_DsBindInfoCtr *our_bind_info_ctr;
87 const char *binding = lp_parm_string(global_loadparm, NULL, "torture", "binding");
88 ctx = talloc_zero(mem_ctx, struct DsSyncTest);
89 if (!ctx) return NULL;
91 status = dcerpc_parse_binding(ctx, binding, &ctx->drsuapi_binding);
92 if (!NT_STATUS_IS_OK(status)) {
93 printf("Bad binding string %s\n", binding);
96 ctx->drsuapi_binding->flags |= DCERPC_SIGN | DCERPC_SEAL;
98 ctx->ldap_url = talloc_asprintf(ctx, "ldap://%s/", ctx->drsuapi_binding->host);
101 ctx->admin.credentials = cmdline_credentials;
103 our_bind_info28 = &ctx->admin.drsuapi.our_bind_info28;
104 our_bind_info28->supported_extensions = 0xFFFFFFFF;
105 our_bind_info28->supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_ADDENTRYREPLY_V3;
106 our_bind_info28->site_guid = GUID_zero();
107 our_bind_info28->u1 = 0;
108 our_bind_info28->repl_epoch = 1;
110 our_bind_info_ctr = &ctx->admin.drsuapi.our_bind_info_ctr;
111 our_bind_info_ctr->length = 28;
112 our_bind_info_ctr->info.info28 = *our_bind_info28;
114 GUID_from_string(DRSUAPI_DS_BIND_GUID, &ctx->admin.drsuapi.bind_guid);
116 ctx->admin.drsuapi.req.in.bind_guid = &ctx->admin.drsuapi.bind_guid;
117 ctx->admin.drsuapi.req.in.bind_info = our_bind_info_ctr;
118 ctx->admin.drsuapi.req.out.bind_handle = &ctx->admin.drsuapi.bind_handle;
121 ctx->new_dc.credentials = cmdline_credentials;
123 our_bind_info28 = &ctx->new_dc.drsuapi.our_bind_info28;
124 our_bind_info28->supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_BASE;
125 our_bind_info28->supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_ASYNC_REPLICATION;
126 our_bind_info28->supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_REMOVEAPI;
127 our_bind_info28->supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_MOVEREQ_V2;
128 our_bind_info28->supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_GETCHG_COMPRESS;
129 our_bind_info28->supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_DCINFO_V1;
130 our_bind_info28->supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_RESTORE_USN_OPTIMIZATION;
131 our_bind_info28->supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_KCC_EXECUTE;
132 our_bind_info28->supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_ADDENTRY_V2;
133 our_bind_info28->supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_LINKED_VALUE_REPLICATION;
134 our_bind_info28->supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_DCINFO_V2;
135 our_bind_info28->supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_INSTANCE_TYPE_NOT_REQ_ON_MOD;
136 our_bind_info28->supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_CRYPTO_BIND;
137 our_bind_info28->supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_GET_REPL_INFO;
138 our_bind_info28->supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_STRONG_ENCRYPTION;
139 our_bind_info28->supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_DCINFO_V01;
140 our_bind_info28->supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_TRANSITIVE_MEMBERSHIP;
141 our_bind_info28->supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_ADD_SID_HISTORY;
142 our_bind_info28->supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_POST_BETA3;
143 our_bind_info28->supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_GET_MEMBERSHIPS2;
144 our_bind_info28->supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_GETCHGREQ_V6;
145 our_bind_info28->supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_NONDOMAIN_NCS;
146 our_bind_info28->supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_GETCHGREQ_V8;
147 our_bind_info28->supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_GETCHGREPLY_V5;
148 our_bind_info28->supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_GETCHGREPLY_V6;
149 our_bind_info28->supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_ADDENTRYREPLY_V3;
150 our_bind_info28->supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_GETCHGREPLY_V7;
151 our_bind_info28->supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_VERIFY_OBJECT;
152 if (lp_parm_bool(global_loadparm, NULL, "dssync", "xpress", false)) {
153 our_bind_info28->supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_XPRESS_COMPRESS;
155 our_bind_info28->site_guid = GUID_zero();
156 our_bind_info28->u1 = 508;
157 our_bind_info28->repl_epoch = 0;
159 our_bind_info_ctr = &ctx->new_dc.drsuapi.our_bind_info_ctr;
160 our_bind_info_ctr->length = 28;
161 our_bind_info_ctr->info.info28 = *our_bind_info28;
163 GUID_from_string(DRSUAPI_DS_BIND_GUID_W2K3, &ctx->new_dc.drsuapi.bind_guid);
165 ctx->new_dc.drsuapi.req.in.bind_guid = &ctx->new_dc.drsuapi.bind_guid;
166 ctx->new_dc.drsuapi.req.in.bind_info = our_bind_info_ctr;
167 ctx->new_dc.drsuapi.req.out.bind_handle = &ctx->new_dc.drsuapi.bind_handle;
169 ctx->new_dc.invocation_id = ctx->new_dc.drsuapi.bind_guid;
176 static bool _test_DsBind(struct DsSyncTest *ctx, struct cli_credentials *credentials, struct DsSyncBindInfo *b)
180 struct event_context *event = NULL;
182 status = dcerpc_pipe_connect_b(ctx,
183 &b->pipe, ctx->drsuapi_binding,
187 if (!NT_STATUS_IS_OK(status)) {
188 printf("Failed to connect to server as a BDC: %s\n", nt_errstr(status));
192 status = dcerpc_drsuapi_DsBind(b->pipe, ctx, &b->req);
193 if (!NT_STATUS_IS_OK(status)) {
194 const char *errstr = nt_errstr(status);
195 if (NT_STATUS_EQUAL(status, NT_STATUS_NET_WRITE_FAULT)) {
196 errstr = dcerpc_errstr(ctx, b->pipe->last_fault_code);
198 printf("dcerpc_drsuapi_DsBind failed - %s\n", errstr);
200 } else if (!W_ERROR_IS_OK(b->req.out.result)) {
201 printf("DsBind failed - %s\n", win_errstr(b->req.out.result));
205 ZERO_STRUCT(b->peer_bind_info28);
206 if (b->req.out.bind_info) {
207 switch (b->req.out.bind_info->length) {
209 struct drsuapi_DsBindInfo24 *info24;
210 info24 = &b->req.out.bind_info->info.info24;
211 b->peer_bind_info28.supported_extensions= info24->supported_extensions;
212 b->peer_bind_info28.site_guid = info24->site_guid;
213 b->peer_bind_info28.u1 = info24->u1;
214 b->peer_bind_info28.repl_epoch = 0;
218 b->peer_bind_info28 = b->req.out.bind_info->info.info28;
226 static bool test_LDAPBind(struct DsSyncTest *ctx, struct cli_credentials *credentials, struct DsSyncLDAPInfo *l)
231 status = torture_ldap_connection(ctx, &l->conn, ctx->ldap_url);
232 if (!NT_STATUS_IS_OK(status)) {
233 printf("failed to connect to LDAP: %s\n", ctx->ldap_url);
237 printf("connected to LDAP: %s\n", ctx->ldap_url);
239 status = torture_ldap_bind_sasl(l->conn, credentials);
240 if (!NT_STATUS_IS_OK(status)) {
241 printf("failed to bind to LDAP:\n");
244 printf("bound to LDAP.\n");
249 static bool test_GetInfo(struct DsSyncTest *ctx)
252 struct drsuapi_DsCrackNames r;
253 struct drsuapi_DsNameString names[1];
256 struct cldap_socket *cldap = cldap_socket_init(ctx, NULL);
257 struct cldap_netlogon search;
259 r.in.bind_handle = &ctx->admin.drsuapi.bind_handle;
261 r.in.req.req1.codepage = 1252; /* western european */
262 r.in.req.req1.language = 0x00000407; /* german */
263 r.in.req.req1.count = 1;
264 r.in.req.req1.names = names;
265 r.in.req.req1.format_flags = DRSUAPI_DS_NAME_FLAG_NO_FLAGS;
266 r.in.req.req1.format_offered = DRSUAPI_DS_NAME_FORMAT_NT4_ACCOUNT;
267 r.in.req.req1.format_desired = DRSUAPI_DS_NAME_FORMAT_FQDN_1779;
268 names[0].str = talloc_asprintf(ctx, "%s\\", lp_workgroup(global_loadparm));
270 status = dcerpc_drsuapi_DsCrackNames(ctx->admin.drsuapi.pipe, ctx, &r);
271 if (!NT_STATUS_IS_OK(status)) {
272 const char *errstr = nt_errstr(status);
273 if (NT_STATUS_EQUAL(status, NT_STATUS_NET_WRITE_FAULT)) {
274 errstr = dcerpc_errstr(ctx, ctx->admin.drsuapi.pipe->last_fault_code);
276 printf("dcerpc_drsuapi_DsCrackNames failed - %s\n", errstr);
278 } else if (!W_ERROR_IS_OK(r.out.result)) {
279 printf("DsCrackNames failed - %s\n", win_errstr(r.out.result));
283 ctx->domain_dn = r.out.ctr.ctr1->array[0].result_name;
286 search.in.dest_address = ctx->drsuapi_binding->host;
287 search.in.acct_control = -1;
288 search.in.version = 6;
289 status = cldap_netlogon(cldap, ctx, &search);
290 if (!NT_STATUS_IS_OK(status)) {
291 const char *errstr = nt_errstr(status);
292 ctx->site_name = talloc_asprintf(ctx, "%s", "Default-First-Site-Name");
293 printf("cldap_netlogon() returned %s. Defaulting to Site-Name: %s\n", errstr, ctx->site_name);
295 ctx->site_name = talloc_steal(ctx, search.out.netlogon.logon5.client_site);
296 printf("cldap_netlogon() returned Client Site-Name: %s.\n",ctx->site_name);
297 printf("cldap_netlogon() returned Server Site-Name: %s.\n",search.out.netlogon.logon5.server_site);
303 static DATA_BLOB decrypt_blob(TALLOC_CTX *mem_ctx,
304 const DATA_BLOB *gensec_skey,
306 struct drsuapi_DsReplicaObjectIdentifier *id,
308 const DATA_BLOB *buffer)
310 DATA_BLOB confounder;
311 DATA_BLOB enc_buffer;
313 struct MD5Context md5;
314 uint8_t _enc_key[16];
317 DATA_BLOB dec_buffer;
319 uint32_t crc32_given;
321 DATA_BLOB checked_buffer;
323 DATA_BLOB plain_buffer;
326 * the combination "c[3] s[1] e[1] d[0]..."
327 * was successful!!!!!!!!!!!!!!!!!!!!!!!!!!
331 * the first 16 bytes at the beginning are the confounder
332 * followed by the 4 byte crc32 checksum
334 if (buffer->length < 20) {
335 return data_blob_const(NULL, 0);
337 confounder = data_blob_const(buffer->data, 16);
338 enc_buffer = data_blob_const(buffer->data + 16, buffer->length - 16);
341 * build the encryption key md5 over the session key followed
344 * here the gensec session key is used and
345 * not the dcerpc ncacn_ip_tcp "SystemLibraryDTC" key!
347 enc_key = data_blob_const(_enc_key, sizeof(_enc_key));
349 MD5Update(&md5, gensec_skey->data, gensec_skey->length);
350 MD5Update(&md5, confounder.data, confounder.length);
351 MD5Final(enc_key.data, &md5);
354 * copy the encrypted buffer part and
355 * decrypt it using the created encryption key using arcfour
357 dec_buffer = data_blob_talloc(mem_ctx, enc_buffer.data, enc_buffer.length);
358 if (!dec_buffer.data) {
359 return data_blob_const(NULL, 0);
361 arcfour_crypt_blob(dec_buffer.data, dec_buffer.length, &enc_key);
364 * the first 4 byte are the crc32 checksum
365 * of the remaining bytes
367 crc32_given = IVAL(dec_buffer.data, 0);
368 crc32_calc = crc32_calc_buffer(dec_buffer.data + 4 , dec_buffer.length - 4);
369 if (crc32_given != crc32_calc) {
370 DEBUG(0,("CRC32: given[0x%08X] calc[0x%08X]\n",
371 crc32_given, crc32_calc));
372 return data_blob_const(NULL, 0);
374 checked_buffer = data_blob_talloc(mem_ctx, dec_buffer.data + 4, dec_buffer.length - 4);
375 if (!checked_buffer.data) {
376 return data_blob_const(NULL, 0);
380 * some attributes seem to be in a usable form after this decryption
381 * (supplementalCredentials, priorValue, currentValue, trustAuthOutgoing,
382 * trustAuthIncoming, initialAuthOutgoing, initialAuthIncoming)
383 * At least supplementalCredentials contains plaintext
384 * like "Primary:Kerberos" (in unicode form)
386 * some attributes seem to have some additional encryption
387 * dBCSPwd, unicodePwd, ntPwdHistory, lmPwdHistory
389 * it's the sam_rid_crypt() function, as the value is constant,
390 * so it doesn't depend on sessionkeys.
393 uint32_t i, num_hashes;
395 if ((checked_buffer.length % 16) != 0) {
396 return data_blob_const(NULL, 0);
399 plain_buffer = data_blob_talloc(mem_ctx, checked_buffer.data, checked_buffer.length);
400 if (!plain_buffer.data) {
401 return data_blob_const(NULL, 0);
404 num_hashes = plain_buffer.length / 16;
405 for (i = 0; i < num_hashes; i++) {
406 uint32_t offset = i * 16;
407 sam_rid_crypt(rid, checked_buffer.data + offset, plain_buffer.data + offset, 0);
410 plain_buffer = checked_buffer;
416 static void test_analyse_objects(struct DsSyncTest *ctx,
417 const DATA_BLOB *gensec_skey,
418 struct drsuapi_DsReplicaObjectListItemEx *cur)
420 static uint32_t object_id;
421 const char *save_values_dir;
423 if (!lp_parm_bool(global_loadparm, NULL, "dssync", "print_pwd_blobs", false)) {
427 save_values_dir = lp_parm_string(global_loadparm, NULL, "dssync", "save_pwd_blobs_dir");
429 for (; cur; cur = cur->next_object) {
431 struct dom_sid *sid = NULL;
433 bool dn_printed = false;
436 if (!cur->object.identifier) continue;
438 dn = cur->object.identifier->dn;
439 if (cur->object.identifier->sid.num_auths > 0) {
440 sid = &cur->object.identifier->sid;
441 rid = sid->sub_auths[sid->num_auths - 1];
444 for (i=0; i < cur->object.attribute_ctr.num_attributes; i++) {
445 const char *name = NULL;
447 DATA_BLOB *enc_data = NULL;
448 DATA_BLOB plain_data;
449 struct drsuapi_DsReplicaAttribute *attr;
450 attr = &cur->object.attribute_ctr.attributes[i];
452 switch (attr->attid) {
453 case DRSUAPI_ATTRIBUTE_dBCSPwd:
457 case DRSUAPI_ATTRIBUTE_unicodePwd:
461 case DRSUAPI_ATTRIBUTE_ntPwdHistory:
462 name = "ntPwdHistory";
465 case DRSUAPI_ATTRIBUTE_lmPwdHistory:
466 name = "lmPwdHistory";
469 case DRSUAPI_ATTRIBUTE_supplementalCredentials:
470 name = "supplementalCredentials";
472 case DRSUAPI_ATTRIBUTE_priorValue:
475 case DRSUAPI_ATTRIBUTE_currentValue:
476 name = "currentValue";
478 case DRSUAPI_ATTRIBUTE_trustAuthOutgoing:
479 name = "trustAuthOutgoing";
481 case DRSUAPI_ATTRIBUTE_trustAuthIncoming:
482 name = "trustAuthIncoming";
484 case DRSUAPI_ATTRIBUTE_initialAuthOutgoing:
485 name = "initialAuthOutgoing";
487 case DRSUAPI_ATTRIBUTE_initialAuthIncoming:
488 name = "initialAuthIncoming";
494 if (attr->value_ctr.num_values != 1) continue;
496 if (!attr->value_ctr.values[0].blob) continue;
498 enc_data = attr->value_ctr.values[0].blob;
499 ZERO_STRUCT(plain_data);
501 plain_data = decrypt_blob(ctx, gensec_skey, rcrypt,
502 cur->object.identifier, rid,
506 DEBUG(0,("DN[%u] %s\n", object_id, dn));
509 DEBUGADD(0,("ATTR: %s enc.length=%lu plain.length=%lu\n",
510 name, (long)enc_data->length, (long)plain_data.length));
511 if (plain_data.length) {
512 dump_data(0, plain_data.data, plain_data.length);
513 if (save_values_dir) {
515 fname = talloc_asprintf(ctx, "%s/%s%02d",
520 ok = file_save(fname, plain_data.data, plain_data.length);
522 DEBUGADD(0,("Failed to save '%s'\n", fname));
528 dump_data(0, enc_data->data, enc_data->length);
534 static bool test_FetchData(struct DsSyncTest *ctx)
539 uint64_t highest_usn = 0;
540 const char *partition = NULL;
541 struct drsuapi_DsGetNCChanges r;
542 struct drsuapi_DsReplicaObjectIdentifier nc;
543 struct drsuapi_DsGetNCChangesCtr1 *ctr1 = NULL;
544 struct drsuapi_DsGetNCChangesCtr6 *ctr6 = NULL;
545 int32_t out_level = 0;
546 struct GUID null_guid;
547 struct dom_sid null_sid;
548 DATA_BLOB gensec_skey;
560 ZERO_STRUCT(null_guid);
561 ZERO_STRUCT(null_sid);
563 partition = lp_parm_string(global_loadparm, NULL, "dssync", "partition");
564 if (partition == NULL) {
565 partition = ctx->domain_dn;
566 printf("dssync:partition not specified, defaulting to %s.\n", ctx->domain_dn);
569 highest_usn = lp_parm_int(global_loadparm, NULL, "dssync", "highest_usn", 0);
571 array[0].level = lp_parm_int(global_loadparm, NULL, "dssync", "get_nc_changes_level", array[0].level);
573 if (lp_parm_bool(global_loadparm, NULL, "dssync", "print_pwd_blobs", false)) {
574 const struct samr_Password *nthash;
575 nthash = cli_credentials_get_nt_hash(ctx->new_dc.credentials, ctx);
577 dump_data_pw("CREDENTIALS nthash:", nthash->hash, sizeof(nthash->hash));
580 status = gensec_session_key(ctx->new_dc.drsuapi.pipe->conn->security_state.generic_state,
582 if (!NT_STATUS_IS_OK(status)) {
583 printf("failed to get gensec session key: %s\n", nt_errstr(status));
587 for (i=0; i < ARRAY_SIZE(array); i++) {
588 printf("testing DsGetNCChanges level %d\n",
591 r.in.bind_handle = &ctx->new_dc.drsuapi.bind_handle;
592 r.in.level = &array[i].level;
594 switch (*r.in.level) {
600 r.in.req.req5.destination_dsa_guid = ctx->new_dc.invocation_id;
601 r.in.req.req5.source_dsa_invocation_id = null_guid;
602 r.in.req.req5.naming_context = &nc;
603 r.in.req.req5.highwatermark.tmp_highest_usn = highest_usn;
604 r.in.req.req5.highwatermark.reserved_usn = 0;
605 r.in.req.req5.highwatermark.highest_usn = highest_usn;
606 r.in.req.req5.uptodateness_vector = NULL;
607 r.in.req.req5.replica_flags = 0;
608 if (lp_parm_bool(global_loadparm, NULL, "dssync", "compression", false)) {
609 r.in.req.req5.replica_flags |= DRSUAPI_DS_REPLICA_NEIGHBOUR_COMPRESS_CHANGES;
611 if (lp_parm_bool(global_loadparm, NULL, "dssync", "neighbour_writeable", true)) {
612 r.in.req.req5.replica_flags |= DRSUAPI_DS_REPLICA_NEIGHBOUR_WRITEABLE;
614 r.in.req.req5.replica_flags |= DRSUAPI_DS_REPLICA_NEIGHBOUR_SYNC_ON_STARTUP
615 | DRSUAPI_DS_REPLICA_NEIGHBOUR_DO_SCHEDULED_SYNCS
616 | DRSUAPI_DS_REPLICA_NEIGHBOUR_RETURN_OBJECT_PARENTS
617 | DRSUAPI_DS_REPLICA_NEIGHBOUR_NEVER_SYNCED
619 r.in.req.req5.max_object_count = 133;
620 r.in.req.req5.max_ndr_size = 1336770;
621 r.in.req.req5.unknown4 = 0;
622 r.in.req.req5.h1 = 0;
629 /* nc.dn can be set to any other ad partition */
631 r.in.req.req8.destination_dsa_guid = ctx->new_dc.invocation_id;
632 r.in.req.req8.source_dsa_invocation_id = null_guid;
633 r.in.req.req8.naming_context = &nc;
634 r.in.req.req8.highwatermark.tmp_highest_usn = highest_usn;
635 r.in.req.req8.highwatermark.reserved_usn = 0;
636 r.in.req.req8.highwatermark.highest_usn = highest_usn;
637 r.in.req.req8.uptodateness_vector = NULL;
638 r.in.req.req8.replica_flags = 0;
639 if (lp_parm_bool(global_loadparm, NULL, "dssync", "compression", false)) {
640 r.in.req.req8.replica_flags |= DRSUAPI_DS_REPLICA_NEIGHBOUR_COMPRESS_CHANGES;
642 if (lp_parm_bool(global_loadparm, NULL, "dssync", "neighbour_writeable", true)) {
643 r.in.req.req8.replica_flags |= DRSUAPI_DS_REPLICA_NEIGHBOUR_WRITEABLE;
645 r.in.req.req8.replica_flags |= DRSUAPI_DS_REPLICA_NEIGHBOUR_SYNC_ON_STARTUP
646 | DRSUAPI_DS_REPLICA_NEIGHBOUR_DO_SCHEDULED_SYNCS
647 | DRSUAPI_DS_REPLICA_NEIGHBOUR_RETURN_OBJECT_PARENTS
648 | DRSUAPI_DS_REPLICA_NEIGHBOUR_NEVER_SYNCED
650 r.in.req.req8.max_object_count = 402;
651 r.in.req.req8.max_ndr_size = 402116;
653 r.in.req.req8.unknown4 = 0;
654 r.in.req.req8.h1 = 0;
655 r.in.req.req8.unique_ptr1 = 0;
656 r.in.req.req8.unique_ptr2 = 0;
657 r.in.req.req8.mapping_ctr.num_mappings = 0;
658 r.in.req.req8.mapping_ctr.mappings = NULL;
663 printf("Dumping AD partition: %s\n", nc.dn);
667 r.out.level = &_level;
669 if (*r.in.level == 5) {
670 DEBUG(0,("start[%d] tmp_higest_usn: %llu , highest_usn: %llu\n",y,
671 (long long)r.in.req.req5.highwatermark.tmp_highest_usn,
672 (long long)r.in.req.req5.highwatermark.highest_usn));
675 if (*r.in.level == 8) {
676 DEBUG(0,("start[%d] tmp_higest_usn: %llu , highest_usn: %llu\n",y,
677 (long long)r.in.req.req8.highwatermark.tmp_highest_usn,
678 (long long)r.in.req.req8.highwatermark.highest_usn));
681 status = dcerpc_drsuapi_DsGetNCChanges(ctx->new_dc.drsuapi.pipe, ctx, &r);
682 if (!NT_STATUS_IS_OK(status)) {
683 const char *errstr = nt_errstr(status);
684 if (NT_STATUS_EQUAL(status, NT_STATUS_NET_WRITE_FAULT)) {
685 errstr = dcerpc_errstr(ctx, ctx->new_dc.drsuapi.pipe->last_fault_code);
687 printf("dcerpc_drsuapi_DsGetNCChanges failed - %s\n", errstr);
689 } else if (!W_ERROR_IS_OK(r.out.result)) {
690 printf("DsGetNCChanges failed - %s\n", win_errstr(r.out.result));
694 if (ret == true && *r.out.level == 1) {
696 ctr1 = &r.out.ctr.ctr1;
697 } else if (ret == true && *r.out.level == 2) {
699 ctr1 = r.out.ctr.ctr2.ctr.mszip1.ctr1;
702 if (out_level == 1) {
703 DEBUG(0,("end[%d] tmp_highest_usn: %llu , highest_usn: %llu\n",y,
704 (long long)ctr1->new_highwatermark.tmp_highest_usn,
705 (long long)ctr1->new_highwatermark.highest_usn));
707 test_analyse_objects(ctx, &gensec_skey, ctr1->first_object);
709 if (ctr1->new_highwatermark.tmp_highest_usn > ctr1->new_highwatermark.highest_usn) {
710 r.in.req.req5.highwatermark = ctr1->new_highwatermark;
715 if (ret == true && *r.out.level == 6) {
717 ctr6 = &r.out.ctr.ctr6;
718 } else if (ret == true && *r.out.level == 7
719 && r.out.ctr.ctr7.level == 6
720 && r.out.ctr.ctr7.type == DRSUAPI_COMPRESSION_TYPE_MSZIP) {
722 ctr6 = r.out.ctr.ctr7.ctr.mszip6.ctr6;
725 if (out_level == 6) {
726 DEBUG(0,("end[%d] tmp_highest_usn: %llu , highest_usn: %llu\n",y,
727 (long long)ctr6->new_highwatermark.tmp_highest_usn,
728 (long long)ctr6->new_highwatermark.highest_usn));
730 test_analyse_objects(ctx, &gensec_skey, ctr6->first_object);
732 if (ctr6->new_highwatermark.tmp_highest_usn > ctr6->new_highwatermark.highest_usn) {
733 r.in.req.req8.highwatermark = ctr6->new_highwatermark;
745 static bool test_FetchNT4Data(struct DsSyncTest *ctx)
749 struct drsuapi_DsGetNT4ChangeLog r;
750 struct GUID null_guid;
751 struct dom_sid null_sid;
754 ZERO_STRUCT(null_guid);
755 ZERO_STRUCT(null_sid);
759 r.in.bind_handle = &ctx->new_dc.drsuapi.bind_handle;
762 r.in.req.req1.unknown1 = lp_parm_int(global_loadparm, NULL, "dssync", "nt4-1", 3);
763 r.in.req.req1.unknown2 = lp_parm_int(global_loadparm, NULL, "dssync", "nt4-2", 0x00004000);
766 r.in.req.req1.length = cookie.length;
767 r.in.req.req1.data = cookie.data;
769 status = dcerpc_drsuapi_DsGetNT4ChangeLog(ctx->new_dc.drsuapi.pipe, ctx, &r);
770 if (!NT_STATUS_IS_OK(status)) {
771 const char *errstr = nt_errstr(status);
772 if (NT_STATUS_EQUAL(status, NT_STATUS_NET_WRITE_FAULT)) {
773 errstr = dcerpc_errstr(ctx, ctx->new_dc.drsuapi.pipe->last_fault_code);
775 printf("dcerpc_drsuapi_DsGetNT4ChangeLog failed - %s\n", errstr);
777 } else if (W_ERROR_EQUAL(r.out.result, WERR_INVALID_DOMAIN_ROLE)) {
778 printf("DsGetNT4ChangeLog not supported by target server\n");
780 } else if (!W_ERROR_IS_OK(r.out.result)) {
781 printf("DsGetNT4ChangeLog failed - %s\n", win_errstr(r.out.result));
783 } else if (r.out.level != 1) {
784 printf("DsGetNT4ChangeLog unknown level - %u\n", r.out.level);
786 } else if (NT_STATUS_IS_OK(r.out.info.info1.status)) {
787 } else if (NT_STATUS_EQUAL(r.out.info.info1.status, STATUS_MORE_ENTRIES)) {
788 cookie.length = r.out.info.info1.length1;
789 cookie.data = r.out.info.info1.data1;
792 printf("DsGetNT4ChangeLog failed - %s\n", nt_errstr(r.out.info.info1.status));
802 bool torture_rpc_dssync(struct torture_context *torture)
806 struct DsSyncTest *ctx;
808 mem_ctx = talloc_init("torture_rpc_dssync");
809 ctx = test_create_context(mem_ctx);
811 ret &= _test_DsBind(ctx, ctx->admin.credentials, &ctx->admin.drsuapi);
815 ret &= test_LDAPBind(ctx, ctx->admin.credentials, &ctx->admin.ldap);
819 ret &= test_GetInfo(ctx);
820 ret &= _test_DsBind(ctx, ctx->new_dc.credentials, &ctx->new_dc.drsuapi);
824 ret &= test_FetchData(ctx);
825 ret &= test_FetchNT4Data(ctx);