torture: Fix copy and paste error in debug message.
[kai/samba.git] / source4 / winbind / wb_async_helpers.c
index c8611e6300a9897de6cf2a7a6bf5c7e4b4d516c1..2af8567fd4cfe1358d74238f4baa007a5557b4cb 100644 (file)
@@ -5,7 +5,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/>.
 */
 /*
   a composite API for finding a DC and its name
 */
 
 #include "includes.h"
+#include <tevent.h>
 #include "libcli/composite/composite.h"
 #include "winbind/wb_async_helpers.h"
 
-#include "lib/messaging/irpc.h"
-#include "librpc/gen_ndr/ndr_irpc.h"
-#include "libcli/auth/credentials.h"
-#include "libcli/security/proto.h"
-#include "libcli/auth/libcli_auth.h"
+#include "libcli/security/security.h"
+#include "librpc/gen_ndr/ndr_lsa_c.h"
+#include "librpc/gen_ndr/ndr_samr_c.h"
 
 #include "winbind/wb_helper.h"
 
-struct get_schannel_creds_state {
-       struct cli_credentials *wks_creds;
-       struct dcerpc_pipe *p;
-       struct netr_ServerReqChallenge r;
-
-       struct creds_CredentialState *creds_state;
-       struct netr_Credential netr_cred;
-       uint32_t negotiate_flags;
-       struct netr_ServerAuthenticate2 a;
-};
-
-static void get_schannel_creds_recv_anonbind(struct composite_context *creq);
-static void get_schannel_creds_recv_auth(struct rpc_request *req);
-static void get_schannel_creds_recv_chal(struct rpc_request *req);
-static void get_schannel_creds_recv_pipe(struct composite_context *ctx);
-
-struct composite_context *wb_get_schannel_creds_send(TALLOC_CTX *mem_ctx,
-                                                    struct cli_credentials *wks_creds,
-                                                    struct smbcli_tree *tree,
-                                                    struct event_context *ev)
-{
-       struct composite_context *c, *creq;
-       struct get_schannel_creds_state *state;
-
-       c = talloc_zero(mem_ctx, struct composite_context);
-       if (c == NULL) return NULL;
-
-       state = talloc(c, struct get_schannel_creds_state);
-       if (state == NULL) {
-               c->status = NT_STATUS_NO_MEMORY;
-               goto failed;
-       }
-
-       c->state = COMPOSITE_STATE_IN_PROGRESS;
-       c->private_data = state;
-       c->event_ctx = ev;
-
-       state->wks_creds = wks_creds;
-
-       state->p = dcerpc_pipe_init(state, ev);
-       if (state->p == NULL) {
-               c->status = NT_STATUS_NO_MEMORY;
-               goto failed;
-       }
-
-       creq = dcerpc_pipe_open_smb_send(state->p->conn, tree, "\\netlogon");
-       if (creq == NULL) {
-               c->status = NT_STATUS_NO_MEMORY;
-               goto failed;
-       }
-
-       creq->async.fn = get_schannel_creds_recv_pipe;
-       creq->async.private_data = c;
-
-       return c;
-
- failed:
-       composite_error(c, c->status);
-       return c;
-}
-
-static void get_schannel_creds_recv_pipe(struct composite_context *creq)
-{
-       struct composite_context *c =
-               talloc_get_type(creq->async.private_data,
-                               struct composite_context);
-       struct get_schannel_creds_state *state =
-               talloc_get_type(c->private_data,
-                               struct get_schannel_creds_state);
-
-       c->status = dcerpc_pipe_open_smb_recv(creq);
-       if (!composite_is_ok(c)) return;
-
-       creq = dcerpc_bind_auth_none_send(state, state->p,
-                                                                         &dcerpc_table_netlogon);
-       composite_continue(c, creq, get_schannel_creds_recv_anonbind, c);
-}
-
-static void get_schannel_creds_recv_anonbind(struct composite_context *creq)
-{
-       struct composite_context *c =
-               talloc_get_type(creq->async.private_data,
-                               struct composite_context);
-       struct get_schannel_creds_state *state =
-               talloc_get_type(c->private_data,
-                               struct get_schannel_creds_state);
-       struct rpc_request *req;
-
-       c->status = dcerpc_bind_auth_none_recv(creq);
-       if (!composite_is_ok(c)) return;
-
-       state->r.in.computer_name =
-               cli_credentials_get_workstation(state->wks_creds);
-       state->r.in.server_name =
-               talloc_asprintf(state, "\\\\%s",
-                               dcerpc_server_name(state->p));
-       if (composite_nomem(state->r.in.server_name, c)) return;
-
-       state->r.in.credentials = talloc(state, struct netr_Credential);
-       if (composite_nomem(state->r.in.credentials, c)) return;
-
-       state->r.out.credentials = talloc(state, struct netr_Credential);
-       if (composite_nomem(state->r.out.credentials, c)) return;
-
-       generate_random_buffer(state->r.in.credentials->data,
-                              sizeof(state->r.in.credentials->data));
-
-       req = dcerpc_netr_ServerReqChallenge_send(state->p, state, &state->r);
-       composite_continue_rpc(c, req, get_schannel_creds_recv_chal, c);
-}
-
-static void get_schannel_creds_recv_chal(struct rpc_request *req)
-{
-       struct composite_context *c =
-               talloc_get_type(req->async.private,
-                               struct composite_context);
-       struct get_schannel_creds_state *state =
-               talloc_get_type(c->private_data,
-                               struct get_schannel_creds_state);
-       const struct samr_Password *mach_pwd;
-
-       c->status = dcerpc_ndr_request_recv(req);
-       if (!composite_is_ok(c)) return;
-       c->status = state->r.out.result;
-       if (!composite_is_ok(c)) return;
-
-       state->creds_state = talloc(state, struct creds_CredentialState);
-       if (composite_nomem(state->creds_state, c)) return;
-
-       mach_pwd = cli_credentials_get_nt_hash(state->wks_creds, state);
-       if (composite_nomem(mach_pwd, c)) return;
-
-       state->negotiate_flags = NETLOGON_NEG_AUTH2_FLAGS;
-
-       creds_client_init(state->creds_state, state->r.in.credentials,
-                         state->r.out.credentials, mach_pwd,
-                         &state->netr_cred, state->negotiate_flags);
-
-       state->a.in.server_name =
-               talloc_reference(state, state->r.in.server_name);
-       state->a.in.account_name =
-               cli_credentials_get_username(state->wks_creds);
-       state->a.in.secure_channel_type =
-               cli_credentials_get_secure_channel_type(state->wks_creds);
-       state->a.in.computer_name =
-               cli_credentials_get_workstation(state->wks_creds);
-       state->a.in.negotiate_flags = &state->negotiate_flags;
-       state->a.out.negotiate_flags = &state->negotiate_flags;
-       state->a.in.credentials = &state->netr_cred;
-       state->a.out.credentials = &state->netr_cred;
-
-       req = dcerpc_netr_ServerAuthenticate2_send(state->p, state, &state->a);
-       composite_continue_rpc(c, req, get_schannel_creds_recv_auth, c);
-}
-
-static void get_schannel_creds_recv_auth(struct rpc_request *req)
-{
-       struct composite_context *c =
-               talloc_get_type(req->async.private,
-                               struct composite_context);
-       struct get_schannel_creds_state *state =
-               talloc_get_type(c->private_data,
-                               struct get_schannel_creds_state);
-
-       c->status = dcerpc_ndr_request_recv(req);
-       if (!composite_is_ok(c)) return;
-       c->status = state->a.out.result;
-       if (!composite_is_ok(c)) return;
-
-       if (!creds_client_check(state->creds_state,
-                               state->a.out.credentials)) {
-               DEBUG(5, ("Server got us invalid creds\n"));
-               composite_error(c, NT_STATUS_UNSUCCESSFUL);
-               return;
-       }
-
-       cli_credentials_set_netlogon_creds(state->wks_creds,
-                                          state->creds_state);
-
-       composite_done(c);
-}
-
-NTSTATUS wb_get_schannel_creds_recv(struct composite_context *c,
-                                   TALLOC_CTX *mem_ctx,
-                                   struct dcerpc_pipe **netlogon_pipe)
-{
-       NTSTATUS status = composite_wait(c);
-       if (NT_STATUS_IS_OK(status)) {
-               struct get_schannel_creds_state *state =
-                       talloc_get_type(c->private_data,
-                                       struct get_schannel_creds_state);
-               *netlogon_pipe = talloc_steal(mem_ctx, state->p);
-       }
-       talloc_free(c);
-       return status;
-}
-
-NTSTATUS wb_get_schannel_creds(TALLOC_CTX *mem_ctx,
-                              struct cli_credentials *wks_creds,
-                              struct smbcli_tree *tree,
-                              struct event_context *event_ctx,
-                              struct dcerpc_pipe **netlogon_pipe)
-{
-       struct composite_context *c =
-               wb_get_schannel_creds_send(mem_ctx, wks_creds, tree,
-                                          event_ctx);
-       return wb_get_schannel_creds_recv(c, mem_ctx, netlogon_pipe);
-}
 
 struct lsa_lookupsids_state {
        struct composite_context *ctx;
-       int num_sids;
+       uint32_t num_sids;
        struct lsa_LookupSids r;
        struct lsa_SidArray sids;
        struct lsa_TransNameArray names;
+       struct lsa_RefDomainList *domains;
        uint32_t count;
        struct wb_sid_object **result;
 };
 
-static void lsa_lookupsids_recv_names(struct rpc_request *req);
+static void lsa_lookupsids_recv_names(struct tevent_req *subreq);
 
 struct composite_context *wb_lsa_lookupsids_send(TALLOC_CTX *mem_ctx,
                                                 struct dcerpc_pipe *lsa_pipe,
                                                 struct policy_handle *handle,
-                                                int num_sids,
+                                                uint32_t num_sids,
                                                 const struct dom_sid **sids)
 {
        struct composite_context *result;
-       struct rpc_request *req;
        struct lsa_lookupsids_state *state;
-       int i;
+       uint32_t i;
+       struct tevent_req *subreq;
 
-       result = talloc(mem_ctx, struct composite_context);
+       result = composite_create(mem_ctx, lsa_pipe->conn->event_ctx);
        if (result == NULL) goto failed;
-       result->state = COMPOSITE_STATE_IN_PROGRESS;
-       result->async.fn = NULL;
-       result->event_ctx = lsa_pipe->conn->event_ctx;
 
        state = talloc(result, struct lsa_lookupsids_state);
        if (state == NULL) goto failed;
@@ -286,6 +74,9 @@ struct composite_context *wb_lsa_lookupsids_send(TALLOC_CTX *mem_ctx,
                if (state->sids.sids[i].sid == NULL) goto failed;
        }
 
+       state->domains = talloc(state, struct lsa_RefDomainList);
+       if (state->domains == NULL) goto failed;
+
        state->count = 0;
        state->num_sids = num_sids;
        state->names.count = 0;
@@ -298,12 +89,15 @@ struct composite_context *wb_lsa_lookupsids_send(TALLOC_CTX *mem_ctx,
        state->r.in.count = &state->count;
        state->r.out.names = &state->names;
        state->r.out.count = &state->count;
+       state->r.out.domains = &state->domains;
 
-       req = dcerpc_lsa_LookupSids_send(lsa_pipe, state, &state->r);
-       if (req == NULL) goto failed;
+       subreq = dcerpc_lsa_LookupSids_r_send(state,
+                                             result->event_ctx,
+                                             lsa_pipe->binding_handle,
+                                             &state->r);
+       if (subreq == NULL) goto failed;
+       tevent_req_set_callback(subreq, lsa_lookupsids_recv_names, state);
 
-       req->async.callback = lsa_lookupsids_recv_names;
-       req->async.private = state;
        return result;
 
  failed:
@@ -311,14 +105,15 @@ struct composite_context *wb_lsa_lookupsids_send(TALLOC_CTX *mem_ctx,
        return NULL;
 }
 
-static void lsa_lookupsids_recv_names(struct rpc_request *req)
+static void lsa_lookupsids_recv_names(struct tevent_req *subreq)
 {
        struct lsa_lookupsids_state *state =
-               talloc_get_type(req->async.private,
-                               struct lsa_lookupsids_state);
-       int i;
+               tevent_req_callback_data(subreq,
+               struct lsa_lookupsids_state);
+       uint32_t i;
 
-       state->ctx->status = dcerpc_ndr_request_recv(req);
+       state->ctx->status = dcerpc_lsa_LookupSids_r_recv(subreq, state);
+       TALLOC_FREE(subreq);
        if (!composite_is_ok(state->ctx)) return;
        state->ctx->status = state->r.out.result;
        if (!NT_STATUS_IS_OK(state->ctx->status) &&
@@ -334,7 +129,9 @@ static void lsa_lookupsids_recv_names(struct rpc_request *req)
        for (i=0; i<state->num_sids; i++) {
                struct lsa_TranslatedName *name =
                        &state->r.out.names->names[i];
-               struct lsa_TrustInformation *dom;
+               struct lsa_DomainInfo *dom;
+               struct lsa_RefDomainList *domains =
+                       state->domains;
 
                state->result[i] = talloc_zero(state->result,
                                               struct wb_sid_object);
@@ -345,13 +142,13 @@ static void lsa_lookupsids_recv_names(struct rpc_request *req)
                        continue;
                }
 
-               if (name->sid_index >= state->r.out.domains->count) {
+               if (name->sid_index >= domains->count) {
                        composite_error(state->ctx,
                                        NT_STATUS_INVALID_PARAMETER);
                        return;
                }
 
-               dom = &state->r.out.domains->domains[name->sid_index];
+               dom = &domains->domains[name->sid_index];
                state->result[i]->domain = talloc_reference(state->result[i],
                                                            dom->name.string);
                if ((name->sid_type == SID_NAME_DOMAIN) ||
@@ -387,49 +184,34 @@ NTSTATUS wb_lsa_lookupsids_recv(struct composite_context *c,
        return status;
 }
 
-NTSTATUS wb_lsa_lookupsids(TALLOC_CTX *mem_ctx,
-                          struct dcerpc_pipe *lsa_pipe,
-                          struct policy_handle *handle,
-                          int num_sids, const struct dom_sid **sids,
-                          struct wb_sid_object ***names)
-{
-       struct composite_context *c =
-               wb_lsa_lookupsids_send(mem_ctx, lsa_pipe, handle,
-                                      num_sids, sids);
-       return wb_lsa_lookupnames_recv(c, mem_ctx, names);
-}
-
-                          
 
 struct lsa_lookupnames_state {
        struct composite_context *ctx;
        uint32_t num_names;
        struct lsa_LookupNames r;
        struct lsa_TransSidArray sids;
+       struct lsa_RefDomainList *domains;
        uint32_t count;
        struct wb_sid_object **result;
 };
 
-static void lsa_lookupnames_recv_sids(struct rpc_request *req);
+static void lsa_lookupnames_recv_sids(struct tevent_req *subreq);
 
 struct composite_context *wb_lsa_lookupnames_send(TALLOC_CTX *mem_ctx,
                                                  struct dcerpc_pipe *lsa_pipe,
                                                  struct policy_handle *handle,
-                                                 int num_names,
+                                                 uint32_t num_names,
                                                  const char **names)
 {
        struct composite_context *result;
-       struct rpc_request *req;
        struct lsa_lookupnames_state *state;
+       struct tevent_req *subreq;
 
        struct lsa_String *lsa_names;
-       int i;
+       uint32_t i;
 
-       result = talloc(mem_ctx, struct composite_context);
+       result = composite_create(mem_ctx, lsa_pipe->conn->event_ctx);
        if (result == NULL) goto failed;
-       result->state = COMPOSITE_STATE_IN_PROGRESS;
-       result->async.fn = NULL;
-       result->event_ctx = lsa_pipe->conn->event_ctx;
 
        state = talloc(result, struct lsa_lookupnames_state);
        if (state == NULL) goto failed;
@@ -448,6 +230,9 @@ struct composite_context *wb_lsa_lookupnames_send(TALLOC_CTX *mem_ctx,
                lsa_names[i].string = names[i];
        }
 
+       state->domains = talloc(state, struct lsa_RefDomainList);
+       if (state->domains == NULL) goto failed;
+
        state->r.in.handle = handle;
        state->r.in.num_names = num_names;
        state->r.in.names = lsa_names;
@@ -456,12 +241,15 @@ struct composite_context *wb_lsa_lookupnames_send(TALLOC_CTX *mem_ctx,
        state->r.in.count = &state->count;
        state->r.out.count = &state->count;
        state->r.out.sids = &state->sids;
+       state->r.out.domains = &state->domains;
 
-       req = dcerpc_lsa_LookupNames_send(lsa_pipe, state, &state->r);
-       if (req == NULL) goto failed;
+       subreq = dcerpc_lsa_LookupNames_r_send(state,
+                                              result->event_ctx,
+                                              lsa_pipe->binding_handle,
+                                              &state->r);
+       if (subreq == NULL) goto failed;
+       tevent_req_set_callback(subreq, lsa_lookupnames_recv_sids, state);
 
-       req->async.callback = lsa_lookupnames_recv_sids;
-       req->async.private = state;
        return result;
 
  failed:
@@ -469,14 +257,15 @@ struct composite_context *wb_lsa_lookupnames_send(TALLOC_CTX *mem_ctx,
        return NULL;
 }
 
-static void lsa_lookupnames_recv_sids(struct rpc_request *req)
+static void lsa_lookupnames_recv_sids(struct tevent_req *subreq)
 {
        struct lsa_lookupnames_state *state =
-               talloc_get_type(req->async.private,
-                               struct lsa_lookupnames_state);
-       int i;
+               tevent_req_callback_data(subreq,
+               struct lsa_lookupnames_state);
+       uint32_t i;
 
-       state->ctx->status = dcerpc_ndr_request_recv(req);
+       state->ctx->status = dcerpc_lsa_LookupNames_r_recv(subreq, state);
+       TALLOC_FREE(subreq);
        if (!composite_is_ok(state->ctx)) return;
        state->ctx->status = state->r.out.result;
        if (!NT_STATUS_IS_OK(state->ctx->status) &&
@@ -491,7 +280,8 @@ static void lsa_lookupnames_recv_sids(struct rpc_request *req)
 
        for (i=0; i<state->num_names; i++) {
                struct lsa_TranslatedSid *sid = &state->r.out.sids->sids[i];
-               struct lsa_TrustInformation *dom;
+               struct lsa_RefDomainList *domains = state->domains;
+               struct lsa_DomainInfo *dom;
 
                state->result[i] = talloc_zero(state->result,
                                               struct wb_sid_object);
@@ -502,13 +292,13 @@ static void lsa_lookupnames_recv_sids(struct rpc_request *req)
                        continue;
                }
 
-               if (sid->sid_index >= state->r.out.domains->count) {
+               if (sid->sid_index >= domains->count) {
                        composite_error(state->ctx,
                                        NT_STATUS_INVALID_PARAMETER);
                        return;
                }
 
-               dom = &state->r.out.domains->domains[sid->sid_index];
+               dom = &domains->domains[sid->sid_index];
 
                state->result[i]->sid = dom_sid_add_rid(state->result[i],
                                                        dom->sid, sid->rid);
@@ -531,103 +321,24 @@ NTSTATUS wb_lsa_lookupnames_recv(struct composite_context *c,
        talloc_free(c);
        return status;
 }
-
-NTSTATUS wb_lsa_lookupnames(TALLOC_CTX *mem_ctx,
-                           struct dcerpc_pipe *lsa_pipe, 
-                           struct policy_handle *handle,
-                           int num_names, const char **names,
-                           struct wb_sid_object ***sids)
-{
-       struct composite_context *c =
-               wb_lsa_lookupnames_send(mem_ctx, lsa_pipe, handle,
-                                       num_names, names);
-       return wb_lsa_lookupnames_recv(c, mem_ctx, sids);
-}
-
-#if 0
-
-struct cmd_checkmachacc_state {
-       struct composite_context *ctx;
-       struct wbsrv_call *call;
-       struct wbsrv_domain *domain;
-};
-
-static void cmd_checkmachacc_recv_init(struct composite_context *ctx);
-
- struct composite_context *wb_cmd_checkmachacc_send(struct wbsrv_call *call)
-{
-       struct composite_context *result, *ctx;
-       struct cmd_checkmachacc_state *state;
-       struct wbsrv_service *service = call->wbconn->listen_socket->service;
-
-       result = talloc(call, struct composite_context);
-       if (result == NULL) goto failed;
-       result->state = COMPOSITE_STATE_IN_PROGRESS;
-       result->async.fn = NULL;
-       result->event_ctx = call->event_ctx;
-
-       state = talloc(result, struct cmd_checkmachacc_state);
-       if (state == NULL) goto failed;
-       state->ctx = result;
-       result->private_data = state;
-       state->call = call;
-
-       state->domain = service->domains;
-
-       ctx = wb_init_domain_send(service, state->domain);
-       if (ctx == NULL) goto failed;
-       ctx->async.fn = cmd_checkmachacc_recv_init;
-       ctx->async.private_data = state;
-
-       return result;
-
- failed:
-       talloc_free(result);
-       return NULL;
-}
-
-static void cmd_checkmachacc_recv_init(struct composite_context *ctx)
-{
-       struct cmd_checkmachacc_state *state =
-               talloc_get_type(ctx->async.private_data,
-                               struct cmd_checkmachacc_state);
-
-       state->ctx->status = wb_init_domain_recv(ctx);
-       if (!composite_is_ok(state->ctx)) return;
-
-       composite_done(state->ctx);
-}
-
- NTSTATUS wb_cmd_checkmachacc_recv(struct composite_context *c)
-{
-       NTSTATUS status = composite_wait(c);
-       talloc_free(c);
-       return status;
-}
-
- NTSTATUS wb_cmd_checkmachacc(struct wbsrv_call *call)
-{
-       struct composite_context *c = wb_cmd_checkmachacc_send(call);
-       return wb_cmd_checkmachacc_recv(c);
-}
-#endif
-
 struct samr_getuserdomgroups_state {
        struct composite_context *ctx;
        struct dcerpc_pipe *samr_pipe;
 
-       int num_rids;
+       uint32_t num_rids;
        uint32_t *rids;
 
+       struct samr_RidWithAttributeArray *rid_array;
+
        struct policy_handle *user_handle;
        struct samr_OpenUser o;
        struct samr_GetGroupsForUser g;
        struct samr_Close c;
 };
 
-static void samr_usergroups_recv_open(struct rpc_request *req);
-static void samr_usergroups_recv_groups(struct rpc_request *req);
-static void samr_usergroups_recv_close(struct rpc_request *req);
+static void samr_usergroups_recv_open(struct tevent_req *subreq);
+static void samr_usergroups_recv_groups(struct tevent_req *subreq);
+static void samr_usergroups_recv_close(struct tevent_req *subreq);
 
 struct composite_context *wb_samr_userdomgroups_send(TALLOC_CTX *mem_ctx,
                                                     struct dcerpc_pipe *samr_pipe,
@@ -635,14 +346,11 @@ struct composite_context *wb_samr_userdomgroups_send(TALLOC_CTX *mem_ctx,
                                                     uint32_t rid)
 {
        struct composite_context *result;
-       struct rpc_request *req;
        struct samr_getuserdomgroups_state *state;
+       struct tevent_req *subreq;
 
-       result = talloc(mem_ctx, struct composite_context);
+       result = composite_create(mem_ctx, samr_pipe->conn->event_ctx);
        if (result == NULL) goto failed;
-       result->state = COMPOSITE_STATE_IN_PROGRESS;
-       result->async.fn = NULL;
-       result->event_ctx = samr_pipe->conn->event_ctx;
 
        state = talloc(result, struct samr_getuserdomgroups_state);
        if (state == NULL) goto failed;
@@ -659,11 +367,13 @@ struct composite_context *wb_samr_userdomgroups_send(TALLOC_CTX *mem_ctx,
        state->o.in.rid = rid;
        state->o.out.user_handle = state->user_handle;
 
-       req = dcerpc_samr_OpenUser_send(state->samr_pipe, state, &state->o);
-       if (req == NULL) goto failed;
+       subreq = dcerpc_samr_OpenUser_r_send(state,
+                                            result->event_ctx,
+                                            state->samr_pipe->binding_handle,
+                                            &state->o);
+       if (subreq == NULL) goto failed;
+       tevent_req_set_callback(subreq, samr_usergroups_recv_open, state);
 
-       req->async.callback = samr_usergroups_recv_open;
-       req->async.private = state;
        return result;
 
  failed:
@@ -671,32 +381,37 @@ struct composite_context *wb_samr_userdomgroups_send(TALLOC_CTX *mem_ctx,
        return NULL;
 }
                                              
-static void samr_usergroups_recv_open(struct rpc_request *req)
+static void samr_usergroups_recv_open(struct tevent_req *subreq)
 {
        struct samr_getuserdomgroups_state *state =
-               talloc_get_type(req->async.private,
-                               struct samr_getuserdomgroups_state);
+               tevent_req_callback_data(subreq,
+               struct samr_getuserdomgroups_state);
 
-       state->ctx->status = dcerpc_ndr_request_recv(req);
+       state->ctx->status = dcerpc_samr_OpenUser_r_recv(subreq, state);
+       TALLOC_FREE(subreq);
        if (!composite_is_ok(state->ctx)) return;
        state->ctx->status = state->o.out.result;
        if (!composite_is_ok(state->ctx)) return;
 
        state->g.in.user_handle = state->user_handle;
-
-       req = dcerpc_samr_GetGroupsForUser_send(state->samr_pipe, state,
-                                               &state->g);
-       composite_continue_rpc(state->ctx, req, samr_usergroups_recv_groups,
-                              state);
+       state->g.out.rids = &state->rid_array;
+
+       subreq = dcerpc_samr_GetGroupsForUser_r_send(state,
+                                                    state->ctx->event_ctx,
+                                                    state->samr_pipe->binding_handle,
+                                                    &state->g);
+       if (composite_nomem(subreq, state->ctx)) return;
+       tevent_req_set_callback(subreq, samr_usergroups_recv_groups, state);
 }
 
-static void samr_usergroups_recv_groups(struct rpc_request *req)
+static void samr_usergroups_recv_groups(struct tevent_req *subreq)
 {
        struct samr_getuserdomgroups_state *state =
-               talloc_get_type(req->async.private,
-                               struct samr_getuserdomgroups_state);
+               tevent_req_callback_data(subreq,
+               struct samr_getuserdomgroups_state);
 
-       state->ctx->status = dcerpc_ndr_request_recv(req);
+       state->ctx->status = dcerpc_samr_GetGroupsForUser_r_recv(subreq, state);
+       TALLOC_FREE(subreq);
        if (!composite_is_ok(state->ctx)) return;
        state->ctx->status = state->g.out.result;
        if (!composite_is_ok(state->ctx)) return;
@@ -704,18 +419,22 @@ static void samr_usergroups_recv_groups(struct rpc_request *req)
        state->c.in.handle = state->user_handle;
        state->c.out.handle = state->user_handle;
 
-       req = dcerpc_samr_Close_send(state->samr_pipe, state, &state->c);
-       composite_continue_rpc(state->ctx, req, samr_usergroups_recv_close,
-                              state);
+       subreq = dcerpc_samr_Close_r_send(state,
+                                         state->ctx->event_ctx,
+                                         state->samr_pipe->binding_handle,
+                                         &state->c);
+       if (composite_nomem(subreq, state->ctx)) return;
+       tevent_req_set_callback(subreq, samr_usergroups_recv_close, state);
 }
 
-static void samr_usergroups_recv_close(struct rpc_request *req)
+static void samr_usergroups_recv_close(struct tevent_req *subreq)
 {
         struct samr_getuserdomgroups_state *state =
-                talloc_get_type(req->async.private,
-                                struct samr_getuserdomgroups_state);
+               tevent_req_callback_data(subreq,
+               struct samr_getuserdomgroups_state);
 
-        state->ctx->status = dcerpc_ndr_request_recv(req);
+       state->ctx->status = dcerpc_samr_Close_r_recv(subreq, state);
+       TALLOC_FREE(subreq);
         if (!composite_is_ok(state->ctx)) return;
         state->ctx->status = state->c.out.result;
         if (!composite_is_ok(state->ctx)) return;
@@ -725,17 +444,17 @@ static void samr_usergroups_recv_close(struct rpc_request *req)
 
 NTSTATUS wb_samr_userdomgroups_recv(struct composite_context *ctx,
                                    TALLOC_CTX *mem_ctx,
-                                   int *num_rids, uint32_t **rids)
+                                   uint32_t *num_rids, uint32_t **rids)
 {
         struct samr_getuserdomgroups_state *state =
                 talloc_get_type(ctx->private_data,
                                 struct samr_getuserdomgroups_state);
 
-       int i;
+       uint32_t i;
        NTSTATUS status = composite_wait(ctx);
        if (!NT_STATUS_IS_OK(status)) goto done;
 
-       *num_rids = state->g.out.rids->count;
+       *num_rids = state->rid_array->count;
        *rids = talloc_array(mem_ctx, uint32_t, *num_rids);
        if (*rids == NULL) {
                status = NT_STATUS_NO_MEMORY;
@@ -743,7 +462,7 @@ NTSTATUS wb_samr_userdomgroups_recv(struct composite_context *ctx,
        }
 
        for (i=0; i<*num_rids; i++) {
-               (*rids)[i] = state->g.out.rids->rids[i].rid;
+               (*rids)[i] = state->rid_array->rids[i].rid;
        }
 
  done: