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