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 "../libcli/drsuapi/drsuapi.h"
34 #include "auth/credentials/credentials.h"
35 #include "libcli/auth/libcli_auth.h"
36 #include "auth/gensec/gensec.h"
37 #include "param/param.h"
38 #include "dsdb/samdb/samdb.h"
39 #include "torture/rpc/rpc.h"
40 #include "torture/drs/proto.h"
43 struct DsSyncBindInfo {
44 struct dcerpc_pipe *pipe;
45 struct drsuapi_DsBind req;
46 struct GUID bind_guid;
47 struct drsuapi_DsBindInfoCtr our_bind_info_ctr;
48 struct drsuapi_DsBindInfo28 our_bind_info28;
49 struct drsuapi_DsBindInfo28 peer_bind_info28;
50 struct policy_handle bind_handle;
53 struct DsSyncLDAPInfo {
54 struct ldap_connection *conn;
58 struct dcerpc_binding *drsuapi_binding;
61 const char *site_name;
63 const char *domain_dn;
65 /* what we need to do as 'Administrator' */
67 struct cli_credentials *credentials;
68 struct DsSyncBindInfo drsuapi;
69 struct DsSyncLDAPInfo ldap;
72 /* what we need to do as the new dc machine account */
74 struct cli_credentials *credentials;
75 struct DsSyncBindInfo drsuapi;
76 struct drsuapi_DsGetDCInfo2 dc_info2;
77 struct GUID invocation_id;
78 struct GUID object_guid;
81 /* info about the old dc */
83 struct drsuapi_DsGetDomainControllerInfo dc_info;
87 static struct DsSyncTest *test_create_context(struct torture_context *tctx)
90 struct DsSyncTest *ctx;
91 struct drsuapi_DsBindInfo28 *our_bind_info28;
92 struct drsuapi_DsBindInfoCtr *our_bind_info_ctr;
93 const char *binding = torture_setting_string(tctx, "binding", NULL);
94 ctx = talloc_zero(tctx, struct DsSyncTest);
95 if (!ctx) return NULL;
97 status = dcerpc_parse_binding(ctx, binding, &ctx->drsuapi_binding);
98 if (!NT_STATUS_IS_OK(status)) {
99 printf("Bad binding string %s\n", binding);
102 ctx->drsuapi_binding->flags |= DCERPC_SIGN | DCERPC_SEAL;
104 ctx->ldap_url = talloc_asprintf(ctx, "ldap://%s/", ctx->drsuapi_binding->host);
107 ctx->admin.credentials = cmdline_credentials;
109 our_bind_info28 = &ctx->admin.drsuapi.our_bind_info28;
110 our_bind_info28->supported_extensions = 0xFFFFFFFF;
111 our_bind_info28->supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_ADDENTRYREPLY_V3;
112 our_bind_info28->site_guid = GUID_zero();
113 our_bind_info28->pid = 0;
114 our_bind_info28->repl_epoch = 1;
116 our_bind_info_ctr = &ctx->admin.drsuapi.our_bind_info_ctr;
117 our_bind_info_ctr->length = 28;
118 our_bind_info_ctr->info.info28 = *our_bind_info28;
120 GUID_from_string(DRSUAPI_DS_BIND_GUID, &ctx->admin.drsuapi.bind_guid);
122 ctx->admin.drsuapi.req.in.bind_guid = &ctx->admin.drsuapi.bind_guid;
123 ctx->admin.drsuapi.req.in.bind_info = our_bind_info_ctr;
124 ctx->admin.drsuapi.req.out.bind_handle = &ctx->admin.drsuapi.bind_handle;
127 ctx->new_dc.credentials = cmdline_credentials;
129 our_bind_info28 = &ctx->new_dc.drsuapi.our_bind_info28;
130 our_bind_info28->supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_BASE;
131 our_bind_info28->supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_ASYNC_REPLICATION;
132 our_bind_info28->supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_REMOVEAPI;
133 our_bind_info28->supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_MOVEREQ_V2;
134 our_bind_info28->supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_GETCHG_COMPRESS;
135 our_bind_info28->supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_DCINFO_V1;
136 our_bind_info28->supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_RESTORE_USN_OPTIMIZATION;
137 our_bind_info28->supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_KCC_EXECUTE;
138 our_bind_info28->supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_ADDENTRY_V2;
139 our_bind_info28->supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_LINKED_VALUE_REPLICATION;
140 our_bind_info28->supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_DCINFO_V2;
141 our_bind_info28->supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_INSTANCE_TYPE_NOT_REQ_ON_MOD;
142 our_bind_info28->supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_CRYPTO_BIND;
143 our_bind_info28->supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_GET_REPL_INFO;
144 our_bind_info28->supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_STRONG_ENCRYPTION;
145 our_bind_info28->supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_DCINFO_V01;
146 our_bind_info28->supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_TRANSITIVE_MEMBERSHIP;
147 our_bind_info28->supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_ADD_SID_HISTORY;
148 our_bind_info28->supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_POST_BETA3;
149 our_bind_info28->supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_GET_MEMBERSHIPS2;
150 our_bind_info28->supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_GETCHGREQ_V6;
151 our_bind_info28->supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_NONDOMAIN_NCS;
152 our_bind_info28->supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_GETCHGREQ_V8;
153 our_bind_info28->supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_GETCHGREPLY_V5;
154 our_bind_info28->supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_GETCHGREPLY_V6;
155 our_bind_info28->supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_ADDENTRYREPLY_V3;
156 our_bind_info28->supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_GETCHGREPLY_V7;
157 our_bind_info28->supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_VERIFY_OBJECT;
158 if (lp_parm_bool(tctx->lp_ctx, NULL, "dssync", "xpress", false)) {
159 our_bind_info28->supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_XPRESS_COMPRESS;
161 our_bind_info28->site_guid = GUID_zero();
162 our_bind_info28->pid = 0;
163 our_bind_info28->repl_epoch = 0;
165 our_bind_info_ctr = &ctx->new_dc.drsuapi.our_bind_info_ctr;
166 our_bind_info_ctr->length = 28;
167 our_bind_info_ctr->info.info28 = *our_bind_info28;
169 GUID_from_string(DRSUAPI_DS_BIND_GUID_W2K3, &ctx->new_dc.drsuapi.bind_guid);
171 ctx->new_dc.drsuapi.req.in.bind_guid = &ctx->new_dc.drsuapi.bind_guid;
172 ctx->new_dc.drsuapi.req.in.bind_info = our_bind_info_ctr;
173 ctx->new_dc.drsuapi.req.out.bind_handle = &ctx->new_dc.drsuapi.bind_handle;
175 ctx->new_dc.invocation_id = ctx->new_dc.drsuapi.bind_guid;
182 static bool _test_DsBind(struct torture_context *tctx,
183 struct DsSyncTest *ctx, struct cli_credentials *credentials, struct DsSyncBindInfo *b)
188 status = dcerpc_pipe_connect_b(ctx,
189 &b->pipe, ctx->drsuapi_binding,
191 credentials, tctx->ev, tctx->lp_ctx);
193 if (!NT_STATUS_IS_OK(status)) {
194 printf("Failed to connect to server as a BDC: %s\n", nt_errstr(status));
198 status = dcerpc_drsuapi_DsBind(b->pipe, ctx, &b->req);
199 if (!NT_STATUS_IS_OK(status)) {
200 const char *errstr = nt_errstr(status);
201 if (NT_STATUS_EQUAL(status, NT_STATUS_NET_WRITE_FAULT)) {
202 errstr = dcerpc_errstr(ctx, b->pipe->last_fault_code);
204 printf("dcerpc_drsuapi_DsBind failed - %s\n", errstr);
206 } else if (!W_ERROR_IS_OK(b->req.out.result)) {
207 printf("DsBind failed - %s\n", win_errstr(b->req.out.result));
211 ZERO_STRUCT(b->peer_bind_info28);
212 if (b->req.out.bind_info) {
213 switch (b->req.out.bind_info->length) {
215 struct drsuapi_DsBindInfo24 *info24;
216 info24 = &b->req.out.bind_info->info.info24;
217 b->peer_bind_info28.supported_extensions= info24->supported_extensions;
218 b->peer_bind_info28.site_guid = info24->site_guid;
219 b->peer_bind_info28.pid = info24->pid;
220 b->peer_bind_info28.repl_epoch = 0;
224 struct drsuapi_DsBindInfo48 *info48;
225 info48 = &b->req.out.bind_info->info.info48;
226 b->peer_bind_info28.supported_extensions= info48->supported_extensions;
227 b->peer_bind_info28.site_guid = info48->site_guid;
228 b->peer_bind_info28.pid = info48->pid;
229 b->peer_bind_info28.repl_epoch = info48->repl_epoch;
233 b->peer_bind_info28 = b->req.out.bind_info->info.info28;
236 printf("DsBind - warning: unknown BindInfo length: %u\n",
237 b->req.out.bind_info->length);
244 static bool test_LDAPBind(struct torture_context *tctx, struct DsSyncTest *ctx,
245 struct cli_credentials *credentials, struct DsSyncLDAPInfo *l)
250 status = torture_ldap_connection(tctx, &l->conn, ctx->ldap_url);
251 if (!NT_STATUS_IS_OK(status)) {
252 printf("failed to connect to LDAP: %s\n", ctx->ldap_url);
256 printf("connected to LDAP: %s\n", ctx->ldap_url);
258 status = torture_ldap_bind_sasl(l->conn, credentials, tctx->lp_ctx);
259 if (!NT_STATUS_IS_OK(status)) {
260 printf("failed to bind to LDAP:\n");
263 printf("bound to LDAP.\n");
268 static bool test_GetInfo(struct torture_context *tctx, struct DsSyncTest *ctx)
271 struct drsuapi_DsCrackNames r;
272 union drsuapi_DsNameRequest req;
273 union drsuapi_DsNameCtr ctr;
274 int32_t level_out = 0;
275 struct drsuapi_DsNameString names[1];
277 struct cldap_socket *cldap;
278 struct cldap_netlogon search;
280 status = cldap_socket_init(ctx, NULL, NULL, NULL, &cldap);
281 if (!NT_STATUS_IS_OK(status)) {
282 printf("failed to setup cldap socket - %s\n",
287 r.in.bind_handle = &ctx->admin.drsuapi.bind_handle;
290 r.in.req->req1.codepage = 1252; /* western european */
291 r.in.req->req1.language = 0x00000407; /* german */
292 r.in.req->req1.count = 1;
293 r.in.req->req1.names = names;
294 r.in.req->req1.format_flags = DRSUAPI_DS_NAME_FLAG_NO_FLAGS;
295 r.in.req->req1.format_offered = DRSUAPI_DS_NAME_FORMAT_NT4_ACCOUNT;
296 r.in.req->req1.format_desired = DRSUAPI_DS_NAME_FORMAT_FQDN_1779;
297 names[0].str = talloc_asprintf(ctx, "%s\\", lp_workgroup(tctx->lp_ctx));
299 r.out.level_out = &level_out;
302 status = dcerpc_drsuapi_DsCrackNames(ctx->admin.drsuapi.pipe, ctx, &r);
303 if (!NT_STATUS_IS_OK(status)) {
304 const char *errstr = nt_errstr(status);
305 if (NT_STATUS_EQUAL(status, NT_STATUS_NET_WRITE_FAULT)) {
306 errstr = dcerpc_errstr(ctx, ctx->admin.drsuapi.pipe->last_fault_code);
308 printf("dcerpc_drsuapi_DsCrackNames failed - %s\n", errstr);
310 } else if (!W_ERROR_IS_OK(r.out.result)) {
311 printf("DsCrackNames failed - %s\n", win_errstr(r.out.result));
315 ctx->domain_dn = r.out.ctr->ctr1->array[0].result_name;
318 search.in.dest_address = ctx->drsuapi_binding->host;
319 search.in.dest_port = lp_cldap_port(tctx->lp_ctx);
320 search.in.acct_control = -1;
321 search.in.version = NETLOGON_NT_VERSION_5 | NETLOGON_NT_VERSION_5EX;
322 search.in.map_response = true;
323 status = cldap_netlogon(cldap, lp_iconv_convenience(tctx->lp_ctx), ctx, &search);
324 if (!NT_STATUS_IS_OK(status)) {
325 const char *errstr = nt_errstr(status);
326 ctx->site_name = talloc_asprintf(ctx, "%s", "Default-First-Site-Name");
327 printf("cldap_netlogon() returned %s. Defaulting to Site-Name: %s\n", errstr, ctx->site_name);
329 ctx->site_name = talloc_steal(ctx, search.out.netlogon.data.nt5_ex.client_site);
330 printf("cldap_netlogon() returned Client Site-Name: %s.\n",ctx->site_name);
331 printf("cldap_netlogon() returned Server Site-Name: %s.\n",search.out.netlogon.data.nt5_ex.server_site);
334 if (!ctx->domain_dn) {
335 struct ldb_context *ldb = ldb_init(ctx, tctx->ev);
336 struct ldb_dn *dn = samdb_dns_domain_to_dn(ldb, ctx, search.out.netlogon.data.nt5_ex.dns_domain);
337 ctx->domain_dn = ldb_dn_alloc_linearized(ctx, dn);
345 static void test_analyse_objects(struct torture_context *tctx,
346 struct DsSyncTest *ctx,
347 const DATA_BLOB *gensec_skey,
348 struct drsuapi_DsReplicaObjectListItemEx *cur)
350 static uint32_t object_id;
351 const char *save_values_dir;
353 if (!lp_parm_bool(tctx->lp_ctx, NULL, "dssync", "print_pwd_blobs", false)) {
357 save_values_dir = lp_parm_string(tctx->lp_ctx, NULL, "dssync", "save_pwd_blobs_dir");
359 for (; cur; cur = cur->next_object) {
361 struct dom_sid *sid = NULL;
363 bool dn_printed = false;
366 if (!cur->object.identifier) continue;
368 dn = cur->object.identifier->dn;
369 if (cur->object.identifier->sid.num_auths > 0) {
370 sid = &cur->object.identifier->sid;
371 rid = sid->sub_auths[sid->num_auths - 1];
374 for (i=0; i < cur->object.attribute_ctr.num_attributes; i++) {
376 const char *name = NULL;
378 DATA_BLOB *enc_data = NULL;
379 DATA_BLOB plain_data;
380 struct drsuapi_DsReplicaAttribute *attr;
381 ndr_pull_flags_fn_t pull_fn = NULL;
382 ndr_print_fn_t print_fn = NULL;
384 attr = &cur->object.attribute_ctr.attributes[i];
386 switch (attr->attid) {
387 case DRSUAPI_ATTRIBUTE_dBCSPwd:
391 case DRSUAPI_ATTRIBUTE_unicodePwd:
395 case DRSUAPI_ATTRIBUTE_ntPwdHistory:
396 name = "ntPwdHistory";
399 case DRSUAPI_ATTRIBUTE_lmPwdHistory:
400 name = "lmPwdHistory";
403 case DRSUAPI_ATTRIBUTE_supplementalCredentials:
404 name = "supplementalCredentials";
405 pull_fn = (ndr_pull_flags_fn_t)ndr_pull_supplementalCredentialsBlob;
406 print_fn = (ndr_print_fn_t)ndr_print_supplementalCredentialsBlob;
407 ptr = talloc(ctx, struct supplementalCredentialsBlob);
409 case DRSUAPI_ATTRIBUTE_priorValue:
412 case DRSUAPI_ATTRIBUTE_currentValue:
413 name = "currentValue";
415 case DRSUAPI_ATTRIBUTE_trustAuthOutgoing:
416 name = "trustAuthOutgoing";
417 pull_fn = (ndr_pull_flags_fn_t)ndr_pull_trustAuthInOutBlob;
418 print_fn = (ndr_print_fn_t)ndr_print_trustAuthInOutBlob;
419 ptr = talloc(ctx, struct trustAuthInOutBlob);
421 case DRSUAPI_ATTRIBUTE_trustAuthIncoming:
422 name = "trustAuthIncoming";
423 pull_fn = (ndr_pull_flags_fn_t)ndr_pull_trustAuthInOutBlob;
424 print_fn = (ndr_print_fn_t)ndr_print_trustAuthInOutBlob;
425 ptr = talloc(ctx, struct trustAuthInOutBlob);
427 case DRSUAPI_ATTRIBUTE_initialAuthOutgoing:
428 name = "initialAuthOutgoing";
430 case DRSUAPI_ATTRIBUTE_initialAuthIncoming:
431 name = "initialAuthIncoming";
437 if (attr->value_ctr.num_values != 1) continue;
439 if (!attr->value_ctr.values[0].blob) continue;
441 enc_data = attr->value_ctr.values[0].blob;
442 ZERO_STRUCT(plain_data);
444 werr = drsuapi_decrypt_attribute_value(ctx, gensec_skey, rcrypt,
446 enc_data, &plain_data);
447 if (!W_ERROR_IS_OK(werr)) {
448 DEBUG(0, ("Failed to decrypt %s\n", name));
453 DEBUG(0,("DN[%u] %s\n", object_id, dn));
456 DEBUGADD(0,("ATTR: %s enc.length=%lu plain.length=%lu\n",
457 name, (long)enc_data->length, (long)plain_data.length));
458 if (plain_data.length) {
459 enum ndr_err_code ndr_err;
460 dump_data(0, plain_data.data, plain_data.length);
461 if (save_values_dir) {
463 fname = talloc_asprintf(ctx, "%s/%s%02d",
468 ok = file_save(fname, plain_data.data, plain_data.length);
470 DEBUGADD(0,("Failed to save '%s'\n", fname));
477 /* Can't use '_all' because of PIDL bugs with relative pointers */
478 ndr_err = ndr_pull_struct_blob(&plain_data, ptr,
479 lp_iconv_convenience(tctx->lp_ctx), ptr,
481 if (NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
482 ndr_print_debug(print_fn, name, ptr);
484 DEBUG(0, ("Failed to decode %s\n", name));
488 dump_data(0, enc_data->data, enc_data->length);
496 * Fetch LDAP attribute name and DN by supplied OID
498 static bool _drs_ldap_attr_by_oid(struct torture_context *tctx,
499 struct DsSyncTest *ctx,
501 const char **attr_dn,
502 const char **attr_name)
505 const char *config_dn;
506 const char *expression;
507 struct ldap_message **res_msg;
508 struct ldap_SearchResEntry *search_res;
509 TALLOC_CTX *tmp_ctx = NULL;
510 const char *search_attrs[] = {"lDAPDisplayName", NULL};
512 tmp_ctx = talloc_new(ctx);
514 config_dn = talloc_asprintf(tmp_ctx, "CN=Schema,CN=Configuration,%s", ctx->domain_dn);
515 expression = talloc_asprintf(tmp_ctx, "(attributeID=%s)", oid);
517 status = ildap_search(ctx->admin.ldap.conn,
518 config_dn, LDAP_SEARCH_SCOPE_SUB,
519 expression, search_attrs, false,
520 NULL, NULL, &res_msg);
521 torture_assert_ntstatus_ok(tctx, status, "LDAP search request failed");
523 ildap_count_entries(ctx->admin.ldap.conn, res_msg) == 1,
524 talloc_asprintf(tmp_ctx, "Failed to find attribute with OID=%s", oid));
526 search_res = &res_msg[0]->r.SearchResultEntry;
527 torture_assert(tctx, search_res->num_attributes > 0, "No attributes returned!")
528 torture_assert(tctx, strequal(search_attrs[0], search_res->attributes[0].name),
529 "Requested attributes for attribute class not returned");
532 *attr_dn = search_res->dn;
536 *attr_name = (const char *)search_res->attributes[0].values[0].data;
539 talloc_free(tmp_ctx);
545 * Make Attribute OID and verify such Attribute exists in schema
547 static bool _drs_util_verify_attids(struct torture_context *tctx,
548 struct DsSyncTest *ctx,
549 struct drsuapi_DsReplicaOIDMapping_Ctr *prefix_map,
550 struct drsuapi_DsReplicaObjectListItemEx *cur)
554 DEBUG(1,("drs_test_verify_attids:\n"));
556 for (; cur; cur = cur->next_object) {
557 const char *attr_dn = NULL;
558 const char *attr_name = NULL;
559 struct drsuapi_DsReplicaObject *obj = &cur->object;
561 DEBUG(1,("%3s %-10s: %s\n", "", "object_dn", obj->identifier->dn));
563 for (i = 0; i < obj->attribute_ctr.num_attributes; i++) {
565 const char *oid = NULL;
566 struct drsuapi_DsReplicaAttribute *attr;
568 attr = &obj->attribute_ctr.attributes[i];
569 if (!drs_util_oid_from_attid(tctx, prefix_map, attr->attid, &oid, &map_idx)) {
573 if (!_drs_ldap_attr_by_oid(tctx, ctx, oid, &attr_dn, &attr_name)) {
577 DEBUG(1,("%7s attr[%2d]: %-22s {map_idx=%2d; attid=0x%06x; ldap_name=%-26s; idl_name=%s}\n", "",
578 i, oid, map_idx, attr->attid, attr_name,
579 drs_util_DsAttributeId_to_string(attr->attid)));
587 static bool test_FetchData(struct torture_context *tctx, struct DsSyncTest *ctx)
592 uint64_t highest_usn = 0;
593 const char *partition = NULL;
594 struct drsuapi_DsGetNCChanges r;
595 union drsuapi_DsGetNCChangesRequest req;
596 struct drsuapi_DsReplicaObjectIdentifier nc;
597 struct drsuapi_DsGetNCChangesCtr1 *ctr1 = NULL;
598 struct drsuapi_DsGetNCChangesCtr6 *ctr6 = NULL;
599 int32_t out_level = 0;
600 struct GUID null_guid;
601 struct dom_sid null_sid;
602 DATA_BLOB gensec_skey;
614 ZERO_STRUCT(null_guid);
615 ZERO_STRUCT(null_sid);
617 partition = lp_parm_string(tctx->lp_ctx, NULL, "dssync", "partition");
618 if (partition == NULL) {
619 partition = ctx->domain_dn;
620 printf("dssync:partition not specified, defaulting to %s.\n", ctx->domain_dn);
623 highest_usn = lp_parm_int(tctx->lp_ctx, NULL, "dssync", "highest_usn", 0);
625 array[0].level = lp_parm_int(tctx->lp_ctx, NULL, "dssync", "get_nc_changes_level", array[0].level);
627 if (lp_parm_bool(tctx->lp_ctx, NULL, "dssync", "print_pwd_blobs", false)) {
628 const struct samr_Password *nthash;
629 nthash = cli_credentials_get_nt_hash(ctx->new_dc.credentials, ctx);
631 dump_data_pw("CREDENTIALS nthash:", nthash->hash, sizeof(nthash->hash));
634 status = gensec_session_key(ctx->new_dc.drsuapi.pipe->conn->security_state.generic_state,
636 if (!NT_STATUS_IS_OK(status)) {
637 printf("failed to get gensec session key: %s\n", nt_errstr(status));
641 for (i=0; i < ARRAY_SIZE(array); i++) {
642 printf("testing DsGetNCChanges level %d\n",
645 r.in.bind_handle = &ctx->new_dc.drsuapi.bind_handle;
646 r.in.level = array[i].level;
648 switch (r.in.level) {
655 r.in.req->req5.destination_dsa_guid = ctx->new_dc.invocation_id;
656 r.in.req->req5.source_dsa_invocation_id = null_guid;
657 r.in.req->req5.naming_context = &nc;
658 r.in.req->req5.highwatermark.tmp_highest_usn = highest_usn;
659 r.in.req->req5.highwatermark.reserved_usn = 0;
660 r.in.req->req5.highwatermark.highest_usn = highest_usn;
661 r.in.req->req5.uptodateness_vector = NULL;
662 r.in.req->req5.replica_flags = 0;
663 if (lp_parm_bool(tctx->lp_ctx, NULL, "dssync", "compression", false)) {
664 r.in.req->req5.replica_flags |= DRSUAPI_DS_REPLICA_NEIGHBOUR_COMPRESS_CHANGES;
666 if (lp_parm_bool(tctx->lp_ctx, NULL, "dssync", "neighbour_writeable", true)) {
667 r.in.req->req5.replica_flags |= DRSUAPI_DS_REPLICA_NEIGHBOUR_WRITEABLE;
669 r.in.req->req5.replica_flags |= DRSUAPI_DS_REPLICA_NEIGHBOUR_SYNC_ON_STARTUP
670 | DRSUAPI_DS_REPLICA_NEIGHBOUR_DO_SCHEDULED_SYNCS
671 | DRSUAPI_DS_REPLICA_NEIGHBOUR_RETURN_OBJECT_PARENTS
672 | DRSUAPI_DS_REPLICA_NEIGHBOUR_NEVER_SYNCED
674 r.in.req->req5.max_object_count = 133;
675 r.in.req->req5.max_ndr_size = 1336770;
676 r.in.req->req5.extended_op = DRSUAPI_EXOP_NONE;
677 r.in.req->req5.fsmo_info = 0;
684 /* nc.dn can be set to any other ad partition */
687 r.in.req->req8.destination_dsa_guid = ctx->new_dc.invocation_id;
688 r.in.req->req8.source_dsa_invocation_id = null_guid;
689 r.in.req->req8.naming_context = &nc;
690 r.in.req->req8.highwatermark.tmp_highest_usn = highest_usn;
691 r.in.req->req8.highwatermark.reserved_usn = 0;
692 r.in.req->req8.highwatermark.highest_usn = highest_usn;
693 r.in.req->req8.uptodateness_vector = NULL;
694 r.in.req->req8.replica_flags = 0;
695 if (lp_parm_bool(tctx->lp_ctx, NULL, "dssync", "compression", false)) {
696 r.in.req->req8.replica_flags |= DRSUAPI_DS_REPLICA_NEIGHBOUR_COMPRESS_CHANGES;
698 if (lp_parm_bool(tctx->lp_ctx, NULL, "dssync", "neighbour_writeable", true)) {
699 r.in.req->req8.replica_flags |= DRSUAPI_DS_REPLICA_NEIGHBOUR_WRITEABLE;
701 r.in.req->req8.replica_flags |= DRSUAPI_DS_REPLICA_NEIGHBOUR_SYNC_ON_STARTUP
702 | DRSUAPI_DS_REPLICA_NEIGHBOUR_DO_SCHEDULED_SYNCS
703 | DRSUAPI_DS_REPLICA_NEIGHBOUR_RETURN_OBJECT_PARENTS
704 | DRSUAPI_DS_REPLICA_NEIGHBOUR_NEVER_SYNCED
706 r.in.req->req8.max_object_count = 402;
707 r.in.req->req8.max_ndr_size = 402116;
709 r.in.req->req8.extended_op = DRSUAPI_EXOP_NONE;
710 r.in.req->req8.fsmo_info = 0;
711 r.in.req->req8.partial_attribute_set = NULL;
712 r.in.req->req8.partial_attribute_set_ex = NULL;
713 r.in.req->req8.mapping_ctr.num_mappings = 0;
714 r.in.req->req8.mapping_ctr.mappings = NULL;
719 printf("Dumping AD partition: %s\n", nc.dn);
722 union drsuapi_DsGetNCChangesCtr ctr;
726 r.out.level_out = &_level;
729 if (r.in.level == 5) {
730 DEBUG(0,("start[%d] tmp_higest_usn: %llu , highest_usn: %llu\n",y,
731 (long long)r.in.req->req5.highwatermark.tmp_highest_usn,
732 (long long)r.in.req->req5.highwatermark.highest_usn));
735 if (r.in.level == 8) {
736 DEBUG(0,("start[%d] tmp_higest_usn: %llu , highest_usn: %llu\n",y,
737 (long long)r.in.req->req8.highwatermark.tmp_highest_usn,
738 (long long)r.in.req->req8.highwatermark.highest_usn));
741 status = dcerpc_drsuapi_DsGetNCChanges(ctx->new_dc.drsuapi.pipe, ctx, &r);
742 if (!NT_STATUS_IS_OK(status)) {
743 const char *errstr = nt_errstr(status);
744 if (NT_STATUS_EQUAL(status, NT_STATUS_NET_WRITE_FAULT)) {
745 errstr = dcerpc_errstr(ctx, ctx->new_dc.drsuapi.pipe->last_fault_code);
747 printf("dcerpc_drsuapi_DsGetNCChanges failed - %s\n", errstr);
749 } else if (!W_ERROR_IS_OK(r.out.result)) {
750 printf("DsGetNCChanges failed - %s\n", win_errstr(r.out.result));
754 if (ret == true && *r.out.level_out == 1) {
756 ctr1 = &r.out.ctr->ctr1;
757 } else if (ret == true && *r.out.level_out == 2 &&
758 r.out.ctr->ctr2.mszip1.ts) {
760 ctr1 = &r.out.ctr->ctr2.mszip1.ts->ctr1;
763 if (out_level == 1) {
764 DEBUG(0,("end[%d] tmp_highest_usn: %llu , highest_usn: %llu\n",y,
765 (long long)ctr1->new_highwatermark.tmp_highest_usn,
766 (long long)ctr1->new_highwatermark.highest_usn));
768 _drs_util_verify_attids(tctx, ctx, &ctr1->mapping_ctr, ctr1->first_object);
770 test_analyse_objects(tctx, ctx, &gensec_skey, ctr1->first_object);
772 if (ctr1->more_data) {
773 r.in.req->req5.highwatermark = ctr1->new_highwatermark;
778 if (ret == true && *r.out.level_out == 6) {
780 ctr6 = &r.out.ctr->ctr6;
781 } else if (ret == true && *r.out.level_out == 7
782 && r.out.ctr->ctr7.level == 6
783 && r.out.ctr->ctr7.type == DRSUAPI_COMPRESSION_TYPE_MSZIP
784 && r.out.ctr->ctr7.ctr.mszip6.ts) {
786 ctr6 = &r.out.ctr->ctr7.ctr.mszip6.ts->ctr6;
787 } else if (ret == true && *r.out.level_out == 7
788 && r.out.ctr->ctr7.level == 6
789 && r.out.ctr->ctr7.type == DRSUAPI_COMPRESSION_TYPE_XPRESS
790 && r.out.ctr->ctr7.ctr.xpress6.ts) {
792 ctr6 = &r.out.ctr->ctr7.ctr.xpress6.ts->ctr6;
795 if (out_level == 6) {
796 DEBUG(0,("end[%d] tmp_highest_usn: %llu , highest_usn: %llu\n",y,
797 (long long)ctr6->new_highwatermark.tmp_highest_usn,
798 (long long)ctr6->new_highwatermark.highest_usn));
800 _drs_util_verify_attids(tctx, ctx, &ctr6->mapping_ctr, ctr6->first_object);
802 test_analyse_objects(tctx, ctx, &gensec_skey, ctr6->first_object);
804 if (ctr6->more_data) {
805 r.in.req->req8.highwatermark = ctr6->new_highwatermark;
817 static bool test_FetchNT4Data(struct torture_context *tctx,
818 struct DsSyncTest *ctx)
822 struct drsuapi_DsGetNT4ChangeLog r;
823 union drsuapi_DsGetNT4ChangeLogRequest req;
824 union drsuapi_DsGetNT4ChangeLogInfo info;
825 uint32_t level_out = 0;
826 struct GUID null_guid;
827 struct dom_sid null_sid;
830 ZERO_STRUCT(null_guid);
831 ZERO_STRUCT(null_sid);
835 r.in.bind_handle = &ctx->new_dc.drsuapi.bind_handle;
838 r.out.level_out = &level_out;
840 req.req1.unknown1 = lp_parm_int(tctx->lp_ctx, NULL, "dssync", "nt4-1", 3);
841 req.req1.unknown2 = lp_parm_int(tctx->lp_ctx, NULL, "dssync", "nt4-2", 0x00004000);
844 req.req1.length = cookie.length;
845 req.req1.data = cookie.data;
849 status = dcerpc_drsuapi_DsGetNT4ChangeLog(ctx->new_dc.drsuapi.pipe, ctx, &r);
850 if (NT_STATUS_EQUAL(status, NT_STATUS_NOT_IMPLEMENTED)) {
851 printf("DsGetNT4ChangeLog not supported by target server\n");
853 } else if (!NT_STATUS_IS_OK(status)) {
854 const char *errstr = nt_errstr(status);
855 if (NT_STATUS_EQUAL(status, NT_STATUS_NET_WRITE_FAULT)) {
856 errstr = dcerpc_errstr(ctx, ctx->new_dc.drsuapi.pipe->last_fault_code);
858 printf("dcerpc_drsuapi_DsGetNT4ChangeLog failed - %s\n", errstr);
860 } else if (W_ERROR_EQUAL(r.out.result, WERR_INVALID_DOMAIN_ROLE)) {
861 printf("DsGetNT4ChangeLog not supported by target server\n");
863 } else if (!W_ERROR_IS_OK(r.out.result)) {
864 printf("DsGetNT4ChangeLog failed - %s\n", win_errstr(r.out.result));
866 } else if (*r.out.level_out != 1) {
867 printf("DsGetNT4ChangeLog unknown level - %u\n", *r.out.level_out);
869 } else if (NT_STATUS_IS_OK(r.out.info->info1.status)) {
870 } else if (NT_STATUS_EQUAL(r.out.info->info1.status, STATUS_MORE_ENTRIES)) {
871 cookie.length = r.out.info->info1.length1;
872 cookie.data = r.out.info->info1.data1;
875 printf("DsGetNT4ChangeLog failed - %s\n", nt_errstr(r.out.info->info1.status));
885 bool torture_rpc_dssync(struct torture_context *torture)
889 struct DsSyncTest *ctx;
891 mem_ctx = talloc_init("torture_rpc_dssync");
892 ctx = test_create_context(torture);
894 ret &= _test_DsBind(torture, ctx, ctx->admin.credentials, &ctx->admin.drsuapi);
898 ret &= test_LDAPBind(torture, ctx, ctx->admin.credentials, &ctx->admin.ldap);
902 ret &= test_GetInfo(torture, ctx);
903 ret &= _test_DsBind(torture, ctx, ctx->new_dc.credentials, &ctx->new_dc.drsuapi);
907 ret &= test_FetchData(torture, ctx);
908 ret &= test_FetchNT4Data(torture, ctx);