>From 445d9be4fca3472afd4519b972460fb8614c1f45 Mon Sep 17 00:00:00 2001 From: Dirk Godau Date: Wed, 25 May 2016 11:50:09 +1200 Subject: [PATCH 1/2] drsuapi tests for DsBind with w2k8 These are marked as known_fail pending the next patch ("Extend DsBind and DsGetDomainControllerInfo to work with w2k8"). Signed-off-by: Dirk Godau Reviewed-by: Douglas Bagnall Reviewed-by: Garming Sam --- selftest/knownfail | 1 + source4/selftest/tests.py | 2 +- source4/torture/rpc/drsuapi.h | 18 ++ source4/torture/rpc/drsuapi_w2k8.c | 334 +++++++++++++++++++++++++++++++++++++ source4/torture/rpc/rpc.c | 1 + source4/torture/wscript_build | 1 + 6 files changed, 356 insertions(+), 1 deletion(-) create mode 100644 source4/torture/rpc/drsuapi_w2k8.c diff --git a/selftest/knownfail b/selftest/knownfail index 2f2d6bf..641730c 100644 --- a/selftest/knownfail +++ b/selftest/knownfail @@ -330,3 +330,4 @@ # ad_dc requires signing # ^samba4.smb.signing.*disabled.*signing=off.*\(ad_dc\) +^samba4.rpc.drsuapi_w2k8.*DsGetDomainControllerInfo_W2K8 diff --git a/source4/selftest/tests.py b/source4/selftest/tests.py index 15e7d19..fb66af9 100755 --- a/source4/selftest/tests.py +++ b/source4/selftest/tests.py @@ -147,7 +147,7 @@ else: ncacn_np_tests = ["rpc.schannel", "rpc.join", "rpc.lsa", "rpc.dssetup", "rpc.altercontext", "rpc.netlogon", "rpc.netlogon.admin", "rpc.handles", "rpc.samsync", "rpc.samba3-sessionkey", "rpc.samba3-getusername", "rpc.samba3-lsa", "rpc.samba3-bind", "rpc.samba3-netlogon", "rpc.asyncbind", "rpc.lsalookup", "rpc.lsa-getuser", "rpc.schannel2", "rpc.authcontext"] ncalrpc_tests = ["rpc.schannel", "rpc.join", "rpc.lsa", "rpc.dssetup", "rpc.altercontext", "rpc.netlogon", "rpc.netlogon.admin", "rpc.asyncbind", "rpc.lsalookup", "rpc.lsa-getuser", "rpc.schannel2", "rpc.authcontext"] drs_rpc_tests = smbtorture4_testsuites("drs.rpc") -ncacn_ip_tcp_tests = ["rpc.schannel", "rpc.join", "rpc.lsa", "rpc.dssetup", "rpc.drsuapi", "rpc.netlogon", "rpc.netlogon.admin", "rpc.asyncbind", "rpc.lsalookup", "rpc.lsa-getuser", "rpc.schannel2", "rpc.authcontext", "rpc.samr.passwords.validate"] + drs_rpc_tests +ncacn_ip_tcp_tests = ["rpc.schannel", "rpc.join", "rpc.lsa", "rpc.dssetup", "rpc.drsuapi", "rpc.drsuapi_w2k8", "rpc.netlogon", "rpc.netlogon.admin", "rpc.asyncbind", "rpc.lsalookup", "rpc.lsa-getuser", "rpc.schannel2", "rpc.authcontext", "rpc.samr.passwords.validate"] + drs_rpc_tests slow_ncacn_np_tests = ["rpc.samlogon", "rpc.samr", "rpc.samr.users", "rpc.samr.large-dc", "rpc.samr.users.privileges", "rpc.samr.passwords", "rpc.samr.passwords.pwdlastset", "rpc.samr.passwords.lockout", "rpc.samr.passwords.badpwdcount"] slow_ncacn_ip_tcp_tests = ["rpc.cracknames"] diff --git a/source4/torture/rpc/drsuapi.h b/source4/torture/rpc/drsuapi.h index 6ce3009..f1a5bba 100644 --- a/source4/torture/rpc/drsuapi.h +++ b/source4/torture/rpc/drsuapi.h @@ -40,6 +40,24 @@ struct DsPrivate { struct test_join *join; }; +/** + * Data structure of DRSUAPI W2K8 tests + * W2K8 Clients use different versions of structs + */ +struct DsPrivate_w2k8 { + struct dcerpc_pipe *drs_pipe; + struct policy_handle bind_handle; + struct GUID bind_guid; + struct drsuapi_DsBindInfoCtr srv_bind_info; + + const char *domain_obj_dn; + const char *domain_guid_str; + const char *domain_dns_name; + struct GUID domain_guid; + struct drsuapi_DsGetDCInfo3 dcinfo; + struct test_join *join; +}; + /** * Custom torture macro to check dcerpc_drsuapi_ call diff --git a/source4/torture/rpc/drsuapi_w2k8.c b/source4/torture/rpc/drsuapi_w2k8.c new file mode 100644 index 0000000..9ff37ed --- /dev/null +++ b/source4/torture/rpc/drsuapi_w2k8.c @@ -0,0 +1,334 @@ +/* + Unix SMB/CIFS implementation. + + DRSUapi tests + + Copyright (C) Andrew Tridgell 2003 + Copyright (C) Stefan (metze) Metzmacher 2004 + Copyright (C) Andrew Bartlett 2005-2006 + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 3 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . +*/ + +#include "includes.h" +#include "librpc/gen_ndr/ndr_drsuapi_c.h" +#include "torture/rpc/torture_rpc.h" +#include "param/param.h" + +#define TEST_MACHINE_NAME "torturetest" + +/* + * DsBind as sent from W2K8 Client. + * This should work regardless of functional level, and accept + * any info <=48 + */ +bool test_DsBind_w2k8(struct torture_context *tctx, + struct DsPrivate_w2k8 *priv) +{ + NTSTATUS status; + struct dcerpc_pipe *p = priv->drs_pipe; + struct drsuapi_DsBind r; + struct drsuapi_DsBindInfo48 *bind_info48; + struct drsuapi_DsBindInfoCtr bind_info_ctr; + + /* We send info48 */ + ZERO_STRUCT(bind_info_ctr); + bind_info_ctr.length = 48; + + bind_info48 = &bind_info_ctr.info.info48; + bind_info48->supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_BASE; + bind_info48->supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_ASYNC_REPLICATION; + bind_info48->supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_REMOVEAPI; + bind_info48->supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_MOVEREQ_V2; + bind_info48->supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_GETCHG_COMPRESS; + bind_info48->supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_DCINFO_V1; + bind_info48->supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_RESTORE_USN_OPTIMIZATION; + bind_info48->supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_KCC_EXECUTE; + bind_info48->supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_ADDENTRY_V2; + bind_info48->supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_LINKED_VALUE_REPLICATION; + bind_info48->supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_DCINFO_V2; + bind_info48->supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_INSTANCE_TYPE_NOT_REQ_ON_MOD; + bind_info48->supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_CRYPTO_BIND; + bind_info48->supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_GET_REPL_INFO; + bind_info48->supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_STRONG_ENCRYPTION; + bind_info48->supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_DCINFO_V01; + bind_info48->supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_TRANSITIVE_MEMBERSHIP; + bind_info48->supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_ADD_SID_HISTORY; + bind_info48->supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_POST_BETA3; + bind_info48->supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_GET_MEMBERSHIPS2; + bind_info48->supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_GETCHGREQ_V6; + bind_info48->supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_NONDOMAIN_NCS; + bind_info48->supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_GETCHGREQ_V8; + bind_info48->supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_GETCHGREPLY_V5; + bind_info48->supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_GETCHGREPLY_V6; + bind_info48->supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_ADDENTRYREPLY_V3; + bind_info48->supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_GETCHGREPLY_V7; + bind_info48->supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_VERIFY_OBJECT; + + /* + * We wish for DRSUAPI_SUPPORTED_EXTENSION_LH_BETA2, + * needed for DsGetDomainControllerInfo level 3 + */ + bind_info48->supported_extensions_ext |= DRSUAPI_SUPPORTED_EXTENSION_LH_BETA2; + + GUID_from_string(DRSUAPI_DS_BIND_GUID, &priv->bind_guid); + + r.in.bind_guid = &priv->bind_guid; + r.in.bind_info = &bind_info_ctr; + r.out.bind_handle = &priv->bind_handle; + + torture_comment(tctx, "Testing DsBind W2K8\n"); + + status = dcerpc_drsuapi_DsBind_r(p->binding_handle, tctx, &r); + torture_drsuapi_assert_call(tctx, p, status, &r, "dcerpc_drsuapi_DsBind"); + + torture_assert_not_null(tctx, r.out.bind_info, + "DsBind with info48 results in NULL"); + + /* cache server supported extensions, i.e. bind_info */ + priv->srv_bind_info = *r.out.bind_info; + + /* + * We do not check for length here, because it should be valid to return + * any valid info + */ + + return true; +} + +static bool test_DsGetDomainControllerInfo_w2k8(struct torture_context *tctx, + struct DsPrivate_w2k8 *priv) +{ + NTSTATUS status; + struct dcerpc_pipe *p = priv->drs_pipe; + struct drsuapi_DsGetDomainControllerInfo r; + union drsuapi_DsGetDCInfoCtr ctr; + int32_t level_out = 0; + uint32_t supported_extensions_ext = 0; + bool found = false; + int j, k; + + struct { + const char *name; + WERROR expected; + } names[] = { + { + .name = torture_join_dom_netbios_name(priv->join), + .expected = WERR_OK + }, + { + .name = torture_join_dom_dns_name(priv->join), + .expected = WERR_OK + }, + { + .name = "__UNKNOWN_DOMAIN__", + .expected = WERR_DS_OBJ_NOT_FOUND + }, + { + .name = "unknown.domain.samba.example.com", + .expected = WERR_DS_OBJ_NOT_FOUND + }, + }; + + /* Levels 1 and 2 are tested in standard drsuapi tests */ + int level = 3; + + /* Do Bind first. */ + if (!test_DsBind_w2k8(tctx, priv)) { + return false; + } + + /* + * We used DsBind_w2k8, so DRSUAPI_SUPPORTED_EXTENSION_LH_BETA2 + * should mean support for level 3 + */ + + /* + * We are looking for an extension found in info32 and later + */ + switch (priv->srv_bind_info.length) { + case 32: + supported_extensions_ext = priv->srv_bind_info.info.info32.supported_extensions_ext; + break; + case 48: + supported_extensions_ext = priv->srv_bind_info.info.info48.supported_extensions_ext; + break; + default: + supported_extensions_ext = 0; + break; + } + + supported_extensions_ext &= DRSUAPI_SUPPORTED_EXTENSION_LH_BETA2; + torture_assert(tctx, (supported_extensions_ext > 0), + "Server does not support DRSUAPI_SUPPORTED_EXTENSION_LH_BETA2"); + + for (j=0; j < ARRAY_SIZE(names); j++) { + union drsuapi_DsGetDCInfoRequest req; + r.in.bind_handle = &priv->bind_handle; + r.in.level = 1; + r.in.req = &req; + + r.in.req->req1.domain_name = names[j].name; + r.in.req->req1.level = level; + + r.out.ctr = &ctr; + r.out.level_out = &level_out; + + torture_comment(tctx, + "Testing DsGetDomainControllerInfo level %d on domainname '%s'\n", + r.in.req->req1.level, r.in.req->req1.domain_name); + + status = dcerpc_drsuapi_DsGetDomainControllerInfo_r(p->binding_handle, tctx, &r); + torture_assert_ntstatus_ok(tctx, status, + "dcerpc_drsuapi_DsGetDomainControllerInfo with dns domain failed"); + torture_assert_werr_equal(tctx, r.out.result, names[j].expected, + "DsGetDomainControllerInfo level with dns domain failed"); + + if (!W_ERROR_IS_OK(r.out.result)) { + /* If this was an error, we can't read the result structure */ + continue; + } + + torture_assert_int_equal(tctx, r.in.req->req1.level, *r.out.level_out, + "dcerpc_drsuapi_DsGetDomainControllerInfo in/out level differs"); + + for (k=0; k < r.out.ctr->ctr3.count; k++) { + if (strcasecmp_m(r.out.ctr->ctr3.array[k].netbios_name, + torture_join_netbios_name(priv->join)) == 0) { + found = true; + priv->dcinfo = r.out.ctr->ctr3.array[k]; + break; + } + } + break; + + torture_assert(tctx, found, + "dcerpc_drsuapi_DsGetDomainControllerInfo: Failed to find the domain controller we just created during the join"); + } + + return true; +} + + +bool test_DsUnbind_w2k8(struct torture_context *tctx, + struct DsPrivate_w2k8 *priv) +{ + NTSTATUS status; + struct dcerpc_pipe *p = priv->drs_pipe; + struct drsuapi_DsUnbind r; + + r.in.bind_handle = &priv->bind_handle; + r.out.bind_handle = &priv->bind_handle; + + torture_comment(tctx, "Testing DsUnbind W2K8\n"); + + status = dcerpc_drsuapi_DsUnbind_r(p->binding_handle, tctx, &r); + torture_drsuapi_assert_call(tctx, p, status, &r, "dcerpc_drsuapi_DsUnbind"); + + return true; +} + +/** + * Common test case setup function to be used + * in DRS suit of test when appropriate + */ +bool torture_drsuapi_w2k8_tcase_setup_common(struct torture_context *tctx, + struct DsPrivate_w2k8 *priv) +{ + NTSTATUS status; + int rnd = rand() % 1000; + char *name = talloc_asprintf(tctx, "%s%d", TEST_MACHINE_NAME, rnd); + struct cli_credentials *machine_credentials; + + torture_assert(tctx, priv, "Invalid argument"); + + torture_comment(tctx, "Create DRSUAPI pipe\n"); + status = torture_rpc_connection(tctx, + &priv->drs_pipe, + &ndr_table_drsuapi); + torture_assert(tctx, NT_STATUS_IS_OK(status), "Unable to connect to DRSUAPI pipe"); + + torture_comment(tctx, "About to join domain with name %s\n", name); + priv->join = torture_join_domain(tctx, name, ACB_SVRTRUST, + &machine_credentials); + torture_assert(tctx, priv->join, "Failed to join as BDC"); + + /* + * After that every test should use DsBind and DsGetDomainControllerInfo + */ + if (!test_DsBind_w2k8(tctx, priv)) { + /* clean up */ + torture_drsuapi_w2k8_tcase_teardown_common(tctx, priv); + torture_fail(tctx, "Failed execute test_DsBind_w2k8()"); + } + + + return true; +} + +/** + * Common test case teardown function to be used + * in DRS suit of test when appropriate + */ +bool torture_drsuapi_w2k8_tcase_teardown_common(struct torture_context *tctx, + struct DsPrivate_w2k8 *priv) +{ + if (priv->join) { + torture_leave_domain(tctx, priv->join); + } + + return true; +} + +/** + * Test case setup for DRSUAPI test case + */ +static bool torture_drsuapi_w2k8_tcase_setup(struct torture_context *tctx, void **data) +{ + struct DsPrivate_w2k8 *priv; + + *data = priv = talloc_zero(tctx, struct DsPrivate_w2k8); + + return torture_drsuapi_w2k8_tcase_setup_common(tctx, priv); +} + +/** + * Test case tear-down for DRSUAPI test case + */ +static bool torture_drsuapi_w2k8_tcase_teardown(struct torture_context *tctx, void *data) +{ + bool ret; + struct DsPrivate_w2k8 *priv = talloc_get_type(data, struct DsPrivate_w2k8); + + ret = torture_drsuapi_w2k8_tcase_teardown_common(tctx, priv); + + talloc_free(priv); + return ret; +} + +/** + * DRSUAPI test case implementation + */ +void torture_rpc_drsuapi_w2k8_tcase(struct torture_suite *suite) +{ + typedef bool (*run_func) (struct torture_context *test, void *tcase_data); + + struct torture_tcase *tcase = torture_suite_add_tcase(suite, "drsuapi_w2k8"); + + torture_tcase_set_fixture(tcase, torture_drsuapi_w2k8_tcase_setup, + torture_drsuapi_w2k8_tcase_teardown); + + torture_tcase_add_simple_test(tcase, "DsBind_W2K8", (run_func)test_DsBind_w2k8); + torture_tcase_add_simple_test(tcase, "DsGetDomainControllerInfo_W2K8", (run_func)test_DsGetDomainControllerInfo_w2k8); +} diff --git a/source4/torture/rpc/rpc.c b/source4/torture/rpc/rpc.c index 46a9e56..e41f726 100644 --- a/source4/torture/rpc/rpc.c +++ b/source4/torture/rpc/rpc.c @@ -530,6 +530,7 @@ NTSTATUS torture_rpc_init(void) torture_suite_add_simple_test(suite, "authcontext", torture_bind_authcontext); torture_suite_add_suite(suite, torture_rpc_samba3(suite)); torture_rpc_drsuapi_tcase(suite); + torture_rpc_drsuapi_w2k8_tcase(suite); torture_rpc_drsuapi_cracknames_tcase(suite); torture_suite_add_suite(suite, torture_rpc_dssetup(suite)); torture_suite_add_suite(suite, torture_rpc_browser(suite)); diff --git a/source4/torture/wscript_build b/source4/torture/wscript_build index 8966026..fcc442d 100755 --- a/source4/torture/wscript_build +++ b/source4/torture/wscript_build @@ -83,6 +83,7 @@ bld.SAMBA_MODULE('torture_rpc', rpc/echo.c rpc/dfs.c rpc/drsuapi.c + rpc/drsuapi_w2k8.c rpc/drsuapi_cracknames.c rpc/dsgetinfo.c rpc/spoolss.c -- 2.7.4 >From c4ace0e6c9f6d0d898a0f7679fc8b38811e5643e Mon Sep 17 00:00:00 2001 From: Dirk Godau Date: Wed, 25 May 2016 11:49:24 +1200 Subject: [PATCH 2/2] Extend DsBind and DsGetDomainControllerInfo to work with w2k8. W2K8 Clients ask for DRSUAPI_SUPPORTED_EXTENSION_LH_BETA2 on DsBind. W2K8 expect this to be set (with server fl 2k8) or else they do not call DsGetDomainControllerInfo. If DRSUAPI_SUPPORTED_EXTENSION_LH_BETA2 is set, DsGetDomainControllerInfo must be able to return DCInfo Level 3. If Samba4 AD ist set to work as 2k8, with >2k8 clients the following will not work as expected: * Group Policy Editor Infrastructure Discovery * nltest /dclist: * w32tm /monitor BUG: https://bugzilla.samba.org/show_bug.cgi?id=9971 BUG: https://bugzilla.samba.org/show_bug.cgi?id=9976 Signed-off-by: Dirk Godau Reviewed-by: Douglas Bagnall Reviewed-by: Garming Sam --- selftest/knownfail | 1 - source4/rpc_server/drsuapi/dcesrv_drsuapi.c | 266 ++++++++++++++++++++++------ source4/rpc_server/drsuapi/dcesrv_drsuapi.h | 4 +- 3 files changed, 210 insertions(+), 61 deletions(-) diff --git a/selftest/knownfail b/selftest/knownfail index 641730c..2f2d6bf 100644 --- a/selftest/knownfail +++ b/selftest/knownfail @@ -330,4 +330,3 @@ # ad_dc requires signing # ^samba4.smb.signing.*disabled.*signing=off.*\(ad_dc\) -^samba4.rpc.drsuapi_w2k8.*DsGetDomainControllerInfo_W2K8 diff --git a/source4/rpc_server/drsuapi/dcesrv_drsuapi.c b/source4/rpc_server/drsuapi/dcesrv_drsuapi.c index 3fe6c13..949dea8 100644 --- a/source4/rpc_server/drsuapi/dcesrv_drsuapi.c +++ b/source4/rpc_server/drsuapi/dcesrv_drsuapi.c @@ -56,15 +56,19 @@ static WERROR dcesrv_drsuapi_DsBind(struct dcesrv_call_state *dce_call, TALLOC_C struct drsuapi_bind_state *b_state; struct dcesrv_handle *handle; struct drsuapi_DsBindInfoCtr *bind_info; - struct GUID site_guid; - struct ldb_result *site_res; - struct ldb_dn *server_site_dn; + struct drsuapi_DsBindInfoCtr *local_info; + struct GUID site_guid, config_guid; + struct ldb_result *site_res, *config_res; + struct ldb_dn *server_site_dn, *config_dn; static const char *site_attrs[] = { "objectGUID", NULL }; + static const char *config_attrs[] = { "objectGUID", NULL }; struct ldb_result *ntds_res; struct ldb_dn *ntds_dn; static const char *ntds_attrs[] = { "ms-DS-ReplicationEpoch", NULL }; uint32_t pid; uint32_t repl_epoch; + uint32_t supported_extensions; + uint32_t req_length; int ret; struct auth_session_info *auth_info; WERROR werr; @@ -166,73 +170,112 @@ static WERROR dcesrv_drsuapi_DsBind(struct dcesrv_call_state *dce_call, TALLOC_C * store the clients bind_info */ if (r->in.bind_info) { - switch (r->in.bind_info->length) { - case 24: { - struct drsuapi_DsBindInfo24 *info24; - info24 = &r->in.bind_info->info.info24; - b_state->remote_info28.supported_extensions = info24->supported_extensions; - b_state->remote_info28.site_guid = info24->site_guid; - b_state->remote_info28.pid = info24->pid; - b_state->remote_info28.repl_epoch = 0; - break; - } - case 28: - b_state->remote_info28 = r->in.bind_info->info.info28; - break; - } + b_state->remote_info = r->in.bind_info; } /* - * fill in our local bind info 28 + * fill in our local bind info + */ + local_info = talloc_zero(mem_ctx, struct drsuapi_DsBindInfoCtr); + W_ERROR_HAVE_NO_MEMORY(local_info); + + /* + * Fill in supported extensions */ - b_state->local_info28.supported_extensions = 0; - b_state->local_info28.supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_BASE; - b_state->local_info28.supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_ASYNC_REPLICATION; - b_state->local_info28.supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_REMOVEAPI; - b_state->local_info28.supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_MOVEREQ_V2; + supported_extensions = 0; + supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_BASE; + supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_ASYNC_REPLICATION; + supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_REMOVEAPI; + supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_MOVEREQ_V2; #if 0 /* we don't support MSZIP compression (only decompression) */ - b_state->local_info28.supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_GETCHG_COMPRESS; + supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_GETCHG_COMPRESS; #endif - b_state->local_info28.supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_DCINFO_V1; - b_state->local_info28.supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_RESTORE_USN_OPTIMIZATION; - b_state->local_info28.supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_KCC_EXECUTE; - b_state->local_info28.supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_ADDENTRY_V2; - b_state->local_info28.supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_LINKED_VALUE_REPLICATION; - b_state->local_info28.supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_DCINFO_V2; - b_state->local_info28.supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_INSTANCE_TYPE_NOT_REQ_ON_MOD; - b_state->local_info28.supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_CRYPTO_BIND; - b_state->local_info28.supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_GET_REPL_INFO; - b_state->local_info28.supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_STRONG_ENCRYPTION; - b_state->local_info28.supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_DCINFO_V01; - b_state->local_info28.supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_TRANSITIVE_MEMBERSHIP; - b_state->local_info28.supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_ADD_SID_HISTORY; - b_state->local_info28.supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_POST_BETA3; - b_state->local_info28.supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_GETCHGREQ_V5; - b_state->local_info28.supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_GET_MEMBERSHIPS2; - b_state->local_info28.supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_GETCHGREQ_V6; - b_state->local_info28.supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_NONDOMAIN_NCS; - b_state->local_info28.supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_GETCHGREQ_V8; - b_state->local_info28.supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_GETCHGREPLY_V5; - b_state->local_info28.supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_GETCHGREPLY_V6; - b_state->local_info28.supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_ADDENTRYREPLY_V3; - b_state->local_info28.supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_GETCHGREPLY_V7; - b_state->local_info28.supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_VERIFY_OBJECT; + supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_DCINFO_V1; + supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_RESTORE_USN_OPTIMIZATION; + supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_KCC_EXECUTE; + supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_ADDENTRY_V2; + supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_LINKED_VALUE_REPLICATION; + supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_DCINFO_V2; + supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_INSTANCE_TYPE_NOT_REQ_ON_MOD; + supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_CRYPTO_BIND; + supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_GET_REPL_INFO; + supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_STRONG_ENCRYPTION; + supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_DCINFO_V01; + supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_TRANSITIVE_MEMBERSHIP; + supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_ADD_SID_HISTORY; + supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_POST_BETA3; + supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_GETCHGREQ_V5; + supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_GET_MEMBERSHIPS2; + supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_GETCHGREQ_V6; + supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_NONDOMAIN_NCS; + supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_GETCHGREQ_V8; + supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_GETCHGREPLY_V5; + supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_GETCHGREPLY_V6; + supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_ADDENTRYREPLY_V3; + supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_GETCHGREPLY_V7; + supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_VERIFY_OBJECT; #if 0 /* we don't support XPRESS compression yet */ - b_state->local_info28.supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_XPRESS_COMPRESS; + supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_XPRESS_COMPRESS; #endif - b_state->local_info28.supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_GETCHGREQ_V10; - b_state->local_info28.site_guid = site_guid; - b_state->local_info28.pid = pid; - b_state->local_info28.repl_epoch = repl_epoch; + supported_extensions |= DRSUAPI_SUPPORTED_EXTENSION_GETCHGREQ_V10; + + /* + * There is a chance for r->in.bind_info == NULL + * Currently we don't care, since it seems to be used nowhere else. + * But we need a request length. So use 28 as default. + */ + req_length = 28; + if (r->in.bind_info) { + req_length = r->in.bind_info->length; + } + + /* + * fill 28 or 48 info, depends on request + */ + if (req_length < 48) { + local_info->length = 28; + local_info->info.info28.supported_extensions = supported_extensions; + local_info->info.info28.site_guid = site_guid; + local_info->info.info28.pid = pid; + local_info->info.info28.repl_epoch = repl_epoch; + } else { + local_info->length = 48; + local_info->info.info48.supported_extensions = supported_extensions; + local_info->info.info48.site_guid = site_guid; + local_info->info.info48.pid = pid; + local_info->info.info48.repl_epoch = repl_epoch; + + local_info->info.info48.supported_extensions_ext = 0; + local_info->info.info48.supported_extensions_ext |= DRSUAPI_SUPPORTED_EXTENSION_LH_BETA2; + + /* + * find out the guid of our own site + */ + config_dn = ldb_get_config_basedn(b_state->sam_ctx); + W_ERROR_HAVE_NO_MEMORY(config_dn); + + ret = ldb_search(b_state->sam_ctx, mem_ctx, &config_res, + config_dn, LDB_SCOPE_BASE, config_attrs, + "(objectClass=*)"); + if (ret != LDB_SUCCESS) { + return WERR_DS_DRA_INTERNAL_ERROR; + } + if (config_res->count != 1) { + return WERR_DS_DRA_INTERNAL_ERROR; + } + config_guid = samdb_result_guid(config_res->msgs[0], "objectGUID"); + local_info->info.info48.config_dn_guid = config_guid; + } /* - * allocate the return bind_info + * set local_info */ - bind_info = talloc_zero(mem_ctx, struct drsuapi_DsBindInfoCtr); - W_ERROR_HAVE_NO_MEMORY(bind_info); + b_state->local_info = local_info; - bind_info->length = 28; - bind_info->info.info28 = b_state->local_info28; + /* + * set bind_info + */ + bind_info = local_info; /* * allocate a bind handle @@ -580,6 +623,7 @@ static WERROR dcesrv_drsuapi_DsGetDomainControllerInfo_1(struct drsuapi_bind_sta struct drsuapi_DsGetDCInfoCtr1 *ctr1; struct drsuapi_DsGetDCInfoCtr2 *ctr2; + struct drsuapi_DsGetDCInfoCtr3 *ctr3; int ret; unsigned int i; @@ -596,6 +640,7 @@ static WERROR dcesrv_drsuapi_DsGetDomainControllerInfo_1(struct drsuapi_bind_sta attrs = attrs_1; break; case 2: + case 3: attrs = attrs_2; break; default: @@ -781,6 +826,111 @@ static WERROR dcesrv_drsuapi_DsGetDomainControllerInfo_1(struct drsuapi_bind_sta } break; + case 3: + ctr3 = &r->out.ctr->ctr3; + ctr3->count = res->count; + ctr3->array = talloc_zero_array(mem_ctx, + struct drsuapi_DsGetDCInfo3, + res->count); + for (i=0; icount; i++) { + struct ldb_dn *domain_dn; + struct ldb_result *res_domain; + struct ldb_result *res_account; + struct ldb_dn *ntds_dn = ldb_dn_copy(mem_ctx, res->msgs[i]->dn); + struct ldb_result *res_ntds; + struct ldb_dn *site_dn = ldb_dn_copy(mem_ctx, res->msgs[i]->dn); + struct ldb_result *res_site; + bool is_rodc; + struct ldb_dn *ref_dn + = ldb_msg_find_attr_as_dn(b_state->sam_ctx, + mem_ctx, res->msgs[i], + "serverReference"); + + if (!ntds_dn || !ldb_dn_add_child_fmt(ntds_dn, "CN=NTDS Settings")) { + return WERR_NOMEM; + } + + /* Format is cn=,cn=Servers,cn=,cn=sites.... */ + if (!site_dn || !ldb_dn_remove_child_components(site_dn, 2)) { + return WERR_NOMEM; + } + + ret = ldb_search(b_state->sam_ctx, mem_ctx, &res_ntds, ntds_dn, + LDB_SCOPE_BASE, attrs_ntds, "objectClass=nTDSDSA"); + if (ret == LDB_SUCCESS && res_ntds->count == 1) { + ctr3->array[i].is_gc + = (ldb_msg_find_attr_as_uint(res_ntds->msgs[0], "options", 0) & DS_NTDSDSA_OPT_IS_GC); + ctr3->array[i].ntds_guid + = samdb_result_guid(res_ntds->msgs[0], "objectGUID"); + ctr3->array[i].ntds_dn = ldb_dn_get_linearized(res_ntds->msgs[0]->dn); + } + if ((ret != LDB_SUCCESS) && (ret != LDB_ERR_NO_SUCH_OBJECT)) { + DEBUG(5, ("warning: searching for NTDS DN %s failed: %s\n", + ldb_dn_get_linearized(ntds_dn), ldb_errstring(b_state->sam_ctx))); + } + + ret = ldb_search(b_state->sam_ctx, mem_ctx, &res_site, site_dn, + LDB_SCOPE_BASE, attrs_site, "objectClass=site"); + if (ret == LDB_SUCCESS && res_site->count == 1) { + ctr3->array[i].site_guid + = samdb_result_guid(res_site->msgs[0], "objectGUID"); + ctr3->array[i].site_dn = ldb_dn_get_linearized(res_site->msgs[0]->dn); + } + if ((ret != LDB_SUCCESS) && (ret != LDB_ERR_NO_SUCH_OBJECT)) { + DEBUG(5, ("warning: searching for site DN %s failed: %s\n", + ldb_dn_get_linearized(site_dn), ldb_errstring(b_state->sam_ctx))); + } + + ret = ldb_search(b_state->sam_ctx, mem_ctx, &res_account, ref_dn, + LDB_SCOPE_BASE, attrs_account_2, "objectClass=computer"); + if (ret == LDB_SUCCESS && res_account->count == 1) { + const char *errstr; + ctr3->array[i].dns_name + = ldb_msg_find_attr_as_string(res_account->msgs[0], "dNSHostName", NULL); + ctr3->array[i].netbios_name + = ldb_msg_find_attr_as_string(res_account->msgs[0], "cn", NULL); + ctr3->array[i].computer_dn = ldb_dn_get_linearized(res_account->msgs[0]->dn); + ctr3->array[i].computer_guid + = samdb_result_guid(res_account->msgs[0], "objectGUID"); + + /* Determine if this is the PDC */ + ret = samdb_search_for_parent_domain(b_state->sam_ctx, + mem_ctx, res_account->msgs[0]->dn, + &domain_dn, &errstr); + + if (ret == LDB_SUCCESS) { + ret = ldb_search(b_state->sam_ctx, mem_ctx, &res_domain, domain_dn, + LDB_SCOPE_BASE, attrs_none, "fSMORoleOwner=%s", + ldb_dn_get_linearized(ntds_dn)); + if (ret == LDB_SUCCESS && res_domain->count == 1) { + ctr3->array[i].is_pdc = true; + } + if ((ret != LDB_SUCCESS) && (ret != LDB_ERR_NO_SUCH_OBJECT)) { + DEBUG(5, ("warning: searching for domain DN %s failed: %s\n", + ldb_dn_get_linearized(domain_dn), ldb_errstring(b_state->sam_ctx))); + } + } + } + if ((ret != LDB_SUCCESS) && (ret != LDB_ERR_NO_SUCH_OBJECT)) { + DEBUG(5, ("warning: searching for computer account DN %s failed: %s\n", + ldb_dn_get_linearized(ref_dn), ldb_errstring(b_state->sam_ctx))); + } + + /* Look at server DN and extract site component */ + ctr3->array[i].site_name = result_site_name(res->msgs[i]->dn); + ctr3->array[i].server_dn = ldb_dn_get_linearized(res->msgs[i]->dn); + ctr3->array[i].server_guid + = samdb_result_guid(res->msgs[i], "objectGUID"); + + ctr3->array[i].is_enabled = true; + + /* rodc? */ + ret = samdb_is_rodc(b_state->sam_ctx, &ctr3->array[i].server_guid, &is_rodc); + if (ret == LDB_SUCCESS && is_rodc) { + ctr3->array[i].is_rodc = true; + } + } + break; default: return WERR_UNKNOWN_LEVEL; } diff --git a/source4/rpc_server/drsuapi/dcesrv_drsuapi.h b/source4/rpc_server/drsuapi/dcesrv_drsuapi.h index 49d1d42..d376f7e 100644 --- a/source4/rpc_server/drsuapi/dcesrv_drsuapi.h +++ b/source4/rpc_server/drsuapi/dcesrv_drsuapi.h @@ -33,8 +33,8 @@ struct drsuapi_bind_state { struct ldb_context *sam_ctx; struct ldb_context *sam_ctx_system; struct GUID remote_bind_guid; - struct drsuapi_DsBindInfo28 remote_info28; - struct drsuapi_DsBindInfo28 local_info28; + struct drsuapi_DsBindInfoCtr *remote_info; + struct drsuapi_DsBindInfoCtr *local_info; struct drsuapi_getncchanges_state *getncchanges_state; }; -- 2.7.4