smb_traffic_analyzer.c: optimize marshalling function and document
[Samba/ekacnet.git] / source4 / winbind / wb_irpc.c
blobbfb31e66a76d11ae3474234a2833fdcf16335c84
1 /*
2 Unix SMB/CIFS implementation.
3 Main winbindd irpc handlers
5 Copyright (C) Stefan Metzmacher 2006
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>.
21 #include "includes.h"
22 #include "winbind/wb_server.h"
23 #include "lib/messaging/irpc.h"
24 #include "libcli/composite/composite.h"
25 #include "librpc/gen_ndr/ndr_winbind.h"
26 #include "smbd/service_task.h"
28 struct wb_irpc_SamLogon_state {
29 struct irpc_message *msg;
30 struct winbind_SamLogon *req;
33 static void wb_irpc_SamLogon_callback(struct composite_context *ctx);
35 static NTSTATUS wb_irpc_SamLogon(struct irpc_message *msg,
36 struct winbind_SamLogon *req)
38 struct wbsrv_service *service = talloc_get_type(msg->private_data,
39 struct wbsrv_service);
40 struct wb_irpc_SamLogon_state *s;
41 struct composite_context *ctx;
43 DEBUG(5, ("wb_irpc_SamLogon called\n"));
45 s = talloc(msg, struct wb_irpc_SamLogon_state);
46 NT_STATUS_HAVE_NO_MEMORY(s);
48 s->msg = msg;
49 s->req = req;
51 ctx = wb_sam_logon_send(msg, service, req);
52 NT_STATUS_HAVE_NO_MEMORY(ctx);
54 ctx->async.fn = wb_irpc_SamLogon_callback;
55 ctx->async.private_data = s;
57 msg->defer_reply = true;
58 return NT_STATUS_OK;
61 static void wb_irpc_SamLogon_callback(struct composite_context *ctx)
63 struct wb_irpc_SamLogon_state *s = talloc_get_type(ctx->async.private_data,
64 struct wb_irpc_SamLogon_state);
65 NTSTATUS status;
67 DEBUG(5, ("wb_irpc_SamLogon_callback called\n"));
69 status = wb_sam_logon_recv(ctx, s, s->req);
71 irpc_send_reply(s->msg, status);
74 struct wb_irpc_get_idmap_state {
75 struct irpc_message *msg;
76 struct winbind_get_idmap *req;
77 int level;
80 static void wb_irpc_get_idmap_callback(struct composite_context *ctx);
82 static NTSTATUS wb_irpc_get_idmap(struct irpc_message *msg,
83 struct winbind_get_idmap *req)
85 struct wbsrv_service *service = talloc_get_type(msg->private_data,
86 struct wbsrv_service);
87 struct wb_irpc_get_idmap_state *s;
88 struct composite_context *ctx = NULL;
90 DEBUG(5, ("wb_irpc_get_idmap called\n"));
92 s = talloc(msg, struct wb_irpc_get_idmap_state);
93 NT_STATUS_HAVE_NO_MEMORY(s);
95 s->msg = msg;
96 s->req = req;
97 s->level = req->in.level;
99 switch(s->level) {
100 case WINBIND_IDMAP_LEVEL_SIDS_TO_XIDS:
101 ctx = wb_sids2xids_send(msg, service, req->in.count,
102 req->in.ids);
103 break;
104 case WINBIND_IDMAP_LEVEL_XIDS_TO_SIDS:
105 ctx = wb_xids2sids_send(msg, service, req->in.count,
106 req->in.ids);
107 break;
109 NT_STATUS_HAVE_NO_MEMORY(ctx);
111 composite_continue(ctx, ctx, wb_irpc_get_idmap_callback, s);
112 msg->defer_reply = true;
114 return NT_STATUS_OK;
117 static void wb_irpc_get_idmap_callback(struct composite_context *ctx)
119 struct wb_irpc_get_idmap_state *s;
120 NTSTATUS status;
122 DEBUG(5, ("wb_irpc_get_idmap_callback called\n"));
124 s = talloc_get_type(ctx->async.private_data,
125 struct wb_irpc_get_idmap_state);
127 switch(s->level) {
128 case WINBIND_IDMAP_LEVEL_SIDS_TO_XIDS:
129 status = wb_sids2xids_recv(ctx, &s->req->out.ids);
130 break;
131 case WINBIND_IDMAP_LEVEL_XIDS_TO_SIDS:
132 status = wb_xids2sids_recv(ctx, &s->req->out.ids);
133 break;
134 default:
135 status = NT_STATUS_INTERNAL_ERROR;
136 break;
139 irpc_send_reply(s->msg, status);
142 NTSTATUS wbsrv_init_irpc(struct wbsrv_service *service)
144 NTSTATUS status;
146 irpc_add_name(service->task->msg_ctx, "winbind_server");
148 status = IRPC_REGISTER(service->task->msg_ctx, winbind, WINBIND_SAMLOGON,
149 wb_irpc_SamLogon, service);
150 NT_STATUS_NOT_OK_RETURN(status);
152 status = IRPC_REGISTER(service->task->msg_ctx, winbind, WINBIND_GET_IDMAP,
153 wb_irpc_get_idmap, service);
154 NT_STATUS_NOT_OK_RETURN(status);
156 return NT_STATUS_OK;