wb-ndr: implement WINBIND_DC_INFO_LEVEL_COMPAT_DS in the locator child
authorStefan Metzmacher <metze@sernet.de>
Fri, 7 Dec 2007 18:04:57 +0000 (19:04 +0100)
committerStefan Metzmacher <metze@sernet.de>
Fri, 2 May 2008 14:12:32 +0000 (16:12 +0200)
metze

source/winbindd/winbindd_locator.c

index 10a6c5afeb8d546f961163dbd2fe4de0514b015e..f1eebab612c211093e02c51c6016aba5695f368a 100644 (file)
@@ -94,11 +94,82 @@ static enum winbindd_result dual_dsgetdcname(struct winbindd_domain *domain,
        return WINBINDD_OK;
 }
 
+static void ndr_child_get_dc_info_comapt_ds(struct winbindd_domain *domain,
+                                           struct winbindd_cli_state *state,
+                                           struct winbind_get_dc_info *r)
+{
+       NTSTATUS result;
+       struct DS_DOMAIN_CONTROLLER_INFO *info = NULL;
+       const char *dc = NULL;
+
+       DEBUG(3, ("dsgetdcname for '%s'\n", r->in.domain_name));
+
+       result = dsgetdcname(state->mem_ctx, r->in.domain_name,
+                            NULL, NULL, r->in.params.flags, &info);
+       if (!NT_STATUS_IS_OK(result)) {
+               DEBUG(1, ("dsgetdcname failed: %s\n", nt_errstr(result)));
+               r->out.result = WINBIND_STATUS_FOOBAR;
+               return;
+       }
+
+       if (info->domain_controller_address) {
+               dc = info->domain_controller_address;
+               if ((dc[0] == '\\') && (dc[1] == '\\')) {
+                       dc += 2;
+               }
+       }
+
+       if ((!dc || !is_ipaddress_v4(dc)) && info->domain_controller_name) {
+               dc = info->domain_controller_name;
+       }
+
+       if (!dc || !*dc) {
+               TALLOC_FREE(info);
+               DEBUG(1, ("DsGetDcName failed: no dc name\n"));
+               r->out.result = WINBIND_STATUS_FOOBAR;
+               return;
+       }
+
+       r->out.dc_info->name = talloc_strdup(r, dc);
+       TALLOC_FREE(info);
+       if (!r->out.dc_info->name) {
+               r->out.result = WINBIND_STATUS_NO_MEMORY;
+               return;
+       }
+       r->out.result = WINBIND_STATUS_OK;
+}
+
+void winbindd_ndr_locator_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:
+               r->out.result = WINBIND_STATUS_INVALID_LEVEL;
+               return;
+
+       case WINBIND_DC_INFO_LEVEL_COMPAT_DS:
+               ndr_child_get_dc_info_comapt_ds(domain, state, r);
+               return;
+       }
+
+       r->out.result = WINBIND_STATUS_UNKNOWN_LEVEL;
+       return;
+}
+
 static const struct winbindd_child_dispatch_table locator_dispatch_table[] = {
        {
                .name           = "DSGETDCNAME",
                .struct_cmd     = WINBINDD_DSGETDCNAME,
                .struct_fn      = dual_dsgetdcname,
+       },{
+               .name           = "NDR_WINBIND_GET_DC_INFO",
+               .ndr_opnum      = NDR_WINBIND_GET_DC_INFO,
+               .ndr_fn         = winbindd_ndr_locator_child_get_dc_info,
        },{
                .name           = NULL,
        }