s3:winbind: Convert winbindd_dsgetdcname to the new API
authorVolker Lendecke <vl@samba.org>
Tue, 25 Aug 2009 21:02:44 +0000 (23:02 +0200)
committerVolker Lendecke <vl@samba.org>
Sat, 29 Aug 2009 17:42:26 +0000 (19:42 +0200)
source3/Makefile.in
source3/winbindd/winbindd.c
source3/winbindd/winbindd_dsgetdcname.c [new file with mode: 0644]
source3/winbindd/winbindd_locator.c
source3/winbindd/winbindd_proto.h

index 2aa8e37ddbbf2cca6889239c9f8ef9e3f7e3ee1d..7a07350876a894626685e9f00f7ce193023f258f 100644 (file)
@@ -1201,6 +1201,7 @@ WINBINDD_OBJ1 = \
                winbindd/winbindd_setpwent.o \
                winbindd/winbindd_getpwent.o \
                winbindd/winbindd_endpwent.o \
+               winbindd/winbindd_dsgetdcname.o \
                auth/token_util.o \
                ../nsswitch/libwbclient/wb_reqtrans.o \
                smbd/connection.o
index 85203fbed0c463eeaa9aa3709774d5364741f975..6485f1734c28a0c7381e5c9154c0c7f1811fe047 100644 (file)
@@ -471,7 +471,6 @@ static struct winbindd_dispatch_table {
        { WINBINDD_PRIV_PIPE_DIR, winbindd_priv_pipe_dir,
          "WINBINDD_PRIV_PIPE_DIR" },
        { WINBINDD_GETDCNAME, winbindd_getdcname, "GETDCNAME" },
-       { WINBINDD_DSGETDCNAME, winbindd_dsgetdcname, "DSGETDCNAME" },
 
        /* Credential cache access */
        { WINBINDD_CCACHE_NTLMAUTH, winbindd_ccache_ntlm_auth, "NTLMAUTH" },
@@ -538,6 +537,8 @@ static struct winbindd_async_dispatch_table async_nonpriv_table[] = {
          winbindd_getpwent_send, winbindd_getpwent_recv },
        { WINBINDD_ENDPWENT, "ENDPWENT",
          winbindd_endpwent_send, winbindd_endpwent_recv },
+       { WINBINDD_DSGETDCNAME, "DSGETDCNAME",
+         winbindd_dsgetdcname_send, winbindd_dsgetdcname_recv },
 
        { 0, NULL, NULL, NULL }
 };
diff --git a/source3/winbindd/winbindd_dsgetdcname.c b/source3/winbindd/winbindd_dsgetdcname.c
new file mode 100644 (file)
index 0000000..2c475d8
--- /dev/null
@@ -0,0 +1,198 @@
+/*
+   Unix SMB/CIFS implementation.
+   async implementation of WINBINDD_DSGETDCNAME
+   Copyright (C) Volker Lendecke 2009
+
+   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 <http://www.gnu.org/licenses/>.
+*/
+
+#include "includes.h"
+#include "winbindd.h"
+#include "librpc/gen_ndr/cli_wbint.h"
+
+struct winbindd_dsgetdcname_state {
+       struct GUID guid;
+       struct netr_DsRGetDCNameInfo *dc_info;
+};
+
+static uint32_t get_dsgetdc_flags(uint32_t wbc_flags);
+static void winbindd_dsgetdcname_done(struct tevent_req *subreq);
+
+struct tevent_req *winbindd_dsgetdcname_send(TALLOC_CTX *mem_ctx,
+                                            struct tevent_context *ev,
+                                            struct winbindd_cli_state *cli,
+                                            struct winbindd_request *request)
+{
+       struct tevent_req *req, *subreq;
+       struct winbindd_child *child;
+       struct winbindd_dsgetdcname_state *state;
+       struct GUID *guid_ptr = NULL;
+       uint32_t ds_flags = 0;
+       NTSTATUS status;
+
+       req = tevent_req_create(mem_ctx, &state,
+                               struct winbindd_dsgetdcname_state);
+       if (req == NULL) {
+               return NULL;
+       }
+
+       request->data.dsgetdcname.domain_name
+               [sizeof(request->data.dsgetdcname.domain_name)-1] = '\0';
+       request->data.dsgetdcname.site_name
+               [sizeof(request->data.dsgetdcname.site_name)-1] = '\0';
+       request->data.dsgetdcname.domain_guid
+               [sizeof(request->data.dsgetdcname.domain_guid)-1] = '\0';
+
+       DEBUG(3, ("[%5lu]: dsgetdcname for %s\n", (unsigned long)cli->pid,
+                 request->data.dsgetdcname.domain_name));
+
+       ds_flags = get_dsgetdc_flags(request->flags);
+
+       status = GUID_from_string(request->data.dsgetdcname.domain_guid,
+                                 &state->guid);
+       if (NT_STATUS_IS_OK(status) && !GUID_all_zero(&state->guid)) {
+               guid_ptr = &state->guid;
+       }
+
+       child = locator_child();
+
+       subreq = rpccli_wbint_DsGetDcName_send(
+               state, ev, child->rpccli,
+               request->data.dsgetdcname.domain_name, guid_ptr,
+               request->data.dsgetdcname.site_name,
+               ds_flags, &state->dc_info);
+       if (tevent_req_nomem(subreq, req)) {
+               return tevent_req_post(req, ev);
+       }
+       tevent_req_set_callback(subreq, winbindd_dsgetdcname_done, req);
+       return req;
+}
+
+static void winbindd_dsgetdcname_done(struct tevent_req *subreq)
+{
+       struct tevent_req *req = tevent_req_callback_data(
+               subreq, struct tevent_req);
+       struct winbindd_dsgetdcname_state *state = tevent_req_data(
+               req, struct winbindd_dsgetdcname_state);
+       NTSTATUS status, result;
+
+       status = rpccli_wbint_DsGetDcName_recv(subreq, state, &result);
+       TALLOC_FREE(subreq);
+       if (!NT_STATUS_IS_OK(status)) {
+               tevent_req_nterror(req, status);
+               return;
+       }
+       if (!NT_STATUS_IS_OK(result)) {
+               tevent_req_nterror(req, result);
+               return;
+       }
+       tevent_req_done(req);
+}
+
+NTSTATUS winbindd_dsgetdcname_recv(struct tevent_req *req,
+                                  struct winbindd_response *response)
+{
+       struct winbindd_dsgetdcname_state *state = tevent_req_data(
+               req, struct winbindd_dsgetdcname_state);
+       char *guid_str;
+       NTSTATUS status;
+
+       if (tevent_req_is_nterror(req, &status)) {
+               DEBUG(5, ("dsgetdcname failed: %s\n", nt_errstr(status)));
+               return status;
+       }
+
+       guid_str = GUID_string(talloc_tos(), &state->dc_info->domain_guid);
+       if (guid_str == NULL) {
+               return NT_STATUS_NO_MEMORY;
+       }
+
+       fstrcpy(response->data.dsgetdcname.dc_unc,
+               state->dc_info->dc_unc);
+       fstrcpy(response->data.dsgetdcname.dc_address,
+               state->dc_info->dc_address);
+       response->data.dsgetdcname.dc_address_type =
+               state->dc_info->dc_address_type;
+       fstrcpy(response->data.dsgetdcname.domain_guid, guid_str);
+       TALLOC_FREE(guid_str);
+       fstrcpy(response->data.dsgetdcname.domain_name,
+               state->dc_info->domain_name);
+       fstrcpy(response->data.dsgetdcname.forest_name,
+               state->dc_info->forest_name);
+       response->data.dsgetdcname.dc_flags = state->dc_info->dc_flags;
+       fstrcpy(response->data.dsgetdcname.dc_site_name,
+               state->dc_info->dc_site_name);
+       fstrcpy(response->data.dsgetdcname.client_site_name,
+               state->dc_info->client_site_name);
+
+       return NT_STATUS_OK;
+}
+
+static uint32_t get_dsgetdc_flags(uint32_t wbc_flags)
+{
+       struct wbc_flag_map {
+               uint32_t wbc_dc_flag;
+               uint32_t ds_dc_flags;
+       } lookup_dc_flags[] = {
+               { WBC_LOOKUP_DC_FORCE_REDISCOVERY,
+                 DS_FORCE_REDISCOVERY },
+               { WBC_LOOKUP_DC_DS_REQUIRED,
+                 DS_DIRECTORY_SERVICE_REQUIRED },
+               { WBC_LOOKUP_DC_DS_PREFERRED,
+                 DS_DIRECTORY_SERVICE_PREFERRED},
+               { WBC_LOOKUP_DC_GC_SERVER_REQUIRED,
+                 DS_GC_SERVER_REQUIRED },
+               { WBC_LOOKUP_DC_PDC_REQUIRED,
+                 DS_PDC_REQUIRED},
+               { WBC_LOOKUP_DC_BACKGROUND_ONLY,
+                 DS_BACKGROUND_ONLY  },
+               { WBC_LOOKUP_DC_IP_REQUIRED,
+                 DS_IP_REQUIRED },
+               { WBC_LOOKUP_DC_KDC_REQUIRED,
+                 DS_KDC_REQUIRED },
+               { WBC_LOOKUP_DC_TIMESERV_REQUIRED,
+                 DS_TIMESERV_REQUIRED },
+               { WBC_LOOKUP_DC_WRITABLE_REQUIRED,
+                 DS_WRITABLE_REQUIRED },
+               { WBC_LOOKUP_DC_GOOD_TIMESERV_PREFERRED,
+                 DS_GOOD_TIMESERV_PREFERRED },
+               { WBC_LOOKUP_DC_AVOID_SELF,
+                 DS_AVOID_SELF },
+               { WBC_LOOKUP_DC_ONLY_LDAP_NEEDED,
+                 DS_ONLY_LDAP_NEEDED },
+               { WBC_LOOKUP_DC_IS_FLAT_NAME,
+                 DS_IS_FLAT_NAME },
+               { WBC_LOOKUP_DC_IS_DNS_NAME,
+                 DS_IS_DNS_NAME },
+               { WBC_LOOKUP_DC_TRY_NEXTCLOSEST_SITE,
+                 DS_TRY_NEXTCLOSEST_SITE },
+               { WBC_LOOKUP_DC_DS_6_REQUIRED,
+                 DS_DIRECTORY_SERVICE_6_REQUIRED },
+               { WBC_LOOKUP_DC_RETURN_DNS_NAME,
+                 DS_RETURN_DNS_NAME },
+               { WBC_LOOKUP_DC_RETURN_FLAT_NAME,
+                 DS_RETURN_FLAT_NAME }
+       };
+
+       uint32_t ds_flags = 0;
+       int i = 0 ;
+
+       for (i=0; i<ARRAY_SIZE(lookup_dc_flags); i++) {
+               if (wbc_flags & lookup_dc_flags[i].wbc_dc_flag) {
+                       ds_flags |= lookup_dc_flags[i].ds_dc_flags;
+               }
+       }
+
+       return ds_flags;
+}
index 5488394976dfeb6f95ef9b120a61c729023edab2..7776c3dc97800c2cecd7e1f87e9dae3ac974698a 100644 (file)
@@ -43,127 +43,11 @@ struct winbindd_child *locator_child(void)
        return &static_locator_child;
 }
 
-void winbindd_dsgetdcname(struct winbindd_cli_state *state)
-{
-       state->request->data.dsgetdcname.domain_name
-               [sizeof(state->request->data.dsgetdcname.domain_name)-1] = '\0';
-       state->request->data.dsgetdcname.site_name
-               [sizeof(state->request->data.dsgetdcname.site_name)-1] = '\0';
-       state->request->data.dsgetdcname.domain_guid
-               [sizeof(state->request->data.dsgetdcname.domain_guid)-1] = '\0';
-
-       DEBUG(3, ("[%5lu]: dsgetdcname for %s\n", (unsigned long)state->pid,
-                 state->request->data.dsgetdcname.domain_name));
-
-       sendto_child(state, locator_child());
-}
-
-struct wbc_flag_map {
-       uint32_t wbc_dc_flag;
-       uint32_t ds_dc_flags;
-};
-
-static uint32_t get_dsgetdc_flags(uint32_t wbc_flags)
-{
-       struct wbc_flag_map lookup_dc_flags[] = {
-               { WBC_LOOKUP_DC_FORCE_REDISCOVERY, DS_FORCE_REDISCOVERY },
-               { WBC_LOOKUP_DC_DS_REQUIRED, DS_DIRECTORY_SERVICE_REQUIRED },
-               { WBC_LOOKUP_DC_DS_PREFERRED, DS_DIRECTORY_SERVICE_PREFERRED},
-               { WBC_LOOKUP_DC_GC_SERVER_REQUIRED, DS_GC_SERVER_REQUIRED },
-               { WBC_LOOKUP_DC_PDC_REQUIRED,  DS_PDC_REQUIRED},
-               { WBC_LOOKUP_DC_BACKGROUND_ONLY, DS_BACKGROUND_ONLY  },
-               { WBC_LOOKUP_DC_IP_REQUIRED, DS_IP_REQUIRED },
-               { WBC_LOOKUP_DC_KDC_REQUIRED, DS_KDC_REQUIRED },
-               { WBC_LOOKUP_DC_TIMESERV_REQUIRED, DS_TIMESERV_REQUIRED },
-               { WBC_LOOKUP_DC_WRITABLE_REQUIRED,  DS_WRITABLE_REQUIRED },
-               { WBC_LOOKUP_DC_GOOD_TIMESERV_PREFERRED, DS_GOOD_TIMESERV_PREFERRED },
-               { WBC_LOOKUP_DC_AVOID_SELF, DS_AVOID_SELF },
-               { WBC_LOOKUP_DC_ONLY_LDAP_NEEDED, DS_ONLY_LDAP_NEEDED },
-               { WBC_LOOKUP_DC_IS_FLAT_NAME, DS_IS_FLAT_NAME },
-               { WBC_LOOKUP_DC_IS_DNS_NAME, DS_IS_DNS_NAME },
-               { WBC_LOOKUP_DC_TRY_NEXTCLOSEST_SITE, DS_TRY_NEXTCLOSEST_SITE },
-               { WBC_LOOKUP_DC_DS_6_REQUIRED, DS_DIRECTORY_SERVICE_6_REQUIRED },
-               { WBC_LOOKUP_DC_RETURN_DNS_NAME, DS_RETURN_DNS_NAME },
-               { WBC_LOOKUP_DC_RETURN_FLAT_NAME, DS_RETURN_FLAT_NAME }
-       };
-       uint32_t ds_flags = 0;
-       int i = 0 ;
-       int num_entries = sizeof(lookup_dc_flags) / sizeof(struct wbc_flag_map);
-
-       for (i=0; i<num_entries; i++) {
-               if (wbc_flags & lookup_dc_flags[i].wbc_dc_flag)
-                       ds_flags |= lookup_dc_flags[i].ds_dc_flags;
-       }
-
-       return ds_flags;
-}
-
-static enum winbindd_result dual_dsgetdcname(struct winbindd_domain *domain,
-                                            struct winbindd_cli_state *state)
-{
-       NTSTATUS result;
-       struct netr_DsRGetDCNameInfo *info = NULL;
-       uint32_t ds_flags = 0;
-       struct GUID guid, *guid_ptr = NULL;
-       const char *guid_str = NULL;
-
-       state->request->data.dsgetdcname.domain_name
-               [sizeof(state->request->data.dsgetdcname.domain_name)-1] = '\0';
-       state->request->data.dsgetdcname.site_name
-               [sizeof(state->request->data.dsgetdcname.site_name)-1] = '\0';
-       state->request->data.dsgetdcname.domain_guid
-               [sizeof(state->request->data.dsgetdcname.domain_guid)-1] = '\0';
-
-       DEBUG(3, ("[%5lu]: dsgetdcname for %s\n", (unsigned long)state->pid,
-                 state->request->data.dsgetdcname.domain_name));
-
-       ds_flags = get_dsgetdc_flags(state->request->flags);
-
-       result = GUID_from_string(state->request->data.dsgetdcname.domain_guid,
-                                 &guid);
-       if (NT_STATUS_IS_OK(result) && !GUID_all_zero(&guid)) {
-               guid_ptr = &guid;
-       }
-
-       result = dsgetdcname(state->mem_ctx,
-                            winbind_messaging_context(),
-                            state->request->data.dsgetdcname.domain_name,
-                            guid_ptr,
-                            state->request->data.dsgetdcname.site_name,
-                            ds_flags,
-                            &info);
-
-       if (!NT_STATUS_IS_OK(result)) {
-               return WINBINDD_ERROR;
-       }
-
-       guid_str = GUID_string(state->mem_ctx, &info->domain_guid);
-       if (!guid_str) {
-               return WINBINDD_ERROR;
-       }
-
-       fstrcpy(state->response->data.dsgetdcname.dc_unc, info->dc_unc);
-       fstrcpy(state->response->data.dsgetdcname.dc_address, info->dc_address);
-       state->response->data.dsgetdcname.dc_address_type = info->dc_address_type;
-       fstrcpy(state->response->data.dsgetdcname.domain_guid, guid_str);
-       fstrcpy(state->response->data.dsgetdcname.domain_name, info->domain_name);
-       fstrcpy(state->response->data.dsgetdcname.forest_name, info->forest_name);
-       state->response->data.dsgetdcname.dc_flags = info->dc_flags;
-       fstrcpy(state->response->data.dsgetdcname.dc_site_name, info->dc_site_name);
-       fstrcpy(state->response->data.dsgetdcname.client_site_name, info->client_site_name);
-
-       return WINBINDD_OK;
-}
-
 static const struct winbindd_child_dispatch_table locator_dispatch_table[] = {
        {
                .name           = "PING",
                .struct_cmd     = WINBINDD_PING,
                .struct_fn      = winbindd_dual_ping,
-       },{
-               .name           = "DSGETDCNAME",
-               .struct_cmd     = WINBINDD_DSGETDCNAME,
-               .struct_fn      = dual_dsgetdcname,
        },{
                .name           = "NDRCMD",
                .struct_cmd     = WINBINDD_DUAL_NDRCMD,
index 1cce60c1cbc1e84005d654ad5dc270c361cb74f2..59acdbb47e07714163e901f9c3a2f73387dc9c71 100644 (file)
@@ -889,4 +889,11 @@ struct tevent_req *winbindd_endpwent_send(TALLOC_CTX *mem_ctx,
 NTSTATUS winbindd_endpwent_recv(struct tevent_req *req,
                                struct winbindd_response *response);
 
+struct tevent_req *winbindd_dsgetdcname_send(TALLOC_CTX *mem_ctx,
+                                            struct tevent_context *ev,
+                                            struct winbindd_cli_state *cli,
+                                            struct winbindd_request *request);
+NTSTATUS winbindd_dsgetdcname_recv(struct tevent_req *req,
+                                  struct winbindd_response *response);
+
 #endif /*  _WINBINDD_PROTO_H_  */