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) Marc Jacobsen 1999,
8 * Copyright (C) Jeremy Allison 2001-2005,
9 * Copyright (C) Jean François Micouleau 1998-2001,
10 * Copyright (C) Jim McDonough <jmcd@us.ibm.com> 2002,
11 * Copyright (C) Gerald (Jerry) Carter 2003-2004,
12 * Copyright (C) Simo Sorce 2003.
13 * Copyright (C) Volker Lendecke 2005.
15 * This program is free software; you can redistribute it and/or modify
16 * it under the terms of the GNU General Public License as published by
17 * the Free Software Foundation; either version 3 of the License, or
18 * (at your option) any later version.
20 * This program is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
25 * You should have received a copy of the GNU General Public License
26 * along with this program; if not, see <http://www.gnu.org/licenses/>.
30 * This is the implementation of the SAMR code.
36 #define DBGC_CLASS DBGC_RPC_SRV
38 #define SAMR_USR_RIGHTS_WRITE_PW \
39 ( READ_CONTROL_ACCESS | \
40 SA_RIGHT_USER_CHANGE_PASSWORD | \
41 SA_RIGHT_USER_SET_LOC_COM )
42 #define SAMR_USR_RIGHTS_CANT_WRITE_PW \
43 ( READ_CONTROL_ACCESS | SA_RIGHT_USER_SET_LOC_COM )
45 #define DISP_INFO_CACHE_TIMEOUT 10
47 typedef struct disp_info {
48 DOM_SID sid; /* identify which domain this is. */
49 bool builtin_domain; /* Quick flag to check if this is the builtin domain. */
50 struct pdb_search *users; /* querydispinfo 1 and 4 */
51 struct pdb_search *machines; /* querydispinfo 2 */
52 struct pdb_search *groups; /* querydispinfo 3 and 5, enumgroups */
53 struct pdb_search *aliases; /* enumaliases */
56 struct pdb_search *enum_users; /* enumusers with a mask */
58 struct timed_event *cache_timeout_event; /* cache idle timeout
62 /* We keep a static list of these by SID as modern clients close down
63 all resources between each request in a complete enumeration. */
66 /* for use by the \PIPE\samr policy */
68 bool builtin_domain; /* Quick flag to check if this is the builtin domain. */
69 uint32 status; /* some sort of flag. best to record it. comes from opnum 0x39 */
75 static const struct generic_mapping sam_generic_mapping = {
76 GENERIC_RIGHTS_SAM_READ,
77 GENERIC_RIGHTS_SAM_WRITE,
78 GENERIC_RIGHTS_SAM_EXECUTE,
79 GENERIC_RIGHTS_SAM_ALL_ACCESS};
80 static const struct generic_mapping dom_generic_mapping = {
81 GENERIC_RIGHTS_DOMAIN_READ,
82 GENERIC_RIGHTS_DOMAIN_WRITE,
83 GENERIC_RIGHTS_DOMAIN_EXECUTE,
84 GENERIC_RIGHTS_DOMAIN_ALL_ACCESS};
85 static const struct generic_mapping usr_generic_mapping = {
86 GENERIC_RIGHTS_USER_READ,
87 GENERIC_RIGHTS_USER_WRITE,
88 GENERIC_RIGHTS_USER_EXECUTE,
89 GENERIC_RIGHTS_USER_ALL_ACCESS};
90 static const struct generic_mapping usr_nopwchange_generic_mapping = {
91 GENERIC_RIGHTS_USER_READ,
92 GENERIC_RIGHTS_USER_WRITE,
93 GENERIC_RIGHTS_USER_EXECUTE & ~SA_RIGHT_USER_CHANGE_PASSWORD,
94 GENERIC_RIGHTS_USER_ALL_ACCESS};
95 static const struct generic_mapping grp_generic_mapping = {
96 GENERIC_RIGHTS_GROUP_READ,
97 GENERIC_RIGHTS_GROUP_WRITE,
98 GENERIC_RIGHTS_GROUP_EXECUTE,
99 GENERIC_RIGHTS_GROUP_ALL_ACCESS};
100 static const struct generic_mapping ali_generic_mapping = {
101 GENERIC_RIGHTS_ALIAS_READ,
102 GENERIC_RIGHTS_ALIAS_WRITE,
103 GENERIC_RIGHTS_ALIAS_EXECUTE,
104 GENERIC_RIGHTS_ALIAS_ALL_ACCESS};
106 /*******************************************************************
107 *******************************************************************/
109 static NTSTATUS make_samr_object_sd( TALLOC_CTX *ctx, SEC_DESC **psd, size_t *sd_size,
110 const struct generic_mapping *map,
111 DOM_SID *sid, uint32 sid_access )
113 DOM_SID domadmin_sid;
114 SEC_ACE ace[5]; /* at most 5 entries */
120 /* basic access for Everyone */
122 init_sec_access(&mask, map->generic_execute | map->generic_read );
123 init_sec_ace(&ace[i++], &global_sid_World, SEC_ACE_TYPE_ACCESS_ALLOWED, mask, 0);
125 /* add Full Access 'BUILTIN\Administrators' and 'BUILTIN\Account Operators */
127 init_sec_access(&mask, map->generic_all);
129 init_sec_ace(&ace[i++], &global_sid_Builtin_Administrators, SEC_ACE_TYPE_ACCESS_ALLOWED, mask, 0);
130 init_sec_ace(&ace[i++], &global_sid_Builtin_Account_Operators, SEC_ACE_TYPE_ACCESS_ALLOWED, mask, 0);
132 /* Add Full Access for Domain Admins if we are a DC */
135 sid_copy( &domadmin_sid, get_global_sam_sid() );
136 sid_append_rid( &domadmin_sid, DOMAIN_GROUP_RID_ADMINS );
137 init_sec_ace(&ace[i++], &domadmin_sid, SEC_ACE_TYPE_ACCESS_ALLOWED, mask, 0);
140 /* if we have a sid, give it some special access */
143 init_sec_access( &mask, sid_access );
144 init_sec_ace(&ace[i++], sid, SEC_ACE_TYPE_ACCESS_ALLOWED, mask, 0);
147 /* create the security descriptor */
149 if ((psa = make_sec_acl(ctx, NT4_ACL_REVISION, i, ace)) == NULL)
150 return NT_STATUS_NO_MEMORY;
152 if ((*psd = make_sec_desc(ctx, SECURITY_DESCRIPTOR_REVISION_1,
153 SEC_DESC_SELF_RELATIVE, NULL, NULL, NULL,
154 psa, sd_size)) == NULL)
155 return NT_STATUS_NO_MEMORY;
160 /*******************************************************************
161 Checks if access to an object should be granted, and returns that
162 level of access for further checks.
163 ********************************************************************/
165 static NTSTATUS access_check_samr_object( SEC_DESC *psd, NT_USER_TOKEN *token,
166 SE_PRIV *rights, uint32 rights_mask,
167 uint32 des_access, uint32 *acc_granted,
170 NTSTATUS status = NT_STATUS_ACCESS_DENIED;
171 uint32 saved_mask = 0;
173 /* check privileges; certain SAM access bits should be overridden
174 by privileges (mostly having to do with creating/modifying/deleting
177 if ( rights && user_has_any_privilege( token, rights ) ) {
179 saved_mask = (des_access & rights_mask);
180 des_access &= ~saved_mask;
182 DEBUG(4,("access_check_samr_object: user rights access mask [0x%x]\n",
187 /* check the security descriptor first */
189 if ( se_access_check(psd, token, des_access, acc_granted, &status) )
192 /* give root a free pass */
194 if ( geteuid() == sec_initial_uid() ) {
196 DEBUG(4,("%s: ACCESS should be DENIED (requested: %#010x)\n", debug, des_access));
197 DEBUGADD(4,("but overritten by euid == sec_initial_uid()\n"));
199 *acc_granted = des_access;
201 status = NT_STATUS_OK;
207 /* add in any bits saved during the privilege check (only
208 matters is status is ok) */
210 *acc_granted |= rights_mask;
212 DEBUG(4,("%s: access %s (requested: 0x%08x, granted: 0x%08x)\n",
213 debug, NT_STATUS_IS_OK(status) ? "GRANTED" : "DENIED",
214 des_access, *acc_granted));
219 /*******************************************************************
220 Checks if access to a function can be granted
221 ********************************************************************/
223 static NTSTATUS access_check_samr_function(uint32 acc_granted, uint32 acc_required, const char *debug)
225 DEBUG(5,("%s: access check ((granted: %#010x; required: %#010x)\n",
226 debug, acc_granted, acc_required));
228 /* check the security descriptor first */
230 if ( (acc_granted&acc_required) == acc_required )
233 /* give root a free pass */
235 if (geteuid() == sec_initial_uid()) {
237 DEBUG(4,("%s: ACCESS should be DENIED (granted: %#010x; required: %#010x)\n",
238 debug, acc_granted, acc_required));
239 DEBUGADD(4,("but overwritten by euid == 0\n"));
244 DEBUG(2,("%s: ACCESS DENIED (granted: %#010x; required: %#010x)\n",
245 debug, acc_granted, acc_required));
247 return NT_STATUS_ACCESS_DENIED;
250 /*******************************************************************
251 Fetch or create a dispinfo struct.
252 ********************************************************************/
254 static DISP_INFO *get_samr_dispinfo_by_sid(DOM_SID *psid)
257 * We do a static cache for DISP_INFO's here. Explanation can be found
258 * in Jeremy's checkin message to r11793:
260 * Fix the SAMR cache so it works across completely insane
261 * client behaviour (ie.:
262 * open pipe/open SAMR handle/enumerate 0 - 1024
263 * close SAMR handle, close pipe.
264 * open pipe/open SAMR handle/enumerate 1024 - 2048...
265 * close SAMR handle, close pipe.
266 * And on ad-nausium. Amazing.... probably object-oriented
267 * client side programming in action yet again.
268 * This change should *massively* improve performance when
269 * enumerating users from an LDAP database.
272 * "Our" and the builtin domain are the only ones where we ever
273 * enumerate stuff, so just cache 2 entries.
276 static struct disp_info builtin_dispinfo;
277 static struct disp_info domain_dispinfo;
279 /* There are two cases to consider here:
280 1) The SID is a domain SID and we look for an equality match, or
281 2) This is an account SID and so we return the DISP_INFO* for our
288 if (sid_check_is_builtin(psid) || sid_check_is_in_builtin(psid)) {
290 * Necessary only once, but it does not really hurt.
292 sid_copy(&builtin_dispinfo.sid, &global_sid_Builtin);
294 return &builtin_dispinfo;
297 if (sid_check_is_domain(psid) || sid_check_is_in_our_domain(psid)) {
299 * Necessary only once, but it does not really hurt.
301 sid_copy(&domain_dispinfo.sid, get_global_sam_sid());
303 return &domain_dispinfo;
309 /*******************************************************************
310 Create a samr_info struct.
311 ********************************************************************/
313 static struct samr_info *get_samr_info_by_sid(DOM_SID *psid)
315 struct samr_info *info;
320 sid_to_fstring(sid_str, psid);
322 fstrcpy(sid_str,"(NULL)");
325 mem_ctx = talloc_init("samr_info for domain sid %s", sid_str);
327 if ((info = TALLOC_ZERO_P(mem_ctx, struct samr_info)) == NULL)
330 DEBUG(10,("get_samr_info_by_sid: created new info for sid %s\n", sid_str));
332 sid_copy( &info->sid, psid);
333 info->builtin_domain = sid_check_is_builtin(psid);
335 DEBUG(10,("get_samr_info_by_sid: created new info for NULL sid.\n"));
336 info->builtin_domain = False;
338 info->mem_ctx = mem_ctx;
340 info->disp_info = get_samr_dispinfo_by_sid(psid);
345 /*******************************************************************
346 Function to free the per SID data.
347 ********************************************************************/
349 static void free_samr_cache(DISP_INFO *disp_info)
351 DEBUG(10, ("free_samr_cache: deleting cache for SID %s\n",
352 sid_string_dbg(&disp_info->sid)));
354 /* We need to become root here because the paged search might have to
355 * tell the LDAP server we're not interested in the rest anymore. */
359 if (disp_info->users) {
360 DEBUG(10,("free_samr_cache: deleting users cache\n"));
361 pdb_search_destroy(disp_info->users);
362 disp_info->users = NULL;
364 if (disp_info->machines) {
365 DEBUG(10,("free_samr_cache: deleting machines cache\n"));
366 pdb_search_destroy(disp_info->machines);
367 disp_info->machines = NULL;
369 if (disp_info->groups) {
370 DEBUG(10,("free_samr_cache: deleting groups cache\n"));
371 pdb_search_destroy(disp_info->groups);
372 disp_info->groups = NULL;
374 if (disp_info->aliases) {
375 DEBUG(10,("free_samr_cache: deleting aliases cache\n"));
376 pdb_search_destroy(disp_info->aliases);
377 disp_info->aliases = NULL;
379 if (disp_info->enum_users) {
380 DEBUG(10,("free_samr_cache: deleting enum_users cache\n"));
381 pdb_search_destroy(disp_info->enum_users);
382 disp_info->enum_users = NULL;
384 disp_info->enum_acb_mask = 0;
389 /*******************************************************************
390 Function to free the per handle data.
391 ********************************************************************/
393 static void free_samr_info(void *ptr)
395 struct samr_info *info=(struct samr_info *) ptr;
397 /* Only free the dispinfo cache if no one bothered to set up
400 if (info->disp_info && info->disp_info->cache_timeout_event == NULL) {
401 free_samr_cache(info->disp_info);
404 talloc_destroy(info->mem_ctx);
407 /*******************************************************************
408 Idle event handler. Throw away the disp info cache.
409 ********************************************************************/
411 static void disp_info_cache_idle_timeout_handler(struct event_context *ev_ctx,
412 struct timed_event *te,
413 const struct timeval *now,
416 DISP_INFO *disp_info = (DISP_INFO *)private_data;
418 TALLOC_FREE(disp_info->cache_timeout_event);
420 DEBUG(10, ("disp_info_cache_idle_timeout_handler: caching timed "
422 free_samr_cache(disp_info);
425 /*******************************************************************
426 Setup cache removal idle event handler.
427 ********************************************************************/
429 static void set_disp_info_cache_timeout(DISP_INFO *disp_info, time_t secs_fromnow)
431 /* Remove any pending timeout and update. */
433 TALLOC_FREE(disp_info->cache_timeout_event);
435 DEBUG(10,("set_disp_info_cache_timeout: caching enumeration for "
436 "SID %s for %u seconds\n", sid_string_dbg(&disp_info->sid),
437 (unsigned int)secs_fromnow ));
439 disp_info->cache_timeout_event = event_add_timed(
440 smbd_event_context(), NULL,
441 timeval_current_ofs(secs_fromnow, 0),
442 "disp_info_cache_idle_timeout_handler",
443 disp_info_cache_idle_timeout_handler, (void *)disp_info);
446 /*******************************************************************
447 Force flush any cache. We do this on any samr_set_xxx call.
448 We must also remove the timeout handler.
449 ********************************************************************/
451 static void force_flush_samr_cache(DISP_INFO *disp_info)
453 if ((disp_info == NULL) || (disp_info->cache_timeout_event == NULL)) {
457 DEBUG(10,("force_flush_samr_cache: clearing idle event\n"));
458 TALLOC_FREE(disp_info->cache_timeout_event);
459 free_samr_cache(disp_info);
462 /*******************************************************************
463 Ensure password info is never given out. Paranioa... JRA.
464 ********************************************************************/
466 static void samr_clear_sam_passwd(struct samu *sam_pass)
472 /* These now zero out the old password */
474 pdb_set_lanman_passwd(sam_pass, NULL, PDB_DEFAULT);
475 pdb_set_nt_passwd(sam_pass, NULL, PDB_DEFAULT);
478 static uint32 count_sam_users(struct disp_info *info, uint32 acct_flags)
480 struct samr_displayentry *entry;
482 if (info->builtin_domain) {
483 /* No users in builtin. */
487 if (info->users == NULL) {
488 info->users = pdb_search_users(acct_flags);
489 if (info->users == NULL) {
493 /* Fetch the last possible entry, thus trigger an enumeration */
494 pdb_search_entries(info->users, 0xffffffff, 1, &entry);
496 /* Ensure we cache this enumeration. */
497 set_disp_info_cache_timeout(info, DISP_INFO_CACHE_TIMEOUT);
499 return info->users->num_entries;
502 static uint32 count_sam_groups(struct disp_info *info)
504 struct samr_displayentry *entry;
506 if (info->builtin_domain) {
507 /* No groups in builtin. */
511 if (info->groups == NULL) {
512 info->groups = pdb_search_groups();
513 if (info->groups == NULL) {
517 /* Fetch the last possible entry, thus trigger an enumeration */
518 pdb_search_entries(info->groups, 0xffffffff, 1, &entry);
520 /* Ensure we cache this enumeration. */
521 set_disp_info_cache_timeout(info, DISP_INFO_CACHE_TIMEOUT);
523 return info->groups->num_entries;
526 static uint32 count_sam_aliases(struct disp_info *info)
528 struct samr_displayentry *entry;
530 if (info->aliases == NULL) {
531 info->aliases = pdb_search_aliases(&info->sid);
532 if (info->aliases == NULL) {
536 /* Fetch the last possible entry, thus trigger an enumeration */
537 pdb_search_entries(info->aliases, 0xffffffff, 1, &entry);
539 /* Ensure we cache this enumeration. */
540 set_disp_info_cache_timeout(info, DISP_INFO_CACHE_TIMEOUT);
542 return info->aliases->num_entries;
545 /*******************************************************************
547 ********************************************************************/
549 NTSTATUS _samr_Close(pipes_struct *p, struct samr_Close *r)
551 if (!close_policy_hnd(p, r->in.handle)) {
552 return NT_STATUS_INVALID_HANDLE;
555 ZERO_STRUCTP(r->out.handle);
560 /*******************************************************************
562 ********************************************************************/
564 NTSTATUS _samr_OpenDomain(pipes_struct *p,
565 struct samr_OpenDomain *r)
567 struct samr_info *info;
568 SEC_DESC *psd = NULL;
570 uint32 des_access = r->in.access_mask;
575 /* find the connection policy handle. */
577 if ( !find_policy_by_hnd(p, r->in.connect_handle, (void**)(void *)&info) )
578 return NT_STATUS_INVALID_HANDLE;
580 status = access_check_samr_function( info->acc_granted,
581 SA_RIGHT_SAM_OPEN_DOMAIN, "_samr_OpenDomain" );
583 if ( !NT_STATUS_IS_OK(status) )
586 /*check if access can be granted as requested by client. */
588 make_samr_object_sd( p->mem_ctx, &psd, &sd_size, &dom_generic_mapping, NULL, 0 );
589 se_map_generic( &des_access, &dom_generic_mapping );
591 se_priv_copy( &se_rights, &se_machine_account );
592 se_priv_add( &se_rights, &se_add_users );
594 status = access_check_samr_object( psd, p->pipe_user.nt_user_token,
595 &se_rights, GENERIC_RIGHTS_DOMAIN_WRITE, des_access,
596 &acc_granted, "_samr_OpenDomain" );
598 if ( !NT_STATUS_IS_OK(status) )
601 if (!sid_check_is_domain(r->in.sid) &&
602 !sid_check_is_builtin(r->in.sid)) {
603 return NT_STATUS_NO_SUCH_DOMAIN;
606 /* associate the domain SID with the (unique) handle. */
607 if ((info = get_samr_info_by_sid(r->in.sid))==NULL)
608 return NT_STATUS_NO_MEMORY;
609 info->acc_granted = acc_granted;
611 /* get a (unique) handle. open a policy on it. */
612 if (!create_policy_hnd(p, r->out.domain_handle, free_samr_info, (void *)info))
613 return NT_STATUS_OBJECT_NAME_NOT_FOUND;
615 DEBUG(5,("_samr_OpenDomain: %d\n", __LINE__));
620 /*******************************************************************
621 _samr_get_usrdom_pwinfo
622 ********************************************************************/
624 NTSTATUS _samr_get_usrdom_pwinfo(pipes_struct *p, SAMR_Q_GET_USRDOM_PWINFO *q_u, SAMR_R_GET_USRDOM_PWINFO *r_u)
626 struct samr_info *info = NULL;
628 r_u->status = NT_STATUS_OK;
630 /* find the policy handle. open a policy on it. */
631 if (!find_policy_by_hnd(p, &q_u->user_pol, (void **)(void *)&info))
632 return NT_STATUS_INVALID_HANDLE;
634 if (!sid_check_is_in_our_domain(&info->sid))
635 return NT_STATUS_OBJECT_TYPE_MISMATCH;
637 init_samr_r_get_usrdom_pwinfo(r_u, NT_STATUS_OK);
639 DEBUG(5,("_samr_get_usrdom_pwinfo: %d\n", __LINE__));
642 * NT sometimes return NT_STATUS_ACCESS_DENIED
643 * I don't know yet why.
649 /*******************************************************************
650 ********************************************************************/
652 static bool get_lsa_policy_samr_sid( pipes_struct *p, POLICY_HND *pol,
653 DOM_SID *sid, uint32 *acc_granted,
654 DISP_INFO **ppdisp_info)
656 struct samr_info *info = NULL;
658 /* find the policy handle. open a policy on it. */
659 if (!find_policy_by_hnd(p, pol, (void **)(void *)&info))
666 *acc_granted = info->acc_granted;
668 *ppdisp_info = info->disp_info;
674 /*******************************************************************
676 ********************************************************************/
678 NTSTATUS _samr_set_sec_obj(pipes_struct *p, SAMR_Q_SET_SEC_OBJ *q_u, SAMR_R_SET_SEC_OBJ *r_u)
681 uint32 acc_granted, i;
684 struct samu *sampass=NULL;
687 r_u->status = NT_STATUS_OK;
689 if (!get_lsa_policy_samr_sid(p, &q_u->pol, &pol_sid, &acc_granted, NULL))
690 return NT_STATUS_INVALID_HANDLE;
692 if (!(sampass = samu_new( p->mem_ctx))) {
693 DEBUG(0,("No memory!\n"));
694 return NT_STATUS_NO_MEMORY;
697 /* get the user record */
699 ret = pdb_getsampwsid(sampass, &pol_sid);
703 DEBUG(4, ("User %s not found\n", sid_string_dbg(&pol_sid)));
704 TALLOC_FREE(sampass);
705 return NT_STATUS_INVALID_HANDLE;
708 dacl = q_u->buf->sd->dacl;
709 for (i=0; i < dacl->num_aces; i++) {
710 if (sid_equal(&pol_sid, &dacl->aces[i].trustee)) {
711 ret = pdb_set_pass_can_change(sampass,
712 (dacl->aces[i].access_mask &
713 SA_RIGHT_USER_CHANGE_PASSWORD) ?
720 TALLOC_FREE(sampass);
721 return NT_STATUS_ACCESS_DENIED;
724 status = access_check_samr_function(acc_granted, SA_RIGHT_USER_SET_ATTRIBUTES, "_samr_set_sec_obj");
725 if (NT_STATUS_IS_OK(status)) {
727 status = pdb_update_sam_account(sampass);
731 TALLOC_FREE(sampass);
736 /*******************************************************************
737 build correct perms based on policies and password times for _samr_query_sec_obj
738 *******************************************************************/
739 static bool check_change_pw_access(TALLOC_CTX *mem_ctx, DOM_SID *user_sid)
741 struct samu *sampass=NULL;
744 if ( !(sampass = samu_new( mem_ctx )) ) {
745 DEBUG(0,("No memory!\n"));
750 ret = pdb_getsampwsid(sampass, user_sid);
754 DEBUG(4,("User %s not found\n", sid_string_dbg(user_sid)));
755 TALLOC_FREE(sampass);
759 DEBUG(3,("User:[%s]\n", pdb_get_username(sampass) ));
761 if (pdb_get_pass_can_change(sampass)) {
762 TALLOC_FREE(sampass);
765 TALLOC_FREE(sampass);
770 /*******************************************************************
772 ********************************************************************/
774 NTSTATUS _samr_query_sec_obj(pipes_struct *p, SAMR_Q_QUERY_SEC_OBJ *q_u, SAMR_R_QUERY_SEC_OBJ *r_u)
777 SEC_DESC * psd = NULL;
781 r_u->status = NT_STATUS_OK;
784 if (!get_lsa_policy_samr_sid(p, &q_u->user_pol, &pol_sid, &acc_granted, NULL))
785 return NT_STATUS_INVALID_HANDLE;
787 DEBUG(10,("_samr_query_sec_obj: querying security on SID: %s\n",
788 sid_string_dbg(&pol_sid)));
790 /* Check what typ of SID is beeing queried (e.g Domain SID, User SID, Group SID) */
792 /* To query the security of the SAM it self an invalid SID with S-0-0 is passed to this function */
793 if (pol_sid.sid_rev_num == 0) {
794 DEBUG(5,("_samr_query_sec_obj: querying security on SAM\n"));
795 r_u->status = make_samr_object_sd(p->mem_ctx, &psd, &sd_size, &sam_generic_mapping, NULL, 0);
796 } else if (sid_equal(&pol_sid,get_global_sam_sid())) {
797 /* check if it is our domain SID */
798 DEBUG(5,("_samr_query_sec_obj: querying security on Domain "
799 "with SID: %s\n", sid_string_dbg(&pol_sid)));
800 r_u->status = make_samr_object_sd(p->mem_ctx, &psd, &sd_size, &dom_generic_mapping, NULL, 0);
801 } else if (sid_equal(&pol_sid,&global_sid_Builtin)) {
802 /* check if it is the Builtin Domain */
803 /* TODO: Builtin probably needs a different SD with restricted write access*/
804 DEBUG(5,("_samr_query_sec_obj: querying security on Builtin "
805 "Domain with SID: %s\n", sid_string_dbg(&pol_sid)));
806 r_u->status = make_samr_object_sd(p->mem_ctx, &psd, &sd_size, &dom_generic_mapping, NULL, 0);
807 } else if (sid_check_is_in_our_domain(&pol_sid) ||
808 sid_check_is_in_builtin(&pol_sid)) {
809 /* TODO: different SDs have to be generated for aliases groups and users.
810 Currently all three get a default user SD */
811 DEBUG(10,("_samr_query_sec_obj: querying security on Object "
812 "with SID: %s\n", sid_string_dbg(&pol_sid)));
813 if (check_change_pw_access(p->mem_ctx, &pol_sid)) {
814 r_u->status = make_samr_object_sd(p->mem_ctx, &psd, &sd_size, &usr_generic_mapping,
815 &pol_sid, SAMR_USR_RIGHTS_WRITE_PW);
817 r_u->status = make_samr_object_sd(p->mem_ctx, &psd, &sd_size, &usr_nopwchange_generic_mapping,
818 &pol_sid, SAMR_USR_RIGHTS_CANT_WRITE_PW);
821 return NT_STATUS_OBJECT_TYPE_MISMATCH;
824 if ((r_u->buf = make_sec_desc_buf(p->mem_ctx, sd_size, psd)) == NULL)
825 return NT_STATUS_NO_MEMORY;
827 if (NT_STATUS_IS_OK(r_u->status))
833 /*******************************************************************
834 makes a SAM_ENTRY / UNISTR2* structure from a user list.
835 ********************************************************************/
837 static NTSTATUS make_user_sam_entry_list(TALLOC_CTX *ctx, SAM_ENTRY **sam_pp,
838 UNISTR2 **uni_name_pp,
839 uint32 num_entries, uint32 start_idx,
840 struct samr_displayentry *entries)
849 if (num_entries == 0)
852 sam = TALLOC_ZERO_ARRAY(ctx, SAM_ENTRY, num_entries);
854 uni_name = TALLOC_ZERO_ARRAY(ctx, UNISTR2, num_entries);
856 if (sam == NULL || uni_name == NULL) {
857 DEBUG(0, ("make_user_sam_entry_list: TALLOC_ZERO failed!\n"));
858 return NT_STATUS_NO_MEMORY;
861 for (i = 0; i < num_entries; i++) {
862 UNISTR2 uni_temp_name;
864 * usrmgr expects a non-NULL terminated string with
865 * trust relationships
867 if (entries[i].acct_flags & ACB_DOMTRUST) {
868 init_unistr2(&uni_temp_name, entries[i].account_name,
871 init_unistr2(&uni_temp_name, entries[i].account_name,
875 init_sam_entry(&sam[i], &uni_temp_name, entries[i].rid);
876 copy_unistr2(&uni_name[i], &uni_temp_name);
880 *uni_name_pp = uni_name;
884 /*******************************************************************
885 samr_reply_enum_dom_users
886 ********************************************************************/
888 NTSTATUS _samr_enum_dom_users(pipes_struct *p, SAMR_Q_ENUM_DOM_USERS *q_u,
889 SAMR_R_ENUM_DOM_USERS *r_u)
891 struct samr_info *info = NULL;
893 uint32 enum_context=q_u->start_idx;
894 enum remote_arch_types ra_type = get_remote_arch();
895 int max_sam_entries = (ra_type == RA_WIN95) ? MAX_SAM_ENTRIES_W95 : MAX_SAM_ENTRIES_W2K;
896 uint32 max_entries = max_sam_entries;
897 struct samr_displayentry *entries = NULL;
899 r_u->status = NT_STATUS_OK;
901 /* find the policy handle. open a policy on it. */
902 if (!find_policy_by_hnd(p, &q_u->pol, (void **)(void *)&info))
903 return NT_STATUS_INVALID_HANDLE;
905 if (!NT_STATUS_IS_OK(r_u->status = access_check_samr_function(info->acc_granted,
906 SA_RIGHT_DOMAIN_ENUM_ACCOUNTS,
907 "_samr_enum_dom_users"))) {
911 DEBUG(5,("_samr_enum_dom_users: %d\n", __LINE__));
913 if (info->builtin_domain) {
914 /* No users in builtin. */
915 init_samr_r_enum_dom_users(r_u, q_u->start_idx, 0);
916 DEBUG(5,("_samr_enum_dom_users: No users in BUILTIN\n"));
924 if ((info->disp_info->enum_users != NULL) &&
925 (info->disp_info->enum_acb_mask != q_u->acb_mask)) {
926 pdb_search_destroy(info->disp_info->enum_users);
927 info->disp_info->enum_users = NULL;
930 if (info->disp_info->enum_users == NULL) {
931 info->disp_info->enum_users = pdb_search_users(q_u->acb_mask);
932 info->disp_info->enum_acb_mask = q_u->acb_mask;
935 if (info->disp_info->enum_users == NULL) {
936 /* END AS ROOT !!!! */
938 return NT_STATUS_ACCESS_DENIED;
941 num_account = pdb_search_entries(info->disp_info->enum_users,
942 enum_context, max_entries,
945 /* END AS ROOT !!!! */
949 if (num_account == 0) {
950 DEBUG(5, ("_samr_enum_dom_users: enumeration handle over "
952 init_samr_r_enum_dom_users(r_u, q_u->start_idx, 0);
956 r_u->status = make_user_sam_entry_list(p->mem_ctx, &r_u->sam,
958 num_account, enum_context,
961 if (!NT_STATUS_IS_OK(r_u->status))
964 if (max_entries <= num_account) {
965 r_u->status = STATUS_MORE_ENTRIES;
967 r_u->status = NT_STATUS_OK;
970 /* Ensure we cache this enumeration. */
971 set_disp_info_cache_timeout(info->disp_info, DISP_INFO_CACHE_TIMEOUT);
973 DEBUG(5, ("_samr_enum_dom_users: %d\n", __LINE__));
975 init_samr_r_enum_dom_users(r_u, q_u->start_idx + num_account,
978 DEBUG(5,("_samr_enum_dom_users: %d\n", __LINE__));
983 /*******************************************************************
984 makes a SAM_ENTRY / UNISTR2* structure from a group list.
985 ********************************************************************/
987 static void make_group_sam_entry_list(TALLOC_CTX *ctx, SAM_ENTRY **sam_pp,
988 UNISTR2 **uni_name_pp,
989 uint32 num_sam_entries,
990 struct samr_displayentry *entries)
999 if (num_sam_entries == 0)
1002 sam = TALLOC_ZERO_ARRAY(ctx, SAM_ENTRY, num_sam_entries);
1003 uni_name = TALLOC_ZERO_ARRAY(ctx, UNISTR2, num_sam_entries);
1005 if (sam == NULL || uni_name == NULL) {
1006 DEBUG(0, ("NULL pointers in SAMR_R_QUERY_DISPINFO\n"));
1010 for (i = 0; i < num_sam_entries; i++) {
1012 * JRA. I think this should include the null. TNG does not.
1014 init_unistr2(&uni_name[i], entries[i].account_name,
1016 init_sam_entry(&sam[i], &uni_name[i], entries[i].rid);
1020 *uni_name_pp = uni_name;
1023 /*******************************************************************
1024 samr_reply_enum_dom_groups
1025 ********************************************************************/
1027 NTSTATUS _samr_enum_dom_groups(pipes_struct *p, SAMR_Q_ENUM_DOM_GROUPS *q_u, SAMR_R_ENUM_DOM_GROUPS *r_u)
1029 struct samr_info *info = NULL;
1030 struct samr_displayentry *groups;
1033 r_u->status = NT_STATUS_OK;
1035 /* find the policy handle. open a policy on it. */
1036 if (!find_policy_by_hnd(p, &q_u->pol, (void **)(void *)&info))
1037 return NT_STATUS_INVALID_HANDLE;
1039 r_u->status = access_check_samr_function(info->acc_granted,
1040 SA_RIGHT_DOMAIN_ENUM_ACCOUNTS,
1041 "_samr_enum_dom_groups");
1042 if (!NT_STATUS_IS_OK(r_u->status))
1045 DEBUG(5,("samr_reply_enum_dom_groups: %d\n", __LINE__));
1047 if (info->builtin_domain) {
1048 /* No groups in builtin. */
1049 init_samr_r_enum_dom_groups(r_u, q_u->start_idx, 0);
1050 DEBUG(5,("_samr_enum_dom_users: No groups in BUILTIN\n"));
1054 /* the domain group array is being allocated in the function below */
1058 if (info->disp_info->groups == NULL) {
1059 info->disp_info->groups = pdb_search_groups();
1061 if (info->disp_info->groups == NULL) {
1063 return NT_STATUS_ACCESS_DENIED;
1067 num_groups = pdb_search_entries(info->disp_info->groups, q_u->start_idx,
1068 MAX_SAM_ENTRIES, &groups);
1071 /* Ensure we cache this enumeration. */
1072 set_disp_info_cache_timeout(info->disp_info, DISP_INFO_CACHE_TIMEOUT);
1074 make_group_sam_entry_list(p->mem_ctx, &r_u->sam, &r_u->uni_grp_name,
1075 num_groups, groups);
1077 init_samr_r_enum_dom_groups(r_u, q_u->start_idx, num_groups);
1079 DEBUG(5,("samr_enum_dom_groups: %d\n", __LINE__));
1084 /*******************************************************************
1085 samr_reply_enum_dom_aliases
1086 ********************************************************************/
1088 NTSTATUS _samr_enum_dom_aliases(pipes_struct *p, SAMR_Q_ENUM_DOM_ALIASES *q_u, SAMR_R_ENUM_DOM_ALIASES *r_u)
1090 struct samr_info *info;
1091 struct samr_displayentry *aliases;
1092 uint32 num_aliases = 0;
1094 /* find the policy handle. open a policy on it. */
1095 if (!find_policy_by_hnd(p, &q_u->pol, (void **)(void *)&info))
1096 return NT_STATUS_INVALID_HANDLE;
1098 r_u->status = access_check_samr_function(info->acc_granted,
1099 SA_RIGHT_DOMAIN_ENUM_ACCOUNTS,
1100 "_samr_enum_dom_aliases");
1101 if (!NT_STATUS_IS_OK(r_u->status))
1104 DEBUG(5,("samr_reply_enum_dom_aliases: sid %s\n",
1105 sid_string_dbg(&info->sid)));
1109 if (info->disp_info->aliases == NULL) {
1110 info->disp_info->aliases = pdb_search_aliases(&info->sid);
1111 if (info->disp_info->aliases == NULL) {
1113 return NT_STATUS_ACCESS_DENIED;
1117 num_aliases = pdb_search_entries(info->disp_info->aliases, q_u->start_idx,
1118 MAX_SAM_ENTRIES, &aliases);
1121 /* Ensure we cache this enumeration. */
1122 set_disp_info_cache_timeout(info->disp_info, DISP_INFO_CACHE_TIMEOUT);
1124 make_group_sam_entry_list(p->mem_ctx, &r_u->sam, &r_u->uni_grp_name,
1125 num_aliases, aliases);
1127 init_samr_r_enum_dom_aliases(r_u, q_u->start_idx + num_aliases,
1130 DEBUG(5,("samr_enum_dom_aliases: %d\n", __LINE__));
1135 /*******************************************************************
1136 samr_reply_query_dispinfo
1137 ********************************************************************/
1139 NTSTATUS _samr_query_dispinfo(pipes_struct *p, SAMR_Q_QUERY_DISPINFO *q_u,
1140 SAMR_R_QUERY_DISPINFO *r_u)
1142 struct samr_info *info = NULL;
1143 uint32 struct_size=0x20; /* W2K always reply that, client doesn't care */
1145 uint32 max_entries=q_u->max_entries;
1146 uint32 enum_context=q_u->start_idx;
1147 uint32 max_size=q_u->max_size;
1149 SAM_DISPINFO_CTR *ctr;
1150 uint32 temp_size=0, total_data_size=0;
1151 NTSTATUS disp_ret = NT_STATUS_UNSUCCESSFUL;
1152 uint32 num_account = 0;
1153 enum remote_arch_types ra_type = get_remote_arch();
1154 int max_sam_entries = (ra_type == RA_WIN95) ? MAX_SAM_ENTRIES_W95 : MAX_SAM_ENTRIES_W2K;
1155 struct samr_displayentry *entries = NULL;
1157 DEBUG(5, ("samr_reply_query_dispinfo: %d\n", __LINE__));
1158 r_u->status = NT_STATUS_UNSUCCESSFUL;
1160 /* find the policy handle. open a policy on it. */
1161 if (!find_policy_by_hnd(p, &q_u->domain_pol, (void **)(void *)&info))
1162 return NT_STATUS_INVALID_HANDLE;
1165 * calculate how many entries we will return.
1167 * - the number of entries the client asked
1168 * - our limit on that
1169 * - the starting point (enumeration context)
1170 * - the buffer size the client will accept
1174 * We are a lot more like W2K. Instead of reading the SAM
1175 * each time to find the records we need to send back,
1176 * we read it once and link that copy to the sam handle.
1177 * For large user list (over the MAX_SAM_ENTRIES)
1178 * it's a definitive win.
1179 * second point to notice: between enumerations
1180 * our sam is now the same as it's a snapshoot.
1181 * third point: got rid of the static SAM_USER_21 struct
1182 * no more intermediate.
1183 * con: it uses much more memory, as a full copy is stored
1186 * If you want to change it, think twice and think
1187 * of the second point , that's really important.
1192 if ((q_u->switch_level < 1) || (q_u->switch_level > 5)) {
1193 DEBUG(0,("_samr_query_dispinfo: Unknown info level (%u)\n",
1194 (unsigned int)q_u->switch_level ));
1195 return NT_STATUS_INVALID_INFO_CLASS;
1198 /* first limit the number of entries we will return */
1199 if(max_entries > max_sam_entries) {
1200 DEBUG(5, ("samr_reply_query_dispinfo: client requested %d "
1201 "entries, limiting to %d\n", max_entries,
1203 max_entries = max_sam_entries;
1206 /* calculate the size and limit on the number of entries we will
1209 temp_size=max_entries*struct_size;
1211 if (temp_size>max_size) {
1212 max_entries=MIN((max_size/struct_size),max_entries);;
1213 DEBUG(5, ("samr_reply_query_dispinfo: buffer size limits to "
1214 "only %d entries\n", max_entries));
1217 if (!(ctr = TALLOC_ZERO_P(p->mem_ctx,SAM_DISPINFO_CTR)))
1218 return NT_STATUS_NO_MEMORY;
1224 /* THe following done as ROOT. Don't return without unbecome_root(). */
1226 switch (q_u->switch_level) {
1229 if (info->disp_info->users == NULL) {
1230 info->disp_info->users = pdb_search_users(ACB_NORMAL);
1231 if (info->disp_info->users == NULL) {
1233 return NT_STATUS_ACCESS_DENIED;
1235 DEBUG(10,("samr_reply_query_dispinfo: starting user enumeration at index %u\n",
1236 (unsigned int)enum_context ));
1238 DEBUG(10,("samr_reply_query_dispinfo: using cached user enumeration at index %u\n",
1239 (unsigned int)enum_context ));
1242 num_account = pdb_search_entries(info->disp_info->users,
1243 enum_context, max_entries,
1247 if (info->disp_info->machines == NULL) {
1248 info->disp_info->machines =
1249 pdb_search_users(ACB_WSTRUST|ACB_SVRTRUST);
1250 if (info->disp_info->machines == NULL) {
1252 return NT_STATUS_ACCESS_DENIED;
1254 DEBUG(10,("samr_reply_query_dispinfo: starting machine enumeration at index %u\n",
1255 (unsigned int)enum_context ));
1257 DEBUG(10,("samr_reply_query_dispinfo: using cached machine enumeration at index %u\n",
1258 (unsigned int)enum_context ));
1261 num_account = pdb_search_entries(info->disp_info->machines,
1262 enum_context, max_entries,
1267 if (info->disp_info->groups == NULL) {
1268 info->disp_info->groups = pdb_search_groups();
1269 if (info->disp_info->groups == NULL) {
1271 return NT_STATUS_ACCESS_DENIED;
1273 DEBUG(10,("samr_reply_query_dispinfo: starting group enumeration at index %u\n",
1274 (unsigned int)enum_context ));
1276 DEBUG(10,("samr_reply_query_dispinfo: using cached group enumeration at index %u\n",
1277 (unsigned int)enum_context ));
1280 num_account = pdb_search_entries(info->disp_info->groups,
1281 enum_context, max_entries,
1286 smb_panic("info class changed");
1291 /* Now create reply structure */
1292 switch (q_u->switch_level) {
1294 disp_ret = init_sam_dispinfo_1(p->mem_ctx, &ctr->sam.info1,
1295 num_account, enum_context,
1299 disp_ret = init_sam_dispinfo_2(p->mem_ctx, &ctr->sam.info2,
1300 num_account, enum_context,
1304 disp_ret = init_sam_dispinfo_3(p->mem_ctx, &ctr->sam.info3,
1305 num_account, enum_context,
1309 disp_ret = init_sam_dispinfo_4(p->mem_ctx, &ctr->sam.info4,
1310 num_account, enum_context,
1314 disp_ret = init_sam_dispinfo_5(p->mem_ctx, &ctr->sam.info5,
1315 num_account, enum_context,
1319 smb_panic("info class changed");
1323 if (!NT_STATUS_IS_OK(disp_ret))
1326 /* calculate the total size */
1327 total_data_size=num_account*struct_size;
1330 r_u->status = STATUS_MORE_ENTRIES;
1332 r_u->status = NT_STATUS_OK;
1335 /* Ensure we cache this enumeration. */
1336 set_disp_info_cache_timeout(info->disp_info, DISP_INFO_CACHE_TIMEOUT);
1338 DEBUG(5, ("_samr_query_dispinfo: %d\n", __LINE__));
1340 init_samr_r_query_dispinfo(r_u, num_account, total_data_size,
1341 temp_size, q_u->switch_level, ctr,
1348 /*******************************************************************
1349 samr_reply_query_aliasinfo
1350 ********************************************************************/
1352 NTSTATUS _samr_query_aliasinfo(pipes_struct *p, SAMR_Q_QUERY_ALIASINFO *q_u, SAMR_R_QUERY_ALIASINFO *r_u)
1355 struct acct_info info;
1359 r_u->status = NT_STATUS_OK;
1361 DEBUG(5,("_samr_query_aliasinfo: %d\n", __LINE__));
1363 /* find the policy handle. open a policy on it. */
1364 if (!get_lsa_policy_samr_sid(p, &q_u->pol, &sid, &acc_granted, NULL))
1365 return NT_STATUS_INVALID_HANDLE;
1366 if (!NT_STATUS_IS_OK(r_u->status = access_check_samr_function(acc_granted, SA_RIGHT_ALIAS_LOOKUP_INFO, "_samr_query_aliasinfo"))) {
1371 status = pdb_get_aliasinfo(&sid, &info);
1374 if ( !NT_STATUS_IS_OK(status))
1377 if ( !(r_u->ctr = TALLOC_ZERO_P( p->mem_ctx, ALIAS_INFO_CTR )) )
1378 return NT_STATUS_NO_MEMORY;
1381 switch (q_u->level ) {
1383 r_u->ctr->level = 1;
1384 init_samr_alias_info1(&r_u->ctr->alias.info1, info.acct_name, 1, info.acct_desc);
1387 r_u->ctr->level = 3;
1388 init_samr_alias_info3(&r_u->ctr->alias.info3, info.acct_desc);
1391 return NT_STATUS_INVALID_INFO_CLASS;
1394 DEBUG(5,("_samr_query_aliasinfo: %d\n", __LINE__));
1400 /*******************************************************************
1401 samr_reply_lookup_ids
1402 ********************************************************************/
1404 uint32 _samr_lookup_ids(pipes_struct *p, SAMR_Q_LOOKUP_IDS *q_u, SAMR_R_LOOKUP_IDS *r_u)
1406 uint32 rid[MAX_SAM_ENTRIES];
1407 int num_rids = q_u->num_sids1;
1409 r_u->status = NT_STATUS_OK;
1411 DEBUG(5,("_samr_lookup_ids: %d\n", __LINE__));
1413 if (num_rids > MAX_SAM_ENTRIES) {
1414 num_rids = MAX_SAM_ENTRIES;
1415 DEBUG(5,("_samr_lookup_ids: truncating entries to %d\n", num_rids));
1420 SMB_ASSERT_ARRAY(q_u->uni_user_name, num_rids);
1422 for (i = 0; i < num_rids && status == 0; i++)
1424 struct sam_passwd *sam_pass;
1428 fstrcpy(user_name, unistrn2(q_u->uni_user_name[i].buffer,
1429 q_u->uni_user_name[i].uni_str_len));
1431 /* find the user account */
1433 sam_pass = get_smb21pwd_entry(user_name, 0);
1436 if (sam_pass == NULL)
1438 status = 0xC0000000 | NT_STATUS_NO_SUCH_USER;
1443 rid[i] = sam_pass->user_rid;
1449 rid[0] = BUILTIN_ALIAS_RID_USERS;
1451 init_samr_r_lookup_ids(&r_u, num_rids, rid, NT_STATUS_OK);
1453 DEBUG(5,("_samr_lookup_ids: %d\n", __LINE__));
1459 /*******************************************************************
1461 ********************************************************************/
1463 NTSTATUS _samr_lookup_names(pipes_struct *p, SAMR_Q_LOOKUP_NAMES *q_u, SAMR_R_LOOKUP_NAMES *r_u)
1465 uint32 rid[MAX_SAM_ENTRIES];
1466 enum lsa_SidType type[MAX_SAM_ENTRIES];
1468 int num_rids = q_u->num_names2;
1472 r_u->status = NT_STATUS_OK;
1474 DEBUG(5,("_samr_lookup_names: %d\n", __LINE__));
1479 if (!get_lsa_policy_samr_sid(p, &q_u->pol, &pol_sid, &acc_granted, NULL)) {
1480 init_samr_r_lookup_names(p->mem_ctx, r_u, 0, NULL, NULL, NT_STATUS_OBJECT_TYPE_MISMATCH);
1484 if (!NT_STATUS_IS_OK(r_u->status = access_check_samr_function(acc_granted, 0, "_samr_lookup_names"))) { /* Don't know the acc_bits yet */
1488 if (num_rids > MAX_SAM_ENTRIES) {
1489 num_rids = MAX_SAM_ENTRIES;
1490 DEBUG(5,("_samr_lookup_names: truncating entries to %d\n", num_rids));
1493 DEBUG(5,("_samr_lookup_names: looking name on SID %s\n",
1494 sid_string_dbg(&pol_sid)));
1496 for (i = 0; i < num_rids; i++) {
1500 r_u->status = NT_STATUS_NONE_MAPPED;
1501 type[i] = SID_NAME_UNKNOWN;
1503 rid [i] = 0xffffffff;
1505 ret = rpcstr_pull(name, q_u->uni_name[i].buffer, sizeof(name), q_u->uni_name[i].uni_str_len*2, 0);
1511 if (sid_check_is_builtin(&pol_sid)) {
1512 if (lookup_builtin_name(name, &rid[i])) {
1513 type[i] = SID_NAME_ALIAS;
1516 lookup_global_sam_name(name, 0, &rid[i], &type[i]);
1519 if (type[i] != SID_NAME_UNKNOWN) {
1520 r_u->status = NT_STATUS_OK;
1524 init_samr_r_lookup_names(p->mem_ctx, r_u, num_rids, rid, type, r_u->status);
1526 DEBUG(5,("_samr_lookup_names: %d\n", __LINE__));
1531 /*******************************************************************
1532 _samr_chgpasswd_user
1533 ********************************************************************/
1535 NTSTATUS _samr_chgpasswd_user(pipes_struct *p, SAMR_Q_CHGPASSWD_USER *q_u, SAMR_R_CHGPASSWD_USER *r_u)
1540 DEBUG(5,("_samr_chgpasswd_user: %d\n", __LINE__));
1542 r_u->status = NT_STATUS_OK;
1544 rpcstr_pull(user_name, q_u->uni_user_name.buffer, sizeof(user_name), q_u->uni_user_name.uni_str_len*2, 0);
1545 rpcstr_pull(wks, q_u->uni_dest_host.buffer, sizeof(wks), q_u->uni_dest_host.uni_str_len*2,0);
1547 DEBUG(5,("samr_chgpasswd_user: user: %s wks: %s\n", user_name, wks));
1550 * Pass the user through the NT -> unix user mapping
1554 (void)map_username(user_name);
1557 * UNIX username case mangling not required, pass_oem_change
1558 * is case insensitive.
1561 r_u->status = pass_oem_change(user_name, q_u->lm_newpass.pass, q_u->lm_oldhash.hash,
1562 q_u->nt_newpass.pass, q_u->nt_oldhash.hash, NULL);
1564 init_samr_r_chgpasswd_user(r_u, r_u->status);
1566 DEBUG(5,("_samr_chgpasswd_user: %d\n", __LINE__));
1571 /*******************************************************************
1572 _samr_chgpasswd_user3
1573 ********************************************************************/
1575 NTSTATUS _samr_chgpasswd_user3(pipes_struct *p, SAMR_Q_CHGPASSWD_USER3 *q_u, SAMR_R_CHGPASSWD_USER3 *r_u)
1579 uint32 reject_reason;
1580 SAM_UNK_INFO_1 *info = NULL;
1581 SAMR_CHANGE_REJECT *reject = NULL;
1583 DEBUG(5,("_samr_chgpasswd_user3: %d\n", __LINE__));
1585 rpcstr_pull(user_name, q_u->uni_user_name.buffer, sizeof(user_name), q_u->uni_user_name.uni_str_len*2, 0);
1586 rpcstr_pull(wks, q_u->uni_dest_host.buffer, sizeof(wks), q_u->uni_dest_host.uni_str_len*2,0);
1588 DEBUG(5,("_samr_chgpasswd_user3: user: %s wks: %s\n", user_name, wks));
1591 * Pass the user through the NT -> unix user mapping
1595 (void)map_username(user_name);
1598 * UNIX username case mangling not required, pass_oem_change
1599 * is case insensitive.
1602 r_u->status = pass_oem_change(user_name, q_u->lm_newpass.pass, q_u->lm_oldhash.hash,
1603 q_u->nt_newpass.pass, q_u->nt_oldhash.hash, &reject_reason);
1605 if (NT_STATUS_EQUAL(r_u->status, NT_STATUS_PASSWORD_RESTRICTION) ||
1606 NT_STATUS_EQUAL(r_u->status, NT_STATUS_ACCOUNT_RESTRICTION)) {
1608 uint32 min_pass_len,pass_hist,password_properties;
1609 time_t u_expire, u_min_age;
1610 NTTIME nt_expire, nt_min_age;
1611 uint32 account_policy_temp;
1613 if ((info = TALLOC_ZERO_P(p->mem_ctx, SAM_UNK_INFO_1)) == NULL) {
1614 return NT_STATUS_NO_MEMORY;
1617 if ((reject = TALLOC_ZERO_P(p->mem_ctx, SAMR_CHANGE_REJECT)) == NULL) {
1618 return NT_STATUS_NO_MEMORY;
1622 ZERO_STRUCTP(reject);
1628 pdb_get_account_policy(AP_MIN_PASSWORD_LEN, &account_policy_temp);
1629 min_pass_len = account_policy_temp;
1631 pdb_get_account_policy(AP_PASSWORD_HISTORY, &account_policy_temp);
1632 pass_hist = account_policy_temp;
1634 pdb_get_account_policy(AP_USER_MUST_LOGON_TO_CHG_PASS, &account_policy_temp);
1635 password_properties = account_policy_temp;
1637 pdb_get_account_policy(AP_MAX_PASSWORD_AGE, &account_policy_temp);
1638 u_expire = account_policy_temp;
1640 pdb_get_account_policy(AP_MIN_PASSWORD_AGE, &account_policy_temp);
1641 u_min_age = account_policy_temp;
1647 unix_to_nt_time_abs(&nt_expire, u_expire);
1648 unix_to_nt_time_abs(&nt_min_age, u_min_age);
1650 init_unk_info1(info, (uint16)min_pass_len, (uint16)pass_hist,
1651 password_properties, nt_expire, nt_min_age);
1653 reject->reject_reason = reject_reason;
1656 init_samr_r_chgpasswd_user3(r_u, r_u->status, reject, info);
1658 DEBUG(5,("_samr_chgpasswd_user3: %d\n", __LINE__));
1663 /*******************************************************************
1664 makes a SAMR_R_LOOKUP_RIDS structure.
1665 ********************************************************************/
1667 static bool make_samr_lookup_rids(TALLOC_CTX *ctx, uint32 num_names,
1668 const char **names, UNIHDR **pp_hdr_name,
1669 UNISTR2 **pp_uni_name)
1672 UNIHDR *hdr_name=NULL;
1673 UNISTR2 *uni_name=NULL;
1675 *pp_uni_name = NULL;
1676 *pp_hdr_name = NULL;
1678 if (num_names != 0) {
1679 hdr_name = TALLOC_ZERO_ARRAY(ctx, UNIHDR, num_names);
1680 if (hdr_name == NULL)
1683 uni_name = TALLOC_ZERO_ARRAY(ctx,UNISTR2, num_names);
1684 if (uni_name == NULL)
1688 for (i = 0; i < num_names; i++) {
1689 DEBUG(10, ("names[%d]:%s\n", i, names[i] && *names[i] ? names[i] : ""));
1690 init_unistr2(&uni_name[i], names[i], UNI_FLAGS_NONE);
1691 init_uni_hdr(&hdr_name[i], &uni_name[i]);
1694 *pp_uni_name = uni_name;
1695 *pp_hdr_name = hdr_name;
1700 /*******************************************************************
1702 ********************************************************************/
1704 NTSTATUS _samr_lookup_rids(pipes_struct *p, SAMR_Q_LOOKUP_RIDS *q_u, SAMR_R_LOOKUP_RIDS *r_u)
1707 enum lsa_SidType *attrs = NULL;
1708 uint32 *wire_attrs = NULL;
1709 UNIHDR *hdr_name = NULL;
1710 UNISTR2 *uni_name = NULL;
1712 int num_rids = (int)q_u->num_rids1;
1716 r_u->status = NT_STATUS_OK;
1718 DEBUG(5,("_samr_lookup_rids: %d\n", __LINE__));
1720 /* find the policy handle. open a policy on it. */
1721 if (!get_lsa_policy_samr_sid(p, &q_u->pol, &pol_sid, &acc_granted, NULL))
1722 return NT_STATUS_INVALID_HANDLE;
1724 if (num_rids > 1000) {
1725 DEBUG(0, ("Got asked for %d rids (more than 1000) -- according "
1726 "to samba4 idl this is not possible\n", num_rids));
1727 return NT_STATUS_UNSUCCESSFUL;
1731 names = TALLOC_ZERO_ARRAY(p->mem_ctx, const char *, num_rids);
1732 attrs = TALLOC_ZERO_ARRAY(p->mem_ctx, enum lsa_SidType, num_rids);
1733 wire_attrs = TALLOC_ZERO_ARRAY(p->mem_ctx, uint32, num_rids);
1735 if ((names == NULL) || (attrs == NULL) || (wire_attrs==NULL))
1736 return NT_STATUS_NO_MEMORY;
1743 become_root(); /* lookup_sid can require root privs */
1744 r_u->status = pdb_lookup_rids(&pol_sid, num_rids, q_u->rid,
1748 if ( NT_STATUS_EQUAL(r_u->status, NT_STATUS_NONE_MAPPED) && (num_rids == 0) ) {
1749 r_u->status = NT_STATUS_OK;
1752 if(!make_samr_lookup_rids(p->mem_ctx, num_rids, names,
1753 &hdr_name, &uni_name))
1754 return NT_STATUS_NO_MEMORY;
1756 /* Convert from enum lsa_SidType to uint32 for wire format. */
1757 for (i = 0; i < num_rids; i++) {
1758 wire_attrs[i] = (uint32)attrs[i];
1761 init_samr_r_lookup_rids(r_u, num_rids, hdr_name, uni_name, wire_attrs);
1763 DEBUG(5,("_samr_lookup_rids: %d\n", __LINE__));
1768 /*******************************************************************
1770 ********************************************************************/
1772 NTSTATUS _samr_OpenUser(pipes_struct *p,
1773 struct samr_OpenUser *r)
1775 struct samu *sampass=NULL;
1777 POLICY_HND domain_pol = *r->in.domain_handle;
1778 POLICY_HND *user_pol = r->out.user_handle;
1779 struct samr_info *info = NULL;
1780 SEC_DESC *psd = NULL;
1782 uint32 des_access = r->in.access_mask;
1788 /* find the domain policy handle and get domain SID / access bits in the domain policy. */
1790 if ( !get_lsa_policy_samr_sid(p, &domain_pol, &sid, &acc_granted, NULL) )
1791 return NT_STATUS_INVALID_HANDLE;
1793 nt_status = access_check_samr_function( acc_granted,
1794 SA_RIGHT_DOMAIN_OPEN_ACCOUNT, "_samr_OpenUser" );
1796 if ( !NT_STATUS_IS_OK(nt_status) )
1799 if ( !(sampass = samu_new( p->mem_ctx )) ) {
1800 return NT_STATUS_NO_MEMORY;
1803 /* append the user's RID to it */
1805 if (!sid_append_rid(&sid, r->in.rid))
1806 return NT_STATUS_NO_SUCH_USER;
1808 /* check if access can be granted as requested by client. */
1810 make_samr_object_sd(p->mem_ctx, &psd, &sd_size, &usr_generic_mapping, &sid, SAMR_USR_RIGHTS_WRITE_PW);
1811 se_map_generic(&des_access, &usr_generic_mapping);
1813 se_priv_copy( &se_rights, &se_machine_account );
1814 se_priv_add( &se_rights, &se_add_users );
1816 nt_status = access_check_samr_object(psd, p->pipe_user.nt_user_token,
1817 &se_rights, GENERIC_RIGHTS_USER_WRITE, des_access,
1818 &acc_granted, "_samr_OpenUser");
1820 if ( !NT_STATUS_IS_OK(nt_status) )
1824 ret=pdb_getsampwsid(sampass, &sid);
1827 /* check that the SID exists in our domain. */
1829 return NT_STATUS_NO_SUCH_USER;
1832 TALLOC_FREE(sampass);
1834 /* associate the user's SID and access bits with the new handle. */
1835 if ((info = get_samr_info_by_sid(&sid)) == NULL)
1836 return NT_STATUS_NO_MEMORY;
1837 info->acc_granted = acc_granted;
1839 /* get a (unique) handle. open a policy on it. */
1840 if (!create_policy_hnd(p, user_pol, free_samr_info, (void *)info))
1841 return NT_STATUS_OBJECT_NAME_NOT_FOUND;
1843 return NT_STATUS_OK;
1846 /*************************************************************************
1847 get_user_info_7. Safe. Only gives out account_name.
1848 *************************************************************************/
1850 static NTSTATUS get_user_info_7(TALLOC_CTX *mem_ctx, SAM_USER_INFO_7 *id7, DOM_SID *user_sid)
1852 struct samu *smbpass=NULL;
1855 if ( !(smbpass = samu_new( mem_ctx )) ) {
1856 return NT_STATUS_NO_MEMORY;
1860 ret = pdb_getsampwsid(smbpass, user_sid);
1864 DEBUG(4,("User %s not found\n", sid_string_dbg(user_sid)));
1865 return NT_STATUS_NO_SUCH_USER;
1868 DEBUG(3,("User:[%s]\n", pdb_get_username(smbpass) ));
1871 init_sam_user_info7(id7, pdb_get_username(smbpass) );
1873 TALLOC_FREE(smbpass);
1875 return NT_STATUS_OK;
1878 /*************************************************************************
1879 get_user_info_9. Only gives out primary group SID.
1880 *************************************************************************/
1881 static NTSTATUS get_user_info_9(TALLOC_CTX *mem_ctx, SAM_USER_INFO_9 * id9, DOM_SID *user_sid)
1883 struct samu *smbpass=NULL;
1886 if ( !(smbpass = samu_new( mem_ctx )) ) {
1887 return NT_STATUS_NO_MEMORY;
1891 ret = pdb_getsampwsid(smbpass, user_sid);
1895 DEBUG(4,("User %s not found\n", sid_string_dbg(user_sid)));
1896 return NT_STATUS_NO_SUCH_USER;
1899 DEBUG(3,("User:[%s]\n", pdb_get_username(smbpass) ));
1902 init_sam_user_info9(id9, pdb_get_group_rid(smbpass) );
1904 TALLOC_FREE(smbpass);
1906 return NT_STATUS_OK;
1909 /*************************************************************************
1910 get_user_info_16. Safe. Only gives out acb bits.
1911 *************************************************************************/
1913 static NTSTATUS get_user_info_16(TALLOC_CTX *mem_ctx, SAM_USER_INFO_16 *id16, DOM_SID *user_sid)
1915 struct samu *smbpass=NULL;
1918 if ( !(smbpass = samu_new( mem_ctx )) ) {
1919 return NT_STATUS_NO_MEMORY;
1923 ret = pdb_getsampwsid(smbpass, user_sid);
1927 DEBUG(4,("User %s not found\n", sid_string_dbg(user_sid)));
1928 return NT_STATUS_NO_SUCH_USER;
1931 DEBUG(3,("User:[%s]\n", pdb_get_username(smbpass) ));
1934 init_sam_user_info16(id16, pdb_get_acct_ctrl(smbpass) );
1936 TALLOC_FREE(smbpass);
1938 return NT_STATUS_OK;
1941 /*************************************************************************
1942 get_user_info_18. OK - this is the killer as it gives out password info.
1943 Ensure that this is only allowed on an encrypted connection with a root
1945 *************************************************************************/
1947 static NTSTATUS get_user_info_18(pipes_struct *p, TALLOC_CTX *mem_ctx, SAM_USER_INFO_18 * id18, DOM_SID *user_sid)
1949 struct samu *smbpass=NULL;
1952 if (p->auth.auth_type != PIPE_AUTH_TYPE_NTLMSSP || p->auth.auth_type != PIPE_AUTH_TYPE_SPNEGO_NTLMSSP) {
1953 return NT_STATUS_ACCESS_DENIED;
1956 if (p->auth.auth_level != PIPE_AUTH_LEVEL_PRIVACY) {
1957 return NT_STATUS_ACCESS_DENIED;
1961 * Do *NOT* do become_root()/unbecome_root() here ! JRA.
1964 if ( !(smbpass = samu_new( mem_ctx )) ) {
1965 return NT_STATUS_NO_MEMORY;
1968 ret = pdb_getsampwsid(smbpass, user_sid);
1971 DEBUG(4, ("User %s not found\n", sid_string_dbg(user_sid)));
1972 TALLOC_FREE(smbpass);
1973 return (geteuid() == (uid_t)0) ? NT_STATUS_NO_SUCH_USER : NT_STATUS_ACCESS_DENIED;
1976 DEBUG(3,("User:[%s] 0x%x\n", pdb_get_username(smbpass), pdb_get_acct_ctrl(smbpass) ));
1978 if ( pdb_get_acct_ctrl(smbpass) & ACB_DISABLED) {
1979 TALLOC_FREE(smbpass);
1980 return NT_STATUS_ACCOUNT_DISABLED;
1984 init_sam_user_info18(id18, pdb_get_lanman_passwd(smbpass), pdb_get_nt_passwd(smbpass));
1986 TALLOC_FREE(smbpass);
1988 return NT_STATUS_OK;
1991 /*************************************************************************
1993 *************************************************************************/
1995 static NTSTATUS get_user_info_20(TALLOC_CTX *mem_ctx, SAM_USER_INFO_20 *id20, DOM_SID *user_sid)
1997 struct samu *sampass=NULL;
2000 if ( !(sampass = samu_new( mem_ctx )) ) {
2001 return NT_STATUS_NO_MEMORY;
2005 ret = pdb_getsampwsid(sampass, user_sid);
2009 DEBUG(4,("User %s not found\n", sid_string_dbg(user_sid)));
2010 return NT_STATUS_NO_SUCH_USER;
2013 samr_clear_sam_passwd(sampass);
2015 DEBUG(3,("User:[%s]\n", pdb_get_username(sampass) ));
2018 init_sam_user_info20A(id20, sampass);
2020 TALLOC_FREE(sampass);
2022 return NT_STATUS_OK;
2025 /*************************************************************************
2027 *************************************************************************/
2029 static NTSTATUS get_user_info_21(TALLOC_CTX *mem_ctx, SAM_USER_INFO_21 *id21,
2030 DOM_SID *user_sid, DOM_SID *domain_sid)
2032 struct samu *sampass=NULL;
2036 if ( !(sampass = samu_new( mem_ctx )) ) {
2037 return NT_STATUS_NO_MEMORY;
2041 ret = pdb_getsampwsid(sampass, user_sid);
2045 DEBUG(4,("User %s not found\n", sid_string_dbg(user_sid)));
2046 return NT_STATUS_NO_SUCH_USER;
2049 samr_clear_sam_passwd(sampass);
2051 DEBUG(3,("User:[%s]\n", pdb_get_username(sampass) ));
2054 nt_status = init_sam_user_info21A(id21, sampass, domain_sid);
2056 TALLOC_FREE(sampass);
2061 /*******************************************************************
2062 _samr_query_userinfo
2063 ********************************************************************/
2065 NTSTATUS _samr_query_userinfo(pipes_struct *p, SAMR_Q_QUERY_USERINFO *q_u, SAMR_R_QUERY_USERINFO *r_u)
2067 SAM_USERINFO_CTR *ctr;
2068 struct samr_info *info = NULL;
2072 r_u->status=NT_STATUS_OK;
2074 /* search for the handle */
2075 if (!find_policy_by_hnd(p, &q_u->pol, (void **)(void *)&info))
2076 return NT_STATUS_INVALID_HANDLE;
2078 domain_sid = info->sid;
2080 sid_split_rid(&domain_sid, &rid);
2082 if (!sid_check_is_in_our_domain(&info->sid))
2083 return NT_STATUS_OBJECT_TYPE_MISMATCH;
2085 DEBUG(5,("_samr_query_userinfo: sid:%s\n",
2086 sid_string_dbg(&info->sid)));
2088 ctr = TALLOC_ZERO_P(p->mem_ctx, SAM_USERINFO_CTR);
2090 return NT_STATUS_NO_MEMORY;
2094 /* ok! user info levels (lots: see MSDEV help), off we go... */
2095 ctr->switch_value = q_u->switch_value;
2097 DEBUG(5,("_samr_query_userinfo: user info level: %d\n", q_u->switch_value));
2099 switch (q_u->switch_value) {
2101 ctr->info.id7 = TALLOC_ZERO_P(p->mem_ctx, SAM_USER_INFO_7);
2102 if (ctr->info.id7 == NULL)
2103 return NT_STATUS_NO_MEMORY;
2105 if (!NT_STATUS_IS_OK(r_u->status = get_user_info_7(p->mem_ctx, ctr->info.id7, &info->sid)))
2109 ctr->info.id9 = TALLOC_ZERO_P(p->mem_ctx, SAM_USER_INFO_9);
2110 if (ctr->info.id9 == NULL)
2111 return NT_STATUS_NO_MEMORY;
2113 if (!NT_STATUS_IS_OK(r_u->status = get_user_info_9(p->mem_ctx, ctr->info.id9, &info->sid)))
2117 ctr->info.id16 = TALLOC_ZERO_P(p->mem_ctx, SAM_USER_INFO_16);
2118 if (ctr->info.id16 == NULL)
2119 return NT_STATUS_NO_MEMORY;
2121 if (!NT_STATUS_IS_OK(r_u->status = get_user_info_16(p->mem_ctx, ctr->info.id16, &info->sid)))
2126 ctr->info.id18 = TALLOC_ZERO_P(p->mem_ctx, SAM_USER_INFO_18);
2127 if (ctr->info.id18 == NULL)
2128 return NT_STATUS_NO_MEMORY;
2130 if (!NT_STATUS_IS_OK(r_u->status = get_user_info_18(p, p->mem_ctx, ctr->info.id18, &info->sid)))
2135 ctr->info.id20 = TALLOC_ZERO_P(p->mem_ctx,SAM_USER_INFO_20);
2136 if (ctr->info.id20 == NULL)
2137 return NT_STATUS_NO_MEMORY;
2138 if (!NT_STATUS_IS_OK(r_u->status = get_user_info_20(p->mem_ctx, ctr->info.id20, &info->sid)))
2143 ctr->info.id21 = TALLOC_ZERO_P(p->mem_ctx,SAM_USER_INFO_21);
2144 if (ctr->info.id21 == NULL)
2145 return NT_STATUS_NO_MEMORY;
2146 if (!NT_STATUS_IS_OK(r_u->status = get_user_info_21(p->mem_ctx, ctr->info.id21,
2147 &info->sid, &domain_sid)))
2152 return NT_STATUS_INVALID_INFO_CLASS;
2155 init_samr_r_query_userinfo(r_u, ctr, r_u->status);
2157 DEBUG(5,("_samr_query_userinfo: %d\n", __LINE__));
2162 /*******************************************************************
2163 samr_reply_query_usergroups
2164 ********************************************************************/
2166 NTSTATUS _samr_query_usergroups(pipes_struct *p, SAMR_Q_QUERY_USERGROUPS *q_u, SAMR_R_QUERY_USERGROUPS *r_u)
2168 struct samu *sam_pass=NULL;
2172 DOM_GID *gids = NULL;
2173 uint32 primary_group_rid;
2174 size_t num_groups = 0;
2180 bool success = False;
2183 * from the SID in the request:
2184 * we should send back the list of DOMAIN GROUPS
2185 * the user is a member of
2187 * and only the DOMAIN GROUPS
2188 * no ALIASES !!! neither aliases of the domain
2189 * nor aliases of the builtin SID
2194 r_u->status = NT_STATUS_OK;
2196 DEBUG(5,("_samr_query_usergroups: %d\n", __LINE__));
2198 /* find the policy handle. open a policy on it. */
2199 if (!get_lsa_policy_samr_sid(p, &q_u->pol, &sid, &acc_granted, NULL))
2200 return NT_STATUS_INVALID_HANDLE;
2202 if (!NT_STATUS_IS_OK(r_u->status = access_check_samr_function(acc_granted, SA_RIGHT_USER_GET_GROUPS, "_samr_query_usergroups"))) {
2206 if (!sid_check_is_in_our_domain(&sid))
2207 return NT_STATUS_OBJECT_TYPE_MISMATCH;
2209 if ( !(sam_pass = samu_new( p->mem_ctx )) ) {
2210 return NT_STATUS_NO_MEMORY;
2214 ret = pdb_getsampwsid(sam_pass, &sid);
2218 DEBUG(10, ("pdb_getsampwsid failed for %s\n",
2219 sid_string_dbg(&sid)));
2220 return NT_STATUS_NO_SUCH_USER;
2225 /* make both calls inside the root block */
2227 result = pdb_enum_group_memberships(p->mem_ctx, sam_pass,
2228 &sids, &unix_gids, &num_groups);
2229 if ( NT_STATUS_IS_OK(result) ) {
2230 success = sid_peek_check_rid(get_global_sam_sid(),
2231 pdb_get_group_sid(sam_pass),
2232 &primary_group_rid);
2236 if (!NT_STATUS_IS_OK(result)) {
2237 DEBUG(10, ("pdb_enum_group_memberships failed for %s\n",
2238 sid_string_dbg(&sid)));
2243 DEBUG(5, ("Group sid %s for user %s not in our domain\n",
2244 sid_string_dbg(pdb_get_group_sid(sam_pass)),
2245 pdb_get_username(sam_pass)));
2246 TALLOC_FREE(sam_pass);
2247 return NT_STATUS_INTERNAL_DB_CORRUPTION;
2253 dom_gid.attr = (SE_GROUP_MANDATORY|SE_GROUP_ENABLED_BY_DEFAULT|
2255 dom_gid.g_rid = primary_group_rid;
2256 ADD_TO_ARRAY(p->mem_ctx, DOM_GID, dom_gid, &gids, &num_gids);
2258 for (i=0; i<num_groups; i++) {
2260 if (!sid_peek_check_rid(get_global_sam_sid(),
2261 &(sids[i]), &dom_gid.g_rid)) {
2262 DEBUG(10, ("Found sid %s not in our domain\n",
2263 sid_string_dbg(&sids[i])));
2267 if (dom_gid.g_rid == primary_group_rid) {
2268 /* We added the primary group directly from the
2269 * sam_account. The other SIDs are unique from
2270 * enum_group_memberships */
2274 ADD_TO_ARRAY(p->mem_ctx, DOM_GID, dom_gid, &gids, &num_gids);
2277 /* construct the response. lkclXXXX: gids are not copied! */
2278 init_samr_r_query_usergroups(r_u, num_gids, gids, r_u->status);
2280 DEBUG(5,("_samr_query_usergroups: %d\n", __LINE__));
2285 /*******************************************************************
2286 _samr_query_domain_info
2287 ********************************************************************/
2289 NTSTATUS _samr_query_domain_info(pipes_struct *p,
2290 SAMR_Q_QUERY_DOMAIN_INFO *q_u,
2291 SAMR_R_QUERY_DOMAIN_INFO *r_u)
2293 struct samr_info *info = NULL;
2295 uint32 min_pass_len,pass_hist,password_properties;
2296 time_t u_expire, u_min_age;
2297 NTTIME nt_expire, nt_min_age;
2299 time_t u_lock_duration, u_reset_time;
2300 NTTIME nt_lock_duration, nt_reset_time;
2305 uint32 account_policy_temp;
2310 uint32 num_users=0, num_groups=0, num_aliases=0;
2312 if ((ctr = TALLOC_ZERO_P(p->mem_ctx, SAM_UNK_CTR)) == NULL) {
2313 return NT_STATUS_NO_MEMORY;
2318 r_u->status = NT_STATUS_OK;
2320 DEBUG(5,("_samr_query_domain_info: %d\n", __LINE__));
2322 /* find the policy handle. open a policy on it. */
2323 if (!find_policy_by_hnd(p, &q_u->domain_pol, (void **)(void *)&info)) {
2324 return NT_STATUS_INVALID_HANDLE;
2327 switch (q_u->switch_value) {
2334 pdb_get_account_policy(AP_MIN_PASSWORD_LEN, &account_policy_temp);
2335 min_pass_len = account_policy_temp;
2337 pdb_get_account_policy(AP_PASSWORD_HISTORY, &account_policy_temp);
2338 pass_hist = account_policy_temp;
2340 pdb_get_account_policy(AP_USER_MUST_LOGON_TO_CHG_PASS, &account_policy_temp);
2341 password_properties = account_policy_temp;
2343 pdb_get_account_policy(AP_MAX_PASSWORD_AGE, &account_policy_temp);
2344 u_expire = account_policy_temp;
2346 pdb_get_account_policy(AP_MIN_PASSWORD_AGE, &account_policy_temp);
2347 u_min_age = account_policy_temp;
2353 unix_to_nt_time_abs(&nt_expire, u_expire);
2354 unix_to_nt_time_abs(&nt_min_age, u_min_age);
2356 init_unk_info1(&ctr->info.inf1, (uint16)min_pass_len, (uint16)pass_hist,
2357 password_properties, nt_expire, nt_min_age);
2365 num_users = count_sam_users(info->disp_info, ACB_NORMAL);
2366 num_groups = count_sam_groups(info->disp_info);
2367 num_aliases = count_sam_aliases(info->disp_info);
2369 pdb_get_account_policy(AP_TIME_TO_LOGOUT, &account_policy_temp);
2370 u_logout = account_policy_temp;
2372 unix_to_nt_time_abs(&nt_logout, u_logout);
2374 if (!pdb_get_seq_num(&seq_num))
2375 seq_num = time(NULL);
2381 server_role = ROLE_DOMAIN_PDC;
2382 if (lp_server_role() == ROLE_DOMAIN_BDC)
2383 server_role = ROLE_DOMAIN_BDC;
2385 init_unk_info2(&ctr->info.inf2, lp_serverstring(), lp_workgroup(), global_myname(), seq_num,
2386 num_users, num_groups, num_aliases, nt_logout, server_role);
2396 pdb_get_account_policy(AP_TIME_TO_LOGOUT, &ul);
2397 u_logout = (time_t)ul;
2404 unix_to_nt_time_abs(&nt_logout, u_logout);
2406 init_unk_info3(&ctr->info.inf3, nt_logout);
2409 init_unk_info4(&ctr->info.inf4, lp_serverstring());
2412 init_unk_info5(&ctr->info.inf5, get_global_sam_name());
2415 /* NT returns its own name when a PDC. win2k and later
2416 * only the name of the PDC if itself is a BDC (samba4
2418 init_unk_info6(&ctr->info.inf6, global_myname());
2421 server_role = ROLE_DOMAIN_PDC;
2422 if (lp_server_role() == ROLE_DOMAIN_BDC)
2423 server_role = ROLE_DOMAIN_BDC;
2425 init_unk_info7(&ctr->info.inf7, server_role);
2433 if (!pdb_get_seq_num(&seq_num)) {
2434 seq_num = time(NULL);
2441 init_unk_info8(&ctr->info.inf8, (uint32) seq_num);
2449 pdb_get_account_policy(AP_LOCK_ACCOUNT_DURATION, &account_policy_temp);
2450 u_lock_duration = account_policy_temp;
2451 if (u_lock_duration != -1) {
2452 u_lock_duration *= 60;
2455 pdb_get_account_policy(AP_RESET_COUNT_TIME, &account_policy_temp);
2456 u_reset_time = account_policy_temp * 60;
2458 pdb_get_account_policy(AP_BAD_ATTEMPT_LOCKOUT, &account_policy_temp);
2459 lockout = account_policy_temp;
2465 unix_to_nt_time_abs(&nt_lock_duration, u_lock_duration);
2466 unix_to_nt_time_abs(&nt_reset_time, u_reset_time);
2468 init_unk_info12(&ctr->info.inf12, nt_lock_duration, nt_reset_time, (uint16)lockout);
2471 return NT_STATUS_INVALID_INFO_CLASS;
2475 init_samr_r_query_domain_info(r_u, q_u->switch_value, ctr, NT_STATUS_OK);
2477 DEBUG(5,("_samr_query_domain_info: %d\n", __LINE__));
2482 /* W2k3 seems to use the same check for all 3 objects that can be created via
2483 * SAMR, if you try to create for example "Dialup" as an alias it says
2484 * "NT_STATUS_USER_EXISTS". This is racy, but we can't really lock the user
2487 static NTSTATUS can_create(TALLOC_CTX *mem_ctx, const char *new_name)
2489 enum lsa_SidType type;
2492 DEBUG(10, ("Checking whether [%s] can be created\n", new_name));
2495 /* Lookup in our local databases (LOOKUP_NAME_REMOTE not set)
2496 * whether the name already exists */
2497 result = lookup_name(mem_ctx, new_name, LOOKUP_NAME_LOCAL,
2498 NULL, NULL, NULL, &type);
2502 DEBUG(10, ("%s does not exist, can create it\n", new_name));
2503 return NT_STATUS_OK;
2506 DEBUG(5, ("trying to create %s, exists as %s\n",
2507 new_name, sid_type_lookup(type)));
2509 if (type == SID_NAME_DOM_GRP) {
2510 return NT_STATUS_GROUP_EXISTS;
2512 if (type == SID_NAME_ALIAS) {
2513 return NT_STATUS_ALIAS_EXISTS;
2516 /* Yes, the default is NT_STATUS_USER_EXISTS */
2517 return NT_STATUS_USER_EXISTS;
2520 /*******************************************************************
2522 ********************************************************************/
2524 NTSTATUS _samr_CreateUser2(pipes_struct *p,
2525 struct samr_CreateUser2 *r)
2527 const char *account = NULL;
2529 POLICY_HND dom_pol = *r->in.domain_handle;
2530 uint32_t acb_info = r->in.acct_flags;
2531 POLICY_HND *user_pol = r->out.user_handle;
2532 struct samr_info *info = NULL;
2537 /* check this, when giving away 'add computer to domain' privs */
2538 uint32 des_access = GENERIC_RIGHTS_USER_ALL_ACCESS;
2539 bool can_add_account = False;
2541 DISP_INFO *disp_info = NULL;
2543 /* Get the domain SID stored in the domain policy */
2544 if (!get_lsa_policy_samr_sid(p, &dom_pol, &sid, &acc_granted,
2546 return NT_STATUS_INVALID_HANDLE;
2548 nt_status = access_check_samr_function(acc_granted,
2549 SA_RIGHT_DOMAIN_CREATE_USER,
2550 "_samr_CreateUser2");
2551 if (!NT_STATUS_IS_OK(nt_status)) {
2555 if (!(acb_info == ACB_NORMAL || acb_info == ACB_DOMTRUST ||
2556 acb_info == ACB_WSTRUST || acb_info == ACB_SVRTRUST)) {
2557 /* Match Win2k, and return NT_STATUS_INVALID_PARAMETER if
2558 this parameter is not an account type */
2559 return NT_STATUS_INVALID_PARAMETER;
2562 account = r->in.account_name->string;
2563 if (account == NULL) {
2564 return NT_STATUS_NO_MEMORY;
2567 nt_status = can_create(p->mem_ctx, account);
2568 if (!NT_STATUS_IS_OK(nt_status)) {
2572 /* determine which user right we need to check based on the acb_info */
2574 if ( acb_info & ACB_WSTRUST )
2576 se_priv_copy( &se_rights, &se_machine_account );
2577 can_add_account = user_has_privileges(
2578 p->pipe_user.nt_user_token, &se_rights );
2580 /* usrmgr.exe (and net rpc trustdom grant) creates a normal user
2581 account for domain trusts and changes the ACB flags later */
2582 else if ( acb_info & ACB_NORMAL &&
2583 (account[strlen(account)-1] != '$') )
2585 se_priv_copy( &se_rights, &se_add_users );
2586 can_add_account = user_has_privileges(
2587 p->pipe_user.nt_user_token, &se_rights );
2589 else /* implicit assumption of a BDC or domain trust account here
2590 * (we already check the flags earlier) */
2592 if ( lp_enable_privileges() ) {
2593 /* only Domain Admins can add a BDC or domain trust */
2594 se_priv_copy( &se_rights, &se_priv_none );
2595 can_add_account = nt_token_check_domain_rid(
2596 p->pipe_user.nt_user_token,
2597 DOMAIN_GROUP_RID_ADMINS );
2601 DEBUG(5, ("_samr_CreateUser2: %s can add this account : %s\n",
2602 uidtoname(p->pipe_user.ut.uid),
2603 can_add_account ? "True":"False" ));
2605 /********** BEGIN Admin BLOCK **********/
2607 if ( can_add_account )
2610 nt_status = pdb_create_user(p->mem_ctx, account, acb_info,
2613 if ( can_add_account )
2616 /********** END Admin BLOCK **********/
2618 /* now check for failure */
2620 if ( !NT_STATUS_IS_OK(nt_status) )
2623 /* Get the user's SID */
2625 sid_compose(&sid, get_global_sam_sid(), *r->out.rid);
2627 make_samr_object_sd(p->mem_ctx, &psd, &sd_size, &usr_generic_mapping,
2628 &sid, SAMR_USR_RIGHTS_WRITE_PW);
2629 se_map_generic(&des_access, &usr_generic_mapping);
2631 nt_status = access_check_samr_object(psd, p->pipe_user.nt_user_token,
2632 &se_rights, GENERIC_RIGHTS_USER_WRITE, des_access,
2633 &acc_granted, "_samr_CreateUser2");
2635 if ( !NT_STATUS_IS_OK(nt_status) ) {
2639 /* associate the user's SID with the new handle. */
2640 if ((info = get_samr_info_by_sid(&sid)) == NULL) {
2641 return NT_STATUS_NO_MEMORY;
2646 info->acc_granted = acc_granted;
2648 /* get a (unique) handle. open a policy on it. */
2649 if (!create_policy_hnd(p, user_pol, free_samr_info, (void *)info)) {
2650 return NT_STATUS_OBJECT_NAME_NOT_FOUND;
2653 /* After a "set" ensure we have no cached display info. */
2654 force_flush_samr_cache(info->disp_info);
2656 *r->out.access_granted = acc_granted;
2658 return NT_STATUS_OK;
2661 /*******************************************************************
2662 samr_reply_connect_anon
2663 ********************************************************************/
2665 NTSTATUS _samr_connect_anon(pipes_struct *p, SAMR_Q_CONNECT_ANON *q_u, SAMR_R_CONNECT_ANON *r_u)
2667 struct samr_info *info = NULL;
2668 uint32 des_access = q_u->access_mask;
2672 if (!pipe_access_check(p)) {
2673 DEBUG(3, ("access denied to samr_connect_anon\n"));
2674 r_u->status = NT_STATUS_ACCESS_DENIED;
2678 /* set up the SAMR connect_anon response */
2680 r_u->status = NT_STATUS_OK;
2682 /* associate the user's SID with the new handle. */
2683 if ((info = get_samr_info_by_sid(NULL)) == NULL)
2684 return NT_STATUS_NO_MEMORY;
2686 /* don't give away the farm but this is probably ok. The SA_RIGHT_SAM_ENUM_DOMAINS
2687 was observed from a win98 client trying to enumerate users (when configured
2688 user level access control on shares) --jerry */
2690 if (des_access == MAXIMUM_ALLOWED_ACCESS) {
2691 /* Map to max possible knowing we're filtered below. */
2692 des_access = GENERIC_ALL_ACCESS;
2695 se_map_generic( &des_access, &sam_generic_mapping );
2696 info->acc_granted = des_access & (SA_RIGHT_SAM_ENUM_DOMAINS|SA_RIGHT_SAM_OPEN_DOMAIN);
2698 info->status = q_u->unknown_0;
2700 /* get a (unique) handle. open a policy on it. */
2701 if (!create_policy_hnd(p, &r_u->connect_pol, free_samr_info, (void *)info))
2702 return NT_STATUS_OBJECT_NAME_NOT_FOUND;
2707 /*******************************************************************
2709 ********************************************************************/
2711 NTSTATUS _samr_connect(pipes_struct *p, SAMR_Q_CONNECT *q_u, SAMR_R_CONNECT *r_u)
2713 struct samr_info *info = NULL;
2714 SEC_DESC *psd = NULL;
2716 uint32 des_access = q_u->access_mask;
2721 DEBUG(5,("_samr_connect: %d\n", __LINE__));
2725 if (!pipe_access_check(p)) {
2726 DEBUG(3, ("access denied to samr_connect\n"));
2727 r_u->status = NT_STATUS_ACCESS_DENIED;
2731 make_samr_object_sd(p->mem_ctx, &psd, &sd_size, &sam_generic_mapping, NULL, 0);
2732 se_map_generic(&des_access, &sam_generic_mapping);
2734 nt_status = access_check_samr_object(psd, p->pipe_user.nt_user_token,
2735 NULL, 0, des_access, &acc_granted, "_samr_connect");
2737 if ( !NT_STATUS_IS_OK(nt_status) )
2740 r_u->status = NT_STATUS_OK;
2742 /* associate the user's SID and access granted with the new handle. */
2743 if ((info = get_samr_info_by_sid(NULL)) == NULL)
2744 return NT_STATUS_NO_MEMORY;
2746 info->acc_granted = acc_granted;
2747 info->status = q_u->access_mask;
2749 /* get a (unique) handle. open a policy on it. */
2750 if (!create_policy_hnd(p, &r_u->connect_pol, free_samr_info, (void *)info))
2751 return NT_STATUS_OBJECT_NAME_NOT_FOUND;
2753 DEBUG(5,("_samr_connect: %d\n", __LINE__));
2758 /*******************************************************************
2760 ********************************************************************/
2762 NTSTATUS _samr_connect4(pipes_struct *p, SAMR_Q_CONNECT4 *q_u, SAMR_R_CONNECT4 *r_u)
2764 struct samr_info *info = NULL;
2765 SEC_DESC *psd = NULL;
2767 uint32 des_access = q_u->access_mask;
2772 DEBUG(5,("_samr_connect4: %d\n", __LINE__));
2776 if (!pipe_access_check(p)) {
2777 DEBUG(3, ("access denied to samr_connect4\n"));
2778 r_u->status = NT_STATUS_ACCESS_DENIED;
2782 make_samr_object_sd(p->mem_ctx, &psd, &sd_size, &sam_generic_mapping, NULL, 0);
2783 se_map_generic(&des_access, &sam_generic_mapping);
2785 nt_status = access_check_samr_object(psd, p->pipe_user.nt_user_token,
2786 NULL, 0, des_access, &acc_granted, "_samr_connect4");
2788 if ( !NT_STATUS_IS_OK(nt_status) )
2791 r_u->status = NT_STATUS_OK;
2793 /* associate the user's SID and access granted with the new handle. */
2794 if ((info = get_samr_info_by_sid(NULL)) == NULL)
2795 return NT_STATUS_NO_MEMORY;
2797 info->acc_granted = acc_granted;
2798 info->status = q_u->access_mask;
2800 /* get a (unique) handle. open a policy on it. */
2801 if (!create_policy_hnd(p, &r_u->connect_pol, free_samr_info, (void *)info))
2802 return NT_STATUS_OBJECT_NAME_NOT_FOUND;
2804 DEBUG(5,("_samr_connect: %d\n", __LINE__));
2809 /*******************************************************************
2811 ********************************************************************/
2813 NTSTATUS _samr_connect5(pipes_struct *p, SAMR_Q_CONNECT5 *q_u, SAMR_R_CONNECT5 *r_u)
2815 struct samr_info *info = NULL;
2816 SEC_DESC *psd = NULL;
2818 uint32 des_access = q_u->access_mask;
2824 DEBUG(5,("_samr_connect5: %d\n", __LINE__));
2830 if (!pipe_access_check(p)) {
2831 DEBUG(3, ("access denied to samr_connect5\n"));
2832 r_u->status = NT_STATUS_ACCESS_DENIED;
2836 make_samr_object_sd(p->mem_ctx, &psd, &sd_size, &sam_generic_mapping, NULL, 0);
2837 se_map_generic(&des_access, &sam_generic_mapping);
2839 nt_status = access_check_samr_object(psd, p->pipe_user.nt_user_token,
2840 NULL, 0, des_access, &acc_granted, "_samr_connect5");
2842 if ( !NT_STATUS_IS_OK(nt_status) )
2845 /* associate the user's SID and access granted with the new handle. */
2846 if ((info = get_samr_info_by_sid(NULL)) == NULL)
2847 return NT_STATUS_NO_MEMORY;
2849 info->acc_granted = acc_granted;
2850 info->status = q_u->access_mask;
2852 /* get a (unique) handle. open a policy on it. */
2853 if (!create_policy_hnd(p, &pol, free_samr_info, (void *)info))
2854 return NT_STATUS_OBJECT_NAME_NOT_FOUND;
2856 DEBUG(5,("_samr_connect: %d\n", __LINE__));
2858 init_samr_r_connect5(r_u, &pol, NT_STATUS_OK);
2863 /**********************************************************************
2864 api_samr_lookup_domain
2865 **********************************************************************/
2867 NTSTATUS _samr_lookup_domain(pipes_struct *p, SAMR_Q_LOOKUP_DOMAIN *q_u, SAMR_R_LOOKUP_DOMAIN *r_u)
2869 struct samr_info *info;
2870 fstring domain_name;
2873 r_u->status = NT_STATUS_OK;
2875 if (!find_policy_by_hnd(p, &q_u->connect_pol, (void**)(void *)&info))
2876 return NT_STATUS_INVALID_HANDLE;
2878 /* win9x user manager likes to use SA_RIGHT_SAM_ENUM_DOMAINS here.
2879 Reverted that change so we will work with RAS servers again */
2881 if (!NT_STATUS_IS_OK(r_u->status = access_check_samr_function(info->acc_granted,
2882 SA_RIGHT_SAM_OPEN_DOMAIN, "_samr_lookup_domain")))
2887 rpcstr_pull(domain_name, q_u->uni_domain.buffer, sizeof(domain_name), q_u->uni_domain.uni_str_len*2, 0);
2891 if (strequal(domain_name, builtin_domain_name())) {
2892 sid_copy(&sid, &global_sid_Builtin);
2894 if (!secrets_fetch_domain_sid(domain_name, &sid)) {
2895 r_u->status = NT_STATUS_NO_SUCH_DOMAIN;
2899 DEBUG(2,("Returning domain sid for domain %s -> %s\n", domain_name,
2900 sid_string_dbg(&sid)));
2902 init_samr_r_lookup_domain(r_u, &sid, r_u->status);
2907 /******************************************************************
2908 makes a SAMR_R_ENUM_DOMAINS structure.
2909 ********************************************************************/
2911 static bool make_enum_domains(TALLOC_CTX *ctx, SAM_ENTRY **pp_sam,
2912 UNISTR2 **pp_uni_name, uint32 num_sam_entries, fstring doms[])
2918 DEBUG(5, ("make_enum_domains\n"));
2921 *pp_uni_name = NULL;
2923 if (num_sam_entries == 0)
2926 sam = TALLOC_ZERO_ARRAY(ctx, SAM_ENTRY, num_sam_entries);
2927 uni_name = TALLOC_ZERO_ARRAY(ctx, UNISTR2, num_sam_entries);
2929 if (sam == NULL || uni_name == NULL)
2932 for (i = 0; i < num_sam_entries; i++) {
2933 init_unistr2(&uni_name[i], doms[i], UNI_FLAGS_NONE);
2934 init_sam_entry(&sam[i], &uni_name[i], 0);
2938 *pp_uni_name = uni_name;
2943 /**********************************************************************
2944 api_samr_enum_domains
2945 **********************************************************************/
2947 NTSTATUS _samr_enum_domains(pipes_struct *p, SAMR_Q_ENUM_DOMAINS *q_u, SAMR_R_ENUM_DOMAINS *r_u)
2949 struct samr_info *info;
2950 uint32 num_entries = 2;
2954 r_u->status = NT_STATUS_OK;
2956 if (!find_policy_by_hnd(p, &q_u->pol, (void**)(void *)&info))
2957 return NT_STATUS_INVALID_HANDLE;
2959 if (!NT_STATUS_IS_OK(r_u->status = access_check_samr_function(info->acc_granted, SA_RIGHT_SAM_ENUM_DOMAINS, "_samr_enum_domains"))) {
2963 name = get_global_sam_name();
2965 fstrcpy(dom[0],name);
2967 fstrcpy(dom[1],"Builtin");
2969 if (!make_enum_domains(p->mem_ctx, &r_u->sam, &r_u->uni_dom_name, num_entries, dom))
2970 return NT_STATUS_NO_MEMORY;
2972 init_samr_r_enum_domains(r_u, q_u->start_idx + num_entries, num_entries);
2977 /*******************************************************************
2979 ********************************************************************/
2981 NTSTATUS _samr_OpenAlias(pipes_struct *p,
2982 struct samr_OpenAlias *r)
2985 POLICY_HND domain_pol = *r->in.domain_handle;
2986 uint32 alias_rid = r->in.rid;
2987 POLICY_HND *alias_pol = r->out.alias_handle;
2988 struct samr_info *info = NULL;
2989 SEC_DESC *psd = NULL;
2991 uint32 des_access = r->in.access_mask;
2996 /* find the domain policy and get the SID / access bits stored in the domain policy */
2998 if ( !get_lsa_policy_samr_sid(p, &domain_pol, &sid, &acc_granted, NULL) )
2999 return NT_STATUS_INVALID_HANDLE;
3001 status = access_check_samr_function(acc_granted,
3002 SA_RIGHT_DOMAIN_OPEN_ACCOUNT, "_samr_OpenAlias");
3004 if ( !NT_STATUS_IS_OK(status) )
3007 /* append the alias' RID to it */
3009 if (!sid_append_rid(&sid, alias_rid))
3010 return NT_STATUS_NO_SUCH_ALIAS;
3012 /*check if access can be granted as requested by client. */
3014 make_samr_object_sd(p->mem_ctx, &psd, &sd_size, &ali_generic_mapping, NULL, 0);
3015 se_map_generic(&des_access,&ali_generic_mapping);
3017 se_priv_copy( &se_rights, &se_add_users );
3020 status = access_check_samr_object(psd, p->pipe_user.nt_user_token,
3021 &se_rights, GENERIC_RIGHTS_ALIAS_WRITE, des_access,
3022 &acc_granted, "_samr_OpenAlias");
3024 if ( !NT_STATUS_IS_OK(status) )
3028 /* Check we actually have the requested alias */
3029 enum lsa_SidType type;
3034 result = lookup_sid(NULL, &sid, NULL, NULL, &type);
3037 if (!result || (type != SID_NAME_ALIAS)) {
3038 return NT_STATUS_NO_SUCH_ALIAS;
3041 /* make sure there is a mapping */
3043 if ( !sid_to_gid( &sid, &gid ) ) {
3044 return NT_STATUS_NO_SUCH_ALIAS;
3049 /* associate the alias SID with the new handle. */
3050 if ((info = get_samr_info_by_sid(&sid)) == NULL)
3051 return NT_STATUS_NO_MEMORY;
3053 info->acc_granted = acc_granted;
3055 /* get a (unique) handle. open a policy on it. */
3056 if (!create_policy_hnd(p, alias_pol, free_samr_info, (void *)info))
3057 return NT_STATUS_OBJECT_NAME_NOT_FOUND;
3059 return NT_STATUS_OK;
3062 /*******************************************************************
3064 ********************************************************************/
3065 static NTSTATUS set_user_info_7(TALLOC_CTX *mem_ctx,
3066 const SAM_USER_INFO_7 *id7, struct samu *pwd)
3072 DEBUG(5, ("set_user_info_7: NULL id7\n"));
3074 return NT_STATUS_ACCESS_DENIED;
3077 if(!rpcstr_pull(new_name, id7->uni_name.buffer, sizeof(new_name), id7->uni_name.uni_str_len*2, 0)) {
3078 DEBUG(5, ("set_user_info_7: failed to get new username\n"));
3080 return NT_STATUS_ACCESS_DENIED;
3083 /* check to see if the new username already exists. Note: we can't
3084 reliably lock all backends, so there is potentially the
3085 possibility that a user can be created in between this check and
3086 the rename. The rename should fail, but may not get the
3087 exact same failure status code. I think this is small enough
3088 of a window for this type of operation and the results are
3089 simply that the rename fails with a slightly different status
3090 code (like UNSUCCESSFUL instead of ALREADY_EXISTS). */
3092 rc = can_create(mem_ctx, new_name);
3093 if (!NT_STATUS_IS_OK(rc)) {
3097 rc = pdb_rename_sam_account(pwd, new_name);
3103 /*******************************************************************
3105 ********************************************************************/
3107 static bool set_user_info_16(const SAM_USER_INFO_16 *id16, struct samu *pwd)
3110 DEBUG(5, ("set_user_info_16: NULL id16\n"));
3115 /* FIX ME: check if the value is really changed --metze */
3116 if (!pdb_set_acct_ctrl(pwd, id16->acb_info, PDB_CHANGED)) {
3121 if(!NT_STATUS_IS_OK(pdb_update_sam_account(pwd))) {
3131 /*******************************************************************
3133 ********************************************************************/
3135 static bool set_user_info_18(SAM_USER_INFO_18 *id18, struct samu *pwd)
3139 DEBUG(2, ("set_user_info_18: id18 is NULL\n"));
3144 if (!pdb_set_lanman_passwd (pwd, id18->lm_pwd, PDB_CHANGED)) {
3148 if (!pdb_set_nt_passwd (pwd, id18->nt_pwd, PDB_CHANGED)) {
3152 if (!pdb_set_pass_last_set_time (pwd, time(NULL), PDB_CHANGED)) {
3157 if(!NT_STATUS_IS_OK(pdb_update_sam_account(pwd))) {
3166 /*******************************************************************
3168 ********************************************************************/
3170 static bool set_user_info_20(SAM_USER_INFO_20 *id20, struct samu *pwd)
3173 DEBUG(5, ("set_user_info_20: NULL id20\n"));
3177 copy_id20_to_sam_passwd(pwd, id20);
3179 /* write the change out */
3180 if(!NT_STATUS_IS_OK(pdb_update_sam_account(pwd))) {
3189 /*******************************************************************
3191 ********************************************************************/
3193 static NTSTATUS set_user_info_21(TALLOC_CTX *mem_ctx, SAM_USER_INFO_21 *id21,
3200 DEBUG(5, ("set_user_info_21: NULL id21\n"));
3201 return NT_STATUS_INVALID_PARAMETER;
3204 /* we need to separately check for an account rename first */
3206 if (rpcstr_pull(new_name, id21->uni_user_name.buffer,
3207 sizeof(new_name), id21->uni_user_name.uni_str_len*2, 0)
3208 && (!strequal(new_name, pdb_get_username(pwd))))
3211 /* check to see if the new username already exists. Note: we can't
3212 reliably lock all backends, so there is potentially the
3213 possibility that a user can be created in between this check and
3214 the rename. The rename should fail, but may not get the
3215 exact same failure status code. I think this is small enough
3216 of a window for this type of operation and the results are
3217 simply that the rename fails with a slightly different status
3218 code (like UNSUCCESSFUL instead of ALREADY_EXISTS). */
3220 status = can_create(mem_ctx, new_name);
3221 if (!NT_STATUS_IS_OK(status)) {
3225 status = pdb_rename_sam_account(pwd, new_name);
3227 if (!NT_STATUS_IS_OK(status)) {
3228 DEBUG(0,("set_user_info_21: failed to rename account: %s\n",
3229 nt_errstr(status)));
3234 /* set the new username so that later
3235 functions can work on the new account */
3236 pdb_set_username(pwd, new_name, PDB_SET);
3239 copy_id21_to_sam_passwd(pwd, id21);
3242 * The funny part about the previous two calls is
3243 * that pwd still has the password hashes from the
3244 * passdb entry. These have not been updated from
3245 * id21. I don't know if they need to be set. --jerry
3248 if ( IS_SAM_CHANGED(pwd, PDB_GROUPSID) ) {
3249 status = pdb_set_unix_primary_group(mem_ctx, pwd);
3250 if ( !NT_STATUS_IS_OK(status) ) {
3255 /* Don't worry about writing out the user account since the
3256 primary group SID is generated solely from the user's Unix
3259 /* write the change out */
3260 if(!NT_STATUS_IS_OK(status = pdb_update_sam_account(pwd))) {
3267 return NT_STATUS_OK;
3270 /*******************************************************************
3272 ********************************************************************/
3274 static NTSTATUS set_user_info_23(TALLOC_CTX *mem_ctx, SAM_USER_INFO_23 *id23,
3277 char *plaintext_buf = NULL;
3283 DEBUG(5, ("set_user_info_23: NULL id23\n"));
3284 return NT_STATUS_INVALID_PARAMETER;
3287 DEBUG(5, ("Attempting administrator password change (level 23) for user %s\n",
3288 pdb_get_username(pwd)));
3290 acct_ctrl = pdb_get_acct_ctrl(pwd);
3292 if (!decode_pw_buffer(mem_ctx,
3298 return NT_STATUS_INVALID_PARAMETER;
3301 if (!pdb_set_plaintext_passwd (pwd, plaintext_buf)) {
3303 return NT_STATUS_ACCESS_DENIED;
3306 copy_id23_to_sam_passwd(pwd, id23);
3308 /* if it's a trust account, don't update /etc/passwd */
3309 if ( ( (acct_ctrl & ACB_DOMTRUST) == ACB_DOMTRUST ) ||
3310 ( (acct_ctrl & ACB_WSTRUST) == ACB_WSTRUST) ||
3311 ( (acct_ctrl & ACB_SVRTRUST) == ACB_SVRTRUST) ) {
3312 DEBUG(5, ("Changing trust account. Not updating /etc/passwd\n"));
3314 /* update the UNIX password */
3315 if (lp_unix_password_sync() ) {
3316 struct passwd *passwd;
3317 if (pdb_get_username(pwd) == NULL) {
3318 DEBUG(1, ("chgpasswd: User without name???\n"));
3320 return NT_STATUS_ACCESS_DENIED;
3323 passwd = Get_Pwnam_alloc(pwd, pdb_get_username(pwd));
3324 if (passwd == NULL) {
3325 DEBUG(1, ("chgpasswd: Username does not exist in system !?!\n"));
3328 if(!chgpasswd(pdb_get_username(pwd), passwd, "", plaintext_buf, True)) {
3330 return NT_STATUS_ACCESS_DENIED;
3332 TALLOC_FREE(passwd);
3336 memset(plaintext_buf, '\0', strlen(plaintext_buf));
3338 if (IS_SAM_CHANGED(pwd, PDB_GROUPSID) &&
3339 (!NT_STATUS_IS_OK(status = pdb_set_unix_primary_group(mem_ctx,
3345 if(!NT_STATUS_IS_OK(status = pdb_update_sam_account(pwd))) {
3352 return NT_STATUS_OK;
3355 /*******************************************************************
3357 ********************************************************************/
3359 static bool set_user_info_pw(uint8 *pass, struct samu *pwd)
3362 char *plaintext_buf = NULL;
3364 time_t last_set_time;
3365 enum pdb_value_state last_set_state;
3367 DEBUG(5, ("Attempting administrator password change for user %s\n",
3368 pdb_get_username(pwd)));
3370 acct_ctrl = pdb_get_acct_ctrl(pwd);
3371 /* we need to know if it's expired, because this is an admin change, not a
3372 user change, so it's still expired when we're done */
3373 last_set_state = pdb_get_init_flags(pwd, PDB_PASSLASTSET);
3374 last_set_time = pdb_get_pass_last_set_time(pwd);
3376 if (!decode_pw_buffer(talloc_tos(),
3385 if (!pdb_set_plaintext_passwd (pwd, plaintext_buf)) {
3390 /* if it's a trust account, don't update /etc/passwd */
3391 if ( ( (acct_ctrl & ACB_DOMTRUST) == ACB_DOMTRUST ) ||
3392 ( (acct_ctrl & ACB_WSTRUST) == ACB_WSTRUST) ||
3393 ( (acct_ctrl & ACB_SVRTRUST) == ACB_SVRTRUST) ) {
3394 DEBUG(5, ("Changing trust account or non-unix-user password, not updating /etc/passwd\n"));
3396 /* update the UNIX password */
3397 if (lp_unix_password_sync()) {
3398 struct passwd *passwd;
3400 if (pdb_get_username(pwd) == NULL) {
3401 DEBUG(1, ("chgpasswd: User without name???\n"));
3406 passwd = Get_Pwnam_alloc(pwd, pdb_get_username(pwd));
3407 if (passwd == NULL) {
3408 DEBUG(1, ("chgpasswd: Username does not exist in system !?!\n"));
3411 if(!chgpasswd(pdb_get_username(pwd), passwd, "", plaintext_buf, True)) {
3415 TALLOC_FREE(passwd);
3419 memset(plaintext_buf, '\0', strlen(plaintext_buf));
3421 /* restore last set time as this is an admin change, not a user pw change */
3422 pdb_set_pass_last_set_time (pwd, last_set_time, last_set_state);
3424 DEBUG(5,("set_user_info_pw: pdb_update_pwd()\n"));
3426 /* update the SAMBA password */
3427 if(!NT_STATUS_IS_OK(pdb_update_sam_account(pwd))) {
3437 /*******************************************************************
3439 ********************************************************************/
3441 static NTSTATUS set_user_info_25(TALLOC_CTX *mem_ctx, SAM_USER_INFO_25 *id25,
3447 DEBUG(5, ("set_user_info_25: NULL id25\n"));
3448 return NT_STATUS_INVALID_PARAMETER;
3451 copy_id25_to_sam_passwd(pwd, id25);
3453 /* write the change out */
3454 if(!NT_STATUS_IS_OK(status = pdb_update_sam_account(pwd))) {
3460 * We need to "pdb_update_sam_account" before the unix primary group
3461 * is set, because the idealx scripts would also change the
3462 * sambaPrimaryGroupSid using the ldap replace method. pdb_ldap uses
3463 * the delete explicit / add explicit, which would then fail to find
3464 * the previous primaryGroupSid value.
3467 if ( IS_SAM_CHANGED(pwd, PDB_GROUPSID) ) {
3468 status = pdb_set_unix_primary_group(mem_ctx, pwd);
3469 if ( !NT_STATUS_IS_OK(status) ) {
3474 /* WARNING: No TALLOC_FREE(pwd), we are about to set the password
3477 return NT_STATUS_OK;
3480 /*******************************************************************
3481 samr_reply_set_userinfo
3482 ********************************************************************/
3484 NTSTATUS _samr_set_userinfo(pipes_struct *p, SAMR_Q_SET_USERINFO *q_u, SAMR_R_SET_USERINFO *r_u)
3486 struct samu *pwd = NULL;
3488 POLICY_HND *pol = &q_u->pol;
3489 uint16 switch_value = q_u->switch_value;
3490 SAM_USERINFO_CTR *ctr = q_u->ctr;
3492 uint32 acc_required;
3494 bool has_enough_rights = False;
3496 DISP_INFO *disp_info = NULL;
3498 DEBUG(5, ("_samr_set_userinfo: %d\n", __LINE__));
3500 r_u->status = NT_STATUS_OK;
3502 /* find the policy handle. open a policy on it. */
3503 if (!get_lsa_policy_samr_sid(p, pol, &sid, &acc_granted, &disp_info))
3504 return NT_STATUS_INVALID_HANDLE;
3506 /* This is tricky. A WinXP domain join sets
3507 (SA_RIGHT_USER_SET_PASSWORD|SA_RIGHT_USER_SET_ATTRIBUTES|SA_RIGHT_USER_ACCT_FLAGS_EXPIRY)
3508 The MMC lusrmgr plugin includes these perms and more in the SamrOpenUser(). But the
3509 standard Win32 API calls just ask for SA_RIGHT_USER_SET_PASSWORD in the SamrOpenUser().
3510 This should be enough for levels 18, 24, 25,& 26. Info level 23 can set more so
3511 we'll use the set from the WinXP join as the basis. */
3513 switch (switch_value) {
3518 acc_required = SA_RIGHT_USER_SET_PASSWORD;
3521 acc_required = SA_RIGHT_USER_SET_PASSWORD | SA_RIGHT_USER_SET_ATTRIBUTES | SA_RIGHT_USER_ACCT_FLAGS_EXPIRY;
3525 if (!NT_STATUS_IS_OK(r_u->status = access_check_samr_function(acc_granted, acc_required, "_samr_set_userinfo"))) {
3529 DEBUG(5, ("_samr_set_userinfo: sid:%s, level:%d\n",
3530 sid_string_dbg(&sid), switch_value));
3533 DEBUG(5, ("_samr_set_userinfo: NULL info level\n"));
3534 return NT_STATUS_INVALID_INFO_CLASS;
3537 if ( !(pwd = samu_new( NULL )) ) {
3538 return NT_STATUS_NO_MEMORY;
3542 ret = pdb_getsampwsid(pwd, &sid);
3547 return NT_STATUS_NO_SUCH_USER;
3550 /* deal with machine password changes differently from userinfo changes */
3551 /* check to see if we have the sufficient rights */
3553 acb_info = pdb_get_acct_ctrl(pwd);
3554 if ( acb_info & ACB_WSTRUST )
3555 has_enough_rights = user_has_privileges( p->pipe_user.nt_user_token, &se_machine_account);
3556 else if ( acb_info & ACB_NORMAL )
3557 has_enough_rights = user_has_privileges( p->pipe_user.nt_user_token, &se_add_users );
3558 else if ( acb_info & (ACB_SVRTRUST|ACB_DOMTRUST) ) {
3559 if ( lp_enable_privileges() )
3560 has_enough_rights = nt_token_check_domain_rid( p->pipe_user.nt_user_token, DOMAIN_GROUP_RID_ADMINS );
3563 DEBUG(5, ("_samr_set_userinfo: %s does%s possess sufficient rights\n",
3564 uidtoname(p->pipe_user.ut.uid),
3565 has_enough_rights ? "" : " not"));
3567 /* ================ BEGIN SeMachineAccountPrivilege BLOCK ================ */
3569 if ( has_enough_rights )
3572 /* ok! user info levels (lots: see MSDEV help), off we go... */
3574 switch (switch_value) {
3576 if (!set_user_info_18(ctr->info.id18, pwd))
3577 r_u->status = NT_STATUS_ACCESS_DENIED;
3581 if (!p->session_key.length) {
3582 r_u->status = NT_STATUS_NO_USER_SESSION_KEY;
3584 SamOEMhashBlob(ctr->info.id24->pass, 516, &p->session_key);
3586 dump_data(100, ctr->info.id24->pass, 516);
3588 if (!set_user_info_pw(ctr->info.id24->pass, pwd))
3589 r_u->status = NT_STATUS_ACCESS_DENIED;
3593 if (!p->session_key.length) {
3594 r_u->status = NT_STATUS_NO_USER_SESSION_KEY;
3596 encode_or_decode_arc4_passwd_buffer(ctr->info.id25->pass, &p->session_key);
3598 dump_data(100, ctr->info.id25->pass, 532);
3600 r_u->status = set_user_info_25(p->mem_ctx,
3601 ctr->info.id25, pwd);
3602 if (!NT_STATUS_IS_OK(r_u->status)) {
3605 if (!set_user_info_pw(ctr->info.id25->pass, pwd))
3606 r_u->status = NT_STATUS_ACCESS_DENIED;
3610 if (!p->session_key.length) {
3611 r_u->status = NT_STATUS_NO_USER_SESSION_KEY;
3613 encode_or_decode_arc4_passwd_buffer(ctr->info.id26->pass, &p->session_key);
3615 dump_data(100, ctr->info.id26->pass, 516);
3617 if (!set_user_info_pw(ctr->info.id26->pass, pwd))
3618 r_u->status = NT_STATUS_ACCESS_DENIED;
3622 if (!p->session_key.length) {
3623 r_u->status = NT_STATUS_NO_USER_SESSION_KEY;
3625 SamOEMhashBlob(ctr->info.id23->pass, 516, &p->session_key);
3627 dump_data(100, ctr->info.id23->pass, 516);
3629 r_u->status = set_user_info_23(p->mem_ctx,
3630 ctr->info.id23, pwd);
3634 r_u->status = NT_STATUS_INVALID_INFO_CLASS;
3639 if ( has_enough_rights )
3642 /* ================ END SeMachineAccountPrivilege BLOCK ================ */
3644 if (NT_STATUS_IS_OK(r_u->status)) {
3645 force_flush_samr_cache(disp_info);
3651 /*******************************************************************
3652 samr_reply_set_userinfo2
3653 ********************************************************************/
3655 NTSTATUS _samr_set_userinfo2(pipes_struct *p, SAMR_Q_SET_USERINFO2 *q_u, SAMR_R_SET_USERINFO2 *r_u)
3657 struct samu *pwd = NULL;
3659 SAM_USERINFO_CTR *ctr = q_u->ctr;
3660 POLICY_HND *pol = &q_u->pol;
3661 uint16 switch_value = q_u->switch_value;
3663 uint32 acc_required;
3665 bool has_enough_rights = False;
3667 DISP_INFO *disp_info = NULL;
3669 DEBUG(5, ("samr_reply_set_userinfo2: %d\n", __LINE__));
3671 r_u->status = NT_STATUS_OK;
3673 /* find the policy handle. open a policy on it. */
3674 if (!get_lsa_policy_samr_sid(p, pol, &sid, &acc_granted, &disp_info))
3675 return NT_STATUS_INVALID_HANDLE;
3678 #if 0 /* this really should be applied on a per info level basis --jerry */
3680 /* observed when joining XP client to Samba domain */
3681 acc_required = SA_RIGHT_USER_SET_PASSWORD | SA_RIGHT_USER_SET_ATTRIBUTES | SA_RIGHT_USER_ACCT_FLAGS_EXPIRY;
3683 acc_required = SA_RIGHT_USER_SET_ATTRIBUTES;
3686 if (!NT_STATUS_IS_OK(r_u->status = access_check_samr_function(acc_granted, acc_required, "_samr_set_userinfo2"))) {
3690 DEBUG(5, ("samr_reply_set_userinfo2: sid:%s\n",
3691 sid_string_dbg(&sid)));
3694 DEBUG(5, ("samr_reply_set_userinfo2: NULL info level\n"));
3695 return NT_STATUS_INVALID_INFO_CLASS;
3698 switch_value=ctr->switch_value;
3700 if ( !(pwd = samu_new( NULL )) ) {
3701 return NT_STATUS_NO_MEMORY;
3705 ret = pdb_getsampwsid(pwd, &sid);
3710 return NT_STATUS_NO_SUCH_USER;
3713 acb_info = pdb_get_acct_ctrl(pwd);
3714 if ( acb_info & ACB_WSTRUST )
3715 has_enough_rights = user_has_privileges( p->pipe_user.nt_user_token, &se_machine_account);
3716 else if ( acb_info & ACB_NORMAL )
3717 has_enough_rights = user_has_privileges( p->pipe_user.nt_user_token, &se_add_users );
3718 else if ( acb_info & (ACB_SVRTRUST|ACB_DOMTRUST) ) {
3719 if ( lp_enable_privileges() )
3720 has_enough_rights = nt_token_check_domain_rid( p->pipe_user.nt_user_token, DOMAIN_GROUP_RID_ADMINS );
3723 DEBUG(5, ("_samr_set_userinfo2: %s does%s possess sufficient rights\n",
3724 uidtoname(p->pipe_user.ut.uid),
3725 has_enough_rights ? "" : " not"));
3727 /* ================ BEGIN SeMachineAccountPrivilege BLOCK ================ */
3729 if ( has_enough_rights )
3732 /* ok! user info levels (lots: see MSDEV help), off we go... */
3734 switch (switch_value) {
3736 r_u->status = set_user_info_7(p->mem_ctx,
3737 ctr->info.id7, pwd);
3740 if (!set_user_info_16(ctr->info.id16, pwd))
3741 r_u->status = NT_STATUS_ACCESS_DENIED;
3744 /* Used by AS/U JRA. */
3745 if (!set_user_info_18(ctr->info.id18, pwd))
3746 r_u->status = NT_STATUS_ACCESS_DENIED;
3749 if (!set_user_info_20(ctr->info.id20, pwd))
3750 r_u->status = NT_STATUS_ACCESS_DENIED;
3753 r_u->status = set_user_info_21(p->mem_ctx,
3754 ctr->info.id21, pwd);
3757 if (!p->session_key.length) {
3758 r_u->status = NT_STATUS_NO_USER_SESSION_KEY;
3760 SamOEMhashBlob(ctr->info.id23->pass, 516, &p->session_key);
3762 dump_data(100, ctr->info.id23->pass, 516);
3764 r_u->status = set_user_info_23(p->mem_ctx,
3765 ctr->info.id23, pwd);
3768 if (!p->session_key.length) {
3769 r_u->status = NT_STATUS_NO_USER_SESSION_KEY;
3771 encode_or_decode_arc4_passwd_buffer(ctr->info.id26->pass, &p->session_key);
3773 dump_data(100, ctr->info.id26->pass, 516);
3775 if (!set_user_info_pw(ctr->info.id26->pass, pwd))
3776 r_u->status = NT_STATUS_ACCESS_DENIED;
3779 r_u->status = NT_STATUS_INVALID_INFO_CLASS;
3782 if ( has_enough_rights )
3785 /* ================ END SeMachineAccountPrivilege BLOCK ================ */
3787 if (NT_STATUS_IS_OK(r_u->status)) {
3788 force_flush_samr_cache(disp_info);
3794 /*********************************************************************
3795 _samr_query_aliasmem
3796 *********************************************************************/
3798 NTSTATUS _samr_query_useraliases(pipes_struct *p, SAMR_Q_QUERY_USERALIASES *q_u, SAMR_R_QUERY_USERALIASES *r_u)
3800 size_t num_alias_rids;
3802 struct samr_info *info = NULL;
3810 r_u->status = NT_STATUS_OK;
3812 DEBUG(5,("_samr_query_useraliases: %d\n", __LINE__));
3814 /* find the policy handle. open a policy on it. */
3815 if (!find_policy_by_hnd(p, &q_u->pol, (void **)(void *)&info))
3816 return NT_STATUS_INVALID_HANDLE;
3818 ntstatus1 = access_check_samr_function(info->acc_granted, SA_RIGHT_DOMAIN_LOOKUP_ALIAS_BY_MEM, "_samr_query_useraliases");
3819 ntstatus2 = access_check_samr_function(info->acc_granted, SA_RIGHT_DOMAIN_OPEN_ACCOUNT, "_samr_query_useraliases");
3821 if (!NT_STATUS_IS_OK(ntstatus1) || !NT_STATUS_IS_OK(ntstatus2)) {
3822 if (!(NT_STATUS_EQUAL(ntstatus1,NT_STATUS_ACCESS_DENIED) && NT_STATUS_IS_OK(ntstatus2)) &&
3823 !(NT_STATUS_EQUAL(ntstatus1,NT_STATUS_ACCESS_DENIED) && NT_STATUS_IS_OK(ntstatus1))) {
3824 return (NT_STATUS_IS_OK(ntstatus1)) ? ntstatus2 : ntstatus1;
3828 if (!sid_check_is_domain(&info->sid) &&
3829 !sid_check_is_builtin(&info->sid))
3830 return NT_STATUS_OBJECT_TYPE_MISMATCH;
3832 if (q_u->num_sids1) {
3833 members = TALLOC_ARRAY(p->mem_ctx, DOM_SID, q_u->num_sids1);
3835 if (members == NULL)
3836 return NT_STATUS_NO_MEMORY;
3841 for (i=0; i<q_u->num_sids1; i++)
3842 sid_copy(&members[i], &q_u->sid[i].sid);
3848 ntstatus1 = pdb_enum_alias_memberships(p->mem_ctx, &info->sid, members,
3850 &alias_rids, &num_alias_rids);
3853 if (!NT_STATUS_IS_OK(ntstatus1)) {
3857 init_samr_r_query_useraliases(r_u, num_alias_rids, alias_rids,
3859 return NT_STATUS_OK;
3862 /*********************************************************************
3863 _samr_query_aliasmem
3864 *********************************************************************/
3866 NTSTATUS _samr_query_aliasmem(pipes_struct *p, SAMR_Q_QUERY_ALIASMEM *q_u, SAMR_R_QUERY_ALIASMEM *r_u)
3870 size_t num_sids = 0;
3878 /* find the policy handle. open a policy on it. */
3879 if (!get_lsa_policy_samr_sid(p, &q_u->alias_pol, &alias_sid, &acc_granted, NULL))
3880 return NT_STATUS_INVALID_HANDLE;
3882 if (!NT_STATUS_IS_OK(r_u->status =
3883 access_check_samr_function(acc_granted, SA_RIGHT_ALIAS_GET_MEMBERS, "_samr_query_aliasmem"))) {
3887 DEBUG(10, ("sid is %s\n", sid_string_dbg(&alias_sid)));
3890 status = pdb_enum_aliasmem(&alias_sid, &sids, &num_sids);
3893 if (!NT_STATUS_IS_OK(status)) {
3898 sid = TALLOC_ZERO_ARRAY(p->mem_ctx, DOM_SID2, num_sids);
3901 return NT_STATUS_NO_MEMORY;
3907 for (i = 0; i < num_sids; i++) {
3908 init_dom_sid2(&sid[i], &sids[i]);
3911 init_samr_r_query_aliasmem(r_u, num_sids, sid, NT_STATUS_OK);
3915 return NT_STATUS_OK;
3918 /*********************************************************************
3919 _samr_query_groupmem
3920 *********************************************************************/
3922 NTSTATUS _samr_query_groupmem(pipes_struct *p, SAMR_Q_QUERY_GROUPMEM *q_u, SAMR_R_QUERY_GROUPMEM *r_u)
3925 size_t i, num_members;
3934 /* find the policy handle. open a policy on it. */
3935 if (!get_lsa_policy_samr_sid(p, &q_u->group_pol, &group_sid, &acc_granted, NULL))
3936 return NT_STATUS_INVALID_HANDLE;
3938 if (!NT_STATUS_IS_OK(r_u->status = access_check_samr_function(acc_granted, SA_RIGHT_GROUP_GET_MEMBERS, "_samr_query_groupmem"))) {
3942 DEBUG(10, ("sid is %s\n", sid_string_dbg(&group_sid)));
3944 if (!sid_check_is_in_our_domain(&group_sid)) {
3945 DEBUG(3, ("sid %s is not in our domain\n",
3946 sid_string_dbg(&group_sid)));
3947 return NT_STATUS_NO_SUCH_GROUP;
3950 DEBUG(10, ("lookup on Domain SID\n"));
3953 result = pdb_enum_group_members(p->mem_ctx, &group_sid,
3954 &rid, &num_members);
3957 if (!NT_STATUS_IS_OK(result))
3961 attr=TALLOC_ZERO_ARRAY(p->mem_ctx, uint32, num_members);
3963 return NT_STATUS_NO_MEMORY;
3969 for (i=0; i<num_members; i++)
3970 attr[i] = SID_NAME_USER;
3972 init_samr_r_query_groupmem(r_u, num_members, rid, attr, NT_STATUS_OK);
3974 return NT_STATUS_OK;
3977 /*********************************************************************
3979 *********************************************************************/
3981 NTSTATUS _samr_add_aliasmem(pipes_struct *p, SAMR_Q_ADD_ALIASMEM *q_u, SAMR_R_ADD_ALIASMEM *r_u)
3986 bool can_add_accounts;
3988 DISP_INFO *disp_info = NULL;
3990 /* Find the policy handle. Open a policy on it. */
3991 if (!get_lsa_policy_samr_sid(p, &q_u->alias_pol, &alias_sid, &acc_granted, &disp_info))
3992 return NT_STATUS_INVALID_HANDLE;
3994 if (!NT_STATUS_IS_OK(r_u->status = access_check_samr_function(acc_granted, SA_RIGHT_ALIAS_ADD_MEMBER, "_samr_add_aliasmem"))) {
3998 DEBUG(10, ("sid is %s\n", sid_string_dbg(&alias_sid)));
4000 se_priv_copy( &se_rights, &se_add_users );
4001 can_add_accounts = user_has_privileges( p->pipe_user.nt_user_token, &se_rights );
4003 /******** BEGIN SeAddUsers BLOCK *********/
4005 if ( can_add_accounts )
4008 ret = pdb_add_aliasmem(&alias_sid, &q_u->sid.sid);
4010 if ( can_add_accounts )
4013 /******** END SeAddUsers BLOCK *********/
4015 if (NT_STATUS_IS_OK(ret)) {
4016 force_flush_samr_cache(disp_info);
4022 /*********************************************************************
4024 *********************************************************************/
4026 NTSTATUS _samr_del_aliasmem(pipes_struct *p, SAMR_Q_DEL_ALIASMEM *q_u, SAMR_R_DEL_ALIASMEM *r_u)
4031 bool can_add_accounts;
4033 DISP_INFO *disp_info = NULL;
4035 /* Find the policy handle. Open a policy on it. */
4036 if (!get_lsa_policy_samr_sid(p, &q_u->alias_pol, &alias_sid, &acc_granted, &disp_info))
4037 return NT_STATUS_INVALID_HANDLE;
4039 if (!NT_STATUS_IS_OK(r_u->status = access_check_samr_function(acc_granted, SA_RIGHT_ALIAS_REMOVE_MEMBER, "_samr_del_aliasmem"))) {
4043 DEBUG(10, ("_samr_del_aliasmem:sid is %s\n",
4044 sid_string_dbg(&alias_sid)));
4046 se_priv_copy( &se_rights, &se_add_users );
4047 can_add_accounts = user_has_privileges( p->pipe_user.nt_user_token, &se_rights );
4049 /******** BEGIN SeAddUsers BLOCK *********/
4051 if ( can_add_accounts )
4054 ret = pdb_del_aliasmem(&alias_sid, &q_u->sid.sid);
4056 if ( can_add_accounts )
4059 /******** END SeAddUsers BLOCK *********/
4061 if (NT_STATUS_IS_OK(ret)) {
4062 force_flush_samr_cache(disp_info);
4068 /*********************************************************************
4070 *********************************************************************/
4072 NTSTATUS _samr_add_groupmem(pipes_struct *p, SAMR_Q_ADD_GROUPMEM *q_u, SAMR_R_ADD_GROUPMEM *r_u)
4078 bool can_add_accounts;
4079 DISP_INFO *disp_info = NULL;
4081 /* Find the policy handle. Open a policy on it. */
4082 if (!get_lsa_policy_samr_sid(p, &q_u->pol, &group_sid, &acc_granted, &disp_info))
4083 return NT_STATUS_INVALID_HANDLE;
4085 if (!NT_STATUS_IS_OK(r_u->status = access_check_samr_function(acc_granted, SA_RIGHT_GROUP_ADD_MEMBER, "_samr_add_groupmem"))) {
4089 DEBUG(10, ("sid is %s\n", sid_string_dbg(&group_sid)));
4091 if (!sid_peek_check_rid(get_global_sam_sid(), &group_sid,
4093 return NT_STATUS_INVALID_HANDLE;
4096 se_priv_copy( &se_rights, &se_add_users );
4097 can_add_accounts = user_has_privileges( p->pipe_user.nt_user_token, &se_rights );
4099 /******** BEGIN SeAddUsers BLOCK *********/
4101 if ( can_add_accounts )
4104 r_u->status = pdb_add_groupmem(p->mem_ctx, group_rid, q_u->rid);
4106 if ( can_add_accounts )
4109 /******** END SeAddUsers BLOCK *********/
4111 force_flush_samr_cache(disp_info);
4116 /*********************************************************************
4118 *********************************************************************/
4120 NTSTATUS _samr_del_groupmem(pipes_struct *p, SAMR_Q_DEL_GROUPMEM *q_u, SAMR_R_DEL_GROUPMEM *r_u)
4126 bool can_add_accounts;
4127 DISP_INFO *disp_info = NULL;
4130 * delete the group member named q_u->rid
4131 * who is a member of the sid associated with the handle
4132 * the rid is a user's rid as the group is a domain group.
4135 /* Find the policy handle. Open a policy on it. */
4136 if (!get_lsa_policy_samr_sid(p, &q_u->pol, &group_sid, &acc_granted, &disp_info))
4137 return NT_STATUS_INVALID_HANDLE;
4139 if (!NT_STATUS_IS_OK(r_u->status = access_check_samr_function(acc_granted, SA_RIGHT_GROUP_REMOVE_MEMBER, "_samr_del_groupmem"))) {
4143 if (!sid_peek_check_rid(get_global_sam_sid(), &group_sid,
4145 return NT_STATUS_INVALID_HANDLE;
4148 se_priv_copy( &se_rights, &se_add_users );
4149 can_add_accounts = user_has_privileges( p->pipe_user.nt_user_token, &se_rights );
4151 /******** BEGIN SeAddUsers BLOCK *********/
4153 if ( can_add_accounts )
4156 r_u->status = pdb_del_groupmem(p->mem_ctx, group_rid, q_u->rid);
4158 if ( can_add_accounts )
4161 /******** END SeAddUsers BLOCK *********/
4163 force_flush_samr_cache(disp_info);
4168 /*********************************************************************
4170 *********************************************************************/
4172 NTSTATUS _samr_DeleteUser(pipes_struct *p,
4173 struct samr_DeleteUser *r)
4177 struct samu *sam_pass=NULL;
4179 bool can_add_accounts;
4181 DISP_INFO *disp_info = NULL;
4184 DEBUG(5, ("_samr_DeleteUser: %d\n", __LINE__));
4186 /* Find the policy handle. Open a policy on it. */
4187 if (!get_lsa_policy_samr_sid(p, r->in.user_handle, &user_sid, &acc_granted, &disp_info))
4188 return NT_STATUS_INVALID_HANDLE;
4190 status = access_check_samr_function(acc_granted, STD_RIGHT_DELETE_ACCESS, "_samr_DeleteUser");
4191 if (!NT_STATUS_IS_OK(status)) {
4195 if (!sid_check_is_in_our_domain(&user_sid))
4196 return NT_STATUS_CANNOT_DELETE;
4198 /* check if the user exists before trying to delete */
4199 if ( !(sam_pass = samu_new( NULL )) ) {
4200 return NT_STATUS_NO_MEMORY;
4204 ret = pdb_getsampwsid(sam_pass, &user_sid);
4208 DEBUG(5,("_samr_DeleteUser: User %s doesn't exist.\n",
4209 sid_string_dbg(&user_sid)));
4210 TALLOC_FREE(sam_pass);
4211 return NT_STATUS_NO_SUCH_USER;
4214 acb_info = pdb_get_acct_ctrl(sam_pass);
4216 /* For machine accounts it's the SeMachineAccountPrivilege that counts. */
4217 if ( acb_info & ACB_WSTRUST ) {
4218 can_add_accounts = user_has_privileges( p->pipe_user.nt_user_token, &se_machine_account );
4220 can_add_accounts = user_has_privileges( p->pipe_user.nt_user_token, &se_add_users );
4223 /******** BEGIN SeAddUsers BLOCK *********/
4225 if ( can_add_accounts )
4228 status = pdb_delete_user(p->mem_ctx, sam_pass);
4230 if ( can_add_accounts )
4233 /******** END SeAddUsers BLOCK *********/
4235 if ( !NT_STATUS_IS_OK(status) ) {
4236 DEBUG(5,("_samr_DeleteUser: Failed to delete entry for "
4237 "user %s: %s.\n", pdb_get_username(sam_pass),
4238 nt_errstr(status)));
4239 TALLOC_FREE(sam_pass);
4244 TALLOC_FREE(sam_pass);
4246 if (!close_policy_hnd(p, r->in.user_handle))
4247 return NT_STATUS_OBJECT_NAME_INVALID;
4249 force_flush_samr_cache(disp_info);
4251 return NT_STATUS_OK;
4254 /*********************************************************************
4255 _samr_DeleteDomainGroup
4256 *********************************************************************/
4258 NTSTATUS _samr_DeleteDomainGroup(pipes_struct *p,
4259 struct samr_DeleteDomainGroup *r)
4266 bool can_add_accounts;
4267 DISP_INFO *disp_info = NULL;
4269 DEBUG(5, ("samr_DeleteDomainGroup: %d\n", __LINE__));
4271 /* Find the policy handle. Open a policy on it. */
4272 if (!get_lsa_policy_samr_sid(p, r->in.group_handle, &group_sid, &acc_granted, &disp_info))
4273 return NT_STATUS_INVALID_HANDLE;
4275 status = access_check_samr_function(acc_granted, STD_RIGHT_DELETE_ACCESS, "_samr_DeleteDomainGroup");
4276 if (!NT_STATUS_IS_OK(status)) {
4280 DEBUG(10, ("sid is %s\n", sid_string_dbg(&group_sid)));
4282 if (!sid_peek_check_rid(get_global_sam_sid(), &group_sid,
4284 return NT_STATUS_NO_SUCH_GROUP;
4287 se_priv_copy( &se_rights, &se_add_users );
4288 can_add_accounts = user_has_privileges( p->pipe_user.nt_user_token, &se_rights );
4290 /******** BEGIN SeAddUsers BLOCK *********/
4292 if ( can_add_accounts )
4295 status = pdb_delete_dom_group(p->mem_ctx, group_rid);
4297 if ( can_add_accounts )
4300 /******** END SeAddUsers BLOCK *********/
4302 if ( !NT_STATUS_IS_OK(status) ) {
4303 DEBUG(5,("_samr_DeleteDomainGroup: Failed to delete mapping "
4304 "entry for group %s: %s\n",
4305 sid_string_dbg(&group_sid),
4306 nt_errstr(status)));
4310 if (!close_policy_hnd(p, r->in.group_handle))
4311 return NT_STATUS_OBJECT_NAME_INVALID;
4313 force_flush_samr_cache(disp_info);
4315 return NT_STATUS_OK;
4318 /*********************************************************************
4319 _samr_DeleteDomAlias
4320 *********************************************************************/
4322 NTSTATUS _samr_DeleteDomAlias(pipes_struct *p,
4323 struct samr_DeleteDomAlias *r)
4328 bool can_add_accounts;
4330 DISP_INFO *disp_info = NULL;
4332 DEBUG(5, ("_samr_DeleteDomAlias: %d\n", __LINE__));
4334 /* Find the policy handle. Open a policy on it. */
4335 if (!get_lsa_policy_samr_sid(p, r->in.alias_handle, &alias_sid, &acc_granted, &disp_info))
4336 return NT_STATUS_INVALID_HANDLE;
4338 /* copy the handle to the outgoing reply */
4340 memcpy(r->out.alias_handle, r->in.alias_handle, sizeof(r->out.alias_handle));
4342 status = access_check_samr_function(acc_granted, STD_RIGHT_DELETE_ACCESS, "_samr_DeleteDomAlias");
4343 if (!NT_STATUS_IS_OK(status)) {
4347 DEBUG(10, ("sid is %s\n", sid_string_dbg(&alias_sid)));
4349 /* Don't let Windows delete builtin groups */
4351 if ( sid_check_is_in_builtin( &alias_sid ) ) {
4352 return NT_STATUS_SPECIAL_ACCOUNT;
4355 if (!sid_check_is_in_our_domain(&alias_sid))
4356 return NT_STATUS_NO_SUCH_ALIAS;
4358 DEBUG(10, ("lookup on Local SID\n"));
4360 se_priv_copy( &se_rights, &se_add_users );
4361 can_add_accounts = user_has_privileges( p->pipe_user.nt_user_token, &se_rights );
4363 /******** BEGIN SeAddUsers BLOCK *********/
4365 if ( can_add_accounts )
4368 /* Have passdb delete the alias */
4369 status = pdb_delete_alias(&alias_sid);
4371 if ( can_add_accounts )
4374 /******** END SeAddUsers BLOCK *********/
4376 if ( !NT_STATUS_IS_OK(status))
4379 if (!close_policy_hnd(p, r->in.alias_handle))
4380 return NT_STATUS_OBJECT_NAME_INVALID;
4382 force_flush_samr_cache(disp_info);
4384 return NT_STATUS_OK;
4387 /*********************************************************************
4388 _samr_CreateDomainGroup
4389 *********************************************************************/
4391 NTSTATUS _samr_CreateDomainGroup(pipes_struct *p,
4392 struct samr_CreateDomainGroup *r)
4399 struct samr_info *info;
4402 bool can_add_accounts;
4403 DISP_INFO *disp_info = NULL;
4405 /* Find the policy handle. Open a policy on it. */
4406 if (!get_lsa_policy_samr_sid(p, r->in.domain_handle, &dom_sid, &acc_granted, &disp_info))
4407 return NT_STATUS_INVALID_HANDLE;
4409 status = access_check_samr_function(acc_granted, SA_RIGHT_DOMAIN_CREATE_GROUP, "_samr_CreateDomainGroup");
4410 if (!NT_STATUS_IS_OK(status)) {
4414 if (!sid_equal(&dom_sid, get_global_sam_sid()))
4415 return NT_STATUS_ACCESS_DENIED;
4417 name = r->in.name->string;
4419 return NT_STATUS_NO_MEMORY;
4422 status = can_create(p->mem_ctx, name);
4423 if (!NT_STATUS_IS_OK(status)) {
4427 se_priv_copy( &se_rights, &se_add_users );
4428 can_add_accounts = user_has_privileges( p->pipe_user.nt_user_token, &se_rights );
4430 /******** BEGIN SeAddUsers BLOCK *********/
4432 if ( can_add_accounts )
4435 /* check that we successfully create the UNIX group */
4437 status = pdb_create_dom_group(p->mem_ctx, name, r->out.rid);
4439 if ( can_add_accounts )
4442 /******** END SeAddUsers BLOCK *********/
4444 /* check if we should bail out here */
4446 if ( !NT_STATUS_IS_OK(status) )
4449 sid_compose(&info_sid, get_global_sam_sid(), *r->out.rid);
4451 if ((info = get_samr_info_by_sid(&info_sid)) == NULL)
4452 return NT_STATUS_NO_MEMORY;
4454 /* they created it; let the user do what he wants with it */
4456 info->acc_granted = GENERIC_RIGHTS_GROUP_ALL_ACCESS;
4458 /* get a (unique) handle. open a policy on it. */
4459 if (!create_policy_hnd(p, r->out.group_handle, free_samr_info, (void *)info))
4460 return NT_STATUS_OBJECT_NAME_NOT_FOUND;
4462 force_flush_samr_cache(disp_info);
4464 return NT_STATUS_OK;
4467 /*********************************************************************
4468 _samr_CreateDomAlias
4469 *********************************************************************/
4471 NTSTATUS _samr_CreateDomAlias(pipes_struct *p,
4472 struct samr_CreateDomAlias *r)
4476 const char *name = NULL;
4477 struct samr_info *info;
4482 bool can_add_accounts;
4483 DISP_INFO *disp_info = NULL;
4485 /* Find the policy handle. Open a policy on it. */
4486 if (!get_lsa_policy_samr_sid(p, r->in.domain_handle, &dom_sid, &acc_granted, &disp_info))
4487 return NT_STATUS_INVALID_HANDLE;
4489 result = access_check_samr_function(acc_granted, SA_RIGHT_DOMAIN_CREATE_ALIAS, "_samr_CreateDomAlias");
4490 if (!NT_STATUS_IS_OK(result)) {
4494 if (!sid_equal(&dom_sid, get_global_sam_sid()))
4495 return NT_STATUS_ACCESS_DENIED;
4497 name = r->in.alias_name->string;
4499 se_priv_copy( &se_rights, &se_add_users );
4500 can_add_accounts = user_has_privileges( p->pipe_user.nt_user_token, &se_rights );
4502 result = can_create(p->mem_ctx, name);
4503 if (!NT_STATUS_IS_OK(result)) {
4507 /******** BEGIN SeAddUsers BLOCK *********/
4509 if ( can_add_accounts )
4512 /* Have passdb create the alias */
4513 result = pdb_create_alias(name, r->out.rid);
4515 if ( can_add_accounts )
4518 /******** END SeAddUsers BLOCK *********/
4520 if (!NT_STATUS_IS_OK(result)) {
4521 DEBUG(10, ("pdb_create_alias failed: %s\n",
4522 nt_errstr(result)));
4526 sid_copy(&info_sid, get_global_sam_sid());
4527 sid_append_rid(&info_sid, *r->out.rid);
4529 if (!sid_to_gid(&info_sid, &gid)) {
4530 DEBUG(10, ("Could not find alias just created\n"));
4531 return NT_STATUS_ACCESS_DENIED;
4534 /* check if the group has been successfully created */
4535 if ( getgrgid(gid) == NULL ) {
4536 DEBUG(10, ("getgrgid(%d) of just created alias failed\n",
4538 return NT_STATUS_ACCESS_DENIED;
4541 if ((info = get_samr_info_by_sid(&info_sid)) == NULL)
4542 return NT_STATUS_NO_MEMORY;
4544 /* they created it; let the user do what he wants with it */
4546 info->acc_granted = GENERIC_RIGHTS_ALIAS_ALL_ACCESS;
4548 /* get a (unique) handle. open a policy on it. */
4549 if (!create_policy_hnd(p, r->out.alias_handle, free_samr_info, (void *)info))
4550 return NT_STATUS_OBJECT_NAME_NOT_FOUND;
4552 force_flush_samr_cache(disp_info);
4554 return NT_STATUS_OK;
4557 /*********************************************************************
4558 _samr_query_groupinfo
4560 sends the name/comment pair of a domain group
4561 level 1 send also the number of users of that group
4562 *********************************************************************/
4564 NTSTATUS _samr_query_groupinfo(pipes_struct *p, SAMR_Q_QUERY_GROUPINFO *q_u, SAMR_R_QUERY_GROUPINFO *r_u)
4568 GROUP_INFO_CTR *ctr;
4572 if (!get_lsa_policy_samr_sid(p, &q_u->pol, &group_sid, &acc_granted, NULL))
4573 return NT_STATUS_INVALID_HANDLE;
4575 if (!NT_STATUS_IS_OK(r_u->status = access_check_samr_function(acc_granted, SA_RIGHT_GROUP_LOOKUP_INFO, "_samr_query_groupinfo"))) {
4580 ret = get_domain_group_from_sid(group_sid, &map);
4583 return NT_STATUS_INVALID_HANDLE;
4585 ctr=TALLOC_ZERO_P(p->mem_ctx, GROUP_INFO_CTR);
4587 return NT_STATUS_NO_MEMORY;
4589 switch (q_u->switch_level) {
4594 ctr->switch_value1 = 1;
4597 r_u->status = pdb_enum_group_members(
4598 p->mem_ctx, &group_sid, &members, &num_members);
4601 if (!NT_STATUS_IS_OK(r_u->status)) {
4605 init_samr_group_info1(&ctr->group.info1, map.nt_name,
4606 map.comment, num_members);
4610 ctr->switch_value1 = 2;
4611 init_samr_group_info2(&ctr->group.info2, map.nt_name);
4614 ctr->switch_value1 = 3;
4615 init_samr_group_info3(&ctr->group.info3);
4618 ctr->switch_value1 = 4;
4619 init_samr_group_info4(&ctr->group.info4, map.comment);
4627 ctr->switch_value1 = 5;
4631 r_u->status = pdb_enum_group_members(
4632 p->mem_ctx, &group_sid, &members, &num_members);
4635 if (!NT_STATUS_IS_OK(r_u->status)) {
4639 init_samr_group_info5(&ctr->group.info5, map.nt_name,
4640 map.comment, 0 /* num_members */); /* in w2k3 this is always 0 */
4644 return NT_STATUS_INVALID_INFO_CLASS;
4647 init_samr_r_query_groupinfo(r_u, ctr, NT_STATUS_OK);
4649 return NT_STATUS_OK;
4652 /*********************************************************************
4655 update a domain group's comment.
4656 *********************************************************************/
4658 NTSTATUS _samr_set_groupinfo(pipes_struct *p, SAMR_Q_SET_GROUPINFO *q_u, SAMR_R_SET_GROUPINFO *r_u)
4662 GROUP_INFO_CTR *ctr;
4666 bool can_mod_accounts;
4667 DISP_INFO *disp_info = NULL;
4669 if (!get_lsa_policy_samr_sid(p, &q_u->pol, &group_sid, &acc_granted, &disp_info))
4670 return NT_STATUS_INVALID_HANDLE;
4672 if (!NT_STATUS_IS_OK(r_u->status = access_check_samr_function(acc_granted, SA_RIGHT_GROUP_SET_INFO, "_samr_set_groupinfo"))) {
4677 result = get_domain_group_from_sid(group_sid, &map);
4680 return NT_STATUS_NO_SUCH_GROUP;
4684 switch (ctr->switch_value1) {
4686 unistr2_to_ascii(map.comment, &(ctr->group.info1.uni_acct_desc), sizeof(map.comment));
4689 unistr2_to_ascii(map.comment, &(ctr->group.info4.uni_acct_desc), sizeof(map.comment));
4692 return NT_STATUS_INVALID_INFO_CLASS;
4695 can_mod_accounts = user_has_privileges( p->pipe_user.nt_user_token, &se_add_users );
4697 /******** BEGIN SeAddUsers BLOCK *********/
4699 if ( can_mod_accounts )
4702 ret = pdb_update_group_mapping_entry(&map);
4704 if ( can_mod_accounts )
4707 /******** End SeAddUsers BLOCK *********/
4709 if (NT_STATUS_IS_OK(ret)) {
4710 force_flush_samr_cache(disp_info);
4716 /*********************************************************************
4719 update an alias's comment.
4720 *********************************************************************/
4722 NTSTATUS _samr_set_aliasinfo(pipes_struct *p, SAMR_Q_SET_ALIASINFO *q_u, SAMR_R_SET_ALIASINFO *r_u)
4725 struct acct_info info;
4726 ALIAS_INFO_CTR *ctr;
4728 bool can_mod_accounts;
4730 DISP_INFO *disp_info = NULL;
4732 if (!get_lsa_policy_samr_sid(p, &q_u->alias_pol, &group_sid, &acc_granted, &disp_info))
4733 return NT_STATUS_INVALID_HANDLE;
4735 if (!NT_STATUS_IS_OK(r_u->status = access_check_samr_function(acc_granted, SA_RIGHT_ALIAS_SET_INFO, "_samr_set_aliasinfo"))) {
4741 /* get the current group information */
4744 status = pdb_get_aliasinfo( &group_sid, &info );
4747 if ( !NT_STATUS_IS_OK(status))
4750 switch (ctr->level) {
4753 fstring group_name, acct_name;
4755 /* We currently do not support renaming groups in the
4756 the BUILTIN domain. Refer to util_builtin.c to understand
4757 why. The eventually needs to be fixed to be like Windows
4758 where you can rename builtin groups, just not delete them */
4760 if ( sid_check_is_in_builtin( &group_sid ) ) {
4761 return NT_STATUS_SPECIAL_ACCOUNT;
4764 /* There has to be a valid name (and it has to be different) */
4766 if ( !ctr->alias.info2.name.string )
4767 return NT_STATUS_INVALID_PARAMETER;
4769 unistr2_to_ascii( acct_name, ctr->alias.info2.name.string,
4772 /* If the name is the same just reply "ok". Yes this
4773 doesn't allow you to change the case of a group name. */
4775 if ( strequal( acct_name, info.acct_name ) )
4776 return NT_STATUS_OK;
4778 fstrcpy( info.acct_name, acct_name );
4780 /* make sure the name doesn't already exist as a user
4783 fstr_sprintf( group_name, "%s\\%s", global_myname(), info.acct_name );
4784 status = can_create( p->mem_ctx, group_name );
4785 if ( !NT_STATUS_IS_OK( status ) )
4790 if ( ctr->alias.info3.description.string ) {
4791 unistr2_to_ascii( info.acct_desc,
4792 ctr->alias.info3.description.string,
4793 sizeof(info.acct_desc));
4796 fstrcpy( info.acct_desc, "" );
4799 return NT_STATUS_INVALID_INFO_CLASS;
4802 can_mod_accounts = user_has_privileges( p->pipe_user.nt_user_token, &se_add_users );
4804 /******** BEGIN SeAddUsers BLOCK *********/
4806 if ( can_mod_accounts )
4809 status = pdb_set_aliasinfo( &group_sid, &info );
4811 if ( can_mod_accounts )
4814 /******** End SeAddUsers BLOCK *********/
4816 if (NT_STATUS_IS_OK(status))
4817 force_flush_samr_cache(disp_info);
4822 /****************************************************************
4824 ****************************************************************/
4826 NTSTATUS _samr_GetDomPwInfo(pipes_struct *p,
4827 struct samr_GetDomPwInfo *r)
4829 /* Perform access check. Since this rpc does not require a
4830 policy handle it will not be caught by the access checks on
4831 SAMR_CONNECT or SAMR_CONNECT_ANON. */
4833 if (!pipe_access_check(p)) {
4834 DEBUG(3, ("access denied to _samr_GetDomPwInfo\n"));
4835 return NT_STATUS_ACCESS_DENIED;
4838 /* Actually, returning zeros here works quite well :-). */
4839 ZERO_STRUCTP(r->out.info);
4841 return NT_STATUS_OK;
4844 /*********************************************************************
4846 *********************************************************************/
4848 NTSTATUS _samr_OpenGroup(pipes_struct *p,
4849 struct samr_OpenGroup *r)
4855 struct samr_info *info;
4856 SEC_DESC *psd = NULL;
4858 uint32 des_access = r->in.access_mask;
4865 if (!get_lsa_policy_samr_sid(p, r->in.domain_handle, &sid, &acc_granted, NULL))
4866 return NT_STATUS_INVALID_HANDLE;
4868 status = access_check_samr_function(acc_granted,
4869 SA_RIGHT_DOMAIN_OPEN_ACCOUNT, "_samr_OpenGroup");
4871 if ( !NT_STATUS_IS_OK(status) )
4874 /*check if access can be granted as requested by client. */
4875 make_samr_object_sd(p->mem_ctx, &psd, &sd_size, &grp_generic_mapping, NULL, 0);
4876 se_map_generic(&des_access,&grp_generic_mapping);
4878 se_priv_copy( &se_rights, &se_add_users );
4880 status = access_check_samr_object(psd, p->pipe_user.nt_user_token,
4881 &se_rights, GENERIC_RIGHTS_GROUP_WRITE, des_access,
4882 &acc_granted, "_samr_OpenGroup");
4884 if ( !NT_STATUS_IS_OK(status) )
4887 /* this should not be hard-coded like this */
4889 if (!sid_equal(&sid, get_global_sam_sid()))
4890 return NT_STATUS_ACCESS_DENIED;
4892 sid_copy(&info_sid, get_global_sam_sid());
4893 sid_append_rid(&info_sid, r->in.rid);
4894 sid_to_fstring(sid_string, &info_sid);
4896 if ((info = get_samr_info_by_sid(&info_sid)) == NULL)
4897 return NT_STATUS_NO_MEMORY;
4899 info->acc_granted = acc_granted;
4901 DEBUG(10, ("_samr_OpenGroup:Opening SID: %s\n", sid_string));
4903 /* check if that group really exists */
4905 ret = get_domain_group_from_sid(info->sid, &map);
4908 return NT_STATUS_NO_SUCH_GROUP;
4910 /* get a (unique) handle. open a policy on it. */
4911 if (!create_policy_hnd(p, r->out.group_handle, free_samr_info, (void *)info))
4912 return NT_STATUS_OBJECT_NAME_NOT_FOUND;
4914 return NT_STATUS_OK;
4917 /*********************************************************************
4918 _samr_remove_sid_foreign_domain
4919 *********************************************************************/
4921 NTSTATUS _samr_remove_sid_foreign_domain(pipes_struct *p,
4922 SAMR_Q_REMOVE_SID_FOREIGN_DOMAIN *q_u,
4923 SAMR_R_REMOVE_SID_FOREIGN_DOMAIN *r_u)
4925 DOM_SID delete_sid, domain_sid;
4928 DISP_INFO *disp_info = NULL;
4930 sid_copy( &delete_sid, &q_u->sid.sid );
4932 DEBUG(5,("_samr_remove_sid_foreign_domain: removing SID [%s]\n",
4933 sid_string_dbg(&delete_sid)));
4935 /* Find the policy handle. Open a policy on it. */
4937 if (!get_lsa_policy_samr_sid(p, &q_u->dom_pol, &domain_sid,
4938 &acc_granted, &disp_info))
4939 return NT_STATUS_INVALID_HANDLE;
4941 result = access_check_samr_function(acc_granted, STD_RIGHT_DELETE_ACCESS,
4942 "_samr_remove_sid_foreign_domain");
4944 if (!NT_STATUS_IS_OK(result))
4947 DEBUG(8, ("_samr_remove_sid_foreign_domain:sid is %s\n",
4948 sid_string_dbg(&domain_sid)));
4950 /* we can only delete a user from a group since we don't have
4951 nested groups anyways. So in the latter case, just say OK */
4953 /* TODO: The above comment nowadays is bogus. Since we have nested
4954 * groups now, and aliases members are never reported out of the unix
4955 * group membership, the "just say OK" makes this call a no-op. For
4956 * us. This needs fixing however. */
4958 /* I've only ever seen this in the wild when deleting a user from
4959 * usrmgr.exe. domain_sid is the builtin domain, and the sid to delete
4960 * is the user about to be deleted. I very much suspect this is the
4961 * only application of this call. To verify this, let people report
4964 if (!sid_check_is_builtin(&domain_sid)) {
4965 DEBUG(1,("_samr_remove_sid_foreign_domain: domain_sid = %s, "
4966 "global_sam_sid() = %s\n",
4967 sid_string_dbg(&domain_sid),
4968 sid_string_dbg(get_global_sam_sid())));
4969 DEBUGADD(1,("please report to samba-technical@samba.org!\n"));
4970 return NT_STATUS_OK;
4973 force_flush_samr_cache(disp_info);
4975 result = NT_STATUS_OK;
4980 /*******************************************************************
4981 _samr_query_domain_info2
4982 ********************************************************************/
4984 NTSTATUS _samr_query_domain_info2(pipes_struct *p,
4985 SAMR_Q_QUERY_DOMAIN_INFO2 *q_u,
4986 SAMR_R_QUERY_DOMAIN_INFO2 *r_u)
4988 SAMR_Q_QUERY_DOMAIN_INFO q;
4989 SAMR_R_QUERY_DOMAIN_INFO r;
4994 DEBUG(5,("_samr_query_domain_info2: %d\n", __LINE__));
4996 q.domain_pol = q_u->domain_pol;
4997 q.switch_value = q_u->switch_value;
4999 r_u->status = _samr_query_domain_info(p, &q, &r);
5001 r_u->ptr_0 = r.ptr_0;
5002 r_u->switch_value = r.switch_value;
5008 /*******************************************************************
5010 ********************************************************************/
5012 NTSTATUS _samr_set_dom_info(pipes_struct *p, SAMR_Q_SET_DOMAIN_INFO *q_u, SAMR_R_SET_DOMAIN_INFO *r_u)
5014 time_t u_expire, u_min_age;
5016 time_t u_lock_duration, u_reset_time;
5018 r_u->status = NT_STATUS_OK;
5020 DEBUG(5,("_samr_set_dom_info: %d\n", __LINE__));
5022 /* find the policy handle. open a policy on it. */
5023 if (!find_policy_by_hnd(p, &q_u->domain_pol, NULL))
5024 return NT_STATUS_INVALID_HANDLE;
5026 DEBUG(5,("_samr_set_dom_info: switch_value: %d\n", q_u->switch_value));
5028 switch (q_u->switch_value) {
5030 u_expire=nt_time_to_unix_abs(&q_u->ctr->info.inf1.expire);
5031 u_min_age=nt_time_to_unix_abs(&q_u->ctr->info.inf1.min_passwordage);
5033 pdb_set_account_policy(AP_MIN_PASSWORD_LEN, (uint32)q_u->ctr->info.inf1.min_length_password);
5034 pdb_set_account_policy(AP_PASSWORD_HISTORY, (uint32)q_u->ctr->info.inf1.password_history);
5035 pdb_set_account_policy(AP_USER_MUST_LOGON_TO_CHG_PASS, (uint32)q_u->ctr->info.inf1.password_properties);
5036 pdb_set_account_policy(AP_MAX_PASSWORD_AGE, (int)u_expire);
5037 pdb_set_account_policy(AP_MIN_PASSWORD_AGE, (int)u_min_age);
5042 u_logout=nt_time_to_unix_abs(&q_u->ctr->info.inf3.logout);
5043 pdb_set_account_policy(AP_TIME_TO_LOGOUT, (int)u_logout);
5052 u_lock_duration=nt_time_to_unix_abs(&q_u->ctr->info.inf12.duration);
5053 if (u_lock_duration != -1)
5054 u_lock_duration /= 60;
5056 u_reset_time=nt_time_to_unix_abs(&q_u->ctr->info.inf12.reset_count)/60;
5058 pdb_set_account_policy(AP_LOCK_ACCOUNT_DURATION, (int)u_lock_duration);
5059 pdb_set_account_policy(AP_RESET_COUNT_TIME, (int)u_reset_time);
5060 pdb_set_account_policy(AP_BAD_ATTEMPT_LOCKOUT, (uint32)q_u->ctr->info.inf12.bad_attempt_lockout);
5063 return NT_STATUS_INVALID_INFO_CLASS;
5066 init_samr_r_set_domain_info(r_u, NT_STATUS_OK);
5068 DEBUG(5,("_samr_set_dom_info: %d\n", __LINE__));
5073 /****************************************************************
5074 ****************************************************************/
5076 NTSTATUS _samr_Connect(pipes_struct *p,
5077 struct samr_Connect *r)
5079 p->rng_fault_state = true;
5080 return NT_STATUS_NOT_IMPLEMENTED;
5083 /****************************************************************
5084 ****************************************************************/
5086 NTSTATUS _samr_SetSecurity(pipes_struct *p,
5087 struct samr_SetSecurity *r)
5089 p->rng_fault_state = true;
5090 return NT_STATUS_NOT_IMPLEMENTED;
5093 /****************************************************************
5094 ****************************************************************/
5096 NTSTATUS _samr_QuerySecurity(pipes_struct *p,
5097 struct samr_QuerySecurity *r)
5099 p->rng_fault_state = true;
5100 return NT_STATUS_NOT_IMPLEMENTED;
5103 /****************************************************************
5104 ****************************************************************/
5106 NTSTATUS _samr_Shutdown(pipes_struct *p,
5107 struct samr_Shutdown *r)
5109 p->rng_fault_state = true;
5110 return NT_STATUS_NOT_IMPLEMENTED;
5113 /****************************************************************
5114 ****************************************************************/
5116 NTSTATUS _samr_LookupDomain(pipes_struct *p,
5117 struct samr_LookupDomain *r)
5119 p->rng_fault_state = true;
5120 return NT_STATUS_NOT_IMPLEMENTED;
5123 /****************************************************************
5124 ****************************************************************/
5126 NTSTATUS _samr_EnumDomains(pipes_struct *p,
5127 struct samr_EnumDomains *r)
5129 p->rng_fault_state = true;
5130 return NT_STATUS_NOT_IMPLEMENTED;
5133 /****************************************************************
5134 ****************************************************************/
5136 NTSTATUS _samr_QueryDomainInfo(pipes_struct *p,
5137 struct samr_QueryDomainInfo *r)
5139 p->rng_fault_state = true;
5140 return NT_STATUS_NOT_IMPLEMENTED;
5143 /****************************************************************
5144 ****************************************************************/
5146 NTSTATUS _samr_SetDomainInfo(pipes_struct *p,
5147 struct samr_SetDomainInfo *r)
5149 p->rng_fault_state = true;
5150 return NT_STATUS_NOT_IMPLEMENTED;
5153 /****************************************************************
5154 ****************************************************************/
5156 NTSTATUS _samr_EnumDomainGroups(pipes_struct *p,
5157 struct samr_EnumDomainGroups *r)
5159 p->rng_fault_state = true;
5160 return NT_STATUS_NOT_IMPLEMENTED;
5163 /****************************************************************
5164 ****************************************************************/
5166 NTSTATUS _samr_CreateUser(pipes_struct *p,
5167 struct samr_CreateUser *r)
5169 p->rng_fault_state = true;
5170 return NT_STATUS_NOT_IMPLEMENTED;
5173 /****************************************************************
5174 ****************************************************************/
5176 NTSTATUS _samr_EnumDomainUsers(pipes_struct *p,
5177 struct samr_EnumDomainUsers *r)
5179 p->rng_fault_state = true;
5180 return NT_STATUS_NOT_IMPLEMENTED;
5183 /****************************************************************
5184 ****************************************************************/
5186 NTSTATUS _samr_EnumDomainAliases(pipes_struct *p,
5187 struct samr_EnumDomainAliases *r)
5189 p->rng_fault_state = true;
5190 return NT_STATUS_NOT_IMPLEMENTED;
5193 /****************************************************************
5194 ****************************************************************/
5196 NTSTATUS _samr_GetAliasMembership(pipes_struct *p,
5197 struct samr_GetAliasMembership *r)
5199 p->rng_fault_state = true;
5200 return NT_STATUS_NOT_IMPLEMENTED;
5203 /****************************************************************
5204 ****************************************************************/
5206 NTSTATUS _samr_LookupNames(pipes_struct *p,
5207 struct samr_LookupNames *r)
5209 p->rng_fault_state = true;
5210 return NT_STATUS_NOT_IMPLEMENTED;
5213 /****************************************************************
5214 ****************************************************************/
5216 NTSTATUS _samr_LookupRids(pipes_struct *p,
5217 struct samr_LookupRids *r)
5219 p->rng_fault_state = true;
5220 return NT_STATUS_NOT_IMPLEMENTED;
5223 /****************************************************************
5224 ****************************************************************/
5226 NTSTATUS _samr_QueryGroupInfo(pipes_struct *p,
5227 struct samr_QueryGroupInfo *r)
5229 p->rng_fault_state = true;
5230 return NT_STATUS_NOT_IMPLEMENTED;
5233 /****************************************************************
5234 ****************************************************************/
5236 NTSTATUS _samr_SetGroupInfo(pipes_struct *p,
5237 struct samr_SetGroupInfo *r)
5239 p->rng_fault_state = true;
5240 return NT_STATUS_NOT_IMPLEMENTED;
5243 /****************************************************************
5244 ****************************************************************/
5246 NTSTATUS _samr_AddGroupMember(pipes_struct *p,
5247 struct samr_AddGroupMember *r)
5249 p->rng_fault_state = true;
5250 return NT_STATUS_NOT_IMPLEMENTED;
5253 /****************************************************************
5254 ****************************************************************/
5256 NTSTATUS _samr_DeleteGroupMember(pipes_struct *p,
5257 struct samr_DeleteGroupMember *r)
5259 p->rng_fault_state = true;
5260 return NT_STATUS_NOT_IMPLEMENTED;
5263 /****************************************************************
5264 ****************************************************************/
5266 NTSTATUS _samr_QueryGroupMember(pipes_struct *p,
5267 struct samr_QueryGroupMember *r)
5269 p->rng_fault_state = true;
5270 return NT_STATUS_NOT_IMPLEMENTED;
5273 /****************************************************************
5274 ****************************************************************/
5276 NTSTATUS _samr_SetMemberAttributesOfGroup(pipes_struct *p,
5277 struct samr_SetMemberAttributesOfGroup *r)
5279 p->rng_fault_state = true;
5280 return NT_STATUS_NOT_IMPLEMENTED;
5283 /****************************************************************
5284 ****************************************************************/
5286 NTSTATUS _samr_QueryAliasInfo(pipes_struct *p,
5287 struct samr_QueryAliasInfo *r)
5289 p->rng_fault_state = true;
5290 return NT_STATUS_NOT_IMPLEMENTED;
5293 /****************************************************************
5294 ****************************************************************/
5296 NTSTATUS _samr_SetAliasInfo(pipes_struct *p,
5297 struct samr_SetAliasInfo *r)
5299 p->rng_fault_state = true;
5300 return NT_STATUS_NOT_IMPLEMENTED;
5303 /****************************************************************
5304 ****************************************************************/
5306 NTSTATUS _samr_AddAliasMember(pipes_struct *p,
5307 struct samr_AddAliasMember *r)
5309 p->rng_fault_state = true;
5310 return NT_STATUS_NOT_IMPLEMENTED;
5313 /****************************************************************
5314 ****************************************************************/
5316 NTSTATUS _samr_DeleteAliasMember(pipes_struct *p,
5317 struct samr_DeleteAliasMember *r)
5319 p->rng_fault_state = true;
5320 return NT_STATUS_NOT_IMPLEMENTED;
5323 /****************************************************************
5324 ****************************************************************/
5326 NTSTATUS _samr_GetMembersInAlias(pipes_struct *p,
5327 struct samr_GetMembersInAlias *r)
5329 p->rng_fault_state = true;
5330 return NT_STATUS_NOT_IMPLEMENTED;
5333 /****************************************************************
5334 ****************************************************************/
5336 NTSTATUS _samr_QueryUserInfo(pipes_struct *p,
5337 struct samr_QueryUserInfo *r)
5339 p->rng_fault_state = true;
5340 return NT_STATUS_NOT_IMPLEMENTED;
5343 /****************************************************************
5344 ****************************************************************/
5346 NTSTATUS _samr_SetUserInfo(pipes_struct *p,
5347 struct samr_SetUserInfo *r)
5349 p->rng_fault_state = true;
5350 return NT_STATUS_NOT_IMPLEMENTED;
5353 /****************************************************************
5354 ****************************************************************/
5356 NTSTATUS _samr_ChangePasswordUser(pipes_struct *p,
5357 struct samr_ChangePasswordUser *r)
5359 p->rng_fault_state = true;
5360 return NT_STATUS_NOT_IMPLEMENTED;
5363 /****************************************************************
5364 ****************************************************************/
5366 NTSTATUS _samr_GetGroupsForUser(pipes_struct *p,
5367 struct samr_GetGroupsForUser *r)
5369 p->rng_fault_state = true;
5370 return NT_STATUS_NOT_IMPLEMENTED;
5373 /****************************************************************
5374 ****************************************************************/
5376 NTSTATUS _samr_QueryDisplayInfo(pipes_struct *p,
5377 struct samr_QueryDisplayInfo *r)
5379 p->rng_fault_state = true;
5380 return NT_STATUS_NOT_IMPLEMENTED;
5383 /****************************************************************
5384 ****************************************************************/
5386 NTSTATUS _samr_GetDisplayEnumerationIndex(pipes_struct *p,
5387 struct samr_GetDisplayEnumerationIndex *r)
5389 p->rng_fault_state = true;
5390 return NT_STATUS_NOT_IMPLEMENTED;
5393 /****************************************************************
5394 ****************************************************************/
5396 NTSTATUS _samr_TestPrivateFunctionsDomain(pipes_struct *p,
5397 struct samr_TestPrivateFunctionsDomain *r)
5399 p->rng_fault_state = true;
5400 return NT_STATUS_NOT_IMPLEMENTED;
5403 /****************************************************************
5404 ****************************************************************/
5406 NTSTATUS _samr_TestPrivateFunctionsUser(pipes_struct *p,
5407 struct samr_TestPrivateFunctionsUser *r)
5409 p->rng_fault_state = true;
5410 return NT_STATUS_NOT_IMPLEMENTED;
5413 /****************************************************************
5414 ****************************************************************/
5416 NTSTATUS _samr_GetUserPwInfo(pipes_struct *p,
5417 struct samr_GetUserPwInfo *r)
5419 p->rng_fault_state = true;
5420 return NT_STATUS_NOT_IMPLEMENTED;
5423 /****************************************************************
5424 ****************************************************************/
5426 NTSTATUS _samr_RemoveMemberFromForeignDomain(pipes_struct *p,
5427 struct samr_RemoveMemberFromForeignDomain *r)
5429 p->rng_fault_state = true;
5430 return NT_STATUS_NOT_IMPLEMENTED;
5433 /****************************************************************
5434 ****************************************************************/
5436 NTSTATUS _samr_QueryDomainInfo2(pipes_struct *p,
5437 struct samr_QueryDomainInfo2 *r)
5439 p->rng_fault_state = true;
5440 return NT_STATUS_NOT_IMPLEMENTED;
5443 /****************************************************************
5444 ****************************************************************/
5446 NTSTATUS _samr_QueryUserInfo2(pipes_struct *p,
5447 struct samr_QueryUserInfo2 *r)
5449 p->rng_fault_state = true;
5450 return NT_STATUS_NOT_IMPLEMENTED;
5453 /****************************************************************
5454 ****************************************************************/
5456 NTSTATUS _samr_QueryDisplayInfo2(pipes_struct *p,
5457 struct samr_QueryDisplayInfo2 *r)
5459 p->rng_fault_state = true;
5460 return NT_STATUS_NOT_IMPLEMENTED;
5463 /****************************************************************
5464 ****************************************************************/
5466 NTSTATUS _samr_GetDisplayEnumerationIndex2(pipes_struct *p,
5467 struct samr_GetDisplayEnumerationIndex2 *r)
5469 p->rng_fault_state = true;
5470 return NT_STATUS_NOT_IMPLEMENTED;
5473 /****************************************************************
5474 ****************************************************************/
5476 NTSTATUS _samr_QueryDisplayInfo3(pipes_struct *p,
5477 struct samr_QueryDisplayInfo3 *r)
5479 p->rng_fault_state = true;
5480 return NT_STATUS_NOT_IMPLEMENTED;
5483 /****************************************************************
5484 ****************************************************************/
5486 NTSTATUS _samr_AddMultipleMembersToAlias(pipes_struct *p,
5487 struct samr_AddMultipleMembersToAlias *r)
5489 p->rng_fault_state = true;
5490 return NT_STATUS_NOT_IMPLEMENTED;
5493 /****************************************************************
5494 ****************************************************************/
5496 NTSTATUS _samr_RemoveMultipleMembersFromAlias(pipes_struct *p,
5497 struct samr_RemoveMultipleMembersFromAlias *r)
5499 p->rng_fault_state = true;
5500 return NT_STATUS_NOT_IMPLEMENTED;
5503 /****************************************************************
5504 ****************************************************************/
5506 NTSTATUS _samr_OemChangePasswordUser2(pipes_struct *p,
5507 struct samr_OemChangePasswordUser2 *r)
5509 p->rng_fault_state = true;
5510 return NT_STATUS_NOT_IMPLEMENTED;
5513 /****************************************************************
5514 ****************************************************************/
5516 NTSTATUS _samr_ChangePasswordUser2(pipes_struct *p,
5517 struct samr_ChangePasswordUser2 *r)
5519 p->rng_fault_state = true;
5520 return NT_STATUS_NOT_IMPLEMENTED;
5523 /****************************************************************
5524 ****************************************************************/
5526 NTSTATUS _samr_Connect2(pipes_struct *p,
5527 struct samr_Connect2 *r)
5529 p->rng_fault_state = true;
5530 return NT_STATUS_NOT_IMPLEMENTED;
5533 /****************************************************************
5534 ****************************************************************/
5536 NTSTATUS _samr_SetUserInfo2(pipes_struct *p,
5537 struct samr_SetUserInfo2 *r)
5539 p->rng_fault_state = true;
5540 return NT_STATUS_NOT_IMPLEMENTED;
5543 /****************************************************************
5544 ****************************************************************/
5546 NTSTATUS _samr_SetBootKeyInformation(pipes_struct *p,
5547 struct samr_SetBootKeyInformation *r)
5549 p->rng_fault_state = true;
5550 return NT_STATUS_NOT_IMPLEMENTED;
5553 /****************************************************************
5554 ****************************************************************/
5556 NTSTATUS _samr_GetBootKeyInformation(pipes_struct *p,
5557 struct samr_GetBootKeyInformation *r)
5559 p->rng_fault_state = true;
5560 return NT_STATUS_NOT_IMPLEMENTED;
5563 /****************************************************************
5564 ****************************************************************/
5566 NTSTATUS _samr_Connect3(pipes_struct *p,
5567 struct samr_Connect3 *r)
5569 p->rng_fault_state = true;
5570 return NT_STATUS_NOT_IMPLEMENTED;
5573 /****************************************************************
5574 ****************************************************************/
5576 NTSTATUS _samr_Connect4(pipes_struct *p,
5577 struct samr_Connect4 *r)
5579 p->rng_fault_state = true;
5580 return NT_STATUS_NOT_IMPLEMENTED;
5583 /****************************************************************
5584 ****************************************************************/
5586 NTSTATUS _samr_ChangePasswordUser3(pipes_struct *p,
5587 struct samr_ChangePasswordUser3 *r)
5589 p->rng_fault_state = true;
5590 return NT_STATUS_NOT_IMPLEMENTED;
5593 /****************************************************************
5594 ****************************************************************/
5596 NTSTATUS _samr_Connect5(pipes_struct *p,
5597 struct samr_Connect5 *r)
5599 p->rng_fault_state = true;
5600 return NT_STATUS_NOT_IMPLEMENTED;
5603 /****************************************************************
5604 ****************************************************************/
5606 NTSTATUS _samr_RidToSid(pipes_struct *p,
5607 struct samr_RidToSid *r)
5609 p->rng_fault_state = true;
5610 return NT_STATUS_NOT_IMPLEMENTED;
5613 /****************************************************************
5614 ****************************************************************/
5616 NTSTATUS _samr_SetDsrmPassword(pipes_struct *p,
5617 struct samr_SetDsrmPassword *r)
5619 p->rng_fault_state = true;
5620 return NT_STATUS_NOT_IMPLEMENTED;
5623 /****************************************************************
5624 ****************************************************************/
5626 NTSTATUS _samr_ValidatePassword(pipes_struct *p,
5627 struct samr_ValidatePassword *r)
5629 p->rng_fault_state = true;
5630 return NT_STATUS_NOT_IMPLEMENTED;