0269e75e4e14fd2d0a36fe81dffa08636aadb6ed
[ab/samba.git/.git] / source3 / rpc_server / srv_lsa.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                    2001,
8  *  Copyright (C) Jim McDonough <jmcd@us.ibm.com> 2002-2003.
9  *  Copyright (C) Gerald (Jerry) Carter             2005
10  *
11  *  This program is free software; you can redistribute it and/or modify
12  *  it under the terms of the GNU General Public License as published by
13  *  the Free Software Foundation; either version 2 of the License, or
14  *  (at your option) any later version.
15  *  
16  *  This program is distributed in the hope that it will be useful,
17  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
18  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  *  GNU General Public License for more details.
20  *  
21  *  You should have received a copy of the GNU General Public License
22  *  along with this program; if not, write to the Free Software
23  *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24  */
25
26 /* This is the interface to the lsa server code. */
27
28 #include "includes.h"
29
30 #undef DBGC_CLASS
31 #define DBGC_CLASS DBGC_RPC_SRV
32
33 static BOOL proxy_lsa_call(pipes_struct *p, uint8 opnum)
34 {
35         struct api_struct *fns;
36         int n_fns;
37
38         lsarpc_get_pipe_fns(&fns, &n_fns);
39
40         if (opnum >= n_fns)
41                 return False;
42
43         if (fns[opnum].opnum != opnum) {
44                 smb_panic("LSA function table not sorted\n");
45         }
46
47         return fns[opnum].fn(p);
48 }
49
50 /***************************************************************************
51  api_lsa_open_policy2
52  ***************************************************************************/
53
54 static BOOL api_lsa_open_policy2(pipes_struct *p)
55 {
56         LSA_Q_OPEN_POL2 q_u;
57         LSA_R_OPEN_POL2 r_u;
58         prs_struct *data = &p->in_data.data;
59         prs_struct *rdata = &p->out_data.rdata;
60
61         ZERO_STRUCT(q_u);
62         ZERO_STRUCT(r_u);
63
64         /* grab the server, object attributes and desired access flag...*/
65         if(!lsa_io_q_open_pol2("", &q_u, data, 0)) {
66                 DEBUG(0,("api_lsa_open_policy2: unable to unmarshall LSA_Q_OPEN_POL2.\n"));
67                 return False;
68         }
69
70         r_u.status = _lsa_open_policy2(p, &q_u, &r_u);
71
72         /* store the response in the SMB stream */
73         if(!lsa_io_r_open_pol2("", &r_u, rdata, 0)) {
74                 DEBUG(0,("api_lsa_open_policy2: unable to marshall LSA_R_OPEN_POL2.\n"));
75                 return False;
76         }
77
78         return True;
79 }
80
81 /***************************************************************************
82 api_lsa_open_policy
83  ***************************************************************************/
84
85 static BOOL api_lsa_open_policy(pipes_struct *p)
86 {
87         LSA_Q_OPEN_POL q_u;
88         LSA_R_OPEN_POL r_u;
89         prs_struct *data = &p->in_data.data;
90         prs_struct *rdata = &p->out_data.rdata;
91
92         ZERO_STRUCT(q_u);
93         ZERO_STRUCT(r_u);
94
95         /* grab the server, object attributes and desired access flag...*/
96         if(!lsa_io_q_open_pol("", &q_u, data, 0)) {
97                 DEBUG(0,("api_lsa_open_policy: unable to unmarshall LSA_Q_OPEN_POL.\n"));
98                 return False;
99         }
100
101         r_u.status = _lsa_open_policy(p, &q_u, &r_u);
102
103         /* store the response in the SMB stream */
104         if(!lsa_io_r_open_pol("", &r_u, rdata, 0)) {
105                 DEBUG(0,("api_lsa_open_policy: unable to marshall LSA_R_OPEN_POL.\n"));
106                 return False;
107         }
108
109         return True;
110 }
111
112 /***************************************************************************
113  api_lsa_enum_trust_dom
114  ***************************************************************************/
115
116 static BOOL api_lsa_enum_trust_dom(pipes_struct *p)
117 {
118         LSA_Q_ENUM_TRUST_DOM q_u;
119         LSA_R_ENUM_TRUST_DOM r_u;
120         prs_struct *data = &p->in_data.data;
121         prs_struct *rdata = &p->out_data.rdata;
122
123         ZERO_STRUCT(q_u);
124         ZERO_STRUCT(r_u);
125
126         /* grab the enum trust domain context etc. */
127         if(!lsa_io_q_enum_trust_dom("", &q_u, data, 0))
128                 return False;
129
130         /* get required trusted domains information */
131         r_u.status = _lsa_enum_trust_dom(p, &q_u, &r_u);
132
133         /* prepare the response */
134         if(!lsa_io_r_enum_trust_dom("", &r_u, rdata, 0))
135                 return False;
136
137         return True;
138 }
139
140 /***************************************************************************
141  api_lsa_query_info
142  ***************************************************************************/
143
144 static BOOL api_lsa_query_info(pipes_struct *p)
145 {
146         LSA_Q_QUERY_INFO q_u;
147         LSA_R_QUERY_INFO r_u;
148         prs_struct *data = &p->in_data.data;
149         prs_struct *rdata = &p->out_data.rdata;
150
151         ZERO_STRUCT(q_u);
152         ZERO_STRUCT(r_u);
153
154         /* grab the info class and policy handle */
155         if(!lsa_io_q_query("", &q_u, data, 0)) {
156                 DEBUG(0,("api_lsa_query_info: failed to unmarshall LSA_Q_QUERY_INFO.\n"));
157                 return False;
158         }
159
160         r_u.status = _lsa_query_info(p, &q_u, &r_u);
161
162         /* store the response in the SMB stream */
163         if(!lsa_io_r_query("", &r_u, rdata, 0)) {
164                 DEBUG(0,("api_lsa_query_info: failed to marshall LSA_R_QUERY_INFO.\n"));
165                 return False;
166         }
167
168         return True;
169 }
170
171 /***************************************************************************
172  api_lsa_lookup_sids
173  ***************************************************************************/
174
175 static BOOL api_lsa_lookup_sids(pipes_struct *p)
176 {
177         LSA_Q_LOOKUP_SIDS q_u;
178         LSA_R_LOOKUP_SIDS r_u;
179         prs_struct *data = &p->in_data.data;
180         prs_struct *rdata = &p->out_data.rdata;
181
182         ZERO_STRUCT(q_u);
183         ZERO_STRUCT(r_u);
184
185         /* grab the info class and policy handle */
186         if(!lsa_io_q_lookup_sids("", &q_u, data, 0)) {
187                 DEBUG(0,("api_lsa_lookup_sids: failed to unmarshall LSA_Q_LOOKUP_SIDS.\n"));
188                 return False;
189         }
190
191         r_u.status = _lsa_lookup_sids(p, &q_u, &r_u);
192
193         if(!lsa_io_r_lookup_sids("", &r_u, rdata, 0)) {
194                 DEBUG(0,("api_lsa_lookup_sids: Failed to marshall LSA_R_LOOKUP_SIDS.\n"));
195                 return False;
196         }
197
198         return True;
199 }
200
201 /***************************************************************************
202  api_lsa_lookup_names
203  ***************************************************************************/
204
205 static BOOL api_lsa_lookup_names(pipes_struct *p)
206 {
207         LSA_Q_LOOKUP_NAMES q_u;
208         LSA_R_LOOKUP_NAMES r_u;
209         prs_struct *data = &p->in_data.data;
210         prs_struct *rdata = &p->out_data.rdata;
211
212         ZERO_STRUCT(q_u);
213         ZERO_STRUCT(r_u);
214
215         /* grab the info class and policy handle */
216         if(!lsa_io_q_lookup_names("", &q_u, data, 0)) {
217                 DEBUG(0,("api_lsa_lookup_names: failed to unmarshall LSA_Q_LOOKUP_NAMES.\n"));
218                 return False;
219         }
220
221         r_u.status = _lsa_lookup_names(p, &q_u, &r_u);
222
223         /* store the response in the SMB stream */
224         if(!lsa_io_r_lookup_names("", &r_u, rdata, 0)) {
225                 DEBUG(0,("api_lsa_lookup_names: Failed to marshall LSA_R_LOOKUP_NAMES.\n"));
226                 return False;
227         }
228
229         return True;
230 }
231
232 /***************************************************************************
233  api_lsa_close.
234  ***************************************************************************/
235
236 static BOOL api_lsa_close(pipes_struct *p)
237 {
238         return proxy_lsa_call(p, DCERPC_LSA_CLOSE);
239 }
240
241 /***************************************************************************
242  api_lsa_open_secret.
243  ***************************************************************************/
244
245 static BOOL api_lsa_open_secret(pipes_struct *p)
246 {
247         return proxy_lsa_call(p, DCERPC_LSA_OPENSECRET);
248 }
249
250 /***************************************************************************
251  api_lsa_open_secret.
252  ***************************************************************************/
253
254 static BOOL api_lsa_enum_privs(pipes_struct *p)
255 {
256         LSA_Q_ENUM_PRIVS q_u;
257         LSA_R_ENUM_PRIVS r_u;
258         prs_struct *data = &p->in_data.data;
259         prs_struct *rdata = &p->out_data.rdata;
260
261         ZERO_STRUCT(q_u);
262         ZERO_STRUCT(r_u);
263
264         if(!lsa_io_q_enum_privs("", &q_u, data, 0)) {
265                 DEBUG(0,("api_lsa_enum_privs: failed to unmarshall LSA_Q_ENUM_PRIVS.\n"));
266                 return False;
267         }
268
269         r_u.status = _lsa_enum_privs(p, &q_u, &r_u);
270
271         /* store the response in the SMB stream */
272         if(!lsa_io_r_enum_privs("", &r_u, rdata, 0)) {
273                 DEBUG(0,("api_lsa_enum_privs: Failed to marshall LSA_R_ENUM_PRIVS.\n"));
274                 return False;
275         }
276
277         return True;
278 }
279
280 /***************************************************************************
281  api_lsa_open_secret.
282  ***************************************************************************/
283
284 static BOOL api_lsa_priv_get_dispname(pipes_struct *p)
285 {
286         LSA_Q_PRIV_GET_DISPNAME q_u;
287         LSA_R_PRIV_GET_DISPNAME r_u;
288         prs_struct *data = &p->in_data.data;
289         prs_struct *rdata = &p->out_data.rdata;
290
291         ZERO_STRUCT(q_u);
292         ZERO_STRUCT(r_u);
293
294         if(!lsa_io_q_priv_get_dispname("", &q_u, data, 0)) {
295                 DEBUG(0,("api_lsa_priv_get_dispname: failed to unmarshall LSA_Q_PRIV_GET_DISPNAME.\n"));
296                 return False;
297         }
298
299         r_u.status = _lsa_priv_get_dispname(p, &q_u, &r_u);
300
301         /* store the response in the SMB stream */
302         if(!lsa_io_r_priv_get_dispname("", &r_u, rdata, 0)) {
303                 DEBUG(0,("api_lsa_priv_get_dispname: Failed to marshall LSA_R_PRIV_GET_DISPNAME.\n"));
304                 return False;
305         }
306
307         return True;
308 }
309
310 /***************************************************************************
311  api_lsa_open_secret.
312  ***************************************************************************/
313
314 static BOOL api_lsa_enum_accounts(pipes_struct *p)
315 {
316         LSA_Q_ENUM_ACCOUNTS q_u;
317         LSA_R_ENUM_ACCOUNTS r_u;
318         prs_struct *data = &p->in_data.data;
319         prs_struct *rdata = &p->out_data.rdata;
320
321         ZERO_STRUCT(q_u);
322         ZERO_STRUCT(r_u);
323
324         if(!lsa_io_q_enum_accounts("", &q_u, data, 0)) {
325                 DEBUG(0,("api_lsa_enum_accounts: failed to unmarshall LSA_Q_ENUM_ACCOUNTS.\n"));
326                 return False;
327         }
328
329         r_u.status = _lsa_enum_accounts(p, &q_u, &r_u);
330
331         /* store the response in the SMB stream */
332         if(!lsa_io_r_enum_accounts("", &r_u, rdata, 0)) {
333                 DEBUG(0,("api_lsa_enum_accounts: Failed to marshall LSA_R_ENUM_ACCOUNTS.\n"));
334                 return False;
335         }
336
337         return True;
338 }
339
340 /***************************************************************************
341  api_lsa_UNK_GET_CONNUSER
342  ***************************************************************************/
343
344 static BOOL api_lsa_unk_get_connuser(pipes_struct *p)
345 {
346         LSA_Q_UNK_GET_CONNUSER q_u;
347         LSA_R_UNK_GET_CONNUSER r_u;
348         
349         prs_struct *data = &p->in_data.data;
350         prs_struct *rdata = &p->out_data.rdata;
351
352         ZERO_STRUCT(q_u);
353         ZERO_STRUCT(r_u);
354
355         if(!lsa_io_q_unk_get_connuser("", &q_u, data, 0)) {
356                 DEBUG(0,("api_lsa_unk_get_connuser: failed to unmarshall LSA_Q_UNK_GET_CONNUSER.\n"));
357                 return False;
358         }
359
360         r_u.status = _lsa_unk_get_connuser(p, &q_u, &r_u);
361
362         /* store the response in the SMB stream */
363         if(!lsa_io_r_unk_get_connuser("", &r_u, rdata, 0)) {
364                 DEBUG(0,("api_lsa_unk_get_connuser: Failed to marshall LSA_R_UNK_GET_CONNUSER.\n"));
365                 return False;
366         }
367
368         return True;
369 }
370
371 /***************************************************************************
372  api_lsa_create_user
373  ***************************************************************************/
374
375 static BOOL api_lsa_create_account(pipes_struct *p)
376 {
377         LSA_Q_CREATEACCOUNT q_u;
378         LSA_R_CREATEACCOUNT r_u;
379         
380         prs_struct *data = &p->in_data.data;
381         prs_struct *rdata = &p->out_data.rdata;
382
383         ZERO_STRUCT(q_u);
384         ZERO_STRUCT(r_u);
385
386         if(!lsa_io_q_create_account("", &q_u, data, 0)) {
387                 DEBUG(0,("api_lsa_create_account: failed to unmarshall LSA_Q_CREATEACCOUNT.\n"));
388                 return False;
389         }
390
391         r_u.status = _lsa_create_account(p, &q_u, &r_u);
392
393         /* store the response in the SMB stream */
394         if(!lsa_io_r_create_account("", &r_u, rdata, 0)) {
395                 DEBUG(0,("api_lsa_create_account: Failed to marshall LSA_R_CREATEACCOUNT.\n"));
396                 return False;
397         }
398
399         return True;
400 }
401
402 /***************************************************************************
403  api_lsa_open_user
404  ***************************************************************************/
405
406 static BOOL api_lsa_open_account(pipes_struct *p)
407 {
408         LSA_Q_OPENACCOUNT q_u;
409         LSA_R_OPENACCOUNT r_u;
410         
411         prs_struct *data = &p->in_data.data;
412         prs_struct *rdata = &p->out_data.rdata;
413
414         ZERO_STRUCT(q_u);
415         ZERO_STRUCT(r_u);
416
417         if(!lsa_io_q_open_account("", &q_u, data, 0)) {
418                 DEBUG(0,("api_lsa_open_account: failed to unmarshall LSA_Q_OPENACCOUNT.\n"));
419                 return False;
420         }
421
422         r_u.status = _lsa_open_account(p, &q_u, &r_u);
423
424         /* store the response in the SMB stream */
425         if(!lsa_io_r_open_account("", &r_u, rdata, 0)) {
426                 DEBUG(0,("api_lsa_open_account: Failed to marshall LSA_R_OPENACCOUNT.\n"));
427                 return False;
428         }
429
430         return True;
431 }
432
433 /***************************************************************************
434  api_lsa_get_privs
435  ***************************************************************************/
436
437 static BOOL api_lsa_enum_privsaccount(pipes_struct *p)
438 {
439         LSA_Q_ENUMPRIVSACCOUNT q_u;
440         LSA_R_ENUMPRIVSACCOUNT r_u;
441         
442         prs_struct *data = &p->in_data.data;
443         prs_struct *rdata = &p->out_data.rdata;
444
445         ZERO_STRUCT(q_u);
446         ZERO_STRUCT(r_u);
447
448         if(!lsa_io_q_enum_privsaccount("", &q_u, data, 0)) {
449                 DEBUG(0,("api_lsa_enum_privsaccount: failed to unmarshall LSA_Q_ENUMPRIVSACCOUNT.\n"));
450                 return False;
451         }
452
453         r_u.status = _lsa_enum_privsaccount(p, rdata, &q_u, &r_u);
454
455         /* store the response in the SMB stream */
456         if(!lsa_io_r_enum_privsaccount("", &r_u, rdata, 0)) {
457                 DEBUG(0,("api_lsa_enum_privsaccount: Failed to marshall LSA_R_ENUMPRIVSACCOUNT.\n"));
458                 return False;
459         }
460
461         return True;
462 }
463
464 /***************************************************************************
465  api_lsa_getsystemaccount
466  ***************************************************************************/
467
468 static BOOL api_lsa_getsystemaccount(pipes_struct *p)
469 {
470         LSA_Q_GETSYSTEMACCOUNT q_u;
471         LSA_R_GETSYSTEMACCOUNT r_u;
472         
473         prs_struct *data = &p->in_data.data;
474         prs_struct *rdata = &p->out_data.rdata;
475
476         ZERO_STRUCT(q_u);
477         ZERO_STRUCT(r_u);
478
479         if(!lsa_io_q_getsystemaccount("", &q_u, data, 0)) {
480                 DEBUG(0,("api_lsa_getsystemaccount: failed to unmarshall LSA_Q_GETSYSTEMACCOUNT.\n"));
481                 return False;
482         }
483
484         r_u.status = _lsa_getsystemaccount(p, &q_u, &r_u);
485
486         /* store the response in the SMB stream */
487         if(!lsa_io_r_getsystemaccount("", &r_u, rdata, 0)) {
488                 DEBUG(0,("api_lsa_getsystemaccount: Failed to marshall LSA_R_GETSYSTEMACCOUNT.\n"));
489                 return False;
490         }
491
492         return True;
493 }
494
495
496 /***************************************************************************
497  api_lsa_setsystemaccount
498  ***************************************************************************/
499
500 static BOOL api_lsa_setsystemaccount(pipes_struct *p)
501 {
502         LSA_Q_SETSYSTEMACCOUNT q_u;
503         LSA_R_SETSYSTEMACCOUNT r_u;
504         
505         prs_struct *data = &p->in_data.data;
506         prs_struct *rdata = &p->out_data.rdata;
507
508         ZERO_STRUCT(q_u);
509         ZERO_STRUCT(r_u);
510
511         if(!lsa_io_q_setsystemaccount("", &q_u, data, 0)) {
512                 DEBUG(0,("api_lsa_setsystemaccount: failed to unmarshall LSA_Q_SETSYSTEMACCOUNT.\n"));
513                 return False;
514         }
515
516         r_u.status = _lsa_setsystemaccount(p, &q_u, &r_u);
517
518         /* store the response in the SMB stream */
519         if(!lsa_io_r_setsystemaccount("", &r_u, rdata, 0)) {
520                 DEBUG(0,("api_lsa_setsystemaccount: Failed to marshall LSA_R_SETSYSTEMACCOUNT.\n"));
521                 return False;
522         }
523
524         return True;
525 }
526
527 /***************************************************************************
528  api_lsa_addprivs
529  ***************************************************************************/
530
531 static BOOL api_lsa_addprivs(pipes_struct *p)
532 {
533         LSA_Q_ADDPRIVS q_u;
534         LSA_R_ADDPRIVS r_u;
535         
536         prs_struct *data = &p->in_data.data;
537         prs_struct *rdata = &p->out_data.rdata;
538
539         ZERO_STRUCT(q_u);
540         ZERO_STRUCT(r_u);
541
542         if(!lsa_io_q_addprivs("", &q_u, data, 0)) {
543                 DEBUG(0,("api_lsa_addprivs: failed to unmarshall LSA_Q_ADDPRIVS.\n"));
544                 return False;
545         }
546
547         r_u.status = _lsa_addprivs(p, &q_u, &r_u);
548
549         /* store the response in the SMB stream */
550         if(!lsa_io_r_addprivs("", &r_u, rdata, 0)) {
551                 DEBUG(0,("api_lsa_addprivs: Failed to marshall LSA_R_ADDPRIVS.\n"));
552                 return False;
553         }
554
555         return True;
556 }
557
558 /***************************************************************************
559  api_lsa_removeprivs
560  ***************************************************************************/
561
562 static BOOL api_lsa_removeprivs(pipes_struct *p)
563 {
564         LSA_Q_REMOVEPRIVS q_u;
565         LSA_R_REMOVEPRIVS r_u;
566         
567         prs_struct *data = &p->in_data.data;
568         prs_struct *rdata = &p->out_data.rdata;
569
570         ZERO_STRUCT(q_u);
571         ZERO_STRUCT(r_u);
572
573         if(!lsa_io_q_removeprivs("", &q_u, data, 0)) {
574                 DEBUG(0,("api_lsa_removeprivs: failed to unmarshall LSA_Q_REMOVEPRIVS.\n"));
575                 return False;
576         }
577
578         r_u.status = _lsa_removeprivs(p, &q_u, &r_u);
579
580         /* store the response in the SMB stream */
581         if(!lsa_io_r_removeprivs("", &r_u, rdata, 0)) {
582                 DEBUG(0,("api_lsa_removeprivs: Failed to marshall LSA_R_REMOVEPRIVS.\n"));
583                 return False;
584         }
585
586         return True;
587 }
588
589 /***************************************************************************
590  api_lsa_query_secobj
591  ***************************************************************************/
592
593 static BOOL api_lsa_query_secobj(pipes_struct *p)
594 {
595         LSA_Q_QUERY_SEC_OBJ q_u;
596         LSA_R_QUERY_SEC_OBJ r_u;
597         
598         prs_struct *data = &p->in_data.data;
599         prs_struct *rdata = &p->out_data.rdata;
600
601         ZERO_STRUCT(q_u);
602         ZERO_STRUCT(r_u);
603
604         if(!lsa_io_q_query_sec_obj("", &q_u, data, 0)) {
605                 DEBUG(0,("api_lsa_query_secobj: failed to unmarshall LSA_Q_QUERY_SEC_OBJ.\n"));
606                 return False;
607         }
608
609         r_u.status = _lsa_query_secobj(p, &q_u, &r_u);
610
611         /* store the response in the SMB stream */
612         if(!lsa_io_r_query_sec_obj("", &r_u, rdata, 0)) {
613                 DEBUG(0,("api_lsa_query_secobj: Failed to marshall LSA_R_QUERY_SEC_OBJ.\n"));
614                 return False;
615         }
616
617         return True;
618 }
619
620 /***************************************************************************
621  api_lsa_add_acct_rights
622  ***************************************************************************/
623
624 static BOOL api_lsa_add_acct_rights(pipes_struct *p)
625 {
626         LSA_Q_ADD_ACCT_RIGHTS q_u;
627         LSA_R_ADD_ACCT_RIGHTS r_u;
628         
629         prs_struct *data = &p->in_data.data;
630         prs_struct *rdata = &p->out_data.rdata;
631
632         ZERO_STRUCT(q_u);
633         ZERO_STRUCT(r_u);
634
635         if(!lsa_io_q_add_acct_rights("", &q_u, data, 0)) {
636                 DEBUG(0,("api_lsa_add_acct_rights: failed to unmarshall LSA_Q_ADD_ACCT_RIGHTS.\n"));
637                 return False;
638         }
639
640         r_u.status = _lsa_add_acct_rights(p, &q_u, &r_u);
641
642         /* store the response in the SMB stream */
643         if(!lsa_io_r_add_acct_rights("", &r_u, rdata, 0)) {
644                 DEBUG(0,("api_lsa_add_acct_rights: Failed to marshall LSA_R_ADD_ACCT_RIGHTS.\n"));
645                 return False;
646         }
647
648         return True;
649 }
650
651 /***************************************************************************
652  api_lsa_remove_acct_rights
653  ***************************************************************************/
654
655 static BOOL api_lsa_remove_acct_rights(pipes_struct *p)
656 {
657         LSA_Q_REMOVE_ACCT_RIGHTS q_u;
658         LSA_R_REMOVE_ACCT_RIGHTS r_u;
659         
660         prs_struct *data = &p->in_data.data;
661         prs_struct *rdata = &p->out_data.rdata;
662
663         ZERO_STRUCT(q_u);
664         ZERO_STRUCT(r_u);
665
666         if(!lsa_io_q_remove_acct_rights("", &q_u, data, 0)) {
667                 DEBUG(0,("api_lsa_remove_acct_rights: failed to unmarshall LSA_Q_REMOVE_ACCT_RIGHTS.\n"));
668                 return False;
669         }
670
671         r_u.status = _lsa_remove_acct_rights(p, &q_u, &r_u);
672
673         /* store the response in the SMB stream */
674         if(!lsa_io_r_remove_acct_rights("", &r_u, rdata, 0)) {
675                 DEBUG(0,("api_lsa_remove_acct_rights: Failed to marshall LSA_R_REMOVE_ACCT_RIGHTS.\n"));
676                 return False;
677         }
678
679         return True;
680 }
681
682 /***************************************************************************
683  api_lsa_enum_acct_rights
684  ***************************************************************************/
685
686 static BOOL api_lsa_enum_acct_rights(pipes_struct *p)
687 {
688         LSA_Q_ENUM_ACCT_RIGHTS q_u;
689         LSA_R_ENUM_ACCT_RIGHTS r_u;
690         
691         prs_struct *data = &p->in_data.data;
692         prs_struct *rdata = &p->out_data.rdata;
693
694         ZERO_STRUCT(q_u);
695         ZERO_STRUCT(r_u);
696
697         if(!lsa_io_q_enum_acct_rights("", &q_u, data, 0)) {
698                 DEBUG(0,("api_lsa_enum_acct_rights: failed to unmarshall LSA_Q_ENUM_ACCT_RIGHTS.\n"));
699                 return False;
700         }
701
702         r_u.status = _lsa_enum_acct_rights(p, &q_u, &r_u);
703
704         /* store the response in the SMB stream */
705         if(!lsa_io_r_enum_acct_rights("", &r_u, rdata, 0)) {
706                 DEBUG(0,("api_lsa_enum_acct_rights: Failed to marshall LSA_R_ENUM_ACCT_RIGHTS.\n"));
707                 return False;
708         }
709
710         return True;
711 }
712
713 /***************************************************************************
714  api_lsa_lookup_priv_value
715  ***************************************************************************/
716
717 static BOOL api_lsa_lookup_priv_value(pipes_struct *p)
718 {
719         LSA_Q_LOOKUP_PRIV_VALUE q_u;
720         LSA_R_LOOKUP_PRIV_VALUE r_u;
721         
722         prs_struct *data = &p->in_data.data;
723         prs_struct *rdata = &p->out_data.rdata;
724
725         ZERO_STRUCT(q_u);
726         ZERO_STRUCT(r_u);
727
728         if(!lsa_io_q_lookup_priv_value("", &q_u, data, 0)) {
729                 DEBUG(0,("api_lsa_lookup_priv_value: failed to unmarshall LSA_Q_LOOKUP_PRIV_VALUE .\n"));
730                 return False;
731         }
732
733         r_u.status = _lsa_lookup_priv_value(p, &q_u, &r_u);
734
735         /* store the response in the SMB stream */
736         if(!lsa_io_r_lookup_priv_value("", &r_u, rdata, 0)) {
737                 DEBUG(0,("api_lsa_lookup_priv_value: Failed to marshall LSA_R_LOOKUP_PRIV_VALUE.\n"));
738                 return False;
739         }
740
741         return True;
742 }
743
744 /***************************************************************************
745  ***************************************************************************/
746
747 static BOOL api_lsa_open_trust_dom(pipes_struct *p)
748 {
749         return proxy_lsa_call(p, DCERPC_LSA_OPENTRUSTEDDOMAIN);
750 }
751
752 /***************************************************************************
753  ***************************************************************************/
754
755 static BOOL api_lsa_create_trust_dom(pipes_struct *p)
756 {
757         return proxy_lsa_call(p, DCERPC_LSA_CREATETRUSTEDDOMAIN);
758 }
759
760 /***************************************************************************
761  ***************************************************************************/
762
763 static BOOL api_lsa_create_secret(pipes_struct *p)
764 {
765         return proxy_lsa_call(p, DCERPC_LSA_CREATESECRET);
766 }
767
768 /***************************************************************************
769  ***************************************************************************/
770
771 static BOOL api_lsa_set_secret(pipes_struct *p)
772 {
773         return proxy_lsa_call(p, DCERPC_LSA_SETSECRET);
774 }
775
776 /***************************************************************************
777  ***************************************************************************/
778
779 static BOOL api_lsa_delete_object(pipes_struct *p)
780 {
781         LSA_Q_DELETE_OBJECT q_u;
782         LSA_R_DELETE_OBJECT r_u;
783         
784         prs_struct *data = &p->in_data.data;
785         prs_struct *rdata = &p->out_data.rdata;
786
787         ZERO_STRUCT(q_u);
788         ZERO_STRUCT(r_u);
789
790         if(!lsa_io_q_delete_object("", &q_u, data, 0)) {
791                 DEBUG(0,("api_lsa_delete_object: failed to unmarshall LSA_Q_DELETE_OBJECT.\n"));
792                 return False;
793         }
794
795         r_u.status = _lsa_delete_object(p, &q_u, &r_u);
796
797         /* store the response in the SMB stream */
798         if(!lsa_io_r_delete_object("", &r_u, rdata, 0)) {
799                 DEBUG(0,("api_lsa_delete_object: Failed to marshall LSA_R_DELETE_OBJECT.\n"));
800                 return False;
801         }
802
803         return True;
804 }
805
806 /***************************************************************************
807  api_lsa_lookup_sids2
808  ***************************************************************************/
809
810 static BOOL api_lsa_lookup_sids2(pipes_struct *p)
811 {
812         LSA_Q_LOOKUP_SIDS2 q_u;
813         LSA_R_LOOKUP_SIDS2 r_u;
814         prs_struct *data = &p->in_data.data;
815         prs_struct *rdata = &p->out_data.rdata;
816
817         ZERO_STRUCT(q_u);
818         ZERO_STRUCT(r_u);
819
820         /* grab the info class and policy handle */
821         if(!lsa_io_q_lookup_sids2("", &q_u, data, 0)) {
822                 DEBUG(0,("api_lsa_lookup_sids2: failed to unmarshall LSA_Q_LOOKUP_SIDS2.\n"));
823                 return False;
824         }
825
826         r_u.status = _lsa_lookup_sids2(p, &q_u, &r_u);
827
828         if(!lsa_io_r_lookup_sids2("", &r_u, rdata, 0)) {
829                 DEBUG(0,("api_lsa_lookup_sids2: Failed to marshall LSA_R_LOOKUP_SIDS2.\n"));
830                 return False;
831         }
832
833         return True;
834 }
835
836 /***************************************************************************
837  api_lsa_lookup_sids3
838  ***************************************************************************/
839
840 static BOOL api_lsa_lookup_sids3(pipes_struct *p)
841 {
842         LSA_Q_LOOKUP_SIDS3 q_u;
843         LSA_R_LOOKUP_SIDS3 r_u;
844         prs_struct *data = &p->in_data.data;
845         prs_struct *rdata = &p->out_data.rdata;
846
847         ZERO_STRUCT(q_u);
848         ZERO_STRUCT(r_u);
849
850         /* grab the info class and policy handle */
851         if(!lsa_io_q_lookup_sids3("", &q_u, data, 0)) {
852                 DEBUG(0,("api_lsa_lookup_sids3: failed to unmarshall LSA_Q_LOOKUP_SIDS3.\n"));
853                 return False;
854         }
855
856         r_u.status = _lsa_lookup_sids3(p, &q_u, &r_u);
857
858         if(!lsa_io_r_lookup_sids3("", &r_u, rdata, 0)) {
859                 DEBUG(0,("api_lsa_lookup_sids3: Failed to marshall LSA_R_LOOKUP_SIDS3.\n"));
860                 return False;
861         }
862
863         return True;
864 }
865
866 /***************************************************************************
867  api_lsa_lookup_names2
868  ***************************************************************************/
869
870 static BOOL api_lsa_lookup_names2(pipes_struct *p)
871 {
872         LSA_Q_LOOKUP_NAMES2 q_u;
873         LSA_R_LOOKUP_NAMES2 r_u;
874         prs_struct *data = &p->in_data.data;
875         prs_struct *rdata = &p->out_data.rdata;
876
877         ZERO_STRUCT(q_u);
878         ZERO_STRUCT(r_u);
879
880         /* grab the info class and policy handle */
881         if(!lsa_io_q_lookup_names2("", &q_u, data, 0)) {
882                 DEBUG(0,("api_lsa_lookup_names2: failed to unmarshall LSA_Q_LOOKUP_NAMES2.\n"));
883                 return False;
884         }
885
886         r_u.status = _lsa_lookup_names2(p, &q_u, &r_u);
887
888         /* store the response in the SMB stream */
889         if(!lsa_io_r_lookup_names2("", &r_u, rdata, 0)) {
890                 DEBUG(0,("api_lsa_lookup_names2: Failed to marshall LSA_R_LOOKUP_NAMES2.\n"));
891                 return False;
892         }
893
894         return True;
895 }
896
897 /***************************************************************************
898  api_lsa_lookup_names3
899  ***************************************************************************/
900
901 static BOOL api_lsa_lookup_names3(pipes_struct *p)
902 {
903         LSA_Q_LOOKUP_NAMES3 q_u;
904         LSA_R_LOOKUP_NAMES3 r_u;
905         prs_struct *data = &p->in_data.data;
906         prs_struct *rdata = &p->out_data.rdata;
907
908         ZERO_STRUCT(q_u);
909         ZERO_STRUCT(r_u);
910
911         /* grab the info class and policy handle */
912         if(!lsa_io_q_lookup_names3("", &q_u, data, 0)) {
913                 DEBUG(0,("api_lsa_lookup_names3: failed to unmarshall LSA_Q_LOOKUP_NAMES3.\n"));
914                 return False;
915         }
916
917         r_u.status = _lsa_lookup_names3(p, &q_u, &r_u);
918
919         /* store the response in the SMB stream */
920         if(!lsa_io_r_lookup_names3("", &r_u, rdata, 0)) {
921                 DEBUG(0,("api_lsa_lookup_names3: Failed to marshall LSA_R_LOOKUP_NAMES3.\n"));
922                 return False;
923         }
924
925         return True;
926 }
927
928 /***************************************************************************
929  api_lsa_lookup_names4
930  ***************************************************************************/
931
932 static BOOL api_lsa_lookup_names4(pipes_struct *p)
933 {
934         LSA_Q_LOOKUP_NAMES4 q_u;
935         LSA_R_LOOKUP_NAMES4 r_u;
936         prs_struct *data = &p->in_data.data;
937         prs_struct *rdata = &p->out_data.rdata;
938
939         ZERO_STRUCT(q_u);
940         ZERO_STRUCT(r_u);
941
942         /* grab the info class and policy handle */
943         if(!lsa_io_q_lookup_names4("", &q_u, data, 0)) {
944                 DEBUG(0,("api_lsa_lookup_names4: failed to unmarshall LSA_Q_LOOKUP_NAMES4.\n"));
945                 return False;
946         }
947
948         r_u.status = _lsa_lookup_names4(p, &q_u, &r_u);
949
950         /* store the response in the SMB stream */
951         if(!lsa_io_r_lookup_names4("", &r_u, rdata, 0)) {
952                 DEBUG(0,("api_lsa_lookup_names4: Failed to marshall LSA_R_LOOKUP_NAMES4.\n"));
953                 return False;
954         }
955
956         return True;
957 }
958
959 #if 0   /* AD DC work in ongoing in Samba 4 */
960
961 /***************************************************************************
962  api_lsa_query_info2
963  ***************************************************************************/
964
965 static BOOL api_lsa_query_info2(pipes_struct *p)
966 {
967         LSA_Q_QUERY_INFO2 q_u;
968         LSA_R_QUERY_INFO2 r_u;
969
970         prs_struct *data = &p->in_data.data;
971         prs_struct *rdata = &p->out_data.rdata;
972
973         ZERO_STRUCT(q_u);
974         ZERO_STRUCT(r_u);
975
976         if(!lsa_io_q_query_info2("", &q_u, data, 0)) {
977                 DEBUG(0,("api_lsa_query_info2: failed to unmarshall LSA_Q_QUERY_INFO2.\n"));
978                 return False;
979         }
980
981         r_u.status = _lsa_query_info2(p, &q_u, &r_u);
982
983         if (!lsa_io_r_query_info2("", &r_u, rdata, 0)) {
984                 DEBUG(0,("api_lsa_query_info2: failed to marshall LSA_R_QUERY_INFO2.\n"));
985                 return False;
986         }
987
988         return True;
989 }
990 #endif  /* AD DC work in ongoing in Samba 4 */
991
992 /***************************************************************************
993  \PIPE\ntlsa commands
994  ***************************************************************************/
995  
996 static struct api_struct api_lsa_cmds[] =
997 {
998         { "LSA_OPENPOLICY2"     , LSA_OPENPOLICY2     , api_lsa_open_policy2     },
999         { "LSA_OPENPOLICY"      , LSA_OPENPOLICY      , api_lsa_open_policy      },
1000         { "LSA_QUERYINFOPOLICY" , LSA_QUERYINFOPOLICY , api_lsa_query_info       },
1001         { "LSA_ENUMTRUSTDOM"    , LSA_ENUMTRUSTDOM    , api_lsa_enum_trust_dom   },
1002         { "LSA_CLOSE"           , LSA_CLOSE           , api_lsa_close            },
1003         { "LSA_OPENSECRET"      , LSA_OPENSECRET      , api_lsa_open_secret      },
1004         { "LSA_LOOKUPSIDS"      , LSA_LOOKUPSIDS      , api_lsa_lookup_sids      },
1005         { "LSA_LOOKUPNAMES"     , LSA_LOOKUPNAMES     , api_lsa_lookup_names     },
1006         { "LSA_ENUM_PRIVS"      , LSA_ENUM_PRIVS      , api_lsa_enum_privs       },
1007         { "LSA_PRIV_GET_DISPNAME",LSA_PRIV_GET_DISPNAME,api_lsa_priv_get_dispname},
1008         { "LSA_ENUM_ACCOUNTS"   , LSA_ENUM_ACCOUNTS   , api_lsa_enum_accounts    },
1009         { "LSA_UNK_GET_CONNUSER", LSA_UNK_GET_CONNUSER, api_lsa_unk_get_connuser },
1010         { "LSA_CREATEACCOUNT"   , LSA_CREATEACCOUNT   , api_lsa_create_account   },
1011         { "LSA_OPENACCOUNT"     , LSA_OPENACCOUNT     , api_lsa_open_account     },
1012         { "LSA_ENUMPRIVSACCOUNT", LSA_ENUMPRIVSACCOUNT, api_lsa_enum_privsaccount},
1013         { "LSA_GETSYSTEMACCOUNT", LSA_GETSYSTEMACCOUNT, api_lsa_getsystemaccount },
1014         { "LSA_SETSYSTEMACCOUNT", LSA_SETSYSTEMACCOUNT, api_lsa_setsystemaccount },
1015         { "LSA_ADDPRIVS"        , LSA_ADDPRIVS        , api_lsa_addprivs         },
1016         { "LSA_REMOVEPRIVS"     , LSA_REMOVEPRIVS     , api_lsa_removeprivs      },
1017         { "LSA_ADDACCTRIGHTS"   , LSA_ADDACCTRIGHTS   , api_lsa_add_acct_rights    },
1018         { "LSA_REMOVEACCTRIGHTS", LSA_REMOVEACCTRIGHTS, api_lsa_remove_acct_rights },
1019         { "LSA_ENUMACCTRIGHTS"  , LSA_ENUMACCTRIGHTS  , api_lsa_enum_acct_rights },
1020         { "LSA_QUERYSECOBJ"     , LSA_QUERYSECOBJ     , api_lsa_query_secobj     },
1021         { "LSA_LOOKUPPRIVVALUE" , LSA_LOOKUPPRIVVALUE , api_lsa_lookup_priv_value },
1022         { "LSA_OPENTRUSTDOM"    , LSA_OPENTRUSTDOM    , api_lsa_open_trust_dom },
1023         { "LSA_OPENSECRET"      , LSA_OPENSECRET      , api_lsa_open_secret },
1024         { "LSA_CREATETRUSTDOM"  , LSA_CREATETRUSTDOM  , api_lsa_create_trust_dom },
1025         { "LSA_CREATSECRET"     , LSA_CREATESECRET    , api_lsa_create_secret },
1026         { "LSA_SETSECRET"       , LSA_SETSECRET       , api_lsa_set_secret },
1027         { "LSA_DELETEOBJECT"    , LSA_DELETEOBJECT    , api_lsa_delete_object },
1028         { "LSA_LOOKUPSIDS2"     , LSA_LOOKUPSIDS2     , api_lsa_lookup_sids2 },
1029         { "LSA_LOOKUPNAMES2"    , LSA_LOOKUPNAMES2    , api_lsa_lookup_names2 },
1030         { "LSA_LOOKUPNAMES3"    , LSA_LOOKUPNAMES3    , api_lsa_lookup_names3 },
1031         { "LSA_LOOKUPSIDS3"     , LSA_LOOKUPSIDS3     , api_lsa_lookup_sids3 },
1032         { "LSA_LOOKUPNAMES4"    , LSA_LOOKUPNAMES4    , api_lsa_lookup_names4 }
1033 #if 0   /* AD DC work in ongoing in Samba 4 */
1034         /* be careful of the adding of new RPC's.  See commentrs below about
1035            ADS DC capabilities                                               */
1036         { "LSA_QUERYINFO2"      , LSA_QUERYINFO2      , api_lsa_query_info2      }
1037 #endif  /* AD DC work in ongoing in Samba 4 */
1038 };
1039
1040 static int count_fns(void)
1041 {
1042         int funcs = sizeof(api_lsa_cmds) / sizeof(struct api_struct);
1043         
1044 #if 0   /* AD DC work is on going in Samba 4 */
1045         /*
1046          * NOTE: Certain calls can not be enabled if we aren't an ADS DC.  Make sure
1047          * these calls are always last and that you decrement by the amount of calls
1048          * to disable.
1049          */
1050         if (!(SEC_ADS == lp_security() && ROLE_DOMAIN_PDC == lp_server_role())) {
1051                 funcs -= 1;
1052         }
1053 #endif  /* AD DC work in ongoing in Samba 4 */
1054
1055         return funcs;
1056 }
1057 void lsa_get_pipe_fns( struct api_struct **fns, int *n_fns )
1058 {
1059         *fns = api_lsa_cmds;
1060         *n_fns = count_fns();
1061 }
1062
1063
1064 NTSTATUS rpc_lsa_init(void)
1065 {
1066         int funcs = count_fns();
1067
1068         return rpc_pipe_register_commands(SMB_RPC_INTERFACE_VERSION, "lsarpc", "lsass", api_lsa_cmds, 
1069                 funcs);
1070 }