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 "librpc/gen_ndr/ndr_drsblobs.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"
36 #include "param/param.h"
37 #include "dsdb/samdb/samdb.h"
39 struct DsSyncBindInfo {
40 struct dcerpc_pipe *pipe;
41 struct drsuapi_DsBind req;
42 struct GUID bind_guid;
43 struct drsuapi_DsBindInfoCtr our_bind_info_ctr;
44 struct drsuapi_DsBindInfo28 our_bind_info28;
45 struct drsuapi_DsBindInfo28 peer_bind_info28;
46 struct policy_handle bind_handle;
49 struct DsSyncLDAPInfo {
50 struct ldap_connection *conn;
54 struct dcerpc_binding *drsuapi_binding;
57 const char *site_name;
59 const char *domain_dn;
61 /* what we need to do as 'Administrator' */
63 struct cli_credentials *credentials;
64 struct DsSyncBindInfo drsuapi;
65 struct DsSyncLDAPInfo ldap;
68 /* what we need to do as the new dc machine account */
70 struct cli_credentials *credentials;
71 struct DsSyncBindInfo drsuapi;
72 struct drsuapi_DsGetDCInfo2 dc_info2;
73 struct GUID invocation_id;
74 struct GUID object_guid;
77 /* info about the old dc */
79 struct drsuapi_DsGetDomainControllerInfo dc_info;
83 static struct DsSyncTest *test_create_context(struct torture_context *tctx)
86 struct DsSyncTest *ctx;
87 struct drsuapi_DsBindInfo28 *our_bind_info28;
88 struct drsuapi_DsBindInfoCtr *our_bind_info_ctr;
89 const char *binding = torture_setting_string(tctx, "binding", NULL);
90 ctx = talloc_zero(tctx, struct DsSyncTest);
91 if (!ctx) return NULL;
93 status = dcerpc_parse_binding(ctx, binding, &ctx->drsuapi_binding);
94 if (!NT_STATUS_IS_OK(status)) {
95 printf("Bad binding string %s\n", binding);
98 ctx->drsuapi_binding->flags |= DCERPC_SIGN | DCERPC_SEAL;
100 ctx->ldap_url = talloc_asprintf(ctx, "ldap://%s/", ctx->drsuapi_binding->host);
103 ctx->admin.credentials = cmdline_credentials;
105 our_bind_info28 = &ctx->admin.drsuapi.our_bind_info28;
106 our_bind_info28->supported_extensions = 0xFFFFFFFF;
107 our_bind_info28->supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_ADDENTRYREPLY_V3;
108 our_bind_info28->site_guid = GUID_zero();
109 our_bind_info28->pid = 0;
110 our_bind_info28->repl_epoch = 1;
112 our_bind_info_ctr = &ctx->admin.drsuapi.our_bind_info_ctr;
113 our_bind_info_ctr->length = 28;
114 our_bind_info_ctr->info.info28 = *our_bind_info28;
116 GUID_from_string(DRSUAPI_DS_BIND_GUID, &ctx->admin.drsuapi.bind_guid);
118 ctx->admin.drsuapi.req.in.bind_guid = &ctx->admin.drsuapi.bind_guid;
119 ctx->admin.drsuapi.req.in.bind_info = our_bind_info_ctr;
120 ctx->admin.drsuapi.req.out.bind_handle = &ctx->admin.drsuapi.bind_handle;
123 ctx->new_dc.credentials = cmdline_credentials;
125 our_bind_info28 = &ctx->new_dc.drsuapi.our_bind_info28;
126 our_bind_info28->supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_BASE;
127 our_bind_info28->supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_ASYNC_REPLICATION;
128 our_bind_info28->supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_REMOVEAPI;
129 our_bind_info28->supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_MOVEREQ_V2;
130 our_bind_info28->supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_GETCHG_COMPRESS;
131 our_bind_info28->supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_DCINFO_V1;
132 our_bind_info28->supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_RESTORE_USN_OPTIMIZATION;
133 our_bind_info28->supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_KCC_EXECUTE;
134 our_bind_info28->supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_ADDENTRY_V2;
135 our_bind_info28->supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_LINKED_VALUE_REPLICATION;
136 our_bind_info28->supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_DCINFO_V2;
137 our_bind_info28->supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_INSTANCE_TYPE_NOT_REQ_ON_MOD;
138 our_bind_info28->supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_CRYPTO_BIND;
139 our_bind_info28->supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_GET_REPL_INFO;
140 our_bind_info28->supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_STRONG_ENCRYPTION;
141 our_bind_info28->supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_DCINFO_V01;
142 our_bind_info28->supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_TRANSITIVE_MEMBERSHIP;
143 our_bind_info28->supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_ADD_SID_HISTORY;
144 our_bind_info28->supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_POST_BETA3;
145 our_bind_info28->supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_GET_MEMBERSHIPS2;
146 our_bind_info28->supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_GETCHGREQ_V6;
147 our_bind_info28->supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_NONDOMAIN_NCS;
148 our_bind_info28->supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_GETCHGREQ_V8;
149 our_bind_info28->supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_GETCHGREPLY_V5;
150 our_bind_info28->supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_GETCHGREPLY_V6;
151 our_bind_info28->supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_ADDENTRYREPLY_V3;
152 our_bind_info28->supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_GETCHGREPLY_V7;
153 our_bind_info28->supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_VERIFY_OBJECT;
154 if (lp_parm_bool(tctx->lp_ctx, NULL, "dssync", "xpress", false)) {
155 our_bind_info28->supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_XPRESS_COMPRESS;
157 our_bind_info28->site_guid = GUID_zero();
158 our_bind_info28->pid = 0;
159 our_bind_info28->repl_epoch = 0;
161 our_bind_info_ctr = &ctx->new_dc.drsuapi.our_bind_info_ctr;
162 our_bind_info_ctr->length = 28;
163 our_bind_info_ctr->info.info28 = *our_bind_info28;
165 GUID_from_string(DRSUAPI_DS_BIND_GUID_W2K3, &ctx->new_dc.drsuapi.bind_guid);
167 ctx->new_dc.drsuapi.req.in.bind_guid = &ctx->new_dc.drsuapi.bind_guid;
168 ctx->new_dc.drsuapi.req.in.bind_info = our_bind_info_ctr;
169 ctx->new_dc.drsuapi.req.out.bind_handle = &ctx->new_dc.drsuapi.bind_handle;
171 ctx->new_dc.invocation_id = ctx->new_dc.drsuapi.bind_guid;
178 static bool _test_DsBind(struct torture_context *tctx,
179 struct DsSyncTest *ctx, struct cli_credentials *credentials, struct DsSyncBindInfo *b)
184 status = dcerpc_pipe_connect_b(ctx,
185 &b->pipe, ctx->drsuapi_binding,
187 credentials, tctx->ev, tctx->lp_ctx);
189 if (!NT_STATUS_IS_OK(status)) {
190 printf("Failed to connect to server as a BDC: %s\n", nt_errstr(status));
194 status = dcerpc_drsuapi_DsBind(b->pipe, ctx, &b->req);
195 if (!NT_STATUS_IS_OK(status)) {
196 const char *errstr = nt_errstr(status);
197 if (NT_STATUS_EQUAL(status, NT_STATUS_NET_WRITE_FAULT)) {
198 errstr = dcerpc_errstr(ctx, b->pipe->last_fault_code);
200 printf("dcerpc_drsuapi_DsBind failed - %s\n", errstr);
202 } else if (!W_ERROR_IS_OK(b->req.out.result)) {
203 printf("DsBind failed - %s\n", win_errstr(b->req.out.result));
207 ZERO_STRUCT(b->peer_bind_info28);
208 if (b->req.out.bind_info) {
209 switch (b->req.out.bind_info->length) {
211 struct drsuapi_DsBindInfo24 *info24;
212 info24 = &b->req.out.bind_info->info.info24;
213 b->peer_bind_info28.supported_extensions= info24->supported_extensions;
214 b->peer_bind_info28.site_guid = info24->site_guid;
215 b->peer_bind_info28.pid = info24->pid;
216 b->peer_bind_info28.repl_epoch = 0;
220 struct drsuapi_DsBindInfo48 *info48;
221 info48 = &b->req.out.bind_info->info.info48;
222 b->peer_bind_info28.supported_extensions= info48->supported_extensions;
223 b->peer_bind_info28.site_guid = info48->site_guid;
224 b->peer_bind_info28.pid = info48->pid;
225 b->peer_bind_info28.repl_epoch = info48->repl_epoch;
229 b->peer_bind_info28 = b->req.out.bind_info->info.info28;
232 printf("DsBind - warning: unknown BindInfo length: %u\n",
233 b->req.out.bind_info->length);
240 static bool test_LDAPBind(struct torture_context *tctx, struct DsSyncTest *ctx,
241 struct cli_credentials *credentials, struct DsSyncLDAPInfo *l)
246 status = torture_ldap_connection(tctx, &l->conn, ctx->ldap_url);
247 if (!NT_STATUS_IS_OK(status)) {
248 printf("failed to connect to LDAP: %s\n", ctx->ldap_url);
252 printf("connected to LDAP: %s\n", ctx->ldap_url);
254 status = torture_ldap_bind_sasl(l->conn, credentials, tctx->lp_ctx);
255 if (!NT_STATUS_IS_OK(status)) {
256 printf("failed to bind to LDAP:\n");
259 printf("bound to LDAP.\n");
264 static bool test_GetInfo(struct torture_context *tctx, struct DsSyncTest *ctx)
267 struct drsuapi_DsCrackNames r;
268 struct drsuapi_DsNameString names[1];
270 struct cldap_socket *cldap;
271 struct cldap_netlogon search;
273 cldap = cldap_socket_init(ctx, tctx->ev, lp_iconv_convenience(tctx->lp_ctx));
275 r.in.bind_handle = &ctx->admin.drsuapi.bind_handle;
277 r.in.req.req1.codepage = 1252; /* western european */
278 r.in.req.req1.language = 0x00000407; /* german */
279 r.in.req.req1.count = 1;
280 r.in.req.req1.names = names;
281 r.in.req.req1.format_flags = DRSUAPI_DS_NAME_FLAG_NO_FLAGS;
282 r.in.req.req1.format_offered = DRSUAPI_DS_NAME_FORMAT_NT4_ACCOUNT;
283 r.in.req.req1.format_desired = DRSUAPI_DS_NAME_FORMAT_FQDN_1779;
284 names[0].str = talloc_asprintf(ctx, "%s\\", lp_workgroup(tctx->lp_ctx));
286 status = dcerpc_drsuapi_DsCrackNames(ctx->admin.drsuapi.pipe, ctx, &r);
287 if (!NT_STATUS_IS_OK(status)) {
288 const char *errstr = nt_errstr(status);
289 if (NT_STATUS_EQUAL(status, NT_STATUS_NET_WRITE_FAULT)) {
290 errstr = dcerpc_errstr(ctx, ctx->admin.drsuapi.pipe->last_fault_code);
292 printf("dcerpc_drsuapi_DsCrackNames failed - %s\n", errstr);
294 } else if (!W_ERROR_IS_OK(r.out.result)) {
295 printf("DsCrackNames failed - %s\n", win_errstr(r.out.result));
299 ctx->domain_dn = r.out.ctr.ctr1->array[0].result_name;
302 search.in.dest_address = ctx->drsuapi_binding->host;
303 search.in.dest_port = lp_cldap_port(tctx->lp_ctx);
304 search.in.acct_control = -1;
305 search.in.version = NETLOGON_NT_VERSION_5 | NETLOGON_NT_VERSION_5EX;
306 search.in.map_response = true;
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.nt5_ex.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.nt5_ex.server_site);
318 if (!ctx->domain_dn) {
319 struct ldb_context *ldb = ldb_init(ctx, tctx->ev);
320 struct ldb_dn *dn = samdb_dns_domain_to_dn(ldb, ctx, search.out.netlogon.nt5_ex.dns_domain);
321 ctx->domain_dn = ldb_dn_alloc_linearized(ctx, dn);
329 static DATA_BLOB decrypt_blob(TALLOC_CTX *mem_ctx,
330 const DATA_BLOB *gensec_skey,
332 struct drsuapi_DsReplicaObjectIdentifier *id,
334 const DATA_BLOB *buffer)
336 DATA_BLOB confounder;
337 DATA_BLOB enc_buffer;
339 struct MD5Context md5;
340 uint8_t _enc_key[16];
343 DATA_BLOB dec_buffer;
345 uint32_t crc32_given;
347 DATA_BLOB checked_buffer;
349 DATA_BLOB plain_buffer;
352 * the combination "c[3] s[1] e[1] d[0]..."
353 * was successful!!!!!!!!!!!!!!!!!!!!!!!!!!
357 * the first 16 bytes at the beginning are the confounder
358 * followed by the 4 byte crc32 checksum
360 if (buffer->length < 20) {
361 return data_blob_const(NULL, 0);
363 confounder = data_blob_const(buffer->data, 16);
364 enc_buffer = data_blob_const(buffer->data + 16, buffer->length - 16);
367 * build the encryption key md5 over the session key followed
370 * here the gensec session key is used and
371 * not the dcerpc ncacn_ip_tcp "SystemLibraryDTC" key!
373 enc_key = data_blob_const(_enc_key, sizeof(_enc_key));
375 MD5Update(&md5, gensec_skey->data, gensec_skey->length);
376 MD5Update(&md5, confounder.data, confounder.length);
377 MD5Final(enc_key.data, &md5);
380 * copy the encrypted buffer part and
381 * decrypt it using the created encryption key using arcfour
383 dec_buffer = data_blob_talloc(mem_ctx, enc_buffer.data, enc_buffer.length);
384 if (!dec_buffer.data) {
385 return data_blob_const(NULL, 0);
387 arcfour_crypt_blob(dec_buffer.data, dec_buffer.length, &enc_key);
390 * the first 4 byte are the crc32 checksum
391 * of the remaining bytes
393 crc32_given = IVAL(dec_buffer.data, 0);
394 crc32_calc = crc32_calc_buffer(dec_buffer.data + 4 , dec_buffer.length - 4);
395 if (crc32_given != crc32_calc) {
396 DEBUG(0,("CRC32: given[0x%08X] calc[0x%08X]\n",
397 crc32_given, crc32_calc));
398 return data_blob_const(NULL, 0);
400 checked_buffer = data_blob_talloc(mem_ctx, dec_buffer.data + 4, dec_buffer.length - 4);
401 if (!checked_buffer.data) {
402 return data_blob_const(NULL, 0);
406 * some attributes seem to be in a usable form after this decryption
407 * (supplementalCredentials, priorValue, currentValue, trustAuthOutgoing,
408 * trustAuthIncoming, initialAuthOutgoing, initialAuthIncoming)
409 * At least supplementalCredentials contains plaintext
410 * like "Primary:Kerberos" (in unicode form)
412 * some attributes seem to have some additional encryption
413 * dBCSPwd, unicodePwd, ntPwdHistory, lmPwdHistory
415 * it's the sam_rid_crypt() function, as the value is constant,
416 * so it doesn't depend on sessionkeys.
419 uint32_t i, num_hashes;
421 if ((checked_buffer.length % 16) != 0) {
422 return data_blob_const(NULL, 0);
425 plain_buffer = data_blob_talloc(mem_ctx, checked_buffer.data, checked_buffer.length);
426 if (!plain_buffer.data) {
427 return data_blob_const(NULL, 0);
430 num_hashes = plain_buffer.length / 16;
431 for (i = 0; i < num_hashes; i++) {
432 uint32_t offset = i * 16;
433 sam_rid_crypt(rid, checked_buffer.data + offset, plain_buffer.data + offset, 0);
436 plain_buffer = checked_buffer;
442 static void test_analyse_objects(struct torture_context *tctx,
443 struct DsSyncTest *ctx,
444 const DATA_BLOB *gensec_skey,
445 struct drsuapi_DsReplicaObjectListItemEx *cur)
447 static uint32_t object_id;
448 const char *save_values_dir;
450 if (!lp_parm_bool(tctx->lp_ctx, NULL, "dssync", "print_pwd_blobs", false)) {
454 save_values_dir = lp_parm_string(tctx->lp_ctx, NULL, "dssync", "save_pwd_blobs_dir");
456 for (; cur; cur = cur->next_object) {
458 struct dom_sid *sid = NULL;
460 bool dn_printed = false;
463 if (!cur->object.identifier) continue;
465 dn = cur->object.identifier->dn;
466 if (cur->object.identifier->sid.num_auths > 0) {
467 sid = &cur->object.identifier->sid;
468 rid = sid->sub_auths[sid->num_auths - 1];
471 for (i=0; i < cur->object.attribute_ctr.num_attributes; i++) {
472 const char *name = NULL;
474 DATA_BLOB *enc_data = NULL;
475 DATA_BLOB plain_data;
476 struct drsuapi_DsReplicaAttribute *attr;
477 ndr_pull_flags_fn_t pull_fn = NULL;
478 ndr_print_fn_t print_fn = NULL;
480 attr = &cur->object.attribute_ctr.attributes[i];
482 switch (attr->attid) {
483 case DRSUAPI_ATTRIBUTE_dBCSPwd:
487 case DRSUAPI_ATTRIBUTE_unicodePwd:
491 case DRSUAPI_ATTRIBUTE_ntPwdHistory:
492 name = "ntPwdHistory";
495 case DRSUAPI_ATTRIBUTE_lmPwdHistory:
496 name = "lmPwdHistory";
499 case DRSUAPI_ATTRIBUTE_supplementalCredentials:
500 name = "supplementalCredentials";
501 pull_fn = (ndr_pull_flags_fn_t)ndr_pull_supplementalCredentialsBlob;
502 print_fn = (ndr_print_fn_t)ndr_print_supplementalCredentialsBlob;
503 ptr = talloc(ctx, struct supplementalCredentialsBlob);
505 case DRSUAPI_ATTRIBUTE_priorValue:
508 case DRSUAPI_ATTRIBUTE_currentValue:
509 name = "currentValue";
511 case DRSUAPI_ATTRIBUTE_trustAuthOutgoing:
512 name = "trustAuthOutgoing";
513 pull_fn = (ndr_pull_flags_fn_t)ndr_pull_trustAuthInOutBlob;
514 print_fn = (ndr_print_fn_t)ndr_print_trustAuthInOutBlob;
515 ptr = talloc(ctx, struct trustAuthInOutBlob);
517 case DRSUAPI_ATTRIBUTE_trustAuthIncoming:
518 name = "trustAuthIncoming";
519 pull_fn = (ndr_pull_flags_fn_t)ndr_pull_trustAuthInOutBlob;
520 print_fn = (ndr_print_fn_t)ndr_print_trustAuthInOutBlob;
521 ptr = talloc(ctx, struct trustAuthInOutBlob);
523 case DRSUAPI_ATTRIBUTE_initialAuthOutgoing:
524 name = "initialAuthOutgoing";
526 case DRSUAPI_ATTRIBUTE_initialAuthIncoming:
527 name = "initialAuthIncoming";
533 if (attr->value_ctr.num_values != 1) continue;
535 if (!attr->value_ctr.values[0].blob) continue;
537 enc_data = attr->value_ctr.values[0].blob;
538 ZERO_STRUCT(plain_data);
540 plain_data = decrypt_blob(ctx, gensec_skey, rcrypt,
541 cur->object.identifier, rid,
545 DEBUG(0,("DN[%u] %s\n", object_id, dn));
548 DEBUGADD(0,("ATTR: %s enc.length=%lu plain.length=%lu\n",
549 name, (long)enc_data->length, (long)plain_data.length));
550 if (plain_data.length) {
551 enum ndr_err_code ndr_err;
552 dump_data(0, plain_data.data, plain_data.length);
553 if (save_values_dir) {
555 fname = talloc_asprintf(ctx, "%s/%s%02d",
560 ok = file_save(fname, plain_data.data, plain_data.length);
562 DEBUGADD(0,("Failed to save '%s'\n", fname));
569 ndr_err = ndr_pull_struct_blob_all(&plain_data, ptr,
570 lp_iconv_convenience(tctx->lp_ctx), ptr,
572 if (NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
573 ndr_print_debug(print_fn, name, ptr);
575 DEBUG(0, ("Failed to decode %s\n", name));
579 dump_data(0, enc_data->data, enc_data->length);
586 static bool test_FetchData(struct torture_context *tctx, struct DsSyncTest *ctx)
591 uint64_t highest_usn = 0;
592 const char *partition = NULL;
593 struct drsuapi_DsGetNCChanges r;
594 struct drsuapi_DsReplicaObjectIdentifier nc;
595 struct drsuapi_DsGetNCChangesCtr1 *ctr1 = NULL;
596 struct drsuapi_DsGetNCChangesCtr6 *ctr6 = NULL;
597 int32_t out_level = 0;
598 struct GUID null_guid;
599 struct dom_sid null_sid;
600 DATA_BLOB gensec_skey;
612 ZERO_STRUCT(null_guid);
613 ZERO_STRUCT(null_sid);
615 partition = lp_parm_string(tctx->lp_ctx, NULL, "dssync", "partition");
616 if (partition == NULL) {
617 partition = ctx->domain_dn;
618 printf("dssync:partition not specified, defaulting to %s.\n", ctx->domain_dn);
621 highest_usn = lp_parm_int(tctx->lp_ctx, NULL, "dssync", "highest_usn", 0);
623 array[0].level = lp_parm_int(tctx->lp_ctx, NULL, "dssync", "get_nc_changes_level", array[0].level);
625 if (lp_parm_bool(tctx->lp_ctx, NULL, "dssync", "print_pwd_blobs", false)) {
626 const struct samr_Password *nthash;
627 nthash = cli_credentials_get_nt_hash(ctx->new_dc.credentials, ctx);
629 dump_data_pw("CREDENTIALS nthash:", nthash->hash, sizeof(nthash->hash));
632 status = gensec_session_key(ctx->new_dc.drsuapi.pipe->conn->security_state.generic_state,
634 if (!NT_STATUS_IS_OK(status)) {
635 printf("failed to get gensec session key: %s\n", nt_errstr(status));
639 for (i=0; i < ARRAY_SIZE(array); i++) {
640 printf("testing DsGetNCChanges level %d\n",
643 r.in.bind_handle = &ctx->new_dc.drsuapi.bind_handle;
644 r.in.level = &array[i].level;
646 switch (*r.in.level) {
652 r.in.req.req5.destination_dsa_guid = ctx->new_dc.invocation_id;
653 r.in.req.req5.source_dsa_invocation_id = null_guid;
654 r.in.req.req5.naming_context = &nc;
655 r.in.req.req5.highwatermark.tmp_highest_usn = highest_usn;
656 r.in.req.req5.highwatermark.reserved_usn = 0;
657 r.in.req.req5.highwatermark.highest_usn = highest_usn;
658 r.in.req.req5.uptodateness_vector = NULL;
659 r.in.req.req5.replica_flags = 0;
660 if (lp_parm_bool(tctx->lp_ctx, NULL, "dssync", "compression", false)) {
661 r.in.req.req5.replica_flags |= DRSUAPI_DS_REPLICA_NEIGHBOUR_COMPRESS_CHANGES;
663 if (lp_parm_bool(tctx->lp_ctx, NULL, "dssync", "neighbour_writeable", true)) {
664 r.in.req.req5.replica_flags |= DRSUAPI_DS_REPLICA_NEIGHBOUR_WRITEABLE;
666 r.in.req.req5.replica_flags |= DRSUAPI_DS_REPLICA_NEIGHBOUR_SYNC_ON_STARTUP
667 | DRSUAPI_DS_REPLICA_NEIGHBOUR_DO_SCHEDULED_SYNCS
668 | DRSUAPI_DS_REPLICA_NEIGHBOUR_RETURN_OBJECT_PARENTS
669 | DRSUAPI_DS_REPLICA_NEIGHBOUR_NEVER_SYNCED
671 r.in.req.req5.max_object_count = 133;
672 r.in.req.req5.max_ndr_size = 1336770;
673 r.in.req.req5.extended_op = DRSUAPI_EXOP_NONE;
674 r.in.req.req5.fsmo_info = 0;
681 /* nc.dn can be set to any other ad partition */
683 r.in.req.req8.destination_dsa_guid = ctx->new_dc.invocation_id;
684 r.in.req.req8.source_dsa_invocation_id = null_guid;
685 r.in.req.req8.naming_context = &nc;
686 r.in.req.req8.highwatermark.tmp_highest_usn = highest_usn;
687 r.in.req.req8.highwatermark.reserved_usn = 0;
688 r.in.req.req8.highwatermark.highest_usn = highest_usn;
689 r.in.req.req8.uptodateness_vector = NULL;
690 r.in.req.req8.replica_flags = 0;
691 if (lp_parm_bool(tctx->lp_ctx, NULL, "dssync", "compression", false)) {
692 r.in.req.req8.replica_flags |= DRSUAPI_DS_REPLICA_NEIGHBOUR_COMPRESS_CHANGES;
694 if (lp_parm_bool(tctx->lp_ctx, NULL, "dssync", "neighbour_writeable", true)) {
695 r.in.req.req8.replica_flags |= DRSUAPI_DS_REPLICA_NEIGHBOUR_WRITEABLE;
697 r.in.req.req8.replica_flags |= DRSUAPI_DS_REPLICA_NEIGHBOUR_SYNC_ON_STARTUP
698 | DRSUAPI_DS_REPLICA_NEIGHBOUR_DO_SCHEDULED_SYNCS
699 | DRSUAPI_DS_REPLICA_NEIGHBOUR_RETURN_OBJECT_PARENTS
700 | DRSUAPI_DS_REPLICA_NEIGHBOUR_NEVER_SYNCED
702 r.in.req.req8.max_object_count = 402;
703 r.in.req.req8.max_ndr_size = 402116;
705 r.in.req.req8.extended_op = DRSUAPI_EXOP_NONE;
706 r.in.req.req8.fsmo_info = 0;
707 r.in.req.req8.partial_attribute_set = NULL;
708 r.in.req.req8.partial_attribute_set_ex = NULL;
709 r.in.req.req8.mapping_ctr.num_mappings = 0;
710 r.in.req.req8.mapping_ctr.mappings = NULL;
715 printf("Dumping AD partition: %s\n", nc.dn);
719 r.out.level = &_level;
721 if (*r.in.level == 5) {
722 DEBUG(0,("start[%d] tmp_higest_usn: %llu , highest_usn: %llu\n",y,
723 (long long)r.in.req.req5.highwatermark.tmp_highest_usn,
724 (long long)r.in.req.req5.highwatermark.highest_usn));
727 if (*r.in.level == 8) {
728 DEBUG(0,("start[%d] tmp_higest_usn: %llu , highest_usn: %llu\n",y,
729 (long long)r.in.req.req8.highwatermark.tmp_highest_usn,
730 (long long)r.in.req.req8.highwatermark.highest_usn));
733 status = dcerpc_drsuapi_DsGetNCChanges(ctx->new_dc.drsuapi.pipe, ctx, &r);
734 if (!NT_STATUS_IS_OK(status)) {
735 const char *errstr = nt_errstr(status);
736 if (NT_STATUS_EQUAL(status, NT_STATUS_NET_WRITE_FAULT)) {
737 errstr = dcerpc_errstr(ctx, ctx->new_dc.drsuapi.pipe->last_fault_code);
739 printf("dcerpc_drsuapi_DsGetNCChanges failed - %s\n", errstr);
741 } else if (!W_ERROR_IS_OK(r.out.result)) {
742 printf("DsGetNCChanges failed - %s\n", win_errstr(r.out.result));
746 if (ret == true && *r.out.level == 1) {
748 ctr1 = &r.out.ctr.ctr1;
749 } else if (ret == true && *r.out.level == 2) {
751 ctr1 = r.out.ctr.ctr2.ctr.mszip1.ctr1;
754 if (out_level == 1) {
755 DEBUG(0,("end[%d] tmp_highest_usn: %llu , highest_usn: %llu\n",y,
756 (long long)ctr1->new_highwatermark.tmp_highest_usn,
757 (long long)ctr1->new_highwatermark.highest_usn));
759 test_analyse_objects(tctx, ctx, &gensec_skey, ctr1->first_object);
761 if (ctr1->more_data) {
762 r.in.req.req5.highwatermark = ctr1->new_highwatermark;
767 if (ret == true && *r.out.level == 6) {
769 ctr6 = &r.out.ctr.ctr6;
770 } else if (ret == true && *r.out.level == 7
771 && r.out.ctr.ctr7.level == 6
772 && r.out.ctr.ctr7.type == DRSUAPI_COMPRESSION_TYPE_MSZIP) {
774 ctr6 = r.out.ctr.ctr7.ctr.mszip6.ctr6;
775 } else if (ret == true && *r.out.level == 7
776 && r.out.ctr.ctr7.level == 6
777 && r.out.ctr.ctr7.type == DRSUAPI_COMPRESSION_TYPE_XPRESS) {
779 ctr6 = r.out.ctr.ctr7.ctr.xpress6.ctr6;
782 if (out_level == 6) {
783 DEBUG(0,("end[%d] tmp_highest_usn: %llu , highest_usn: %llu\n",y,
784 (long long)ctr6->new_highwatermark.tmp_highest_usn,
785 (long long)ctr6->new_highwatermark.highest_usn));
787 test_analyse_objects(tctx, ctx, &gensec_skey, ctr6->first_object);
789 if (ctr6->more_data) {
790 r.in.req.req8.highwatermark = ctr6->new_highwatermark;
802 static bool test_FetchNT4Data(struct torture_context *tctx,
803 struct DsSyncTest *ctx)
807 struct drsuapi_DsGetNT4ChangeLog r;
808 struct GUID null_guid;
809 struct dom_sid null_sid;
812 ZERO_STRUCT(null_guid);
813 ZERO_STRUCT(null_sid);
817 r.in.bind_handle = &ctx->new_dc.drsuapi.bind_handle;
820 r.in.req.req1.unknown1 = lp_parm_int(tctx->lp_ctx, NULL, "dssync", "nt4-1", 3);
821 r.in.req.req1.unknown2 = lp_parm_int(tctx->lp_ctx, NULL, "dssync", "nt4-2", 0x00004000);
824 r.in.req.req1.length = cookie.length;
825 r.in.req.req1.data = cookie.data;
827 status = dcerpc_drsuapi_DsGetNT4ChangeLog(ctx->new_dc.drsuapi.pipe, ctx, &r);
828 if (NT_STATUS_EQUAL(status, NT_STATUS_NOT_IMPLEMENTED)) {
829 printf("DsGetNT4ChangeLog not supported by target server\n");
831 } else if (!NT_STATUS_IS_OK(status)) {
832 const char *errstr = nt_errstr(status);
833 if (NT_STATUS_EQUAL(status, NT_STATUS_NET_WRITE_FAULT)) {
834 errstr = dcerpc_errstr(ctx, ctx->new_dc.drsuapi.pipe->last_fault_code);
836 printf("dcerpc_drsuapi_DsGetNT4ChangeLog failed - %s\n", errstr);
838 } else if (W_ERROR_EQUAL(r.out.result, WERR_INVALID_DOMAIN_ROLE)) {
839 printf("DsGetNT4ChangeLog not supported by target server\n");
841 } else if (!W_ERROR_IS_OK(r.out.result)) {
842 printf("DsGetNT4ChangeLog failed - %s\n", win_errstr(r.out.result));
844 } else if (r.out.level != 1) {
845 printf("DsGetNT4ChangeLog unknown level - %u\n", r.out.level);
847 } else if (NT_STATUS_IS_OK(r.out.info.info1.status)) {
848 } else if (NT_STATUS_EQUAL(r.out.info.info1.status, STATUS_MORE_ENTRIES)) {
849 cookie.length = r.out.info.info1.length1;
850 cookie.data = r.out.info.info1.data1;
853 printf("DsGetNT4ChangeLog failed - %s\n", nt_errstr(r.out.info.info1.status));
863 bool torture_rpc_dssync(struct torture_context *torture)
867 struct DsSyncTest *ctx;
869 mem_ctx = talloc_init("torture_rpc_dssync");
870 ctx = test_create_context(torture);
872 ret &= _test_DsBind(torture, ctx, ctx->admin.credentials, &ctx->admin.drsuapi);
876 ret &= test_LDAPBind(torture, ctx, ctx->admin.credentials, &ctx->admin.ldap);
880 ret &= test_GetInfo(torture, ctx);
881 ret &= _test_DsBind(torture, ctx, ctx->new_dc.credentials, &ctx->new_dc.drsuapi);
885 ret &= test_FetchData(torture, ctx);
886 ret &= test_FetchNT4Data(torture, ctx);