r17342: implement a SamLogon via IRPC in samba4's winbind
[samba.git] / source4 / winbind / wb_irpc.c
1 /* 
2    Unix SMB/CIFS implementation.
3    Main winbindd irpc handlers
4
5    Copyright (C) Stefan Metzmacher      2006
6    
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 2 of the License, or
10    (at your option) any later version.
11    
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.
16    
17    You should have received a copy of the GNU General Public License
18    along with this program; if not, write to the Free Software
19    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 */
21
22 #include "includes.h"
23 #include "winbind/wb_server.h"
24 #include "lib/messaging/irpc.h"
25 #include "libcli/composite/composite.h"
26 #include "librpc/gen_ndr/ndr_winbind.h"
27 #include "smbd/service_task.h"
28
29 struct wb_irpc_SamLogon_state {
30         struct irpc_message *msg;
31         struct winbind_SamLogon *req;
32 };
33
34 static void wb_irpc_SamLogon_callback(struct composite_context *ctx);
35
36 static NTSTATUS wb_irpc_SamLogon(struct irpc_message *msg, 
37                                  struct winbind_SamLogon *req)
38 {
39         struct wbsrv_service *service = talloc_get_type(msg->private,
40                                         struct wbsrv_service);
41         struct wb_irpc_SamLogon_state *s;
42         struct composite_context *ctx;
43
44         DEBUG(5, ("wb_irpc_SamLogon called\n"));
45
46         s = talloc(msg, struct wb_irpc_SamLogon_state);
47         NT_STATUS_HAVE_NO_MEMORY(s);
48
49         s->msg = msg;
50         s->req = req;
51
52         ctx = wb_sam_logon_send(msg, service, req);
53         NT_STATUS_HAVE_NO_MEMORY(ctx);
54
55         ctx->async.fn = wb_irpc_SamLogon_callback;
56         ctx->async.private_data = s;
57
58         msg->defer_reply = True;
59         return NT_STATUS_OK;
60 }
61
62 static void wb_irpc_SamLogon_callback(struct composite_context *ctx)
63 {
64         struct wb_irpc_SamLogon_state *s = talloc_get_type(ctx->async.private_data,
65                                            struct wb_irpc_SamLogon_state);
66         NTSTATUS status;
67
68         DEBUG(5, ("wb_irpc_SamLogon_callback called\n"));
69
70         status = wb_sam_logon_recv(ctx, s, s->req);
71
72         irpc_send_reply(s->msg, status);
73 }
74
75 NTSTATUS wbsrv_init_irpc(struct wbsrv_service *service)
76 {
77         NTSTATUS status;
78
79         irpc_add_name(service->task->msg_ctx, "winbind_server");
80
81         status = IRPC_REGISTER(service->task->msg_ctx, winbind, WINBIND_SAMLOGON,
82                                wb_irpc_SamLogon, service);
83         NT_STATUS_NOT_OK_RETURN(status);
84
85         return NT_STATUS_OK;
86 }