s4:libcli/wbclient: use irpc_binding_handle_by_name()
authorStefan Metzmacher <metze@samba.org>
Fri, 3 Sep 2010 10:33:17 +0000 (12:33 +0200)
committerStefan Metzmacher <metze@samba.org>
Fri, 3 Sep 2010 15:00:21 +0000 (17:00 +0200)
metze

source4/libcli/wbclient/wbclient.c
source4/libcli/wbclient/wbclient.h
source4/libcli/wbclient/wscript_build
source4/librpc/wscript_build

index 3c3f166d06b3788dc02796271f07aa24b0547f42..5c4312cc66d640085b831cd7907e2011b630be06 100644 (file)
 */
 
 #include "includes.h"
+#include <tevent.h>
 #include "libcli/wbclient/wbclient.h"
 
-/**
- * Get the server_id of the winbind task.
- *
- * \param[in] msg_ctx message context to use
- * \param[in] mem_ctx talloc context to use
- * \param[out] ids array of server_id structs containing the winbind id
- * \return NT_STATUS_OK on success, NT_STATUS_INTERNAL_ERROR on failure
- */
-static NTSTATUS get_server_id(struct messaging_context *msg_ctx,
-                             TALLOC_CTX *mem_ctx, struct server_id **ids)
-{
-       *ids = irpc_servers_byname(msg_ctx, mem_ctx, "winbind_server");
-       if (*ids == NULL || (*ids)[0].id == 0) {
-               DEBUG(0, ("Getting the winbind server ID failed.\n"));
-               return NT_STATUS_INTERNAL_ERROR;
-       }
-       return NT_STATUS_OK;
-}
-
 /**
  * Initialize the wbclient context, talloc_free() when done.
  *
@@ -53,31 +35,30 @@ struct wbc_context *wbc_init(TALLOC_CTX *mem_ctx,
                             struct tevent_context *event_ctx)
 {
        struct wbc_context *ctx;
-       NTSTATUS status;
 
        ctx = talloc(mem_ctx, struct wbc_context);
        if (ctx == NULL) return NULL;
 
-       status = get_server_id(msg_ctx, mem_ctx, &ctx->ids);
-       if (!NT_STATUS_IS_OK(status)) {
+       ctx->event_ctx = event_ctx;
+
+       ctx->irpc_handle = irpc_binding_handle_by_name(ctx, msg_ctx,
+                                                      "winbind_server",
+                                                      &ndr_table_winbind);
+       if (ctx->irpc_handle == NULL) {
                talloc_free(ctx);
                return NULL;
        }
 
-       ctx->msg_ctx = msg_ctx;
-       ctx->event_ctx = event_ctx;
-
        return ctx;
 }
 
 struct wbc_idmap_state {
        struct composite_context *ctx;
        struct winbind_get_idmap *req;
-       struct irpc_request *irpc_req;
        struct id_map *ids;
 };
 
-static void sids_to_xids_recv_ids(struct irpc_request *req);
+static void sids_to_xids_recv_ids(struct tevent_req *subreq);
 
 struct composite_context *wbc_sids_to_xids_send(struct wbc_context *wbc_ctx,
                                                TALLOC_CTX *mem_ctx,
@@ -86,6 +67,7 @@ struct composite_context *wbc_sids_to_xids_send(struct wbc_context *wbc_ctx,
 {
        struct composite_context *ctx;
        struct wbc_idmap_state *state;
+       struct tevent_req *subreq;
 
        DEBUG(5, ("wbc_sids_to_xids called\n"));
 
@@ -104,23 +86,25 @@ struct composite_context *wbc_sids_to_xids_send(struct wbc_context *wbc_ctx,
        state->req->in.ids = ids;
        state->ctx = ctx;
 
-       state->irpc_req = IRPC_CALL_SEND(wbc_ctx->msg_ctx, wbc_ctx->ids[0],
-                                        winbind, WINBIND_GET_IDMAP, state->req,
-                                        state);
-       if (composite_nomem(state->irpc_req, ctx)) return ctx;
+       subreq = dcerpc_winbind_get_idmap_r_send(state,
+                                                wbc_ctx->event_ctx,
+                                                wbc_ctx->irpc_handle,
+                                                state->req);
+       if (composite_nomem(subreq, ctx)) return ctx;
+
+       tevent_req_set_callback(subreq, sids_to_xids_recv_ids, state);
 
-       composite_continue_irpc(ctx, state->irpc_req, sids_to_xids_recv_ids,
-                               state);
        return ctx;
 }
 
-static void sids_to_xids_recv_ids(struct irpc_request *req)
+static void sids_to_xids_recv_ids(struct tevent_req *subreq)
 {
-       struct wbc_idmap_state *state = talloc_get_type_abort(
-                                                       req->async.private_data,
-                                                       struct wbc_idmap_state);
+       struct wbc_idmap_state *state =
+               tevent_req_callback_data(subreq,
+               struct wbc_idmap_state);
 
-       state->ctx->status = irpc_call_recv(state->irpc_req);
+       state->ctx->status = dcerpc_winbind_get_idmap_r_recv(subreq, state);
+       TALLOC_FREE(subreq);
        if (!composite_is_ok(state->ctx)) return;
 
        state->ids = state->req->out.ids;
@@ -142,7 +126,7 @@ NTSTATUS wbc_sids_to_xids_recv(struct composite_context *ctx,
        return status;
 }
 
-static void xids_to_sids_recv_ids(struct irpc_request *req);
+static void xids_to_sids_recv_ids(struct tevent_req *subreq);
 
 struct composite_context *wbc_xids_to_sids_send(struct wbc_context *wbc_ctx,
                                                TALLOC_CTX *mem_ctx,
@@ -151,6 +135,7 @@ struct composite_context *wbc_xids_to_sids_send(struct wbc_context *wbc_ctx,
 {
        struct composite_context *ctx;
        struct wbc_idmap_state *state;
+       struct tevent_req *subreq;
 
        DEBUG(5, ("wbc_xids_to_sids called\n"));
 
@@ -169,24 +154,25 @@ struct composite_context *wbc_xids_to_sids_send(struct wbc_context *wbc_ctx,
        state->req->in.ids = ids;
        state->ctx = ctx;
 
-       state->irpc_req = IRPC_CALL_SEND(wbc_ctx->msg_ctx, wbc_ctx->ids[0],
-                                        winbind, WINBIND_GET_IDMAP, state->req,
-                                        state);
-       if (composite_nomem(state->irpc_req, ctx)) return ctx;
+       subreq = dcerpc_winbind_get_idmap_r_send(state,
+                                                wbc_ctx->event_ctx,
+                                                wbc_ctx->irpc_handle,
+                                                state->req);
+       if (composite_nomem(subreq, ctx)) return ctx;
 
-       composite_continue_irpc(ctx, state->irpc_req, xids_to_sids_recv_ids,
-                       state);
+       tevent_req_set_callback(subreq, xids_to_sids_recv_ids, state);
 
        return ctx;
 }
 
-static void xids_to_sids_recv_ids(struct irpc_request *req)
+static void xids_to_sids_recv_ids(struct tevent_req *subreq)
 {
-       struct wbc_idmap_state *state = talloc_get_type_abort(
-                                                       req->async.private_data,
-                                                       struct wbc_idmap_state);
+       struct wbc_idmap_state *state =
+               tevent_req_callback_data(subreq,
+               struct wbc_idmap_state);
 
-       state->ctx->status = irpc_call_recv(state->irpc_req);
+       state->ctx->status = dcerpc_winbind_get_idmap_r_recv(subreq, state);
+       TALLOC_FREE(subreq);
        if (!composite_is_ok(state->ctx)) return;
 
        state->ids = state->req->out.ids;
index 28b2df9b3d2c91a61eb3c7b3e294b7ab3809275b..e7473e3e7b1e10e1193bf6bb17aa03d132909cf0 100644 (file)
 */
 #include "lib/messaging/irpc.h"
 #include "libcli/composite/composite.h"
-#include "librpc/gen_ndr/ndr_winbind.h"
+#include "librpc/gen_ndr/ndr_winbind_c.h"
 
 struct wbc_context {
-       struct messaging_context *msg_ctx;
        struct tevent_context *event_ctx;
-       struct server_id *ids;
+       struct dcerpc_binding_handle *irpc_handle;
 };
 
 struct wbc_context *wbc_init(TALLOC_CTX *mem_ctx,
index 30f5ff1f2e9702889ef89b4d202392bbddaf32cb..c7a21485196ac4111df3ca11f4d9bcdcd39700c1 100644 (file)
@@ -3,6 +3,6 @@
 bld.SAMBA_SUBSYSTEM('LIBWBCLIENT_OLD',
        source='wbclient.c',
        public_deps='LIBSAMBA-ERRORS LIBEVENTS',
-       deps='NDR_WINBIND MESSAGING'
+       deps='NDR_WINBIND MESSAGING RPC_NDR_WINBIND'
        )
 
index a48c1ead01d1f531424784c3f627f069b64ab3df..de0fc77060f925a0ea1e012edfad4ba9f5cf1b54 100755 (executable)
@@ -454,6 +454,11 @@ bld.SAMBA_SUBSYSTEM('RPC_NDR_IRPC',
        public_deps='dcerpc NDR_IRPC'
        )
 
+bld.SAMBA_SUBSYSTEM('RPC_NDR_WINBIND',
+       source='gen_ndr/ndr_winbind_c.c',
+       public_deps='dcerpc NDR_WINBIND'
+       )
+
 
 bld.SAMBA_LIBRARY('dcerpc_samr',
        source='../../librpc/gen_ndr/ndr_samr_c.c',