Add context for libcli_resolve.
[samba-svnmirror.git] / source / winbind / wb_dom_info_trusted.c
index ce9e5b9c477639c348ac8f706f4c2e1a70562ca5..46d3bf37f65d8c37ccc31cfd9f8ef10f4315c618 100644 (file)
@@ -7,7 +7,7 @@
    
    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 2 of the License, or
+   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,
    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, write to the Free Software
-   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
 
 #include "includes.h"
 #include "libcli/composite/composite.h"
-#include "libcli/smb_composite/smb_composite.h"
-#include "winbind/wb_async_helpers.h"
+#include "libcli/resolve/resolve.h"
+#include "libcli/security/security.h"
 #include "winbind/wb_server.h"
-#include "smbd/service_stream.h"
 #include "smbd/service_task.h"
-#include "librpc/gen_ndr/nbt.h"
-#include "librpc/gen_ndr/ndr_netlogon.h"
+#include "librpc/gen_ndr/ndr_netlogon_c.h"
+#include "libcli/libcli.h"
+#include "param/param.h"
 
 struct trusted_dom_info_state {
        struct composite_context *ctx;
@@ -54,11 +53,8 @@ struct composite_context *wb_trusted_dom_info_send(TALLOC_CTX *mem_ctx,
        struct composite_context *result, *ctx;
        struct trusted_dom_info_state *state;
 
-       result = talloc(mem_ctx, struct composite_context);
+       result = composite_create(mem_ctx, service->task->event_ctx);
        if (result == NULL) goto failed;
-       result->state = COMPOSITE_STATE_IN_PROGRESS;
-       result->async.fn = NULL;
-       result->event_ctx = service->task->event_ctx;
 
        state = talloc(result, struct trusted_dom_info_state);
        if (state == NULL) goto failed;
@@ -100,14 +96,14 @@ static void trusted_dom_info_recv_domain(struct composite_context *ctx)
 
        state->d.in.server_unc =
                talloc_asprintf(state, "\\\\%s",
-                               state->my_domain->info->dc_name);
+                               dcerpc_server_name(state->my_domain->netlogon_pipe));
        if (composite_nomem(state->d.in.server_unc,
                            state->ctx)) return;
 
        state->d.in.domain_name = state->info->name;
        state->d.in.domain_guid = NULL;
        state->d.in.site_guid = NULL;
-       state->d.in.flags = 0x40000000;
+       state->d.in.flags = DS_RETURN_DNS_NAME;
 
        req = dcerpc_netr_DsRGetDCName_send(state->my_domain->netlogon_pipe,
                                            state, &state->d);
@@ -122,7 +118,7 @@ static void trusted_dom_info_recv_domain(struct composite_context *ctx)
 static void trusted_dom_info_recv_dsr(struct rpc_request *req)
 {
        struct trusted_dom_info_state *state =
-               talloc_get_type(req->async.private,
+               talloc_get_type(req->async.private_data,
                                struct trusted_dom_info_state);
 
        state->ctx->status = dcerpc_ndr_request_recv(req);
@@ -141,16 +137,17 @@ static void trusted_dom_info_recv_dsr(struct rpc_request *req)
        }
 
        /* Hey, that was easy! */
-
-       state->info->dc_name = talloc_steal(state->info,
+       state->info->num_dcs = 1;
+       state->info->dcs = talloc(state->info, struct nbt_dc_name);
+       state->info->dcs[0].name = talloc_steal(state->info,
                                            state->d.out.info->dc_unc);
-       if (*state->info->dc_name == '\\') state->info->dc_name++;
-       if (*state->info->dc_name == '\\') state->info->dc_name++;
+       if (*state->info->dcs[0].name == '\\') state->info->dcs[0].name++;
+       if (*state->info->dcs[0].name == '\\') state->info->dcs[0].name++;
 
-       state->info->dc_address = talloc_steal(state->info,
+       state->info->dcs[0].address = talloc_steal(state->info,
                                               state->d.out.info->dc_address);
-       if (*state->info->dc_address == '\\') state->info->dc_address++;
-       if (*state->info->dc_address == '\\') state->info->dc_address++;
+       if (*state->info->dcs[0].address == '\\') state->info->dcs[0].address++;
+       if (*state->info->dcs[0].address == '\\') state->info->dcs[0].address++;
 
        state->info->dns_name = talloc_steal(state->info,
                                             state->d.out.info->domain_name);
@@ -176,7 +173,7 @@ static void trusted_dom_info_recv_dsr(struct rpc_request *req)
 static void trusted_dom_info_recv_dcname(struct rpc_request *req)
 {
        struct trusted_dom_info_state *state =
-               talloc_get_type(req->async.private,
+               talloc_get_type(req->async.private_data,
                                struct trusted_dom_info_state);
        struct composite_context *ctx;
        struct nbt_name name;
@@ -186,15 +183,17 @@ static void trusted_dom_info_recv_dcname(struct rpc_request *req)
        state->ctx->status = werror_to_ntstatus(state->g.out.result);
        if (!composite_is_ok(state->ctx)) return;
 
-       state->info->dc_name = talloc_steal(state->info,
+       /* Hey, that was easy! */
+       state->info->num_dcs = 1;
+       state->info->dcs = talloc(state->info, struct nbt_dc_name);
+       state->info->dcs[0].name = talloc_steal(state->info,
                                            state->g.out.dcname);
-
-       if (*state->info->dc_name == '\\') state->info->dc_name++;
-       if (*state->info->dc_name == '\\') state->info->dc_name++;
+       if (*state->info->dcs[0].name == '\\') state->info->dcs[0].name++;
+       if (*state->info->dcs[0].name == '\\') state->info->dcs[0].name++;
        
-       make_nbt_name(&name, state->info->dc_name, 0x20);
-       ctx = resolve_name_send(&name, state->service->task->event_ctx,
-                               lp_name_resolve_order());
+       make_nbt_name(&name, state->info->dcs[0].name, 0x20);
+       ctx = resolve_name_send(lp_resolve_context(state->service->task->lp_ctx), 
+                               &name, state->service->task->event_ctx);
 
        composite_continue(state->ctx, ctx, trusted_dom_info_recv_dcaddr,
                           state);
@@ -207,7 +206,7 @@ static void trusted_dom_info_recv_dcaddr(struct composite_context *ctx)
                                struct trusted_dom_info_state);
 
        state->ctx->status = resolve_name_recv(ctx, state->info,
-                                              &state->info->dc_address);
+                                              &state->info->dcs[0].address);
        if (!composite_is_ok(state->ctx)) return;
 
        composite_done(state->ctx);