This commit was manufactured by cvs2svn to create branch 'SAMBA_3_0'.(This used to...
[samba.git] / source3 / 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,
8  *  Copyright (C) Rafal Szczesniak                  2002,
9  *  Copyright (C) Jim McDonough                     2002.
10  *
11  *  This program is free software; you can redistribute it and/or modify
12  *  it under the terms of the GNU General Public License as published by
13  *  the Free Software Foundation; either version 2 of the License, or
14  *  (at your option) any later version.
15  *  
16  *  This program is distributed in the hope that it will be useful,
17  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
18  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  *  GNU General Public License for more details.
20  *  
21  *  You should have received a copy of the GNU General Public License
22  *  along with this program; if not, write to the Free Software
23  *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24  */
25
26 /* This is the implementation of the lsa server code. */
27
28 #include "includes.h"
29
30 #undef DBGC_CLASS
31 #define DBGC_CLASS DBGC_RPC_SRV
32
33 extern PRIVS privs[];
34
35 struct lsa_info {
36         DOM_SID sid;
37         uint32 access;
38 };
39
40 struct generic_mapping lsa_generic_mapping = {
41         POLICY_READ,
42         POLICY_WRITE,
43         POLICY_EXECUTE,
44         POLICY_ALL_ACCESS
45 };
46
47 /*******************************************************************
48  Function to free the per handle data.
49  ********************************************************************/
50
51 static void free_lsa_info(void *ptr)
52 {
53         struct lsa_info *lsa = (struct lsa_info *)ptr;
54
55         SAFE_FREE(lsa);
56 }
57
58 /***************************************************************************
59 Init dom_query
60  ***************************************************************************/
61
62 static void init_dom_query(DOM_QUERY *d_q, const char *dom_name, DOM_SID *dom_sid)
63 {
64         int domlen = (dom_name != NULL) ? strlen(dom_name) : 0;
65
66         /*
67          * I'm not sure why this really odd combination of length
68          * values works, but it does appear to. I need to look at
69          * this *much* more closely - but at the moment leave alone
70          * until it's understood. This allows a W2k client to join
71          * a domain with both odd and even length names... JRA.
72          */
73
74         d_q->uni_dom_str_len = domlen ? ((domlen + 1) * 2) : 0;
75         d_q->uni_dom_max_len = domlen * 2;
76         d_q->buffer_dom_name = domlen != 0 ? 1 : 0; /* domain buffer pointer */
77         d_q->buffer_dom_sid = dom_sid != NULL ? 1 : 0;  /* domain sid pointer */
78
79         /* this string is supposed to be character short */
80         init_unistr2(&d_q->uni_domain_name, dom_name, domlen);
81         d_q->uni_domain_name.uni_max_len++;
82
83         if (dom_sid != NULL)
84                 init_dom_sid2(&d_q->dom_sid, dom_sid);
85 }
86
87 /***************************************************************************
88  init_dom_ref - adds a domain if it's not already in, returns the index.
89 ***************************************************************************/
90
91 static int init_dom_ref(DOM_R_REF *ref, char *dom_name, DOM_SID *dom_sid)
92 {
93         int num = 0;
94         int len;
95
96         if (dom_name != NULL) {
97                 for (num = 0; num < ref->num_ref_doms_1; num++) {
98                         fstring domname;
99                         rpcstr_pull(domname, &ref->ref_dom[num].uni_dom_name, sizeof(domname), -1, 0);
100                         if (strequal(domname, dom_name))
101                                 return num;
102                 }
103         } else {
104                 num = ref->num_ref_doms_1;
105         }
106
107         if (num >= MAX_REF_DOMAINS) {
108                 /* index not found, already at maximum domain limit */
109                 return -1;
110         }
111
112         ref->num_ref_doms_1 = num+1;
113         ref->ptr_ref_dom  = 1;
114         ref->max_entries = MAX_REF_DOMAINS;
115         ref->num_ref_doms_2 = num+1;
116
117         len = (dom_name != NULL) ? strlen(dom_name) : 0;
118         if(dom_name != NULL && len == 0)
119                 len = 1;
120
121         init_uni_hdr(&ref->hdr_ref_dom[num].hdr_dom_name, len);
122         ref->hdr_ref_dom[num].ptr_dom_sid = dom_sid != NULL ? 1 : 0;
123
124         init_unistr2(&ref->ref_dom[num].uni_dom_name, dom_name, len);
125         init_dom_sid2(&ref->ref_dom[num].ref_dom, dom_sid );
126
127         return num;
128 }
129
130 /***************************************************************************
131  init_lsa_rid2s
132  ***************************************************************************/
133
134 static void init_lsa_rid2s(DOM_R_REF *ref, DOM_RID2 *rid2,
135                                 int num_entries, UNISTR2 *name,
136                                 uint32 *mapped_count, BOOL endian)
137 {
138         int i;
139         int total = 0;
140         *mapped_count = 0;
141
142         SMB_ASSERT(num_entries <= MAX_LOOKUP_SIDS);
143
144         become_root(); /* lookup_name can require root privs */
145
146         for (i = 0; i < num_entries; i++) {
147                 BOOL status = False;
148                 DOM_SID sid;
149                 uint32 rid = 0xffffffff;
150                 int dom_idx = -1;
151                 pstring full_name;
152                 fstring dom_name, user;
153                 enum SID_NAME_USE name_type = SID_NAME_UNKNOWN;
154
155                 /* Split name into domain and user component */
156
157                 unistr2_to_ascii(full_name, &name[i], sizeof(full_name));
158                 split_domain_name(full_name, dom_name, user);
159
160                 /* Lookup name */
161
162                 DEBUG(5, ("init_lsa_rid2s: looking up name %s\n", full_name));
163
164                 status = lookup_name(dom_name, user, &sid, &name_type);
165
166                 DEBUG(5, ("init_lsa_rid2s: %s\n", status ? "found" : 
167                           "not found"));
168
169                 if (status && name_type != SID_NAME_UNKNOWN) {
170                         sid_split_rid(&sid, &rid);
171                         dom_idx = init_dom_ref(ref, dom_name, &sid);
172                         (*mapped_count)++;
173                 } else {
174                         dom_idx = -1;
175                         rid = 0xffffffff;
176                         name_type = SID_NAME_UNKNOWN;
177                 }
178
179                 init_dom_rid2(&rid2[total], rid, name_type, dom_idx);
180                 total++;
181         }
182
183         unbecome_root();
184 }
185
186 /***************************************************************************
187  init_reply_lookup_names
188  ***************************************************************************/
189
190 static void init_reply_lookup_names(LSA_R_LOOKUP_NAMES *r_l,
191                 DOM_R_REF *ref, uint32 num_entries,
192                 DOM_RID2 *rid2, uint32 mapped_count)
193 {
194         r_l->ptr_dom_ref  = 1;
195         r_l->dom_ref      = ref;
196
197         r_l->num_entries  = num_entries;
198         r_l->ptr_entries  = 1;
199         r_l->num_entries2 = num_entries;
200         r_l->dom_rid      = rid2;
201
202         r_l->mapped_count = mapped_count;
203
204         if (mapped_count == 0)
205                 r_l->status = NT_STATUS_NONE_MAPPED;
206         else
207                 r_l->status = NT_STATUS_OK;
208 }
209
210 /***************************************************************************
211  Init lsa_trans_names.
212  ***************************************************************************/
213
214 static void init_lsa_trans_names(TALLOC_CTX *ctx, DOM_R_REF *ref, LSA_TRANS_NAME_ENUM *trn,
215                                  int num_entries, DOM_SID2 *sid,
216                                  uint32 *mapped_count)
217 {
218         int i;
219         int total = 0;
220         *mapped_count = 0;
221
222         /* Allocate memory for list of names */
223
224         if (num_entries > 0) {
225                 if (!(trn->name = (LSA_TRANS_NAME *)talloc(ctx, sizeof(LSA_TRANS_NAME) *
226                                                           num_entries))) {
227                         DEBUG(0, ("init_lsa_trans_names(): out of memory\n"));
228                         return;
229                 }
230
231                 if (!(trn->uni_name = (UNISTR2 *)talloc(ctx, sizeof(UNISTR2) * 
232                                                         num_entries))) {
233                         DEBUG(0, ("init_lsa_trans_names(): out of memory\n"));
234                         return;
235                 }
236         }
237
238         become_root(); /* Need root to get to passdb to for local sids */
239
240         for (i = 0; i < num_entries; i++) {
241                 BOOL status = False;
242                 DOM_SID find_sid = sid[i].sid;
243                 uint32 rid = 0xffffffff;
244                 int dom_idx = -1;
245                 fstring name, dom_name;
246                 enum SID_NAME_USE sid_name_use = (enum SID_NAME_USE)0;
247
248                 sid_to_string(name, &find_sid);
249                 DEBUG(5, ("init_lsa_trans_names: looking up sid %s\n", name));
250
251                 /* Lookup sid from winbindd */
252
253                 memset(dom_name, '\0', sizeof(dom_name));
254                 memset(name, '\0', sizeof(name));
255
256                 status = lookup_sid(&find_sid, dom_name, name, &sid_name_use);
257
258                 DEBUG(5, ("init_lsa_trans_names: %s\n", status ? "found" : 
259                           "not found"));
260
261                 if (!status) {
262                         sid_name_use = SID_NAME_UNKNOWN;
263                 } else {
264                         (*mapped_count)++;
265                 }
266
267                 /* Store domain sid in ref array */
268
269                 if (find_sid.num_auths == 5) {
270                         sid_split_rid(&find_sid, &rid);
271                 }
272
273                 dom_idx = init_dom_ref(ref, dom_name, &find_sid);
274
275                 DEBUG(10,("init_lsa_trans_names: added user '%s\\%s' to "
276                           "referenced list.\n", dom_name, name ));
277
278                 init_lsa_trans_name(&trn->name[total], &trn->uni_name[total],
279                                         sid_name_use, name, dom_idx);
280                 total++;
281         }
282
283         unbecome_root();
284
285         trn->num_entries = total;
286         trn->ptr_trans_names = 1;
287         trn->num_entries2 = total;
288 }
289
290 /***************************************************************************
291  Init_reply_lookup_sids.
292  ***************************************************************************/
293
294 static void init_reply_lookup_sids(LSA_R_LOOKUP_SIDS *r_l,
295                 DOM_R_REF *ref, LSA_TRANS_NAME_ENUM *names,
296                 uint32 mapped_count)
297 {
298         r_l->ptr_dom_ref  = 1;
299         r_l->dom_ref      = ref;
300         r_l->names        = names;
301         r_l->mapped_count = mapped_count;
302
303         if (mapped_count == 0)
304                 r_l->status = NT_STATUS_NONE_MAPPED;
305         else
306                 r_l->status = NT_STATUS_OK;
307 }
308
309 static NTSTATUS lsa_get_generic_sd(TALLOC_CTX *mem_ctx, SEC_DESC **sd, size_t *sd_size)
310 {
311         extern DOM_SID global_sid_World;
312         extern DOM_SID global_sid_Builtin;
313         DOM_SID local_adm_sid;
314         DOM_SID adm_sid;
315
316         SEC_ACE ace[3];
317         SEC_ACCESS mask;
318
319         SEC_ACL *psa = NULL;
320
321         init_sec_access(&mask, POLICY_EXECUTE);
322         init_sec_ace(&ace[0], &global_sid_World, SEC_ACE_TYPE_ACCESS_ALLOWED, mask, 0);
323
324         sid_copy(&adm_sid, get_global_sam_sid());
325         sid_append_rid(&adm_sid, DOMAIN_GROUP_RID_ADMINS);
326         init_sec_access(&mask, POLICY_ALL_ACCESS);
327         init_sec_ace(&ace[1], &adm_sid, SEC_ACE_TYPE_ACCESS_ALLOWED, mask, 0);
328
329         sid_copy(&local_adm_sid, &global_sid_Builtin);
330         sid_append_rid(&local_adm_sid, BUILTIN_ALIAS_RID_ADMINS);
331         init_sec_access(&mask, POLICY_ALL_ACCESS);
332         init_sec_ace(&ace[2], &local_adm_sid, SEC_ACE_TYPE_ACCESS_ALLOWED, mask, 0);
333
334         if((psa = make_sec_acl(mem_ctx, NT4_ACL_REVISION, 3, ace)) == NULL)
335                 return NT_STATUS_NO_MEMORY;
336
337         if((*sd = make_sec_desc(mem_ctx, SEC_DESC_REVISION, &adm_sid, NULL, NULL, psa, sd_size)) == NULL)
338                 return NT_STATUS_NO_MEMORY;
339
340         return NT_STATUS_OK;
341 }
342
343 /***************************************************************************
344  Init_dns_dom_info.
345 ***************************************************************************/
346
347 static void init_dns_dom_info(LSA_DNS_DOM_INFO *r_l, const char *nb_name,
348                               const char *dns_name, const char *forest_name,
349                               GUID *dom_guid, DOM_SID *dom_sid)
350 {
351         if (nb_name && *nb_name) {
352                 init_uni_hdr(&r_l->hdr_nb_dom_name, strlen(nb_name));
353                 init_unistr2(&r_l->uni_nb_dom_name, nb_name, 
354                              strlen(nb_name));
355                 r_l->hdr_nb_dom_name.uni_max_len += 2;
356                 r_l->uni_nb_dom_name.uni_max_len += 1;
357         }
358         
359         if (dns_name && *dns_name) {
360                 init_uni_hdr(&r_l->hdr_dns_dom_name, strlen(dns_name));
361                 init_unistr2(&r_l->uni_dns_dom_name, dns_name,
362                              strlen(dns_name));
363                 r_l->hdr_dns_dom_name.uni_max_len += 2;
364                 r_l->uni_dns_dom_name.uni_max_len += 1;
365         }
366
367         if (forest_name && *forest_name) {
368                 init_uni_hdr(&r_l->hdr_forest_name, strlen(forest_name));
369                 init_unistr2(&r_l->uni_forest_name, forest_name,
370                              strlen(forest_name));
371                 r_l->hdr_forest_name.uni_max_len += 2;
372                 r_l->uni_forest_name.uni_max_len += 1;
373         }
374
375         /* how do we init the guid ? probably should write an init fn */
376         if (dom_guid) {
377                 memcpy(&r_l->dom_guid, dom_guid, sizeof(GUID));
378         }
379         
380         if (dom_sid) {
381                 r_l->ptr_dom_sid = 1;
382                 init_dom_sid2(&r_l->dom_sid, dom_sid);
383         }
384 }
385
386 /***************************************************************************
387  _lsa_open_policy2.
388  ***************************************************************************/
389
390 NTSTATUS _lsa_open_policy2(pipes_struct *p, LSA_Q_OPEN_POL2 *q_u, LSA_R_OPEN_POL2 *r_u)
391 {
392         struct lsa_info *info;
393         SEC_DESC *psd = NULL;
394         size_t sd_size;
395         uint32 des_access=q_u->des_access;
396         uint32 acc_granted;
397         NTSTATUS status;
398
399
400         /* map the generic bits to the lsa policy ones */
401         se_map_generic(&des_access, &lsa_generic_mapping);
402
403         /* get the generic lsa policy SD until we store it */
404         lsa_get_generic_sd(p->mem_ctx, &psd, &sd_size);
405
406         if(!se_access_check(psd, p->pipe_user.nt_user_token, des_access, &acc_granted, &status))
407                 return status;
408
409         /* associate the domain SID with the (unique) handle. */
410         if ((info = (struct lsa_info *)malloc(sizeof(struct lsa_info))) == NULL)
411                 return NT_STATUS_NO_MEMORY;
412
413         ZERO_STRUCTP(info);
414         sid_copy(&info->sid,get_global_sam_sid());
415         info->access = acc_granted;
416
417         /* set up the LSA QUERY INFO response */
418         if (!create_policy_hnd(p, &r_u->pol, free_lsa_info, (void *)info))
419                 return NT_STATUS_OBJECT_NAME_NOT_FOUND;
420
421         return NT_STATUS_OK;
422 }
423
424 /***************************************************************************
425  _lsa_open_policy
426  ***************************************************************************/
427
428 NTSTATUS _lsa_open_policy(pipes_struct *p, LSA_Q_OPEN_POL *q_u, LSA_R_OPEN_POL *r_u)
429 {
430         struct lsa_info *info;
431         SEC_DESC *psd = NULL;
432         size_t sd_size;
433         uint32 des_access=q_u->des_access;
434         uint32 acc_granted;
435         NTSTATUS status;
436
437
438         /* map the generic bits to the lsa policy ones */
439         se_map_generic(&des_access, &lsa_generic_mapping);
440
441         /* get the generic lsa policy SD until we store it */
442         lsa_get_generic_sd(p->mem_ctx, &psd, &sd_size);
443
444         if(!se_access_check(psd, p->pipe_user.nt_user_token, des_access, &acc_granted, &status))
445                 return status;
446
447         /* associate the domain SID with the (unique) handle. */
448         if ((info = (struct lsa_info *)malloc(sizeof(struct lsa_info))) == NULL)
449                 return NT_STATUS_NO_MEMORY;
450
451         ZERO_STRUCTP(info);
452         sid_copy(&info->sid,get_global_sam_sid());
453         info->access = acc_granted;
454
455         /* set up the LSA QUERY INFO response */
456         if (!create_policy_hnd(p, &r_u->pol, free_lsa_info, (void *)info))
457                 return NT_STATUS_OBJECT_NAME_NOT_FOUND;
458
459         return NT_STATUS_OK;
460 }
461
462 /***************************************************************************
463  _lsa_enum_trust_dom - this needs fixing to do more than return NULL ! JRA.
464  ufff, done :)  mimir
465  ***************************************************************************/
466
467 NTSTATUS _lsa_enum_trust_dom(pipes_struct *p, LSA_Q_ENUM_TRUST_DOM *q_u, LSA_R_ENUM_TRUST_DOM *r_u)
468 {
469         struct lsa_info *info;
470         uint32 enum_context = q_u->enum_context;
471
472         /*
473          * preferred length is set to 5 as a "our" preferred length
474          * nt sets this parameter to 2
475          * update (20.08.2002): it's not preferred length, but preferred size!
476          * it needs further investigation how to optimally choose this value
477          */
478         uint32 max_num_domains = q_u->preferred_len < 5 ? q_u->preferred_len : 10;
479         TRUSTDOM **trust_doms;
480         uint32 num_domains;
481         NTSTATUS nt_status;
482
483         if (!find_policy_by_hnd(p, &q_u->pol, (void **)&info))
484                 return NT_STATUS_INVALID_HANDLE;
485
486         /* check if the user have enough rights */
487         if (!(info->access & POLICY_VIEW_LOCAL_INFORMATION))
488                 return NT_STATUS_ACCESS_DENIED;
489
490         nt_status = secrets_get_trusted_domains(p->mem_ctx, &enum_context, max_num_domains, &num_domains, &trust_doms);
491
492         if (!NT_STATUS_IS_OK(nt_status) &&
493             !NT_STATUS_EQUAL(nt_status, STATUS_MORE_ENTRIES) &&
494             !NT_STATUS_EQUAL(nt_status, NT_STATUS_NO_MORE_ENTRIES)) {
495                 return nt_status;
496         } else {
497                 r_u->status = nt_status;
498         }
499
500         /* set up the lsa_enum_trust_dom response */
501         init_r_enum_trust_dom(p->mem_ctx, r_u, enum_context, max_num_domains, num_domains, trust_doms);
502
503         return r_u->status;
504 }
505
506 /***************************************************************************
507  _lsa_query_info. See the POLICY_INFOMATION_CLASS docs at msdn.
508  ***************************************************************************/
509
510 NTSTATUS _lsa_query_info(pipes_struct *p, LSA_Q_QUERY_INFO *q_u, LSA_R_QUERY_INFO *r_u)
511 {
512         struct lsa_info *handle;
513         LSA_INFO_UNION *info = &r_u->dom;
514         DOM_SID domain_sid;
515         const char *name;
516         DOM_SID *sid = NULL;
517
518         r_u->status = NT_STATUS_OK;
519
520         if (!find_policy_by_hnd(p, &q_u->pol, (void **)&handle))
521                 return NT_STATUS_INVALID_HANDLE;
522
523         switch (q_u->info_class) {
524         case 0x02:
525                 {
526                 unsigned int i;
527                 /* check if the user have enough rights */
528                 if (!(handle->access & POLICY_VIEW_AUDIT_INFORMATION))
529                         return NT_STATUS_ACCESS_DENIED;
530
531                 /* fake info: We audit everything. ;) */
532                 info->id2.auditing_enabled = 1;
533                 info->id2.count1 = 7;
534                 info->id2.count2 = 7;
535                 if ((info->id2.auditsettings = (uint32 *)talloc(p->mem_ctx,7*sizeof(uint32))) == NULL)
536                         return NT_STATUS_NO_MEMORY;
537                 for (i = 0; i < 7; i++)
538                         info->id2.auditsettings[i] = 3;
539                 break;
540                 }
541         case 0x03:
542                 /* check if the user have enough rights */
543                 if (!(handle->access & POLICY_VIEW_LOCAL_INFORMATION))
544                         return NT_STATUS_ACCESS_DENIED;
545
546                 /* Request PolicyPrimaryDomainInformation. */
547                 switch (lp_server_role()) {
548                         case ROLE_DOMAIN_PDC:
549                         case ROLE_DOMAIN_BDC:
550                                 name = get_global_sam_name();
551                                 sid = get_global_sam_sid();
552                                 break;
553                         case ROLE_DOMAIN_MEMBER:
554                                 name = lp_workgroup();
555                                 /* We need to return the Domain SID here. */
556                                 if (secrets_fetch_domain_sid(lp_workgroup(), &domain_sid))
557                                         sid = &domain_sid;
558                                 else
559                                         return NT_STATUS_CANT_ACCESS_DOMAIN_INFO;
560                                 break;
561                         case ROLE_STANDALONE:
562                                 name = lp_workgroup();
563                                 sid = NULL;
564                                 break;
565                         default:
566                                 return NT_STATUS_CANT_ACCESS_DOMAIN_INFO;
567                 }
568                 init_dom_query(&r_u->dom.id3, name, sid);
569                 break;
570         case 0x05:
571                 /* check if the user have enough rights */
572                 if (!(handle->access & POLICY_VIEW_LOCAL_INFORMATION))
573                         return NT_STATUS_ACCESS_DENIED;
574
575                 /* Request PolicyAccountDomainInformation. */
576                 name = get_global_sam_name();
577                 sid = get_global_sam_sid();
578                 init_dom_query(&r_u->dom.id5, name, sid);
579                 break;
580         case 0x06:
581                 /* check if the user have enough rights */
582                 if (!(handle->access & POLICY_VIEW_LOCAL_INFORMATION))
583                         return NT_STATUS_ACCESS_DENIED;
584
585                 switch (lp_server_role()) {
586                         case ROLE_DOMAIN_BDC:
587                                 /*
588                                  * only a BDC is a backup controller
589                                  * of the domain, it controls.
590                                  */
591                                 info->id6.server_role = 2;
592                                 break;
593                         default:
594                                 /*
595                                  * any other role is a primary
596                                  * of the domain, it controls.
597                                  */
598                                 info->id6.server_role = 3;
599                                 break; 
600                 }
601                 break;
602         default:
603                 DEBUG(0,("_lsa_query_info: unknown info level in Lsa Query: %d\n", q_u->info_class));
604                 r_u->status = NT_STATUS_INVALID_INFO_CLASS;
605                 break;
606         }
607
608         if (NT_STATUS_IS_OK(r_u->status)) {
609                 r_u->undoc_buffer = 0x22000000; /* bizarre */
610                 r_u->info_class = q_u->info_class;
611         }
612
613         return r_u->status;
614 }
615
616 /***************************************************************************
617  _lsa_lookup_sids
618  ***************************************************************************/
619
620 NTSTATUS _lsa_lookup_sids(pipes_struct *p, LSA_Q_LOOKUP_SIDS *q_u, LSA_R_LOOKUP_SIDS *r_u)
621 {
622         struct lsa_info *handle;
623         DOM_SID2 *sid = q_u->sids.sid;
624         int num_entries = q_u->sids.num_entries;
625         DOM_R_REF *ref = NULL;
626         LSA_TRANS_NAME_ENUM *names = NULL;
627         uint32 mapped_count = 0;
628
629         if (num_entries >  MAX_LOOKUP_SIDS) {
630                 num_entries = MAX_LOOKUP_SIDS;
631                 DEBUG(5,("_lsa_lookup_sids: truncating SID lookup list to %d\n", num_entries));
632         }
633
634         ref = (DOM_R_REF *)talloc_zero(p->mem_ctx, sizeof(DOM_R_REF));
635         names = (LSA_TRANS_NAME_ENUM *)talloc_zero(p->mem_ctx, sizeof(LSA_TRANS_NAME_ENUM));
636
637         if (!find_policy_by_hnd(p, &q_u->pol, (void **)&handle)) {
638                 r_u->status = NT_STATUS_INVALID_HANDLE;
639                 goto done;
640         }
641
642         /* check if the user have enough rights */
643         if (!(handle->access & POLICY_LOOKUP_NAMES)) {
644                 r_u->status = NT_STATUS_ACCESS_DENIED;
645                 goto done;
646         }
647         if (!ref || !names)
648                 return NT_STATUS_NO_MEMORY;
649
650 done:
651
652         /* set up the LSA Lookup SIDs response */
653         init_lsa_trans_names(p->mem_ctx, ref, names, num_entries, sid, &mapped_count);
654         init_reply_lookup_sids(r_u, ref, names, mapped_count);
655
656         return r_u->status;
657 }
658
659 /***************************************************************************
660 lsa_reply_lookup_names
661  ***************************************************************************/
662
663 NTSTATUS _lsa_lookup_names(pipes_struct *p,LSA_Q_LOOKUP_NAMES *q_u, LSA_R_LOOKUP_NAMES *r_u)
664 {
665         struct lsa_info *handle;
666         UNISTR2 *names = q_u->uni_name;
667         int num_entries = q_u->num_entries;
668         DOM_R_REF *ref;
669         DOM_RID2 *rids;
670         uint32 mapped_count = 0;
671
672         if (num_entries >  MAX_LOOKUP_SIDS) {
673                 num_entries = MAX_LOOKUP_SIDS;
674                 DEBUG(5,("_lsa_lookup_names: truncating name lookup list to %d\n", num_entries));
675         }
676                 
677         ref = (DOM_R_REF *)talloc_zero(p->mem_ctx, sizeof(DOM_R_REF));
678         rids = (DOM_RID2 *)talloc_zero(p->mem_ctx, sizeof(DOM_RID2)*num_entries);
679
680         if (!find_policy_by_hnd(p, &q_u->pol, (void **)&handle)) {
681                 r_u->status = NT_STATUS_INVALID_HANDLE;
682                 goto done;
683         }
684
685         /* check if the user have enough rights */
686         if (!(handle->access & POLICY_LOOKUP_NAMES)) {
687                 r_u->status = NT_STATUS_ACCESS_DENIED;
688                 goto done;
689         }
690
691         if (!ref || !rids)
692                 return NT_STATUS_NO_MEMORY;
693
694 done:
695
696         /* set up the LSA Lookup RIDs response */
697         init_lsa_rid2s(ref, rids, num_entries, names, &mapped_count, p->endian);
698         init_reply_lookup_names(r_u, ref, num_entries, rids, mapped_count);
699
700         return r_u->status;
701 }
702
703 /***************************************************************************
704  _lsa_close. Also weird - needs to check if lsa handle is correct. JRA.
705  ***************************************************************************/
706
707 NTSTATUS _lsa_close(pipes_struct *p, LSA_Q_CLOSE *q_u, LSA_R_CLOSE *r_u)
708 {
709         if (!find_policy_by_hnd(p, &q_u->pol, NULL))
710                 return NT_STATUS_INVALID_HANDLE;
711
712         close_policy_hnd(p, &q_u->pol);
713         return NT_STATUS_OK;
714 }
715
716 /***************************************************************************
717   "No more secrets Marty...." :-).
718  ***************************************************************************/
719
720 NTSTATUS _lsa_open_secret(pipes_struct *p, LSA_Q_OPEN_SECRET *q_u, LSA_R_OPEN_SECRET *r_u)
721 {
722         return NT_STATUS_OBJECT_NAME_NOT_FOUND;
723 }
724
725 /***************************************************************************
726 _lsa_enum_privs.
727  ***************************************************************************/
728
729 NTSTATUS _lsa_enum_privs(pipes_struct *p, LSA_Q_ENUM_PRIVS *q_u, LSA_R_ENUM_PRIVS *r_u)
730 {
731         struct lsa_info *handle;
732         uint32 i;
733
734         uint32 enum_context=q_u->enum_context;
735         LSA_PRIV_ENTRY *entry;
736         LSA_PRIV_ENTRY *entries=NULL;
737
738         if (enum_context >= PRIV_ALL_INDEX)
739                 return NT_STATUS_NO_MORE_ENTRIES;
740
741         entries = (LSA_PRIV_ENTRY *)talloc_zero(p->mem_ctx, sizeof(LSA_PRIV_ENTRY) * (PRIV_ALL_INDEX));
742         if (entries==NULL)
743                 return NT_STATUS_NO_MEMORY;
744
745         if (!find_policy_by_hnd(p, &q_u->pol, (void **)&handle))
746                 return NT_STATUS_INVALID_HANDLE;
747
748         /* check if the user have enough rights */
749
750         /*
751          * I don't know if it's the right one. not documented.
752          */
753         if (!(handle->access & POLICY_VIEW_LOCAL_INFORMATION))
754                 return NT_STATUS_ACCESS_DENIED;
755
756         entry = entries;
757         
758         DEBUG(10,("_lsa_enum_privs: enum_context:%d total entries:%d\n", enum_context, PRIV_ALL_INDEX));
759
760         for (i = 0; i < PRIV_ALL_INDEX; i++, entry++) {
761                 if( i<enum_context) {
762                         init_uni_hdr(&entry->hdr_name, 0);
763                         init_unistr2(&entry->name, NULL, 0 );
764                         entry->luid_low = 0;
765                         entry->luid_high = 0;
766                 } else {
767                         init_uni_hdr(&entry->hdr_name, strlen(privs[i+1].priv));
768                         init_unistr2(&entry->name, privs[i+1].priv, strlen(privs[i+1].priv) );
769                         entry->luid_low = privs[i+1].se_priv;
770                         entry->luid_high = 0;
771                 }
772         }
773
774         enum_context = PRIV_ALL_INDEX;
775         init_lsa_r_enum_privs(r_u, enum_context, PRIV_ALL_INDEX, entries);
776
777         return NT_STATUS_OK;
778 }
779
780 /***************************************************************************
781 _lsa_priv_get_dispname.
782  ***************************************************************************/
783
784 NTSTATUS _lsa_priv_get_dispname(pipes_struct *p, LSA_Q_PRIV_GET_DISPNAME *q_u, LSA_R_PRIV_GET_DISPNAME *r_u)
785 {
786         struct lsa_info *handle;
787         fstring name_asc;
788         int i=1;
789
790         if (!find_policy_by_hnd(p, &q_u->pol, (void **)&handle))
791                 return NT_STATUS_INVALID_HANDLE;
792
793         /* check if the user have enough rights */
794
795         /*
796          * I don't know if it's the right one. not documented.
797          */
798         if (!(handle->access & POLICY_VIEW_LOCAL_INFORMATION))
799                 return NT_STATUS_ACCESS_DENIED;
800
801         unistr2_to_ascii(name_asc, &q_u->name, sizeof(name_asc));
802
803         DEBUG(10,("_lsa_priv_get_dispname: %s", name_asc));
804
805         while (privs[i].se_priv!=SE_PRIV_ALL && strcmp(name_asc, privs[i].priv))
806                 i++;
807         
808         if (privs[i].se_priv!=SE_PRIV_ALL) {
809                 DEBUG(10,(": %s\n", privs[i].description));
810                 init_uni_hdr(&r_u->hdr_desc, strlen(privs[i].description));
811                 init_unistr2(&r_u->desc, privs[i].description, strlen(privs[i].description) );
812
813                 r_u->ptr_info=0xdeadbeef;
814                 r_u->lang_id=q_u->lang_id;
815                 return NT_STATUS_OK;
816         } else {
817                 DEBUG(10,("_lsa_priv_get_dispname: doesn't exist\n"));
818                 r_u->ptr_info=0;
819                 return NT_STATUS_NO_SUCH_PRIVILEGE;
820         }
821 }
822
823 /***************************************************************************
824 _lsa_enum_accounts.
825  ***************************************************************************/
826
827 NTSTATUS _lsa_enum_accounts(pipes_struct *p, LSA_Q_ENUM_ACCOUNTS *q_u, LSA_R_ENUM_ACCOUNTS *r_u)
828 {
829         struct lsa_info *handle;
830         GROUP_MAP *map=NULL;
831         int num_entries=0;
832         LSA_SID_ENUM *sids=&r_u->sids;
833         int i=0,j=0;
834
835         if (!find_policy_by_hnd(p, &q_u->pol, (void **)&handle))
836                 return NT_STATUS_INVALID_HANDLE;
837
838         /* check if the user have enough rights */
839
840         /*
841          * I don't know if it's the right one. not documented.
842          */
843         if (!(handle->access & POLICY_VIEW_LOCAL_INFORMATION))
844                 return NT_STATUS_ACCESS_DENIED;
845
846         /* get the list of mapped groups (domain, local, builtin) */
847         if(!pdb_enum_group_mapping(SID_NAME_UNKNOWN, &map, &num_entries, ENUM_ONLY_MAPPED, MAPPING_WITHOUT_PRIV))
848                 return NT_STATUS_OK;
849
850         if (q_u->enum_context >= num_entries)
851                 return NT_STATUS_NO_MORE_ENTRIES;
852
853         sids->ptr_sid = (uint32 *)talloc_zero(p->mem_ctx, (num_entries-q_u->enum_context)*sizeof(uint32));
854         sids->sid = (DOM_SID2 *)talloc_zero(p->mem_ctx, (num_entries-q_u->enum_context)*sizeof(DOM_SID2));
855
856         if (sids->ptr_sid==NULL || sids->sid==NULL) {
857                 SAFE_FREE(map);
858                 return NT_STATUS_NO_MEMORY;
859         }
860
861         for (i=q_u->enum_context, j=0; i<num_entries; i++) {
862                 init_dom_sid2( &(*sids).sid[j],  &map[i].sid);
863                 (*sids).ptr_sid[j]=1;
864                 j++;
865         }
866
867         SAFE_FREE(map);
868
869         init_lsa_r_enum_accounts(r_u, j);
870
871         return NT_STATUS_OK;
872 }
873
874
875 NTSTATUS _lsa_unk_get_connuser(pipes_struct *p, LSA_Q_UNK_GET_CONNUSER *q_u, LSA_R_UNK_GET_CONNUSER *r_u)
876 {
877         fstring username, domname;
878         int ulen, dlen;
879         user_struct *vuser = get_valid_user_struct(p->vuid);
880   
881         if (vuser == NULL)
882                 return NT_STATUS_CANT_ACCESS_DOMAIN_INFO;
883   
884         fstrcpy(username, vuser->user.smb_name);
885         fstrcpy(domname, vuser->user.domain);
886   
887         ulen = strlen(username) + 1;
888         dlen = strlen(domname) + 1;
889   
890         init_uni_hdr(&r_u->hdr_user_name, ulen);
891         r_u->ptr_user_name = 1;
892         init_unistr2(&r_u->uni2_user_name, username, ulen);
893
894         r_u->unk1 = 1;
895   
896         init_uni_hdr(&r_u->hdr_dom_name, dlen);
897         r_u->ptr_dom_name = 1;
898         init_unistr2(&r_u->uni2_dom_name, domname, dlen);
899
900         r_u->status = NT_STATUS_OK;
901   
902         return r_u->status;
903 }
904
905 /***************************************************************************
906  
907  ***************************************************************************/
908
909 NTSTATUS _lsa_open_account(pipes_struct *p, LSA_Q_OPENACCOUNT *q_u, LSA_R_OPENACCOUNT *r_u)
910 {
911         struct lsa_info *handle;
912         struct lsa_info *info;
913
914         r_u->status = NT_STATUS_OK;
915
916         /* find the connection policy handle. */
917         if (!find_policy_by_hnd(p, &q_u->pol, (void **)&handle))
918                 return NT_STATUS_INVALID_HANDLE;
919
920         /* check if the user have enough rights */
921
922         /*
923          * I don't know if it's the right one. not documented.
924          * but guessed with rpcclient.
925          */
926         if (!(handle->access & POLICY_GET_PRIVATE_INFORMATION))
927                 return NT_STATUS_ACCESS_DENIED;
928
929         /* associate the user/group SID with the (unique) handle. */
930         if ((info = (struct lsa_info *)malloc(sizeof(struct lsa_info))) == NULL)
931                 return NT_STATUS_NO_MEMORY;
932
933         ZERO_STRUCTP(info);
934         info->sid = q_u->sid.sid;
935         info->access = q_u->access;
936
937         /* get a (unique) handle.  open a policy on it. */
938         if (!create_policy_hnd(p, &r_u->pol, free_lsa_info, (void *)info))
939                 return NT_STATUS_OBJECT_NAME_NOT_FOUND;
940
941         return r_u->status;
942 }
943
944 /***************************************************************************
945  For a given SID, enumerate all the privilege this account has.
946  ***************************************************************************/
947
948 NTSTATUS _lsa_enum_privsaccount(pipes_struct *p, LSA_Q_ENUMPRIVSACCOUNT *q_u, LSA_R_ENUMPRIVSACCOUNT *r_u)
949 {
950         struct lsa_info *info=NULL;
951         GROUP_MAP map;
952         int i=0;
953
954         LUID_ATTR *set=NULL;
955
956         r_u->status = NT_STATUS_OK;
957
958         /* find the connection policy handle. */
959         if (!find_policy_by_hnd(p, &q_u->pol, (void **)&info))
960                 return NT_STATUS_INVALID_HANDLE;
961
962         if (!pdb_getgrsid(&map, info->sid, MAPPING_WITH_PRIV))
963                 return NT_STATUS_NO_SUCH_GROUP;
964
965         DEBUG(10,("_lsa_enum_privsaccount: %d privileges\n", map.priv_set.count));
966         if (map.priv_set.count!=0) {
967         
968                 set=(LUID_ATTR *)talloc(p->mem_ctx, map.priv_set.count*sizeof(LUID_ATTR));
969                 if (set == NULL) {
970                         free_privilege(&map.priv_set);  
971                         return NT_STATUS_NO_MEMORY;
972                 }
973
974                 for (i=0; i<map.priv_set.count; i++) {
975                         set[i].luid.low=map.priv_set.set[i].luid.low;
976                         set[i].luid.high=map.priv_set.set[i].luid.high;
977                         set[i].attr=map.priv_set.set[i].attr;
978                         DEBUG(10,("_lsa_enum_privsaccount: priv %d: %d:%d:%d\n", i, 
979                                    set[i].luid.high, set[i].luid.low, set[i].attr));
980                 }
981         }
982
983         init_lsa_r_enum_privsaccount(r_u, set, map.priv_set.count, 0);  
984         free_privilege(&map.priv_set);  
985
986         return r_u->status;
987 }
988
989 /***************************************************************************
990  
991  ***************************************************************************/
992
993 NTSTATUS _lsa_getsystemaccount(pipes_struct *p, LSA_Q_GETSYSTEMACCOUNT *q_u, LSA_R_GETSYSTEMACCOUNT *r_u)
994 {
995         struct lsa_info *info=NULL;
996         GROUP_MAP map;
997         r_u->status = NT_STATUS_OK;
998
999         /* find the connection policy handle. */
1000         if (!find_policy_by_hnd(p, &q_u->pol, (void **)&info))
1001                 return NT_STATUS_INVALID_HANDLE;
1002
1003         if (!pdb_getgrsid(&map, info->sid, MAPPING_WITHOUT_PRIV))
1004                 return NT_STATUS_NO_SUCH_GROUP;
1005
1006         /*
1007           0x01 -> Log on locally
1008           0x02 -> Access this computer from network
1009           0x04 -> Log on as a batch job
1010           0x10 -> Log on as a service
1011           
1012           they can be ORed together
1013         */
1014
1015         r_u->access=map.systemaccount;
1016
1017         return r_u->status;
1018 }
1019
1020 /***************************************************************************
1021   update the systemaccount information
1022  ***************************************************************************/
1023
1024 NTSTATUS _lsa_setsystemaccount(pipes_struct *p, LSA_Q_SETSYSTEMACCOUNT *q_u, LSA_R_SETSYSTEMACCOUNT *r_u)
1025 {
1026         struct lsa_info *info=NULL;
1027         GROUP_MAP map;
1028         r_u->status = NT_STATUS_OK;
1029
1030         /* find the connection policy handle. */
1031         if (!find_policy_by_hnd(p, &q_u->pol, (void **)&info))
1032                 return NT_STATUS_INVALID_HANDLE;
1033
1034         if (!pdb_getgrsid(&map, info->sid, MAPPING_WITH_PRIV))
1035                 return NT_STATUS_NO_SUCH_GROUP;
1036
1037         map.systemaccount=q_u->access;
1038
1039         if(!pdb_update_group_mapping_entry(&map))
1040                 return NT_STATUS_NO_SUCH_GROUP;
1041
1042         free_privilege(&map.priv_set);
1043
1044         return r_u->status;
1045 }
1046
1047 /***************************************************************************
1048  For a given SID, add some privileges.
1049  ***************************************************************************/
1050
1051 NTSTATUS _lsa_addprivs(pipes_struct *p, LSA_Q_ADDPRIVS *q_u, LSA_R_ADDPRIVS *r_u)
1052 {
1053         struct lsa_info *info=NULL;
1054         GROUP_MAP map;
1055         int i=0;
1056
1057         LUID_ATTR *luid_attr=NULL;
1058         PRIVILEGE_SET *set=NULL;
1059
1060         r_u->status = NT_STATUS_OK;
1061
1062         /* find the connection policy handle. */
1063         if (!find_policy_by_hnd(p, &q_u->pol, (void **)&info))
1064                 return NT_STATUS_INVALID_HANDLE;
1065
1066         if (!pdb_getgrsid(&map, info->sid, MAPPING_WITH_PRIV))
1067                 return NT_STATUS_NO_SUCH_GROUP;
1068
1069         set=&q_u->set;
1070
1071         for (i=0; i<set->count; i++) {
1072                 luid_attr=&set->set[i];
1073                 
1074                 /* check if the privilege is already there */
1075                 if (check_priv_in_privilege(&map.priv_set, *luid_attr)){
1076                         free_privilege(&map.priv_set);
1077                         return NT_STATUS_NO_SUCH_PRIVILEGE;
1078                 }
1079                 
1080                 add_privilege(&map.priv_set, *luid_attr);
1081         }
1082
1083         if(!pdb_update_group_mapping_entry(&map))
1084                 return NT_STATUS_NO_SUCH_GROUP;
1085         
1086         free_privilege(&map.priv_set);  
1087
1088         return r_u->status;
1089 }
1090
1091 /***************************************************************************
1092  For a given SID, remove some privileges.
1093  ***************************************************************************/
1094
1095 NTSTATUS _lsa_removeprivs(pipes_struct *p, LSA_Q_REMOVEPRIVS *q_u, LSA_R_REMOVEPRIVS *r_u)
1096 {
1097         struct lsa_info *info=NULL;
1098         GROUP_MAP map;
1099         int i=0;
1100
1101         LUID_ATTR *luid_attr=NULL;
1102         PRIVILEGE_SET *set=NULL;
1103
1104         r_u->status = NT_STATUS_OK;
1105
1106         /* find the connection policy handle. */
1107         if (!find_policy_by_hnd(p, &q_u->pol, (void **)&info))
1108                 return NT_STATUS_INVALID_HANDLE;
1109
1110         if (!pdb_getgrsid(&map, info->sid, MAPPING_WITH_PRIV))
1111                 return NT_STATUS_NO_SUCH_GROUP;
1112
1113         if (q_u->allrights!=0) {
1114                 /* log it and return, until I see one myself don't do anything */
1115                 DEBUG(5,("_lsa_removeprivs: trying to remove all privileges ?\n"));
1116                 return NT_STATUS_OK;
1117         }
1118
1119         if (q_u->ptr==0) {
1120                 /* log it and return, until I see one myself don't do anything */
1121                 DEBUG(5,("_lsa_removeprivs: no privileges to remove ?\n"));
1122                 return NT_STATUS_OK;
1123         }
1124
1125         set=&q_u->set;
1126
1127         for (i=0; i<set->count; i++) {
1128                 luid_attr=&set->set[i];
1129                 
1130                 /* if we don't have the privilege, we're trying to remove, give up */
1131                 /* what else can we do ??? JFM. */
1132                 if (!check_priv_in_privilege(&map.priv_set, *luid_attr)){
1133                         free_privilege(&map.priv_set);
1134                         return NT_STATUS_NO_SUCH_PRIVILEGE;
1135                 }
1136                 
1137                 remove_privilege(&map.priv_set, *luid_attr);
1138         }
1139
1140         if(!pdb_update_group_mapping_entry(&map))
1141                 return NT_STATUS_NO_SUCH_GROUP;
1142         
1143         free_privilege(&map.priv_set);  
1144
1145         return r_u->status;
1146 }
1147
1148 /***************************************************************************
1149  For a given SID, remove some privileges.
1150  ***************************************************************************/
1151
1152 NTSTATUS _lsa_query_secobj(pipes_struct *p, LSA_Q_QUERY_SEC_OBJ *q_u, LSA_R_QUERY_SEC_OBJ *r_u)
1153 {
1154         struct lsa_info *handle=NULL;
1155         SEC_DESC *psd = NULL;
1156         size_t sd_size;
1157         NTSTATUS status;
1158
1159         r_u->status = NT_STATUS_OK;
1160
1161         /* find the connection policy handle. */
1162         if (!find_policy_by_hnd(p, &q_u->pol, (void **)&handle))
1163                 return NT_STATUS_INVALID_HANDLE;
1164
1165         /* check if the user have enough rights */
1166         if (!(handle->access & POLICY_VIEW_LOCAL_INFORMATION))
1167                 return NT_STATUS_ACCESS_DENIED;
1168
1169
1170         switch (q_u->sec_info) {
1171         case 1:
1172                 /* SD contains only the owner */
1173
1174                 status=lsa_get_generic_sd(p->mem_ctx, &psd, &sd_size);
1175                 if(!NT_STATUS_IS_OK(status))
1176                         return NT_STATUS_NO_MEMORY;
1177
1178
1179                 if((r_u->buf = make_sec_desc_buf(p->mem_ctx, sd_size, psd)) == NULL)
1180                         return NT_STATUS_NO_MEMORY;
1181                 break;
1182         case 4:
1183                 /* SD contains only the ACL */
1184
1185                 status=lsa_get_generic_sd(p->mem_ctx, &psd, &sd_size);
1186                 if(!NT_STATUS_IS_OK(status))
1187                         return NT_STATUS_NO_MEMORY;
1188
1189                 if((r_u->buf = make_sec_desc_buf(p->mem_ctx, sd_size, psd)) == NULL)
1190                         return NT_STATUS_NO_MEMORY;
1191                 break;
1192         default:
1193                 return NT_STATUS_INVALID_LEVEL;
1194         }
1195
1196         r_u->ptr=1;
1197
1198         return r_u->status;
1199 }
1200
1201
1202 NTSTATUS _lsa_query_info2(pipes_struct *p, LSA_Q_QUERY_INFO2 *q_u, LSA_R_QUERY_INFO2 *r_u)
1203 {
1204         struct lsa_info *handle;
1205         const char *nb_name;
1206         char *dns_name = NULL;
1207         char *forest_name = NULL;
1208         DOM_SID *sid = NULL;
1209         GUID guid;
1210         fstring dnsdomname;
1211
1212         ZERO_STRUCT(guid);
1213         r_u->status = NT_STATUS_OK;
1214
1215         if (!find_policy_by_hnd(p, &q_u->pol, (void **)&handle))
1216                 return NT_STATUS_INVALID_HANDLE;
1217
1218         switch (q_u->info_class) {
1219         case 0x0c:
1220                 /* check if the user have enough rights */
1221                 if (!(handle->access & POLICY_VIEW_LOCAL_INFORMATION))
1222                         return NT_STATUS_ACCESS_DENIED;
1223
1224                 /* Request PolicyPrimaryDomainInformation. */
1225                 switch (lp_server_role()) {
1226                         case ROLE_DOMAIN_PDC:
1227                         case ROLE_DOMAIN_BDC:
1228                                 nb_name = get_global_sam_name();
1229                                 /* ugly temp hack for these next two */
1230
1231                                 /* This should be a 'netbios domain -> DNS domain' mapping */
1232                                 dnsdomname[0] = '\0';
1233                                 get_mydomname(dnsdomname);
1234                                 strlower(dnsdomname);
1235                                 
1236                                 dns_name = dnsdomname;
1237                                 forest_name = dnsdomname;
1238
1239                                 sid = get_global_sam_sid();
1240                                 secrets_fetch_domain_guid(lp_workgroup(), &guid);
1241                                 break;
1242                         default:
1243                                 return NT_STATUS_CANT_ACCESS_DOMAIN_INFO;
1244                 }
1245                 init_dns_dom_info(&r_u->info.dns_dom_info, nb_name, dns_name, 
1246                                   forest_name,&guid,sid);
1247                 break;
1248         default:
1249                 DEBUG(0,("_lsa_query_info2: unknown info level in Lsa Query: %d\n", q_u->info_class));
1250                 r_u->status = NT_STATUS_INVALID_INFO_CLASS;
1251                 break;
1252         }
1253
1254         if (NT_STATUS_IS_OK(r_u->status)) {
1255                 r_u->ptr = 0x1;
1256                 r_u->info_class = q_u->info_class;
1257         }
1258
1259         return r_u->status;
1260 }