r21563: Fix a memleak: We only need dispinfo structs for "our" and for the builtin
[kai/samba.git] / source / rpc_server / srv_netlog.c
1 /* 
2  *  Unix SMB/CIFS implementation.
3  *  RPC Pipe client / server routines
4  *  Copyright (C) Andrew Tridgell              1992-1997,
5  *  Copyright (C) Luke Kenneth Casson Leighton 1996-1997,
6  *  Copyright (C) Paul Ashton                       1997,
7  *  Copyright (C) Jeremy Allison               1998-2001,
8  *  Copyright (C) Jim McDonough <jmcd@us.ibm.com>   2003.
9  *
10  *  This program is free software; you can redistribute it and/or modify
11  *  it under the terms of the GNU General Public License as published by
12  *  the Free Software Foundation; either version 2 of the License, or
13  *  (at your option) any later version.
14  *  
15  *  This program is distributed in the hope that it will be useful,
16  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
17  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  *  GNU General Public License for more details.
19  *  
20  *  You should have received a copy of the GNU General Public License
21  *  along with this program; if not, write to the Free Software
22  *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23  */
24
25 /* This is the interface to the netlogon pipe. */
26
27 #include "includes.h"
28
29 #undef DBGC_CLASS
30 #define DBGC_CLASS DBGC_RPC_SRV
31
32 /*************************************************************************
33  api_net_req_chal:
34  *************************************************************************/
35
36 static BOOL api_net_req_chal(pipes_struct *p)
37 {
38         NET_Q_REQ_CHAL q_u;
39         NET_R_REQ_CHAL r_u;
40         prs_struct *data = &p->in_data.data;
41         prs_struct *rdata = &p->out_data.rdata;
42
43         ZERO_STRUCT(q_u);
44         ZERO_STRUCT(r_u);
45
46         /* grab the challenge... */
47         if(!net_io_q_req_chal("", &q_u, data, 0)) {
48                 DEBUG(0,("api_net_req_chal: Failed to unmarshall NET_Q_REQ_CHAL.\n"));
49                 return False;
50         }
51
52         r_u.status = _net_req_chal(p, &q_u, &r_u);
53
54         /* store the response in the SMB stream */
55         if(!net_io_r_req_chal("", &r_u, rdata, 0)) {
56                 DEBUG(0,("api_net_req_chal: Failed to marshall NET_R_REQ_CHAL.\n"));
57                 return False;
58         }
59
60         return True;
61 }
62
63 /*************************************************************************
64  api_net_auth:
65  *************************************************************************/
66
67 static BOOL api_net_auth(pipes_struct *p)
68 {
69         NET_Q_AUTH q_u;
70         NET_R_AUTH r_u;
71         prs_struct *data = &p->in_data.data;
72         prs_struct *rdata = &p->out_data.rdata;
73
74         ZERO_STRUCT(q_u);
75         ZERO_STRUCT(r_u);
76
77         /* grab the challenge... */
78         if(!net_io_q_auth("", &q_u, data, 0)) {
79                 DEBUG(0,("api_net_auth: Failed to unmarshall NET_Q_AUTH.\n"));
80                 return False;
81         }
82
83         r_u.status = _net_auth(p, &q_u, &r_u);
84
85         /* store the response in the SMB stream */
86         if(!net_io_r_auth("", &r_u, rdata, 0)) {
87                 DEBUG(0,("api_net_auth: Failed to marshall NET_R_AUTH.\n"));
88                 return False;
89         }
90
91         return True;
92 }
93
94 /*************************************************************************
95  api_net_auth_2:
96  *************************************************************************/
97
98 static BOOL api_net_auth_2(pipes_struct *p)
99 {
100         NET_Q_AUTH_2 q_u;
101         NET_R_AUTH_2 r_u;
102         prs_struct *data = &p->in_data.data;
103         prs_struct *rdata = &p->out_data.rdata;
104
105         ZERO_STRUCT(q_u);
106         ZERO_STRUCT(r_u);
107
108         /* grab the challenge... */
109         if(!net_io_q_auth_2("", &q_u, data, 0)) {
110                 DEBUG(0,("api_net_auth_2: Failed to unmarshall NET_Q_AUTH_2.\n"));
111                 return False;
112         }
113
114         r_u.status = _net_auth_2(p, &q_u, &r_u);
115
116         /* store the response in the SMB stream */
117         if(!net_io_r_auth_2("", &r_u, rdata, 0)) {
118                 DEBUG(0,("api_net_auth_2: Failed to marshall NET_R_AUTH_2.\n"));
119                 return False;
120         }
121
122         return True;
123 }
124
125 /*************************************************************************
126  api_net_srv_pwset:
127  *************************************************************************/
128
129 static BOOL api_net_srv_pwset(pipes_struct *p)
130 {
131         NET_Q_SRV_PWSET q_u;
132         NET_R_SRV_PWSET r_u;
133         prs_struct *data = &p->in_data.data;
134         prs_struct *rdata = &p->out_data.rdata;
135
136         ZERO_STRUCT(q_u);
137         ZERO_STRUCT(r_u);
138
139         /* grab the challenge and encrypted password ... */
140         if(!net_io_q_srv_pwset("", &q_u, data, 0)) {
141                 DEBUG(0,("api_net_srv_pwset: Failed to unmarshall NET_Q_SRV_PWSET.\n"));
142                 return False;
143         }
144
145         r_u.status = _net_srv_pwset(p, &q_u, &r_u);
146
147         /* store the response in the SMB stream */
148         if(!net_io_r_srv_pwset("", &r_u, rdata, 0)) {
149                 DEBUG(0,("api_net_srv_pwset: Failed to marshall NET_R_SRV_PWSET.\n"));
150                 return False;
151         }
152
153         return True;
154 }
155
156 /*************************************************************************
157  api_net_sam_logoff:
158  *************************************************************************/
159
160 static BOOL api_net_sam_logoff(pipes_struct *p)
161 {
162         NET_Q_SAM_LOGOFF q_u;
163         NET_R_SAM_LOGOFF r_u;
164         prs_struct *data = &p->in_data.data;
165         prs_struct *rdata = &p->out_data.rdata;
166
167         ZERO_STRUCT(q_u);
168         ZERO_STRUCT(r_u);
169
170         if(!net_io_q_sam_logoff("", &q_u, data, 0)) {
171                 DEBUG(0,("api_net_sam_logoff: Failed to unmarshall NET_Q_SAM_LOGOFF.\n"));
172                 return False;
173         }
174
175         r_u.status = _net_sam_logoff(p, &q_u, &r_u);
176
177         /* store the response in the SMB stream */
178         if(!net_io_r_sam_logoff("", &r_u, rdata, 0)) {
179                 DEBUG(0,("api_net_sam_logoff: Failed to marshall NET_R_SAM_LOGOFF.\n"));
180                 return False;
181         }
182
183         return True;
184 }
185
186 /*************************************************************************
187  api_net_sam_logon:
188  *************************************************************************/
189
190 static BOOL api_net_sam_logon(pipes_struct *p)
191 {
192         NET_Q_SAM_LOGON q_u;
193         NET_R_SAM_LOGON r_u;
194         prs_struct *data = &p->in_data.data;
195         prs_struct *rdata = &p->out_data.rdata;
196     
197         ZERO_STRUCT(q_u);
198         ZERO_STRUCT(r_u);
199
200         if(!net_io_q_sam_logon("", &q_u, data, 0)) {
201                 DEBUG(0, ("api_net_sam_logon: Failed to unmarshall NET_Q_SAM_LOGON.\n"));
202                 return False;
203         }
204    
205         r_u.status = _net_sam_logon(p, &q_u, &r_u);
206
207         /* store the response in the SMB stream */
208         if(!net_io_r_sam_logon("", &r_u, rdata, 0)) {
209                 DEBUG(0,("api_net_sam_logon: Failed to marshall NET_R_SAM_LOGON.\n"));
210                 return False;
211         }
212
213         return True;
214 }
215
216 /*************************************************************************
217  api_net_trust_dom_list:
218  *************************************************************************/
219
220 static BOOL api_net_trust_dom_list(pipes_struct *p)
221 {
222         NET_Q_TRUST_DOM_LIST q_u;
223         NET_R_TRUST_DOM_LIST r_u;
224         prs_struct *data = &p->in_data.data;
225         prs_struct *rdata = &p->out_data.rdata;
226
227         ZERO_STRUCT(q_u);
228         ZERO_STRUCT(r_u);
229
230         /* grab the lsa trusted domain list query... */
231         if(!net_io_q_trust_dom("", &q_u, data, 0)) {
232                 DEBUG(0,("api_net_trust_dom_list: Failed to unmarshall NET_Q_TRUST_DOM_LIST.\n"));
233                 return False;
234         }
235
236         /* construct reply. */
237         r_u.status = _net_trust_dom_list(p, &q_u, &r_u);
238
239         /* store the response in the SMB stream */
240         if(!net_io_r_trust_dom("", &r_u, rdata, 0)) {
241                 DEBUG(0,("net_reply_trust_dom_list: Failed to marshall NET_R_TRUST_DOM_LIST.\n"));
242                 return False;
243         }
244
245         return True;
246 }
247
248 /*************************************************************************
249  api_net_logon_ctrl2:
250  *************************************************************************/
251
252 static BOOL api_net_logon_ctrl2(pipes_struct *p)
253 {
254         NET_Q_LOGON_CTRL2 q_u;
255         NET_R_LOGON_CTRL2 r_u;
256         prs_struct *data = &p->in_data.data;
257         prs_struct *rdata = &p->out_data.rdata;
258
259         ZERO_STRUCT(q_u);
260         ZERO_STRUCT(r_u);
261
262
263         /* grab the lsa netlogon ctrl2 query... */
264         if(!net_io_q_logon_ctrl2("", &q_u, data, 0)) {
265                 DEBUG(0,("api_net_logon_ctrl2: Failed to unmarshall NET_Q_LOGON_CTRL2.\n"));
266                 return False;
267         }
268
269         r_u.status = _net_logon_ctrl2(p, &q_u, &r_u);
270
271         if(!net_io_r_logon_ctrl2("", &r_u, rdata, 0)) {
272                 DEBUG(0,("net_reply_logon_ctrl2: Failed to marshall NET_R_LOGON_CTRL2.\n"));
273                 return False;
274         }
275
276         return True;
277 }
278
279 /*************************************************************************
280  api_net_logon_ctrl:
281  *************************************************************************/
282
283 static BOOL api_net_logon_ctrl(pipes_struct *p)
284 {
285         NET_Q_LOGON_CTRL q_u;
286         NET_R_LOGON_CTRL r_u;
287         prs_struct *data = &p->in_data.data;
288         prs_struct *rdata = &p->out_data.rdata;
289
290         ZERO_STRUCT(q_u);
291         ZERO_STRUCT(r_u);
292
293         /* grab the lsa netlogon ctrl query... */
294         if(!net_io_q_logon_ctrl("", &q_u, data, 0)) {
295                 DEBUG(0,("api_net_logon_ctrl: Failed to unmarshall NET_Q_LOGON_CTRL.\n"));
296                 return False;
297         }
298
299         r_u.status = _net_logon_ctrl(p, &q_u, &r_u);
300
301         if(!net_io_r_logon_ctrl("", &r_u, rdata, 0)) {
302                 DEBUG(0,("net_reply_logon_ctrl2: Failed to marshall NET_R_LOGON_CTRL.\n"));
303                 return False;
304         }
305
306         return True;
307 }
308
309 /*************************************************************************
310  api_net_sam_logon_ex:
311  *************************************************************************/
312
313 static BOOL api_net_sam_logon_ex(pipes_struct *p)
314 {
315         NET_Q_SAM_LOGON_EX q_u;
316         NET_R_SAM_LOGON_EX r_u;
317         prs_struct *data = &p->in_data.data;
318         prs_struct *rdata = &p->out_data.rdata;
319     
320         ZERO_STRUCT(q_u);
321         ZERO_STRUCT(r_u);
322
323         if(!net_io_q_sam_logon_ex("", &q_u, data, 0)) {
324                 DEBUG(0, ("api_net_sam_logon_ex: Failed to unmarshall NET_Q_SAM_LOGON_EX.\n"));
325                 return False;
326         }
327    
328         r_u.status = _net_sam_logon_ex(p, &q_u, &r_u);
329
330         /* store the response in the SMB stream */
331         if(!net_io_r_sam_logon_ex("", &r_u, rdata, 0)) {
332                 DEBUG(0,("api_net_sam_logon_ex: Failed to marshall NET_R_SAM_LOGON_EX.\n"));
333                 return False;
334         }
335
336         return True;
337 }
338
339
340 /*************************************************************************
341  api_ds_enum_dom_trusts:
342  *************************************************************************/
343
344 #if 0   /* JERRY */
345 static BOOL api_ds_enum_dom_trusts(pipes_struct *p)
346 {
347         DS_Q_ENUM_DOM_TRUSTS q_u;
348         DS_R_ENUM_DOM_TRUSTS r_u;
349
350         prs_struct *data = &p->in_data.data;
351         prs_struct *rdata = &p->out_data.rdata;
352
353         ZERO_STRUCT(q_u);
354         ZERO_STRUCT(r_u);
355
356         DEBUG(6,("api_ds_enum_dom_trusts\n"));
357
358         if ( !ds_io_q_enum_domain_trusts("", data, 0, &q_u) ) {
359                 DEBUG(0,("api_ds_enum_domain_trusts: Failed to unmarshall DS_Q_ENUM_DOM_TRUSTS.\n"));
360                 return False;
361         }
362
363         r_u.status = _ds_enum_dom_trusts(p, &q_u, &r_u);
364
365         if ( !ds_io_r_enum_domain_trusts("", rdata, 0, &r_u) ) {
366                 DEBUG(0,("api_ds_enum_domain_trusts: Failed to marshall DS_R_ENUM_DOM_TRUSTS.\n"));
367                 return False;
368         }
369
370         DEBUG(6,("api_ds_enum_dom_trusts\n"));
371
372         return True;
373 }
374 #endif  /* JERRY */
375
376 /*******************************************************************
377  array of \PIPE\NETLOGON operations
378  ********************************************************************/
379 static struct api_struct api_net_cmds [] =
380     {
381       { "NET_REQCHAL"       , NET_REQCHAL       , api_net_req_chal       }, 
382       { "NET_AUTH"          , NET_AUTH          , api_net_auth           }, 
383       { "NET_AUTH2"         , NET_AUTH2         , api_net_auth_2         }, 
384       { "NET_SRVPWSET"      , NET_SRVPWSET      , api_net_srv_pwset      }, 
385       { "NET_SAMLOGON"      , NET_SAMLOGON      , api_net_sam_logon      }, 
386       { "NET_SAMLOGOFF"     , NET_SAMLOGOFF     , api_net_sam_logoff     }, 
387       { "NET_LOGON_CTRL2"   , NET_LOGON_CTRL2   , api_net_logon_ctrl2    }, 
388       { "NET_TRUST_DOM_LIST", NET_TRUST_DOM_LIST, api_net_trust_dom_list },
389       { "NET_LOGON_CTRL"    , NET_LOGON_CTRL    , api_net_logon_ctrl     },
390       { "NET_SAMLOGON_EX"   , NET_SAMLOGON_EX   , api_net_sam_logon_ex   },
391 #if 0   /* JERRY */
392       { "DS_ENUM_DOM_TRUSTS", DS_ENUM_DOM_TRUSTS, api_ds_enum_dom_trusts }
393 #endif  /* JERRY */
394     };
395
396 void netlog_get_pipe_fns( struct api_struct **fns, int *n_fns )
397 {
398         *fns = api_net_cmds;
399         *n_fns = sizeof(api_net_cmds) / sizeof(struct api_struct);
400 }
401
402 NTSTATUS rpc_net_init(void)
403 {
404   return rpc_pipe_register_commands(SMB_RPC_INTERFACE_VERSION, "NETLOGON", "lsass", api_net_cmds,
405                                     sizeof(api_net_cmds) / sizeof(struct api_struct));
406 }