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