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 "torture/torture.h"
29 #include "../libcli/drsuapi/drsuapi.h"
30 #include "auth/gensec/gensec.h"
31 #include "param/param.h"
32 #include "dsdb/samdb/samdb.h"
33 #include "torture/rpc/torture_rpc.h"
34 #include "torture/drs/proto.h"
35 #include "lib/tsocket/tsocket.h"
36 #include "libcli/resolve/resolve.h"
38 struct DsSyncBindInfo {
39 struct dcerpc_pipe *drs_pipe;
40 struct dcerpc_binding_handle *drs_handle;
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 ldb_context *ldb;
54 struct dcerpc_binding *drsuapi_binding;
57 const char *dest_address;
58 const char *domain_dn;
59 const char *config_dn;
60 const char *schema_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(struct torture_context *tctx)
87 struct DsSyncTest *ctx;
88 struct drsuapi_DsBindInfo28 *our_bind_info28;
89 struct drsuapi_DsBindInfoCtr *our_bind_info_ctr;
90 const char *binding = torture_setting_string(tctx, "binding", NULL);
93 ctx = talloc_zero(tctx, struct DsSyncTest);
94 if (!ctx) return NULL;
96 status = dcerpc_parse_binding(ctx, binding, &ctx->drsuapi_binding);
97 if (!NT_STATUS_IS_OK(status)) {
98 printf("Bad binding string %s\n", binding);
101 ctx->drsuapi_binding->flags |= DCERPC_SIGN | DCERPC_SEAL;
103 ctx->ldap_url = talloc_asprintf(ctx, "ldap://%s", ctx->drsuapi_binding->host);
105 make_nbt_name_server(&name, ctx->drsuapi_binding->host);
107 /* do an initial name resolution to find its IP */
108 status = resolve_name_ex(lpcfg_resolve_context(tctx->lp_ctx),
110 &ctx->dest_address, tctx->ev);
111 if (!NT_STATUS_IS_OK(status)) {
112 printf("Failed to resolve %s - %s\n",
113 name.name, nt_errstr(status));
118 ctx->admin.credentials = cmdline_credentials;
120 our_bind_info28 = &ctx->admin.drsuapi.our_bind_info28;
121 our_bind_info28->supported_extensions = 0xFFFFFFFF;
122 our_bind_info28->supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_ADDENTRYREPLY_V3;
123 our_bind_info28->site_guid = GUID_zero();
124 our_bind_info28->pid = 0;
125 our_bind_info28->repl_epoch = 1;
127 our_bind_info_ctr = &ctx->admin.drsuapi.our_bind_info_ctr;
128 our_bind_info_ctr->length = 28;
129 our_bind_info_ctr->info.info28 = *our_bind_info28;
131 GUID_from_string(DRSUAPI_DS_BIND_GUID, &ctx->admin.drsuapi.bind_guid);
133 ctx->admin.drsuapi.req.in.bind_guid = &ctx->admin.drsuapi.bind_guid;
134 ctx->admin.drsuapi.req.in.bind_info = our_bind_info_ctr;
135 ctx->admin.drsuapi.req.out.bind_handle = &ctx->admin.drsuapi.bind_handle;
138 ctx->new_dc.credentials = cmdline_credentials;
140 our_bind_info28 = &ctx->new_dc.drsuapi.our_bind_info28;
141 our_bind_info28->supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_BASE;
142 our_bind_info28->supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_ASYNC_REPLICATION;
143 our_bind_info28->supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_REMOVEAPI;
144 our_bind_info28->supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_MOVEREQ_V2;
145 our_bind_info28->supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_GETCHG_COMPRESS;
146 our_bind_info28->supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_DCINFO_V1;
147 our_bind_info28->supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_RESTORE_USN_OPTIMIZATION;
148 our_bind_info28->supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_KCC_EXECUTE;
149 our_bind_info28->supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_ADDENTRY_V2;
150 our_bind_info28->supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_LINKED_VALUE_REPLICATION;
151 our_bind_info28->supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_DCINFO_V2;
152 our_bind_info28->supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_INSTANCE_TYPE_NOT_REQ_ON_MOD;
153 our_bind_info28->supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_CRYPTO_BIND;
154 our_bind_info28->supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_GET_REPL_INFO;
155 our_bind_info28->supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_STRONG_ENCRYPTION;
156 our_bind_info28->supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_DCINFO_V01;
157 our_bind_info28->supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_TRANSITIVE_MEMBERSHIP;
158 our_bind_info28->supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_ADD_SID_HISTORY;
159 our_bind_info28->supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_POST_BETA3;
160 our_bind_info28->supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_GET_MEMBERSHIPS2;
161 our_bind_info28->supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_GETCHGREQ_V6;
162 our_bind_info28->supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_NONDOMAIN_NCS;
163 our_bind_info28->supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_GETCHGREQ_V8;
164 our_bind_info28->supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_GETCHGREPLY_V5;
165 our_bind_info28->supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_GETCHGREPLY_V6;
166 our_bind_info28->supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_ADDENTRYREPLY_V3;
167 our_bind_info28->supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_GETCHGREPLY_V7;
168 our_bind_info28->supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_VERIFY_OBJECT;
169 if (lpcfg_parm_bool(tctx->lp_ctx, NULL, "dssync", "xpress", false)) {
170 our_bind_info28->supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_XPRESS_COMPRESS;
172 our_bind_info28->site_guid = GUID_zero();
173 our_bind_info28->pid = 0;
174 our_bind_info28->repl_epoch = 0;
176 our_bind_info_ctr = &ctx->new_dc.drsuapi.our_bind_info_ctr;
177 our_bind_info_ctr->length = 28;
178 our_bind_info_ctr->info.info28 = *our_bind_info28;
180 GUID_from_string(DRSUAPI_DS_BIND_GUID_W2K3, &ctx->new_dc.drsuapi.bind_guid);
182 ctx->new_dc.drsuapi.req.in.bind_guid = &ctx->new_dc.drsuapi.bind_guid;
183 ctx->new_dc.drsuapi.req.in.bind_info = our_bind_info_ctr;
184 ctx->new_dc.drsuapi.req.out.bind_handle = &ctx->new_dc.drsuapi.bind_handle;
186 ctx->new_dc.invocation_id = ctx->new_dc.drsuapi.bind_guid;
193 static bool _test_DsBind(struct torture_context *tctx,
194 struct DsSyncTest *ctx, struct cli_credentials *credentials, struct DsSyncBindInfo *b)
199 status = dcerpc_pipe_connect_b(ctx,
200 &b->drs_pipe, ctx->drsuapi_binding,
202 credentials, tctx->ev, tctx->lp_ctx);
204 if (!NT_STATUS_IS_OK(status)) {
205 printf("Failed to connect to server as a BDC: %s\n", nt_errstr(status));
208 b->drs_handle = b->drs_pipe->binding_handle;
210 status = dcerpc_drsuapi_DsBind_r(b->drs_handle, ctx, &b->req);
211 if (!NT_STATUS_IS_OK(status)) {
212 const char *errstr = nt_errstr(status);
213 printf("dcerpc_drsuapi_DsBind failed - %s\n", errstr);
215 } else if (!W_ERROR_IS_OK(b->req.out.result)) {
216 printf("DsBind failed - %s\n", win_errstr(b->req.out.result));
220 ZERO_STRUCT(b->peer_bind_info28);
221 if (b->req.out.bind_info) {
222 switch (b->req.out.bind_info->length) {
224 struct drsuapi_DsBindInfo24 *info24;
225 info24 = &b->req.out.bind_info->info.info24;
226 b->peer_bind_info28.supported_extensions= info24->supported_extensions;
227 b->peer_bind_info28.site_guid = info24->site_guid;
228 b->peer_bind_info28.pid = info24->pid;
229 b->peer_bind_info28.repl_epoch = 0;
233 struct drsuapi_DsBindInfo48 *info48;
234 info48 = &b->req.out.bind_info->info.info48;
235 b->peer_bind_info28.supported_extensions= info48->supported_extensions;
236 b->peer_bind_info28.site_guid = info48->site_guid;
237 b->peer_bind_info28.pid = info48->pid;
238 b->peer_bind_info28.repl_epoch = info48->repl_epoch;
242 b->peer_bind_info28 = b->req.out.bind_info->info.info28;
245 printf("DsBind - warning: unknown BindInfo length: %u\n",
246 b->req.out.bind_info->length);
253 static bool test_LDAPBind(struct torture_context *tctx, struct DsSyncTest *ctx,
254 struct cli_credentials *credentials, struct DsSyncLDAPInfo *l)
258 struct ldb_context *ldb;
260 const char *modules_option[] = { "modules:paged_searches", NULL };
261 ctx->admin.ldap.ldb = ldb = ldb_init(ctx, tctx->ev);
266 /* Despite us loading the schema from the AD server, we need
267 * the samba handlers to get the extended DN syntax stuff */
268 ret = ldb_register_samba_handlers(ldb);
269 if (ret != LDB_SUCCESS) {
274 ldb_set_modules_dir(ldb, modules_path(ldb, "ldb"));
276 if (ldb_set_opaque(ldb, "credentials", credentials)) {
281 if (ldb_set_opaque(ldb, "loadparm", tctx->lp_ctx)) {
286 ret = ldb_connect(ldb, ctx->ldap_url, 0, modules_option);
287 if (ret != LDB_SUCCESS) {
289 torture_assert_int_equal(tctx, ret, LDB_SUCCESS, "Failed to make LDB connection to target");
292 printf("connected to LDAP: %s\n", ctx->ldap_url);
297 static bool test_GetInfo(struct torture_context *tctx, struct DsSyncTest *ctx)
299 struct ldb_context *ldb = ctx->admin.ldap.ldb;
301 /* We must have LDB connection ready by this time */
302 SMB_ASSERT(ldb != NULL);
304 ctx->domain_dn = ldb_dn_get_linearized(ldb_get_default_basedn(ldb));
305 torture_assert(tctx, ctx->domain_dn != NULL, "Failed to get Domain DN");
307 ctx->config_dn = ldb_dn_get_linearized(ldb_get_config_basedn(ldb));
308 torture_assert(tctx, ctx->config_dn != NULL, "Failed to get Domain DN");
310 ctx->schema_dn = ldb_dn_get_linearized(ldb_get_schema_basedn(ldb));
311 torture_assert(tctx, ctx->schema_dn != NULL, "Failed to get Domain DN");
316 static bool test_analyse_objects(struct torture_context *tctx,
317 struct DsSyncTest *ctx,
318 const char *partition,
319 const struct drsuapi_DsReplicaOIDMapping_Ctr *mapping_ctr,
320 uint32_t object_count,
321 const struct drsuapi_DsReplicaObjectListItemEx *first_object,
322 uint32_t linked_attributes_count,
323 const struct drsuapi_DsReplicaLinkedAttribute *linked_attributes,
324 const DATA_BLOB *gensec_skey)
326 static uint32_t object_id;
327 const char *save_values_dir;
328 const struct drsuapi_DsReplicaObjectListItemEx *cur;
329 struct ldb_context *ldb = ctx->admin.ldap.ldb;
330 struct ldb_dn *deleted_dn;
333 struct dsdb_extended_replicated_objects *objs;
334 struct ldb_extended_dn_control *extended_dn_ctrl;
335 struct dsdb_schema *ldap_schema;
337 /* load dsdb_schema using remote prefixMap */
339 drs_util_dsdb_schema_load_ldb(tctx, ldb, mapping_ctr, false),
340 "drs_util_dsdb_schema_load_ldb() failed");
341 ldap_schema = dsdb_get_schema(ldb, NULL);
343 status = dsdb_replicated_objects_convert(ldb,
349 linked_attributes_count,
355 torture_assert_werr_ok(tctx, status, "dsdb_extended_replicated_objects_convert() failed!");
357 extended_dn_ctrl = talloc(objs, struct ldb_extended_dn_control);
358 extended_dn_ctrl->type = 1;
360 deleted_dn = ldb_dn_new(objs, ldb, partition);
361 ldb_dn_add_child_fmt(deleted_dn, "CN=Deleted Objects");
363 for (i=0; i < object_count; i++) {
364 struct ldb_request *search_req;
365 struct ldb_result *res;
366 struct ldb_message *new_msg, *drs_msg, *ldap_msg;
367 const char **attrs = talloc_array(objs, const char *, objs->objects[i].msg->num_elements+1+1);
368 for (j=0; j < objs->objects[i].msg->num_elements; j++) {
369 attrs[j] = objs->objects[i].msg->elements[j].name;
371 attrs[j] = "uSNChanged";
374 res = talloc_zero(objs, struct ldb_result);
376 return LDB_ERR_OPERATIONS_ERROR;
378 ret = ldb_build_search_req(&search_req, ldb, objs,
379 objs->objects[i].msg->dn,
385 ldb_search_default_callback,
387 if (ret != LDB_SUCCESS) {
390 talloc_steal(search_req, res);
391 ret = ldb_request_add_control(search_req, LDB_CONTROL_SHOW_DELETED_OID, true, NULL);
392 if (ret != LDB_SUCCESS) {
396 ret = ldb_request_add_control(search_req, LDB_CONTROL_SHOW_RECYCLED_OID, false, NULL);
397 if (ret != LDB_SUCCESS) {
401 ret = ldb_request_add_control(search_req, LDB_CONTROL_EXTENDED_DN_OID, true, extended_dn_ctrl);
402 if (ret != LDB_SUCCESS) {
406 ret = ldb_request(ldb, search_req);
407 if (ret == LDB_SUCCESS) {
408 ret = ldb_wait(search_req->handle, LDB_WAIT_ALL);
411 torture_assert_int_equal(tctx, ret, LDB_SUCCESS,
412 talloc_asprintf(tctx,
413 "Could not re-fetch object just delivered over DRS: %s",
414 ldb_errstring(ldb)));
415 torture_assert_int_equal(tctx, res->count, 1, "Could not re-fetch object just delivered over DRS");
416 ldap_msg = res->msgs[0];
419 uint64_t usn = ldb_msg_find_attr_as_int64(ldap_msg, "uSNChanged", 0);
421 GUID_from_ndr_blob(&objs->objects[i].guid_value, &g);
422 torture_comment(tctx, "o[%d] usn_changed[%llu]: %s - %s\n", i, (unsigned long long)usn,
423 GUID_string(objs, &g),
424 ldb_dn_get_linearized(objs->objects[i].msg->dn));
427 for (j=0; j < ldap_msg->num_elements; j++) {
428 ldap_msg->elements[j].flags = LDB_FLAG_MOD_ADD;
429 /* For unknown reasons, there is no nTSecurityDescriptor on cn=deleted objects over LDAP, but there is over DRS! Skip it on both transports for now here so */
430 if ((ldb_attr_cmp(ldap_msg->elements[j].name, "nTSecurityDescriptor") == 0) &&
431 (ldb_dn_compare(ldap_msg->dn, deleted_dn) == 0)) {
432 ldb_msg_remove_element(ldap_msg, &ldap_msg->elements[j]);
438 ret = ldb_msg_normalize(ldb, search_req,
439 objs->objects[i].msg, &drs_msg);
440 torture_assert(tctx, ret == LDB_SUCCESS,
441 "ldb_msg_normalize() has failed");
443 for (j=0; j < drs_msg->num_elements; j++) {
444 if (drs_msg->elements[j].num_values == 0) {
445 ldb_msg_remove_element(drs_msg, &drs_msg->elements[j]);
449 /* For unknown reasons, there is no nTSecurityDescriptor on cn=deleted objects over LDAP, but there is over DRS! */
450 } else if ((ldb_attr_cmp(drs_msg->elements[j].name, "nTSecurityDescriptor") == 0) &&
451 (ldb_dn_compare(drs_msg->dn, deleted_dn) == 0)) {
452 ldb_msg_remove_element(drs_msg, &drs_msg->elements[j]);
455 } else if (ldb_attr_cmp(drs_msg->elements[j].name, "unicodePwd") == 0 ||
456 ldb_attr_cmp(drs_msg->elements[j].name, "dBCSPwd") == 0 ||
457 ldb_attr_cmp(drs_msg->elements[j].name, "ntPwdHistory") == 0 ||
458 ldb_attr_cmp(drs_msg->elements[j].name, "lmPwdHistory") == 0 ||
459 ldb_attr_cmp(drs_msg->elements[j].name, "supplementalCredentials") == 0 ||
460 ldb_attr_cmp(drs_msg->elements[j].name, "priorValue") == 0 ||
461 ldb_attr_cmp(drs_msg->elements[j].name, "currentValue") == 0 ||
462 ldb_attr_cmp(drs_msg->elements[j].name, "trustAuthOutgoing") == 0 ||
463 ldb_attr_cmp(drs_msg->elements[j].name, "trustAuthIncoming") == 0 ||
464 ldb_attr_cmp(drs_msg->elements[j].name, "initialAuthOutgoing") == 0 ||
465 ldb_attr_cmp(drs_msg->elements[j].name, "initialAuthIncoming") == 0) {
467 /* These are not shown over LDAP, so we need to skip them for the comparison */
468 ldb_msg_remove_element(drs_msg, &drs_msg->elements[j]);
472 drs_msg->elements[j].flags = LDB_FLAG_MOD_ADD;
477 ret = ldb_msg_difference(ldb, search_req,
478 drs_msg, ldap_msg, &new_msg);
479 torture_assert(tctx, ret == LDB_SUCCESS, "ldb_msg_difference() has failed");
480 if (new_msg->num_elements != 0) {
482 bool is_warning = true;
484 struct ldb_message_element *el;
485 const struct dsdb_attribute * a;
486 struct ldb_ldif ldif;
487 ldif.changetype = LDB_CHANGETYPE_MODIFY;
489 s = ldb_ldif_write_string(ldb, new_msg, &ldif);
490 s = talloc_asprintf(tctx, "\n# Difference in between DRS and LDAP objects: \n%s", s);
492 ret = ldb_msg_difference(ldb, search_req,
493 ldap_msg, drs_msg, &ldif.msg);
494 torture_assert(tctx, ret == LDB_SUCCESS, "ldb_msg_difference() has failed");
495 s = talloc_asprintf_append(s,
496 "\n# Difference in between LDAP and DRS objects: \n%s",
497 ldb_ldif_write_string(ldb, new_msg, &ldif));
499 s = talloc_asprintf_append(s,
500 "# Should have no objects in 'difference' message. Diff elements: %d",
501 new_msg->num_elements);
504 * In case differences in messages are:
505 * 1. Attributes with different values, i.e. 'replace'
506 * 2. Those attributes are forward-link attributes
507 * then we just warn about those differences.
508 * It turns out windows doesn't send all of those values
509 * in replicated_object but in linked_attributes.
511 for (idx = 0; idx < new_msg->num_elements && is_warning; idx++) {
512 el = &new_msg->elements[idx];
513 a = dsdb_attribute_by_lDAPDisplayName(ldap_schema,
515 if (!(el->flags & (LDB_FLAG_MOD_ADD|LDB_FLAG_MOD_REPLACE))) {
518 } else if (a->linkID & 1) {
523 torture_warning(tctx, "%s", s);
525 torture_fail(tctx, s);
529 /* search_req is used as a tmp talloc context in the above */
530 talloc_free(search_req);
533 for (i=0; i < objs->linked_attributes_count; i++) {
534 torture_comment(tctx, "l[%d] usn_changed[%llu]: attid[%u] %s\n", i,
535 (unsigned long long)objs->linked_attributes[i].meta_data.originating_usn,
536 objs->linked_attributes[i].attid,
537 GUID_string(objs, &objs->linked_attributes[i].identifier->guid));
539 if (!lpcfg_parm_bool(tctx->lp_ctx, NULL, "dssync", "print_pwd_blobs", false)) {
544 save_values_dir = lpcfg_parm_string(tctx->lp_ctx, NULL, "dssync", "save_pwd_blobs_dir");
546 for (cur = first_object; cur; cur = cur->next_object) {
548 struct dom_sid *sid = NULL;
550 bool dn_printed = false;
552 if (!cur->object.identifier) continue;
554 dn = cur->object.identifier->dn;
555 if (cur->object.identifier->sid.num_auths > 0) {
556 sid = &cur->object.identifier->sid;
557 rid = sid->sub_auths[sid->num_auths - 1];
560 for (i=0; i < cur->object.attribute_ctr.num_attributes; i++) {
561 const char *name = NULL;
562 DATA_BLOB plain_data;
563 struct drsuapi_DsReplicaAttribute *attr;
564 ndr_pull_flags_fn_t pull_fn = NULL;
565 ndr_print_fn_t print_fn = NULL;
567 attr = &cur->object.attribute_ctr.attributes[i];
569 switch (attr->attid) {
570 case DRSUAPI_ATTID_dBCSPwd:
573 case DRSUAPI_ATTID_unicodePwd:
576 case DRSUAPI_ATTID_ntPwdHistory:
577 name = "ntPwdHistory";
579 case DRSUAPI_ATTID_lmPwdHistory:
580 name = "lmPwdHistory";
582 case DRSUAPI_ATTID_supplementalCredentials:
583 name = "supplementalCredentials";
584 pull_fn = (ndr_pull_flags_fn_t)ndr_pull_supplementalCredentialsBlob;
585 print_fn = (ndr_print_fn_t)ndr_print_supplementalCredentialsBlob;
586 ptr = talloc(ctx, struct supplementalCredentialsBlob);
588 case DRSUAPI_ATTID_priorValue:
591 case DRSUAPI_ATTID_currentValue:
592 name = "currentValue";
594 case DRSUAPI_ATTID_trustAuthOutgoing:
595 name = "trustAuthOutgoing";
596 pull_fn = (ndr_pull_flags_fn_t)ndr_pull_trustAuthInOutBlob;
597 print_fn = (ndr_print_fn_t)ndr_print_trustAuthInOutBlob;
598 ptr = talloc(ctx, struct trustAuthInOutBlob);
600 case DRSUAPI_ATTID_trustAuthIncoming:
601 name = "trustAuthIncoming";
602 pull_fn = (ndr_pull_flags_fn_t)ndr_pull_trustAuthInOutBlob;
603 print_fn = (ndr_print_fn_t)ndr_print_trustAuthInOutBlob;
604 ptr = talloc(ctx, struct trustAuthInOutBlob);
606 case DRSUAPI_ATTID_initialAuthOutgoing:
607 name = "initialAuthOutgoing";
609 case DRSUAPI_ATTID_initialAuthIncoming:
610 name = "initialAuthIncoming";
616 if (attr->value_ctr.num_values != 1) continue;
618 if (!attr->value_ctr.values[0].blob) continue;
620 plain_data = *attr->value_ctr.values[0].blob;
624 DEBUG(0,("DN[%u] %s\n", object_id, dn));
627 DEBUGADD(0,("ATTR: %s plain.length=%lu\n",
628 name, (long)plain_data.length));
629 if (plain_data.length) {
630 enum ndr_err_code ndr_err;
631 dump_data(0, plain_data.data, plain_data.length);
632 if (save_values_dir) {
634 fname = talloc_asprintf(ctx, "%s/%s%02d",
639 ok = file_save(fname, plain_data.data, plain_data.length);
641 DEBUGADD(0,("Failed to save '%s'\n", fname));
648 /* Can't use '_all' because of PIDL bugs with relative pointers */
649 ndr_err = ndr_pull_struct_blob(&plain_data, ptr,
651 if (NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
652 ndr_print_debug(print_fn, name, ptr);
654 DEBUG(0, ("Failed to decode %s\n", name));
665 static bool test_GetNCChanges(struct torture_context *tctx,
666 struct DsSyncTest *ctx,
667 const char *nc_dn_str)
672 uint64_t highest_usn = 0;
673 struct drsuapi_DsGetNCChanges r;
674 union drsuapi_DsGetNCChangesRequest req;
675 struct drsuapi_DsReplicaObjectIdentifier nc;
676 struct drsuapi_DsGetNCChangesCtr1 *ctr1 = NULL;
677 struct drsuapi_DsGetNCChangesCtr6 *ctr6 = NULL;
678 uint32_t out_level = 0;
679 struct GUID null_guid;
680 struct dom_sid null_sid;
681 DATA_BLOB gensec_skey;
693 struct drsuapi_DsReplicaCursorCtrEx utdv;
694 struct drsuapi_DsReplicaCursor cursors[1];
698 utdv.count = ARRAY_SIZE(cursors);
699 utdv.cursors = cursors;
700 ZERO_STRUCT(cursors);
701 GUID_from_string("0d36ca05-5507-4e62-aca3-354bab0d39e1",
702 &cursors[0].source_dsa_invocation_id);
703 cursors[0].highest_usn = 12755;
705 uptodateness_vector : *
706 uptodateness_vector: struct drsuapi_DsReplicaCursorCtrEx
707 version : 0x00000001 (1)
708 reserved1 : 0x00000000 (0)
709 count : 0x00000001 (1)
710 reserved2 : 0x00000000 (0)
712 cursors: struct drsuapi_DsReplicaCursor
713 source_dsa_invocation_id : 0d36ca05-5507-4e62-aca3-354bab0d39e1
714 highest_usn : 0x00000000000031d3 (12755)
716 ZERO_STRUCT(null_guid);
717 ZERO_STRUCT(null_sid);
719 highest_usn = lpcfg_parm_int(tctx->lp_ctx, NULL, "dssync", "highest_usn", 0);
721 array[0].level = lpcfg_parm_int(tctx->lp_ctx, NULL, "dssync", "get_nc_changes_level", array[0].level);
723 if (lpcfg_parm_bool(tctx->lp_ctx, NULL, "dssync", "print_pwd_blobs", false)) {
724 const struct samr_Password *nthash;
725 nthash = cli_credentials_get_nt_hash(ctx->new_dc.credentials, ctx);
727 dump_data_pw("CREDENTIALS nthash:", nthash->hash, sizeof(nthash->hash));
730 status = gensec_session_key(ctx->new_dc.drsuapi.drs_pipe->conn->security_state.generic_state,
732 if (!NT_STATUS_IS_OK(status)) {
733 printf("failed to get gensec session key: %s\n", nt_errstr(status));
737 for (i=0; i < ARRAY_SIZE(array); i++) {
738 printf("Testing DsGetNCChanges level %d\n",
741 r.in.bind_handle = &ctx->new_dc.drsuapi.bind_handle;
742 r.in.level = array[i].level;
744 switch (r.in.level) {
751 r.in.req->req5.destination_dsa_guid = ctx->new_dc.invocation_id;
752 r.in.req->req5.source_dsa_invocation_id = null_guid;
753 r.in.req->req5.naming_context = &nc;
754 r.in.req->req5.highwatermark.tmp_highest_usn = highest_usn;
755 r.in.req->req5.highwatermark.reserved_usn = 0;
756 r.in.req->req5.highwatermark.highest_usn = highest_usn;
757 r.in.req->req5.uptodateness_vector = NULL;
758 r.in.req->req5.replica_flags = 0;
759 if (lpcfg_parm_bool(tctx->lp_ctx, NULL, "dssync", "compression", false)) {
760 r.in.req->req5.replica_flags |= DRSUAPI_DRS_USE_COMPRESSION;
762 if (lpcfg_parm_bool(tctx->lp_ctx, NULL, "dssync", "neighbour_writeable", true)) {
763 r.in.req->req5.replica_flags |= DRSUAPI_DRS_WRIT_REP;
765 r.in.req->req5.replica_flags |= DRSUAPI_DRS_INIT_SYNC
766 | DRSUAPI_DRS_PER_SYNC
767 | DRSUAPI_DRS_GET_ANC
768 | DRSUAPI_DRS_NEVER_SYNCED
770 r.in.req->req5.max_object_count = 133;
771 r.in.req->req5.max_ndr_size = 1336770;
772 r.in.req->req5.extended_op = DRSUAPI_EXOP_NONE;
773 r.in.req->req5.fsmo_info = 0;
780 /* nc.dn can be set to any other ad partition */
783 r.in.req->req8.destination_dsa_guid = ctx->new_dc.invocation_id;
784 r.in.req->req8.source_dsa_invocation_id = null_guid;
785 r.in.req->req8.naming_context = &nc;
786 r.in.req->req8.highwatermark.tmp_highest_usn = highest_usn;
787 r.in.req->req8.highwatermark.reserved_usn = 0;
788 r.in.req->req8.highwatermark.highest_usn = highest_usn;
789 r.in.req->req8.uptodateness_vector = NULL;//&utdv;
790 r.in.req->req8.replica_flags = 0;
791 if (lpcfg_parm_bool(tctx->lp_ctx, NULL, "dssync", "compression", false)) {
792 r.in.req->req8.replica_flags |= DRSUAPI_DRS_USE_COMPRESSION;
794 if (lpcfg_parm_bool(tctx->lp_ctx, NULL, "dssync", "neighbour_writeable", true)) {
795 r.in.req->req8.replica_flags |= DRSUAPI_DRS_WRIT_REP;
797 r.in.req->req8.replica_flags |= DRSUAPI_DRS_INIT_SYNC
798 | DRSUAPI_DRS_PER_SYNC
799 | DRSUAPI_DRS_GET_ANC
800 | DRSUAPI_DRS_NEVER_SYNCED
802 r.in.req->req8.replica_flags = 0x00201074;
803 //r.in.req->req8.replica_flags |= DRSUAPI_DRS_GET_ANC;
804 r.in.req->req8.max_object_count = 402;
805 r.in.req->req8.max_ndr_size = 402116;
807 r.in.req->req8.extended_op = DRSUAPI_EXOP_NONE;
808 r.in.req->req8.fsmo_info = 0;
809 r.in.req->req8.partial_attribute_set = NULL;
810 r.in.req->req8.partial_attribute_set_ex = NULL;
811 r.in.req->req8.mapping_ctr.num_mappings = 0;
812 r.in.req->req8.mapping_ctr.mappings = NULL;
819 union drsuapi_DsGetNCChangesCtr ctr;
823 r.out.level_out = &_level;
826 if (r.in.level == 5) {
827 torture_comment(tctx,
828 "start[%d] tmp_higest_usn: %llu , highest_usn: %llu\n",
830 (unsigned long long) r.in.req->req5.highwatermark.tmp_highest_usn,
831 (unsigned long long) r.in.req->req5.highwatermark.highest_usn);
834 if (r.in.level == 8) {
835 torture_comment(tctx,
836 "start[%d] tmp_higest_usn: %llu , highest_usn: %llu\n",
838 (unsigned long long) r.in.req->req8.highwatermark.tmp_highest_usn,
839 (unsigned long long) r.in.req->req8.highwatermark.highest_usn);
842 status = dcerpc_drsuapi_DsGetNCChanges_r(ctx->new_dc.drsuapi.drs_handle, ctx, &r);
843 torture_drsuapi_assert_call(tctx, ctx->new_dc.drsuapi.drs_pipe, status,
844 &r, "dcerpc_drsuapi_DsGetNCChanges");
846 if (ret == true && *r.out.level_out == 1) {
848 ctr1 = &r.out.ctr->ctr1;
849 } else if (ret == true && *r.out.level_out == 2 &&
850 r.out.ctr->ctr2.mszip1.ts) {
852 ctr1 = &r.out.ctr->ctr2.mszip1.ts->ctr1;
855 if (out_level == 1) {
856 torture_comment(tctx,
857 "end[%d] tmp_highest_usn: %llu , highest_usn: %llu\n",
859 (unsigned long long) ctr1->new_highwatermark.tmp_highest_usn,
860 (unsigned long long) ctr1->new_highwatermark.highest_usn);
862 if (!test_analyse_objects(tctx, ctx, nc_dn_str, &ctr1->mapping_ctr, ctr1->object_count,
863 ctr1->first_object, 0, NULL, &gensec_skey)) {
867 if (ctr1->more_data) {
868 r.in.req->req5.highwatermark = ctr1->new_highwatermark;
873 if (ret == true && *r.out.level_out == 6) {
875 ctr6 = &r.out.ctr->ctr6;
876 } else if (ret == true && *r.out.level_out == 7
877 && r.out.ctr->ctr7.level == 6
878 && r.out.ctr->ctr7.type == DRSUAPI_COMPRESSION_TYPE_MSZIP
879 && r.out.ctr->ctr7.ctr.mszip6.ts) {
881 ctr6 = &r.out.ctr->ctr7.ctr.mszip6.ts->ctr6;
882 } else if (ret == true && *r.out.level_out == 7
883 && r.out.ctr->ctr7.level == 6
884 && r.out.ctr->ctr7.type == DRSUAPI_COMPRESSION_TYPE_XPRESS
885 && r.out.ctr->ctr7.ctr.xpress6.ts) {
887 ctr6 = &r.out.ctr->ctr7.ctr.xpress6.ts->ctr6;
890 if (out_level == 6) {
891 torture_comment(tctx,
892 "end[%d] tmp_highest_usn: %llu , highest_usn: %llu\n",
894 (unsigned long long) ctr6->new_highwatermark.tmp_highest_usn,
895 (unsigned long long) ctr6->new_highwatermark.highest_usn);
897 if (!test_analyse_objects(tctx, ctx, nc_dn_str, &ctr6->mapping_ctr, ctr6->object_count,
899 ctr6->linked_attributes_count,
900 ctr6->linked_attributes,
905 if (ctr6->more_data) {
906 r.in.req->req8.highwatermark = ctr6->new_highwatermark;
919 * Test DsGetNCChanges() DRSUAPI call against one
920 * or more Naming Contexts.
921 * Specific NC to test with may be supplied
922 * in lp_ctx configuration. If no NC is specified,
923 * it will test DsGetNCChanges() on all NCs on remote DC
925 static bool test_FetchData(struct torture_context *tctx, struct DsSyncTest *ctx)
929 const char *nc_dn_str;
930 const char **nc_list;
932 nc_list = const_str_list(str_list_make_empty(ctx));
933 torture_assert(tctx, nc_list, "Not enough memory!");
935 /* make a list of partitions to test with */
936 nc_dn_str = lpcfg_parm_string(tctx->lp_ctx, NULL, "dssync", "partition");
937 if (nc_dn_str == NULL) {
938 nc_list = str_list_add_const(nc_list, ctx->domain_dn);
939 nc_list = str_list_add_const(nc_list, ctx->config_dn);
940 nc_list = str_list_add_const(nc_list, ctx->schema_dn);
942 nc_list = str_list_add_const(nc_list, nc_dn_str);
945 count = str_list_length(nc_list);
946 for (i = 0; i < count && ret; i++) {
947 torture_comment(tctx, "\nNaming Context: %s\n", nc_list[i]);
948 ret = test_GetNCChanges(tctx, ctx, nc_list[i]);
951 talloc_free(nc_list);
956 static bool test_FetchNT4Data(struct torture_context *tctx,
957 struct DsSyncTest *ctx)
960 struct drsuapi_DsGetNT4ChangeLog r;
961 union drsuapi_DsGetNT4ChangeLogRequest req;
962 union drsuapi_DsGetNT4ChangeLogInfo info;
963 uint32_t level_out = 0;
964 struct GUID null_guid;
965 struct dom_sid null_sid;
968 ZERO_STRUCT(null_guid);
969 ZERO_STRUCT(null_sid);
973 r.in.bind_handle = &ctx->new_dc.drsuapi.bind_handle;
976 r.out.level_out = &level_out;
978 req.req1.flags = lpcfg_parm_int(tctx->lp_ctx, NULL,
979 "dssync", "nt4changelog_flags",
980 DRSUAPI_NT4_CHANGELOG_GET_CHANGELOG |
981 DRSUAPI_NT4_CHANGELOG_GET_SERIAL_NUMBERS);
982 req.req1.preferred_maximum_length = lpcfg_parm_int(tctx->lp_ctx, NULL,
983 "dssync", "nt4changelog_preferred_len",
987 req.req1.restart_length = cookie.length;
988 req.req1.restart_data = cookie.data;
992 status = dcerpc_drsuapi_DsGetNT4ChangeLog_r(ctx->new_dc.drsuapi.drs_handle, ctx, &r);
993 if (NT_STATUS_EQUAL(status, NT_STATUS_NOT_IMPLEMENTED)) {
995 "DsGetNT4ChangeLog not supported: NT_STATUS_NOT_IMPLEMENTED");
996 } else if (!NT_STATUS_IS_OK(status)) {
997 const char *errstr = nt_errstr(status);
998 if (NT_STATUS_EQUAL(status, NT_STATUS_RPC_PROCNUM_OUT_OF_RANGE)) {
1000 "DsGetNT4ChangeLog not supported: NT_STATUS_RPC_PROCNUM_OUT_OF_RANGE");
1003 talloc_asprintf(tctx, "dcerpc_drsuapi_DsGetNT4ChangeLog failed - %s\n",
1005 } else if (W_ERROR_EQUAL(r.out.result, WERR_INVALID_DOMAIN_ROLE)) {
1007 "DsGetNT4ChangeLog not supported: WERR_INVALID_DOMAIN_ROLE");
1008 } else if (!W_ERROR_IS_OK(r.out.result)) {
1010 talloc_asprintf(tctx, "DsGetNT4ChangeLog failed - %s\n",
1011 win_errstr(r.out.result)));
1012 } else if (*r.out.level_out != 1) {
1014 talloc_asprintf(tctx, "DsGetNT4ChangeLog unknown level - %u\n",
1016 } else if (NT_STATUS_IS_OK(r.out.info->info1.status)) {
1017 } else if (NT_STATUS_EQUAL(r.out.info->info1.status, STATUS_MORE_ENTRIES)) {
1018 cookie.length = r.out.info->info1.restart_length;
1019 cookie.data = r.out.info->info1.restart_data;
1023 talloc_asprintf(tctx, "DsGetNT4ChangeLog failed - %s\n",
1024 nt_errstr(r.out.info->info1.status)));
1034 * DSSYNC test case setup
1036 static bool torture_dssync_tcase_setup(struct torture_context *tctx, void **data)
1039 struct DsSyncTest *ctx;
1041 *data = ctx = test_create_context(tctx);
1042 torture_assert(tctx, ctx, "test_create_context() failed");
1044 bret = _test_DsBind(tctx, ctx, ctx->admin.credentials, &ctx->admin.drsuapi);
1045 torture_assert(tctx, bret, "_test_DsBind() failed");
1047 bret = test_LDAPBind(tctx, ctx, ctx->admin.credentials, &ctx->admin.ldap);
1048 torture_assert(tctx, bret, "test_LDAPBind() failed");
1050 bret = test_GetInfo(tctx, ctx);
1051 torture_assert(tctx, bret, "test_GetInfo() failed");
1053 bret = _test_DsBind(tctx, ctx, ctx->new_dc.credentials, &ctx->new_dc.drsuapi);
1054 torture_assert(tctx, bret, "_test_DsBind() failed");
1060 * DSSYNC test case cleanup
1062 static bool torture_dssync_tcase_teardown(struct torture_context *tctx, void *data)
1064 struct DsSyncTest *ctx;
1065 struct drsuapi_DsUnbind r;
1066 struct policy_handle bind_handle;
1068 ctx = talloc_get_type(data, struct DsSyncTest);
1071 r.out.bind_handle = &bind_handle;
1073 /* Unbing admin handle */
1074 r.in.bind_handle = &ctx->admin.drsuapi.bind_handle;
1075 dcerpc_drsuapi_DsUnbind_r(ctx->admin.drsuapi.drs_handle, ctx, &r);
1077 /* Unbing new_dc handle */
1078 r.in.bind_handle = &ctx->new_dc.drsuapi.bind_handle;
1079 dcerpc_drsuapi_DsUnbind_r(ctx->new_dc.drsuapi.drs_handle, ctx, &r);
1087 * DSSYNC test case implementation
1089 void torture_drs_rpc_dssync_tcase(struct torture_suite *suite)
1091 typedef bool (*run_func) (struct torture_context *test, void *tcase_data);
1093 struct torture_test *test;
1094 struct torture_tcase *tcase = torture_suite_add_tcase(suite, "dssync");
1096 torture_tcase_set_fixture(tcase,
1097 torture_dssync_tcase_setup,
1098 torture_dssync_tcase_teardown);
1100 test = torture_tcase_add_simple_test(tcase, "DC_FetchData", (run_func)test_FetchData);
1101 test = torture_tcase_add_simple_test(tcase, "FetchNT4Data", (run_func)test_FetchNT4Data);