From 2ff09f6df096263851b51efe9123bdc37380eccf Mon Sep 17 00:00:00 2001 From: Garming Sam Date: Mon, 20 Mar 2017 17:04:12 +1300 Subject: [PATCH] winbindd_cm: Add new parameter to getdc and find_new_dc calls This is to enforce the requirements on the remote DC. Signed-off-by: Garming Sam Reviewed-by: Andrew Bartlett --- source3/winbindd/winbindd_cm.c | 31 ++++++++++++++++++++----------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/source3/winbindd/winbindd_cm.c b/source3/winbindd/winbindd_cm.c index 3f47ff9cd08..c65fe1ca0f0 100644 --- a/source3/winbindd/winbindd_cm.c +++ b/source3/winbindd/winbindd_cm.c @@ -99,7 +99,8 @@ static NTSTATUS init_dc_connection_network(struct winbindd_domain *domain, bool static void set_dc_type_and_flags( struct winbindd_domain *domain ); static bool set_dc_type_and_flags_trustinfo( struct winbindd_domain *domain ); static bool get_dcs(TALLOC_CTX *mem_ctx, struct winbindd_domain *domain, - struct dc_name_ip **dcs, int *num_dcs); + struct dc_name_ip **dcs, int *num_dcs, + uint32_t request_flags); /**************************************************************** Child failed to find DC's. Reschedule check. @@ -266,7 +267,7 @@ static bool fork_child_dc_connect(struct winbindd_domain *domain) _exit(1); } - if ((!get_dcs(mem_ctx, domain, &dcs, &num_dcs)) || (num_dcs == 0)) { + if ((!get_dcs(mem_ctx, domain, &dcs, &num_dcs, 0)) || (num_dcs == 0)) { /* Still offline ? Can't find DC's. */ messaging_send_buf(winbind_messaging_context(), pid_to_procid(parent_pid), @@ -769,7 +770,8 @@ static bool cm_is_ipc_credentials(struct cli_credentials *creds) static bool get_dc_name_via_netlogon(struct winbindd_domain *domain, fstring dcname, - struct sockaddr_storage *dc_ss) + struct sockaddr_storage *dc_ss, + uint32_t request_flags) { struct winbindd_domain *our_domain = NULL; struct rpc_pipe_client *netlogon_pipe = NULL; @@ -814,13 +816,17 @@ static bool get_dc_name_via_netlogon(struct winbindd_domain *domain, if (our_domain->active_directory) { struct netr_DsRGetDCNameInfo *domain_info = NULL; + /* + * TODO request flags are not respected in the server + * (and in some cases, like REQUIRE_PDC, causes an error) + */ result = dcerpc_netr_DsRGetDCName(b, mem_ctx, our_domain->dcname, domain->name, NULL, NULL, - DS_RETURN_DNS_NAME, + request_flags|DS_RETURN_DNS_NAME, &domain_info, &werr); if (NT_STATUS_IS_OK(result) && W_ERROR_IS_OK(werr)) { @@ -1456,7 +1462,8 @@ static bool dcip_to_name(TALLOC_CTX *mem_ctx, *******************************************************************/ static bool get_dcs(TALLOC_CTX *mem_ctx, struct winbindd_domain *domain, - struct dc_name_ip **dcs, int *num_dcs) + struct dc_name_ip **dcs, int *num_dcs, + uint32_t request_flags) { fstring dcname; struct sockaddr_storage ss; @@ -1470,7 +1477,7 @@ static bool get_dcs(TALLOC_CTX *mem_ctx, struct winbindd_domain *domain, /* If not our domain, get the preferred DC, by asking our primary DC */ if ( !is_our_domain - && get_dc_name_via_netlogon(domain, dcname, &ss) + && get_dc_name_via_netlogon(domain, dcname, &ss, request_flags) && add_one_dc_unique(mem_ctx, domain->name, dcname, &ss, dcs, num_dcs) ) { @@ -1587,7 +1594,8 @@ static bool get_dcs(TALLOC_CTX *mem_ctx, struct winbindd_domain *domain, static bool find_new_dc(TALLOC_CTX *mem_ctx, struct winbindd_domain *domain, - char **dcname, struct sockaddr_storage *pss, int *fd) + char **dcname, struct sockaddr_storage *pss, int *fd, + uint32_t request_flags) { struct dc_name_ip *dcs = NULL; int num_dcs = 0; @@ -1606,7 +1614,7 @@ static bool find_new_dc(TALLOC_CTX *mem_ctx, *fd = -1; again: - if (!get_dcs(mem_ctx, domain, &dcs, &num_dcs) || (num_dcs == 0)) + if (!get_dcs(mem_ctx, domain, &dcs, &num_dcs, request_flags) || (num_dcs == 0)) return False; for (i=0; idcname = talloc_strdup(domain, dcname); if (domain->dcname == NULL) { @@ -1888,7 +1897,7 @@ static NTSTATUS cm_open_connection(struct winbindd_domain *domain, } if ((fd == -1) && - !find_new_dc(mem_ctx, domain, &dcname, &domain->dcaddr, &fd)) + !find_new_dc(mem_ctx, domain, &dcname, &domain->dcaddr, &fd, request_flags)) { /* This is the one place where we will set the global winbindd offline state -- 2.47.2