wb-ndr: implement winbindd_ndr_child_get_dc_info() with DC_INFO_LEVEL_COMPAT_NT4
authorStefan Metzmacher <metze@sernet.de>
Sun, 23 Dec 2007 15:39:58 +0000 (16:39 +0100)
committerStefan Metzmacher <metze@sernet.de>
Fri, 2 May 2008 14:12:28 +0000 (16:12 +0200)
metze

source/winbindd/winbindd_domain.c
source/winbindd/winbindd_misc.c

index 10ba1a4d0046eb1ae22d4a72c87df8ae2a65373d..04bbef3d205ccfd006d86e754d0df4b00ca584df 100644 (file)
@@ -109,6 +109,10 @@ static const struct winbindd_child_dispatch_table domain_dispatch_table[] = {
                .name           = "NDR_WINBIND_GET_DOMAIN_INFO",
                .ndr_opnum      = NDR_WINBIND_GET_DOMAIN_INFO,
                .ndr_fn         = winbindd_ndr_child_get_domain_info,
+       },{
+               .name           = "NDR_WINBIND_GET_DC_INFO",
+               .ndr_opnum      = NDR_WINBIND_GET_DC_INFO,
+               .ndr_fn         = winbindd_ndr_domain_child_get_dc_info,
        },{
                .name           = NULL,
        }
index f63aa1689044770e7cf79323b53aadd8a6f6b6c2..5732ad0dd993602b8804bc60b482d6af9be16398 100644 (file)
@@ -388,6 +388,109 @@ enum winbindd_result winbindd_dual_getdcname(struct winbindd_domain *domain,
        return WINBINDD_OK;
 }
 
+static void ndr_child_get_dc_info_comapt_nt4(struct winbindd_domain *domain,
+                                            struct winbindd_cli_state *state,
+                                            struct winbind_get_dc_info *r)
+{
+       const char *dcname_slash;
+       const char *p;
+       struct rpc_pipe_client *netlogon_pipe;
+       NTSTATUS result;
+       WERROR werr;
+       unsigned int orig_timeout;
+       struct winbindd_domain *req_domain;
+
+       DEBUG(3, ("Get DC name for '%s'\n", r->in.domain_name));
+
+       result = cm_connect_netlogon(domain, &netlogon_pipe);
+
+       if (!NT_STATUS_IS_OK(result)) {
+               DEBUG(1, ("Can't contact the NETLOGON pipe\n"));
+               r->out.result = WINBIND_STATUS_FOOBAR;
+               return;
+       }
+
+       /* This call can take a long time - allow the server to time out.
+          35 seconds should do it. */
+
+       orig_timeout = cli_set_timeout(netlogon_pipe->cli, 35000);
+
+       /*
+        * if the requested domain name matches the current one
+        * we need to use GetDCName(), because GetAnyDCName() only
+        * works for trusted domains
+        */
+       req_domain = find_domain_from_name_noinit(r->in.domain_name);
+       if (req_domain == domain) {
+               result = rpccli_netr_GetDcName(netlogon_pipe,
+                                              r,
+                                              domain->dcname,
+                                              r->in.domain_name,
+                                              &dcname_slash,
+                                              &werr);
+       } else {
+               result = rpccli_netr_GetAnyDCName(netlogon_pipe,
+                                                 r,
+                                                 domain->dcname,
+                                                 r->in.domain_name,
+                                                 &dcname_slash,
+                                                 &werr);
+       }
+       /* And restore our original timeout. */
+       cli_set_timeout(netlogon_pipe->cli, orig_timeout);
+
+       if (!NT_STATUS_IS_OK(result)) {
+               DEBUG(5,("Error requesting DCname for domain %s: %s\n",
+                       r->in.domain_name, nt_errstr(result)));
+               r->out.result = WINBIND_STATUS_FOOBAR;
+               return;
+       }
+
+       if (!W_ERROR_IS_OK(werr)) {
+               DEBUG(5, ("Error requesting DCname for domain %s: %s\n",
+                       r->in.domain_name, dos_errstr(werr)));
+               r->out.result = WINBIND_STATUS_FOOBAR;
+               return;
+       }
+
+       p = dcname_slash;
+       if (*p == '\\') {
+               p+=1;
+       }
+       if (*p == '\\') {
+               p+=1;
+       }
+
+       r->out.dc_info->name = talloc_strdup(r, p);
+       if (!r->out.dc_info->name) {
+               r->out.result = WINBIND_STATUS_NO_MEMORY;
+               return;
+       }
+       r->out.result = WINBIND_STATUS_OK;
+}
+
+void winbindd_ndr_domain_child_get_dc_info(struct winbindd_domain *domain,
+                                          struct winbindd_cli_state *state)
+{
+       struct winbind_get_dc_info *r;
+
+       r = talloc_get_type_abort(state->c.ndr.r,
+                                 struct winbind_get_dc_info);
+
+       switch (*r->in.level) {
+       case WINBIND_DC_INFO_LEVEL_COMPAT_NT4:
+               ndr_child_get_dc_info_comapt_nt4(domain, state, r);
+               return;
+
+       case WINBIND_DC_INFO_LEVEL_COMPAT_DS:
+               r->out.result = WINBIND_STATUS_INVALID_LEVEL;
+               return;
+       }
+
+       r->out.result = WINBIND_STATUS_UNKNOWN_LEVEL;
+       return;
+}
+
 struct sequence_state {
        TALLOC_CTX *mem_ctx;
        struct winbindd_cli_state *cli_state;