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 <jmcd@us.ibm.com> 2002,
10 * Copyright (C) Simo Sorce 2003.
11 * Copyright (C) Gerald (Jerry) Carter 2005.
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 2 of the License, or
16 * (at your option) any later version.
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
23 * You should have received a copy of the GNU General Public License
24 * along with this program; if not, write to the Free Software
25 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
28 /* This is the implementation of the lsa server code. */
33 #define DBGC_CLASS DBGC_RPC_SRV
42 struct generic_mapping lsa_generic_mapping = {
49 /*******************************************************************
50 Function to free the per handle data.
51 ********************************************************************/
53 static void free_lsa_info(void *ptr)
55 struct lsa_info *lsa = (struct lsa_info *)ptr;
60 /***************************************************************************
62 ***************************************************************************/
64 static void init_dom_query(DOM_QUERY *d_q, const char *dom_name, DOM_SID *dom_sid)
66 d_q->buffer_dom_name = (dom_name != NULL) ? 1 : 0; /* domain buffer pointer */
67 d_q->buffer_dom_sid = (dom_sid != NULL) ? 1 : 0; /* domain sid pointer */
69 /* this string is supposed to be non-null terminated. */
70 /* But the maxlen in this UNISTR2 must include the terminating null. */
71 init_unistr2(&d_q->uni_domain_name, dom_name, UNI_BROKEN_NON_NULL);
74 * I'm not sure why this really odd combination of length
75 * values works, but it does appear to. I need to look at
76 * this *much* more closely - but at the moment leave alone
77 * until it's understood. This allows a W2k client to join
78 * a domain with both odd and even length names... JRA.
83 * The two fields below probably are reversed in meaning, ie.
84 * the first field is probably the str_len, the second the max
85 * len. Both are measured in bytes anyway.
88 d_q->uni_dom_str_len = d_q->uni_domain_name.uni_max_len * 2;
89 d_q->uni_dom_max_len = d_q->uni_domain_name.uni_str_len * 2;
92 init_dom_sid2(&d_q->dom_sid, dom_sid);
95 /***************************************************************************
96 init_dom_ref - adds a domain if it's not already in, returns the index.
97 ***************************************************************************/
99 static int init_dom_ref(DOM_R_REF *ref, char *dom_name, DOM_SID *dom_sid)
103 if (dom_name != NULL) {
104 for (num = 0; num < ref->num_ref_doms_1; num++) {
106 rpcstr_pull(domname, ref->ref_dom[num].uni_dom_name.buffer, sizeof(domname), -1, 0);
107 if (strequal(domname, dom_name))
111 num = ref->num_ref_doms_1;
114 if (num >= MAX_REF_DOMAINS) {
115 /* index not found, already at maximum domain limit */
119 ref->num_ref_doms_1 = num+1;
120 ref->ptr_ref_dom = 1;
121 ref->max_entries = MAX_REF_DOMAINS;
122 ref->num_ref_doms_2 = num+1;
124 ref->hdr_ref_dom[num].ptr_dom_sid = dom_sid != NULL ? 1 : 0;
126 init_unistr2(&ref->ref_dom[num].uni_dom_name, dom_name, UNI_FLAGS_NONE);
127 init_uni_hdr(&ref->hdr_ref_dom[num].hdr_dom_name, &ref->ref_dom[num].uni_dom_name);
129 init_dom_sid2(&ref->ref_dom[num].ref_dom, dom_sid );
134 /***************************************************************************
136 ***************************************************************************/
138 static int init_lsa_rid2s(TALLOC_CTX *mem_ctx,
139 DOM_R_REF *ref, DOM_RID2 *rid2,
140 int num_entries, UNISTR2 *name,
145 SMB_ASSERT(num_entries <= MAX_LOOKUP_SIDS);
149 become_root(); /* lookup_name can require root privs */
151 for (i = 0; i < num_entries; i++) {
156 char *full_name, *domain;
157 enum SID_NAME_USE type = SID_NAME_UNKNOWN;
159 /* Split name into domain and user component */
161 if (rpcstr_pull_unistr2_talloc(mem_ctx, &full_name,
163 DEBUG(0, ("pull_ucs2_talloc failed\n"));
167 DEBUG(5, ("init_lsa_rid2s: looking up name %s\n", full_name));
169 /* We can ignore the result of lookup_name, it will not touch
170 "type" if it's not successful */
172 lookup_name(mem_ctx, full_name, flags, &domain, NULL,
175 DEBUG(5, ("init_lsa_rid2s: %s\n", status ? "found" :
180 case SID_NAME_DOM_GRP:
181 case SID_NAME_DOMAIN:
183 case SID_NAME_WKN_GRP:
184 /* Leave these unchanged */
187 /* Don't hand out anything but the list above */
188 type = SID_NAME_UNKNOWN;
195 if (type != SID_NAME_UNKNOWN) {
196 sid_split_rid(&sid, &rid);
197 dom_idx = init_dom_ref(ref, domain, &sid);
201 init_dom_rid2(&rid2[i], rid, type, dom_idx);
209 /***************************************************************************
210 init_reply_lookup_names
211 ***************************************************************************/
213 static void init_reply_lookup_names(LSA_R_LOOKUP_NAMES *r_l,
214 DOM_R_REF *ref, uint32 num_entries,
215 DOM_RID2 *rid2, uint32 mapped_count)
217 r_l->ptr_dom_ref = 1;
220 r_l->num_entries = num_entries;
221 r_l->ptr_entries = 1;
222 r_l->num_entries2 = num_entries;
225 r_l->mapped_count = mapped_count;
228 /***************************************************************************
229 Init lsa_trans_names.
230 ***************************************************************************/
232 static void init_lsa_trans_names(TALLOC_CTX *ctx, DOM_R_REF *ref, LSA_TRANS_NAME_ENUM *trn,
233 int num_entries, DOM_SID2 *sid,
234 uint32 *mapped_count)
240 /* Allocate memory for list of names */
242 if (num_entries > 0) {
243 if (!(trn->name = TALLOC_ARRAY(ctx, LSA_TRANS_NAME, num_entries))) {
244 DEBUG(0, ("init_lsa_trans_names(): out of memory\n"));
248 if (!(trn->uni_name = TALLOC_ARRAY(ctx, UNISTR2, num_entries))) {
249 DEBUG(0, ("init_lsa_trans_names(): out of memory\n"));
254 become_root(); /* Need root to get to passdb to for local sids */
256 for (i = 0; i < num_entries; i++) {
258 DOM_SID find_sid = sid[i].sid;
259 uint32 rid = 0xffffffff;
262 enum SID_NAME_USE type = SID_NAME_UNKNOWN;
264 DEBUG(5, ("init_lsa_trans_names: looking up sid %s\n",
265 sid_string_static(&find_sid)));
267 /* Lookup sid from winbindd */
269 status = lookup_sid(ctx, &find_sid, &domain, &name, &type);
271 DEBUG(5, ("init_lsa_trans_names: %s\n", status ? "found" :
275 type = SID_NAME_UNKNOWN;
276 domain = talloc_strdup(ctx, "");
277 name = talloc_strdup(ctx,
278 sid_string_static(&find_sid));
281 DEBUG(10,("init_lsa_trans_names: added unknown user "
282 "'%s' to referenced list.\n", name ));
285 /* Store domain sid in ref array */
286 if (find_sid.num_auths == 5) {
287 sid_split_rid(&find_sid, &rid);
289 dom_idx = init_dom_ref(ref, domain, &find_sid);
291 DEBUG(10,("init_lsa_trans_names: added %s '%s\\%s' "
292 "(%d) to referenced list.\n",
293 sid_type_lookup(type), domain, name, type));
297 init_lsa_trans_name(&trn->name[total], &trn->uni_name[total],
298 type, name, dom_idx);
304 trn->num_entries = total;
305 trn->ptr_trans_names = 1;
306 trn->num_entries2 = total;
309 /***************************************************************************
310 Init_reply_lookup_sids.
311 ***************************************************************************/
313 static void init_reply_lookup_sids(LSA_R_LOOKUP_SIDS *r_l,
314 DOM_R_REF *ref, LSA_TRANS_NAME_ENUM *names,
317 r_l->ptr_dom_ref = 1;
320 r_l->mapped_count = mapped_count;
323 static NTSTATUS lsa_get_generic_sd(TALLOC_CTX *mem_ctx, SEC_DESC **sd, size_t *sd_size)
325 DOM_SID local_adm_sid;
333 init_sec_access(&mask, POLICY_EXECUTE);
334 init_sec_ace(&ace[0], &global_sid_World, SEC_ACE_TYPE_ACCESS_ALLOWED, mask, 0);
336 sid_copy(&adm_sid, get_global_sam_sid());
337 sid_append_rid(&adm_sid, DOMAIN_GROUP_RID_ADMINS);
338 init_sec_access(&mask, POLICY_ALL_ACCESS);
339 init_sec_ace(&ace[1], &adm_sid, SEC_ACE_TYPE_ACCESS_ALLOWED, mask, 0);
341 sid_copy(&local_adm_sid, &global_sid_Builtin);
342 sid_append_rid(&local_adm_sid, BUILTIN_ALIAS_RID_ADMINS);
343 init_sec_access(&mask, POLICY_ALL_ACCESS);
344 init_sec_ace(&ace[2], &local_adm_sid, SEC_ACE_TYPE_ACCESS_ALLOWED, mask, 0);
346 if((psa = make_sec_acl(mem_ctx, NT4_ACL_REVISION, 3, ace)) == NULL)
347 return NT_STATUS_NO_MEMORY;
349 if((*sd = make_sec_desc(mem_ctx, SEC_DESC_REVISION, SEC_DESC_SELF_RELATIVE, &adm_sid, NULL, NULL, psa, sd_size)) == NULL)
350 return NT_STATUS_NO_MEMORY;
355 #if 0 /* AD DC work in ongoing in Samba 4 */
357 /***************************************************************************
359 ***************************************************************************/
361 static void init_dns_dom_info(LSA_DNS_DOM_INFO *r_l, const char *nb_name,
362 const char *dns_name, const char *forest_name,
363 struct uuid *dom_guid, DOM_SID *dom_sid)
365 if (nb_name && *nb_name) {
366 init_unistr2(&r_l->uni_nb_dom_name, nb_name, UNI_FLAGS_NONE);
367 init_uni_hdr(&r_l->hdr_nb_dom_name, &r_l->uni_nb_dom_name);
368 r_l->hdr_nb_dom_name.uni_max_len += 2;
369 r_l->uni_nb_dom_name.uni_max_len += 1;
372 if (dns_name && *dns_name) {
373 init_unistr2(&r_l->uni_dns_dom_name, dns_name, UNI_FLAGS_NONE);
374 init_uni_hdr(&r_l->hdr_dns_dom_name, &r_l->uni_dns_dom_name);
375 r_l->hdr_dns_dom_name.uni_max_len += 2;
376 r_l->uni_dns_dom_name.uni_max_len += 1;
379 if (forest_name && *forest_name) {
380 init_unistr2(&r_l->uni_forest_name, forest_name, UNI_FLAGS_NONE);
381 init_uni_hdr(&r_l->hdr_forest_name, &r_l->uni_forest_name);
382 r_l->hdr_forest_name.uni_max_len += 2;
383 r_l->uni_forest_name.uni_max_len += 1;
386 /* how do we init the guid ? probably should write an init fn */
388 memcpy(&r_l->dom_guid, dom_guid, sizeof(struct uuid));
392 r_l->ptr_dom_sid = 1;
393 init_dom_sid2(&r_l->dom_sid, dom_sid);
396 #endif /* AD DC work in ongoing in Samba 4 */
399 /***************************************************************************
401 ***************************************************************************/
403 NTSTATUS _lsa_open_policy2(pipes_struct *p, LSA_Q_OPEN_POL2 *q_u, LSA_R_OPEN_POL2 *r_u)
405 struct lsa_info *info;
406 SEC_DESC *psd = NULL;
408 uint32 des_access=q_u->des_access;
413 /* map the generic bits to the lsa policy ones */
414 se_map_generic(&des_access, &lsa_generic_mapping);
416 /* get the generic lsa policy SD until we store it */
417 lsa_get_generic_sd(p->mem_ctx, &psd, &sd_size);
419 if(!se_access_check(psd, p->pipe_user.nt_user_token, des_access, &acc_granted, &status)) {
420 if (geteuid() != 0) {
423 DEBUG(4,("ACCESS should be DENIED (granted: %#010x; required: %#010x)\n",
424 acc_granted, des_access));
425 DEBUGADD(4,("but overwritten by euid == 0\n"));
428 /* This is needed for lsa_open_account and rpcclient .... :-) */
431 acc_granted = POLICY_ALL_ACCESS;
433 /* associate the domain SID with the (unique) handle. */
434 if ((info = SMB_MALLOC_P(struct lsa_info)) == NULL)
435 return NT_STATUS_NO_MEMORY;
438 sid_copy(&info->sid,get_global_sam_sid());
439 info->access = acc_granted;
441 /* set up the LSA QUERY INFO response */
442 if (!create_policy_hnd(p, &r_u->pol, free_lsa_info, (void *)info))
443 return NT_STATUS_OBJECT_NAME_NOT_FOUND;
448 /***************************************************************************
450 ***************************************************************************/
452 NTSTATUS _lsa_open_policy(pipes_struct *p, LSA_Q_OPEN_POL *q_u, LSA_R_OPEN_POL *r_u)
454 struct lsa_info *info;
455 SEC_DESC *psd = NULL;
457 uint32 des_access=q_u->des_access;
462 /* map the generic bits to the lsa policy ones */
463 se_map_generic(&des_access, &lsa_generic_mapping);
465 /* get the generic lsa policy SD until we store it */
466 lsa_get_generic_sd(p->mem_ctx, &psd, &sd_size);
468 if(!se_access_check(psd, p->pipe_user.nt_user_token, des_access, &acc_granted, &status)) {
469 if (geteuid() != 0) {
472 DEBUG(4,("ACCESS should be DENIED (granted: %#010x; required: %#010x)\n",
473 acc_granted, des_access));
474 DEBUGADD(4,("but overwritten by euid == 0\n"));
475 acc_granted = des_access;
478 /* associate the domain SID with the (unique) handle. */
479 if ((info = SMB_MALLOC_P(struct lsa_info)) == NULL)
480 return NT_STATUS_NO_MEMORY;
483 sid_copy(&info->sid,get_global_sam_sid());
484 info->access = acc_granted;
486 /* set up the LSA QUERY INFO response */
487 if (!create_policy_hnd(p, &r_u->pol, free_lsa_info, (void *)info))
488 return NT_STATUS_OBJECT_NAME_NOT_FOUND;
493 /***************************************************************************
494 _lsa_enum_trust_dom - this needs fixing to do more than return NULL ! JRA.
496 ***************************************************************************/
498 NTSTATUS _lsa_enum_trust_dom(pipes_struct *p, LSA_Q_ENUM_TRUST_DOM *q_u, LSA_R_ENUM_TRUST_DOM *r_u)
500 struct lsa_info *info;
501 uint32 enum_context = q_u->enum_context;
504 * preferred length is set to 5 as a "our" preferred length
505 * nt sets this parameter to 2
506 * update (20.08.2002): it's not preferred length, but preferred size!
507 * it needs further investigation how to optimally choose this value
509 uint32 max_num_domains = q_u->preferred_len < 5 ? q_u->preferred_len : 10;
510 TRUSTDOM **trust_doms;
514 if (!find_policy_by_hnd(p, &q_u->pol, (void **)(void *)&info))
515 return NT_STATUS_INVALID_HANDLE;
517 /* check if the user have enough rights */
518 if (!(info->access & POLICY_VIEW_LOCAL_INFORMATION))
519 return NT_STATUS_ACCESS_DENIED;
521 nt_status = secrets_get_trusted_domains(p->mem_ctx, (int *)&enum_context, max_num_domains, (int *)&num_domains, &trust_doms);
523 if (!NT_STATUS_IS_OK(nt_status) &&
524 !NT_STATUS_EQUAL(nt_status, STATUS_MORE_ENTRIES) &&
525 !NT_STATUS_EQUAL(nt_status, NT_STATUS_NO_MORE_ENTRIES)) {
528 r_u->status = nt_status;
531 /* set up the lsa_enum_trust_dom response */
533 init_r_enum_trust_dom(p->mem_ctx, r_u, enum_context, max_num_domains, num_domains, trust_doms);
538 /***************************************************************************
539 _lsa_query_info. See the POLICY_INFOMATION_CLASS docs at msdn.
540 ***************************************************************************/
542 NTSTATUS _lsa_query_info(pipes_struct *p, LSA_Q_QUERY_INFO *q_u, LSA_R_QUERY_INFO *r_u)
544 struct lsa_info *handle;
545 LSA_INFO_UNION *info = &r_u->dom;
550 r_u->status = NT_STATUS_OK;
552 if (!find_policy_by_hnd(p, &q_u->pol, (void **)(void *)&handle))
553 return NT_STATUS_INVALID_HANDLE;
555 switch (q_u->info_class) {
559 /* check if the user have enough rights */
560 if (!(handle->access & POLICY_VIEW_AUDIT_INFORMATION))
561 return NT_STATUS_ACCESS_DENIED;
563 /* fake info: We audit everything. ;) */
564 info->id2.auditing_enabled = 1;
565 info->id2.count1 = 7;
566 info->id2.count2 = 7;
567 if ((info->id2.auditsettings = TALLOC_ARRAY(p->mem_ctx,uint32, 7)) == NULL)
568 return NT_STATUS_NO_MEMORY;
569 for (i = 0; i < 7; i++)
570 info->id2.auditsettings[i] = 3;
574 /* check if the user have enough rights */
575 if (!(handle->access & POLICY_VIEW_LOCAL_INFORMATION))
576 return NT_STATUS_ACCESS_DENIED;
578 /* Request PolicyPrimaryDomainInformation. */
579 switch (lp_server_role()) {
580 case ROLE_DOMAIN_PDC:
581 case ROLE_DOMAIN_BDC:
582 name = get_global_sam_name();
583 sid = get_global_sam_sid();
585 case ROLE_DOMAIN_MEMBER:
586 name = lp_workgroup();
587 /* We need to return the Domain SID here. */
588 if (secrets_fetch_domain_sid(lp_workgroup(), &domain_sid))
591 return NT_STATUS_CANT_ACCESS_DOMAIN_INFO;
593 case ROLE_STANDALONE:
594 name = lp_workgroup();
598 return NT_STATUS_CANT_ACCESS_DOMAIN_INFO;
600 init_dom_query(&r_u->dom.id3, name, sid);
603 /* check if the user have enough rights */
604 if (!(handle->access & POLICY_VIEW_LOCAL_INFORMATION))
605 return NT_STATUS_ACCESS_DENIED;
607 /* Request PolicyAccountDomainInformation. */
608 name = get_global_sam_name();
609 sid = get_global_sam_sid();
610 init_dom_query(&r_u->dom.id5, name, sid);
613 /* check if the user have enough rights */
614 if (!(handle->access & POLICY_VIEW_LOCAL_INFORMATION))
615 return NT_STATUS_ACCESS_DENIED;
617 switch (lp_server_role()) {
618 case ROLE_DOMAIN_BDC:
620 * only a BDC is a backup controller
621 * of the domain, it controls.
623 info->id6.server_role = 2;
627 * any other role is a primary
628 * of the domain, it controls.
630 info->id6.server_role = 3;
635 DEBUG(0,("_lsa_query_info: unknown info level in Lsa Query: %d\n", q_u->info_class));
636 r_u->status = NT_STATUS_INVALID_INFO_CLASS;
640 if (NT_STATUS_IS_OK(r_u->status)) {
641 r_u->undoc_buffer = 0x22000000; /* bizarre */
642 r_u->info_class = q_u->info_class;
648 /***************************************************************************
650 ***************************************************************************/
652 NTSTATUS _lsa_lookup_sids(pipes_struct *p, LSA_Q_LOOKUP_SIDS *q_u, LSA_R_LOOKUP_SIDS *r_u)
654 struct lsa_info *handle;
655 DOM_SID2 *sid = q_u->sids.sid;
656 int num_entries = q_u->sids.num_entries;
657 DOM_R_REF *ref = NULL;
658 LSA_TRANS_NAME_ENUM *names = NULL;
659 uint32 mapped_count = 0;
661 if (num_entries > MAX_LOOKUP_SIDS) {
663 DEBUG(5,("_lsa_lookup_sids: limit of %d exceeded, truncating SID lookup list to %d\n", MAX_LOOKUP_SIDS, num_entries));
664 r_u->status = NT_STATUS_NONE_MAPPED;
667 ref = TALLOC_ZERO_P(p->mem_ctx, DOM_R_REF);
668 names = TALLOC_ZERO_P(p->mem_ctx, LSA_TRANS_NAME_ENUM);
670 if (!find_policy_by_hnd(p, &q_u->pol, (void **)(void *)&handle)) {
671 r_u->status = NT_STATUS_INVALID_HANDLE;
675 /* check if the user have enough rights */
676 if (!(handle->access & POLICY_LOOKUP_NAMES)) {
677 r_u->status = NT_STATUS_ACCESS_DENIED;
681 return NT_STATUS_NO_MEMORY;
685 /* set up the LSA Lookup SIDs response */
686 init_lsa_trans_names(p->mem_ctx, ref, names, num_entries, sid, &mapped_count);
687 if (NT_STATUS_IS_OK(r_u->status)) {
688 if (mapped_count == 0)
689 r_u->status = NT_STATUS_NONE_MAPPED;
690 else if (mapped_count != num_entries)
691 r_u->status = STATUS_SOME_UNMAPPED;
693 init_reply_lookup_sids(r_u, ref, names, mapped_count);
698 /***************************************************************************
699 lsa_reply_lookup_names
700 ***************************************************************************/
702 NTSTATUS _lsa_lookup_names(pipes_struct *p,LSA_Q_LOOKUP_NAMES *q_u, LSA_R_LOOKUP_NAMES *r_u)
704 struct lsa_info *handle;
705 UNISTR2 *names = q_u->uni_name;
706 int num_entries = q_u->num_entries;
709 uint32 mapped_count = 0;
712 if (num_entries > MAX_LOOKUP_SIDS) {
713 num_entries = MAX_LOOKUP_SIDS;
714 DEBUG(5,("_lsa_lookup_names: truncating name lookup list to %d\n", num_entries));
717 /* Probably the lookup_level is some sort of bitmask. */
718 if (q_u->lookup_level == 1) {
719 flags = LOOKUP_NAME_ALL;
722 ref = TALLOC_ZERO_P(p->mem_ctx, DOM_R_REF);
723 rids = TALLOC_ZERO_ARRAY(p->mem_ctx, DOM_RID2, num_entries);
725 if (!find_policy_by_hnd(p, &q_u->pol, (void **)(void *)&handle)) {
726 r_u->status = NT_STATUS_INVALID_HANDLE;
730 /* check if the user have enough rights */
731 if (!(handle->access & POLICY_LOOKUP_NAMES)) {
732 r_u->status = NT_STATUS_ACCESS_DENIED;
737 return NT_STATUS_NO_MEMORY;
739 /* set up the LSA Lookup RIDs response */
740 mapped_count = init_lsa_rid2s(p->mem_ctx, ref, rids, num_entries,
744 if (NT_STATUS_IS_OK(r_u->status)) {
745 if (mapped_count == 0)
746 r_u->status = NT_STATUS_NONE_MAPPED;
747 else if (mapped_count != num_entries)
748 r_u->status = STATUS_SOME_UNMAPPED;
750 init_reply_lookup_names(r_u, ref, num_entries, rids, mapped_count);
755 /***************************************************************************
756 _lsa_close. Also weird - needs to check if lsa handle is correct. JRA.
757 ***************************************************************************/
759 NTSTATUS _lsa_close(pipes_struct *p, LSA_Q_CLOSE *q_u, LSA_R_CLOSE *r_u)
761 if (!find_policy_by_hnd(p, &q_u->pol, NULL))
762 return NT_STATUS_INVALID_HANDLE;
764 close_policy_hnd(p, &q_u->pol);
768 /***************************************************************************
769 ***************************************************************************/
771 NTSTATUS _lsa_open_secret(pipes_struct *p, LSA_Q_OPEN_SECRET *q_u, LSA_R_OPEN_SECRET *r_u)
773 return NT_STATUS_OBJECT_NAME_NOT_FOUND;
776 /***************************************************************************
777 ***************************************************************************/
779 NTSTATUS _lsa_open_trusted_domain(pipes_struct *p, LSA_Q_OPEN_TRUSTED_DOMAIN *q_u, LSA_R_OPEN_TRUSTED_DOMAIN *r_u)
781 return NT_STATUS_OBJECT_NAME_NOT_FOUND;
784 /***************************************************************************
785 ***************************************************************************/
787 NTSTATUS _lsa_create_trusted_domain(pipes_struct *p, LSA_Q_CREATE_TRUSTED_DOMAIN *q_u, LSA_R_CREATE_TRUSTED_DOMAIN *r_u)
789 return NT_STATUS_ACCESS_DENIED;
792 /***************************************************************************
793 ***************************************************************************/
795 NTSTATUS _lsa_create_secret(pipes_struct *p, LSA_Q_CREATE_SECRET *q_u, LSA_R_CREATE_SECRET *r_u)
797 return NT_STATUS_ACCESS_DENIED;
800 /***************************************************************************
801 ***************************************************************************/
803 NTSTATUS _lsa_set_secret(pipes_struct *p, LSA_Q_SET_SECRET *q_u, LSA_R_SET_SECRET *r_u)
805 return NT_STATUS_ACCESS_DENIED;
808 /***************************************************************************
809 ***************************************************************************/
811 NTSTATUS _lsa_delete_object(pipes_struct *p, LSA_Q_DELETE_OBJECT *q_u, LSA_R_DELETE_OBJECT *r_u)
813 return NT_STATUS_ACCESS_DENIED;
816 /***************************************************************************
818 ***************************************************************************/
820 NTSTATUS _lsa_enum_privs(pipes_struct *p, LSA_Q_ENUM_PRIVS *q_u, LSA_R_ENUM_PRIVS *r_u)
822 struct lsa_info *handle;
824 uint32 enum_context = q_u->enum_context;
825 int num_privs = count_all_privileges();
826 LSA_PRIV_ENTRY *entries = NULL;
829 /* remember that the enum_context starts at 0 and not 1 */
831 if ( enum_context >= num_privs )
832 return NT_STATUS_NO_MORE_ENTRIES;
834 DEBUG(10,("_lsa_enum_privs: enum_context:%d total entries:%d\n",
835 enum_context, num_privs));
837 if (!find_policy_by_hnd(p, &q_u->pol, (void **)(void *)&handle))
838 return NT_STATUS_INVALID_HANDLE;
840 /* check if the user have enough rights
841 I don't know if it's the right one. not documented. */
843 if (!(handle->access & POLICY_VIEW_LOCAL_INFORMATION))
844 return NT_STATUS_ACCESS_DENIED;
846 if ( !(entries = TALLOC_ZERO_ARRAY(p->mem_ctx, LSA_PRIV_ENTRY, num_privs )) )
847 return NT_STATUS_NO_MEMORY;
849 for (i = 0; i < num_privs; i++) {
850 if( i < enum_context) {
851 init_unistr2(&entries[i].name, NULL, UNI_FLAGS_NONE);
852 init_uni_hdr(&entries[i].hdr_name, &entries[i].name);
854 entries[i].luid_low = 0;
855 entries[i].luid_high = 0;
857 init_unistr2(&entries[i].name, privs[i].name, UNI_FLAGS_NONE);
858 init_uni_hdr(&entries[i].hdr_name, &entries[i].name);
860 luid = get_privilege_luid( &privs[i].se_priv );
862 entries[i].luid_low = luid.luid.low;
863 entries[i].luid_high = luid.luid.high;
867 enum_context = num_privs;
869 init_lsa_r_enum_privs(r_u, enum_context, num_privs, entries);
874 /***************************************************************************
875 _lsa_priv_get_dispname.
876 ***************************************************************************/
878 NTSTATUS _lsa_priv_get_dispname(pipes_struct *p, LSA_Q_PRIV_GET_DISPNAME *q_u, LSA_R_PRIV_GET_DISPNAME *r_u)
880 struct lsa_info *handle;
882 const char *description;
884 if (!find_policy_by_hnd(p, &q_u->pol, (void **)(void *)&handle))
885 return NT_STATUS_INVALID_HANDLE;
887 /* check if the user have enough rights */
890 * I don't know if it's the right one. not documented.
892 if (!(handle->access & POLICY_VIEW_LOCAL_INFORMATION))
893 return NT_STATUS_ACCESS_DENIED;
895 unistr2_to_ascii(name_asc, &q_u->name, sizeof(name_asc));
897 DEBUG(10,("_lsa_priv_get_dispname: name = %s\n", name_asc));
899 description = get_privilege_dispname( name_asc );
902 DEBUG(10,("_lsa_priv_get_dispname: display name = %s\n", description));
904 init_unistr2(&r_u->desc, description, UNI_FLAGS_NONE);
905 init_uni_hdr(&r_u->hdr_desc, &r_u->desc);
907 r_u->ptr_info = 0xdeadbeef;
908 r_u->lang_id = q_u->lang_id;
912 DEBUG(10,("_lsa_priv_get_dispname: doesn't exist\n"));
916 return NT_STATUS_NO_SUCH_PRIVILEGE;
920 /***************************************************************************
922 ***************************************************************************/
924 NTSTATUS _lsa_enum_accounts(pipes_struct *p, LSA_Q_ENUM_ACCOUNTS *q_u, LSA_R_ENUM_ACCOUNTS *r_u)
926 struct lsa_info *handle;
928 int i, j, num_entries;
929 LSA_SID_ENUM *sids=&r_u->sids;
932 if (!find_policy_by_hnd(p, &q_u->pol, (void **)(void *)&handle))
933 return NT_STATUS_INVALID_HANDLE;
935 if (!(handle->access & POLICY_VIEW_LOCAL_INFORMATION))
936 return NT_STATUS_ACCESS_DENIED;
941 /* The only way we can currently find out all the SIDs that have been
942 privileged is to scan all privileges */
944 if (!NT_STATUS_IS_OK(ret = privilege_enumerate_accounts(&sid_list, &num_entries))) {
948 if (q_u->enum_context >= num_entries)
949 return NT_STATUS_NO_MORE_ENTRIES;
951 sids->ptr_sid = TALLOC_ZERO_ARRAY(p->mem_ctx, uint32, num_entries-q_u->enum_context);
952 sids->sid = TALLOC_ZERO_ARRAY(p->mem_ctx, DOM_SID2, num_entries-q_u->enum_context);
954 if (sids->ptr_sid==NULL || sids->sid==NULL) {
956 return NT_STATUS_NO_MEMORY;
959 for (i = q_u->enum_context, j = 0; i < num_entries; i++, j++) {
960 init_dom_sid2(&(*sids).sid[j], &sid_list[i]);
961 (*sids).ptr_sid[j] = 1;
966 init_lsa_r_enum_accounts(r_u, num_entries);
972 NTSTATUS _lsa_unk_get_connuser(pipes_struct *p, LSA_Q_UNK_GET_CONNUSER *q_u, LSA_R_UNK_GET_CONNUSER *r_u)
974 fstring username, domname;
975 user_struct *vuser = get_valid_user_struct(p->vuid);
978 return NT_STATUS_CANT_ACCESS_DOMAIN_INFO;
980 fstrcpy(username, vuser->user.smb_name);
981 fstrcpy(domname, vuser->user.domain);
983 r_u->ptr_user_name = 1;
984 init_unistr2(&r_u->uni2_user_name, username, UNI_STR_TERMINATE);
985 init_uni_hdr(&r_u->hdr_user_name, &r_u->uni2_user_name);
989 r_u->ptr_dom_name = 1;
990 init_unistr2(&r_u->uni2_dom_name, domname, UNI_STR_TERMINATE);
991 init_uni_hdr(&r_u->hdr_dom_name, &r_u->uni2_dom_name);
993 r_u->status = NT_STATUS_OK;
998 /***************************************************************************
1000 ***************************************************************************/
1002 NTSTATUS _lsa_create_account(pipes_struct *p, LSA_Q_CREATEACCOUNT *q_u, LSA_R_CREATEACCOUNT *r_u)
1004 struct lsa_info *handle;
1005 struct lsa_info *info;
1007 /* find the connection policy handle. */
1008 if (!find_policy_by_hnd(p, &q_u->pol, (void **)(void *)&handle))
1009 return NT_STATUS_INVALID_HANDLE;
1011 /* check if the user have enough rights */
1014 * I don't know if it's the right one. not documented.
1015 * but guessed with rpcclient.
1017 if (!(handle->access & POLICY_GET_PRIVATE_INFORMATION))
1018 return NT_STATUS_ACCESS_DENIED;
1020 /* check to see if the pipe_user is a Domain Admin since
1021 account_pol.tdb was already opened as root, this is all we have */
1023 if ( !nt_token_check_domain_rid( p->pipe_user.nt_user_token, DOMAIN_GROUP_RID_ADMINS ) )
1024 return NT_STATUS_ACCESS_DENIED;
1026 if ( is_privileged_sid( &q_u->sid.sid ) )
1027 return NT_STATUS_OBJECT_NAME_COLLISION;
1029 /* associate the user/group SID with the (unique) handle. */
1031 if ((info = SMB_MALLOC_P(struct lsa_info)) == NULL)
1032 return NT_STATUS_NO_MEMORY;
1035 info->sid = q_u->sid.sid;
1036 info->access = q_u->access;
1038 /* get a (unique) handle. open a policy on it. */
1039 if (!create_policy_hnd(p, &r_u->pol, free_lsa_info, (void *)info))
1040 return NT_STATUS_OBJECT_NAME_NOT_FOUND;
1042 return privilege_create_account( &info->sid );
1046 /***************************************************************************
1048 ***************************************************************************/
1050 NTSTATUS _lsa_open_account(pipes_struct *p, LSA_Q_OPENACCOUNT *q_u, LSA_R_OPENACCOUNT *r_u)
1052 struct lsa_info *handle;
1053 struct lsa_info *info;
1055 /* find the connection policy handle. */
1056 if (!find_policy_by_hnd(p, &q_u->pol, (void **)(void *)&handle))
1057 return NT_STATUS_INVALID_HANDLE;
1059 /* check if the user have enough rights */
1062 * I don't know if it's the right one. not documented.
1063 * but guessed with rpcclient.
1065 if (!(handle->access & POLICY_GET_PRIVATE_INFORMATION))
1066 return NT_STATUS_ACCESS_DENIED;
1068 /* TODO: Fis the parsing routine before reenabling this check! */
1070 if (!lookup_sid(&handle->sid, dom_name, name, &type))
1071 return NT_STATUS_ACCESS_DENIED;
1073 /* associate the user/group SID with the (unique) handle. */
1074 if ((info = SMB_MALLOC_P(struct lsa_info)) == NULL)
1075 return NT_STATUS_NO_MEMORY;
1078 info->sid = q_u->sid.sid;
1079 info->access = q_u->access;
1081 /* get a (unique) handle. open a policy on it. */
1082 if (!create_policy_hnd(p, &r_u->pol, free_lsa_info, (void *)info))
1083 return NT_STATUS_OBJECT_NAME_NOT_FOUND;
1085 return NT_STATUS_OK;
1088 /***************************************************************************
1089 For a given SID, enumerate all the privilege this account has.
1090 ***************************************************************************/
1092 NTSTATUS _lsa_enum_privsaccount(pipes_struct *p, prs_struct *ps, LSA_Q_ENUMPRIVSACCOUNT *q_u, LSA_R_ENUMPRIVSACCOUNT *r_u)
1094 struct lsa_info *info=NULL;
1096 PRIVILEGE_SET privileges;
1098 /* find the connection policy handle. */
1099 if (!find_policy_by_hnd(p, &q_u->pol, (void **)(void *)&info))
1100 return NT_STATUS_INVALID_HANDLE;
1102 if ( !get_privileges_for_sids( &mask, &info->sid, 1 ) )
1103 return NT_STATUS_OBJECT_NAME_NOT_FOUND;
1105 privilege_set_init( &privileges );
1107 if ( se_priv_to_privilege_set( &privileges, &mask ) ) {
1109 DEBUG(10,("_lsa_enum_privsaccount: %s has %d privileges\n",
1110 sid_string_static(&info->sid), privileges.count));
1112 r_u->status = init_lsa_r_enum_privsaccount(ps->mem_ctx, r_u, privileges.set, privileges.count, 0);
1115 r_u->status = NT_STATUS_NO_SUCH_PRIVILEGE;
1117 privilege_set_free( &privileges );
1122 /***************************************************************************
1124 ***************************************************************************/
1126 NTSTATUS _lsa_getsystemaccount(pipes_struct *p, LSA_Q_GETSYSTEMACCOUNT *q_u, LSA_R_GETSYSTEMACCOUNT *r_u)
1128 struct lsa_info *info=NULL;
1130 /* find the connection policy handle. */
1132 if (!find_policy_by_hnd(p, &q_u->pol, (void **)(void *)&info))
1133 return NT_STATUS_INVALID_HANDLE;
1135 if (!lookup_sid(p->mem_ctx, &info->sid, NULL, NULL, NULL))
1136 return NT_STATUS_ACCESS_DENIED;
1139 0x01 -> Log on locally
1140 0x02 -> Access this computer from network
1141 0x04 -> Log on as a batch job
1142 0x10 -> Log on as a service
1144 they can be ORed together
1147 r_u->access = PR_LOG_ON_LOCALLY | PR_ACCESS_FROM_NETWORK;
1149 return NT_STATUS_OK;
1152 /***************************************************************************
1153 update the systemaccount information
1154 ***************************************************************************/
1156 NTSTATUS _lsa_setsystemaccount(pipes_struct *p, LSA_Q_SETSYSTEMACCOUNT *q_u, LSA_R_SETSYSTEMACCOUNT *r_u)
1158 struct lsa_info *info=NULL;
1160 r_u->status = NT_STATUS_OK;
1162 /* find the connection policy handle. */
1163 if (!find_policy_by_hnd(p, &q_u->pol, (void **)(void *)&info))
1164 return NT_STATUS_INVALID_HANDLE;
1166 /* check to see if the pipe_user is a Domain Admin since
1167 account_pol.tdb was already opened as root, this is all we have */
1169 if ( !nt_token_check_domain_rid( p->pipe_user.nt_user_token, DOMAIN_GROUP_RID_ADMINS ) )
1170 return NT_STATUS_ACCESS_DENIED;
1172 if (!pdb_getgrsid(&map, info->sid))
1173 return NT_STATUS_NO_SUCH_GROUP;
1175 if(!pdb_update_group_mapping_entry(&map))
1176 return NT_STATUS_NO_SUCH_GROUP;
1181 /***************************************************************************
1182 For a given SID, add some privileges.
1183 ***************************************************************************/
1185 NTSTATUS _lsa_addprivs(pipes_struct *p, LSA_Q_ADDPRIVS *q_u, LSA_R_ADDPRIVS *r_u)
1187 struct lsa_info *info = NULL;
1189 PRIVILEGE_SET *set = NULL;
1190 struct current_user user;
1192 /* find the connection policy handle. */
1193 if (!find_policy_by_hnd(p, &q_u->pol, (void **)(void *)&info))
1194 return NT_STATUS_INVALID_HANDLE;
1196 /* check to see if the pipe_user is root or a Domain Admin since
1197 account_pol.tdb was already opened as root, this is all we have */
1199 get_current_user( &user, p );
1200 if ( user.uid != sec_initial_uid()
1201 && !nt_token_check_domain_rid( p->pipe_user.nt_user_token, DOMAIN_GROUP_RID_ADMINS ) )
1203 return NT_STATUS_ACCESS_DENIED;
1208 if ( !privilege_set_to_se_priv( &mask, set ) )
1209 return NT_STATUS_NO_SUCH_PRIVILEGE;
1211 if ( !grant_privilege( &info->sid, &mask ) ) {
1212 DEBUG(3,("_lsa_addprivs: grant_privilege(%s) failed!\n",
1213 sid_string_static(&info->sid) ));
1214 DEBUG(3,("Privilege mask:\n"));
1215 dump_se_priv( DBGC_ALL, 3, &mask );
1216 return NT_STATUS_NO_SUCH_PRIVILEGE;
1219 return NT_STATUS_OK;
1222 /***************************************************************************
1223 For a given SID, remove some privileges.
1224 ***************************************************************************/
1226 NTSTATUS _lsa_removeprivs(pipes_struct *p, LSA_Q_REMOVEPRIVS *q_u, LSA_R_REMOVEPRIVS *r_u)
1228 struct lsa_info *info = NULL;
1230 PRIVILEGE_SET *set = NULL;
1231 struct current_user user;
1233 /* find the connection policy handle. */
1234 if (!find_policy_by_hnd(p, &q_u->pol, (void **)(void *)&info))
1235 return NT_STATUS_INVALID_HANDLE;
1237 /* check to see if the pipe_user is root or a Domain Admin since
1238 account_pol.tdb was already opened as root, this is all we have */
1240 get_current_user( &user, p );
1241 if ( user.uid != sec_initial_uid()
1242 && !nt_token_check_domain_rid( p->pipe_user.nt_user_token, DOMAIN_GROUP_RID_ADMINS ) )
1244 return NT_STATUS_ACCESS_DENIED;
1249 if ( !privilege_set_to_se_priv( &mask, set ) )
1250 return NT_STATUS_NO_SUCH_PRIVILEGE;
1252 if ( !revoke_privilege( &info->sid, &mask ) ) {
1253 DEBUG(3,("_lsa_removeprivs: revoke_privilege(%s) failed!\n",
1254 sid_string_static(&info->sid) ));
1255 DEBUG(3,("Privilege mask:\n"));
1256 dump_se_priv( DBGC_ALL, 3, &mask );
1257 return NT_STATUS_NO_SUCH_PRIVILEGE;
1260 return NT_STATUS_OK;
1263 /***************************************************************************
1264 For a given SID, remove some privileges.
1265 ***************************************************************************/
1267 NTSTATUS _lsa_query_secobj(pipes_struct *p, LSA_Q_QUERY_SEC_OBJ *q_u, LSA_R_QUERY_SEC_OBJ *r_u)
1269 struct lsa_info *handle=NULL;
1270 SEC_DESC *psd = NULL;
1274 r_u->status = NT_STATUS_OK;
1276 /* find the connection policy handle. */
1277 if (!find_policy_by_hnd(p, &q_u->pol, (void **)(void *)&handle))
1278 return NT_STATUS_INVALID_HANDLE;
1280 /* check if the user have enough rights */
1281 if (!(handle->access & POLICY_VIEW_LOCAL_INFORMATION))
1282 return NT_STATUS_ACCESS_DENIED;
1285 switch (q_u->sec_info) {
1287 /* SD contains only the owner */
1289 status=lsa_get_generic_sd(p->mem_ctx, &psd, &sd_size);
1290 if(!NT_STATUS_IS_OK(status))
1291 return NT_STATUS_NO_MEMORY;
1294 if((r_u->buf = make_sec_desc_buf(p->mem_ctx, sd_size, psd)) == NULL)
1295 return NT_STATUS_NO_MEMORY;
1298 /* SD contains only the ACL */
1300 status=lsa_get_generic_sd(p->mem_ctx, &psd, &sd_size);
1301 if(!NT_STATUS_IS_OK(status))
1302 return NT_STATUS_NO_MEMORY;
1304 if((r_u->buf = make_sec_desc_buf(p->mem_ctx, sd_size, psd)) == NULL)
1305 return NT_STATUS_NO_MEMORY;
1308 return NT_STATUS_INVALID_LEVEL;
1316 #if 0 /* AD DC work in ongoing in Samba 4 */
1318 /***************************************************************************
1319 ***************************************************************************/
1321 NTSTATUS _lsa_query_info2(pipes_struct *p, LSA_Q_QUERY_INFO2 *q_u, LSA_R_QUERY_INFO2 *r_u)
1323 struct lsa_info *handle;
1324 const char *nb_name;
1325 char *dns_name = NULL;
1326 char *forest_name = NULL;
1327 DOM_SID *sid = NULL;
1332 r_u->status = NT_STATUS_OK;
1334 if (!find_policy_by_hnd(p, &q_u->pol, (void **)(void *)&handle))
1335 return NT_STATUS_INVALID_HANDLE;
1337 switch (q_u->info_class) {
1339 /* check if the user have enough rights */
1340 if (!(handle->access & POLICY_VIEW_LOCAL_INFORMATION))
1341 return NT_STATUS_ACCESS_DENIED;
1343 /* Request PolicyPrimaryDomainInformation. */
1344 switch (lp_server_role()) {
1345 case ROLE_DOMAIN_PDC:
1346 case ROLE_DOMAIN_BDC:
1347 nb_name = get_global_sam_name();
1348 /* ugly temp hack for these next two */
1350 /* This should be a 'netbios domain -> DNS domain' mapping */
1351 dnsdomname[0] = '\0';
1352 get_mydnsdomname(dnsdomname);
1353 strlower_m(dnsdomname);
1355 dns_name = dnsdomname;
1356 forest_name = dnsdomname;
1358 sid = get_global_sam_sid();
1359 secrets_fetch_domain_guid(lp_workgroup(), &guid);
1362 return NT_STATUS_CANT_ACCESS_DOMAIN_INFO;
1364 init_dns_dom_info(&r_u->info.dns_dom_info, nb_name, dns_name,
1365 forest_name,&guid,sid);
1368 DEBUG(0,("_lsa_query_info2: unknown info level in Lsa Query: %d\n", q_u->info_class));
1369 r_u->status = NT_STATUS_INVALID_INFO_CLASS;
1373 if (NT_STATUS_IS_OK(r_u->status)) {
1375 r_u->info_class = q_u->info_class;
1380 #endif /* AD DC work in ongoing in Samba 4 */
1382 /***************************************************************************
1383 ***************************************************************************/
1385 NTSTATUS _lsa_add_acct_rights(pipes_struct *p, LSA_Q_ADD_ACCT_RIGHTS *q_u, LSA_R_ADD_ACCT_RIGHTS *r_u)
1387 struct lsa_info *info = NULL;
1391 UNISTR4_ARRAY *uni_privnames = q_u->rights;
1392 struct current_user user;
1395 /* find the connection policy handle. */
1396 if (!find_policy_by_hnd(p, &q_u->pol, (void **)(void *)&info))
1397 return NT_STATUS_INVALID_HANDLE;
1399 /* check to see if the pipe_user is a Domain Admin since
1400 account_pol.tdb was already opened as root, this is all we have */
1402 get_current_user( &user, p );
1403 if ( user.uid != sec_initial_uid()
1404 && !nt_token_check_domain_rid( p->pipe_user.nt_user_token, DOMAIN_GROUP_RID_ADMINS ) )
1406 return NT_STATUS_ACCESS_DENIED;
1409 /* according to an NT4 PDC, you can add privileges to SIDs even without
1410 call_lsa_create_account() first. And you can use any arbitrary SID. */
1412 sid_copy( &sid, &q_u->sid.sid );
1414 /* just a little sanity check */
1416 if ( q_u->count != uni_privnames->count ) {
1417 DEBUG(0,("_lsa_add_acct_rights: count != number of UNISTR2 elements!\n"));
1418 return NT_STATUS_INVALID_HANDLE;
1421 for ( i=0; i<q_u->count; i++ ) {
1422 UNISTR4 *uni4_str = &uni_privnames->strings[i];
1424 /* only try to add non-null strings */
1426 if ( !uni4_str->string )
1429 rpcstr_pull( privname, uni4_str->string->buffer, sizeof(privname), -1, STR_TERMINATE );
1431 if ( !grant_privilege_by_name( &sid, privname ) ) {
1432 DEBUG(2,("_lsa_add_acct_rights: Failed to add privilege [%s]\n", privname ));
1433 return NT_STATUS_NO_SUCH_PRIVILEGE;
1437 return NT_STATUS_OK;
1440 /***************************************************************************
1441 ***************************************************************************/
1443 NTSTATUS _lsa_remove_acct_rights(pipes_struct *p, LSA_Q_REMOVE_ACCT_RIGHTS *q_u, LSA_R_REMOVE_ACCT_RIGHTS *r_u)
1445 struct lsa_info *info = NULL;
1449 UNISTR4_ARRAY *uni_privnames = q_u->rights;
1450 struct current_user user;
1453 /* find the connection policy handle. */
1454 if (!find_policy_by_hnd(p, &q_u->pol, (void **)(void *)&info))
1455 return NT_STATUS_INVALID_HANDLE;
1457 /* check to see if the pipe_user is a Domain Admin since
1458 account_pol.tdb was already opened as root, this is all we have */
1460 get_current_user( &user, p );
1461 if ( user.uid != sec_initial_uid()
1462 && !nt_token_check_domain_rid( p->pipe_user.nt_user_token, DOMAIN_GROUP_RID_ADMINS ) )
1464 return NT_STATUS_ACCESS_DENIED;
1467 sid_copy( &sid, &q_u->sid.sid );
1469 if ( q_u->removeall ) {
1470 if ( !revoke_all_privileges( &sid ) )
1471 return NT_STATUS_ACCESS_DENIED;
1473 return NT_STATUS_OK;
1476 /* just a little sanity check */
1478 if ( q_u->count != uni_privnames->count ) {
1479 DEBUG(0,("_lsa_add_acct_rights: count != number of UNISTR2 elements!\n"));
1480 return NT_STATUS_INVALID_HANDLE;
1483 for ( i=0; i<q_u->count; i++ ) {
1484 UNISTR4 *uni4_str = &uni_privnames->strings[i];
1486 /* only try to add non-null strings */
1488 if ( !uni4_str->string )
1491 rpcstr_pull( privname, uni4_str->string->buffer, sizeof(privname), -1, STR_TERMINATE );
1493 if ( !revoke_privilege_by_name( &sid, privname ) ) {
1494 DEBUG(2,("_lsa_remove_acct_rights: Failed to revoke privilege [%s]\n", privname ));
1495 return NT_STATUS_NO_SUCH_PRIVILEGE;
1499 return NT_STATUS_OK;
1503 /***************************************************************************
1504 ***************************************************************************/
1506 NTSTATUS _lsa_enum_acct_rights(pipes_struct *p, LSA_Q_ENUM_ACCT_RIGHTS *q_u, LSA_R_ENUM_ACCT_RIGHTS *r_u)
1508 struct lsa_info *info = NULL;
1510 PRIVILEGE_SET privileges;
1514 /* find the connection policy handle. */
1516 if (!find_policy_by_hnd(p, &q_u->pol, (void **)(void *)&info))
1517 return NT_STATUS_INVALID_HANDLE;
1519 /* according to an NT4 PDC, you can add privileges to SIDs even without
1520 call_lsa_create_account() first. And you can use any arbitrary SID. */
1522 sid_copy( &sid, &q_u->sid.sid );
1524 if ( !get_privileges_for_sids( &mask, &sid, 1 ) )
1525 return NT_STATUS_OBJECT_NAME_NOT_FOUND;
1527 privilege_set_init( &privileges );
1529 if ( se_priv_to_privilege_set( &privileges, &mask ) ) {
1531 DEBUG(10,("_lsa_enum_acct_rights: %s has %d privileges\n",
1532 sid_string_static(&sid), privileges.count));
1534 r_u->status = init_r_enum_acct_rights( r_u, &privileges );
1537 r_u->status = NT_STATUS_NO_SUCH_PRIVILEGE;
1539 privilege_set_free( &privileges );
1545 /***************************************************************************
1546 ***************************************************************************/
1548 NTSTATUS _lsa_lookup_priv_value(pipes_struct *p, LSA_Q_LOOKUP_PRIV_VALUE *q_u, LSA_R_LOOKUP_PRIV_VALUE *r_u)
1550 struct lsa_info *info = NULL;
1552 LUID_ATTR priv_luid;
1555 /* find the connection policy handle. */
1557 if (!find_policy_by_hnd(p, &q_u->pol, (void **)(void *)&info))
1558 return NT_STATUS_INVALID_HANDLE;
1560 unistr2_to_ascii(name, &q_u->privname.unistring, sizeof(name));
1562 DEBUG(10,("_lsa_lookup_priv_value: name = %s\n", name));
1564 if ( !se_priv_from_name( name, &mask ) )
1565 return NT_STATUS_NO_SUCH_PRIVILEGE;
1567 priv_luid = get_privilege_luid( &mask );
1569 r_u->luid.low = priv_luid.luid.low;
1570 r_u->luid.high = priv_luid.luid.high;
1573 return NT_STATUS_OK;