6cf26e7eb246f1bae32a79e18c1f63f315121007
[gd/samba/.git] / source / rpc_server / srv_lsa_nt.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, 2006.
8  *  Copyright (C) Rafal Szczesniak                  2002,
9  *  Copyright (C) Jim McDonough <jmcd@us.ibm.com>   2002,
10  *  Copyright (C) Simo Sorce                        2003.
11  *  Copyright (C) Gerald (Jerry) Carter             2005.
12  *  Copyright (C) Volker Lendecke                   2005.
13  *
14  *  This program is free software; you can redistribute it and/or modify
15  *  it under the terms of the GNU General Public License as published by
16  *  the Free Software Foundation; either version 3 of the License, or
17  *  (at your option) any later version.
18  *
19  *  This program is distributed in the hope that it will be useful,
20  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
21  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
22  *  GNU General Public License for more details.
23  *
24  *  You should have received a copy of the GNU General Public License
25  *  along with this program; if not, see <http://www.gnu.org/licenses/>.
26  */
27
28 /* This is the implementation of the lsa server code. */
29
30 #include "includes.h"
31
32 #undef DBGC_CLASS
33 #define DBGC_CLASS DBGC_RPC_SRV
34
35 extern PRIVS privs[];
36
37 struct lsa_info {
38         DOM_SID sid;
39         uint32 access;
40 };
41
42 const struct generic_mapping lsa_generic_mapping = {
43         POLICY_READ,
44         POLICY_WRITE,
45         POLICY_EXECUTE,
46         POLICY_ALL_ACCESS
47 };
48
49 /***************************************************************************
50  init_lsa_ref_domain_list - adds a domain if it's not already in, returns the index.
51 ***************************************************************************/
52
53 static int init_lsa_ref_domain_list(TALLOC_CTX *mem_ctx,
54                                     struct lsa_RefDomainList *ref,
55                                     const char *dom_name,
56                                     DOM_SID *dom_sid)
57 {
58         int num = 0;
59
60         if (dom_name != NULL) {
61                 for (num = 0; num < ref->count; num++) {
62                         if (sid_equal(dom_sid, ref->domains[num].sid)) {
63                                 return num;
64                         }
65                 }
66         } else {
67                 num = ref->count;
68         }
69
70         if (num >= MAX_REF_DOMAINS) {
71                 /* index not found, already at maximum domain limit */
72                 return -1;
73         }
74
75         ref->count = num + 1;
76         ref->max_size = MAX_REF_DOMAINS;
77
78         ref->domains = TALLOC_REALLOC_ARRAY(mem_ctx, ref->domains,
79                                             struct lsa_DomainInfo, ref->count);
80         if (!ref->domains) {
81                 return -1;
82         }
83
84         init_lsa_StringLarge(&ref->domains[num].name, dom_name);
85         ref->domains[num].sid = sid_dup_talloc(mem_ctx, dom_sid);
86         if (!ref->domains[num].sid) {
87                 return -1;
88         }
89
90         return num;
91 }
92
93
94 /*******************************************************************
95  Function to free the per handle data.
96  ********************************************************************/
97
98 static void free_lsa_info(void *ptr)
99 {
100         struct lsa_info *lsa = (struct lsa_info *)ptr;
101
102         SAFE_FREE(lsa);
103 }
104
105 /***************************************************************************
106  initialize a lsa_DomainInfo structure.
107  ***************************************************************************/
108
109 static void init_dom_query_3(struct lsa_DomainInfo *r,
110                              const char *name,
111                              DOM_SID *sid)
112 {
113         init_lsa_StringLarge(&r->name, name);
114         r->sid = sid;
115 }
116
117 /***************************************************************************
118  initialize a lsa_DomainInfo structure.
119  ***************************************************************************/
120
121 static void init_dom_query_5(struct lsa_DomainInfo *r,
122                              const char *name,
123                              DOM_SID *sid)
124 {
125         init_lsa_StringLarge(&r->name, name);
126         r->sid = sid;
127 }
128
129 /***************************************************************************
130  init_dom_ref - adds a domain if it's not already in, returns the index.
131 ***************************************************************************/
132
133 static int init_dom_ref(DOM_R_REF *ref, const char *dom_name, DOM_SID *dom_sid)
134 {
135         int num = 0;
136
137         if (dom_name != NULL) {
138                 for (num = 0; num < ref->num_ref_doms_1; num++) {
139                         if (sid_equal(dom_sid, &ref->ref_dom[num].ref_dom.sid))
140                                 return num;
141                 }
142         } else {
143                 num = ref->num_ref_doms_1;
144         }
145
146         if (num >= MAX_REF_DOMAINS) {
147                 /* index not found, already at maximum domain limit */
148                 return -1;
149         }
150
151         ref->num_ref_doms_1 = num+1;
152         ref->ptr_ref_dom  = 1;
153         ref->max_entries = MAX_REF_DOMAINS;
154         ref->num_ref_doms_2 = num+1;
155
156         ref->hdr_ref_dom[num].ptr_dom_sid = 1; /* dom sid cannot be NULL. */
157
158         init_unistr2(&ref->ref_dom[num].uni_dom_name, dom_name, UNI_FLAGS_NONE);
159         init_uni_hdr(&ref->hdr_ref_dom[num].hdr_dom_name, &ref->ref_dom[num].uni_dom_name);
160
161         init_dom_sid2(&ref->ref_dom[num].ref_dom, dom_sid );
162
163         return num;
164 }
165
166 /***************************************************************************
167  lookup_lsa_rids. Must be called as root for lookup_name to work.
168  ***************************************************************************/
169
170 static NTSTATUS lookup_lsa_rids(TALLOC_CTX *mem_ctx,
171                                 struct lsa_RefDomainList *ref,
172                                 struct lsa_TranslatedSid *prid,
173                                 uint32_t num_entries,
174                                 struct lsa_String *name,
175                                 int flags,
176                                 uint32_t *pmapped_count)
177 {
178         uint32 mapped_count, i;
179
180         SMB_ASSERT(num_entries <= MAX_LOOKUP_SIDS);
181
182         mapped_count = 0;
183         *pmapped_count = 0;
184
185         for (i = 0; i < num_entries; i++) {
186                 DOM_SID sid;
187                 uint32 rid;
188                 int dom_idx;
189                 const char *full_name;
190                 const char *domain;
191                 enum lsa_SidType type = SID_NAME_UNKNOWN;
192
193                 /* Split name into domain and user component */
194
195                 full_name = name[i].string;
196                 if (full_name == NULL) {
197                         return NT_STATUS_NO_MEMORY;
198                 }
199
200                 DEBUG(5, ("lookup_lsa_rids: looking up name %s\n", full_name));
201
202                 /* We can ignore the result of lookup_name, it will not touch
203                    "type" if it's not successful */
204
205                 lookup_name(mem_ctx, full_name, flags, &domain, NULL,
206                             &sid, &type);
207
208                 switch (type) {
209                 case SID_NAME_USER:
210                 case SID_NAME_DOM_GRP:
211                 case SID_NAME_DOMAIN:
212                 case SID_NAME_ALIAS:
213                 case SID_NAME_WKN_GRP:
214                         DEBUG(5, ("init_lsa_rids: %s found\n", full_name));
215                         /* Leave these unchanged */
216                         break;
217                 default:
218                         /* Don't hand out anything but the list above */
219                         DEBUG(5, ("init_lsa_rids: %s not found\n", full_name));
220                         type = SID_NAME_UNKNOWN;
221                         break;
222                 }
223
224                 rid = 0;
225                 dom_idx = -1;
226
227                 if (type != SID_NAME_UNKNOWN) {
228                         sid_split_rid(&sid, &rid);
229                         dom_idx = init_lsa_ref_domain_list(mem_ctx, ref, domain, &sid);
230                         mapped_count++;
231                 }
232
233                 init_lsa_translated_sid(&prid[i], type, rid, dom_idx);
234         }
235
236         *pmapped_count = mapped_count;
237         return NT_STATUS_OK;
238 }
239
240 /***************************************************************************
241  lookup_lsa_sids. Must be called as root for lookup_name to work.
242  ***************************************************************************/
243
244 static NTSTATUS lookup_lsa_sids(TALLOC_CTX *mem_ctx,
245                         DOM_R_REF *ref,
246                         LSA_TRANSLATED_SID3 *trans_sids,
247                         uint32 num_entries,
248                         const UNISTR2 *name,
249                         int flags,
250                         uint32 *pmapped_count)
251 {
252         uint32 mapped_count, i;
253
254         SMB_ASSERT(num_entries <= MAX_LOOKUP_SIDS);
255
256         mapped_count = 0;
257         *pmapped_count = 0;
258
259         for (i = 0; i < num_entries; i++) {
260                 DOM_SID sid;
261                 uint32 rid;
262                 int dom_idx;
263                 char *full_name;
264                 const char *domain;
265                 enum lsa_SidType type = SID_NAME_UNKNOWN;
266
267                 /* Split name into domain and user component */
268
269                 full_name = rpcstr_pull_unistr2_talloc(mem_ctx, &name[i]);
270                 if (full_name == NULL) {
271                         DEBUG(0, ("pull_ucs2_talloc failed\n"));
272                         return NT_STATUS_NO_MEMORY;
273                 }
274
275                 DEBUG(5, ("init_lsa_sids: looking up name %s\n", full_name));
276
277                 /* We can ignore the result of lookup_name, it will not touch
278                    "type" if it's not successful */
279
280                 lookup_name(mem_ctx, full_name, flags, &domain, NULL,
281                             &sid, &type);
282
283                 switch (type) {
284                 case SID_NAME_USER:
285                 case SID_NAME_DOM_GRP:
286                 case SID_NAME_DOMAIN:
287                 case SID_NAME_ALIAS:
288                 case SID_NAME_WKN_GRP:
289                         DEBUG(5, ("init_lsa_sids: %s found\n", full_name));
290                         /* Leave these unchanged */
291                         break;
292                 default:
293                         /* Don't hand out anything but the list above */
294                         DEBUG(5, ("init_lsa_sids: %s not found\n", full_name));
295                         type = SID_NAME_UNKNOWN;
296                         break;
297                 }
298
299                 rid = 0;
300                 dom_idx = -1;
301
302                 if (type != SID_NAME_UNKNOWN) {
303                         DOM_SID domain_sid;
304                         sid_copy(&domain_sid, &sid);
305                         sid_split_rid(&domain_sid, &rid);
306                         dom_idx = init_dom_ref(ref, domain, &domain_sid);
307                         mapped_count++;
308                 }
309
310                 /* Initialize the LSA_TRANSLATED_SID3 return. */
311                 trans_sids[i].sid_type = type;
312                 trans_sids[i].sid2 = TALLOC_P(mem_ctx, DOM_SID2);
313                 if (trans_sids[i].sid2 == NULL) {
314                         return NT_STATUS_NO_MEMORY;
315                 }
316                 init_dom_sid2(trans_sids[i].sid2, &sid);
317                 trans_sids[i].sid_idx = dom_idx;
318         }
319
320         *pmapped_count = mapped_count;
321         return NT_STATUS_OK;
322 }
323
324 /***************************************************************************
325  init_reply_lookup_names
326  ***************************************************************************/
327
328 static void init_reply_lookup_names(LSA_R_LOOKUP_NAMES *r_l,
329                 DOM_R_REF *ref, uint32 num_entries,
330                 DOM_RID *rid, uint32 mapped_count)
331 {
332         r_l->ptr_dom_ref  = 1;
333         r_l->dom_ref      = ref;
334
335         r_l->num_entries  = num_entries;
336         r_l->ptr_entries  = 1;
337         r_l->num_entries2 = num_entries;
338         r_l->dom_rid      = rid;
339
340         r_l->mapped_count = mapped_count;
341 }
342
343 /***************************************************************************
344  init_reply_lookup_names2
345  ***************************************************************************/
346
347 static void init_reply_lookup_names2(LSA_R_LOOKUP_NAMES2 *r_l,
348                 DOM_R_REF *ref, uint32 num_entries,
349                 DOM_RID2 *rid, uint32 mapped_count)
350 {
351         r_l->ptr_dom_ref  = 1;
352         r_l->dom_ref      = ref;
353
354         r_l->num_entries  = num_entries;
355         r_l->ptr_entries  = 1;
356         r_l->num_entries2 = num_entries;
357         r_l->dom_rid      = rid;
358
359         r_l->mapped_count = mapped_count;
360 }
361
362 /***************************************************************************
363  init_reply_lookup_names3
364  ***************************************************************************/
365
366 static void init_reply_lookup_names3(LSA_R_LOOKUP_NAMES3 *r_l,
367                 DOM_R_REF *ref, uint32 num_entries,
368                 LSA_TRANSLATED_SID3 *trans_sids, uint32 mapped_count)
369 {
370         r_l->ptr_dom_ref  = 1;
371         r_l->dom_ref      = ref;
372
373         r_l->num_entries  = num_entries;
374         r_l->ptr_entries  = 1;
375         r_l->num_entries2 = num_entries;
376         r_l->trans_sids   = trans_sids;
377
378         r_l->mapped_count = mapped_count;
379 }
380
381 /***************************************************************************
382  init_reply_lookup_names4
383  ***************************************************************************/
384
385 static void init_reply_lookup_names4(LSA_R_LOOKUP_NAMES4 *r_l,
386                 DOM_R_REF *ref, uint32 num_entries,
387                 LSA_TRANSLATED_SID3 *trans_sids, uint32 mapped_count)
388 {
389         r_l->ptr_dom_ref  = 1;
390         r_l->dom_ref      = ref;
391
392         r_l->num_entries  = num_entries;
393         r_l->ptr_entries  = 1;
394         r_l->num_entries2 = num_entries;
395         r_l->trans_sids   = trans_sids;
396
397         r_l->mapped_count = mapped_count;
398 }
399
400 /***************************************************************************
401  Init_reply_lookup_sids.
402  ***************************************************************************/
403
404 static void init_reply_lookup_sids2(LSA_R_LOOKUP_SIDS2 *r_l,
405                                 DOM_R_REF *ref,
406                                 uint32 mapped_count)
407 {
408         r_l->ptr_dom_ref  = ref ? 1 : 0;
409         r_l->dom_ref      = ref;
410         r_l->mapped_count = mapped_count;
411 }
412
413 /***************************************************************************
414  Init_reply_lookup_sids.
415  ***************************************************************************/
416
417 static void init_reply_lookup_sids3(LSA_R_LOOKUP_SIDS3 *r_l,
418                                 DOM_R_REF *ref,
419                                 uint32 mapped_count)
420 {
421         r_l->ptr_dom_ref  = ref ? 1 : 0;
422         r_l->dom_ref      = ref;
423         r_l->mapped_count = mapped_count;
424 }
425
426 /***************************************************************************
427  Init_reply_lookup_sids.
428  ***************************************************************************/
429
430 static NTSTATUS init_reply_lookup_sids(TALLOC_CTX *mem_ctx,
431                                 LSA_R_LOOKUP_SIDS *r_l,
432                                 DOM_R_REF *ref,
433                                 LSA_TRANS_NAME_ENUM2 *names,
434                                 uint32 mapped_count)
435 {
436         LSA_TRANS_NAME_ENUM *oldnames = &r_l->names;
437
438         oldnames->num_entries = names->num_entries;
439         oldnames->ptr_trans_names = names->ptr_trans_names;
440         oldnames->num_entries2 = names->num_entries2;
441         oldnames->uni_name = names->uni_name;
442
443         if (names->num_entries) {
444                 int i;
445
446                 oldnames->name = TALLOC_ARRAY(mem_ctx, LSA_TRANS_NAME, names->num_entries);
447
448                 if (!oldnames->name) {
449                         return NT_STATUS_NO_MEMORY;
450                 }
451                 for (i = 0; i < names->num_entries; i++) {
452                         oldnames->name[i].sid_name_use = names->name[i].sid_name_use;
453                         oldnames->name[i].hdr_name = names->name[i].hdr_name;
454                         oldnames->name[i].domain_idx = names->name[i].domain_idx;
455                 }
456         }
457
458         r_l->ptr_dom_ref  = ref ? 1 : 0;
459         r_l->dom_ref      = ref;
460         r_l->mapped_count = mapped_count;
461         return NT_STATUS_OK;
462 }
463
464 static NTSTATUS lsa_get_generic_sd(TALLOC_CTX *mem_ctx, SEC_DESC **sd, size_t *sd_size)
465 {
466         DOM_SID local_adm_sid;
467         DOM_SID adm_sid;
468
469         SEC_ACE ace[3];
470         SEC_ACCESS mask;
471
472         SEC_ACL *psa = NULL;
473
474         init_sec_access(&mask, POLICY_EXECUTE);
475         init_sec_ace(&ace[0], &global_sid_World, SEC_ACE_TYPE_ACCESS_ALLOWED, mask, 0);
476
477         sid_copy(&adm_sid, get_global_sam_sid());
478         sid_append_rid(&adm_sid, DOMAIN_GROUP_RID_ADMINS);
479         init_sec_access(&mask, POLICY_ALL_ACCESS);
480         init_sec_ace(&ace[1], &adm_sid, SEC_ACE_TYPE_ACCESS_ALLOWED, mask, 0);
481
482         sid_copy(&local_adm_sid, &global_sid_Builtin);
483         sid_append_rid(&local_adm_sid, BUILTIN_ALIAS_RID_ADMINS);
484         init_sec_access(&mask, POLICY_ALL_ACCESS);
485         init_sec_ace(&ace[2], &local_adm_sid, SEC_ACE_TYPE_ACCESS_ALLOWED, mask, 0);
486
487         if((psa = make_sec_acl(mem_ctx, NT4_ACL_REVISION, 3, ace)) == NULL)
488                 return NT_STATUS_NO_MEMORY;
489
490         if((*sd = make_sec_desc(mem_ctx, SECURITY_DESCRIPTOR_REVISION_1,
491                                 SEC_DESC_SELF_RELATIVE, &adm_sid, NULL, NULL,
492                                 psa, sd_size)) == NULL)
493                 return NT_STATUS_NO_MEMORY;
494
495         return NT_STATUS_OK;
496 }
497
498 #if 0   /* AD DC work in ongoing in Samba 4 */
499
500 /***************************************************************************
501  Init_dns_dom_info.
502 ***************************************************************************/
503
504 static void init_dns_dom_info(LSA_DNS_DOM_INFO *r_l, const char *nb_name,
505                               const char *dns_name, const char *forest_name,
506                               struct GUID *dom_guid, DOM_SID *dom_sid)
507 {
508         if (nb_name && *nb_name) {
509                 init_unistr2(&r_l->uni_nb_dom_name, nb_name, UNI_FLAGS_NONE);
510                 init_uni_hdr(&r_l->hdr_nb_dom_name, &r_l->uni_nb_dom_name);
511                 r_l->hdr_nb_dom_name.uni_max_len += 2;
512                 r_l->uni_nb_dom_name.uni_max_len += 1;
513         }
514
515         if (dns_name && *dns_name) {
516                 init_unistr2(&r_l->uni_dns_dom_name, dns_name, UNI_FLAGS_NONE);
517                 init_uni_hdr(&r_l->hdr_dns_dom_name, &r_l->uni_dns_dom_name);
518                 r_l->hdr_dns_dom_name.uni_max_len += 2;
519                 r_l->uni_dns_dom_name.uni_max_len += 1;
520         }
521
522         if (forest_name && *forest_name) {
523                 init_unistr2(&r_l->uni_forest_name, forest_name, UNI_FLAGS_NONE);
524                 init_uni_hdr(&r_l->hdr_forest_name, &r_l->uni_forest_name);
525                 r_l->hdr_forest_name.uni_max_len += 2;
526                 r_l->uni_forest_name.uni_max_len += 1;
527         }
528
529         /* how do we init the guid ? probably should write an init fn */
530         if (dom_guid) {
531                 memcpy(&r_l->dom_guid, dom_guid, sizeof(struct GUID));
532         }
533
534         if (dom_sid) {
535                 r_l->ptr_dom_sid = 1;
536                 init_dom_sid2(&r_l->dom_sid, dom_sid);
537         }
538 }
539 #endif  /* AD DC work in ongoing in Samba 4 */
540
541
542 /***************************************************************************
543  _lsa_OpenPolicy2
544  ***************************************************************************/
545
546 NTSTATUS _lsa_OpenPolicy2(pipes_struct *p,
547                           struct lsa_OpenPolicy2 *r)
548 {
549         struct lsa_info *info;
550         SEC_DESC *psd = NULL;
551         size_t sd_size;
552         uint32 des_access = r->in.access_mask;
553         uint32 acc_granted;
554         NTSTATUS status;
555
556
557         /* map the generic bits to the lsa policy ones */
558         se_map_generic(&des_access, &lsa_generic_mapping);
559
560         /* get the generic lsa policy SD until we store it */
561         lsa_get_generic_sd(p->mem_ctx, &psd, &sd_size);
562
563         if(!se_access_check(psd, p->pipe_user.nt_user_token, des_access, &acc_granted, &status)) {
564                 if (p->pipe_user.ut.uid != sec_initial_uid()) {
565                         return status;
566                 }
567                 DEBUG(4,("ACCESS should be DENIED (granted: %#010x;  required: %#010x)\n",
568                          acc_granted, des_access));
569                 DEBUGADD(4,("but overwritten by euid == 0\n"));
570         }
571
572         /* This is needed for lsa_open_account and rpcclient .... :-) */
573
574         if (p->pipe_user.ut.uid == sec_initial_uid())
575                 acc_granted = POLICY_ALL_ACCESS;
576
577         /* associate the domain SID with the (unique) handle. */
578         if ((info = SMB_MALLOC_P(struct lsa_info)) == NULL)
579                 return NT_STATUS_NO_MEMORY;
580
581         ZERO_STRUCTP(info);
582         sid_copy(&info->sid,get_global_sam_sid());
583         info->access = acc_granted;
584
585         /* set up the LSA QUERY INFO response */
586         if (!create_policy_hnd(p, r->out.handle, free_lsa_info, (void *)info))
587                 return NT_STATUS_OBJECT_NAME_NOT_FOUND;
588
589         return NT_STATUS_OK;
590 }
591
592 /***************************************************************************
593  _lsa_OpenPolicy
594  ***************************************************************************/
595
596 NTSTATUS _lsa_OpenPolicy(pipes_struct *p,
597                          struct lsa_OpenPolicy *r)
598 {
599         struct lsa_info *info;
600         SEC_DESC *psd = NULL;
601         size_t sd_size;
602         uint32 des_access= r->in.access_mask;
603         uint32 acc_granted;
604         NTSTATUS status;
605
606
607         /* map the generic bits to the lsa policy ones */
608         se_map_generic(&des_access, &lsa_generic_mapping);
609
610         /* get the generic lsa policy SD until we store it */
611         lsa_get_generic_sd(p->mem_ctx, &psd, &sd_size);
612
613         if(!se_access_check(psd, p->pipe_user.nt_user_token, des_access, &acc_granted, &status)) {
614                 if (geteuid() != 0) {
615                         return status;
616                 }
617                 DEBUG(4,("ACCESS should be DENIED (granted: %#010x;  required: %#010x)\n",
618                          acc_granted, des_access));
619                 DEBUGADD(4,("but overwritten by euid == 0\n"));
620                 acc_granted = des_access;
621         }
622
623         /* associate the domain SID with the (unique) handle. */
624         if ((info = SMB_MALLOC_P(struct lsa_info)) == NULL)
625                 return NT_STATUS_NO_MEMORY;
626
627         ZERO_STRUCTP(info);
628         sid_copy(&info->sid,get_global_sam_sid());
629         info->access = acc_granted;
630
631         /* set up the LSA QUERY INFO response */
632         if (!create_policy_hnd(p, r->out.handle, free_lsa_info, (void *)info))
633                 return NT_STATUS_OBJECT_NAME_NOT_FOUND;
634
635         return NT_STATUS_OK;
636 }
637
638 /***************************************************************************
639  _lsa_EnumTrustDom - this needs fixing to do more than return NULL ! JRA.
640  ufff, done :)  mimir
641  ***************************************************************************/
642
643 NTSTATUS _lsa_EnumTrustDom(pipes_struct *p,
644                            struct lsa_EnumTrustDom *r)
645 {
646         struct lsa_info *info;
647         uint32 next_idx;
648         struct trustdom_info **domains;
649         struct lsa_DomainInfo *lsa_domains = NULL;
650         int i;
651
652         /*
653          * preferred length is set to 5 as a "our" preferred length
654          * nt sets this parameter to 2
655          * update (20.08.2002): it's not preferred length, but preferred size!
656          * it needs further investigation how to optimally choose this value
657          */
658         uint32 max_num_domains =
659                 r->in.max_size < 5 ? r->in.max_size : 10;
660         uint32 num_domains;
661         NTSTATUS nt_status;
662         uint32 num_thistime;
663
664         if (!find_policy_by_hnd(p, r->in.handle, (void **)(void *)&info))
665                 return NT_STATUS_INVALID_HANDLE;
666
667         /* check if the user have enough rights */
668         if (!(info->access & POLICY_VIEW_LOCAL_INFORMATION))
669                 return NT_STATUS_ACCESS_DENIED;
670
671         nt_status = pdb_enum_trusteddoms(p->mem_ctx, &num_domains, &domains);
672
673         if (!NT_STATUS_IS_OK(nt_status)) {
674                 return nt_status;
675         }
676
677         if (*r->in.resume_handle < num_domains) {
678                 num_thistime = MIN(num_domains, max_num_domains);
679
680                 nt_status = STATUS_MORE_ENTRIES;
681
682                 if (*r->in.resume_handle + num_thistime > num_domains) {
683                         num_thistime = num_domains - *r->in.resume_handle;
684                         nt_status = NT_STATUS_OK;
685                 }
686
687                 next_idx = *r->in.resume_handle + num_thistime;
688         } else {
689                 num_thistime = 0;
690                 next_idx = 0xffffffff;
691                 nt_status = NT_STATUS_NO_MORE_ENTRIES;
692         }
693
694         /* set up the lsa_enum_trust_dom response */
695
696         lsa_domains = TALLOC_ZERO_ARRAY(p->mem_ctx, struct lsa_DomainInfo,
697                                         num_thistime);
698         if (!lsa_domains) {
699                 return NT_STATUS_NO_MEMORY;
700         }
701
702         for (i=0; i<num_thistime; i++) {
703                 init_lsa_StringLarge(&lsa_domains[i].name, domains[i]->name);
704                 lsa_domains[i].sid = &domains[i]->sid;
705         }
706
707         *r->out.resume_handle = next_idx;
708         r->out.domains->count = num_thistime;
709         r->out.domains->domains = lsa_domains;
710
711         return nt_status;
712 }
713
714 /***************************************************************************
715  _lsa_QueryInfoPolicy
716  ***************************************************************************/
717
718 NTSTATUS _lsa_QueryInfoPolicy(pipes_struct *p,
719                               struct lsa_QueryInfoPolicy *r)
720 {
721         NTSTATUS status = NT_STATUS_OK;
722         struct lsa_info *handle;
723         DOM_SID domain_sid;
724         const char *name;
725         DOM_SID *sid = NULL;
726         union lsa_PolicyInformation *info = NULL;
727
728         if (!find_policy_by_hnd(p, r->in.handle, (void **)(void *)&handle))
729                 return NT_STATUS_INVALID_HANDLE;
730
731         info = TALLOC_ZERO_P(p->mem_ctx, union lsa_PolicyInformation);
732         if (!info) {
733                 return NT_STATUS_NO_MEMORY;
734         }
735
736         switch (r->in.level) {
737         case 0x02:
738                 {
739
740                 uint32 policy_def = LSA_AUDIT_POLICY_ALL;
741
742                 /* check if the user have enough rights */
743                 if (!(handle->access & POLICY_VIEW_AUDIT_INFORMATION)) {
744                         DEBUG(10,("_lsa_QueryInfoPolicy: insufficient access rights\n"));
745                         return NT_STATUS_ACCESS_DENIED;
746                 }
747
748                 /* fake info: We audit everything. ;) */
749
750                 info->audit_events.auditing_mode = true;
751                 info->audit_events.count = LSA_AUDIT_NUM_CATEGORIES;
752                 info->audit_events.settings = TALLOC_ZERO_ARRAY(p->mem_ctx,
753                                                                 enum lsa_PolicyAuditPolicy,
754                                                                 info->audit_events.count);
755                 if (!info->audit_events.settings) {
756                         return NT_STATUS_NO_MEMORY;
757                 }
758
759                 info->audit_events.settings[LSA_AUDIT_CATEGORY_ACCOUNT_MANAGEMENT] = policy_def;
760                 info->audit_events.settings[LSA_AUDIT_CATEGORY_FILE_AND_OBJECT_ACCESS] = policy_def;
761                 info->audit_events.settings[LSA_AUDIT_CATEGORY_LOGON] = policy_def;
762                 info->audit_events.settings[LSA_AUDIT_CATEGORY_PROCCESS_TRACKING] = policy_def;
763                 info->audit_events.settings[LSA_AUDIT_CATEGORY_SECURITY_POLICY_CHANGES] = policy_def;
764                 info->audit_events.settings[LSA_AUDIT_CATEGORY_SYSTEM] = policy_def;
765                 info->audit_events.settings[LSA_AUDIT_CATEGORY_USE_OF_USER_RIGHTS] = policy_def;
766
767                 break;
768                 }
769         case 0x03:
770                 /* check if the user have enough rights */
771                 if (!(handle->access & POLICY_VIEW_LOCAL_INFORMATION))
772                         return NT_STATUS_ACCESS_DENIED;
773
774                 /* Request PolicyPrimaryDomainInformation. */
775                 switch (lp_server_role()) {
776                         case ROLE_DOMAIN_PDC:
777                         case ROLE_DOMAIN_BDC:
778                                 name = get_global_sam_name();
779                                 sid = get_global_sam_sid();
780                                 break;
781                         case ROLE_DOMAIN_MEMBER:
782                                 name = lp_workgroup();
783                                 /* We need to return the Domain SID here. */
784                                 if (secrets_fetch_domain_sid(lp_workgroup(), &domain_sid))
785                                         sid = &domain_sid;
786                                 else
787                                         return NT_STATUS_CANT_ACCESS_DOMAIN_INFO;
788                                 break;
789                         case ROLE_STANDALONE:
790                                 name = lp_workgroup();
791                                 sid = NULL;
792                                 break;
793                         default:
794                                 return NT_STATUS_CANT_ACCESS_DOMAIN_INFO;
795                 }
796                 init_dom_query_3(&info->domain, name, sid);
797                 break;
798         case 0x05:
799                 /* check if the user have enough rights */
800                 if (!(handle->access & POLICY_VIEW_LOCAL_INFORMATION))
801                         return NT_STATUS_ACCESS_DENIED;
802
803                 /* Request PolicyAccountDomainInformation. */
804                 name = get_global_sam_name();
805                 sid = get_global_sam_sid();
806
807                 init_dom_query_5(&info->account_domain, name, sid);
808                 break;
809         case 0x06:
810                 /* check if the user have enough rights */
811                 if (!(handle->access & POLICY_VIEW_LOCAL_INFORMATION))
812                         return NT_STATUS_ACCESS_DENIED;
813
814                 switch (lp_server_role()) {
815                         case ROLE_DOMAIN_BDC:
816                                 /*
817                                  * only a BDC is a backup controller
818                                  * of the domain, it controls.
819                                  */
820                                 info->role.role = 2;
821                                 break;
822                         default:
823                                 /*
824                                  * any other role is a primary
825                                  * of the domain, it controls.
826                                  */
827                                 info->role.role = 3;
828                                 break;
829                 }
830                 break;
831         default:
832                 DEBUG(0,("_lsa_QueryInfoPolicy: unknown info level in Lsa Query: %d\n",
833                         r->in.level));
834                 status = NT_STATUS_INVALID_INFO_CLASS;
835                 break;
836         }
837
838         *r->out.info = info;
839
840         return status;
841 }
842
843 /***************************************************************************
844  _lsa_lookup_sids_internal
845  ***************************************************************************/
846
847 static NTSTATUS _lsa_lookup_sids_internal(pipes_struct *p,
848                                 uint16 level,                           /* input */
849                                 int num_sids,                           /* input */
850                                 const DOM_SID2 *sid,                    /* input */
851                                 DOM_R_REF **pp_ref,                     /* output */
852                                 LSA_TRANS_NAME_ENUM2 *names,            /* input/output */
853                                 uint32 *pp_mapped_count)
854 {
855         NTSTATUS status;
856         int i;
857         const DOM_SID **sids = NULL;
858         DOM_R_REF *ref = NULL;
859         uint32 mapped_count = 0;
860         struct lsa_dom_info *dom_infos = NULL;
861         struct lsa_name_info *name_infos = NULL;
862
863         *pp_mapped_count = 0;
864         *pp_ref = NULL;
865         ZERO_STRUCTP(names);
866
867         if (num_sids == 0) {
868                 return NT_STATUS_OK;
869         }
870
871         sids = TALLOC_ARRAY(p->mem_ctx, const DOM_SID *, num_sids);
872         ref = TALLOC_ZERO_P(p->mem_ctx, DOM_R_REF);
873
874         if (sids == NULL || ref == NULL) {
875                 return NT_STATUS_NO_MEMORY;
876         }
877
878         for (i=0; i<num_sids; i++) {
879                 sids[i] = &sid[i].sid;
880         }
881
882         status = lookup_sids(p->mem_ctx, num_sids, sids, level,
883                                   &dom_infos, &name_infos);
884
885         if (!NT_STATUS_IS_OK(status)) {
886                 return status;
887         }
888
889         names->name = TALLOC_ARRAY(p->mem_ctx, LSA_TRANS_NAME2, num_sids);
890         names->uni_name = TALLOC_ARRAY(p->mem_ctx, UNISTR2, num_sids);
891         if ((names->name == NULL) || (names->uni_name == NULL)) {
892                 return NT_STATUS_NO_MEMORY;
893         }
894
895         for (i=0; i<MAX_REF_DOMAINS; i++) {
896
897                 if (!dom_infos[i].valid) {
898                         break;
899                 }
900
901                 if (init_dom_ref(ref, dom_infos[i].name,
902                                  &dom_infos[i].sid) != i) {
903                         DEBUG(0, ("Domain %s mentioned twice??\n",
904                                   dom_infos[i].name));
905                         return NT_STATUS_INTERNAL_ERROR;
906                 }
907         }
908
909         for (i=0; i<num_sids; i++) {
910                 struct lsa_name_info *name = &name_infos[i];
911
912                 if (name->type == SID_NAME_UNKNOWN) {
913                         fstring tmp;
914                         name->dom_idx = -1;
915                         /* Unknown sids should return the string
916                          * representation of the SID. Windows 2003 behaves
917                          * rather erratic here, in many cases it returns the
918                          * RID as 8 bytes hex, in others it returns the full
919                          * SID. We (Jerry/VL) could not figure out which the
920                          * hard cases are, so leave it with the SID.  */
921                         name->name = talloc_asprintf(p->mem_ctx, "%s",
922                                                      sid_to_fstring(tmp,
923                                                                     sids[i]));
924                         if (name->name == NULL) {
925                                 return NT_STATUS_NO_MEMORY;
926                         }
927                 } else {
928                         mapped_count += 1;
929                 }
930                 init_lsa_trans_name2(&names->name[i], &names->uni_name[i],
931                                     name->type, name->name, name->dom_idx);
932         }
933
934         names->num_entries = num_sids;
935         names->ptr_trans_names = 1;
936         names->num_entries2 = num_sids;
937
938         status = NT_STATUS_NONE_MAPPED;
939         if (mapped_count > 0) {
940                 status = (mapped_count < num_sids) ?
941                         STATUS_SOME_UNMAPPED : NT_STATUS_OK;
942         }
943
944         DEBUG(10, ("num_sids %d, mapped_count %d, status %s\n",
945                    num_sids, mapped_count, nt_errstr(status)));
946
947         *pp_mapped_count = mapped_count;
948         *pp_ref = ref;
949
950         return status;
951 }
952
953 /***************************************************************************
954  _lsa_lookup_sids
955  ***************************************************************************/
956
957 NTSTATUS _lsa_lookup_sids(pipes_struct *p,
958                           LSA_Q_LOOKUP_SIDS *q_u,
959                           LSA_R_LOOKUP_SIDS *r_u)
960 {
961         struct lsa_info *handle;
962         int num_sids = q_u->sids.num_entries;
963         uint32 mapped_count = 0;
964         DOM_R_REF *ref = NULL;
965         LSA_TRANS_NAME_ENUM2 names;
966         NTSTATUS status;
967
968         if ((q_u->level < 1) || (q_u->level > 6)) {
969                 return NT_STATUS_INVALID_PARAMETER;
970         }
971
972         if (!find_policy_by_hnd(p, &q_u->pol, (void **)(void *)&handle)) {
973                 return NT_STATUS_INVALID_HANDLE;
974         }
975
976         /* check if the user has enough rights */
977         if (!(handle->access & POLICY_LOOKUP_NAMES)) {
978                 return NT_STATUS_ACCESS_DENIED;
979         }
980
981         if (num_sids >  MAX_LOOKUP_SIDS) {
982                 DEBUG(5,("_lsa_lookup_sids: limit of %d exceeded, requested %d\n",
983                          MAX_LOOKUP_SIDS, num_sids));
984                 return NT_STATUS_NONE_MAPPED;
985         }
986
987         r_u->status = _lsa_lookup_sids_internal(p,
988                                                 q_u->level,
989                                                 num_sids,
990                                                 q_u->sids.sid,
991                                                 &ref,
992                                                 &names,
993                                                 &mapped_count);
994
995         /* Convert from LSA_TRANS_NAME_ENUM2 to LSA_TRANS_NAME_ENUM */
996
997         status = init_reply_lookup_sids(p->mem_ctx, r_u, ref, &names, mapped_count);
998         if (!NT_STATUS_IS_OK(status)) {
999                 return status;
1000         }
1001         return r_u->status;
1002 }
1003
1004 /***************************************************************************
1005  _lsa_lookup_sids2
1006  ***************************************************************************/
1007
1008 NTSTATUS _lsa_lookup_sids2(pipes_struct *p,
1009                           LSA_Q_LOOKUP_SIDS2 *q_u,
1010                           LSA_R_LOOKUP_SIDS2 *r_u)
1011 {
1012         struct lsa_info *handle;
1013         int num_sids = q_u->sids.num_entries;
1014         uint32 mapped_count = 0;
1015         DOM_R_REF *ref = NULL;
1016
1017         if ((q_u->level < 1) || (q_u->level > 6)) {
1018                 return NT_STATUS_INVALID_PARAMETER;
1019         }
1020
1021         if (!find_policy_by_hnd(p, &q_u->pol, (void **)(void *)&handle)) {
1022                 return NT_STATUS_INVALID_HANDLE;
1023         }
1024
1025         /* check if the user have enough rights */
1026         if (!(handle->access & POLICY_LOOKUP_NAMES)) {
1027                 return NT_STATUS_ACCESS_DENIED;
1028         }
1029
1030         if (num_sids >  MAX_LOOKUP_SIDS) {
1031                 DEBUG(5,("_lsa_lookup_sids2: limit of %d exceeded, requested %d\n",
1032                          MAX_LOOKUP_SIDS, num_sids));
1033                 return NT_STATUS_NONE_MAPPED;
1034         }
1035
1036         r_u->status = _lsa_lookup_sids_internal(p,
1037                                                 q_u->level,
1038                                                 num_sids,
1039                                                 q_u->sids.sid,
1040                                                 &ref,
1041                                                 &r_u->names,
1042                                                 &mapped_count);
1043
1044         init_reply_lookup_sids2(r_u, ref, mapped_count);
1045         return r_u->status;
1046 }
1047
1048 /***************************************************************************
1049  _lsa_lookup_sida3
1050  ***************************************************************************/
1051
1052 NTSTATUS _lsa_lookup_sids3(pipes_struct *p,
1053                           LSA_Q_LOOKUP_SIDS3 *q_u,
1054                           LSA_R_LOOKUP_SIDS3 *r_u)
1055 {
1056         int num_sids = q_u->sids.num_entries;
1057         uint32 mapped_count = 0;
1058         DOM_R_REF *ref = NULL;
1059
1060         if ((q_u->level < 1) || (q_u->level > 6)) {
1061                 return NT_STATUS_INVALID_PARAMETER;
1062         }
1063
1064         /* No policy handle on this call. Restrict to crypto connections. */
1065         if (p->auth.auth_type != PIPE_AUTH_TYPE_SCHANNEL) {
1066                 DEBUG(0,("_lsa_lookup_sids3: client %s not using schannel for netlogon\n",
1067                         get_remote_machine_name() ));
1068                 return NT_STATUS_INVALID_PARAMETER;
1069         }
1070
1071         if (num_sids >  MAX_LOOKUP_SIDS) {
1072                 DEBUG(5,("_lsa_lookup_sids3: limit of %d exceeded, requested %d\n",
1073                          MAX_LOOKUP_SIDS, num_sids));
1074                 return NT_STATUS_NONE_MAPPED;
1075         }
1076
1077         r_u->status = _lsa_lookup_sids_internal(p,
1078                                                 q_u->level,
1079                                                 num_sids,
1080                                                 q_u->sids.sid,
1081                                                 &ref,
1082                                                 &r_u->names,
1083                                                 &mapped_count);
1084
1085         init_reply_lookup_sids3(r_u, ref, mapped_count);
1086         return r_u->status;
1087 }
1088
1089 static int lsa_lookup_level_to_flags(uint16 level)
1090 {
1091         int flags;
1092
1093         switch (level) {
1094                 case 1:
1095                         flags = LOOKUP_NAME_ALL;
1096                         break;
1097                 case 2:
1098                         flags = LOOKUP_NAME_DOMAIN|LOOKUP_NAME_REMOTE|LOOKUP_NAME_ISOLATED;
1099                         break;
1100                 case 3:
1101                         flags = LOOKUP_NAME_DOMAIN|LOOKUP_NAME_ISOLATED;
1102                         break;
1103                 case 4:
1104                 case 5:
1105                 case 6:
1106                 default:
1107                         flags = LOOKUP_NAME_NONE;
1108                         break;
1109         }
1110
1111         return flags;
1112 }
1113
1114 /***************************************************************************
1115  _lsa_LookupNames
1116  ***************************************************************************/
1117
1118 NTSTATUS _lsa_LookupNames(pipes_struct *p,
1119                           struct lsa_LookupNames *r)
1120 {
1121         NTSTATUS status = NT_STATUS_NONE_MAPPED;
1122         struct lsa_info *handle;
1123         struct lsa_String *names = r->in.names;
1124         uint32 num_entries = r->in.num_names;
1125         struct lsa_RefDomainList *domains = NULL;
1126         struct lsa_TranslatedSid *rids = NULL;
1127         uint32 mapped_count = 0;
1128         int flags = 0;
1129
1130         if (num_entries >  MAX_LOOKUP_SIDS) {
1131                 num_entries = MAX_LOOKUP_SIDS;
1132                 DEBUG(5,("_lsa_LookupNames: truncating name lookup list to %d\n",
1133                         num_entries));
1134         }
1135
1136         flags = lsa_lookup_level_to_flags(r->in.level);
1137
1138         domains = TALLOC_ZERO_P(p->mem_ctx, struct lsa_RefDomainList);
1139         if (!domains) {
1140                 return NT_STATUS_NO_MEMORY;
1141         }
1142
1143         if (num_entries) {
1144                 rids = TALLOC_ZERO_ARRAY(p->mem_ctx, struct lsa_TranslatedSid,
1145                                          num_entries);
1146                 if (!rids) {
1147                         return NT_STATUS_NO_MEMORY;
1148                 }
1149         } else {
1150                 rids = NULL;
1151         }
1152
1153         if (!find_policy_by_hnd(p, r->in.handle, (void **)(void *)&handle)) {
1154                 status = NT_STATUS_INVALID_HANDLE;
1155                 goto done;
1156         }
1157
1158         /* check if the user have enough rights */
1159         if (!(handle->access & POLICY_LOOKUP_NAMES)) {
1160                 status = NT_STATUS_ACCESS_DENIED;
1161                 goto done;
1162         }
1163
1164         /* set up the LSA Lookup RIDs response */
1165         become_root(); /* lookup_name can require root privs */
1166         status = lookup_lsa_rids(p->mem_ctx, domains, rids, num_entries,
1167                                  names, flags, &mapped_count);
1168         unbecome_root();
1169
1170 done:
1171
1172         if (NT_STATUS_IS_OK(status) && (num_entries != 0) ) {
1173                 if (mapped_count == 0) {
1174                         status = NT_STATUS_NONE_MAPPED;
1175                 } else if (mapped_count != num_entries) {
1176                         status = STATUS_SOME_UNMAPPED;
1177                 }
1178         }
1179
1180         *r->out.count = num_entries;
1181         *r->out.domains = domains;
1182         r->out.sids->sids = rids;
1183         r->out.sids->count = mapped_count;
1184
1185         return status;
1186 }
1187
1188 /***************************************************************************
1189  _lsa_LookupNames2
1190  ***************************************************************************/
1191
1192 NTSTATUS _lsa_LookupNames2(pipes_struct *p,
1193                            struct lsa_LookupNames2 *r)
1194 {
1195         NTSTATUS status;
1196         struct lsa_LookupNames q;
1197         struct lsa_TransSidArray2 *sid_array2 = r->in.sids;
1198         struct lsa_TransSidArray *sid_array = NULL;
1199         uint32_t i;
1200
1201         sid_array = TALLOC_ZERO_P(p->mem_ctx, struct lsa_TransSidArray);
1202         if (!sid_array) {
1203                 return NT_STATUS_NO_MEMORY;
1204         }
1205
1206         q.in.handle             = r->in.handle;
1207         q.in.num_names          = r->in.num_names;
1208         q.in.names              = r->in.names;
1209         q.in.level              = r->in.level;
1210         q.in.sids               = sid_array;
1211         q.in.count              = r->in.count;
1212         /* we do not know what this is for */
1213         /*                      = r->in.unknown1; */
1214         /*                      = r->in.unknown2; */
1215
1216         q.out.domains           = r->out.domains;
1217         q.out.sids              = sid_array;
1218         q.out.count             = r->out.count;
1219
1220         status = _lsa_LookupNames(p, &q);
1221
1222         sid_array2->sids = TALLOC_ARRAY(p->mem_ctx, struct lsa_TranslatedSid2, sid_array->count);
1223         if (!sid_array2->sids) {
1224                 return NT_STATUS_NO_MEMORY;
1225         }
1226
1227         for (i=0; i<sid_array->count; i++) {
1228                 sid_array2->sids[i].sid_type  = sid_array->sids[i].sid_type;
1229                 sid_array2->sids[i].rid       = sid_array->sids[i].rid;
1230                 sid_array2->sids[i].sid_index = sid_array->sids[i].sid_index;
1231                 sid_array2->sids[i].unknown   = 0;
1232         }
1233
1234         r->out.sids = sid_array2;
1235
1236         return status;
1237 }
1238
1239 /***************************************************************************
1240 lsa_reply_lookup_names3.
1241  ***************************************************************************/
1242
1243 NTSTATUS _lsa_lookup_names3(pipes_struct *p, LSA_Q_LOOKUP_NAMES3 *q_u, LSA_R_LOOKUP_NAMES3 *r_u)
1244 {
1245         struct lsa_info *handle;
1246         UNISTR2 *names = q_u->uni_name;
1247         uint32 num_entries = q_u->num_entries;
1248         DOM_R_REF *ref = NULL;
1249         LSA_TRANSLATED_SID3 *trans_sids = NULL;
1250         uint32 mapped_count = 0;
1251         int flags = 0;
1252
1253         if (num_entries >  MAX_LOOKUP_SIDS) {
1254                 num_entries = MAX_LOOKUP_SIDS;
1255                 DEBUG(5,("_lsa_lookup_names3: truncating name lookup list to %d\n", num_entries));
1256         }
1257
1258         /* Probably the lookup_level is some sort of bitmask. */
1259         if (q_u->lookup_level == 1) {
1260                 flags = LOOKUP_NAME_ALL;
1261         }
1262
1263         ref = TALLOC_ZERO_P(p->mem_ctx, DOM_R_REF);
1264         if (ref == NULL) {
1265                 return NT_STATUS_NO_MEMORY;
1266         }
1267         if (num_entries) {
1268                 trans_sids = TALLOC_ZERO_ARRAY(p->mem_ctx, LSA_TRANSLATED_SID3, num_entries);
1269                 if (!trans_sids) {
1270                         return NT_STATUS_NO_MEMORY;
1271                 }
1272         } else {
1273                 trans_sids = NULL;
1274         }
1275
1276         if (!find_policy_by_hnd(p, &q_u->pol, (void **)(void *)&handle)) {
1277                 r_u->status = NT_STATUS_INVALID_HANDLE;
1278                 goto done;
1279         }
1280
1281         /* check if the user have enough rights */
1282         if (!(handle->access & POLICY_LOOKUP_NAMES)) {
1283                 r_u->status = NT_STATUS_ACCESS_DENIED;
1284                 goto done;
1285         }
1286
1287         /* set up the LSA Lookup SIDs response */
1288         become_root(); /* lookup_name can require root privs */
1289         r_u->status = lookup_lsa_sids(p->mem_ctx, ref, trans_sids, num_entries,
1290                                       names, flags, &mapped_count);
1291         unbecome_root();
1292
1293 done:
1294
1295         if (NT_STATUS_IS_OK(r_u->status)) {
1296                 if (mapped_count == 0) {
1297                         r_u->status = NT_STATUS_NONE_MAPPED;
1298                 } else if (mapped_count != num_entries) {
1299                         r_u->status = STATUS_SOME_UNMAPPED;
1300                 }
1301         }
1302
1303         init_reply_lookup_names3(r_u, ref, num_entries, trans_sids, mapped_count);
1304         return r_u->status;
1305 }
1306
1307 /***************************************************************************
1308 lsa_reply_lookup_names4.
1309  ***************************************************************************/
1310
1311 NTSTATUS _lsa_lookup_names4(pipes_struct *p, LSA_Q_LOOKUP_NAMES4 *q_u, LSA_R_LOOKUP_NAMES4 *r_u)
1312 {
1313         UNISTR2 *names = q_u->uni_name;
1314         uint32 num_entries = q_u->num_entries;
1315         DOM_R_REF *ref = NULL;
1316         LSA_TRANSLATED_SID3 *trans_sids = NULL;
1317         uint32 mapped_count = 0;
1318         int flags = 0;
1319
1320         if (num_entries >  MAX_LOOKUP_SIDS) {
1321                 num_entries = MAX_LOOKUP_SIDS;
1322                 DEBUG(5,("_lsa_lookup_names4: truncating name lookup list to %d\n", num_entries));
1323         }
1324
1325         /* Probably the lookup_level is some sort of bitmask. */
1326         if (q_u->lookup_level == 1) {
1327                 flags = LOOKUP_NAME_ALL;
1328         }
1329
1330         /* No policy handle on this call. Restrict to crypto connections. */
1331         if (p->auth.auth_type != PIPE_AUTH_TYPE_SCHANNEL) {
1332                 DEBUG(0,("_lsa_lookup_names4: client %s not using schannel for netlogon\n",
1333                         get_remote_machine_name() ));
1334                 return NT_STATUS_INVALID_PARAMETER;
1335         }
1336
1337         ref = TALLOC_ZERO_P(p->mem_ctx, DOM_R_REF);
1338         if (!ref) {
1339                 return NT_STATUS_NO_MEMORY;
1340         }
1341
1342         if (num_entries) {
1343                 trans_sids = TALLOC_ZERO_ARRAY(p->mem_ctx, LSA_TRANSLATED_SID3, num_entries);
1344                 if (!trans_sids) {
1345                         return NT_STATUS_NO_MEMORY;
1346                 }
1347         } else {
1348                 trans_sids = NULL;
1349         }
1350
1351         /* set up the LSA Lookup SIDs response */
1352         become_root(); /* lookup_name can require root privs */
1353         r_u->status = lookup_lsa_sids(p->mem_ctx, ref, trans_sids, num_entries,
1354                                       names, flags, &mapped_count);
1355         unbecome_root();
1356
1357         if (NT_STATUS_IS_OK(r_u->status)) {
1358                 if (mapped_count == 0) {
1359                         r_u->status = NT_STATUS_NONE_MAPPED;
1360                 } else if (mapped_count != num_entries) {
1361                         r_u->status = STATUS_SOME_UNMAPPED;
1362                 }
1363         }
1364
1365         init_reply_lookup_names4(r_u, ref, num_entries, trans_sids, mapped_count);
1366         return r_u->status;
1367 }
1368
1369 /***************************************************************************
1370  _lsa_close. Also weird - needs to check if lsa handle is correct. JRA.
1371  ***************************************************************************/
1372
1373 NTSTATUS _lsa_Close(pipes_struct *p, struct lsa_Close *r)
1374 {
1375         if (!find_policy_by_hnd(p, r->in.handle, NULL)) {
1376                 return NT_STATUS_INVALID_HANDLE;
1377         }
1378
1379         close_policy_hnd(p, r->in.handle);
1380         return NT_STATUS_OK;
1381 }
1382
1383 /***************************************************************************
1384  ***************************************************************************/
1385
1386 NTSTATUS _lsa_OpenSecret(pipes_struct *p, struct lsa_OpenSecret *r)
1387 {
1388         return NT_STATUS_OBJECT_NAME_NOT_FOUND;
1389 }
1390
1391 /***************************************************************************
1392  ***************************************************************************/
1393
1394 NTSTATUS _lsa_OpenTrustedDomain(pipes_struct *p, struct lsa_OpenTrustedDomain *r)
1395 {
1396         return NT_STATUS_OBJECT_NAME_NOT_FOUND;
1397 }
1398
1399 /***************************************************************************
1400  ***************************************************************************/
1401
1402 NTSTATUS _lsa_CreateTrustedDomain(pipes_struct *p, struct lsa_CreateTrustedDomain *r)
1403 {
1404         return NT_STATUS_ACCESS_DENIED;
1405 }
1406
1407 /***************************************************************************
1408  ***************************************************************************/
1409
1410 NTSTATUS _lsa_CreateSecret(pipes_struct *p, struct lsa_CreateSecret *r)
1411 {
1412         return NT_STATUS_ACCESS_DENIED;
1413 }
1414
1415 /***************************************************************************
1416  ***************************************************************************/
1417
1418 NTSTATUS _lsa_SetSecret(pipes_struct *p, struct lsa_SetSecret *r)
1419 {
1420         return NT_STATUS_ACCESS_DENIED;
1421 }
1422
1423 /***************************************************************************
1424  _lsa_DeleteObject
1425  ***************************************************************************/
1426
1427 NTSTATUS _lsa_DeleteObject(pipes_struct *p,
1428                            struct lsa_DeleteObject *r)
1429 {
1430         return NT_STATUS_ACCESS_DENIED;
1431 }
1432
1433 /***************************************************************************
1434  _lsa_EnumPrivs
1435  ***************************************************************************/
1436
1437 NTSTATUS _lsa_EnumPrivs(pipes_struct *p,
1438                         struct lsa_EnumPrivs *r)
1439 {
1440         struct lsa_info *handle;
1441         uint32 i;
1442         uint32 enum_context = *r->in.resume_handle;
1443         int num_privs = count_all_privileges();
1444         struct lsa_PrivEntry *entries = NULL;
1445         LUID_ATTR luid;
1446
1447         /* remember that the enum_context starts at 0 and not 1 */
1448
1449         if ( enum_context >= num_privs )
1450                 return NT_STATUS_NO_MORE_ENTRIES;
1451
1452         DEBUG(10,("_lsa_EnumPrivs: enum_context:%d total entries:%d\n",
1453                 enum_context, num_privs));
1454
1455         if (!find_policy_by_hnd(p, r->in.handle, (void **)(void *)&handle))
1456                 return NT_STATUS_INVALID_HANDLE;
1457
1458         /* check if the user have enough rights
1459            I don't know if it's the right one. not documented.  */
1460
1461         if (!(handle->access & POLICY_VIEW_LOCAL_INFORMATION))
1462                 return NT_STATUS_ACCESS_DENIED;
1463
1464         if (num_privs) {
1465                 entries = TALLOC_ZERO_ARRAY(p->mem_ctx, struct lsa_PrivEntry, num_privs);
1466                 if (!entries) {
1467                         return NT_STATUS_NO_MEMORY;
1468                 }
1469         } else {
1470                 entries = NULL;
1471         }
1472
1473         for (i = 0; i < num_privs; i++) {
1474                 if( i < enum_context) {
1475
1476                         init_lsa_StringLarge(&entries[i].name, NULL);
1477
1478                         entries[i].luid.low = 0;
1479                         entries[i].luid.high = 0;
1480                 } else {
1481
1482                         init_lsa_StringLarge(&entries[i].name, privs[i].name);
1483
1484                         luid = get_privilege_luid( &privs[i].se_priv );
1485
1486                         entries[i].luid.low = luid.luid.low;
1487                         entries[i].luid.high = luid.luid.high;
1488                 }
1489         }
1490
1491         enum_context = num_privs;
1492
1493         *r->out.resume_handle = enum_context;
1494         r->out.privs->count = num_privs;
1495         r->out.privs->privs = entries;
1496
1497         return NT_STATUS_OK;
1498 }
1499
1500 /***************************************************************************
1501  _lsa_LookupPrivDisplayName
1502  ***************************************************************************/
1503
1504 NTSTATUS _lsa_LookupPrivDisplayName(pipes_struct *p,
1505                                     struct lsa_LookupPrivDisplayName *r)
1506 {
1507         struct lsa_info *handle;
1508         const char *description;
1509         struct lsa_StringLarge *lsa_name;
1510
1511         if (!find_policy_by_hnd(p, r->in.handle, (void **)(void *)&handle))
1512                 return NT_STATUS_INVALID_HANDLE;
1513
1514         /* check if the user have enough rights */
1515
1516         /*
1517          * I don't know if it's the right one. not documented.
1518          */
1519         if (!(handle->access & POLICY_VIEW_LOCAL_INFORMATION))
1520                 return NT_STATUS_ACCESS_DENIED;
1521
1522         DEBUG(10,("_lsa_LookupPrivDisplayName: name = %s\n", r->in.name->string));
1523
1524         description = get_privilege_dispname(r->in.name->string);
1525         if (!description) {
1526                 DEBUG(10,("_lsa_LookupPrivDisplayName: doesn't exist\n"));
1527                 return NT_STATUS_NO_SUCH_PRIVILEGE;
1528         }
1529
1530         DEBUG(10,("_lsa_LookupPrivDisplayName: display name = %s\n", description));
1531
1532         lsa_name = TALLOC_ZERO_P(p->mem_ctx, struct lsa_StringLarge);
1533         if (!lsa_name) {
1534                 return NT_STATUS_NO_MEMORY;
1535         }
1536
1537         init_lsa_StringLarge(lsa_name, description);
1538
1539         *r->out.returned_language_id = r->in.language_id;
1540         *r->out.disp_name = lsa_name;
1541
1542         return NT_STATUS_OK;
1543 }
1544
1545 /***************************************************************************
1546  _lsa_EnumAccounts
1547  ***************************************************************************/
1548
1549 NTSTATUS _lsa_EnumAccounts(pipes_struct *p,
1550                            struct lsa_EnumAccounts *r)
1551 {
1552         struct lsa_info *handle;
1553         DOM_SID *sid_list;
1554         int i, j, num_entries;
1555         NTSTATUS status;
1556         struct lsa_SidPtr *sids = NULL;
1557
1558         if (!find_policy_by_hnd(p, r->in.handle, (void **)(void *)&handle))
1559                 return NT_STATUS_INVALID_HANDLE;
1560
1561         if (!(handle->access & POLICY_VIEW_LOCAL_INFORMATION))
1562                 return NT_STATUS_ACCESS_DENIED;
1563
1564         sid_list = NULL;
1565         num_entries = 0;
1566
1567         /* The only way we can currently find out all the SIDs that have been
1568            privileged is to scan all privileges */
1569
1570         status = privilege_enumerate_accounts(&sid_list, &num_entries);
1571         if (!NT_STATUS_IS_OK(status)) {
1572                 return status;
1573         }
1574
1575         if (*r->in.resume_handle >= num_entries) {
1576                 return NT_STATUS_NO_MORE_ENTRIES;
1577         }
1578
1579         if (num_entries - *r->in.resume_handle) {
1580                 sids = TALLOC_ZERO_ARRAY(p->mem_ctx, struct lsa_SidPtr,
1581                                          num_entries - *r->in.resume_handle);
1582                 if (!sids) {
1583                         SAFE_FREE(sid_list);
1584                         return NT_STATUS_NO_MEMORY;
1585                 }
1586
1587                 for (i = *r->in.resume_handle, j = 0; i < num_entries; i++, j++) {
1588                         sids[j].sid = sid_dup_talloc(p->mem_ctx, &sid_list[i]);
1589                         if (!sids[j].sid) {
1590                                 SAFE_FREE(sid_list);
1591                                 return NT_STATUS_NO_MEMORY;
1592                         }
1593                 }
1594         }
1595
1596         talloc_free(sid_list);
1597
1598         *r->out.resume_handle = num_entries;
1599         r->out.sids->num_sids = num_entries;
1600         r->out.sids->sids = sids;
1601
1602         return NT_STATUS_OK;
1603 }
1604
1605 /***************************************************************************
1606  _lsa_GetUserName
1607  ***************************************************************************/
1608
1609 NTSTATUS _lsa_GetUserName(pipes_struct *p,
1610                           struct lsa_GetUserName *r)
1611 {
1612         const char *username, *domname;
1613         user_struct *vuser = get_valid_user_struct(p->vuid);
1614         struct lsa_String *account_name = NULL;
1615         struct lsa_String *authority_name = NULL;
1616
1617         if (vuser == NULL)
1618                 return NT_STATUS_CANT_ACCESS_DOMAIN_INFO;
1619
1620         if (vuser->guest) {
1621                 /*
1622                  * I'm 99% sure this is not the right place to do this,
1623                  * global_sid_Anonymous should probably be put into the token
1624                  * instead of the guest id -- vl
1625                  */
1626                 if (!lookup_sid(p->mem_ctx, &global_sid_Anonymous,
1627                                 &domname, &username, NULL)) {
1628                         return NT_STATUS_NO_MEMORY;
1629                 }
1630         } else {
1631                 username = vuser->user.smb_name;
1632                 domname = vuser->user.domain;
1633         }
1634
1635         account_name = TALLOC_ZERO_P(p->mem_ctx, struct lsa_String);
1636         if (!account_name) {
1637                 return NT_STATUS_NO_MEMORY;
1638         }
1639
1640         authority_name = TALLOC_ZERO_P(p->mem_ctx, struct lsa_String);
1641         if (!authority_name) {
1642                 return NT_STATUS_NO_MEMORY;
1643         }
1644
1645         init_lsa_String(account_name, username);
1646         init_lsa_String(authority_name, domname);
1647
1648         *r->out.account_name = account_name;
1649         *r->out.authority_name = authority_name;
1650
1651         return NT_STATUS_OK;
1652 }
1653
1654 /***************************************************************************
1655  _lsa_CreateAccount
1656  ***************************************************************************/
1657
1658 NTSTATUS _lsa_CreateAccount(pipes_struct *p,
1659                             struct lsa_CreateAccount *r)
1660 {
1661         struct lsa_info *handle;
1662         struct lsa_info *info;
1663
1664         /* find the connection policy handle. */
1665         if (!find_policy_by_hnd(p, r->in.handle, (void **)(void *)&handle))
1666                 return NT_STATUS_INVALID_HANDLE;
1667
1668         /* check if the user have enough rights */
1669
1670         /*
1671          * I don't know if it's the right one. not documented.
1672          * but guessed with rpcclient.
1673          */
1674         if (!(handle->access & POLICY_GET_PRIVATE_INFORMATION))
1675                 return NT_STATUS_ACCESS_DENIED;
1676
1677         /* check to see if the pipe_user is a Domain Admin since
1678            account_pol.tdb was already opened as root, this is all we have */
1679
1680         if ( !nt_token_check_domain_rid( p->pipe_user.nt_user_token, DOMAIN_GROUP_RID_ADMINS ) )
1681                 return NT_STATUS_ACCESS_DENIED;
1682
1683         if ( is_privileged_sid( r->in.sid ) )
1684                 return NT_STATUS_OBJECT_NAME_COLLISION;
1685
1686         /* associate the user/group SID with the (unique) handle. */
1687
1688         if ((info = SMB_MALLOC_P(struct lsa_info)) == NULL)
1689                 return NT_STATUS_NO_MEMORY;
1690
1691         ZERO_STRUCTP(info);
1692         info->sid = *r->in.sid;
1693         info->access = r->in.access_mask;
1694
1695         /* get a (unique) handle.  open a policy on it. */
1696         if (!create_policy_hnd(p, r->out.acct_handle, free_lsa_info, (void *)info))
1697                 return NT_STATUS_OBJECT_NAME_NOT_FOUND;
1698
1699         return privilege_create_account( &info->sid );
1700 }
1701
1702
1703 /***************************************************************************
1704  _lsa_OpenAccount
1705  ***************************************************************************/
1706
1707 NTSTATUS _lsa_OpenAccount(pipes_struct *p,
1708                           struct lsa_OpenAccount *r)
1709 {
1710         struct lsa_info *handle;
1711         struct lsa_info *info;
1712
1713         /* find the connection policy handle. */
1714         if (!find_policy_by_hnd(p, r->in.handle, (void **)(void *)&handle))
1715                 return NT_STATUS_INVALID_HANDLE;
1716
1717         /* check if the user have enough rights */
1718
1719         /*
1720          * I don't know if it's the right one. not documented.
1721          * but guessed with rpcclient.
1722          */
1723         if (!(handle->access & POLICY_GET_PRIVATE_INFORMATION))
1724                 return NT_STATUS_ACCESS_DENIED;
1725
1726         /* TODO: Fis the parsing routine before reenabling this check! */
1727         #if 0
1728         if (!lookup_sid(&handle->sid, dom_name, name, &type))
1729                 return NT_STATUS_ACCESS_DENIED;
1730         #endif
1731         /* associate the user/group SID with the (unique) handle. */
1732         if ((info = SMB_MALLOC_P(struct lsa_info)) == NULL)
1733                 return NT_STATUS_NO_MEMORY;
1734
1735         ZERO_STRUCTP(info);
1736         info->sid = *r->in.sid;
1737         info->access = r->in.access_mask;
1738
1739         /* get a (unique) handle.  open a policy on it. */
1740         if (!create_policy_hnd(p, r->out.acct_handle, free_lsa_info, (void *)info))
1741                 return NT_STATUS_OBJECT_NAME_NOT_FOUND;
1742
1743         return NT_STATUS_OK;
1744 }
1745
1746 /***************************************************************************
1747  _lsa_EnumPrivsAccount
1748  For a given SID, enumerate all the privilege this account has.
1749  ***************************************************************************/
1750
1751 NTSTATUS _lsa_EnumPrivsAccount(pipes_struct *p,
1752                                struct lsa_EnumPrivsAccount *r)
1753 {
1754         NTSTATUS status = NT_STATUS_OK;
1755         struct lsa_info *info=NULL;
1756         SE_PRIV mask;
1757         PRIVILEGE_SET privileges;
1758         struct lsa_PrivilegeSet *priv_set = NULL;
1759         struct lsa_LUIDAttribute *luid_attrs = NULL;
1760         int i;
1761
1762         /* find the connection policy handle. */
1763         if (!find_policy_by_hnd(p, r->in.handle, (void **)(void *)&info))
1764                 return NT_STATUS_INVALID_HANDLE;
1765
1766         if ( !get_privileges_for_sids( &mask, &info->sid, 1 ) )
1767                 return NT_STATUS_OBJECT_NAME_NOT_FOUND;
1768
1769         privilege_set_init( &privileges );
1770
1771         if ( se_priv_to_privilege_set( &privileges, &mask ) ) {
1772
1773                 DEBUG(10,("_lsa_EnumPrivsAccount: %s has %d privileges\n",
1774                           sid_string_dbg(&info->sid),
1775                           privileges.count));
1776
1777                 priv_set = TALLOC_ZERO_P(p->mem_ctx, struct lsa_PrivilegeSet);
1778                 if (!priv_set) {
1779                         status = NT_STATUS_NO_MEMORY;
1780                         goto done;
1781                 }
1782
1783                 luid_attrs = TALLOC_ZERO_ARRAY(p->mem_ctx,
1784                                                struct lsa_LUIDAttribute,
1785                                                privileges.count);
1786                 if (!luid_attrs) {
1787                         status = NT_STATUS_NO_MEMORY;
1788                         goto done;
1789                 }
1790
1791                 for (i=0; i<privileges.count; i++) {
1792                         luid_attrs[i].luid.low = privileges.set[i].luid.low;
1793                         luid_attrs[i].luid.high = privileges.set[i].luid.high;
1794                         luid_attrs[i].attribute = privileges.set[i].attr;
1795                 }
1796
1797                 priv_set->count = privileges.count;
1798                 priv_set->unknown = 0;
1799                 priv_set->set = luid_attrs;
1800
1801                 *r->out.privs = priv_set;
1802         } else {
1803                 status = NT_STATUS_NO_SUCH_PRIVILEGE;
1804         }
1805
1806  done:
1807         privilege_set_free( &privileges );
1808
1809         return status;
1810 }
1811
1812 /***************************************************************************
1813  _lsa_GetSystemAccessAccount
1814  ***************************************************************************/
1815
1816 NTSTATUS _lsa_GetSystemAccessAccount(pipes_struct *p,
1817                                      struct lsa_GetSystemAccessAccount *r)
1818 {
1819         struct lsa_info *info=NULL;
1820
1821         /* find the connection policy handle. */
1822
1823         if (!find_policy_by_hnd(p, r->in.handle, (void **)(void *)&info))
1824                 return NT_STATUS_INVALID_HANDLE;
1825
1826         if (!lookup_sid(p->mem_ctx, &info->sid, NULL, NULL, NULL))
1827                 return NT_STATUS_ACCESS_DENIED;
1828
1829         /*
1830           0x01 -> Log on locally
1831           0x02 -> Access this computer from network
1832           0x04 -> Log on as a batch job
1833           0x10 -> Log on as a service
1834
1835           they can be ORed together
1836         */
1837
1838         *r->out.access_mask = PR_LOG_ON_LOCALLY | PR_ACCESS_FROM_NETWORK;
1839
1840         return NT_STATUS_OK;
1841 }
1842
1843 /***************************************************************************
1844   update the systemaccount information
1845  ***************************************************************************/
1846
1847 NTSTATUS _lsa_SetSystemAccessAccount(pipes_struct *p,
1848                                      struct lsa_SetSystemAccessAccount *r)
1849 {
1850         struct lsa_info *info=NULL;
1851         GROUP_MAP map;
1852
1853         /* find the connection policy handle. */
1854         if (!find_policy_by_hnd(p, r->in.handle, (void **)(void *)&info))
1855                 return NT_STATUS_INVALID_HANDLE;
1856
1857         /* check to see if the pipe_user is a Domain Admin since
1858            account_pol.tdb was already opened as root, this is all we have */
1859
1860         if ( !nt_token_check_domain_rid( p->pipe_user.nt_user_token, DOMAIN_GROUP_RID_ADMINS ) )
1861                 return NT_STATUS_ACCESS_DENIED;
1862
1863         if (!pdb_getgrsid(&map, info->sid))
1864                 return NT_STATUS_NO_SUCH_GROUP;
1865
1866         return pdb_update_group_mapping_entry(&map);
1867 }
1868
1869 /***************************************************************************
1870  _lsa_AddPrivilegesToAccount
1871  For a given SID, add some privileges.
1872  ***************************************************************************/
1873
1874 NTSTATUS _lsa_AddPrivilegesToAccount(pipes_struct *p,
1875                                      struct lsa_AddPrivilegesToAccount *r)
1876 {
1877         struct lsa_info *info = NULL;
1878         SE_PRIV mask;
1879         struct lsa_PrivilegeSet *set = NULL;
1880
1881         /* find the connection policy handle. */
1882         if (!find_policy_by_hnd(p, r->in.handle, (void **)(void *)&info))
1883                 return NT_STATUS_INVALID_HANDLE;
1884
1885         /* check to see if the pipe_user is root or a Domain Admin since
1886            account_pol.tdb was already opened as root, this is all we have */
1887
1888         if ( p->pipe_user.ut.uid != sec_initial_uid()
1889                 && !nt_token_check_domain_rid( p->pipe_user.nt_user_token, DOMAIN_GROUP_RID_ADMINS ) )
1890         {
1891                 return NT_STATUS_ACCESS_DENIED;
1892         }
1893
1894         set = r->in.privs;
1895         if ( !privilege_set_to_se_priv( &mask, set ) )
1896                 return NT_STATUS_NO_SUCH_PRIVILEGE;
1897
1898         if ( !grant_privilege( &info->sid, &mask ) ) {
1899                 DEBUG(3,("_lsa_AddPrivilegesToAccount: grant_privilege(%s) failed!\n",
1900                          sid_string_dbg(&info->sid) ));
1901                 DEBUG(3,("Privilege mask:\n"));
1902                 dump_se_priv( DBGC_ALL, 3, &mask );
1903                 return NT_STATUS_NO_SUCH_PRIVILEGE;
1904         }
1905
1906         return NT_STATUS_OK;
1907 }
1908
1909 /***************************************************************************
1910  _lsa_RemovePrivilegesFromAccount
1911  For a given SID, remove some privileges.
1912  ***************************************************************************/
1913
1914 NTSTATUS _lsa_RemovePrivilegesFromAccount(pipes_struct *p,
1915                                           struct lsa_RemovePrivilegesFromAccount *r)
1916 {
1917         struct lsa_info *info = NULL;
1918         SE_PRIV mask;
1919         struct lsa_PrivilegeSet *set = NULL;
1920
1921         /* find the connection policy handle. */
1922         if (!find_policy_by_hnd(p, r->in.handle, (void **)(void *)&info))
1923                 return NT_STATUS_INVALID_HANDLE;
1924
1925         /* check to see if the pipe_user is root or a Domain Admin since
1926            account_pol.tdb was already opened as root, this is all we have */
1927
1928         if ( p->pipe_user.ut.uid != sec_initial_uid()
1929                 && !nt_token_check_domain_rid( p->pipe_user.nt_user_token, DOMAIN_GROUP_RID_ADMINS ) )
1930         {
1931                 return NT_STATUS_ACCESS_DENIED;
1932         }
1933
1934         set = r->in.privs;
1935
1936         if ( !privilege_set_to_se_priv( &mask, set ) )
1937                 return NT_STATUS_NO_SUCH_PRIVILEGE;
1938
1939         if ( !revoke_privilege( &info->sid, &mask ) ) {
1940                 DEBUG(3,("_lsa_RemovePrivilegesFromAccount: revoke_privilege(%s) failed!\n",
1941                          sid_string_dbg(&info->sid) ));
1942                 DEBUG(3,("Privilege mask:\n"));
1943                 dump_se_priv( DBGC_ALL, 3, &mask );
1944                 return NT_STATUS_NO_SUCH_PRIVILEGE;
1945         }
1946
1947         return NT_STATUS_OK;
1948 }
1949
1950 /***************************************************************************
1951  _lsa_QuerySecurity
1952  ***************************************************************************/
1953
1954 NTSTATUS _lsa_QuerySecurity(pipes_struct *p,
1955                             struct lsa_QuerySecurity *r)
1956 {
1957         struct lsa_info *handle=NULL;
1958         SEC_DESC *psd = NULL;
1959         size_t sd_size;
1960         NTSTATUS status;
1961
1962         /* find the connection policy handle. */
1963         if (!find_policy_by_hnd(p, r->in.handle, (void **)(void *)&handle))
1964                 return NT_STATUS_INVALID_HANDLE;
1965
1966         /* check if the user have enough rights */
1967         if (!(handle->access & POLICY_VIEW_LOCAL_INFORMATION))
1968                 return NT_STATUS_ACCESS_DENIED;
1969
1970
1971         switch (r->in.sec_info) {
1972         case 1:
1973                 /* SD contains only the owner */
1974
1975                 status=lsa_get_generic_sd(p->mem_ctx, &psd, &sd_size);
1976                 if(!NT_STATUS_IS_OK(status))
1977                         return NT_STATUS_NO_MEMORY;
1978
1979
1980                 if((*r->out.sdbuf = make_sec_desc_buf(p->mem_ctx, sd_size, psd)) == NULL)
1981                         return NT_STATUS_NO_MEMORY;
1982                 break;
1983         case 4:
1984                 /* SD contains only the ACL */
1985
1986                 status=lsa_get_generic_sd(p->mem_ctx, &psd, &sd_size);
1987                 if(!NT_STATUS_IS_OK(status))
1988                         return NT_STATUS_NO_MEMORY;
1989
1990                 if((*r->out.sdbuf = make_sec_desc_buf(p->mem_ctx, sd_size, psd)) == NULL)
1991                         return NT_STATUS_NO_MEMORY;
1992                 break;
1993         default:
1994                 return NT_STATUS_INVALID_LEVEL;
1995         }
1996
1997         return status;
1998 }
1999
2000 #if 0   /* AD DC work in ongoing in Samba 4 */
2001
2002 /***************************************************************************
2003  ***************************************************************************/
2004
2005  NTSTATUS _lsa_query_info2(pipes_struct *p, LSA_Q_QUERY_INFO2 *q_u, LSA_R_QUERY_INFO2 *r_u)
2006 {
2007         struct lsa_info *handle;
2008         const char *nb_name;
2009         char *dns_name = NULL;
2010         char *forest_name = NULL;
2011         DOM_SID *sid = NULL;
2012         struct GUID guid;
2013         fstring dnsdomname;
2014
2015         ZERO_STRUCT(guid);
2016         r_u->status = NT_STATUS_OK;
2017
2018         if (!find_policy_by_hnd(p, &q_u->pol, (void **)(void *)&handle))
2019                 return NT_STATUS_INVALID_HANDLE;
2020
2021         switch (q_u->info_class) {
2022         case 0x0c:
2023                 /* check if the user have enough rights */
2024                 if (!(handle->access & POLICY_VIEW_LOCAL_INFORMATION))
2025                         return NT_STATUS_ACCESS_DENIED;
2026
2027                 /* Request PolicyPrimaryDomainInformation. */
2028                 switch (lp_server_role()) {
2029                         case ROLE_DOMAIN_PDC:
2030                         case ROLE_DOMAIN_BDC:
2031                                 nb_name = get_global_sam_name();
2032                                 /* ugly temp hack for these next two */
2033
2034                                 /* This should be a 'netbios domain -> DNS domain' mapping */
2035                                 dnsdomname = get_mydnsdomname(p->mem_ctx);
2036                                 if (!dnsdomname || !*dnsdomname) {
2037                                         return NT_STATUS_CANT_ACCESS_DOMAIN_INFO;
2038                                 }
2039                                 strlower_m(dnsdomname);
2040
2041                                 dns_name = dnsdomname;
2042                                 forest_name = dnsdomname;
2043
2044                                 sid = get_global_sam_sid();
2045                                 secrets_fetch_domain_guid(lp_workgroup(), &guid);
2046                                 break;
2047                         default:
2048                                 return NT_STATUS_CANT_ACCESS_DOMAIN_INFO;
2049                 }
2050                 init_dns_dom_info(&r_u->info.dns_dom_info, nb_name, dns_name,
2051                                   forest_name,&guid,sid);
2052                 break;
2053         default:
2054                 DEBUG(0,("_lsa_query_info2: unknown info level in Lsa Query: %d\n", q_u->info_class));
2055                 r_u->status = NT_STATUS_INVALID_INFO_CLASS;
2056                 break;
2057         }
2058
2059         if (NT_STATUS_IS_OK(r_u->status)) {
2060                 r_u->ptr = 0x1;
2061                 r_u->info_class = q_u->info_class;
2062         }
2063
2064         return r_u->status;
2065 }
2066 #endif  /* AD DC work in ongoing in Samba 4 */
2067
2068 /***************************************************************************
2069  _lsa_AddAccountRights
2070  ***************************************************************************/
2071
2072 NTSTATUS _lsa_AddAccountRights(pipes_struct *p,
2073                                struct lsa_AddAccountRights *r)
2074 {
2075         struct lsa_info *info = NULL;
2076         int i = 0;
2077         DOM_SID sid;
2078
2079         /* find the connection policy handle. */
2080         if (!find_policy_by_hnd(p, r->in.handle, (void **)(void *)&info))
2081                 return NT_STATUS_INVALID_HANDLE;
2082
2083         /* check to see if the pipe_user is a Domain Admin since
2084            account_pol.tdb was already opened as root, this is all we have */
2085
2086         if ( p->pipe_user.ut.uid != sec_initial_uid()
2087                 && !nt_token_check_domain_rid( p->pipe_user.nt_user_token, DOMAIN_GROUP_RID_ADMINS ) )
2088         {
2089                 return NT_STATUS_ACCESS_DENIED;
2090         }
2091
2092         /* according to an NT4 PDC, you can add privileges to SIDs even without
2093            call_lsa_create_account() first.  And you can use any arbitrary SID. */
2094
2095         sid_copy( &sid, r->in.sid );
2096
2097         for ( i=0; i < r->in.rights->count; i++ ) {
2098
2099                 const char *privname = r->in.rights->names[i].string;
2100
2101                 /* only try to add non-null strings */
2102
2103                 if ( !privname )
2104                         continue;
2105
2106                 if ( !grant_privilege_by_name( &sid, privname ) ) {
2107                         DEBUG(2,("_lsa_AddAccountRights: Failed to add privilege [%s]\n",
2108                                 privname ));
2109                         return NT_STATUS_NO_SUCH_PRIVILEGE;
2110                 }
2111         }
2112
2113         return NT_STATUS_OK;
2114 }
2115
2116 /***************************************************************************
2117  _lsa_RemoveAccountRights
2118  ***************************************************************************/
2119
2120 NTSTATUS _lsa_RemoveAccountRights(pipes_struct *p,
2121                                   struct lsa_RemoveAccountRights *r)
2122 {
2123         struct lsa_info *info = NULL;
2124         int i = 0;
2125         DOM_SID sid;
2126         const char *privname = NULL;
2127
2128         /* find the connection policy handle. */
2129         if (!find_policy_by_hnd(p, r->in.handle, (void **)(void *)&info))
2130                 return NT_STATUS_INVALID_HANDLE;
2131
2132         /* check to see if the pipe_user is a Domain Admin since
2133            account_pol.tdb was already opened as root, this is all we have */
2134
2135         if ( p->pipe_user.ut.uid != sec_initial_uid()
2136                 && !nt_token_check_domain_rid( p->pipe_user.nt_user_token, DOMAIN_GROUP_RID_ADMINS ) )
2137         {
2138                 return NT_STATUS_ACCESS_DENIED;
2139         }
2140
2141         sid_copy( &sid, r->in.sid );
2142
2143         if ( r->in.remove_all ) {
2144                 if ( !revoke_all_privileges( &sid ) )
2145                         return NT_STATUS_ACCESS_DENIED;
2146
2147                 return NT_STATUS_OK;
2148         }
2149
2150         for ( i=0; i < r->in.rights->count; i++ ) {
2151
2152                 privname = r->in.rights->names[i].string;
2153
2154                 /* only try to add non-null strings */
2155
2156                 if ( !privname )
2157                         continue;
2158
2159                 if ( !revoke_privilege_by_name( &sid, privname ) ) {
2160                         DEBUG(2,("_lsa_RemoveAccountRights: Failed to revoke privilege [%s]\n",
2161                                 privname ));
2162                         return NT_STATUS_NO_SUCH_PRIVILEGE;
2163                 }
2164         }
2165
2166         return NT_STATUS_OK;
2167 }
2168
2169 /*******************************************************************
2170 ********************************************************************/
2171
2172 static NTSTATUS init_lsa_right_set(TALLOC_CTX *mem_ctx,
2173                                    struct lsa_RightSet *r,
2174                                    PRIVILEGE_SET *privileges)
2175 {
2176         uint32 i;
2177         const char *privname;
2178         const char **privname_array = NULL;
2179         int num_priv = 0;
2180
2181         for (i=0; i<privileges->count; i++) {
2182
2183                 privname = luid_to_privilege_name(&privileges->set[i].luid);
2184                 if (privname) {
2185                         if (!add_string_to_array(mem_ctx, privname,
2186                                                  &privname_array, &num_priv)) {
2187                                 return NT_STATUS_NO_MEMORY;
2188                         }
2189                 }
2190         }
2191
2192         if (num_priv) {
2193
2194                 r->names = TALLOC_ZERO_ARRAY(mem_ctx, struct lsa_StringLarge,
2195                                              num_priv);
2196                 if (!r->names) {
2197                         return NT_STATUS_NO_MEMORY;
2198                 }
2199
2200                 for (i=0; i<num_priv; i++) {
2201                         init_lsa_StringLarge(&r->names[i], privname_array[i]);
2202                 }
2203
2204                 r->count = num_priv;
2205         }
2206
2207         return NT_STATUS_OK;
2208 }
2209
2210 /***************************************************************************
2211  _lsa_EnumAccountRights
2212  ***************************************************************************/
2213
2214 NTSTATUS _lsa_EnumAccountRights(pipes_struct *p,
2215                                 struct lsa_EnumAccountRights *r)
2216 {
2217         NTSTATUS status;
2218         struct lsa_info *info = NULL;
2219         DOM_SID sid;
2220         PRIVILEGE_SET privileges;
2221         SE_PRIV mask;
2222
2223         /* find the connection policy handle. */
2224
2225         if (!find_policy_by_hnd(p, r->in.handle, (void **)(void *)&info))
2226                 return NT_STATUS_INVALID_HANDLE;
2227
2228         /* according to an NT4 PDC, you can add privileges to SIDs even without
2229            call_lsa_create_account() first.  And you can use any arbitrary SID. */
2230
2231         sid_copy( &sid, r->in.sid );
2232
2233         if ( !get_privileges_for_sids( &mask, &sid, 1 ) )
2234                 return NT_STATUS_OBJECT_NAME_NOT_FOUND;
2235
2236         privilege_set_init( &privileges );
2237
2238         if ( se_priv_to_privilege_set( &privileges, &mask ) ) {
2239
2240                 DEBUG(10,("_lsa_EnumAccountRights: %s has %d privileges\n",
2241                           sid_string_dbg(&sid), privileges.count));
2242
2243                 status = init_lsa_right_set(p->mem_ctx, r->out.rights, &privileges);
2244         } else {
2245                 status = NT_STATUS_NO_SUCH_PRIVILEGE;
2246         }
2247
2248         privilege_set_free( &privileges );
2249
2250         return status;
2251 }
2252
2253 /***************************************************************************
2254  _lsa_LookupPrivValue
2255  ***************************************************************************/
2256
2257 NTSTATUS _lsa_LookupPrivValue(pipes_struct *p,
2258                               struct lsa_LookupPrivValue *r)
2259 {
2260         struct lsa_info *info = NULL;
2261         const char *name = NULL;
2262         LUID_ATTR priv_luid;
2263         SE_PRIV mask;
2264
2265         /* find the connection policy handle. */
2266
2267         if (!find_policy_by_hnd(p, r->in.handle, (void **)(void *)&info))
2268                 return NT_STATUS_INVALID_HANDLE;
2269
2270         name = r->in.name->string;
2271
2272         DEBUG(10,("_lsa_lookup_priv_value: name = %s\n", name));
2273
2274         if ( !se_priv_from_name( name, &mask ) )
2275                 return NT_STATUS_NO_SUCH_PRIVILEGE;
2276
2277         priv_luid = get_privilege_luid( &mask );
2278
2279         r->out.luid->low = priv_luid.luid.low;
2280         r->out.luid->high = priv_luid.luid.high;
2281
2282         return NT_STATUS_OK;
2283 }
2284
2285 /*
2286  * From here on the server routines are just dummy ones to make smbd link with
2287  * librpc/gen_ndr/srv_lsa.c. These routines are actually never called, we are
2288  * pulling the server stubs across one by one.
2289  */
2290
2291 NTSTATUS _lsa_Delete(pipes_struct *p, struct lsa_Delete *r)
2292 {
2293         p->rng_fault_state = True;
2294         return NT_STATUS_NOT_IMPLEMENTED;
2295 }
2296
2297 NTSTATUS _lsa_SetSecObj(pipes_struct *p, struct lsa_SetSecObj *r)
2298 {
2299         p->rng_fault_state = True;
2300         return NT_STATUS_NOT_IMPLEMENTED;
2301 }
2302
2303 NTSTATUS _lsa_ChangePassword(pipes_struct *p, struct lsa_ChangePassword *r)
2304 {
2305         p->rng_fault_state = True;
2306         return NT_STATUS_NOT_IMPLEMENTED;
2307 }
2308
2309 NTSTATUS _lsa_SetInfoPolicy(pipes_struct *p, struct lsa_SetInfoPolicy *r)
2310 {
2311         p->rng_fault_state = True;
2312         return NT_STATUS_NOT_IMPLEMENTED;
2313 }
2314
2315 NTSTATUS _lsa_ClearAuditLog(pipes_struct *p, struct lsa_ClearAuditLog *r)
2316 {
2317         p->rng_fault_state = True;
2318         return NT_STATUS_NOT_IMPLEMENTED;
2319 }
2320
2321 NTSTATUS _lsa_LookupSids(pipes_struct *p, struct lsa_LookupSids *r)
2322 {
2323         p->rng_fault_state = True;
2324         return NT_STATUS_NOT_IMPLEMENTED;
2325 }
2326
2327 NTSTATUS _lsa_GetQuotasForAccount(pipes_struct *p, struct lsa_GetQuotasForAccount *r)
2328 {
2329         p->rng_fault_state = True;
2330         return NT_STATUS_NOT_IMPLEMENTED;
2331 }
2332
2333 NTSTATUS _lsa_SetQuotasForAccount(pipes_struct *p, struct lsa_SetQuotasForAccount *r)
2334 {
2335         p->rng_fault_state = True;
2336         return NT_STATUS_NOT_IMPLEMENTED;
2337 }
2338
2339 NTSTATUS _lsa_QueryTrustedDomainInfo(pipes_struct *p, struct lsa_QueryTrustedDomainInfo *r)
2340 {
2341         p->rng_fault_state = True;
2342         return NT_STATUS_NOT_IMPLEMENTED;
2343 }
2344
2345 NTSTATUS _lsa_SetInformationTrustedDomain(pipes_struct *p, struct lsa_SetInformationTrustedDomain *r)
2346 {
2347         p->rng_fault_state = True;
2348         return NT_STATUS_NOT_IMPLEMENTED;
2349 }
2350
2351 NTSTATUS _lsa_QuerySecret(pipes_struct *p, struct lsa_QuerySecret *r)
2352 {
2353         p->rng_fault_state = True;
2354         return NT_STATUS_NOT_IMPLEMENTED;
2355 }
2356
2357 NTSTATUS _lsa_LookupPrivName(pipes_struct *p, struct lsa_LookupPrivName *r)
2358 {
2359         p->rng_fault_state = True;
2360         return NT_STATUS_NOT_IMPLEMENTED;
2361 }
2362
2363 NTSTATUS _lsa_EnumAccountsWithUserRight(pipes_struct *p, struct lsa_EnumAccountsWithUserRight *r)
2364 {
2365         p->rng_fault_state = True;
2366         return NT_STATUS_NOT_IMPLEMENTED;
2367 }
2368
2369 NTSTATUS _lsa_QueryTrustedDomainInfoBySid(pipes_struct *p, struct lsa_QueryTrustedDomainInfoBySid *r)
2370 {
2371         p->rng_fault_state = True;
2372         return NT_STATUS_NOT_IMPLEMENTED;
2373 }
2374
2375 NTSTATUS _lsa_SetTrustedDomainInfo(pipes_struct *p, struct lsa_SetTrustedDomainInfo *r)
2376 {
2377         p->rng_fault_state = True;
2378         return NT_STATUS_NOT_IMPLEMENTED;
2379 }
2380
2381 NTSTATUS _lsa_DeleteTrustedDomain(pipes_struct *p, struct lsa_DeleteTrustedDomain *r)
2382 {
2383         p->rng_fault_state = True;
2384         return NT_STATUS_NOT_IMPLEMENTED;
2385 }
2386
2387 NTSTATUS _lsa_StorePrivateData(pipes_struct *p, struct lsa_StorePrivateData *r)
2388 {
2389         p->rng_fault_state = True;
2390         return NT_STATUS_NOT_IMPLEMENTED;
2391 }
2392
2393 NTSTATUS _lsa_RetrievePrivateData(pipes_struct *p, struct lsa_RetrievePrivateData *r)
2394 {
2395         p->rng_fault_state = True;
2396         return NT_STATUS_NOT_IMPLEMENTED;
2397 }
2398
2399 NTSTATUS _lsa_QueryInfoPolicy2(pipes_struct *p, struct lsa_QueryInfoPolicy2 *r)
2400 {
2401         p->rng_fault_state = True;
2402         return NT_STATUS_NOT_IMPLEMENTED;
2403 }
2404
2405 NTSTATUS _lsa_SetInfoPolicy2(pipes_struct *p, struct lsa_SetInfoPolicy2 *r)
2406 {
2407         p->rng_fault_state = True;
2408         return NT_STATUS_NOT_IMPLEMENTED;
2409 }
2410
2411 NTSTATUS _lsa_QueryTrustedDomainInfoByName(pipes_struct *p, struct lsa_QueryTrustedDomainInfoByName *r)
2412 {
2413         p->rng_fault_state = True;
2414         return NT_STATUS_NOT_IMPLEMENTED;
2415 }
2416
2417 NTSTATUS _lsa_SetTrustedDomainInfoByName(pipes_struct *p, struct lsa_SetTrustedDomainInfoByName *r)
2418 {
2419         p->rng_fault_state = True;
2420         return NT_STATUS_NOT_IMPLEMENTED;
2421 }
2422
2423 NTSTATUS _lsa_EnumTrustedDomainsEx(pipes_struct *p, struct lsa_EnumTrustedDomainsEx *r)
2424 {
2425         p->rng_fault_state = True;
2426         return NT_STATUS_NOT_IMPLEMENTED;
2427 }
2428
2429 NTSTATUS _lsa_CreateTrustedDomainEx(pipes_struct *p, struct lsa_CreateTrustedDomainEx *r)
2430 {
2431         p->rng_fault_state = True;
2432         return NT_STATUS_NOT_IMPLEMENTED;
2433 }
2434
2435 NTSTATUS _lsa_CloseTrustedDomainEx(pipes_struct *p, struct lsa_CloseTrustedDomainEx *r)
2436 {
2437         p->rng_fault_state = True;
2438         return NT_STATUS_NOT_IMPLEMENTED;
2439 }
2440
2441 NTSTATUS _lsa_QueryDomainInformationPolicy(pipes_struct *p, struct lsa_QueryDomainInformationPolicy *r)
2442 {
2443         p->rng_fault_state = True;
2444         return NT_STATUS_NOT_IMPLEMENTED;
2445 }
2446
2447 NTSTATUS _lsa_SetDomainInformationPolicy(pipes_struct *p, struct lsa_SetDomainInformationPolicy *r)
2448 {
2449         p->rng_fault_state = True;
2450         return NT_STATUS_NOT_IMPLEMENTED;
2451 }
2452
2453 NTSTATUS _lsa_OpenTrustedDomainByName(pipes_struct *p, struct lsa_OpenTrustedDomainByName *r)
2454 {
2455         p->rng_fault_state = True;
2456         return NT_STATUS_NOT_IMPLEMENTED;
2457 }
2458
2459 NTSTATUS _lsa_TestCall(pipes_struct *p, struct lsa_TestCall *r)
2460 {
2461         p->rng_fault_state = True;
2462         return NT_STATUS_NOT_IMPLEMENTED;
2463 }
2464
2465 NTSTATUS _lsa_LookupSids2(pipes_struct *p, struct lsa_LookupSids2 *r)
2466 {
2467         p->rng_fault_state = True;
2468         return NT_STATUS_NOT_IMPLEMENTED;
2469 }
2470
2471 NTSTATUS _lsa_CreateTrustedDomainEx2(pipes_struct *p, struct lsa_CreateTrustedDomainEx2 *r)
2472 {
2473         p->rng_fault_state = True;
2474         return NT_STATUS_NOT_IMPLEMENTED;
2475 }
2476
2477 NTSTATUS _lsa_CREDRWRITE(pipes_struct *p, struct lsa_CREDRWRITE *r)
2478 {
2479         p->rng_fault_state = True;
2480         return NT_STATUS_NOT_IMPLEMENTED;
2481 }
2482
2483 NTSTATUS _lsa_CREDRREAD(pipes_struct *p, struct lsa_CREDRREAD *r)
2484 {
2485         p->rng_fault_state = True;
2486         return NT_STATUS_NOT_IMPLEMENTED;
2487 }
2488
2489 NTSTATUS _lsa_CREDRENUMERATE(pipes_struct *p, struct lsa_CREDRENUMERATE *r)
2490 {
2491         p->rng_fault_state = True;
2492         return NT_STATUS_NOT_IMPLEMENTED;
2493 }
2494
2495 NTSTATUS _lsa_CREDRWRITEDOMAINCREDENTIALS(pipes_struct *p, struct lsa_CREDRWRITEDOMAINCREDENTIALS *r)
2496 {
2497         p->rng_fault_state = True;
2498         return NT_STATUS_NOT_IMPLEMENTED;
2499 }
2500
2501 NTSTATUS _lsa_CREDRREADDOMAINCREDENTIALS(pipes_struct *p, struct lsa_CREDRREADDOMAINCREDENTIALS *r)
2502 {
2503         p->rng_fault_state = True;
2504         return NT_STATUS_NOT_IMPLEMENTED;
2505 }
2506
2507 NTSTATUS _lsa_CREDRDELETE(pipes_struct *p, struct lsa_CREDRDELETE *r)
2508 {
2509         p->rng_fault_state = True;
2510         return NT_STATUS_NOT_IMPLEMENTED;
2511 }
2512
2513 NTSTATUS _lsa_CREDRGETTARGETINFO(pipes_struct *p, struct lsa_CREDRGETTARGETINFO *r)
2514 {
2515         p->rng_fault_state = True;
2516         return NT_STATUS_NOT_IMPLEMENTED;
2517 }
2518
2519 NTSTATUS _lsa_CREDRPROFILELOADED(pipes_struct *p, struct lsa_CREDRPROFILELOADED *r)
2520 {
2521         p->rng_fault_state = True;
2522         return NT_STATUS_NOT_IMPLEMENTED;
2523 }
2524
2525 NTSTATUS _lsa_LookupNames3(pipes_struct *p, struct lsa_LookupNames3 *r)
2526 {
2527         p->rng_fault_state = True;
2528         return NT_STATUS_NOT_IMPLEMENTED;
2529 }
2530
2531 NTSTATUS _lsa_CREDRGETSESSIONTYPES(pipes_struct *p, struct lsa_CREDRGETSESSIONTYPES *r)
2532 {
2533         p->rng_fault_state = True;
2534         return NT_STATUS_NOT_IMPLEMENTED;
2535 }
2536
2537 NTSTATUS _lsa_LSARREGISTERAUDITEVENT(pipes_struct *p, struct lsa_LSARREGISTERAUDITEVENT *r)
2538 {
2539         p->rng_fault_state = True;
2540         return NT_STATUS_NOT_IMPLEMENTED;
2541 }
2542
2543 NTSTATUS _lsa_LSARGENAUDITEVENT(pipes_struct *p, struct lsa_LSARGENAUDITEVENT *r)
2544 {
2545         p->rng_fault_state = True;
2546         return NT_STATUS_NOT_IMPLEMENTED;
2547 }
2548
2549 NTSTATUS _lsa_LSARUNREGISTERAUDITEVENT(pipes_struct *p, struct lsa_LSARUNREGISTERAUDITEVENT *r)
2550 {
2551         p->rng_fault_state = True;
2552         return NT_STATUS_NOT_IMPLEMENTED;
2553 }
2554
2555 NTSTATUS _lsa_lsaRQueryForestTrustInformation(pipes_struct *p, struct lsa_lsaRQueryForestTrustInformation *r)
2556 {
2557         p->rng_fault_state = True;
2558         return NT_STATUS_NOT_IMPLEMENTED;
2559 }
2560
2561 NTSTATUS _lsa_LSARSETFORESTTRUSTINFORMATION(pipes_struct *p, struct lsa_LSARSETFORESTTRUSTINFORMATION *r)
2562 {
2563         p->rng_fault_state = True;
2564         return NT_STATUS_NOT_IMPLEMENTED;
2565 }
2566
2567 NTSTATUS _lsa_CREDRRENAME(pipes_struct *p, struct lsa_CREDRRENAME *r)
2568 {
2569         p->rng_fault_state = True;
2570         return NT_STATUS_NOT_IMPLEMENTED;
2571 }
2572
2573 NTSTATUS _lsa_LookupSids3(pipes_struct *p, struct lsa_LookupSids3 *r)
2574 {
2575         p->rng_fault_state = True;
2576         return NT_STATUS_NOT_IMPLEMENTED;
2577 }
2578
2579 NTSTATUS _lsa_LookupNames4(pipes_struct *p, struct lsa_LookupNames4 *r)
2580 {
2581         p->rng_fault_state = True;
2582         return NT_STATUS_NOT_IMPLEMENTED;
2583 }
2584
2585 NTSTATUS _lsa_LSAROPENPOLICYSCE(pipes_struct *p, struct lsa_LSAROPENPOLICYSCE *r)
2586 {
2587         p->rng_fault_state = True;
2588         return NT_STATUS_NOT_IMPLEMENTED;
2589 }
2590
2591 NTSTATUS _lsa_LSARADTREGISTERSECURITYEVENTSOURCE(pipes_struct *p, struct lsa_LSARADTREGISTERSECURITYEVENTSOURCE *r)
2592 {
2593         p->rng_fault_state = True;
2594         return NT_STATUS_NOT_IMPLEMENTED;
2595 }
2596
2597 NTSTATUS _lsa_LSARADTUNREGISTERSECURITYEVENTSOURCE(pipes_struct *p, struct lsa_LSARADTUNREGISTERSECURITYEVENTSOURCE *r)
2598 {
2599         p->rng_fault_state = True;
2600         return NT_STATUS_NOT_IMPLEMENTED;
2601 }
2602
2603 NTSTATUS _lsa_LSARADTREPORTSECURITYEVENT(pipes_struct *p, struct lsa_LSARADTREPORTSECURITYEVENT *r)
2604 {
2605         p->rng_fault_state = True;
2606         return NT_STATUS_NOT_IMPLEMENTED;
2607 }