Fix Coverity ID 853 (UNINIT) -- Kai, please check!
[ira/wip.git] / source4 / winbind / wb_irpc.c
index 59399a9aef5ef5916480e2e5b500e62e72de4e46..801c2e7dfa84656015f2688c5b0fe7ed39a2e9c3 100644 (file)
@@ -22,6 +22,7 @@
 #include "winbind/wb_server.h"
 #include "lib/messaging/irpc.h"
 #include "libcli/composite/composite.h"
+#include "libcli/security/proto.h"
 #include "librpc/gen_ndr/ndr_winbind.h"
 #include "smbd/service_task.h"
 
@@ -35,7 +36,7 @@ static void wb_irpc_SamLogon_callback(struct composite_context *ctx);
 static NTSTATUS wb_irpc_SamLogon(struct irpc_message *msg, 
                                 struct winbind_SamLogon *req)
 {
-       struct wbsrv_service *service = talloc_get_type(msg->private,
+       struct wbsrv_service *service = talloc_get_type(msg->private_data,
                                        struct wbsrv_service);
        struct wb_irpc_SamLogon_state *s;
        struct composite_context *ctx;
@@ -54,7 +55,7 @@ static NTSTATUS wb_irpc_SamLogon(struct irpc_message *msg,
        ctx->async.fn = wb_irpc_SamLogon_callback;
        ctx->async.private_data = s;
 
-       msg->defer_reply = True;
+       msg->defer_reply = true;
        return NT_STATUS_OK;
 }
 
@@ -71,6 +72,74 @@ static void wb_irpc_SamLogon_callback(struct composite_context *ctx)
        irpc_send_reply(s->msg, status);
 }
 
+struct wb_irpc_get_idmap_state {
+       struct irpc_message *msg;
+       struct winbind_get_idmap *req;
+       int level;
+};
+
+static void wb_irpc_get_idmap_callback(struct composite_context *ctx);
+
+static NTSTATUS wb_irpc_get_idmap(struct irpc_message *msg,
+                                 struct winbind_get_idmap *req)
+{
+       struct wbsrv_service *service = talloc_get_type(msg->private_data,
+                                       struct wbsrv_service);
+       struct wb_irpc_get_idmap_state *s;
+       struct composite_context *ctx;
+
+       DEBUG(5, ("wb_irpc_get_idmap called\n"));
+
+       s = talloc(msg, struct wb_irpc_get_idmap_state);
+       NT_STATUS_HAVE_NO_MEMORY(s);
+
+       s->msg = msg;
+       s->req = req;
+       s->level = req->in.level;
+
+       switch(s->level) {
+               case WINBIND_IDMAP_LEVEL_SIDS_TO_XIDS:
+                       ctx = wb_sids2xids_send(msg, service, req->in.count,
+                                               req->in.ids);
+                       break;
+               case WINBIND_IDMAP_LEVEL_XIDS_TO_SIDS:
+                       ctx = wb_xids2sids_send(msg, service, req->in.count,
+                                               req->in.ids);
+                       break;
+       }
+       NT_STATUS_HAVE_NO_MEMORY(ctx);
+
+       composite_continue(ctx, ctx, wb_irpc_get_idmap_callback, s);
+       msg->defer_reply = true;
+
+       return NT_STATUS_OK;
+}
+
+static void wb_irpc_get_idmap_callback(struct composite_context *ctx)
+{
+       struct wb_irpc_get_idmap_state *s;
+       NTSTATUS status;
+
+       DEBUG(5, ("wb_irpc_get_idmap_callback called\n"));
+
+       s = talloc_get_type(ctx->async.private_data,
+                           struct wb_irpc_get_idmap_state);
+
+       switch(s->level) {
+               case WINBIND_IDMAP_LEVEL_SIDS_TO_XIDS:
+                       status = wb_sids2xids_recv(ctx, &s->req->out.ids);
+                       break;
+               case WINBIND_IDMAP_LEVEL_XIDS_TO_SIDS:
+                       status = wb_xids2sids_recv(ctx, &s->req->out.ids);
+                       break;
+               default:
+                       status = NT_STATUS_INTERNAL_ERROR;
+                       break;
+       }
+
+       irpc_send_reply(s->msg, status);
+}
+
 NTSTATUS wbsrv_init_irpc(struct wbsrv_service *service)
 {
        NTSTATUS status;
@@ -81,5 +150,9 @@ NTSTATUS wbsrv_init_irpc(struct wbsrv_service *service)
                               wb_irpc_SamLogon, service);
        NT_STATUS_NOT_OK_RETURN(status);
 
+       status = IRPC_REGISTER(service->task->msg_ctx, winbind, WINBIND_GET_IDMAP,
+                              wb_irpc_get_idmap, service);
+       NT_STATUS_NOT_OK_RETURN(status);
+
        return NT_STATUS_OK;
 }