6c060d94347913425a6ad1081c5ae80d29786a80
[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 3 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, see <http://www.gnu.org/licenses/>.
19 */
20
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"
27
28 struct wb_irpc_SamLogon_state {
29         struct irpc_message *msg;
30         struct winbind_SamLogon *req;
31 };
32
33 static void wb_irpc_SamLogon_callback(struct tevent_req *subreq);
34
35 static NTSTATUS wb_irpc_SamLogon(struct irpc_message *msg, 
36                                  struct winbind_SamLogon *req)
37 {
38         struct wbsrv_service *service = talloc_get_type(msg->private_data,
39                                         struct wbsrv_service);
40         struct wb_irpc_SamLogon_state *s;
41         struct tevent_req *subreq;
42
43         DEBUG(5, ("wb_irpc_SamLogon called\n"));
44
45         s = talloc(msg, struct wb_irpc_SamLogon_state);
46         NT_STATUS_HAVE_NO_MEMORY(s);
47
48         s->msg = msg;
49         s->req = req;
50
51         subreq = wb_sam_logon_send(s,
52                                    service->task->event_ctx,
53                                    service, req);
54         NT_STATUS_HAVE_NO_MEMORY(subreq);
55
56         tevent_req_set_callback(subreq, wb_irpc_SamLogon_callback, s);
57
58         msg->defer_reply = true;
59         return NT_STATUS_OK;
60 }
61
62 static void wb_irpc_SamLogon_callback(struct tevent_req *subreq)
63 {
64         struct wb_irpc_SamLogon_state *s =
65                 tevent_req_callback_data(subreq,
66                 struct wb_irpc_SamLogon_state);
67         NTSTATUS status;
68
69         DEBUG(5, ("wb_irpc_SamLogon_callback called\n"));
70
71         status = wb_sam_logon_recv(subreq, s, s->req);
72         TALLOC_FREE(subreq);
73
74         irpc_send_reply(s->msg, status);
75 }
76
77 struct wb_irpc_DsrUpdateReadOnlyServerDnsRecords_state {
78         struct irpc_message *msg;
79         struct winbind_DsrUpdateReadOnlyServerDnsRecords *req;
80 };
81
82 static void wb_irpc_DsrUpdateReadOnlyServerDnsRecords_callback(struct composite_context *ctx);
83
84 static NTSTATUS wb_irpc_DsrUpdateReadOnlyServerDnsRecords(struct irpc_message *msg,
85                                  struct winbind_DsrUpdateReadOnlyServerDnsRecords *req)
86 {
87         struct wbsrv_service *service = talloc_get_type(msg->private_data,
88                                         struct wbsrv_service);
89         struct wb_irpc_DsrUpdateReadOnlyServerDnsRecords_state *s;
90         struct composite_context *ctx;
91
92         DEBUG(5, ("wb_irpc_DsrUpdateReadOnlyServerDnsRecords called\n"));
93
94         s = talloc(msg, struct wb_irpc_DsrUpdateReadOnlyServerDnsRecords_state);
95         NT_STATUS_HAVE_NO_MEMORY(s);
96
97         s->msg = msg;
98         s->req = req;
99
100         ctx = wb_update_rodc_dns_send(msg, service, req);
101         NT_STATUS_HAVE_NO_MEMORY(ctx);
102
103         ctx->async.fn = wb_irpc_DsrUpdateReadOnlyServerDnsRecords_callback;
104         ctx->async.private_data = s;
105
106         msg->defer_reply = true;
107         return NT_STATUS_OK;
108 }
109
110 static void wb_irpc_DsrUpdateReadOnlyServerDnsRecords_callback(struct composite_context *ctx)
111 {
112         struct wb_irpc_DsrUpdateReadOnlyServerDnsRecords_state *s = talloc_get_type(ctx->async.private_data,
113                                            struct wb_irpc_DsrUpdateReadOnlyServerDnsRecords_state);
114         NTSTATUS status;
115
116         DEBUG(5, ("wb_irpc_DsrUpdateReadOnlyServerDnsRecords_callback called\n"));
117
118         status = wb_update_rodc_dns_recv(ctx, s, s->req);
119
120         irpc_send_reply(s->msg, status);
121 }
122
123 struct wb_irpc_get_idmap_state {
124         struct irpc_message *msg;
125         struct winbind_get_idmap *req;
126         int level;
127 };
128
129 static void wb_irpc_get_idmap_callback(struct composite_context *ctx);
130
131 static NTSTATUS wb_irpc_get_idmap(struct irpc_message *msg,
132                                   struct winbind_get_idmap *req)
133 {
134         struct wbsrv_service *service = talloc_get_type(msg->private_data,
135                                         struct wbsrv_service);
136         struct wb_irpc_get_idmap_state *s;
137         struct composite_context *ctx = NULL;
138
139         DEBUG(5, ("wb_irpc_get_idmap called\n"));
140
141         s = talloc(msg, struct wb_irpc_get_idmap_state);
142         NT_STATUS_HAVE_NO_MEMORY(s);
143
144         s->msg = msg;
145         s->req = req;
146         s->level = req->in.level;
147
148         switch(s->level) {
149                 case WINBIND_IDMAP_LEVEL_SIDS_TO_XIDS:
150                         ctx = wb_sids2xids_send(msg, service, req->in.count,
151                                                 req->in.ids);
152                         break;
153                 case WINBIND_IDMAP_LEVEL_XIDS_TO_SIDS:
154                         ctx = wb_xids2sids_send(msg, service, req->in.count,
155                                                 req->in.ids);
156                         break;
157         }
158         NT_STATUS_HAVE_NO_MEMORY(ctx);
159
160         composite_continue(ctx, ctx, wb_irpc_get_idmap_callback, s);
161         msg->defer_reply = true;
162
163         return NT_STATUS_OK;
164 }
165
166 static void wb_irpc_get_idmap_callback(struct composite_context *ctx)
167 {
168         struct wb_irpc_get_idmap_state *s;
169         NTSTATUS status;
170
171         DEBUG(5, ("wb_irpc_get_idmap_callback called\n"));
172
173         s = talloc_get_type(ctx->async.private_data,
174                             struct wb_irpc_get_idmap_state);
175
176         switch(s->level) {
177                 case WINBIND_IDMAP_LEVEL_SIDS_TO_XIDS:
178                         status = wb_sids2xids_recv(ctx, &s->req->out.ids, NULL);
179                         break;
180                 case WINBIND_IDMAP_LEVEL_XIDS_TO_SIDS:
181                         status = wb_xids2sids_recv(ctx, &s->req->out.ids);
182                         break;
183                 default:
184                         status = NT_STATUS_INTERNAL_ERROR;
185                         break;
186         }
187
188         irpc_send_reply(s->msg, status);
189 }
190
191 NTSTATUS wbsrv_init_irpc(struct wbsrv_service *service)
192 {
193         NTSTATUS status;
194
195         irpc_add_name(service->task->msg_ctx, "winbind_server");
196
197         status = IRPC_REGISTER(service->task->msg_ctx, winbind, WINBIND_SAMLOGON,
198                                wb_irpc_SamLogon, service);
199         NT_STATUS_NOT_OK_RETURN(status);
200
201         status = IRPC_REGISTER(service->task->msg_ctx, winbind, WINBIND_DSRUPDATEREADONLYSERVERDNSRECORDS,
202                                wb_irpc_DsrUpdateReadOnlyServerDnsRecords, service);
203         NT_STATUS_NOT_OK_RETURN(status);
204
205         status = IRPC_REGISTER(service->task->msg_ctx, winbind, WINBIND_GET_IDMAP,
206                                wb_irpc_get_idmap, service);
207         NT_STATUS_NOT_OK_RETURN(status);
208
209         return NT_STATUS_OK;
210 }