06e2f75ead45753855b5f45913e5c551423c0b59
[kai/samba.git] / source3 / rpc_server / srv_netlog.c
1 /* 
2  *  Unix SMB/Netbios implementation.
3  *  Version 1.9.
4  *  RPC Pipe client / server routines
5  *  Copyright (C) Andrew Tridgell              1992-1997,
6  *  Copyright (C) Luke Kenneth Casson Leighton 1996-1997,
7  *  Copyright (C) Paul Ashton                       1997.
8  *  Copyright (C) Jeremy Allison               1998-2001.
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 /*************************************************************************
30  api_net_req_chal:
31  *************************************************************************/
32
33 static BOOL api_net_req_chal(pipes_struct *p)
34 {
35         NET_Q_REQ_CHAL q_u;
36         NET_R_REQ_CHAL r_u;
37         prs_struct *data = &p->in_data.data;
38         prs_struct *rdata = &p->out_data.rdata;
39
40         ZERO_STRUCT(q_u);
41         ZERO_STRUCT(r_u);
42
43         /* grab the challenge... */
44         if(!net_io_q_req_chal("", &q_u, data, 0)) {
45                 DEBUG(0,("api_net_req_chal: Failed to unmarshall NET_Q_REQ_CHAL.\n"));
46                 return False;
47         }
48
49         r_u.status = _net_req_chal(p, &q_u, &r_u);
50
51         /* store the response in the SMB stream */
52         if(!net_io_r_req_chal("", &r_u, rdata, 0)) {
53                 DEBUG(0,("api_net_req_chal: Failed to marshall NET_R_REQ_CHAL.\n"));
54                 return False;
55         }
56
57         return True;
58 }
59
60 /*************************************************************************
61  api_net_auth:
62  *************************************************************************/
63
64 static BOOL api_net_auth(pipes_struct *p)
65 {
66         NET_Q_AUTH q_u;
67         NET_R_AUTH r_u;
68         prs_struct *data = &p->in_data.data;
69         prs_struct *rdata = &p->out_data.rdata;
70
71         ZERO_STRUCT(q_u);
72         ZERO_STRUCT(r_u);
73
74         /* grab the challenge... */
75         if(!net_io_q_auth("", &q_u, data, 0)) {
76                 DEBUG(0,("api_net_auth: Failed to unmarshall NET_Q_AUTH.\n"));
77                 return False;
78         }
79
80         r_u.status = _net_auth(p, &q_u, &r_u);
81
82         /* store the response in the SMB stream */
83         if(!net_io_r_auth("", &r_u, rdata, 0)) {
84                 DEBUG(0,("api_net_auth: Failed to marshall NET_R_AUTH.\n"));
85                 return False;
86         }
87
88         return True;
89 }
90
91 /*************************************************************************
92  api_net_auth_2:
93  *************************************************************************/
94
95 static BOOL api_net_auth_2(pipes_struct *p)
96 {
97         NET_Q_AUTH_2 q_u;
98         NET_R_AUTH_2 r_u;
99         prs_struct *data = &p->in_data.data;
100         prs_struct *rdata = &p->out_data.rdata;
101
102         ZERO_STRUCT(q_u);
103         ZERO_STRUCT(r_u);
104
105         /* grab the challenge... */
106         if(!net_io_q_auth_2("", &q_u, data, 0)) {
107                 DEBUG(0,("api_net_auth_2: Failed to unmarshall NET_Q_AUTH_2.\n"));
108                 return False;
109         }
110
111         r_u.status = _net_auth_2(p, &q_u, &r_u);
112
113         /* store the response in the SMB stream */
114         if(!net_io_r_auth_2("", &r_u, rdata, 0)) {
115                 DEBUG(0,("api_net_auth_2: Failed to marshall NET_R_AUTH_2.\n"));
116                 return False;
117         }
118
119         return True;
120 }
121
122 /*************************************************************************
123  api_net_srv_pwset:
124  *************************************************************************/
125
126 static BOOL api_net_srv_pwset(pipes_struct *p)
127 {
128         NET_Q_SRV_PWSET q_u;
129         NET_R_SRV_PWSET r_u;
130         prs_struct *data = &p->in_data.data;
131         prs_struct *rdata = &p->out_data.rdata;
132
133         ZERO_STRUCT(q_u);
134         ZERO_STRUCT(r_u);
135
136         /* grab the challenge and encrypted password ... */
137         if(!net_io_q_srv_pwset("", &q_u, data, 0)) {
138                 DEBUG(0,("api_net_srv_pwset: Failed to unmarshall NET_Q_SRV_PWSET.\n"));
139                 return False;
140         }
141
142         r_u.status = _net_srv_pwset(p, &q_u, &r_u);
143
144         /* store the response in the SMB stream */
145         if(!net_io_r_srv_pwset("", &r_u, rdata, 0)) {
146                 DEBUG(0,("api_net_srv_pwset: Failed to marshall NET_R_SRV_PWSET.\n"));
147                 return False;
148         }
149
150         return True;
151 }
152
153 /*************************************************************************
154  api_net_sam_logoff:
155  *************************************************************************/
156
157 static BOOL api_net_sam_logoff(pipes_struct *p)
158 {
159         NET_Q_SAM_LOGOFF q_u;
160         NET_R_SAM_LOGOFF r_u;
161         prs_struct *data = &p->in_data.data;
162         prs_struct *rdata = &p->out_data.rdata;
163
164         ZERO_STRUCT(q_u);
165         ZERO_STRUCT(r_u);
166
167         if(!net_io_q_sam_logoff("", &q_u, data, 0)) {
168                 DEBUG(0,("api_net_sam_logoff: Failed to unmarshall NET_Q_SAM_LOGOFF.\n"));
169                 return False;
170         }
171
172         r_u.status = _net_sam_logoff(p, &q_u, &r_u);
173
174         /* store the response in the SMB stream */
175         if(!net_io_r_sam_logoff("", &r_u, rdata, 0)) {
176                 DEBUG(0,("api_net_sam_logoff: Failed to marshall NET_R_SAM_LOGOFF.\n"));
177                 return False;
178         }
179
180         return True;
181 }
182
183 /*************************************************************************
184  api_net_sam_logon:
185  *************************************************************************/
186
187 static BOOL api_net_sam_logon(pipes_struct *p)
188 {
189         NET_Q_SAM_LOGON q_u;
190         NET_R_SAM_LOGON r_u;
191         prs_struct *data = &p->in_data.data;
192         prs_struct *rdata = &p->out_data.rdata;
193     
194         ZERO_STRUCT(q_u);
195         ZERO_STRUCT(r_u);
196
197     if(!net_io_q_sam_logon("", &q_u, data, 0)) {
198         DEBUG(0, ("api_net_sam_logon: Failed to unmarshall NET_Q_SAM_LOGON.\n"));
199         return False;
200     }
201    
202         r_u.status = _net_sam_logon(p, &q_u, &r_u);
203
204         /* store the response in the SMB stream */
205         if(!net_io_r_sam_logon("", &r_u, rdata, 0)) {
206                 DEBUG(0,("api_net_sam_logon: Failed to marshall NET_R_SAM_LOGON.\n"));
207                 return False;
208         }
209
210     return True;
211 }
212
213 /*************************************************************************
214  api_net_trust_dom_list:
215  *************************************************************************/
216
217 static BOOL api_net_trust_dom_list(pipes_struct *p)
218 {
219         NET_Q_TRUST_DOM_LIST q_u;
220         NET_R_TRUST_DOM_LIST r_u;
221         prs_struct *data = &p->in_data.data;
222         prs_struct *rdata = &p->out_data.rdata;
223
224         ZERO_STRUCT(q_u);
225         ZERO_STRUCT(r_u);
226
227         DEBUG(6,("api_net_trust_dom_list: %d\n", __LINE__));
228
229         /* grab the lsa trusted domain list query... */
230         if(!net_io_q_trust_dom("", &q_u, data, 0)) {
231                 DEBUG(0,("api_net_trust_dom_list: Failed to unmarshall NET_Q_TRUST_DOM_LIST.\n"));
232                 return False;
233         }
234
235         /* construct reply. */
236         r_u.status = _net_trust_dom_list(p, &q_u, &r_u);
237
238         /* store the response in the SMB stream */
239         if(!net_io_r_trust_dom("", &r_u, rdata, 0)) {
240                 DEBUG(0,("net_reply_trust_dom_list: Failed to marshall NET_R_TRUST_DOM_LIST.\n"));
241                 return False;
242         }
243
244         DEBUG(6,("api_net_trust_dom_list: %d\n", __LINE__));
245
246         return True;
247 }
248
249 /*************************************************************************
250  api_net_logon_ctrl2:
251  *************************************************************************/
252
253 static BOOL api_net_logon_ctrl2(pipes_struct *p)
254 {
255         NET_Q_LOGON_CTRL2 q_u;
256         NET_R_LOGON_CTRL2 r_u;
257         prs_struct *data = &p->in_data.data;
258         prs_struct *rdata = &p->out_data.rdata;
259
260         ZERO_STRUCT(q_u);
261         ZERO_STRUCT(r_u);
262
263         DEBUG(6,("api_net_logon_ctrl2: %d\n", __LINE__));
264
265         /* grab the lsa netlogon ctrl2 query... */
266         if(!net_io_q_logon_ctrl2("", &q_u, data, 0)) {
267                 DEBUG(0,("api_net_logon_ctrl2: Failed to unmarshall NET_Q_LOGON_CTRL2.\n"));
268                 return False;
269         }
270
271         r_u.status = _net_logon_ctrl2(p, &q_u, &r_u);
272
273         if(!net_io_r_logon_ctrl2("", &r_u, rdata, 0)) {
274                 DEBUG(0,("net_reply_logon_ctrl2: Failed to marshall NET_R_LOGON_CTRL2.\n"));
275                 return False;
276         }
277
278         DEBUG(6,("api_net_logon_ctrl2: %d\n", __LINE__));
279
280         return True;
281 }
282
283 /*************************************************************************
284  api_net_logon_ctrl:
285  *************************************************************************/
286
287 static BOOL api_net_logon_ctrl(pipes_struct *p)
288 {
289         NET_Q_LOGON_CTRL q_u;
290         NET_R_LOGON_CTRL r_u;
291         prs_struct *data = &p->in_data.data;
292         prs_struct *rdata = &p->out_data.rdata;
293
294         ZERO_STRUCT(q_u);
295         ZERO_STRUCT(r_u);
296
297         DEBUG(6,("api_net_logon_ctrl: %d\n", __LINE__));
298
299         /* grab the lsa netlogon ctrl query... */
300         if(!net_io_q_logon_ctrl("", &q_u, data, 0)) {
301                 DEBUG(0,("api_net_logon_ctrl: Failed to unmarshall NET_Q_LOGON_CTRL.\n"));
302                 return False;
303         }
304
305         r_u.status = _net_logon_ctrl(p, &q_u, &r_u);
306
307         if(!net_io_r_logon_ctrl("", &r_u, rdata, 0)) {
308                 DEBUG(0,("net_reply_logon_ctrl2: Failed to marshall NET_R_LOGON_CTRL2.\n"));
309                 return False;
310         }
311
312         DEBUG(6,("api_net_logon_ctrl2: %d\n", __LINE__));
313
314         return True;
315 }
316
317 /*******************************************************************
318  array of \PIPE\NETLOGON operations
319  ********************************************************************/
320 static struct api_struct api_net_cmds [] =
321 {
322         { "NET_REQCHAL"       , NET_REQCHAL       , api_net_req_chal       }, 
323         { "NET_AUTH"          , NET_AUTH          , api_net_auth           }, 
324         { "NET_AUTH2"         , NET_AUTH2         , api_net_auth_2         }, 
325         { "NET_SRVPWSET"      , NET_SRVPWSET      , api_net_srv_pwset      }, 
326         { "NET_SAMLOGON"      , NET_SAMLOGON      , api_net_sam_logon      }, 
327         { "NET_SAMLOGOFF"     , NET_SAMLOGOFF     , api_net_sam_logoff     }, 
328         { "NET_LOGON_CTRL2"   , NET_LOGON_CTRL2   , api_net_logon_ctrl2    }, 
329         { "NET_TRUST_DOM_LIST", NET_TRUST_DOM_LIST, api_net_trust_dom_list },
330         { "NET_LOGON_CTRL"    , NET_LOGON_CTRL    , api_net_logon_ctrl     },
331         {  NULL               , 0                 , NULL                   }
332 };
333
334 /*******************************************************************
335  receives a netlogon pipe and responds.
336  ********************************************************************/
337
338 BOOL api_netlog_rpc(pipes_struct *p)
339 {
340         return api_rpcTNP(p, "api_netlog_rpc", api_net_cmds);
341 }