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"
37 #include "lib/util/util_paths.h"
39 struct DsSyncBindInfo {
40 struct dcerpc_pipe *drs_pipe;
41 struct dcerpc_binding_handle *drs_handle;
42 struct drsuapi_DsBind req;
43 struct GUID bind_guid;
44 struct drsuapi_DsBindInfoCtr our_bind_info_ctr;
45 struct drsuapi_DsBindInfo28 our_bind_info28;
46 struct drsuapi_DsBindInfo28 peer_bind_info28;
47 struct policy_handle bind_handle;
50 struct DsSyncLDAPInfo {
51 struct ldb_context *ldb;
55 struct dcerpc_binding *drsuapi_binding;
58 const char *dest_address;
59 const char *domain_dn;
60 const char *config_dn;
61 const char *schema_dn;
63 /* what we need to do as 'Administrator' */
65 struct cli_credentials *credentials;
66 struct DsSyncBindInfo drsuapi;
67 struct DsSyncLDAPInfo ldap;
70 /* what we need to do as the new dc machine account */
72 struct cli_credentials *credentials;
73 struct DsSyncBindInfo drsuapi;
74 struct drsuapi_DsGetDCInfo2 dc_info2;
75 struct GUID invocation_id;
76 struct GUID object_guid;
79 /* info about the old dc */
81 struct drsuapi_DsGetDomainControllerInfo dc_info;
85 static struct DsSyncTest *test_create_context(struct torture_context *tctx)
88 struct DsSyncTest *ctx;
89 struct drsuapi_DsBindInfo28 *our_bind_info28;
90 struct drsuapi_DsBindInfoCtr *our_bind_info_ctr;
91 const char *binding = torture_setting_string(tctx, "binding", NULL);
95 ctx = talloc_zero(tctx, struct DsSyncTest);
96 if (!ctx) return NULL;
98 status = dcerpc_parse_binding(ctx, binding, &ctx->drsuapi_binding);
99 if (!NT_STATUS_IS_OK(status)) {
100 printf("Bad binding string %s\n", binding);
103 status = dcerpc_binding_set_flags(ctx->drsuapi_binding,
104 DCERPC_SIGN | DCERPC_SEAL, 0);
105 if (!NT_STATUS_IS_OK(status)) {
106 printf("dcerpc_binding_set_flags - %s\n", nt_errstr(status));
110 host = dcerpc_binding_get_string_option(ctx->drsuapi_binding, "host");
112 ctx->ldap_url = talloc_asprintf(ctx, "ldap://%s", host);
114 make_nbt_name_server(&name, host);
116 /* do an initial name resolution to find its IP */
117 status = resolve_name_ex(lpcfg_resolve_context(tctx->lp_ctx),
119 &ctx->dest_address, tctx->ev);
120 if (!NT_STATUS_IS_OK(status)) {
121 printf("Failed to resolve %s - %s\n",
122 name.name, nt_errstr(status));
127 ctx->admin.credentials = popt_get_cmdline_credentials();
129 our_bind_info28 = &ctx->admin.drsuapi.our_bind_info28;
130 our_bind_info28->supported_extensions = 0xFFFFFFFF;
131 our_bind_info28->supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_ADDENTRYREPLY_V3;
132 our_bind_info28->site_guid = GUID_zero();
133 our_bind_info28->pid = 0;
134 our_bind_info28->repl_epoch = 1;
136 our_bind_info_ctr = &ctx->admin.drsuapi.our_bind_info_ctr;
137 our_bind_info_ctr->length = 28;
138 our_bind_info_ctr->info.info28 = *our_bind_info28;
140 GUID_from_string(DRSUAPI_DS_BIND_GUID, &ctx->admin.drsuapi.bind_guid);
142 ctx->admin.drsuapi.req.in.bind_guid = &ctx->admin.drsuapi.bind_guid;
143 ctx->admin.drsuapi.req.in.bind_info = our_bind_info_ctr;
144 ctx->admin.drsuapi.req.out.bind_handle = &ctx->admin.drsuapi.bind_handle;
147 ctx->new_dc.credentials = popt_get_cmdline_credentials();
149 our_bind_info28 = &ctx->new_dc.drsuapi.our_bind_info28;
150 our_bind_info28->supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_BASE;
151 our_bind_info28->supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_ASYNC_REPLICATION;
152 our_bind_info28->supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_REMOVEAPI;
153 our_bind_info28->supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_MOVEREQ_V2;
154 our_bind_info28->supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_GETCHG_COMPRESS;
155 our_bind_info28->supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_DCINFO_V1;
156 our_bind_info28->supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_RESTORE_USN_OPTIMIZATION;
157 our_bind_info28->supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_KCC_EXECUTE;
158 our_bind_info28->supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_ADDENTRY_V2;
159 our_bind_info28->supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_LINKED_VALUE_REPLICATION;
160 our_bind_info28->supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_DCINFO_V2;
161 our_bind_info28->supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_INSTANCE_TYPE_NOT_REQ_ON_MOD;
162 our_bind_info28->supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_CRYPTO_BIND;
163 our_bind_info28->supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_GET_REPL_INFO;
164 our_bind_info28->supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_STRONG_ENCRYPTION;
165 our_bind_info28->supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_DCINFO_V01;
166 our_bind_info28->supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_TRANSITIVE_MEMBERSHIP;
167 our_bind_info28->supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_ADD_SID_HISTORY;
168 our_bind_info28->supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_POST_BETA3;
169 our_bind_info28->supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_GET_MEMBERSHIPS2;
170 our_bind_info28->supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_GETCHGREQ_V6;
171 our_bind_info28->supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_NONDOMAIN_NCS;
172 our_bind_info28->supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_GETCHGREQ_V8;
173 our_bind_info28->supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_GETCHGREPLY_V5;
174 our_bind_info28->supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_GETCHGREPLY_V6;
175 our_bind_info28->supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_ADDENTRYREPLY_V3;
176 our_bind_info28->supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_GETCHGREPLY_V7;
177 our_bind_info28->supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_VERIFY_OBJECT;
178 if (lpcfg_parm_bool(tctx->lp_ctx, NULL, "dssync", "xpress", false)) {
179 our_bind_info28->supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_XPRESS_COMPRESS;
181 our_bind_info28->site_guid = GUID_zero();
182 our_bind_info28->pid = 0;
183 our_bind_info28->repl_epoch = 0;
185 our_bind_info_ctr = &ctx->new_dc.drsuapi.our_bind_info_ctr;
186 our_bind_info_ctr->length = 28;
187 our_bind_info_ctr->info.info28 = *our_bind_info28;
189 GUID_from_string(DRSUAPI_DS_BIND_GUID_W2K3, &ctx->new_dc.drsuapi.bind_guid);
191 ctx->new_dc.drsuapi.req.in.bind_guid = &ctx->new_dc.drsuapi.bind_guid;
192 ctx->new_dc.drsuapi.req.in.bind_info = our_bind_info_ctr;
193 ctx->new_dc.drsuapi.req.out.bind_handle = &ctx->new_dc.drsuapi.bind_handle;
195 ctx->new_dc.invocation_id = ctx->new_dc.drsuapi.bind_guid;
202 static bool _test_DsBind(struct torture_context *tctx,
203 struct DsSyncTest *ctx, struct cli_credentials *credentials, struct DsSyncBindInfo *b)
208 status = dcerpc_pipe_connect_b(ctx,
209 &b->drs_pipe, ctx->drsuapi_binding,
211 credentials, tctx->ev, tctx->lp_ctx);
213 if (!NT_STATUS_IS_OK(status)) {
214 printf("Failed to connect to server as a BDC: %s\n", nt_errstr(status));
217 b->drs_handle = b->drs_pipe->binding_handle;
219 status = dcerpc_drsuapi_DsBind_r(b->drs_handle, ctx, &b->req);
220 if (!NT_STATUS_IS_OK(status)) {
221 const char *errstr = nt_errstr(status);
222 printf("dcerpc_drsuapi_DsBind failed - %s\n", errstr);
224 } else if (!W_ERROR_IS_OK(b->req.out.result)) {
225 printf("DsBind failed - %s\n", win_errstr(b->req.out.result));
229 ZERO_STRUCT(b->peer_bind_info28);
230 if (b->req.out.bind_info) {
231 switch (b->req.out.bind_info->length) {
233 struct drsuapi_DsBindInfo24 *info24;
234 info24 = &b->req.out.bind_info->info.info24;
235 b->peer_bind_info28.supported_extensions= info24->supported_extensions;
236 b->peer_bind_info28.site_guid = info24->site_guid;
237 b->peer_bind_info28.pid = info24->pid;
238 b->peer_bind_info28.repl_epoch = 0;
242 b->peer_bind_info28 = b->req.out.bind_info->info.info28;
246 struct drsuapi_DsBindInfo32 *info32;
247 info32 = &b->req.out.bind_info->info.info32;
248 b->peer_bind_info28.supported_extensions= info32->supported_extensions;
249 b->peer_bind_info28.site_guid = info32->site_guid;
250 b->peer_bind_info28.pid = info32->pid;
251 b->peer_bind_info28.repl_epoch = info32->repl_epoch;
255 struct drsuapi_DsBindInfo48 *info48;
256 info48 = &b->req.out.bind_info->info.info48;
257 b->peer_bind_info28.supported_extensions= info48->supported_extensions;
258 b->peer_bind_info28.site_guid = info48->site_guid;
259 b->peer_bind_info28.pid = info48->pid;
260 b->peer_bind_info28.repl_epoch = info48->repl_epoch;
264 struct drsuapi_DsBindInfo52 *info52;
265 info52 = &b->req.out.bind_info->info.info52;
266 b->peer_bind_info28.supported_extensions= info52->supported_extensions;
267 b->peer_bind_info28.site_guid = info52->site_guid;
268 b->peer_bind_info28.pid = info52->pid;
269 b->peer_bind_info28.repl_epoch = info52->repl_epoch;
273 printf("DsBind - warning: unknown BindInfo length: %u\n",
274 b->req.out.bind_info->length);
281 static bool test_LDAPBind(struct torture_context *tctx, struct DsSyncTest *ctx,
282 struct cli_credentials *credentials, struct DsSyncLDAPInfo *l)
286 struct ldb_context *ldb;
288 const char *modules_option[] = { "modules:paged_searches", NULL };
289 ctx->admin.ldap.ldb = ldb = ldb_init(ctx, tctx->ev);
294 /* Despite us loading the schema from the AD server, we need
295 * the samba handlers to get the extended DN syntax stuff */
296 ret = ldb_register_samba_handlers(ldb);
297 if (ret != LDB_SUCCESS) {
302 ldb_set_modules_dir(ldb, modules_path(ldb, "ldb"));
304 if (ldb_set_opaque(ldb, "credentials", credentials)) {
309 if (ldb_set_opaque(ldb, "loadparm", tctx->lp_ctx)) {
314 ret = ldb_connect(ldb, ctx->ldap_url, 0, modules_option);
315 if (ret != LDB_SUCCESS) {
317 torture_assert_int_equal(tctx, ret, LDB_SUCCESS, "Failed to make LDB connection to target");
320 printf("connected to LDAP: %s\n", ctx->ldap_url);
325 static bool test_GetInfo(struct torture_context *tctx, struct DsSyncTest *ctx)
327 struct ldb_context *ldb = ctx->admin.ldap.ldb;
329 /* We must have LDB connection ready by this time */
330 SMB_ASSERT(ldb != NULL);
332 ctx->domain_dn = ldb_dn_get_linearized(ldb_get_default_basedn(ldb));
333 torture_assert(tctx, ctx->domain_dn != NULL, "Failed to get Domain DN");
335 ctx->config_dn = ldb_dn_get_linearized(ldb_get_config_basedn(ldb));
336 torture_assert(tctx, ctx->config_dn != NULL, "Failed to get Domain DN");
338 ctx->schema_dn = ldb_dn_get_linearized(ldb_get_schema_basedn(ldb));
339 torture_assert(tctx, ctx->schema_dn != NULL, "Failed to get Domain DN");
344 static bool test_analyse_objects(struct torture_context *tctx,
345 struct DsSyncTest *ctx,
346 const char *partition,
347 const struct drsuapi_DsReplicaOIDMapping_Ctr *mapping_ctr,
348 uint32_t object_count,
349 const struct drsuapi_DsReplicaObjectListItemEx *first_object,
350 const DATA_BLOB *gensec_skey)
352 static uint32_t object_id;
353 const char *save_values_dir;
354 const struct drsuapi_DsReplicaObjectListItemEx *cur;
355 struct ldb_context *ldb = ctx->admin.ldap.ldb;
356 struct ldb_dn *deleted_dn;
359 struct dsdb_extended_replicated_objects *objs;
360 struct ldb_extended_dn_control *extended_dn_ctrl;
361 struct dsdb_schema *ldap_schema;
362 struct ldb_dn *partition_dn = ldb_dn_new(tctx, ldb, partition);
364 torture_assert_not_null(tctx, partition_dn, "Failed to parse partition DN as as DN");
366 /* load dsdb_schema using remote prefixMap */
368 drs_util_dsdb_schema_load_ldb(tctx, ldb, mapping_ctr, false),
369 "drs_util_dsdb_schema_load_ldb() failed");
370 ldap_schema = dsdb_get_schema(ldb, NULL);
372 status = dsdb_replicated_objects_convert(ldb,
383 torture_assert_werr_ok(tctx, status, "dsdb_extended_replicated_objects_convert() failed!");
385 extended_dn_ctrl = talloc(objs, struct ldb_extended_dn_control);
386 extended_dn_ctrl->type = 1;
388 deleted_dn = ldb_dn_new(objs, ldb, partition);
389 ldb_dn_add_child_fmt(deleted_dn, "CN=Deleted Objects");
391 for (i=0; i < objs->num_objects; i++) {
392 struct ldb_request *search_req;
393 struct ldb_result *res;
394 struct ldb_message *new_msg, *drs_msg, *ldap_msg;
395 size_t num_attrs = objs->objects[i].msg->num_elements+1;
396 const char **attrs = talloc_array(objs, const char *, num_attrs);
397 for (j=0; j < objs->objects[i].msg->num_elements; j++) {
398 attrs[j] = objs->objects[i].msg->elements[j].name;
401 res = talloc_zero(objs, struct ldb_result);
403 return LDB_ERR_OPERATIONS_ERROR;
405 ret = ldb_build_search_req(&search_req, ldb, objs,
406 objs->objects[i].msg->dn,
412 ldb_search_default_callback,
414 if (ret != LDB_SUCCESS) {
417 talloc_steal(search_req, res);
418 ret = ldb_request_add_control(search_req, LDB_CONTROL_SHOW_DELETED_OID, true, NULL);
419 if (ret != LDB_SUCCESS) {
423 ret = ldb_request_add_control(search_req, LDB_CONTROL_EXTENDED_DN_OID, true, extended_dn_ctrl);
424 if (ret != LDB_SUCCESS) {
428 ret = ldb_request(ldb, search_req);
429 if (ret == LDB_SUCCESS) {
430 ret = ldb_wait(search_req->handle, LDB_WAIT_ALL);
433 torture_assert_int_equal(tctx, ret, LDB_SUCCESS,
434 talloc_asprintf(tctx,
435 "Could not re-fetch object just delivered over DRS: %s",
436 ldb_errstring(ldb)));
437 torture_assert_int_equal(tctx, res->count, 1, "Could not re-fetch object just delivered over DRS");
438 ldap_msg = res->msgs[0];
439 for (j=0; j < ldap_msg->num_elements; j++) {
440 ldap_msg->elements[j].flags = LDB_FLAG_MOD_ADD;
441 /* 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 */
442 if ((ldb_attr_cmp(ldap_msg->elements[j].name, "nTSecurityDescriptor") == 0) &&
443 (ldb_dn_compare(ldap_msg->dn, deleted_dn) == 0)) {
444 ldb_msg_remove_element(ldap_msg, &ldap_msg->elements[j]);
450 ret = ldb_msg_normalize(ldb, search_req,
451 objs->objects[i].msg, &drs_msg);
452 torture_assert(tctx, ret == LDB_SUCCESS,
453 "ldb_msg_normalize() has failed");
455 for (j=0; j < drs_msg->num_elements; j++) {
456 if (drs_msg->elements[j].num_values == 0) {
457 ldb_msg_remove_element(drs_msg, &drs_msg->elements[j]);
461 /* For unknown reasons, there is no nTSecurityDescriptor on cn=deleted objects over LDAP, but there is over DRS! */
462 } else if ((ldb_attr_cmp(drs_msg->elements[j].name, "nTSecurityDescriptor") == 0) &&
463 (ldb_dn_compare(drs_msg->dn, deleted_dn) == 0)) {
464 ldb_msg_remove_element(drs_msg, &drs_msg->elements[j]);
467 } else if (ldb_attr_cmp(drs_msg->elements[j].name, "unicodePwd") == 0 ||
468 ldb_attr_cmp(drs_msg->elements[j].name, "dBCSPwd") == 0 ||
469 ldb_attr_cmp(drs_msg->elements[j].name, "userPassword") == 0 ||
470 ldb_attr_cmp(drs_msg->elements[j].name, "ntPwdHistory") == 0 ||
471 ldb_attr_cmp(drs_msg->elements[j].name, "lmPwdHistory") == 0 ||
472 ldb_attr_cmp(drs_msg->elements[j].name, "supplementalCredentials") == 0 ||
473 ldb_attr_cmp(drs_msg->elements[j].name, "priorValue") == 0 ||
474 ldb_attr_cmp(drs_msg->elements[j].name, "currentValue") == 0 ||
475 ldb_attr_cmp(drs_msg->elements[j].name, "trustAuthOutgoing") == 0 ||
476 ldb_attr_cmp(drs_msg->elements[j].name, "trustAuthIncoming") == 0 ||
477 ldb_attr_cmp(drs_msg->elements[j].name, "initialAuthOutgoing") == 0 ||
478 ldb_attr_cmp(drs_msg->elements[j].name, "initialAuthIncoming") == 0) {
480 /* These are not shown over LDAP, so we need to skip them for the comparison */
481 ldb_msg_remove_element(drs_msg, &drs_msg->elements[j]);
485 drs_msg->elements[j].flags = LDB_FLAG_MOD_ADD;
490 ret = ldb_msg_difference(ldb, search_req,
491 drs_msg, ldap_msg, &new_msg);
492 torture_assert(tctx, ret == LDB_SUCCESS, "ldb_msg_difference() has failed");
493 if (new_msg->num_elements != 0) {
495 bool is_warning = true;
497 struct ldb_message_element *el;
498 const struct dsdb_attribute * a;
499 struct ldb_ldif ldif;
500 ldif.changetype = LDB_CHANGETYPE_MODIFY;
502 s = ldb_ldif_write_string(ldb, new_msg, &ldif);
503 s = talloc_asprintf(tctx, "\n# Difference in between DRS and LDAP objects: \n%s", s);
505 ret = ldb_msg_difference(ldb, search_req,
506 ldap_msg, drs_msg, &ldif.msg);
507 torture_assert(tctx, ret == LDB_SUCCESS, "ldb_msg_difference() has failed");
508 s = talloc_asprintf_append(s,
509 "\n# Difference in between LDAP and DRS objects: \n%s",
510 ldb_ldif_write_string(ldb, new_msg, &ldif));
512 s = talloc_asprintf_append(s,
513 "# Should have no objects in 'difference' message. Diff elements: %d",
514 new_msg->num_elements);
517 * In case differences in messages are:
518 * 1. Attributes with different values, i.e. 'replace'
519 * 2. Those attributes are forward-link attributes
520 * then we just warn about those differences.
521 * It turns out windows doesn't send all of those values
522 * in replicated_object but in linked_attributes.
524 for (idx = 0; idx < new_msg->num_elements && is_warning; idx++) {
525 el = &new_msg->elements[idx];
526 a = dsdb_attribute_by_lDAPDisplayName(ldap_schema,
528 if (!(el->flags & (LDB_FLAG_MOD_ADD|LDB_FLAG_MOD_REPLACE))) {
531 } else if (a->linkID & 1) {
536 torture_warning(tctx, "%s", s);
538 torture_fail(tctx, s);
542 /* search_req is used as a tmp talloc context in the above */
543 talloc_free(search_req);
546 if (!lpcfg_parm_bool(tctx->lp_ctx, NULL, "dssync", "print_pwd_blobs", false)) {
551 save_values_dir = lpcfg_parm_string(tctx->lp_ctx, NULL, "dssync", "save_pwd_blobs_dir");
553 for (cur = first_object; cur; cur = cur->next_object) {
555 bool dn_printed = false;
557 if (!cur->object.identifier) continue;
559 dn = cur->object.identifier->dn;
561 for (i=0; i < cur->object.attribute_ctr.num_attributes; i++) {
562 const char *name = NULL;
563 DATA_BLOB plain_data;
564 struct drsuapi_DsReplicaAttribute *attr;
565 ndr_pull_flags_fn_t pull_fn = NULL;
566 ndr_print_fn_t print_fn = NULL;
568 attr = &cur->object.attribute_ctr.attributes[i];
570 switch (attr->attid) {
571 case DRSUAPI_ATTID_dBCSPwd:
574 case DRSUAPI_ATTID_unicodePwd:
577 case DRSUAPI_ATTID_ntPwdHistory:
578 name = "ntPwdHistory";
580 case DRSUAPI_ATTID_lmPwdHistory:
581 name = "lmPwdHistory";
583 case DRSUAPI_ATTID_supplementalCredentials:
584 name = "supplementalCredentials";
585 pull_fn = (ndr_pull_flags_fn_t)ndr_pull_supplementalCredentialsBlob;
586 print_fn = (ndr_print_fn_t)ndr_print_supplementalCredentialsBlob;
587 ptr = talloc(ctx, struct supplementalCredentialsBlob);
589 case DRSUAPI_ATTID_priorValue:
592 case DRSUAPI_ATTID_currentValue:
593 name = "currentValue";
595 case DRSUAPI_ATTID_trustAuthOutgoing:
596 name = "trustAuthOutgoing";
597 pull_fn = (ndr_pull_flags_fn_t)ndr_pull_trustAuthInOutBlob;
598 print_fn = (ndr_print_fn_t)ndr_print_trustAuthInOutBlob;
599 ptr = talloc(ctx, struct trustAuthInOutBlob);
601 case DRSUAPI_ATTID_trustAuthIncoming:
602 name = "trustAuthIncoming";
603 pull_fn = (ndr_pull_flags_fn_t)ndr_pull_trustAuthInOutBlob;
604 print_fn = (ndr_print_fn_t)ndr_print_trustAuthInOutBlob;
605 ptr = talloc(ctx, struct trustAuthInOutBlob);
607 case DRSUAPI_ATTID_initialAuthOutgoing:
608 name = "initialAuthOutgoing";
610 case DRSUAPI_ATTID_initialAuthIncoming:
611 name = "initialAuthIncoming";
617 if (attr->value_ctr.num_values != 1) continue;
619 if (!attr->value_ctr.values[0].blob) continue;
621 plain_data = *attr->value_ctr.values[0].blob;
625 DEBUG(0,("DN[%u] %s\n", object_id, dn));
628 DEBUGADD(0,("ATTR: %s plain.length=%lu\n",
629 name, (long)plain_data.length));
630 if (plain_data.length) {
631 enum ndr_err_code ndr_err;
632 dump_data(0, plain_data.data, plain_data.length);
633 if (save_values_dir) {
635 fname = talloc_asprintf(ctx, "%s/%s%02d",
640 ok = file_save(fname, plain_data.data, plain_data.length);
642 DEBUGADD(0,("Failed to save '%s'\n", fname));
649 /* Can't use '_all' because of PIDL bugs with relative pointers */
650 ndr_err = ndr_pull_struct_blob(&plain_data, ptr,
652 if (NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
653 ndr_print_debug(print_fn, name, ptr);
655 DEBUG(0, ("Failed to decode %s\n", name));
666 static bool test_GetNCChanges(struct torture_context *tctx,
667 struct DsSyncTest *ctx,
668 const char *nc_dn_str)
673 uint64_t highest_usn = 0;
674 struct drsuapi_DsGetNCChanges r;
675 union drsuapi_DsGetNCChangesRequest req;
676 struct drsuapi_DsReplicaObjectIdentifier nc;
677 struct drsuapi_DsGetNCChangesCtr1 *ctr1 = NULL;
678 struct drsuapi_DsGetNCChangesCtr6 *ctr6 = NULL;
679 uint32_t out_level = 0;
680 struct GUID null_guid;
681 struct dom_sid null_sid;
682 DATA_BLOB gensec_skey;
694 ZERO_STRUCT(null_guid);
695 ZERO_STRUCT(null_sid);
697 highest_usn = lpcfg_parm_int(tctx->lp_ctx, NULL, "dssync", "highest_usn", 0);
699 array[0].level = lpcfg_parm_int(tctx->lp_ctx, NULL, "dssync", "get_nc_changes_level", array[0].level);
701 if (lpcfg_parm_bool(tctx->lp_ctx, NULL, "dssync", "print_pwd_blobs", false)) {
702 const struct samr_Password *nthash;
703 nthash = cli_credentials_get_nt_hash(ctx->new_dc.credentials, ctx);
705 dump_data_pw("CREDENTIALS nthash:", nthash->hash, sizeof(nthash->hash));
708 status = gensec_session_key(ctx->new_dc.drsuapi.drs_pipe->conn->security_state.generic_state,
710 if (!NT_STATUS_IS_OK(status)) {
711 printf("failed to get gensec session key: %s\n", nt_errstr(status));
715 for (i=0; i < ARRAY_SIZE(array); i++) {
716 printf("Testing DsGetNCChanges level %d\n",
719 r.in.bind_handle = &ctx->new_dc.drsuapi.bind_handle;
720 r.in.level = array[i].level;
722 switch (r.in.level) {
729 r.in.req->req5.destination_dsa_guid = ctx->new_dc.invocation_id;
730 r.in.req->req5.source_dsa_invocation_id = null_guid;
731 r.in.req->req5.naming_context = &nc;
732 r.in.req->req5.highwatermark.tmp_highest_usn = highest_usn;
733 r.in.req->req5.highwatermark.reserved_usn = 0;
734 r.in.req->req5.highwatermark.highest_usn = highest_usn;
735 r.in.req->req5.uptodateness_vector = NULL;
736 r.in.req->req5.replica_flags = 0;
737 if (lpcfg_parm_bool(tctx->lp_ctx, NULL, "dssync", "compression", false)) {
738 r.in.req->req5.replica_flags |= DRSUAPI_DRS_USE_COMPRESSION;
740 if (lpcfg_parm_bool(tctx->lp_ctx, NULL, "dssync", "neighbour_writeable", true)) {
741 r.in.req->req5.replica_flags |= DRSUAPI_DRS_WRIT_REP;
743 r.in.req->req5.replica_flags |= DRSUAPI_DRS_INIT_SYNC
744 | DRSUAPI_DRS_PER_SYNC
745 | DRSUAPI_DRS_GET_ANC
746 | DRSUAPI_DRS_NEVER_SYNCED
748 r.in.req->req5.max_object_count = 133;
749 r.in.req->req5.max_ndr_size = 1336770;
750 r.in.req->req5.extended_op = DRSUAPI_EXOP_NONE;
751 r.in.req->req5.fsmo_info = 0;
758 /* nc.dn can be set to any other ad partition */
761 r.in.req->req8.destination_dsa_guid = ctx->new_dc.invocation_id;
762 r.in.req->req8.source_dsa_invocation_id = null_guid;
763 r.in.req->req8.naming_context = &nc;
764 r.in.req->req8.highwatermark.tmp_highest_usn = highest_usn;
765 r.in.req->req8.highwatermark.reserved_usn = 0;
766 r.in.req->req8.highwatermark.highest_usn = highest_usn;
767 r.in.req->req8.uptodateness_vector = NULL;
768 r.in.req->req8.replica_flags = 0;
769 if (lpcfg_parm_bool(tctx->lp_ctx, NULL, "dssync", "compression", false)) {
770 r.in.req->req8.replica_flags |= DRSUAPI_DRS_USE_COMPRESSION;
772 if (lpcfg_parm_bool(tctx->lp_ctx, NULL, "dssync", "neighbour_writeable", true)) {
773 r.in.req->req8.replica_flags |= DRSUAPI_DRS_WRIT_REP;
775 r.in.req->req8.replica_flags |= DRSUAPI_DRS_INIT_SYNC
776 | DRSUAPI_DRS_PER_SYNC
777 | DRSUAPI_DRS_GET_ANC
778 | DRSUAPI_DRS_NEVER_SYNCED
780 r.in.req->req8.max_object_count = 402;
781 r.in.req->req8.max_ndr_size = 402116;
783 r.in.req->req8.extended_op = DRSUAPI_EXOP_NONE;
784 r.in.req->req8.fsmo_info = 0;
785 r.in.req->req8.partial_attribute_set = NULL;
786 r.in.req->req8.partial_attribute_set_ex = NULL;
787 r.in.req->req8.mapping_ctr.num_mappings = 0;
788 r.in.req->req8.mapping_ctr.mappings = NULL;
795 union drsuapi_DsGetNCChangesCtr ctr;
799 r.out.level_out = &_level;
802 if (r.in.level == 5) {
803 torture_comment(tctx,
804 "start[%d] tmp_higest_usn: %llu , highest_usn: %llu\n",
806 (unsigned long long) r.in.req->req5.highwatermark.tmp_highest_usn,
807 (unsigned long long) r.in.req->req5.highwatermark.highest_usn);
810 if (r.in.level == 8) {
811 torture_comment(tctx,
812 "start[%d] tmp_higest_usn: %llu , highest_usn: %llu\n",
814 (unsigned long long) r.in.req->req8.highwatermark.tmp_highest_usn,
815 (unsigned long long) r.in.req->req8.highwatermark.highest_usn);
818 status = dcerpc_drsuapi_DsGetNCChanges_r(ctx->new_dc.drsuapi.drs_handle, ctx, &r);
819 torture_drsuapi_assert_call(tctx, ctx->new_dc.drsuapi.drs_pipe, status,
820 &r, "dcerpc_drsuapi_DsGetNCChanges");
822 if (ret == true && *r.out.level_out == 1) {
824 ctr1 = &r.out.ctr->ctr1;
825 } else if (ret == true && *r.out.level_out == 2 &&
826 r.out.ctr->ctr2.mszip1.ts) {
828 ctr1 = &r.out.ctr->ctr2.mszip1.ts->ctr1;
831 if (out_level == 1) {
832 torture_comment(tctx,
833 "end[%d] tmp_highest_usn: %llu , highest_usn: %llu\n",
835 (unsigned long long) ctr1->new_highwatermark.tmp_highest_usn,
836 (unsigned long long) ctr1->new_highwatermark.highest_usn);
838 if (!test_analyse_objects(tctx, ctx, nc_dn_str, &ctr1->mapping_ctr, ctr1->object_count,
839 ctr1->first_object, &gensec_skey)) {
843 if (ctr1->more_data) {
844 r.in.req->req5.highwatermark = ctr1->new_highwatermark;
849 if (ret == true && *r.out.level_out == 6) {
851 ctr6 = &r.out.ctr->ctr6;
852 } else if (ret == true && *r.out.level_out == 7
853 && r.out.ctr->ctr7.level == 6
854 && r.out.ctr->ctr7.type == DRSUAPI_COMPRESSION_TYPE_MSZIP
855 && r.out.ctr->ctr7.ctr.mszip6.ts) {
857 ctr6 = &r.out.ctr->ctr7.ctr.mszip6.ts->ctr6;
858 } else if (ret == true && *r.out.level_out == 7
859 && r.out.ctr->ctr7.level == 6
860 && r.out.ctr->ctr7.type == DRSUAPI_COMPRESSION_TYPE_XPRESS
861 && r.out.ctr->ctr7.ctr.xpress6.ts) {
863 ctr6 = &r.out.ctr->ctr7.ctr.xpress6.ts->ctr6;
866 if (out_level == 6) {
867 torture_comment(tctx,
868 "end[%d] tmp_highest_usn: %llu , highest_usn: %llu\n",
870 (unsigned long long) ctr6->new_highwatermark.tmp_highest_usn,
871 (unsigned long long) ctr6->new_highwatermark.highest_usn);
873 if (!test_analyse_objects(tctx, ctx, nc_dn_str, &ctr6->mapping_ctr, ctr6->object_count,
874 ctr6->first_object, &gensec_skey)) {
878 if (ctr6->more_data) {
879 r.in.req->req8.highwatermark = ctr6->new_highwatermark;
892 * Test DsGetNCChanges() DRSUAPI call against one
893 * or more Naming Contexts.
894 * Specific NC to test with may be supplied
895 * in lp_ctx configuration. If no NC is specified,
896 * it will test DsGetNCChanges() on all NCs on remote DC
898 static bool test_FetchData(struct torture_context *tctx, struct DsSyncTest *ctx)
902 const char *nc_dn_str;
903 const char **nc_list;
905 nc_list = const_str_list(str_list_make_empty(ctx));
906 torture_assert(tctx, nc_list, "Not enough memory!");
908 /* make a list of partitions to test with */
909 nc_dn_str = lpcfg_parm_string(tctx->lp_ctx, NULL, "dssync", "partition");
910 if (nc_dn_str == NULL) {
911 nc_list = str_list_add_const(nc_list, ctx->domain_dn);
912 nc_list = str_list_add_const(nc_list, ctx->config_dn);
913 nc_list = str_list_add_const(nc_list, ctx->schema_dn);
915 nc_list = str_list_add_const(nc_list, nc_dn_str);
918 count = str_list_length(nc_list);
919 for (i = 0; i < count && ret; i++) {
920 torture_comment(tctx, "\nNaming Context: %s\n", nc_list[i]);
921 ret = test_GetNCChanges(tctx, ctx, nc_list[i]);
924 talloc_free(nc_list);
929 static bool test_FetchNT4Data(struct torture_context *tctx,
930 struct DsSyncTest *ctx)
933 struct drsuapi_DsGetNT4ChangeLog r;
934 union drsuapi_DsGetNT4ChangeLogRequest req;
935 union drsuapi_DsGetNT4ChangeLogInfo info;
936 uint32_t level_out = 0;
937 struct GUID null_guid;
940 ZERO_STRUCT(null_guid);
944 r.in.bind_handle = &ctx->new_dc.drsuapi.bind_handle;
947 r.out.level_out = &level_out;
949 req.req1.flags = lpcfg_parm_int(tctx->lp_ctx, NULL,
950 "dssync", "nt4changelog_flags",
951 DRSUAPI_NT4_CHANGELOG_GET_CHANGELOG |
952 DRSUAPI_NT4_CHANGELOG_GET_SERIAL_NUMBERS);
953 req.req1.preferred_maximum_length = lpcfg_parm_int(tctx->lp_ctx, NULL,
954 "dssync", "nt4changelog_preferred_len",
958 req.req1.restart_length = cookie.length;
959 req.req1.restart_data = cookie.data;
963 status = dcerpc_drsuapi_DsGetNT4ChangeLog_r(ctx->new_dc.drsuapi.drs_handle, ctx, &r);
964 if (NT_STATUS_EQUAL(status, NT_STATUS_NOT_IMPLEMENTED)) {
966 "DsGetNT4ChangeLog not supported: NT_STATUS_NOT_IMPLEMENTED");
967 } else if (!NT_STATUS_IS_OK(status)) {
968 const char *errstr = nt_errstr(status);
969 if (NT_STATUS_EQUAL(status, NT_STATUS_RPC_PROCNUM_OUT_OF_RANGE)) {
971 "DsGetNT4ChangeLog not supported: NT_STATUS_RPC_PROCNUM_OUT_OF_RANGE");
974 talloc_asprintf(tctx, "dcerpc_drsuapi_DsGetNT4ChangeLog failed - %s\n",
976 } else if (W_ERROR_EQUAL(r.out.result, WERR_INVALID_DOMAIN_ROLE)) {
978 "DsGetNT4ChangeLog not supported: WERR_INVALID_DOMAIN_ROLE");
979 } else if (!W_ERROR_IS_OK(r.out.result)) {
981 talloc_asprintf(tctx, "DsGetNT4ChangeLog failed - %s\n",
982 win_errstr(r.out.result)));
983 } else if (*r.out.level_out != 1) {
985 talloc_asprintf(tctx, "DsGetNT4ChangeLog unknown level - %u\n",
987 } else if (NT_STATUS_IS_OK(r.out.info->info1.status)) {
988 } else if (NT_STATUS_EQUAL(r.out.info->info1.status, STATUS_MORE_ENTRIES)) {
989 cookie.length = r.out.info->info1.restart_length;
990 cookie.data = r.out.info->info1.restart_data;
994 talloc_asprintf(tctx, "DsGetNT4ChangeLog failed - %s\n",
995 nt_errstr(r.out.info->info1.status)));
1005 * DSSYNC test case setup
1007 static bool torture_dssync_tcase_setup(struct torture_context *tctx, void **data)
1010 struct DsSyncTest *ctx;
1012 *data = ctx = test_create_context(tctx);
1013 torture_assert(tctx, ctx, "test_create_context() failed");
1015 bret = _test_DsBind(tctx, ctx, ctx->admin.credentials, &ctx->admin.drsuapi);
1016 torture_assert(tctx, bret, "_test_DsBind() failed");
1018 bret = test_LDAPBind(tctx, ctx, ctx->admin.credentials, &ctx->admin.ldap);
1019 torture_assert(tctx, bret, "test_LDAPBind() failed");
1021 bret = test_GetInfo(tctx, ctx);
1022 torture_assert(tctx, bret, "test_GetInfo() failed");
1024 bret = _test_DsBind(tctx, ctx, ctx->new_dc.credentials, &ctx->new_dc.drsuapi);
1025 torture_assert(tctx, bret, "_test_DsBind() failed");
1031 * DSSYNC test case cleanup
1033 static bool torture_dssync_tcase_teardown(struct torture_context *tctx, void *data)
1035 struct DsSyncTest *ctx;
1036 struct drsuapi_DsUnbind r;
1037 struct policy_handle bind_handle;
1039 ctx = talloc_get_type(data, struct DsSyncTest);
1042 r.out.bind_handle = &bind_handle;
1044 /* Unbing admin handle */
1045 r.in.bind_handle = &ctx->admin.drsuapi.bind_handle;
1046 dcerpc_drsuapi_DsUnbind_r(ctx->admin.drsuapi.drs_handle, ctx, &r);
1048 /* Unbing new_dc handle */
1049 r.in.bind_handle = &ctx->new_dc.drsuapi.bind_handle;
1050 dcerpc_drsuapi_DsUnbind_r(ctx->new_dc.drsuapi.drs_handle, ctx, &r);
1058 * DSSYNC test case implementation
1060 void torture_drs_rpc_dssync_tcase(struct torture_suite *suite)
1062 typedef bool (*run_func) (struct torture_context *test, void *tcase_data);
1063 struct torture_tcase *tcase = torture_suite_add_tcase(suite, "dssync");
1065 torture_tcase_set_fixture(tcase,
1066 torture_dssync_tcase_setup,
1067 torture_dssync_tcase_teardown);
1069 torture_tcase_add_simple_test(tcase, "DC_FetchData", (run_func)test_FetchData);
1070 torture_tcase_add_simple_test(tcase, "FetchNT4Data", (run_func)test_FetchNT4Data);