winbindd: Do not use group_list->out.resume_index after free
[samba.git] / source4 / winbind / wb_connect_lsa.c
index b8b4fa8e4de0aa8738985f0d2b50482bbdbae92f..3bf02a0ed09766c794117bfa1913fe01719f703c 100644 (file)
@@ -9,7 +9,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/raw/libcliraw.h"
 #include "librpc/gen_ndr/ndr_lsa_c.h"
 #include "winbind/wb_server.h"
+#include "smbd/service_task.h"
 
 /* Helper to initialize LSA with a specific auth methods. Verify by opening
  * the LSA policy. */
@@ -45,7 +44,7 @@ struct init_lsa_state {
 };
 
 static void init_lsa_recv_pipe(struct composite_context *ctx);
-static void init_lsa_recv_openpol(struct rpc_request *req);
+static void init_lsa_recv_openpol(struct tevent_req *subreq);
 
 struct composite_context *wb_init_lsa_send(TALLOC_CTX *mem_ctx,
                                           struct wbsrv_domain *domain)
@@ -53,7 +52,7 @@ struct composite_context *wb_init_lsa_send(TALLOC_CTX *mem_ctx,
        struct composite_context *result, *ctx;
        struct init_lsa_state *state;
 
-       result = composite_create(mem_ctx, domain->netlogon_pipe->conn->event_ctx);
+       result = composite_create(mem_ctx, domain->service->task->event_ctx);
        if (result == NULL) goto failed;
 
        state = talloc(result, struct init_lsa_state);
@@ -63,8 +62,11 @@ struct composite_context *wb_init_lsa_send(TALLOC_CTX *mem_ctx,
 
        /* this will make the secondary connection on the same IPC$ share, 
           secured with SPNEGO or NTLMSSP */
-       ctx = dcerpc_secondary_connection_send(domain->netlogon_pipe,
-                                              domain->lsa_binding);
+       ctx = dcerpc_secondary_auth_connection_send(domain->netlogon_pipe,
+                                                   domain->lsa_binding,
+                                                   &ndr_table_lsarpc,
+                                                   domain->libnet_ctx->cred,
+                                                   domain->libnet_ctx->lp_ctx);
        composite_continue(state->ctx, ctx, init_lsa_recv_pipe, state);
        return result;
        
@@ -75,13 +77,13 @@ struct composite_context *wb_init_lsa_send(TALLOC_CTX *mem_ctx,
 
 static void init_lsa_recv_pipe(struct composite_context *ctx)
 {
-       struct rpc_request *req;
        struct init_lsa_state *state =
                talloc_get_type(ctx->async.private_data,
                                struct init_lsa_state);
+       struct tevent_req *subreq;
 
-       state->ctx->status = dcerpc_secondary_connection_recv(ctx, 
-                                                             &state->lsa_pipe);
+       state->ctx->status = dcerpc_secondary_auth_connection_recv(ctx, state,
+                                                                  &state->lsa_pipe);
        if (!composite_is_ok(state->ctx)) return;
                        
        state->handle = talloc(state, struct policy_handle);
@@ -95,18 +97,22 @@ static void init_lsa_recv_pipe(struct composite_context *ctx)
        state->openpolicy.in.access_mask = SEC_FLAG_MAXIMUM_ALLOWED;
        state->openpolicy.out.handle = state->handle;
 
-       req = dcerpc_lsa_OpenPolicy2_send(state->lsa_pipe, state,
-                                         &state->openpolicy);
-       composite_continue_rpc(state->ctx, req, init_lsa_recv_openpol, state);
+       subreq = dcerpc_lsa_OpenPolicy2_r_send(state,
+                                              state->ctx->event_ctx,
+                                              state->lsa_pipe->binding_handle,
+                                              &state->openpolicy);
+       if (composite_nomem(subreq, state->ctx)) return;
+       tevent_req_set_callback(subreq, init_lsa_recv_openpol, state);
 }
 
-static void init_lsa_recv_openpol(struct rpc_request *req)
+static void init_lsa_recv_openpol(struct tevent_req *subreq)
 {
        struct init_lsa_state *state =
-               talloc_get_type(req->async.private_data,
-                               struct init_lsa_state);
+               tevent_req_callback_data(subreq,
+               struct init_lsa_state);
 
-       state->ctx->status = dcerpc_ndr_request_recv(req);
+       state->ctx->status = dcerpc_lsa_OpenPolicy2_r_recv(subreq, state);
+       TALLOC_FREE(subreq);
        if (!composite_is_ok(state->ctx)) return;
        state->ctx->status = state->openpolicy.out.result;
        if (!composite_is_ok(state->ctx)) return;