Changed again how the privilege list is handled in the group mapping code.
[samba.git] / source3 / rpc_server / srv_lsa.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                    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 lsa server code. */
26
27 #include "includes.h"
28
29 /***************************************************************************
30  api_lsa_open_policy2
31  ***************************************************************************/
32
33 static BOOL api_lsa_open_policy2(pipes_struct *p)
34 {
35         LSA_Q_OPEN_POL2 q_u;
36         LSA_R_OPEN_POL2 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 server, object attributes and desired access flag...*/
44         if(!lsa_io_q_open_pol2("", &q_u, data, 0)) {
45                 DEBUG(0,("api_lsa_open_policy2: unable to unmarshall LSA_Q_OPEN_POL2.\n"));
46                 return False;
47         }
48
49         r_u.status = _lsa_open_policy2(p, &q_u, &r_u);
50
51         /* store the response in the SMB stream */
52         if(!lsa_io_r_open_pol2("", &r_u, rdata, 0)) {
53                 DEBUG(0,("api_lsa_open_policy2: unable to marshall LSA_R_OPEN_POL2.\n"));
54                 return False;
55         }
56
57         return True;
58 }
59
60 /***************************************************************************
61 api_lsa_open_policy
62  ***************************************************************************/
63
64 static BOOL api_lsa_open_policy(pipes_struct *p)
65 {
66         LSA_Q_OPEN_POL q_u;
67         LSA_R_OPEN_POL 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 server, object attributes and desired access flag...*/
75         if(!lsa_io_q_open_pol("", &q_u, data, 0)) {
76                 DEBUG(0,("api_lsa_open_policy: unable to unmarshall LSA_Q_OPEN_POL.\n"));
77                 return False;
78         }
79
80         r_u.status = _lsa_open_policy(p, &q_u, &r_u);
81
82         /* store the response in the SMB stream */
83         if(!lsa_io_r_open_pol("", &r_u, rdata, 0)) {
84                 DEBUG(0,("api_lsa_open_policy: unable to marshall LSA_R_OPEN_POL.\n"));
85                 return False;
86         }
87
88         return True;
89 }
90
91 /***************************************************************************
92  api_lsa_enum_trust_dom
93  ***************************************************************************/
94
95 static BOOL api_lsa_enum_trust_dom(pipes_struct *p)
96 {
97         LSA_Q_ENUM_TRUST_DOM q_u;
98         LSA_R_ENUM_TRUST_DOM 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 enum trust domain context etc. */
106         if(!lsa_io_q_enum_trust_dom("", &q_u, data, 0))
107                 return False;
108
109         r_u.status = _lsa_enum_trust_dom(p, &q_u, &r_u);
110
111         if(!lsa_io_r_enum_trust_dom("", &r_u, rdata, 0))
112                 return False;
113
114         return True;
115 }
116
117 /***************************************************************************
118  api_lsa_query_info
119  ***************************************************************************/
120
121 static BOOL api_lsa_query_info(pipes_struct *p)
122 {
123         LSA_Q_QUERY_INFO q_u;
124         LSA_R_QUERY_INFO r_u;
125         prs_struct *data = &p->in_data.data;
126         prs_struct *rdata = &p->out_data.rdata;
127
128         ZERO_STRUCT(q_u);
129         ZERO_STRUCT(r_u);
130
131         /* grab the info class and policy handle */
132         if(!lsa_io_q_query("", &q_u, data, 0)) {
133                 DEBUG(0,("api_lsa_query_info: failed to unmarshall LSA_Q_QUERY_INFO.\n"));
134                 return False;
135         }
136
137         r_u.status = _lsa_query_info(p, &q_u, &r_u);
138
139         /* store the response in the SMB stream */
140         if(!lsa_io_r_query("", &r_u, rdata, 0)) {
141                 DEBUG(0,("api_lsa_query_info: failed to marshall LSA_R_QUERY_INFO.\n"));
142                 return False;
143         }
144
145         return True;
146 }
147
148 /***************************************************************************
149  api_lsa_lookup_sids
150  ***************************************************************************/
151
152 static BOOL api_lsa_lookup_sids(pipes_struct *p)
153 {
154         LSA_Q_LOOKUP_SIDS q_u;
155         LSA_R_LOOKUP_SIDS r_u;
156         prs_struct *data = &p->in_data.data;
157         prs_struct *rdata = &p->out_data.rdata;
158
159         ZERO_STRUCT(q_u);
160         ZERO_STRUCT(r_u);
161
162         /* grab the info class and policy handle */
163         if(!lsa_io_q_lookup_sids("", &q_u, data, 0)) {
164                 DEBUG(0,("api_lsa_lookup_sids: failed to unmarshall LSA_Q_LOOKUP_SIDS.\n"));
165                 return False;
166         }
167
168         r_u.status = _lsa_lookup_sids(p, &q_u, &r_u);
169
170         if(!lsa_io_r_lookup_sids("", &r_u, rdata, 0)) {
171                 DEBUG(0,("api_lsa_lookup_sids: Failed to marshall LSA_R_LOOKUP_SIDS.\n"));
172                 return False;
173         }
174
175         return True;
176 }
177
178 /***************************************************************************
179  api_lsa_lookup_names
180  ***************************************************************************/
181
182 static BOOL api_lsa_lookup_names(pipes_struct *p)
183 {
184         LSA_Q_LOOKUP_NAMES q_u;
185         LSA_R_LOOKUP_NAMES r_u;
186         prs_struct *data = &p->in_data.data;
187         prs_struct *rdata = &p->out_data.rdata;
188
189         ZERO_STRUCT(q_u);
190         ZERO_STRUCT(r_u);
191
192         /* grab the info class and policy handle */
193         if(!lsa_io_q_lookup_names("", &q_u, data, 0)) {
194                 DEBUG(0,("api_lsa_lookup_names: failed to unmarshall LSA_Q_LOOKUP_NAMES.\n"));
195                 return False;
196         }
197
198         r_u.status = _lsa_lookup_names(p, &q_u, &r_u);
199
200         /* store the response in the SMB stream */
201         if(!lsa_io_r_lookup_names("", &r_u, rdata, 0)) {
202                 DEBUG(0,("api_lsa_lookup_names: Failed to marshall LSA_R_LOOKUP_NAMES.\n"));
203                 return False;
204         }
205
206         return True;
207 }
208
209 /***************************************************************************
210  api_lsa_close.
211  ***************************************************************************/
212
213 static BOOL api_lsa_close(pipes_struct *p)
214 {
215         LSA_Q_CLOSE q_u;
216         LSA_R_CLOSE r_u;
217         prs_struct *data = &p->in_data.data;
218         prs_struct *rdata = &p->out_data.rdata;
219
220         ZERO_STRUCT(q_u);
221         ZERO_STRUCT(r_u);
222
223         if (!lsa_io_q_close("", &q_u, data, 0)) {
224                 DEBUG(0,("api_lsa_close: lsa_io_q_close failed.\n"));
225                 return False;
226         }
227
228         r_u.status = _lsa_close(p, &q_u, &r_u);
229
230         /* store the response in the SMB stream */
231         if (!lsa_io_r_close("", &r_u, rdata, 0)) {
232                 DEBUG(0,("api_lsa_close: lsa_io_r_close failed.\n"));
233                 return False;
234         }
235
236         return True;
237 }
238
239 /***************************************************************************
240  api_lsa_open_secret.
241  ***************************************************************************/
242
243 static BOOL api_lsa_open_secret(pipes_struct *p)
244 {
245         LSA_Q_OPEN_SECRET q_u;
246         LSA_R_OPEN_SECRET r_u;
247         prs_struct *data = &p->in_data.data;
248         prs_struct *rdata = &p->out_data.rdata;
249
250         ZERO_STRUCT(q_u);
251         ZERO_STRUCT(r_u);
252
253         if(!lsa_io_q_open_secret("", &q_u, data, 0)) {
254                 DEBUG(0,("api_lsa_open_secret: failed to unmarshall LSA_Q_OPEN_SECRET.\n"));
255                 return False;
256         }
257
258         r_u.status = _lsa_open_secret(p, &q_u, &r_u);
259
260         /* store the response in the SMB stream */
261         if(!lsa_io_r_open_secret("", &r_u, rdata, 0)) {
262                 DEBUG(0,("api_lsa_open_secret: Failed to marshall LSA_R_OPEN_SECRET.\n"));
263                 return False;
264         }
265
266         return True;
267 }
268
269 /***************************************************************************
270  api_lsa_open_secret.
271  ***************************************************************************/
272
273 static BOOL api_lsa_enum_privs(pipes_struct *p)
274 {
275         LSA_Q_ENUM_PRIVS q_u;
276         LSA_R_ENUM_PRIVS r_u;
277         prs_struct *data = &p->in_data.data;
278         prs_struct *rdata = &p->out_data.rdata;
279
280         ZERO_STRUCT(q_u);
281         ZERO_STRUCT(r_u);
282
283         if(!lsa_io_q_enum_privs("", &q_u, data, 0)) {
284                 DEBUG(0,("api_lsa_enum_privs: failed to unmarshall LSA_Q_ENUM_PRIVS.\n"));
285                 return False;
286         }
287
288         r_u.status = _lsa_enum_privs(p, &q_u, &r_u);
289
290         /* store the response in the SMB stream */
291         if(!lsa_io_r_enum_privs("", &r_u, rdata, 0)) {
292                 DEBUG(0,("api_lsa_enum_privs: Failed to marshall LSA_R_ENUM_PRIVS.\n"));
293                 return False;
294         }
295
296         return True;
297 }
298
299 /***************************************************************************
300  api_lsa_open_secret.
301  ***************************************************************************/
302
303 static BOOL api_lsa_priv_get_dispname(pipes_struct *p)
304 {
305         LSA_Q_PRIV_GET_DISPNAME q_u;
306         LSA_R_PRIV_GET_DISPNAME r_u;
307         prs_struct *data = &p->in_data.data;
308         prs_struct *rdata = &p->out_data.rdata;
309
310         ZERO_STRUCT(q_u);
311         ZERO_STRUCT(r_u);
312
313         if(!lsa_io_q_priv_get_dispname("", &q_u, data, 0)) {
314                 DEBUG(0,("api_lsa_priv_get_dispname: failed to unmarshall LSA_Q_PRIV_GET_DISPNAME.\n"));
315                 return False;
316         }
317
318         r_u.status = _lsa_priv_get_dispname(p, &q_u, &r_u);
319
320         /* store the response in the SMB stream */
321         if(!lsa_io_r_priv_get_dispname("", &r_u, rdata, 0)) {
322                 DEBUG(0,("api_lsa_priv_get_dispname: Failed to marshall LSA_R_PRIV_GET_DISPNAME.\n"));
323                 return False;
324         }
325
326         return True;
327 }
328
329 /***************************************************************************
330  api_lsa_open_secret.
331  ***************************************************************************/
332
333 static BOOL api_lsa_enum_accounts(pipes_struct *p)
334 {
335         LSA_Q_ENUM_ACCOUNTS q_u;
336         LSA_R_ENUM_ACCOUNTS r_u;
337         prs_struct *data = &p->in_data.data;
338         prs_struct *rdata = &p->out_data.rdata;
339
340         ZERO_STRUCT(q_u);
341         ZERO_STRUCT(r_u);
342
343         if(!lsa_io_q_enum_accounts("", &q_u, data, 0)) {
344                 DEBUG(0,("api_lsa_enum_accounts: failed to unmarshall LSA_Q_ENUM_ACCOUNTS.\n"));
345                 return False;
346         }
347
348         r_u.status = _lsa_enum_accounts(p, &q_u, &r_u);
349
350         /* store the response in the SMB stream */
351         if(!lsa_io_r_enum_accounts("", &r_u, rdata, 0)) {
352                 DEBUG(0,("api_lsa_enum_accounts: Failed to marshall LSA_R_ENUM_ACCOUNTS.\n"));
353                 return False;
354         }
355
356         return True;
357 }
358
359 /***************************************************************************
360  api_lsa_UNK_GET_CONNUSER
361  ***************************************************************************/
362
363 static BOOL api_lsa_unk_get_connuser(pipes_struct *p)
364 {
365         LSA_Q_UNK_GET_CONNUSER q_u;
366         LSA_R_UNK_GET_CONNUSER r_u;
367         
368         prs_struct *data = &p->in_data.data;
369         prs_struct *rdata = &p->out_data.rdata;
370
371         ZERO_STRUCT(q_u);
372         ZERO_STRUCT(r_u);
373
374         if(!lsa_io_q_unk_get_connuser("", &q_u, data, 0)) {
375                 DEBUG(0,("api_lsa_unk_get_connuser: failed to unmarshall LSA_Q_UNK_GET_CONNUSER.\n"));
376                 return False;
377         }
378
379         r_u.status = _lsa_unk_get_connuser(p, &q_u, &r_u);
380
381         /* store the response in the SMB stream */
382         if(!lsa_io_r_unk_get_connuser("", &r_u, rdata, 0)) {
383                 DEBUG(0,("api_lsa_unk_get_connuser: Failed to marshall LSA_R_UNK_GET_CONNUSER.\n"));
384                 return False;
385         }
386
387         return True;
388 }
389
390 /***************************************************************************
391  api_lsa_open_user
392  ***************************************************************************/
393
394 static BOOL api_lsa_open_account(pipes_struct *p)
395 {
396         LSA_Q_OPENACCOUNT q_u;
397         LSA_R_OPENACCOUNT r_u;
398         
399         prs_struct *data = &p->in_data.data;
400         prs_struct *rdata = &p->out_data.rdata;
401
402         ZERO_STRUCT(q_u);
403         ZERO_STRUCT(r_u);
404
405         if(!lsa_io_q_open_account("", &q_u, data, 0)) {
406                 DEBUG(0,("api_lsa_open_account: failed to unmarshall LSA_Q_OPENACCOUNT.\n"));
407                 return False;
408         }
409
410         r_u.status = _lsa_open_account(p, &q_u, &r_u);
411
412         /* store the response in the SMB stream */
413         if(!lsa_io_r_open_account("", &r_u, rdata, 0)) {
414                 DEBUG(0,("api_lsa_open_account: Failed to marshall LSA_R_OPENACCOUNT.\n"));
415                 return False;
416         }
417
418         return True;
419 }
420
421 /***************************************************************************
422  api_lsa_get_privs
423  ***************************************************************************/
424
425 static BOOL api_lsa_enum_privsaccount(pipes_struct *p)
426 {
427         LSA_Q_ENUMPRIVSACCOUNT q_u;
428         LSA_R_ENUMPRIVSACCOUNT r_u;
429         
430         prs_struct *data = &p->in_data.data;
431         prs_struct *rdata = &p->out_data.rdata;
432
433         ZERO_STRUCT(q_u);
434         ZERO_STRUCT(r_u);
435
436         if(!lsa_io_q_enum_privsaccount("", &q_u, data, 0)) {
437                 DEBUG(0,("api_lsa_enum_privsaccount: failed to unmarshall LSA_Q_ENUMPRIVSACCOUNT.\n"));
438                 return False;
439         }
440
441         r_u.status = _lsa_enum_privsaccount(p, &q_u, &r_u);
442
443         /* store the response in the SMB stream */
444         if(!lsa_io_r_enum_privsaccount("", &r_u, rdata, 0)) {
445                 DEBUG(0,("api_lsa_enum_privsaccount: Failed to marshall LSA_R_ENUMPRIVSACCOUNT.\n"));
446                 return False;
447         }
448
449         return True;
450 }
451
452 /***************************************************************************
453  api_lsa_getsystemaccount
454  ***************************************************************************/
455
456 static BOOL api_lsa_getsystemaccount(pipes_struct *p)
457 {
458         LSA_Q_GETSYSTEMACCOUNT q_u;
459         LSA_R_GETSYSTEMACCOUNT r_u;
460         
461         prs_struct *data = &p->in_data.data;
462         prs_struct *rdata = &p->out_data.rdata;
463
464         ZERO_STRUCT(q_u);
465         ZERO_STRUCT(r_u);
466
467         if(!lsa_io_q_getsystemaccount("", &q_u, data, 0)) {
468                 DEBUG(0,("api_lsa_getsystemaccount: failed to unmarshall LSA_Q_GETSYSTEMACCOUNT.\n"));
469                 return False;
470         }
471
472         r_u.status = _lsa_getsystemaccount(p, &q_u, &r_u);
473
474         /* store the response in the SMB stream */
475         if(!lsa_io_r_getsystemaccount("", &r_u, rdata, 0)) {
476                 DEBUG(0,("api_lsa_getsystemaccount: Failed to marshall LSA_R_GETSYSTEMACCOUNT.\n"));
477                 return False;
478         }
479
480         return True;
481 }
482
483
484 /***************************************************************************
485  api_lsa_setsystemaccount
486  ***************************************************************************/
487
488 static BOOL api_lsa_setsystemaccount(pipes_struct *p)
489 {
490         LSA_Q_SETSYSTEMACCOUNT q_u;
491         LSA_R_SETSYSTEMACCOUNT r_u;
492         
493         prs_struct *data = &p->in_data.data;
494         prs_struct *rdata = &p->out_data.rdata;
495
496         ZERO_STRUCT(q_u);
497         ZERO_STRUCT(r_u);
498
499         if(!lsa_io_q_setsystemaccount("", &q_u, data, 0)) {
500                 DEBUG(0,("api_lsa_setsystemaccount: failed to unmarshall LSA_Q_SETSYSTEMACCOUNT.\n"));
501                 return False;
502         }
503
504         r_u.status = _lsa_setsystemaccount(p, &q_u, &r_u);
505
506         /* store the response in the SMB stream */
507         if(!lsa_io_r_setsystemaccount("", &r_u, rdata, 0)) {
508                 DEBUG(0,("api_lsa_setsystemaccount: Failed to marshall LSA_R_SETSYSTEMACCOUNT.\n"));
509                 return False;
510         }
511
512         return True;
513 }
514
515 /***************************************************************************
516  api_lsa_addprivs
517  ***************************************************************************/
518
519 static BOOL api_lsa_addprivs(pipes_struct *p)
520 {
521         LSA_Q_ADDPRIVS q_u;
522         LSA_R_ADDPRIVS r_u;
523         
524         prs_struct *data = &p->in_data.data;
525         prs_struct *rdata = &p->out_data.rdata;
526
527         ZERO_STRUCT(q_u);
528         ZERO_STRUCT(r_u);
529
530         if(!lsa_io_q_addprivs("", &q_u, data, 0)) {
531                 DEBUG(0,("api_lsa_addprivs: failed to unmarshall LSA_Q_ADDPRIVS.\n"));
532                 return False;
533         }
534
535         r_u.status = _lsa_addprivs(p, &q_u, &r_u);
536
537         /* store the response in the SMB stream */
538         if(!lsa_io_r_addprivs("", &r_u, rdata, 0)) {
539                 DEBUG(0,("api_lsa_addprivs: Failed to marshall LSA_R_ADDPRIVS.\n"));
540                 return False;
541         }
542
543         return True;
544 }
545
546 /***************************************************************************
547  api_lsa_removeprivs
548  ***************************************************************************/
549
550 static BOOL api_lsa_removeprivs(pipes_struct *p)
551 {
552         LSA_Q_REMOVEPRIVS q_u;
553         LSA_R_REMOVEPRIVS r_u;
554         
555         prs_struct *data = &p->in_data.data;
556         prs_struct *rdata = &p->out_data.rdata;
557
558         ZERO_STRUCT(q_u);
559         ZERO_STRUCT(r_u);
560
561         if(!lsa_io_q_removeprivs("", &q_u, data, 0)) {
562                 DEBUG(0,("api_lsa_removeprivs: failed to unmarshall LSA_Q_REMOVEPRIVS.\n"));
563                 return False;
564         }
565
566         r_u.status = _lsa_removeprivs(p, &q_u, &r_u);
567
568         /* store the response in the SMB stream */
569         if(!lsa_io_r_removeprivs("", &r_u, rdata, 0)) {
570                 DEBUG(0,("api_lsa_removeprivs: Failed to marshall LSA_R_REMOVEPRIVS.\n"));
571                 return False;
572         }
573
574         return True;
575 }
576
577
578 /***************************************************************************
579  \PIPE\ntlsa commands
580  ***************************************************************************/
581
582 static struct api_struct api_lsa_cmds[] =
583 {
584         { "LSA_OPENPOLICY2"     , LSA_OPENPOLICY2     , api_lsa_open_policy2     },
585         { "LSA_OPENPOLICY"      , LSA_OPENPOLICY      , api_lsa_open_policy      },
586         { "LSA_QUERYINFOPOLICY" , LSA_QUERYINFOPOLICY , api_lsa_query_info       },
587         { "LSA_ENUMTRUSTDOM"    , LSA_ENUMTRUSTDOM    , api_lsa_enum_trust_dom   },
588         { "LSA_CLOSE"           , LSA_CLOSE           , api_lsa_close            },
589         { "LSA_OPENSECRET"      , LSA_OPENSECRET      , api_lsa_open_secret      },
590         { "LSA_LOOKUPSIDS"      , LSA_LOOKUPSIDS      , api_lsa_lookup_sids      },
591         { "LSA_LOOKUPNAMES"     , LSA_LOOKUPNAMES     , api_lsa_lookup_names     },
592         { "LSA_ENUM_PRIVS"      , LSA_ENUM_PRIVS      , api_lsa_enum_privs       },
593         { "LSA_PRIV_GET_DISPNAME",LSA_PRIV_GET_DISPNAME,api_lsa_priv_get_dispname},
594         { "LSA_ENUM_ACCOUNTS"   , LSA_ENUM_ACCOUNTS   , api_lsa_enum_accounts    },
595         { "LSA_UNK_GET_CONNUSER", LSA_UNK_GET_CONNUSER, api_lsa_unk_get_connuser },
596         { "LSA_OPENACCOUNT"     , LSA_OPENACCOUNT     , api_lsa_open_account     },
597         { "LSA_ENUMPRIVSACCOUNT", LSA_ENUMPRIVSACCOUNT, api_lsa_enum_privsaccount},
598         { "LSA_GETSYSTEMACCOUNT", LSA_GETSYSTEMACCOUNT, api_lsa_getsystemaccount },
599         { "LSA_SETSYSTEMACCOUNT", LSA_SETSYSTEMACCOUNT, api_lsa_setsystemaccount },
600         { "LSA_ADDPRIVS"        , LSA_ADDPRIVS        , api_lsa_addprivs         },
601         { "LSA_REMOVEPRIVS"     , LSA_REMOVEPRIVS     , api_lsa_removeprivs      },
602         { NULL                  , 0                   , NULL                     }
603 };
604
605 /***************************************************************************
606  api_ntLsarpcTNP
607  ***************************************************************************/
608 BOOL api_ntlsa_rpc(pipes_struct *p)
609 {
610         return api_rpcTNP(p, "api_ntlsa_rpc", api_lsa_cmds);
611 }