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-2002,
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.
14 * This program is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation; either version 2 of the License, or
17 * (at your option) any later version.
19 * This program is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
24 * You should have received a copy of the GNU General Public License
25 * along with this program; if not, write to the Free Software
26 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
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 )
43 extern rid_name domain_group_rids
[];
44 extern rid_name domain_alias_rids
[];
45 extern rid_name builtin_alias_rids
[];
47 typedef struct disp_info
{
48 struct pdb_search
*users
; /* querydispinfo 1 and 4 */
49 struct pdb_search
*machines
; /* querydispinfo 2 */
50 struct pdb_search
*groups
; /* querydispinfo 3 and 5, enumgroups */
51 struct pdb_search
*aliases
; /* enumaliases */
52 struct pdb_search
*builtins
; /* enumaliases */
55 struct pdb_search
*enum_users
; /* enumusers with a mask */
59 /* for use by the \PIPE\samr policy */
61 uint32 status
; /* some sort of flag. best to record it. comes from opnum 0x39 */
70 struct generic_mapping sam_generic_mapping
= {GENERIC_RIGHTS_SAM_READ
, GENERIC_RIGHTS_SAM_WRITE
, GENERIC_RIGHTS_SAM_EXECUTE
, GENERIC_RIGHTS_SAM_ALL_ACCESS
};
71 struct generic_mapping dom_generic_mapping
= {GENERIC_RIGHTS_DOMAIN_READ
, GENERIC_RIGHTS_DOMAIN_WRITE
, GENERIC_RIGHTS_DOMAIN_EXECUTE
, GENERIC_RIGHTS_DOMAIN_ALL_ACCESS
};
72 struct generic_mapping usr_generic_mapping
= {GENERIC_RIGHTS_USER_READ
, GENERIC_RIGHTS_USER_WRITE
, GENERIC_RIGHTS_USER_EXECUTE
, GENERIC_RIGHTS_USER_ALL_ACCESS
};
73 struct generic_mapping grp_generic_mapping
= {GENERIC_RIGHTS_GROUP_READ
, GENERIC_RIGHTS_GROUP_WRITE
, GENERIC_RIGHTS_GROUP_EXECUTE
, GENERIC_RIGHTS_GROUP_ALL_ACCESS
};
74 struct generic_mapping ali_generic_mapping
= {GENERIC_RIGHTS_ALIAS_READ
, GENERIC_RIGHTS_ALIAS_WRITE
, GENERIC_RIGHTS_ALIAS_EXECUTE
, GENERIC_RIGHTS_ALIAS_ALL_ACCESS
};
76 /*******************************************************************
77 *******************************************************************/
79 static NTSTATUS
make_samr_object_sd( TALLOC_CTX
*ctx
, SEC_DESC
**psd
, size_t *sd_size
,
80 struct generic_mapping
*map
,
81 DOM_SID
*sid
, uint32 sid_access
)
84 SEC_ACE ace
[5]; /* at most 5 entries */
90 /* basic access for Everyone */
92 init_sec_access(&mask
, map
->generic_execute
| map
->generic_read
);
93 init_sec_ace(&ace
[i
++], &global_sid_World
, SEC_ACE_TYPE_ACCESS_ALLOWED
, mask
, 0);
95 /* add Full Access 'BUILTIN\Administrators' and 'BUILTIN\Account Operators */
97 init_sec_access(&mask
, map
->generic_all
);
99 init_sec_ace(&ace
[i
++], &global_sid_Builtin_Administrators
, SEC_ACE_TYPE_ACCESS_ALLOWED
, mask
, 0);
100 init_sec_ace(&ace
[i
++], &global_sid_Builtin_Account_Operators
, SEC_ACE_TYPE_ACCESS_ALLOWED
, mask
, 0);
102 /* Add Full Access for Domain Admins if we are a DC */
105 sid_copy( &domadmin_sid
, get_global_sam_sid() );
106 sid_append_rid( &domadmin_sid
, DOMAIN_GROUP_RID_ADMINS
);
107 init_sec_ace(&ace
[i
++], &domadmin_sid
, SEC_ACE_TYPE_ACCESS_ALLOWED
, mask
, 0);
110 /* if we have a sid, give it some special access */
113 init_sec_access( &mask
, sid_access
);
114 init_sec_ace(&ace
[i
++], sid
, SEC_ACE_TYPE_ACCESS_ALLOWED
, mask
, 0);
117 /* create the security descriptor */
119 if ((psa
= make_sec_acl(ctx
, NT4_ACL_REVISION
, i
, ace
)) == NULL
)
120 return NT_STATUS_NO_MEMORY
;
122 if ((*psd
= make_sec_desc(ctx
, SEC_DESC_REVISION
, SEC_DESC_SELF_RELATIVE
, NULL
, NULL
, NULL
, psa
, sd_size
)) == NULL
)
123 return NT_STATUS_NO_MEMORY
;
128 /*******************************************************************
129 Checks if access to an object should be granted, and returns that
130 level of access for further checks.
131 ********************************************************************/
133 static NTSTATUS
access_check_samr_object( SEC_DESC
*psd
, NT_USER_TOKEN
*token
,
134 SE_PRIV
*rights
, uint32 rights_mask
,
135 uint32 des_access
, uint32
*acc_granted
,
138 NTSTATUS status
= NT_STATUS_ACCESS_DENIED
;
139 uint32 saved_mask
= 0;
141 /* check privileges; certain SAM access bits should be overridden
142 by privileges (mostly having to do with creating/modifying/deleting
145 if ( rights
&& user_has_any_privilege( token
, rights
) ) {
147 saved_mask
= (des_access
& rights_mask
);
148 des_access
&= ~saved_mask
;
150 DEBUG(4,("access_check_samr_object: user rights access mask [0x%x]\n",
155 /* check the security descriptor first */
157 if ( se_access_check(psd
, token
, des_access
, acc_granted
, &status
) )
160 /* give root a free pass */
162 if ( geteuid() == sec_initial_uid() ) {
164 DEBUG(4,("%s: ACCESS should be DENIED (requested: %#010x)\n", debug
, des_access
));
165 DEBUGADD(4,("but overritten by euid == sec_initial_uid()\n"));
167 *acc_granted
= des_access
;
169 status
= NT_STATUS_OK
;
175 /* add in any bits saved during the privilege check (only
176 matters is status is ok) */
178 *acc_granted
|= rights_mask
;
180 DEBUG(4,("%s: access %s (requested: 0x%08x, granted: 0x%08x)\n",
181 debug
, NT_STATUS_IS_OK(status
) ? "GRANTED" : "DENIED",
182 des_access
, *acc_granted
));
187 /*******************************************************************
188 Checks if access to a function can be granted
189 ********************************************************************/
191 static NTSTATUS
access_check_samr_function(uint32 acc_granted
, uint32 acc_required
, const char *debug
)
193 DEBUG(5,("%s: access check ((granted: %#010x; required: %#010x)\n",
194 debug
, acc_granted
, acc_required
));
196 /* check the security descriptor first */
198 if ( (acc_granted
&acc_required
) == acc_required
)
201 /* give root a free pass */
203 if (geteuid() == sec_initial_uid()) {
205 DEBUG(4,("%s: ACCESS should be DENIED (granted: %#010x; required: %#010x)\n",
206 debug
, acc_granted
, acc_required
));
207 DEBUGADD(4,("but overwritten by euid == 0\n"));
212 DEBUG(2,("%s: ACCESS DENIED (granted: %#010x; required: %#010x)\n",
213 debug
, acc_granted
, acc_required
));
215 return NT_STATUS_ACCESS_DENIED
;
219 /*******************************************************************
220 Create a samr_info struct.
221 ********************************************************************/
223 static struct samr_info
*get_samr_info_by_sid(DOM_SID
*psid
)
225 struct samr_info
*info
;
230 sid_to_string(sid_str
, psid
);
232 fstrcpy(sid_str
,"(NULL)");
235 mem_ctx
= talloc_init("samr_info for domain sid %s", sid_str
);
237 if ((info
= TALLOC_ZERO_P(mem_ctx
, struct samr_info
)) == NULL
)
240 DEBUG(10,("get_samr_info_by_sid: created new info for sid %s\n", sid_str
));
242 sid_copy( &info
->sid
, psid
);
244 DEBUG(10,("get_samr_info_by_sid: created new info for NULL sid.\n"));
246 info
->mem_ctx
= mem_ctx
;
250 /*******************************************************************
251 Function to free the per handle data.
252 ********************************************************************/
254 /*******************************************************************
255 Function to free the per handle data.
256 ********************************************************************/
258 static void free_samr_db(struct samr_info
*info
)
260 pdb_search_destroy(info
->disp_info
.users
);
261 info
->disp_info
.users
= NULL
;
262 pdb_search_destroy(info
->disp_info
.machines
);
263 info
->disp_info
.machines
= NULL
;
264 pdb_search_destroy(info
->disp_info
.groups
);
265 info
->disp_info
.groups
= NULL
;
266 pdb_search_destroy(info
->disp_info
.aliases
);
267 info
->disp_info
.aliases
= NULL
;
268 pdb_search_destroy(info
->disp_info
.builtins
);
269 info
->disp_info
.builtins
= NULL
;
270 pdb_search_destroy(info
->disp_info
.enum_users
);
271 info
->disp_info
.enum_users
= NULL
;
274 static void free_samr_info(void *ptr
)
276 struct samr_info
*info
=(struct samr_info
*) ptr
;
279 talloc_destroy(info
->mem_ctx
);
282 /*******************************************************************
283 Ensure password info is never given out. Paranioa... JRA.
284 ********************************************************************/
286 static void samr_clear_sam_passwd(SAM_ACCOUNT
*sam_pass
)
292 /* These now zero out the old password */
294 pdb_set_lanman_passwd(sam_pass
, NULL
, PDB_DEFAULT
);
295 pdb_set_nt_passwd(sam_pass
, NULL
, PDB_DEFAULT
);
298 static uint32
count_sam_users(struct disp_info
*info
, uint16 acct_flags
)
300 struct samr_displayentry
*entry
;
301 if (info
->users
== NULL
)
302 info
->users
= pdb_search_users(acct_flags
);
303 if (info
->users
== NULL
)
305 /* Fetch the last possible entry, thus trigger an enumeration */
306 pdb_search_entries(info
->users
, 0xffffffff, 1, &entry
);
307 return info
->users
->num_entries
;
310 static uint32
count_sam_groups(struct disp_info
*info
)
312 struct samr_displayentry
*entry
;
313 if (info
->groups
== NULL
)
314 info
->groups
= pdb_search_groups();
315 if (info
->groups
== NULL
)
317 /* Fetch the last possible entry, thus trigger an enumeration */
318 pdb_search_entries(info
->groups
, 0xffffffff, 1, &entry
);
319 return info
->groups
->num_entries
;
322 /*******************************************************************
324 ********************************************************************/
326 NTSTATUS
_samr_close_hnd(pipes_struct
*p
, SAMR_Q_CLOSE_HND
*q_u
, SAMR_R_CLOSE_HND
*r_u
)
328 r_u
->status
= NT_STATUS_OK
;
330 /* close the policy handle */
331 if (!close_policy_hnd(p
, &q_u
->pol
))
332 return NT_STATUS_OBJECT_NAME_INVALID
;
334 DEBUG(5,("samr_reply_close_hnd: %d\n", __LINE__
));
339 /*******************************************************************
340 samr_reply_open_domain
341 ********************************************************************/
343 NTSTATUS
_samr_open_domain(pipes_struct
*p
, SAMR_Q_OPEN_DOMAIN
*q_u
, SAMR_R_OPEN_DOMAIN
*r_u
)
345 struct samr_info
*info
;
346 SEC_DESC
*psd
= NULL
;
348 uint32 des_access
= q_u
->flags
;
353 r_u
->status
= NT_STATUS_OK
;
355 /* find the connection policy handle. */
357 if ( !find_policy_by_hnd(p
, &q_u
->pol
, (void**)&info
) )
358 return NT_STATUS_INVALID_HANDLE
;
360 status
= access_check_samr_function( info
->acc_granted
,
361 SA_RIGHT_SAM_OPEN_DOMAIN
, "_samr_open_domain" );
363 if ( !NT_STATUS_IS_OK(status
) )
366 /*check if access can be granted as requested by client. */
368 make_samr_object_sd( p
->mem_ctx
, &psd
, &sd_size
, &dom_generic_mapping
, NULL
, 0 );
369 se_map_generic( &des_access
, &dom_generic_mapping
);
371 se_priv_copy( &se_rights
, &se_machine_account
);
372 se_priv_add( &se_rights
, &se_add_users
);
374 status
= access_check_samr_object( psd
, p
->pipe_user
.nt_user_token
,
375 &se_rights
, GENERIC_RIGHTS_DOMAIN_WRITE
, des_access
,
376 &acc_granted
, "_samr_open_domain" );
378 if ( !NT_STATUS_IS_OK(status
) )
381 /* associate the domain SID with the (unique) handle. */
382 if ((info
= get_samr_info_by_sid(&q_u
->dom_sid
.sid
))==NULL
)
383 return NT_STATUS_NO_MEMORY
;
384 info
->acc_granted
= acc_granted
;
386 /* get a (unique) handle. open a policy on it. */
387 if (!create_policy_hnd(p
, &r_u
->domain_pol
, free_samr_info
, (void *)info
))
388 return NT_STATUS_OBJECT_NAME_NOT_FOUND
;
390 DEBUG(5,("samr_open_domain: %d\n", __LINE__
));
395 /*******************************************************************
396 _samr_get_usrdom_pwinfo
397 ********************************************************************/
399 NTSTATUS
_samr_get_usrdom_pwinfo(pipes_struct
*p
, SAMR_Q_GET_USRDOM_PWINFO
*q_u
, SAMR_R_GET_USRDOM_PWINFO
*r_u
)
401 struct samr_info
*info
= NULL
;
403 r_u
->status
= NT_STATUS_OK
;
405 /* find the policy handle. open a policy on it. */
406 if (!find_policy_by_hnd(p
, &q_u
->user_pol
, (void **)&info
))
407 return NT_STATUS_INVALID_HANDLE
;
409 if (!sid_check_is_in_our_domain(&info
->sid
))
410 return NT_STATUS_OBJECT_TYPE_MISMATCH
;
412 init_samr_r_get_usrdom_pwinfo(r_u
, NT_STATUS_OK
);
414 DEBUG(5,("_samr_get_usrdom_pwinfo: %d\n", __LINE__
));
417 * NT sometimes return NT_STATUS_ACCESS_DENIED
418 * I don't know yet why.
425 /*******************************************************************
427 ********************************************************************/
429 NTSTATUS
_samr_set_sec_obj(pipes_struct
*p
, SAMR_Q_SET_SEC_OBJ
*q_u
, SAMR_R_SET_SEC_OBJ
*r_u
)
431 DEBUG(0,("_samr_set_sec_obj: Not yet implemented!\n"));
432 return NT_STATUS_NOT_IMPLEMENTED
;
436 /*******************************************************************
437 ********************************************************************/
439 static BOOL
get_lsa_policy_samr_sid( pipes_struct
*p
, POLICY_HND
*pol
,
440 DOM_SID
*sid
, uint32
*acc_granted
)
442 struct samr_info
*info
= NULL
;
444 /* find the policy handle. open a policy on it. */
445 if (!find_policy_by_hnd(p
, pol
, (void **)&info
))
452 *acc_granted
= info
->acc_granted
;
456 /*******************************************************************
458 ********************************************************************/
460 NTSTATUS
_samr_query_sec_obj(pipes_struct
*p
, SAMR_Q_QUERY_SEC_OBJ
*q_u
, SAMR_R_QUERY_SEC_OBJ
*r_u
)
464 SEC_DESC
* psd
= NULL
;
468 r_u
->status
= NT_STATUS_OK
;
471 if (!get_lsa_policy_samr_sid(p
, &q_u
->user_pol
, &pol_sid
, &acc_granted
))
472 return NT_STATUS_INVALID_HANDLE
;
476 DEBUG(10,("_samr_query_sec_obj: querying security on SID: %s\n", sid_to_string(str_sid
, &pol_sid
)));
478 /* Check what typ of SID is beeing queried (e.g Domain SID, User SID, Group SID) */
480 /* To query the security of the SAM it self an invalid SID with S-0-0 is passed to this function */
481 if (pol_sid
.sid_rev_num
== 0)
483 DEBUG(5,("_samr_query_sec_obj: querying security on SAM\n"));
484 r_u
->status
= make_samr_object_sd(p
->mem_ctx
, &psd
, &sd_size
, &sam_generic_mapping
, NULL
, 0);
486 else if (sid_equal(&pol_sid
,get_global_sam_sid())) /* check if it is our domain SID */
489 DEBUG(5,("_samr_query_sec_obj: querying security on Domain with SID: %s\n", sid_to_string(str_sid
, &pol_sid
)));
490 r_u
->status
= make_samr_object_sd(p
->mem_ctx
, &psd
, &sd_size
, &dom_generic_mapping
, NULL
, 0);
492 else if (sid_equal(&pol_sid
,&global_sid_Builtin
)) /* check if it is the Builtin Domain */
494 /* TODO: Builtin probably needs a different SD with restricted write access*/
495 DEBUG(5,("_samr_query_sec_obj: querying security on Builtin Domain with SID: %s\n", sid_to_string(str_sid
, &pol_sid
)));
496 r_u
->status
= make_samr_object_sd(p
->mem_ctx
, &psd
, &sd_size
, &dom_generic_mapping
, NULL
, 0);
498 else if (sid_check_is_in_our_domain(&pol_sid
) ||
499 sid_check_is_in_builtin(&pol_sid
))
501 /* TODO: different SDs have to be generated for aliases groups and users.
502 Currently all three get a default user SD */
503 DEBUG(10,("_samr_query_sec_obj: querying security on Object with SID: %s\n", sid_to_string(str_sid
, &pol_sid
)));
504 r_u
->status
= make_samr_object_sd(p
->mem_ctx
, &psd
, &sd_size
, &usr_generic_mapping
, &pol_sid
, SAMR_USR_RIGHTS_WRITE_PW
);
506 else return NT_STATUS_OBJECT_TYPE_MISMATCH
;
508 if ((r_u
->buf
= make_sec_desc_buf(p
->mem_ctx
, sd_size
, psd
)) == NULL
)
509 return NT_STATUS_NO_MEMORY
;
511 if (NT_STATUS_IS_OK(r_u
->status
))
517 /*******************************************************************
518 makes a SAM_ENTRY / UNISTR2* structure from a user list.
519 ********************************************************************/
521 static NTSTATUS
make_user_sam_entry_list(TALLOC_CTX
*ctx
, SAM_ENTRY
**sam_pp
,
522 UNISTR2
**uni_name_pp
,
523 uint32 num_entries
, uint32 start_idx
,
524 struct samr_displayentry
*entries
)
533 if (num_entries
== 0)
536 sam
= TALLOC_ZERO_ARRAY(ctx
, SAM_ENTRY
, num_entries
);
538 uni_name
= TALLOC_ZERO_ARRAY(ctx
, UNISTR2
, num_entries
);
540 if (sam
== NULL
|| uni_name
== NULL
) {
541 DEBUG(0, ("make_user_sam_entry_list: talloc_zero failed!\n"));
542 return NT_STATUS_NO_MEMORY
;
545 for (i
= 0; i
< num_entries
; i
++) {
546 UNISTR2 uni_temp_name
;
548 * usrmgr expects a non-NULL terminated string with
549 * trust relationships
551 if (entries
[i
].acct_flags
& ACB_DOMTRUST
) {
552 init_unistr2(&uni_temp_name
, entries
[i
].account_name
,
555 init_unistr2(&uni_temp_name
, entries
[i
].account_name
,
559 init_sam_entry(&sam
[i
], &uni_temp_name
, entries
[i
].rid
);
560 copy_unistr2(&uni_name
[i
], &uni_temp_name
);
564 *uni_name_pp
= uni_name
;
568 /*******************************************************************
569 samr_reply_enum_dom_users
570 ********************************************************************/
572 NTSTATUS
_samr_enum_dom_users(pipes_struct
*p
, SAMR_Q_ENUM_DOM_USERS
*q_u
,
573 SAMR_R_ENUM_DOM_USERS
*r_u
)
575 struct samr_info
*info
= NULL
;
577 uint32 enum_context
=q_u
->start_idx
;
578 enum remote_arch_types ra_type
= get_remote_arch();
579 int max_sam_entries
= (ra_type
== RA_WIN95
) ? MAX_SAM_ENTRIES_W95
: MAX_SAM_ENTRIES_W2K
;
580 uint32 max_entries
= max_sam_entries
;
581 struct samr_displayentry
*entries
= NULL
;
583 r_u
->status
= NT_STATUS_OK
;
585 /* find the policy handle. open a policy on it. */
586 if (!find_policy_by_hnd(p
, &q_u
->pol
, (void **)&info
))
587 return NT_STATUS_INVALID_HANDLE
;
589 if (!NT_STATUS_IS_OK(r_u
->status
= access_check_samr_function(info
->acc_granted
,
590 SA_RIGHT_DOMAIN_ENUM_ACCOUNTS
,
591 "_samr_enum_dom_users"))) {
595 DEBUG(5,("_samr_enum_dom_users: %d\n", __LINE__
));
598 if ((info
->disp_info
.enum_users
!= NULL
) &&
599 (info
->disp_info
.enum_acb_mask
!= q_u
->acb_mask
)) {
600 pdb_search_destroy(info
->disp_info
.enum_users
);
601 info
->disp_info
.enum_users
= NULL
;
604 if (info
->disp_info
.enum_users
== NULL
) {
605 info
->disp_info
.enum_users
= pdb_search_users(q_u
->acb_mask
);
606 info
->disp_info
.enum_acb_mask
= q_u
->acb_mask
;
608 if (info
->disp_info
.enum_users
== NULL
)
609 return NT_STATUS_ACCESS_DENIED
;
610 num_account
= pdb_search_entries(info
->disp_info
.enum_users
,
611 enum_context
, max_entries
,
615 if (num_account
== 0) {
616 DEBUG(5, ("_samr_enum_dom_users: enumeration handle over "
621 r_u
->status
= make_user_sam_entry_list(p
->mem_ctx
, &r_u
->sam
,
623 num_account
, enum_context
,
626 if (!NT_STATUS_IS_OK(r_u
->status
))
629 if (max_entries
<= num_account
)
630 r_u
->status
= STATUS_MORE_ENTRIES
;
632 DEBUG(5, ("_samr_enum_dom_users: %d\n", __LINE__
));
634 init_samr_r_enum_dom_users(r_u
, q_u
->start_idx
+ num_account
,
637 DEBUG(5,("_samr_enum_dom_users: %d\n", __LINE__
));
642 /*******************************************************************
643 makes a SAM_ENTRY / UNISTR2* structure from a group list.
644 ********************************************************************/
646 static void make_group_sam_entry_list(TALLOC_CTX
*ctx
, SAM_ENTRY
**sam_pp
,
647 UNISTR2
**uni_name_pp
,
648 uint32 num_sam_entries
,
649 struct samr_displayentry
*entries
)
658 if (num_sam_entries
== 0)
661 sam
= TALLOC_ZERO_ARRAY(ctx
, SAM_ENTRY
, num_sam_entries
);
662 uni_name
= TALLOC_ZERO_ARRAY(ctx
, UNISTR2
, num_sam_entries
);
664 if (sam
== NULL
|| uni_name
== NULL
) {
665 DEBUG(0, ("NULL pointers in SAMR_R_QUERY_DISPINFO\n"));
669 for (i
= 0; i
< num_sam_entries
; i
++) {
671 * JRA. I think this should include the null. TNG does not.
673 init_unistr2(&uni_name
[i
], entries
[i
].account_name
,
675 init_sam_entry(&sam
[i
], &uni_name
[i
], entries
[i
].rid
);
679 *uni_name_pp
= uni_name
;
682 /*******************************************************************
683 samr_reply_enum_dom_groups
684 ********************************************************************/
686 NTSTATUS
_samr_enum_dom_groups(pipes_struct
*p
, SAMR_Q_ENUM_DOM_GROUPS
*q_u
, SAMR_R_ENUM_DOM_GROUPS
*r_u
)
688 struct samr_info
*info
= NULL
;
689 struct samr_displayentry
*groups
;
692 r_u
->status
= NT_STATUS_OK
;
694 /* find the policy handle. open a policy on it. */
695 if (!find_policy_by_hnd(p
, &q_u
->pol
, (void **)&info
))
696 return NT_STATUS_INVALID_HANDLE
;
698 r_u
->status
= access_check_samr_function(info
->acc_granted
,
699 SA_RIGHT_DOMAIN_ENUM_ACCOUNTS
,
700 "_samr_enum_dom_groups");
701 if (!NT_STATUS_IS_OK(r_u
->status
))
704 DEBUG(5,("samr_reply_enum_dom_groups: %d\n", __LINE__
));
706 /* the domain group array is being allocated in the function below */
709 if (info
->disp_info
.groups
== NULL
)
710 info
->disp_info
.groups
= pdb_search_groups();
713 if (info
->disp_info
.groups
== NULL
)
714 return NT_STATUS_ACCESS_DENIED
;
717 num_groups
= pdb_search_entries(info
->disp_info
.groups
, q_u
->start_idx
,
718 MAX_SAM_ENTRIES
, &groups
);
721 make_group_sam_entry_list(p
->mem_ctx
, &r_u
->sam
, &r_u
->uni_grp_name
,
724 init_samr_r_enum_dom_groups(r_u
, q_u
->start_idx
, num_groups
);
726 DEBUG(5,("samr_enum_dom_groups: %d\n", __LINE__
));
731 /*******************************************************************
732 samr_reply_enum_dom_aliases
733 ********************************************************************/
735 NTSTATUS
_samr_enum_dom_aliases(pipes_struct
*p
, SAMR_Q_ENUM_DOM_ALIASES
*q_u
, SAMR_R_ENUM_DOM_ALIASES
*r_u
)
737 struct samr_info
*info
;
738 struct samr_displayentry
*aliases
;
739 struct pdb_search
**search
= NULL
;
740 uint32 num_aliases
= 0;
742 /* find the policy handle. open a policy on it. */
743 if (!find_policy_by_hnd(p
, &q_u
->pol
, (void **)&info
))
744 return NT_STATUS_INVALID_HANDLE
;
746 r_u
->status
= access_check_samr_function(info
->acc_granted
,
747 SA_RIGHT_DOMAIN_ENUM_ACCOUNTS
,
748 "_samr_enum_dom_aliases");
749 if (!NT_STATUS_IS_OK(r_u
->status
))
752 DEBUG(5,("samr_reply_enum_dom_aliases: sid %s\n",
753 sid_string_static(&info
->sid
)));
755 if (sid_check_is_domain(&info
->sid
))
756 search
= &info
->disp_info
.aliases
;
757 if (sid_check_is_builtin(&info
->sid
))
758 search
= &info
->disp_info
.builtins
;
761 return NT_STATUS_INVALID_HANDLE
;
765 *search
= pdb_search_aliases(&info
->sid
);
769 return NT_STATUS_ACCESS_DENIED
;
772 num_aliases
= pdb_search_entries(*search
, q_u
->start_idx
,
773 MAX_SAM_ENTRIES
, &aliases
);
776 make_group_sam_entry_list(p
->mem_ctx
, &r_u
->sam
, &r_u
->uni_grp_name
,
777 num_aliases
, aliases
);
779 init_samr_r_enum_dom_aliases(r_u
, q_u
->start_idx
+ num_aliases
,
782 DEBUG(5,("samr_enum_dom_aliases: %d\n", __LINE__
));
787 /*******************************************************************
788 samr_reply_query_dispinfo
789 ********************************************************************/
791 NTSTATUS
_samr_query_dispinfo(pipes_struct
*p
, SAMR_Q_QUERY_DISPINFO
*q_u
,
792 SAMR_R_QUERY_DISPINFO
*r_u
)
794 struct samr_info
*info
= NULL
;
795 uint32 struct_size
=0x20; /* W2K always reply that, client doesn't care */
797 uint32 max_entries
=q_u
->max_entries
;
798 uint32 enum_context
=q_u
->start_idx
;
799 uint32 max_size
=q_u
->max_size
;
801 SAM_DISPINFO_CTR
*ctr
;
802 uint32 temp_size
=0, total_data_size
=0;
804 uint32 num_account
= 0;
805 enum remote_arch_types ra_type
= get_remote_arch();
806 int max_sam_entries
= (ra_type
== RA_WIN95
) ? MAX_SAM_ENTRIES_W95
: MAX_SAM_ENTRIES_W2K
;
808 struct samr_displayentry
*entries
= NULL
;
810 DEBUG(5, ("samr_reply_query_dispinfo: %d\n", __LINE__
));
811 r_u
->status
= NT_STATUS_UNSUCCESSFUL
;
813 /* find the policy handle. open a policy on it. */
814 if (!find_policy_by_hnd(p
, &q_u
->domain_pol
, (void **)&info
))
815 return NT_STATUS_INVALID_HANDLE
;
817 domain_sid
= info
->sid
;
820 * calculate how many entries we will return.
822 * - the number of entries the client asked
823 * - our limit on that
824 * - the starting point (enumeration context)
825 * - the buffer size the client will accept
829 * We are a lot more like W2K. Instead of reading the SAM
830 * each time to find the records we need to send back,
831 * we read it once and link that copy to the sam handle.
832 * For large user list (over the MAX_SAM_ENTRIES)
833 * it's a definitive win.
834 * second point to notice: between enumerations
835 * our sam is now the same as it's a snapshoot.
836 * third point: got rid of the static SAM_USER_21 struct
837 * no more intermediate.
838 * con: it uses much more memory, as a full copy is stored
841 * If you want to change it, think twice and think
842 * of the second point , that's really important.
847 if ((q_u
->switch_level
< 1) || (q_u
->switch_level
> 5)) {
848 DEBUG(0,("_samr_query_dispinfo: Unknown info level (%u)\n",
849 (unsigned int)q_u
->switch_level
));
850 return NT_STATUS_INVALID_INFO_CLASS
;
853 /* first limit the number of entries we will return */
854 if(max_entries
> max_sam_entries
) {
855 DEBUG(5, ("samr_reply_query_dispinfo: client requested %d "
856 "entries, limiting to %d\n", max_entries
,
858 max_entries
= max_sam_entries
;
861 /* calculate the size and limit on the number of entries we will
864 temp_size
=max_entries
*struct_size
;
866 if (temp_size
>max_size
) {
867 max_entries
=MIN((max_size
/struct_size
),max_entries
);;
868 DEBUG(5, ("samr_reply_query_dispinfo: buffer size limits to "
869 "only %d entries\n", max_entries
));
872 if (!(ctr
= TALLOC_ZERO_P(p
->mem_ctx
,SAM_DISPINFO_CTR
)))
873 return NT_STATUS_NO_MEMORY
;
879 switch (q_u
->switch_level
) {
882 if (info
->disp_info
.users
== NULL
)
883 info
->disp_info
.users
= pdb_search_users(ACB_NORMAL
);
884 if (info
->disp_info
.users
== NULL
)
885 return NT_STATUS_ACCESS_DENIED
;
886 num_account
= pdb_search_entries(info
->disp_info
.users
,
887 enum_context
, max_entries
,
891 if (info
->disp_info
.machines
== NULL
)
892 info
->disp_info
.machines
=
893 pdb_search_users(ACB_WSTRUST
|ACB_SVRTRUST
);
894 if (info
->disp_info
.machines
== NULL
)
895 return NT_STATUS_ACCESS_DENIED
;
896 num_account
= pdb_search_entries(info
->disp_info
.machines
,
897 enum_context
, max_entries
,
902 if (info
->disp_info
.groups
== NULL
)
903 info
->disp_info
.groups
= pdb_search_groups();
904 if (info
->disp_info
.groups
== NULL
)
905 return NT_STATUS_ACCESS_DENIED
;
906 num_account
= pdb_search_entries(info
->disp_info
.groups
,
907 enum_context
, max_entries
,
911 smb_panic("info class changed");
916 /* Now create reply structure */
917 switch (q_u
->switch_level
) {
919 disp_ret
= init_sam_dispinfo_1(p
->mem_ctx
, &ctr
->sam
.info1
,
920 num_account
, enum_context
,
924 disp_ret
= init_sam_dispinfo_2(p
->mem_ctx
, &ctr
->sam
.info2
,
925 num_account
, enum_context
,
929 disp_ret
= init_sam_dispinfo_3(p
->mem_ctx
, &ctr
->sam
.info3
,
930 num_account
, enum_context
,
934 disp_ret
= init_sam_dispinfo_4(p
->mem_ctx
, &ctr
->sam
.info4
,
935 num_account
, enum_context
,
939 disp_ret
= init_sam_dispinfo_5(p
->mem_ctx
, &ctr
->sam
.info5
,
940 num_account
, enum_context
,
944 smb_panic("info class changed");
948 if (!NT_STATUS_IS_OK(disp_ret
))
951 /* calculate the total size */
952 total_data_size
=num_account
*struct_size
;
955 r_u
->status
= STATUS_MORE_ENTRIES
;
957 r_u
->status
= NT_STATUS_OK
;
959 DEBUG(5, ("_samr_query_dispinfo: %d\n", __LINE__
));
961 init_samr_r_query_dispinfo(r_u
, num_account
, total_data_size
,
962 temp_size
, q_u
->switch_level
, ctr
,
969 /*******************************************************************
970 samr_reply_query_aliasinfo
971 ********************************************************************/
973 NTSTATUS
_samr_query_aliasinfo(pipes_struct
*p
, SAMR_Q_QUERY_ALIASINFO
*q_u
, SAMR_R_QUERY_ALIASINFO
*r_u
)
976 struct acct_info info
;
980 r_u
->status
= NT_STATUS_OK
;
982 DEBUG(5,("_samr_query_aliasinfo: %d\n", __LINE__
));
984 /* find the policy handle. open a policy on it. */
985 if (!get_lsa_policy_samr_sid(p
, &q_u
->pol
, &sid
, &acc_granted
))
986 return NT_STATUS_INVALID_HANDLE
;
987 if (!NT_STATUS_IS_OK(r_u
->status
= access_check_samr_function(acc_granted
, SA_RIGHT_ALIAS_LOOKUP_INFO
, "_samr_query_aliasinfo"))) {
992 ret
= pdb_get_aliasinfo(&sid
, &info
);
996 return NT_STATUS_NO_SUCH_ALIAS
;
998 if ( !(r_u
->ctr
= TALLOC_ZERO_P( p
->mem_ctx
, ALIAS_INFO_CTR
)) )
999 return NT_STATUS_NO_MEMORY
;
1002 switch (q_u
->level
) {
1004 r_u
->ctr
->level
= 1;
1005 init_samr_alias_info1(&r_u
->ctr
->alias
.info1
, info
.acct_name
, 1, info
.acct_desc
);
1008 r_u
->ctr
->level
= 3;
1009 init_samr_alias_info3(&r_u
->ctr
->alias
.info3
, info
.acct_desc
);
1012 return NT_STATUS_INVALID_INFO_CLASS
;
1015 DEBUG(5,("_samr_query_aliasinfo: %d\n", __LINE__
));
1021 /*******************************************************************
1022 samr_reply_lookup_ids
1023 ********************************************************************/
1025 uint32
_samr_lookup_ids(pipes_struct
*p
, SAMR_Q_LOOKUP_IDS
*q_u
, SAMR_R_LOOKUP_IDS
*r_u
)
1027 uint32 rid
[MAX_SAM_ENTRIES
];
1028 int num_rids
= q_u
->num_sids1
;
1030 r_u
->status
= NT_STATUS_OK
;
1032 DEBUG(5,("_samr_lookup_ids: %d\n", __LINE__
));
1034 if (num_rids
> MAX_SAM_ENTRIES
) {
1035 num_rids
= MAX_SAM_ENTRIES
;
1036 DEBUG(5,("_samr_lookup_ids: truncating entries to %d\n", num_rids
));
1041 SMB_ASSERT_ARRAY(q_u
->uni_user_name
, num_rids
);
1043 for (i
= 0; i
< num_rids
&& status
== 0; i
++)
1045 struct sam_passwd
*sam_pass
;
1049 fstrcpy(user_name
, unistrn2(q_u
->uni_user_name
[i
].buffer
,
1050 q_u
->uni_user_name
[i
].uni_str_len
));
1052 /* find the user account */
1054 sam_pass
= get_smb21pwd_entry(user_name
, 0);
1057 if (sam_pass
== NULL
)
1059 status
= 0xC0000000 | NT_STATUS_NO_SUCH_USER
;
1064 rid
[i
] = sam_pass
->user_rid
;
1070 rid
[0] = BUILTIN_ALIAS_RID_USERS
;
1072 init_samr_r_lookup_ids(&r_u
, num_rids
, rid
, NT_STATUS_OK
);
1074 DEBUG(5,("_samr_lookup_ids: %d\n", __LINE__
));
1080 /*******************************************************************
1082 ********************************************************************/
1084 NTSTATUS
_samr_lookup_names(pipes_struct
*p
, SAMR_Q_LOOKUP_NAMES
*q_u
, SAMR_R_LOOKUP_NAMES
*r_u
)
1086 uint32 rid
[MAX_SAM_ENTRIES
];
1088 enum SID_NAME_USE type
[MAX_SAM_ENTRIES
];
1089 enum SID_NAME_USE local_type
;
1091 int num_rids
= q_u
->num_names2
;
1096 r_u
->status
= NT_STATUS_OK
;
1098 DEBUG(5,("_samr_lookup_names: %d\n", __LINE__
));
1103 if (!get_lsa_policy_samr_sid(p
, &q_u
->pol
, &pol_sid
, &acc_granted
)) {
1104 init_samr_r_lookup_names(p
->mem_ctx
, r_u
, 0, NULL
, NULL
, NT_STATUS_OBJECT_TYPE_MISMATCH
);
1108 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 */
1112 if (num_rids
> MAX_SAM_ENTRIES
) {
1113 num_rids
= MAX_SAM_ENTRIES
;
1114 DEBUG(5,("_samr_lookup_names: truncating entries to %d\n", num_rids
));
1117 DEBUG(5,("_samr_lookup_names: looking name on SID %s\n", sid_to_string(sid_str
, &pol_sid
)));
1119 for (i
= 0; i
< num_rids
; i
++) {
1124 r_u
->status
= NT_STATUS_NONE_MAPPED
;
1126 rid
[i
] = 0xffffffff;
1127 type
[i
] = SID_NAME_UNKNOWN
;
1129 ret
= rpcstr_pull(name
, q_u
->uni_name
[i
].buffer
, sizeof(name
), q_u
->uni_name
[i
].uni_str_len
*2, 0);
1132 * we are only looking for a name
1133 * the SID we get back can be outside
1134 * the scope of the pol_sid
1136 * in clear: it prevents to reply to domain\group: yes
1137 * when only builtin\group exists.
1139 * a cleaner code is to add the sid of the domain we're looking in
1140 * to the local_lookup_name function.
1143 if ((ret
> 0) && local_lookup_name(name
, &sid
, &local_type
)) {
1144 sid_split_rid(&sid
, &local_rid
);
1146 if (sid_equal(&sid
, &pol_sid
)) {
1149 /* Windows does not return WKN_GRP here, even
1150 * on lookups in builtin */
1151 type
[i
] = (local_type
== SID_NAME_WKN_GRP
) ?
1152 SID_NAME_ALIAS
: local_type
;
1154 r_u
->status
= NT_STATUS_OK
;
1159 init_samr_r_lookup_names(p
->mem_ctx
, r_u
, num_rids
, rid
, (uint32
*)type
, r_u
->status
);
1161 DEBUG(5,("_samr_lookup_names: %d\n", __LINE__
));
1166 /*******************************************************************
1167 _samr_chgpasswd_user
1168 ********************************************************************/
1170 NTSTATUS
_samr_chgpasswd_user(pipes_struct
*p
, SAMR_Q_CHGPASSWD_USER
*q_u
, SAMR_R_CHGPASSWD_USER
*r_u
)
1175 DEBUG(5,("_samr_chgpasswd_user: %d\n", __LINE__
));
1177 r_u
->status
= NT_STATUS_OK
;
1179 rpcstr_pull(user_name
, q_u
->uni_user_name
.buffer
, sizeof(user_name
), q_u
->uni_user_name
.uni_str_len
*2, 0);
1180 rpcstr_pull(wks
, q_u
->uni_dest_host
.buffer
, sizeof(wks
), q_u
->uni_dest_host
.uni_str_len
*2,0);
1182 DEBUG(5,("samr_chgpasswd_user: user: %s wks: %s\n", user_name
, wks
));
1185 * Pass the user through the NT -> unix user mapping
1189 (void)map_username(user_name
);
1192 * UNIX username case mangling not required, pass_oem_change
1193 * is case insensitive.
1196 r_u
->status
= pass_oem_change(user_name
, q_u
->lm_newpass
.pass
, q_u
->lm_oldhash
.hash
,
1197 q_u
->nt_newpass
.pass
, q_u
->nt_oldhash
.hash
);
1199 init_samr_r_chgpasswd_user(r_u
, r_u
->status
);
1201 DEBUG(5,("_samr_chgpasswd_user: %d\n", __LINE__
));
1206 /*******************************************************************
1207 makes a SAMR_R_LOOKUP_RIDS structure.
1208 ********************************************************************/
1210 static BOOL
make_samr_lookup_rids(TALLOC_CTX
*ctx
, uint32 num_names
,
1211 const char **names
, UNIHDR
**pp_hdr_name
,
1212 UNISTR2
**pp_uni_name
)
1215 UNIHDR
*hdr_name
=NULL
;
1216 UNISTR2
*uni_name
=NULL
;
1218 *pp_uni_name
= NULL
;
1219 *pp_hdr_name
= NULL
;
1221 if (num_names
!= 0) {
1222 hdr_name
= TALLOC_ZERO_ARRAY(ctx
, UNIHDR
, num_names
);
1223 if (hdr_name
== NULL
)
1226 uni_name
= TALLOC_ZERO_ARRAY(ctx
,UNISTR2
, num_names
);
1227 if (uni_name
== NULL
)
1231 for (i
= 0; i
< num_names
; i
++) {
1232 DEBUG(10, ("names[%d]:%s\n", i
, names
[i
] && *names
[i
] ? names
[i
] : ""));
1233 init_unistr2(&uni_name
[i
], names
[i
], UNI_FLAGS_NONE
);
1234 init_uni_hdr(&hdr_name
[i
], &uni_name
[i
]);
1237 *pp_uni_name
= uni_name
;
1238 *pp_hdr_name
= hdr_name
;
1243 /*******************************************************************
1245 ********************************************************************/
1247 NTSTATUS
_samr_lookup_rids(pipes_struct
*p
, SAMR_Q_LOOKUP_RIDS
*q_u
, SAMR_R_LOOKUP_RIDS
*r_u
)
1250 uint32
*attrs
= NULL
;
1251 UNIHDR
*hdr_name
= NULL
;
1252 UNISTR2
*uni_name
= NULL
;
1254 int num_rids
= q_u
->num_rids1
;
1257 r_u
->status
= NT_STATUS_OK
;
1259 DEBUG(5,("_samr_lookup_rids: %d\n", __LINE__
));
1261 /* find the policy handle. open a policy on it. */
1262 if (!get_lsa_policy_samr_sid(p
, &q_u
->pol
, &pol_sid
, &acc_granted
))
1263 return NT_STATUS_INVALID_HANDLE
;
1265 if (num_rids
> 1000) {
1266 DEBUG(0, ("Got asked for %d rids (more than 1000) -- according "
1267 "to samba4 idl this is not possible\n", num_rids
));
1268 return NT_STATUS_UNSUCCESSFUL
;
1271 names
= TALLOC_ZERO_ARRAY(p
->mem_ctx
, const char *, num_rids
);
1272 attrs
= TALLOC_ZERO_ARRAY(p
->mem_ctx
, uint32
, num_rids
);
1274 if ((num_rids
!= 0) && ((names
== NULL
) || (attrs
== NULL
)))
1275 return NT_STATUS_NO_MEMORY
;
1277 if (!sid_equal(&pol_sid
, get_global_sam_sid())) {
1278 /* TODO: Sooner or later we need to look up BUILTIN rids as
1283 become_root(); /* lookup_sid can require root privs */
1284 r_u
->status
= pdb_lookup_rids(p
->mem_ctx
, &pol_sid
, num_rids
, q_u
->rid
,
1290 if(!make_samr_lookup_rids(p
->mem_ctx
, num_rids
, names
,
1291 &hdr_name
, &uni_name
))
1292 return NT_STATUS_NO_MEMORY
;
1294 init_samr_r_lookup_rids(r_u
, num_rids
, hdr_name
, uni_name
, attrs
);
1296 DEBUG(5,("_samr_lookup_rids: %d\n", __LINE__
));
1301 /*******************************************************************
1302 _samr_open_user. Safe - gives out no passwd info.
1303 ********************************************************************/
1305 NTSTATUS
_samr_open_user(pipes_struct
*p
, SAMR_Q_OPEN_USER
*q_u
, SAMR_R_OPEN_USER
*r_u
)
1307 SAM_ACCOUNT
*sampass
=NULL
;
1309 POLICY_HND domain_pol
= q_u
->domain_pol
;
1310 POLICY_HND
*user_pol
= &r_u
->user_pol
;
1311 struct samr_info
*info
= NULL
;
1312 SEC_DESC
*psd
= NULL
;
1314 uint32 des_access
= q_u
->access_mask
;
1320 r_u
->status
= NT_STATUS_OK
;
1322 /* find the domain policy handle and get domain SID / access bits in the domain policy. */
1324 if ( !get_lsa_policy_samr_sid(p
, &domain_pol
, &sid
, &acc_granted
) )
1325 return NT_STATUS_INVALID_HANDLE
;
1327 nt_status
= access_check_samr_function( acc_granted
,
1328 SA_RIGHT_DOMAIN_OPEN_ACCOUNT
, "_samr_open_user" );
1330 if ( !NT_STATUS_IS_OK(nt_status
) )
1333 nt_status
= pdb_init_sam_talloc(p
->mem_ctx
, &sampass
);
1335 if (!NT_STATUS_IS_OK(nt_status
))
1338 /* append the user's RID to it */
1340 if (!sid_append_rid(&sid
, q_u
->user_rid
))
1341 return NT_STATUS_NO_SUCH_USER
;
1343 /* check if access can be granted as requested by client. */
1345 make_samr_object_sd(p
->mem_ctx
, &psd
, &sd_size
, &usr_generic_mapping
, &sid
, SAMR_USR_RIGHTS_WRITE_PW
);
1346 se_map_generic(&des_access
, &usr_generic_mapping
);
1348 se_priv_copy( &se_rights
, &se_machine_account
);
1349 se_priv_add( &se_rights
, &se_add_users
);
1351 nt_status
= access_check_samr_object(psd
, p
->pipe_user
.nt_user_token
,
1352 &se_rights
, GENERIC_RIGHTS_USER_WRITE
, des_access
,
1353 &acc_granted
, "_samr_open_user");
1355 if ( !NT_STATUS_IS_OK(nt_status
) )
1359 ret
=pdb_getsampwsid(sampass
, &sid
);
1362 /* check that the SID exists in our domain. */
1364 return NT_STATUS_NO_SUCH_USER
;
1367 pdb_free_sam(&sampass
);
1369 /* associate the user's SID and access bits with the new handle. */
1370 if ((info
= get_samr_info_by_sid(&sid
)) == NULL
)
1371 return NT_STATUS_NO_MEMORY
;
1372 info
->acc_granted
= acc_granted
;
1374 /* get a (unique) handle. open a policy on it. */
1375 if (!create_policy_hnd(p
, user_pol
, free_samr_info
, (void *)info
))
1376 return NT_STATUS_OBJECT_NAME_NOT_FOUND
;
1381 /*************************************************************************
1382 get_user_info_7. Safe. Only gives out account_name.
1383 *************************************************************************/
1385 static NTSTATUS
get_user_info_7(TALLOC_CTX
*mem_ctx
, SAM_USER_INFO_7
*id7
, DOM_SID
*user_sid
)
1387 SAM_ACCOUNT
*smbpass
=NULL
;
1391 nt_status
= pdb_init_sam_talloc(mem_ctx
, &smbpass
);
1393 if (!NT_STATUS_IS_OK(nt_status
)) {
1398 ret
= pdb_getsampwsid(smbpass
, user_sid
);
1402 DEBUG(4,("User %s not found\n", sid_string_static(user_sid
)));
1403 return NT_STATUS_NO_SUCH_USER
;
1406 DEBUG(3,("User:[%s]\n", pdb_get_username(smbpass
) ));
1409 init_sam_user_info7(id7
, pdb_get_username(smbpass
) );
1411 pdb_free_sam(&smbpass
);
1413 return NT_STATUS_OK
;
1415 /*************************************************************************
1416 get_user_info_16. Safe. Only gives out acb bits.
1417 *************************************************************************/
1419 static NTSTATUS
get_user_info_16(TALLOC_CTX
*mem_ctx
, SAM_USER_INFO_16
*id16
, DOM_SID
*user_sid
)
1421 SAM_ACCOUNT
*smbpass
=NULL
;
1425 nt_status
= pdb_init_sam_talloc(mem_ctx
, &smbpass
);
1427 if (!NT_STATUS_IS_OK(nt_status
)) {
1432 ret
= pdb_getsampwsid(smbpass
, user_sid
);
1436 DEBUG(4,("User %s not found\n", sid_string_static(user_sid
)));
1437 return NT_STATUS_NO_SUCH_USER
;
1440 DEBUG(3,("User:[%s]\n", pdb_get_username(smbpass
) ));
1443 init_sam_user_info16(id16
, pdb_get_acct_ctrl(smbpass
) );
1445 pdb_free_sam(&smbpass
);
1447 return NT_STATUS_OK
;
1450 /*************************************************************************
1451 get_user_info_18. OK - this is the killer as it gives out password info.
1452 Ensure that this is only allowed on an encrypted connection with a root
1454 *************************************************************************/
1456 static NTSTATUS
get_user_info_18(pipes_struct
*p
, TALLOC_CTX
*mem_ctx
, SAM_USER_INFO_18
* id18
, DOM_SID
*user_sid
)
1458 SAM_ACCOUNT
*smbpass
=NULL
;
1462 if (!p
->ntlmssp_auth_validated
)
1463 return NT_STATUS_ACCESS_DENIED
;
1465 if (!(p
->ntlmssp_chal_flags
& NTLMSSP_NEGOTIATE_SIGN
) || !(p
->ntlmssp_chal_flags
& NTLMSSP_NEGOTIATE_SEAL
))
1466 return NT_STATUS_ACCESS_DENIED
;
1469 * Do *NOT* do become_root()/unbecome_root() here ! JRA.
1472 nt_status
= pdb_init_sam_talloc(mem_ctx
, &smbpass
);
1474 if (!NT_STATUS_IS_OK(nt_status
)) {
1478 ret
= pdb_getsampwsid(smbpass
, user_sid
);
1481 DEBUG(4, ("User %s not found\n", sid_string_static(user_sid
)));
1482 pdb_free_sam(&smbpass
);
1483 return (geteuid() == (uid_t
)0) ? NT_STATUS_NO_SUCH_USER
: NT_STATUS_ACCESS_DENIED
;
1486 DEBUG(3,("User:[%s] 0x%x\n", pdb_get_username(smbpass
), pdb_get_acct_ctrl(smbpass
) ));
1488 if ( pdb_get_acct_ctrl(smbpass
) & ACB_DISABLED
) {
1489 pdb_free_sam(&smbpass
);
1490 return NT_STATUS_ACCOUNT_DISABLED
;
1494 init_sam_user_info18(id18
, pdb_get_lanman_passwd(smbpass
), pdb_get_nt_passwd(smbpass
));
1496 pdb_free_sam(&smbpass
);
1498 return NT_STATUS_OK
;
1501 /*************************************************************************
1503 *************************************************************************/
1505 static NTSTATUS
get_user_info_20(TALLOC_CTX
*mem_ctx
, SAM_USER_INFO_20
*id20
, DOM_SID
*user_sid
)
1507 SAM_ACCOUNT
*sampass
=NULL
;
1510 pdb_init_sam_talloc(mem_ctx
, &sampass
);
1513 ret
= pdb_getsampwsid(sampass
, user_sid
);
1517 DEBUG(4,("User %s not found\n", sid_string_static(user_sid
)));
1518 return NT_STATUS_NO_SUCH_USER
;
1521 samr_clear_sam_passwd(sampass
);
1523 DEBUG(3,("User:[%s]\n", pdb_get_username(sampass
) ));
1526 init_sam_user_info20A(id20
, sampass
);
1528 pdb_free_sam(&sampass
);
1530 return NT_STATUS_OK
;
1533 /*************************************************************************
1535 *************************************************************************/
1537 static NTSTATUS
get_user_info_21(TALLOC_CTX
*mem_ctx
, SAM_USER_INFO_21
*id21
,
1538 DOM_SID
*user_sid
, DOM_SID
*domain_sid
)
1540 SAM_ACCOUNT
*sampass
=NULL
;
1544 nt_status
= pdb_init_sam_talloc(mem_ctx
, &sampass
);
1545 if (!NT_STATUS_IS_OK(nt_status
)) {
1550 ret
= pdb_getsampwsid(sampass
, user_sid
);
1554 DEBUG(4,("User %s not found\n", sid_string_static(user_sid
)));
1555 return NT_STATUS_NO_SUCH_USER
;
1558 samr_clear_sam_passwd(sampass
);
1560 DEBUG(3,("User:[%s]\n", pdb_get_username(sampass
) ));
1563 nt_status
= init_sam_user_info21A(id21
, sampass
, domain_sid
);
1565 pdb_free_sam(&sampass
);
1567 return NT_STATUS_OK
;
1570 /*******************************************************************
1571 _samr_query_userinfo
1572 ********************************************************************/
1574 NTSTATUS
_samr_query_userinfo(pipes_struct
*p
, SAMR_Q_QUERY_USERINFO
*q_u
, SAMR_R_QUERY_USERINFO
*r_u
)
1576 SAM_USERINFO_CTR
*ctr
;
1577 struct samr_info
*info
= NULL
;
1581 r_u
->status
=NT_STATUS_OK
;
1583 /* search for the handle */
1584 if (!find_policy_by_hnd(p
, &q_u
->pol
, (void **)&info
))
1585 return NT_STATUS_INVALID_HANDLE
;
1587 domain_sid
= info
->sid
;
1589 sid_split_rid(&domain_sid
, &rid
);
1591 if (!sid_check_is_in_our_domain(&info
->sid
))
1592 return NT_STATUS_OBJECT_TYPE_MISMATCH
;
1594 DEBUG(5,("_samr_query_userinfo: sid:%s\n", sid_string_static(&info
->sid
)));
1596 ctr
= TALLOC_ZERO_P(p
->mem_ctx
, SAM_USERINFO_CTR
);
1598 return NT_STATUS_NO_MEMORY
;
1602 /* ok! user info levels (lots: see MSDEV help), off we go... */
1603 ctr
->switch_value
= q_u
->switch_value
;
1605 switch (q_u
->switch_value
) {
1607 ctr
->info
.id7
= TALLOC_ZERO_P(p
->mem_ctx
, SAM_USER_INFO_7
);
1608 if (ctr
->info
.id7
== NULL
)
1609 return NT_STATUS_NO_MEMORY
;
1611 if (!NT_STATUS_IS_OK(r_u
->status
= get_user_info_7(p
->mem_ctx
, ctr
->info
.id7
, &info
->sid
)))
1615 ctr
->info
.id16
= TALLOC_ZERO_P(p
->mem_ctx
, SAM_USER_INFO_16
);
1616 if (ctr
->info
.id16
== NULL
)
1617 return NT_STATUS_NO_MEMORY
;
1619 if (!NT_STATUS_IS_OK(r_u
->status
= get_user_info_16(p
->mem_ctx
, ctr
->info
.id16
, &info
->sid
)))
1624 /* whoops - got this wrong. i think. or don't understand what's happening. */
1628 info
= (void *)&id11
;
1630 expire
.low
= 0xffffffff;
1631 expire
.high
= 0x7fffffff;
1633 ctr
->info
.id
= TALLOC_ZERO_P(p
->mem_ctx
, SAM_USER_INFO_17
));
1634 ZERO_STRUCTP(ctr
->info
.id17
);
1635 init_sam_user_info17(ctr
->info
.id17
, &expire
,
1636 "BROOKFIELDS$", /* name */
1637 0x03ef, /* user rid */
1638 0x201, /* group rid */
1639 0x0080); /* acb info */
1646 ctr
->info
.id18
= TALLOC_ZERO_P(p
->mem_ctx
, SAM_USER_INFO_18
);
1647 if (ctr
->info
.id18
== NULL
)
1648 return NT_STATUS_NO_MEMORY
;
1650 if (!NT_STATUS_IS_OK(r_u
->status
= get_user_info_18(p
, p
->mem_ctx
, ctr
->info
.id18
, &info
->sid
)))
1655 ctr
->info
.id20
= TALLOC_ZERO_P(p
->mem_ctx
,SAM_USER_INFO_20
);
1656 if (ctr
->info
.id20
== NULL
)
1657 return NT_STATUS_NO_MEMORY
;
1658 if (!NT_STATUS_IS_OK(r_u
->status
= get_user_info_20(p
->mem_ctx
, ctr
->info
.id20
, &info
->sid
)))
1663 ctr
->info
.id21
= TALLOC_ZERO_P(p
->mem_ctx
,SAM_USER_INFO_21
);
1664 if (ctr
->info
.id21
== NULL
)
1665 return NT_STATUS_NO_MEMORY
;
1666 if (!NT_STATUS_IS_OK(r_u
->status
= get_user_info_21(p
->mem_ctx
, ctr
->info
.id21
,
1667 &info
->sid
, &domain_sid
)))
1672 return NT_STATUS_INVALID_INFO_CLASS
;
1675 init_samr_r_query_userinfo(r_u
, ctr
, r_u
->status
);
1677 DEBUG(5,("_samr_query_userinfo: %d\n", __LINE__
));
1682 /*******************************************************************
1683 samr_reply_query_usergroups
1684 ********************************************************************/
1686 NTSTATUS
_samr_query_usergroups(pipes_struct
*p
, SAMR_Q_QUERY_USERGROUPS
*q_u
, SAMR_R_QUERY_USERGROUPS
*r_u
)
1688 SAM_ACCOUNT
*sam_pass
=NULL
;
1689 struct passwd
*passwd
;
1692 DOM_GID
*gids
= NULL
;
1701 * from the SID in the request:
1702 * we should send back the list of DOMAIN GROUPS
1703 * the user is a member of
1705 * and only the DOMAIN GROUPS
1706 * no ALIASES !!! neither aliases of the domain
1707 * nor aliases of the builtin SID
1712 r_u
->status
= NT_STATUS_OK
;
1714 DEBUG(5,("_samr_query_usergroups: %d\n", __LINE__
));
1716 /* find the policy handle. open a policy on it. */
1717 if (!get_lsa_policy_samr_sid(p
, &q_u
->pol
, &sid
, &acc_granted
))
1718 return NT_STATUS_INVALID_HANDLE
;
1720 if (!NT_STATUS_IS_OK(r_u
->status
= access_check_samr_function(acc_granted
, SA_RIGHT_USER_GET_GROUPS
, "_samr_query_usergroups"))) {
1724 if (!sid_check_is_in_our_domain(&sid
))
1725 return NT_STATUS_OBJECT_TYPE_MISMATCH
;
1727 pdb_init_sam(&sam_pass
);
1730 ret
= pdb_getsampwsid(sam_pass
, &sid
);
1734 pdb_free_sam(&sam_pass
);
1735 return NT_STATUS_NO_SUCH_USER
;
1738 passwd
= getpwnam_alloc(pdb_get_username(sam_pass
));
1739 if (passwd
== NULL
) {
1740 pdb_free_sam(&sam_pass
);
1741 return NT_STATUS_NO_SUCH_USER
;
1747 result
= pdb_enum_group_memberships(pdb_get_username(sam_pass
),
1749 &sids
, &unix_gids
, &num_groups
);
1752 pdb_free_sam(&sam_pass
);
1753 passwd_free(&passwd
);
1755 if (!NT_STATUS_IS_OK(result
))
1758 SAFE_FREE(unix_gids
);
1763 for (i
=0; i
<num_groups
; i
++) {
1766 if (!sid_peek_check_rid(get_global_sam_sid(),
1770 gids
= TALLOC_REALLOC_ARRAY(p
->mem_ctx
, gids
, DOM_GID
, num_gids
+1);
1771 gids
[num_gids
].attr
=7;
1772 gids
[num_gids
].g_rid
= rid
;
1777 /* construct the response. lkclXXXX: gids are not copied! */
1778 init_samr_r_query_usergroups(r_u
, num_groups
, gids
, r_u
->status
);
1780 DEBUG(5,("_samr_query_usergroups: %d\n", __LINE__
));
1785 /*******************************************************************
1786 _samr_query_dom_info
1787 ********************************************************************/
1789 NTSTATUS
_samr_query_dom_info(pipes_struct
*p
, SAMR_Q_QUERY_DOMAIN_INFO
*q_u
, SAMR_R_QUERY_DOMAIN_INFO
*r_u
)
1791 struct samr_info
*info
= NULL
;
1793 uint32 min_pass_len
,pass_hist
,flag
;
1794 time_t u_expire
, u_min_age
;
1795 NTTIME nt_expire
, nt_min_age
;
1797 time_t u_lock_duration
, u_reset_time
;
1798 NTTIME nt_lock_duration
, nt_reset_time
;
1804 uint32 account_policy_temp
;
1807 uint32 num_users
=0, num_groups
=0, num_aliases
=0;
1809 if ((ctr
= TALLOC_ZERO_P(p
->mem_ctx
, SAM_UNK_CTR
)) == NULL
)
1810 return NT_STATUS_NO_MEMORY
;
1814 r_u
->status
= NT_STATUS_OK
;
1816 DEBUG(5,("_samr_query_dom_info: %d\n", __LINE__
));
1818 /* find the policy handle. open a policy on it. */
1819 if (!find_policy_by_hnd(p
, &q_u
->domain_pol
, (void **)&info
))
1820 return NT_STATUS_INVALID_HANDLE
;
1822 switch (q_u
->switch_value
) {
1825 account_policy_get(AP_MIN_PASSWORD_LEN
, &account_policy_temp
);
1826 min_pass_len
= account_policy_temp
;
1828 account_policy_get(AP_PASSWORD_HISTORY
, &account_policy_temp
);
1829 pass_hist
= account_policy_temp
;
1831 account_policy_get(AP_USER_MUST_LOGON_TO_CHG_PASS
, &account_policy_temp
);
1832 flag
= account_policy_temp
;
1834 account_policy_get(AP_MAX_PASSWORD_AGE
, &account_policy_temp
);
1835 u_expire
= account_policy_temp
;
1837 account_policy_get(AP_MIN_PASSWORD_AGE
, &account_policy_temp
);
1838 u_min_age
= account_policy_temp
;
1840 unix_to_nt_time_abs(&nt_expire
, u_expire
);
1841 unix_to_nt_time_abs(&nt_min_age
, u_min_age
);
1843 init_unk_info1(&ctr
->info
.inf1
, (uint16
)min_pass_len
, (uint16
)pass_hist
,
1844 flag
, nt_expire
, nt_min_age
);
1848 num_users
=count_sam_users(&info
->disp_info
,
1850 num_groups
=count_sam_groups(&info
->disp_info
);
1853 account_policy_get(AP_TIME_TO_LOGOUT
, &account_policy_temp
);
1854 u_logout
= account_policy_temp
;
1856 unix_to_nt_time_abs(&nt_logout
, u_logout
);
1858 server_role
= ROLE_DOMAIN_PDC
;
1859 if (lp_server_role() == ROLE_DOMAIN_BDC
)
1860 server_role
= ROLE_DOMAIN_BDC
;
1862 /* The time call below is to get a sequence number for the sam. FIXME !!! JRA. */
1863 init_unk_info2(&ctr
->info
.inf2
, lp_serverstring(), lp_workgroup(), global_myname(), time(NULL
),
1864 num_users
, num_groups
, num_aliases
, nt_logout
, server_role
);
1867 account_policy_get(AP_TIME_TO_LOGOUT
, (unsigned int *)&u_logout
);
1868 unix_to_nt_time_abs(&nt_logout
, u_logout
);
1870 init_unk_info3(&ctr
->info
.inf3
, nt_logout
);
1873 init_unk_info5(&ctr
->info
.inf5
, global_myname());
1876 init_unk_info6(&ctr
->info
.inf6
);
1879 server_role
= ROLE_DOMAIN_PDC
;
1880 if (lp_server_role() == ROLE_DOMAIN_BDC
)
1881 server_role
= ROLE_DOMAIN_BDC
;
1883 init_unk_info7(&ctr
->info
.inf7
, server_role
);
1886 init_unk_info8(&ctr
->info
.inf8
, (uint32
) time(NULL
));
1889 account_policy_get(AP_LOCK_ACCOUNT_DURATION
, &account_policy_temp
);
1890 u_lock_duration
= account_policy_temp
;
1891 if (u_lock_duration
!= -1)
1892 u_lock_duration
*= 60;
1894 account_policy_get(AP_RESET_COUNT_TIME
, &account_policy_temp
);
1895 u_reset_time
= account_policy_temp
* 60;
1897 account_policy_get(AP_BAD_ATTEMPT_LOCKOUT
, &account_policy_temp
);
1898 lockout
= account_policy_temp
;
1900 unix_to_nt_time_abs(&nt_lock_duration
, u_lock_duration
);
1901 unix_to_nt_time_abs(&nt_reset_time
, u_reset_time
);
1903 init_unk_info12(&ctr
->info
.inf12
, nt_lock_duration
, nt_reset_time
, (uint16
)lockout
);
1906 return NT_STATUS_INVALID_INFO_CLASS
;
1909 init_samr_r_query_dom_info(r_u
, q_u
->switch_value
, ctr
, NT_STATUS_OK
);
1911 DEBUG(5,("_samr_query_dom_info: %d\n", __LINE__
));
1916 /*******************************************************************
1918 Create an account, can be either a normal user or a machine.
1919 This funcion will need to be updated for bdc/domain trusts.
1920 ********************************************************************/
1922 NTSTATUS
_samr_create_user(pipes_struct
*p
, SAMR_Q_CREATE_USER
*q_u
, SAMR_R_CREATE_USER
*r_u
)
1924 SAM_ACCOUNT
*sam_pass
=NULL
;
1928 POLICY_HND dom_pol
= q_u
->domain_pol
;
1929 UNISTR2 user_account
= q_u
->uni_name
;
1930 uint16 acb_info
= q_u
->acb_info
;
1931 POLICY_HND
*user_pol
= &r_u
->user_pol
;
1932 struct samr_info
*info
= NULL
;
1940 /* check this, when giving away 'add computer to domain' privs */
1941 uint32 des_access
= GENERIC_RIGHTS_USER_ALL_ACCESS
;
1942 BOOL can_add_account
= False
;
1945 /* Get the domain SID stored in the domain policy */
1946 if (!get_lsa_policy_samr_sid(p
, &dom_pol
, &sid
, &acc_granted
))
1947 return NT_STATUS_INVALID_HANDLE
;
1949 if (!NT_STATUS_IS_OK(nt_status
= access_check_samr_function(acc_granted
, SA_RIGHT_DOMAIN_CREATE_USER
, "_samr_create_user"))) {
1953 if (!(acb_info
== ACB_NORMAL
|| acb_info
== ACB_DOMTRUST
|| acb_info
== ACB_WSTRUST
|| acb_info
== ACB_SVRTRUST
)) {
1954 /* Match Win2k, and return NT_STATUS_INVALID_PARAMETER if
1955 this parameter is not an account type */
1956 return NT_STATUS_INVALID_PARAMETER
;
1959 rpcstr_pull(account
, user_account
.buffer
, sizeof(account
), user_account
.uni_str_len
*2, 0);
1960 strlower_m(account
);
1962 pdb_init_sam(&sam_pass
);
1965 ret
= pdb_getsampwnam(sam_pass
, account
);
1968 /* this account exists: say so */
1969 pdb_free_sam(&sam_pass
);
1970 return NT_STATUS_USER_EXISTS
;
1973 pdb_free_sam(&sam_pass
);
1975 /*********************************************************************
1976 * HEADS UP! If we have to create a new user account, we have to get
1977 * a new RID from somewhere. This used to be done by the passdb
1978 * backend. It has been moved into idmap now. Since idmap is now
1979 * wrapped up behind winbind, this means you have to run winbindd if you
1980 * want new accounts to get a new RID when "enable rid algorithm = no".
1981 * Tough. We now have a uniform way of allocating RIDs regardless
1982 * of what ever passdb backend people may use.
1983 * --jerry (2003-07-10)
1984 *********************************************************************/
1986 pw
= Get_Pwnam(account
);
1988 /* determine which user right we need to check based on the acb_info */
1990 if ( acb_info
& ACB_WSTRUST
)
1992 pstrcpy(add_script
, lp_addmachine_script());
1993 se_priv_copy( &se_rights
, &se_machine_account
);
1994 can_add_account
= user_has_privileges( p
->pipe_user
.nt_user_token
, &se_rights
);
1996 /* usrmgr.exe (and net rpc trustdom grant) creates a normal user
1997 account for domain trusts and changes the ACB flags later */
1998 else if ( acb_info
& ACB_NORMAL
&& (account
[strlen(account
)-1] != '$') )
2000 pstrcpy(add_script
, lp_adduser_script());
2001 se_priv_copy( &se_rights
, &se_add_users
);
2002 can_add_account
= user_has_privileges( p
->pipe_user
.nt_user_token
, &se_rights
);
2004 else /* implicit assumption of a BDC or domain trust account here (we already check the flags earlier) */
2006 pstrcpy(add_script
, lp_addmachine_script());
2007 if ( lp_enable_privileges() ) {
2008 /* only Domain Admins can add a BDC or domain trust */
2009 se_priv_copy( &se_rights
, &se_priv_none
);
2010 can_add_account
= nt_token_check_domain_rid( p
->pipe_user
.nt_user_token
, DOMAIN_GROUP_RID_ADMINS
);
2014 DEBUG(5, ("_samr_create_user: %s can add this account : %s\n",
2015 p
->pipe_user_name
, can_add_account
? "True":"False" ));
2017 /********** BEGIN Admin BLOCK **********/
2019 if ( can_add_account
)
2026 all_string_sub(add_script
, "%u", account
, sizeof(add_script
));
2027 add_ret
= smbrun(add_script
,NULL
);
2028 DEBUG(add_ret
? 0 : 3,("_samr_create_user: Running the command `%s' gave %d\n", add_script
, add_ret
));
2032 /* implicit call to getpwnam() next. we have a valid SID coming out of this call */
2034 flush_pwnam_cache();
2035 nt_status
= pdb_init_sam_new(&sam_pass
, account
, new_rid
);
2037 /* this code is order such that we have no unnecessary retuns
2038 out of the admin block of code */
2040 if ( NT_STATUS_IS_OK(nt_status
) ) {
2041 pdb_set_acct_ctrl(sam_pass
, acb_info
, PDB_CHANGED
);
2043 if ( !(ret
= pdb_add_sam_account(sam_pass
)) ) {
2044 pdb_free_sam(&sam_pass
);
2045 DEBUG(0, ("could not add user/computer %s to passdb. Check permissions?\n",
2047 nt_status
= NT_STATUS_ACCESS_DENIED
;
2051 if ( can_add_account
)
2054 /********** END Admin BLOCK **********/
2056 /* now check for failure */
2058 if ( !NT_STATUS_IS_OK(nt_status
) )
2061 /* Get the user's SID */
2063 sid_copy(&sid
, pdb_get_user_sid(sam_pass
));
2065 make_samr_object_sd(p
->mem_ctx
, &psd
, &sd_size
, &usr_generic_mapping
, &sid
, SAMR_USR_RIGHTS_WRITE_PW
);
2066 se_map_generic(&des_access
, &usr_generic_mapping
);
2068 nt_status
= access_check_samr_object(psd
, p
->pipe_user
.nt_user_token
,
2069 &se_rights
, GENERIC_RIGHTS_USER_WRITE
, des_access
,
2070 &acc_granted
, "_samr_create_user");
2072 if ( !NT_STATUS_IS_OK(nt_status
) ) {
2076 /* associate the user's SID with the new handle. */
2077 if ((info
= get_samr_info_by_sid(&sid
)) == NULL
) {
2078 pdb_free_sam(&sam_pass
);
2079 return NT_STATUS_NO_MEMORY
;
2084 info
->acc_granted
= acc_granted
;
2086 /* get a (unique) handle. open a policy on it. */
2087 if (!create_policy_hnd(p
, user_pol
, free_samr_info
, (void *)info
)) {
2088 pdb_free_sam(&sam_pass
);
2089 return NT_STATUS_OBJECT_NAME_NOT_FOUND
;
2092 r_u
->user_rid
=pdb_get_user_rid(sam_pass
);
2094 r_u
->access_granted
= acc_granted
;
2096 pdb_free_sam(&sam_pass
);
2098 return NT_STATUS_OK
;
2101 /*******************************************************************
2102 samr_reply_connect_anon
2103 ********************************************************************/
2105 NTSTATUS
_samr_connect_anon(pipes_struct
*p
, SAMR_Q_CONNECT_ANON
*q_u
, SAMR_R_CONNECT_ANON
*r_u
)
2107 struct samr_info
*info
= NULL
;
2108 uint32 des_access
= q_u
->access_mask
;
2112 if (!pipe_access_check(p
)) {
2113 DEBUG(3, ("access denied to samr_connect_anon\n"));
2114 r_u
->status
= NT_STATUS_ACCESS_DENIED
;
2118 /* set up the SAMR connect_anon response */
2120 r_u
->status
= NT_STATUS_OK
;
2122 /* associate the user's SID with the new handle. */
2123 if ((info
= get_samr_info_by_sid(NULL
)) == NULL
)
2124 return NT_STATUS_NO_MEMORY
;
2126 /* don't give away the farm but this is probably ok. The SA_RIGHT_SAM_ENUM_DOMAINS
2127 was observed from a win98 client trying to enumerate users (when configured
2128 user level access control on shares) --jerry */
2130 se_map_generic( &des_access
, &sam_generic_mapping
);
2131 info
->acc_granted
= des_access
& (SA_RIGHT_SAM_ENUM_DOMAINS
|SA_RIGHT_SAM_OPEN_DOMAIN
);
2133 info
->status
= q_u
->unknown_0
;
2135 /* get a (unique) handle. open a policy on it. */
2136 if (!create_policy_hnd(p
, &r_u
->connect_pol
, free_samr_info
, (void *)info
))
2137 return NT_STATUS_OBJECT_NAME_NOT_FOUND
;
2142 /*******************************************************************
2144 ********************************************************************/
2146 NTSTATUS
_samr_connect(pipes_struct
*p
, SAMR_Q_CONNECT
*q_u
, SAMR_R_CONNECT
*r_u
)
2148 struct samr_info
*info
= NULL
;
2149 SEC_DESC
*psd
= NULL
;
2151 uint32 des_access
= q_u
->access_mask
;
2156 DEBUG(5,("_samr_connect: %d\n", __LINE__
));
2160 if (!pipe_access_check(p
)) {
2161 DEBUG(3, ("access denied to samr_connect\n"));
2162 r_u
->status
= NT_STATUS_ACCESS_DENIED
;
2166 make_samr_object_sd(p
->mem_ctx
, &psd
, &sd_size
, &sam_generic_mapping
, NULL
, 0);
2167 se_map_generic(&des_access
, &sam_generic_mapping
);
2169 nt_status
= access_check_samr_object(psd
, p
->pipe_user
.nt_user_token
,
2170 NULL
, 0, des_access
, &acc_granted
, "_samr_connect");
2172 if ( !NT_STATUS_IS_OK(nt_status
) )
2175 r_u
->status
= NT_STATUS_OK
;
2177 /* associate the user's SID and access granted with the new handle. */
2178 if ((info
= get_samr_info_by_sid(NULL
)) == NULL
)
2179 return NT_STATUS_NO_MEMORY
;
2181 info
->acc_granted
= acc_granted
;
2182 info
->status
= q_u
->access_mask
;
2184 /* get a (unique) handle. open a policy on it. */
2185 if (!create_policy_hnd(p
, &r_u
->connect_pol
, free_samr_info
, (void *)info
))
2186 return NT_STATUS_OBJECT_NAME_NOT_FOUND
;
2188 DEBUG(5,("_samr_connect: %d\n", __LINE__
));
2193 /*******************************************************************
2195 ********************************************************************/
2197 NTSTATUS
_samr_connect4(pipes_struct
*p
, SAMR_Q_CONNECT4
*q_u
, SAMR_R_CONNECT4
*r_u
)
2199 struct samr_info
*info
= NULL
;
2200 SEC_DESC
*psd
= NULL
;
2202 uint32 des_access
= q_u
->access_mask
;
2207 DEBUG(5,("_samr_connect4: %d\n", __LINE__
));
2211 if (!pipe_access_check(p
)) {
2212 DEBUG(3, ("access denied to samr_connect4\n"));
2213 r_u
->status
= NT_STATUS_ACCESS_DENIED
;
2217 make_samr_object_sd(p
->mem_ctx
, &psd
, &sd_size
, &sam_generic_mapping
, NULL
, 0);
2218 se_map_generic(&des_access
, &sam_generic_mapping
);
2220 nt_status
= access_check_samr_object(psd
, p
->pipe_user
.nt_user_token
,
2221 NULL
, 0, des_access
, &acc_granted
, "_samr_connect4");
2223 if ( !NT_STATUS_IS_OK(nt_status
) )
2226 r_u
->status
= NT_STATUS_OK
;
2228 /* associate the user's SID and access granted with the new handle. */
2229 if ((info
= get_samr_info_by_sid(NULL
)) == NULL
)
2230 return NT_STATUS_NO_MEMORY
;
2232 info
->acc_granted
= acc_granted
;
2233 info
->status
= q_u
->access_mask
;
2235 /* get a (unique) handle. open a policy on it. */
2236 if (!create_policy_hnd(p
, &r_u
->connect_pol
, free_samr_info
, (void *)info
))
2237 return NT_STATUS_OBJECT_NAME_NOT_FOUND
;
2239 DEBUG(5,("_samr_connect: %d\n", __LINE__
));
2244 /**********************************************************************
2245 api_samr_lookup_domain
2246 **********************************************************************/
2248 NTSTATUS
_samr_lookup_domain(pipes_struct
*p
, SAMR_Q_LOOKUP_DOMAIN
*q_u
, SAMR_R_LOOKUP_DOMAIN
*r_u
)
2250 struct samr_info
*info
;
2251 fstring domain_name
;
2254 r_u
->status
= NT_STATUS_OK
;
2256 if (!find_policy_by_hnd(p
, &q_u
->connect_pol
, (void**)&info
))
2257 return NT_STATUS_INVALID_HANDLE
;
2259 /* win9x user manager likes to use SA_RIGHT_SAM_ENUM_DOMAINS here.
2260 Reverted that change so we will work with RAS servers again */
2262 if (!NT_STATUS_IS_OK(r_u
->status
= access_check_samr_function(info
->acc_granted
,
2263 SA_RIGHT_SAM_OPEN_DOMAIN
, "_samr_lookup_domain")))
2268 rpcstr_pull(domain_name
, q_u
->uni_domain
.buffer
, sizeof(domain_name
), q_u
->uni_domain
.uni_str_len
*2, 0);
2272 if (!secrets_fetch_domain_sid(domain_name
, &sid
)) {
2273 r_u
->status
= NT_STATUS_NO_SUCH_DOMAIN
;
2276 DEBUG(2,("Returning domain sid for domain %s -> %s\n", domain_name
, sid_string_static(&sid
)));
2278 init_samr_r_lookup_domain(r_u
, &sid
, r_u
->status
);
2283 /******************************************************************
2284 makes a SAMR_R_ENUM_DOMAINS structure.
2285 ********************************************************************/
2287 static BOOL
make_enum_domains(TALLOC_CTX
*ctx
, SAM_ENTRY
**pp_sam
,
2288 UNISTR2
**pp_uni_name
, uint32 num_sam_entries
, fstring doms
[])
2294 DEBUG(5, ("make_enum_domains\n"));
2297 *pp_uni_name
= NULL
;
2299 if (num_sam_entries
== 0)
2302 sam
= TALLOC_ZERO_ARRAY(ctx
, SAM_ENTRY
, num_sam_entries
);
2303 uni_name
= TALLOC_ZERO_ARRAY(ctx
, UNISTR2
, num_sam_entries
);
2305 if (sam
== NULL
|| uni_name
== NULL
)
2308 for (i
= 0; i
< num_sam_entries
; i
++) {
2309 init_unistr2(&uni_name
[i
], doms
[i
], UNI_FLAGS_NONE
);
2310 init_sam_entry(&sam
[i
], &uni_name
[i
], 0);
2314 *pp_uni_name
= uni_name
;
2319 /**********************************************************************
2320 api_samr_enum_domains
2321 **********************************************************************/
2323 NTSTATUS
_samr_enum_domains(pipes_struct
*p
, SAMR_Q_ENUM_DOMAINS
*q_u
, SAMR_R_ENUM_DOMAINS
*r_u
)
2325 struct samr_info
*info
;
2326 uint32 num_entries
= 2;
2330 r_u
->status
= NT_STATUS_OK
;
2332 if (!find_policy_by_hnd(p
, &q_u
->pol
, (void**)&info
))
2333 return NT_STATUS_INVALID_HANDLE
;
2335 if (!NT_STATUS_IS_OK(r_u
->status
= access_check_samr_function(info
->acc_granted
, SA_RIGHT_SAM_ENUM_DOMAINS
, "_samr_enum_domains"))) {
2339 name
= get_global_sam_name();
2341 fstrcpy(dom
[0],name
);
2343 fstrcpy(dom
[1],"Builtin");
2345 if (!make_enum_domains(p
->mem_ctx
, &r_u
->sam
, &r_u
->uni_dom_name
, num_entries
, dom
))
2346 return NT_STATUS_NO_MEMORY
;
2348 init_samr_r_enum_domains(r_u
, q_u
->start_idx
+ num_entries
, num_entries
);
2353 /*******************************************************************
2355 ********************************************************************/
2357 NTSTATUS
_samr_open_alias(pipes_struct
*p
, SAMR_Q_OPEN_ALIAS
*q_u
, SAMR_R_OPEN_ALIAS
*r_u
)
2360 POLICY_HND domain_pol
= q_u
->dom_pol
;
2361 uint32 alias_rid
= q_u
->rid_alias
;
2362 POLICY_HND
*alias_pol
= &r_u
->pol
;
2363 struct samr_info
*info
= NULL
;
2364 SEC_DESC
*psd
= NULL
;
2366 uint32 des_access
= q_u
->access_mask
;
2371 r_u
->status
= NT_STATUS_OK
;
2373 /* find the domain policy and get the SID / access bits stored in the domain policy */
2375 if ( !get_lsa_policy_samr_sid(p
, &domain_pol
, &sid
, &acc_granted
) )
2376 return NT_STATUS_INVALID_HANDLE
;
2378 status
= access_check_samr_function(acc_granted
,
2379 SA_RIGHT_DOMAIN_OPEN_ACCOUNT
, "_samr_open_alias");
2381 if ( !NT_STATUS_IS_OK(status
) )
2384 /* append the alias' RID to it */
2386 if (!sid_append_rid(&sid
, alias_rid
))
2387 return NT_STATUS_NO_SUCH_USER
;
2389 /*check if access can be granted as requested by client. */
2391 make_samr_object_sd(p
->mem_ctx
, &psd
, &sd_size
, &ali_generic_mapping
, NULL
, 0);
2392 se_map_generic(&des_access
,&ali_generic_mapping
);
2394 se_priv_copy( &se_rights
, &se_add_users
);
2397 status
= access_check_samr_object(psd
, p
->pipe_user
.nt_user_token
,
2398 &se_rights
, GENERIC_RIGHTS_ALIAS_WRITE
, des_access
,
2399 &acc_granted
, "_samr_open_alias");
2401 if ( !NT_STATUS_IS_OK(status
) )
2405 * we should check if the rid really exist !!!
2409 /* associate the user's SID with the new handle. */
2410 if ((info
= get_samr_info_by_sid(&sid
)) == NULL
)
2411 return NT_STATUS_NO_MEMORY
;
2413 info
->acc_granted
= acc_granted
;
2415 /* get a (unique) handle. open a policy on it. */
2416 if (!create_policy_hnd(p
, alias_pol
, free_samr_info
, (void *)info
))
2417 return NT_STATUS_OBJECT_NAME_NOT_FOUND
;
2422 /*******************************************************************
2424 ********************************************************************/
2426 static BOOL
set_user_info_16(const SAM_USER_INFO_16
*id16
, SAM_ACCOUNT
*pwd
)
2429 DEBUG(5, ("set_user_info_16: NULL id16\n"));
2434 /* FIX ME: check if the value is really changed --metze */
2435 if (!pdb_set_acct_ctrl(pwd
, id16
->acb_info
, PDB_CHANGED
)) {
2440 if(!pdb_update_sam_account(pwd
)) {
2450 /*******************************************************************
2452 ********************************************************************/
2454 static BOOL
set_user_info_18(SAM_USER_INFO_18
*id18
, SAM_ACCOUNT
*pwd
)
2458 DEBUG(2, ("set_user_info_18: id18 is NULL\n"));
2463 if (!pdb_set_lanman_passwd (pwd
, id18
->lm_pwd
, PDB_CHANGED
)) {
2467 if (!pdb_set_nt_passwd (pwd
, id18
->nt_pwd
, PDB_CHANGED
)) {
2471 if (!pdb_set_pass_changed_now (pwd
)) {
2476 if(!pdb_update_sam_account(pwd
)) {
2485 /*******************************************************************
2486 The GROUPSID field in the SAM_ACCOUNT changed. Try to tell unix.
2487 ********************************************************************/
2488 static BOOL
set_unix_primary_group(SAM_ACCOUNT
*sampass
)
2493 if (!NT_STATUS_IS_OK(sid_to_gid(pdb_get_group_sid(sampass
),
2495 DEBUG(2,("Could not get gid for primary group of "
2496 "user %s\n", pdb_get_username(sampass
)));
2500 grp
= getgrgid(gid
);
2503 DEBUG(2,("Could not find primary group %lu for "
2504 "user %s\n", (unsigned long)gid
,
2505 pdb_get_username(sampass
)));
2509 if (smb_set_primary_group(grp
->gr_name
,
2510 pdb_get_username(sampass
)) != 0) {
2511 DEBUG(2,("Could not set primary group for user %s to "
2513 pdb_get_username(sampass
), grp
->gr_name
));
2521 /*******************************************************************
2523 ********************************************************************/
2525 static BOOL
set_user_info_20(SAM_USER_INFO_20
*id20
, SAM_ACCOUNT
*pwd
)
2528 DEBUG(5, ("set_user_info_20: NULL id20\n"));
2532 copy_id20_to_sam_passwd(pwd
, id20
);
2534 /* write the change out */
2535 if(!pdb_update_sam_account(pwd
)) {
2544 /*******************************************************************
2546 ********************************************************************/
2548 static BOOL
set_user_info_21(SAM_USER_INFO_21
*id21
, SAM_ACCOUNT
*pwd
)
2552 DEBUG(5, ("set_user_info_21: NULL id21\n"));
2556 copy_id21_to_sam_passwd(pwd
, id21
);
2559 * The funny part about the previous two calls is
2560 * that pwd still has the password hashes from the
2561 * passdb entry. These have not been updated from
2562 * id21. I don't know if they need to be set. --jerry
2565 if (IS_SAM_CHANGED(pwd
, PDB_GROUPSID
))
2566 set_unix_primary_group(pwd
);
2568 /* write the change out */
2569 if(!pdb_update_sam_account(pwd
)) {
2579 /*******************************************************************
2581 ********************************************************************/
2583 static BOOL
set_user_info_23(SAM_USER_INFO_23
*id23
, SAM_ACCOUNT
*pwd
)
2585 pstring plaintext_buf
;
2590 DEBUG(5, ("set_user_info_23: NULL id23\n"));
2594 DEBUG(5, ("Attempting administrator password change (level 23) for user %s\n",
2595 pdb_get_username(pwd
)));
2597 acct_ctrl
= pdb_get_acct_ctrl(pwd
);
2599 if (!decode_pw_buffer(id23
->pass
, plaintext_buf
, 256, &len
, STR_UNICODE
)) {
2604 if (!pdb_set_plaintext_passwd (pwd
, plaintext_buf
)) {
2609 copy_id23_to_sam_passwd(pwd
, id23
);
2611 /* if it's a trust account, don't update /etc/passwd */
2612 if ( ( (acct_ctrl
& ACB_DOMTRUST
) == ACB_DOMTRUST
) ||
2613 ( (acct_ctrl
& ACB_WSTRUST
) == ACB_WSTRUST
) ||
2614 ( (acct_ctrl
& ACB_SVRTRUST
) == ACB_SVRTRUST
) ) {
2615 DEBUG(5, ("Changing trust account or non-unix-user password, not updating /etc/passwd\n"));
2617 /* update the UNIX password */
2618 if (lp_unix_password_sync() ) {
2619 struct passwd
*passwd
= Get_Pwnam(pdb_get_username(pwd
));
2621 DEBUG(1, ("chgpasswd: Username does not exist in system !?!\n"));
2624 if(!chgpasswd(pdb_get_username(pwd
), passwd
, "", plaintext_buf
, True
)) {
2631 ZERO_STRUCT(plaintext_buf
);
2633 if (IS_SAM_CHANGED(pwd
, PDB_GROUPSID
))
2634 set_unix_primary_group(pwd
);
2636 if(!pdb_update_sam_account(pwd
)) {
2646 /*******************************************************************
2648 ********************************************************************/
2650 static BOOL
set_user_info_pw(uint8
*pass
, SAM_ACCOUNT
*pwd
)
2653 pstring plaintext_buf
;
2656 DEBUG(5, ("Attempting administrator password change for user %s\n",
2657 pdb_get_username(pwd
)));
2659 acct_ctrl
= pdb_get_acct_ctrl(pwd
);
2661 ZERO_STRUCT(plaintext_buf
);
2663 if (!decode_pw_buffer(pass
, plaintext_buf
, 256, &len
, STR_UNICODE
)) {
2668 if (!pdb_set_plaintext_passwd (pwd
, plaintext_buf
)) {
2673 /* if it's a trust account, don't update /etc/passwd */
2674 if ( ( (acct_ctrl
& ACB_DOMTRUST
) == ACB_DOMTRUST
) ||
2675 ( (acct_ctrl
& ACB_WSTRUST
) == ACB_WSTRUST
) ||
2676 ( (acct_ctrl
& ACB_SVRTRUST
) == ACB_SVRTRUST
) ) {
2677 DEBUG(5, ("Changing trust account or non-unix-user password, not updating /etc/passwd\n"));
2679 /* update the UNIX password */
2680 if (lp_unix_password_sync()) {
2681 struct passwd
*passwd
= Get_Pwnam(pdb_get_username(pwd
));
2683 DEBUG(1, ("chgpasswd: Username does not exist in system !?!\n"));
2686 if(!chgpasswd(pdb_get_username(pwd
), passwd
, "", plaintext_buf
, True
)) {
2693 ZERO_STRUCT(plaintext_buf
);
2695 DEBUG(5,("set_user_info_pw: pdb_update_pwd()\n"));
2697 /* update the SAMBA password */
2698 if(!pdb_update_sam_account(pwd
)) {
2708 /*******************************************************************
2709 samr_reply_set_userinfo
2710 ********************************************************************/
2712 NTSTATUS
_samr_set_userinfo(pipes_struct
*p
, SAMR_Q_SET_USERINFO
*q_u
, SAMR_R_SET_USERINFO
*r_u
)
2714 SAM_ACCOUNT
*pwd
= NULL
;
2716 POLICY_HND
*pol
= &q_u
->pol
;
2717 uint16 switch_value
= q_u
->switch_value
;
2718 SAM_USERINFO_CTR
*ctr
= q_u
->ctr
;
2720 uint32 acc_required
;
2722 BOOL has_enough_rights
= False
;
2725 DEBUG(5, ("_samr_set_userinfo: %d\n", __LINE__
));
2727 r_u
->status
= NT_STATUS_OK
;
2729 /* find the policy handle. open a policy on it. */
2730 if (!get_lsa_policy_samr_sid(p
, pol
, &sid
, &acc_granted
))
2731 return NT_STATUS_INVALID_HANDLE
;
2733 /* observed when joining an XP client to a Samba domain */
2735 acc_required
= SA_RIGHT_USER_SET_PASSWORD
| SA_RIGHT_USER_SET_ATTRIBUTES
| SA_RIGHT_USER_ACCT_FLAGS_EXPIRY
;
2737 if (!NT_STATUS_IS_OK(r_u
->status
= access_check_samr_function(acc_granted
, acc_required
, "_samr_set_userinfo"))) {
2741 DEBUG(5, ("_samr_set_userinfo: sid:%s, level:%d\n", sid_string_static(&sid
), switch_value
));
2744 DEBUG(5, ("_samr_set_userinfo: NULL info level\n"));
2745 return NT_STATUS_INVALID_INFO_CLASS
;
2751 ret
= pdb_getsampwsid(pwd
, &sid
);
2756 return NT_STATUS_NO_SUCH_USER
;
2759 /* deal with machine password changes differently from userinfo changes */
2760 /* check to see if we have the sufficient rights */
2762 acb_info
= pdb_get_acct_ctrl(pwd
);
2763 if ( acb_info
& ACB_WSTRUST
)
2764 has_enough_rights
= user_has_privileges( p
->pipe_user
.nt_user_token
, &se_machine_account
);
2765 else if ( acb_info
& ACB_NORMAL
)
2766 has_enough_rights
= user_has_privileges( p
->pipe_user
.nt_user_token
, &se_add_users
);
2767 else if ( acb_info
& (ACB_SVRTRUST
|ACB_DOMTRUST
) ) {
2768 if ( lp_enable_privileges() )
2769 has_enough_rights
= nt_token_check_domain_rid( p
->pipe_user
.nt_user_token
, DOMAIN_GROUP_RID_ADMINS
);
2772 DEBUG(5, ("_samr_set_userinfo: %s does%s possess sufficient rights\n",
2773 p
->pipe_user_name
, has_enough_rights
? "" : " not"));
2775 /* ================ BEGIN SeMachineAccountPrivilege BLOCK ================ */
2777 if ( has_enough_rights
)
2780 /* ok! user info levels (lots: see MSDEV help), off we go... */
2782 switch (switch_value
) {
2784 if (!set_user_info_18(ctr
->info
.id18
, pwd
))
2785 r_u
->status
= NT_STATUS_ACCESS_DENIED
;
2789 if (!p
->session_key
.length
) {
2790 r_u
->status
= NT_STATUS_NO_USER_SESSION_KEY
;
2792 SamOEMhashBlob(ctr
->info
.id24
->pass
, 516, &p
->session_key
);
2794 dump_data(100, (char *)ctr
->info
.id24
->pass
, 516);
2796 if (!set_user_info_pw(ctr
->info
.id24
->pass
, pwd
))
2797 r_u
->status
= NT_STATUS_ACCESS_DENIED
;
2803 * Currently we don't really know how to unmarshall
2804 * the level 25 struct, and the password encryption
2805 * is different. This is a placeholder for when we
2806 * do understand it. In the meantime just return INVALID
2807 * info level and W2K SP2 drops down to level 23... JRA.
2810 if (!p
->session_key
.length
) {
2811 r_u
->status
= NT_STATUS_NO_USER_SESSION_KEY
;
2813 SamOEMhashBlob(ctr
->info
.id25
->pass
, 532, &p
->session_key
);
2815 dump_data(100, (char *)ctr
->info
.id25
->pass
, 532);
2817 if (!set_user_info_pw(ctr
->info
.id25
->pass
, &sid
))
2818 r_u
->status
= NT_STATUS_ACCESS_DENIED
;
2821 r_u
->status
= NT_STATUS_INVALID_INFO_CLASS
;
2825 if (!p
->session_key
.length
) {
2826 r_u
->status
= NT_STATUS_NO_USER_SESSION_KEY
;
2828 SamOEMhashBlob(ctr
->info
.id23
->pass
, 516, &p
->session_key
);
2830 dump_data(100, (char *)ctr
->info
.id23
->pass
, 516);
2832 if (!set_user_info_23(ctr
->info
.id23
, pwd
))
2833 r_u
->status
= NT_STATUS_ACCESS_DENIED
;
2837 r_u
->status
= NT_STATUS_INVALID_INFO_CLASS
;
2841 if ( has_enough_rights
)
2844 /* ================ END SeMachineAccountPrivilege BLOCK ================ */
2849 /*******************************************************************
2850 samr_reply_set_userinfo2
2851 ********************************************************************/
2853 NTSTATUS
_samr_set_userinfo2(pipes_struct
*p
, SAMR_Q_SET_USERINFO2
*q_u
, SAMR_R_SET_USERINFO2
*r_u
)
2855 SAM_ACCOUNT
*pwd
= NULL
;
2857 SAM_USERINFO_CTR
*ctr
= q_u
->ctr
;
2858 POLICY_HND
*pol
= &q_u
->pol
;
2859 uint16 switch_value
= q_u
->switch_value
;
2861 uint32 acc_required
;
2863 BOOL has_enough_rights
= False
;
2866 DEBUG(5, ("samr_reply_set_userinfo2: %d\n", __LINE__
));
2868 r_u
->status
= NT_STATUS_OK
;
2870 /* find the policy handle. open a policy on it. */
2871 if (!get_lsa_policy_samr_sid(p
, pol
, &sid
, &acc_granted
))
2872 return NT_STATUS_INVALID_HANDLE
;
2874 /* observed when joining XP client to Samba domain */
2876 acc_required
= SA_RIGHT_USER_SET_PASSWORD
| SA_RIGHT_USER_SET_ATTRIBUTES
| SA_RIGHT_USER_ACCT_FLAGS_EXPIRY
;
2878 if (!NT_STATUS_IS_OK(r_u
->status
= access_check_samr_function(acc_granted
, acc_required
, "_samr_set_userinfo2"))) {
2882 DEBUG(5, ("samr_reply_set_userinfo2: sid:%s\n", sid_string_static(&sid
)));
2885 DEBUG(5, ("samr_reply_set_userinfo2: NULL info level\n"));
2886 return NT_STATUS_INVALID_INFO_CLASS
;
2889 switch_value
=ctr
->switch_value
;
2894 ret
= pdb_getsampwsid(pwd
, &sid
);
2899 return NT_STATUS_NO_SUCH_USER
;
2902 acb_info
= pdb_get_acct_ctrl(pwd
);
2903 if ( acb_info
& ACB_WSTRUST
)
2904 has_enough_rights
= user_has_privileges( p
->pipe_user
.nt_user_token
, &se_machine_account
);
2905 else if ( acb_info
& ACB_NORMAL
)
2906 has_enough_rights
= user_has_privileges( p
->pipe_user
.nt_user_token
, &se_add_users
);
2907 else if ( acb_info
& (ACB_SVRTRUST
|ACB_DOMTRUST
) ) {
2908 if ( lp_enable_privileges() )
2909 has_enough_rights
= nt_token_check_domain_rid( p
->pipe_user
.nt_user_token
, DOMAIN_GROUP_RID_ADMINS
);
2912 DEBUG(5, ("_samr_set_userinfo: %s does%s possess sufficient rights\n",
2913 p
->pipe_user_name
, has_enough_rights
? "" : " not"));
2915 /* ================ BEGIN SeMachineAccountPrivilege BLOCK ================ */
2917 if ( has_enough_rights
)
2920 /* ok! user info levels (lots: see MSDEV help), off we go... */
2922 switch (switch_value
) {
2924 if (!set_user_info_16(ctr
->info
.id16
, pwd
))
2925 r_u
->status
= NT_STATUS_ACCESS_DENIED
;
2928 /* Used by AS/U JRA. */
2929 if (!set_user_info_18(ctr
->info
.id18
, pwd
))
2930 r_u
->status
= NT_STATUS_ACCESS_DENIED
;
2933 if (!set_user_info_20(ctr
->info
.id20
, pwd
))
2934 r_u
->status
= NT_STATUS_ACCESS_DENIED
;
2937 if (!set_user_info_21(ctr
->info
.id21
, pwd
))
2938 return NT_STATUS_ACCESS_DENIED
;
2941 r_u
->status
= NT_STATUS_INVALID_INFO_CLASS
;
2944 if ( has_enough_rights
)
2947 /* ================ END SeMachineAccountPrivilege BLOCK ================ */
2952 /*********************************************************************
2953 _samr_query_aliasmem
2954 *********************************************************************/
2956 NTSTATUS
_samr_query_useraliases(pipes_struct
*p
, SAMR_Q_QUERY_USERALIASES
*q_u
, SAMR_R_QUERY_USERALIASES
*r_u
)
2960 struct samr_info
*info
= NULL
;
2969 r_u
->status
= NT_STATUS_OK
;
2971 DEBUG(5,("_samr_query_useraliases: %d\n", __LINE__
));
2973 /* find the policy handle. open a policy on it. */
2974 if (!find_policy_by_hnd(p
, &q_u
->pol
, (void **)&info
))
2975 return NT_STATUS_INVALID_HANDLE
;
2977 ntstatus1
= access_check_samr_function(info
->acc_granted
, SA_RIGHT_DOMAIN_LOOKUP_ALIAS_BY_MEM
, "_samr_query_useraliases");
2978 ntstatus2
= access_check_samr_function(info
->acc_granted
, SA_RIGHT_DOMAIN_OPEN_ACCOUNT
, "_samr_query_useraliases");
2980 if (!NT_STATUS_IS_OK(ntstatus1
) || !NT_STATUS_IS_OK(ntstatus2
)) {
2981 if (!(NT_STATUS_EQUAL(ntstatus1
,NT_STATUS_ACCESS_DENIED
) && NT_STATUS_IS_OK(ntstatus2
)) &&
2982 !(NT_STATUS_EQUAL(ntstatus1
,NT_STATUS_ACCESS_DENIED
) && NT_STATUS_IS_OK(ntstatus1
))) {
2983 return (NT_STATUS_IS_OK(ntstatus1
)) ? ntstatus2
: ntstatus1
;
2987 if (!sid_check_is_domain(&info
->sid
) &&
2988 !sid_check_is_builtin(&info
->sid
))
2989 return NT_STATUS_OBJECT_TYPE_MISMATCH
;
2991 members
= TALLOC_ARRAY(p
->mem_ctx
, DOM_SID
, q_u
->num_sids1
);
2993 if (members
== NULL
)
2994 return NT_STATUS_NO_MEMORY
;
2996 for (i
=0; i
<q_u
->num_sids1
; i
++)
2997 sid_copy(&members
[i
], &q_u
->sid
[i
].sid
);
3003 res
= pdb_enum_alias_memberships(p
->mem_ctx
, &info
->sid
, members
,
3005 &alias_rids
, &num_alias_rids
);
3009 return NT_STATUS_UNSUCCESSFUL
;
3011 init_samr_r_query_useraliases(r_u
, num_alias_rids
, alias_rids
,
3013 return NT_STATUS_OK
;
3016 /*********************************************************************
3017 _samr_query_aliasmem
3018 *********************************************************************/
3020 NTSTATUS
_samr_query_aliasmem(pipes_struct
*p
, SAMR_Q_QUERY_ALIASMEM
*q_u
, SAMR_R_QUERY_ALIASMEM
*r_u
)
3032 /* find the policy handle. open a policy on it. */
3033 if (!get_lsa_policy_samr_sid(p
, &q_u
->alias_pol
, &alias_sid
, &acc_granted
))
3034 return NT_STATUS_INVALID_HANDLE
;
3036 if (!NT_STATUS_IS_OK(r_u
->status
=
3037 access_check_samr_function(acc_granted
, SA_RIGHT_ALIAS_GET_MEMBERS
, "_samr_query_aliasmem"))) {
3041 DEBUG(10, ("sid is %s\n", sid_string_static(&alias_sid
)));
3043 if (!pdb_enum_aliasmem(&alias_sid
, &sids
, &num_sids
))
3044 return NT_STATUS_NO_SUCH_ALIAS
;
3046 sid
= TALLOC_ZERO_ARRAY(p
->mem_ctx
, DOM_SID2
, num_sids
);
3047 if (num_sids
!=0 && sid
== NULL
) {
3049 return NT_STATUS_NO_MEMORY
;
3052 for (i
= 0; i
< num_sids
; i
++) {
3053 init_dom_sid2(&sid
[i
], &sids
[i
]);
3056 init_samr_r_query_aliasmem(r_u
, num_sids
, sid
, NT_STATUS_OK
);
3060 return NT_STATUS_OK
;
3063 static void add_uid_to_array_unique(uid_t uid
, uid_t
**uids
, int *num
)
3067 for (i
=0; i
<*num
; i
++) {
3068 if ((*uids
)[i
] == uid
)
3072 *uids
= SMB_REALLOC_ARRAY(*uids
, uid_t
, *num
+1);
3077 (*uids
)[*num
] = uid
;
3082 static BOOL
get_memberuids(gid_t gid
, uid_t
**uids
, int *num
)
3086 struct sys_pwent
*userlist
, *user
;
3091 /* We only look at our own sam, so don't care about imported stuff */
3095 if ((grp
= getgrgid(gid
)) == NULL
) {
3100 /* Primary group members */
3102 userlist
= getpwent_list();
3104 for (user
= userlist
; user
!= NULL
; user
= user
->next
) {
3105 if (user
->pw_gid
!= gid
)
3107 add_uid_to_array_unique(user
->pw_uid
, uids
, num
);
3110 pwent_free(userlist
);
3112 /* Secondary group members */
3114 for (gr
= grp
->gr_mem
; (*gr
!= NULL
) && ((*gr
)[0] != '\0'); gr
+= 1) {
3115 struct passwd
*pw
= getpwnam(*gr
);
3119 add_uid_to_array_unique(pw
->pw_uid
, uids
, num
);
3127 /*********************************************************************
3128 _samr_query_groupmem
3129 *********************************************************************/
3131 NTSTATUS
_samr_query_groupmem(pipes_struct
*p
, SAMR_Q_QUERY_GROUPMEM
*q_u
, SAMR_R_QUERY_GROUPMEM
*r_u
)
3134 fstring group_sid_str
;
3144 /* find the policy handle. open a policy on it. */
3145 if (!get_lsa_policy_samr_sid(p
, &q_u
->group_pol
, &group_sid
, &acc_granted
))
3146 return NT_STATUS_INVALID_HANDLE
;
3148 if (!NT_STATUS_IS_OK(r_u
->status
= access_check_samr_function(acc_granted
, SA_RIGHT_GROUP_GET_MEMBERS
, "_samr_query_groupmem"))) {
3152 sid_to_string(group_sid_str
, &group_sid
);
3153 DEBUG(10, ("sid is %s\n", group_sid_str
));
3155 if (!sid_check_is_in_our_domain(&group_sid
)) {
3156 DEBUG(3, ("sid %s is not in our domain\n", group_sid_str
));
3157 return NT_STATUS_NO_SUCH_GROUP
;
3160 DEBUG(10, ("lookup on Domain SID\n"));
3163 result
= pdb_enum_group_members(p
->mem_ctx
, &group_sid
,
3164 &rid
, &num_members
);
3167 if (!NT_STATUS_IS_OK(result
))
3170 attr
=TALLOC_ZERO_ARRAY(p
->mem_ctx
, uint32
, num_members
);
3172 if ((num_members
!=0) && (rid
==NULL
))
3173 return NT_STATUS_NO_MEMORY
;
3175 for (i
=0; i
<num_members
; i
++)
3176 attr
[i
] = SID_NAME_USER
;
3178 init_samr_r_query_groupmem(r_u
, num_members
, rid
, attr
, NT_STATUS_OK
);
3180 return NT_STATUS_OK
;
3183 /*********************************************************************
3185 *********************************************************************/
3187 NTSTATUS
_samr_add_aliasmem(pipes_struct
*p
, SAMR_Q_ADD_ALIASMEM
*q_u
, SAMR_R_ADD_ALIASMEM
*r_u
)
3192 BOOL can_add_accounts
;
3196 /* Find the policy handle. Open a policy on it. */
3197 if (!get_lsa_policy_samr_sid(p
, &q_u
->alias_pol
, &alias_sid
, &acc_granted
))
3198 return NT_STATUS_INVALID_HANDLE
;
3200 if (!NT_STATUS_IS_OK(r_u
->status
= access_check_samr_function(acc_granted
, SA_RIGHT_ALIAS_ADD_MEMBER
, "_samr_add_aliasmem"))) {
3204 DEBUG(10, ("sid is %s\n", sid_string_static(&alias_sid
)));
3206 se_priv_copy( &se_rights
, &se_add_users
);
3207 can_add_accounts
= user_has_privileges( p
->pipe_user
.nt_user_token
, &se_rights
);
3209 /******** BEGIN SeAddUsers BLOCK *********/
3211 if ( can_add_accounts
)
3214 ret
= pdb_add_aliasmem(&alias_sid
, &q_u
->sid
.sid
);
3216 if ( can_add_accounts
)
3219 /******** END SeAddUsers BLOCK *********/
3221 return ret
? NT_STATUS_OK
: NT_STATUS_ACCESS_DENIED
;
3224 /*********************************************************************
3226 *********************************************************************/
3228 NTSTATUS
_samr_del_aliasmem(pipes_struct
*p
, SAMR_Q_DEL_ALIASMEM
*q_u
, SAMR_R_DEL_ALIASMEM
*r_u
)
3233 BOOL can_add_accounts
;
3236 /* Find the policy handle. Open a policy on it. */
3237 if (!get_lsa_policy_samr_sid(p
, &q_u
->alias_pol
, &alias_sid
, &acc_granted
))
3238 return NT_STATUS_INVALID_HANDLE
;
3240 if (!NT_STATUS_IS_OK(r_u
->status
= access_check_samr_function(acc_granted
, SA_RIGHT_ALIAS_REMOVE_MEMBER
, "_samr_del_aliasmem"))) {
3244 DEBUG(10, ("_samr_del_aliasmem:sid is %s\n",
3245 sid_string_static(&alias_sid
)));
3247 se_priv_copy( &se_rights
, &se_add_users
);
3248 can_add_accounts
= user_has_privileges( p
->pipe_user
.nt_user_token
, &se_rights
);
3250 /******** BEGIN SeAddUsers BLOCK *********/
3252 if ( can_add_accounts
)
3255 ret
= pdb_del_aliasmem(&alias_sid
, &q_u
->sid
.sid
);
3257 if ( can_add_accounts
)
3260 /******** END SeAddUsers BLOCK *********/
3262 return ret
? NT_STATUS_OK
: NT_STATUS_ACCESS_DENIED
;
3265 /*********************************************************************
3267 *********************************************************************/
3269 NTSTATUS
_samr_add_groupmem(pipes_struct
*p
, SAMR_Q_ADD_GROUPMEM
*q_u
, SAMR_R_ADD_GROUPMEM
*r_u
)
3273 fstring group_sid_str
;
3280 SAM_ACCOUNT
*sam_user
=NULL
;
3284 BOOL can_add_accounts
;
3286 /* Find the policy handle. Open a policy on it. */
3287 if (!get_lsa_policy_samr_sid(p
, &q_u
->pol
, &group_sid
, &acc_granted
))
3288 return NT_STATUS_INVALID_HANDLE
;
3290 if (!NT_STATUS_IS_OK(r_u
->status
= access_check_samr_function(acc_granted
, SA_RIGHT_GROUP_ADD_MEMBER
, "_samr_add_groupmem"))) {
3294 sid_to_string(group_sid_str
, &group_sid
);
3295 DEBUG(10, ("sid is %s\n", group_sid_str
));
3297 if (sid_compare(&group_sid
, get_global_sam_sid())<=0)
3298 return NT_STATUS_NO_SUCH_GROUP
;
3300 DEBUG(10, ("lookup on Domain SID\n"));
3302 if(!get_domain_group_from_sid(group_sid
, &map
))
3303 return NT_STATUS_NO_SUCH_GROUP
;
3305 sid_copy(&user_sid
, get_global_sam_sid());
3306 sid_append_rid(&user_sid
, q_u
->rid
);
3308 ret
= pdb_init_sam(&sam_user
);
3309 if (!NT_STATUS_IS_OK(ret
))
3312 check
= pdb_getsampwsid(sam_user
, &user_sid
);
3314 if (check
!= True
) {
3315 pdb_free_sam(&sam_user
);
3316 return NT_STATUS_NO_SUCH_USER
;
3319 /* check a real user exist before we run the script to add a user to a group */
3320 if (!NT_STATUS_IS_OK(sid_to_uid(pdb_get_user_sid(sam_user
), &uid
))) {
3321 pdb_free_sam(&sam_user
);
3322 return NT_STATUS_NO_SUCH_USER
;
3325 pdb_free_sam(&sam_user
);
3327 if ((pwd
=getpwuid_alloc(uid
)) == NULL
) {
3328 return NT_STATUS_NO_SUCH_USER
;
3331 if ((grp
=getgrgid(map
.gid
)) == NULL
) {
3333 return NT_STATUS_NO_SUCH_GROUP
;
3336 /* we need to copy the name otherwise it's overloaded in user_in_unix_group_list */
3337 fstrcpy(grp_name
, grp
->gr_name
);
3339 /* if the user is already in the group */
3340 if(user_in_unix_group_list(pwd
->pw_name
, grp_name
)) {
3342 return NT_STATUS_MEMBER_IN_GROUP
;
3345 se_priv_copy( &se_rights
, &se_add_users
);
3346 can_add_accounts
= user_has_privileges( p
->pipe_user
.nt_user_token
, &se_rights
);
3348 /******** BEGIN SeAddUsers BLOCK *********/
3350 if ( can_add_accounts
)
3354 * ok, the group exist, the user exist, the user is not in the group,
3356 * we can (finally) add it to the group !
3359 smb_add_user_group(grp_name
, pwd
->pw_name
);
3361 if ( can_add_accounts
)
3364 /******** END SeAddUsers BLOCK *********/
3366 /* check if the user has been added then ... */
3367 if(!user_in_unix_group_list(pwd
->pw_name
, grp_name
)) {
3369 return NT_STATUS_MEMBER_NOT_IN_GROUP
; /* don't know what to reply else */
3373 return NT_STATUS_OK
;
3376 /*********************************************************************
3378 *********************************************************************/
3380 NTSTATUS
_samr_del_groupmem(pipes_struct
*p
, SAMR_Q_DEL_GROUPMEM
*q_u
, SAMR_R_DEL_GROUPMEM
*r_u
)
3384 SAM_ACCOUNT
*sam_pass
=NULL
;
3390 BOOL can_add_accounts
;
3393 * delete the group member named q_u->rid
3394 * who is a member of the sid associated with the handle
3395 * the rid is a user's rid as the group is a domain group.
3398 /* Find the policy handle. Open a policy on it. */
3399 if (!get_lsa_policy_samr_sid(p
, &q_u
->pol
, &group_sid
, &acc_granted
))
3400 return NT_STATUS_INVALID_HANDLE
;
3402 if (!NT_STATUS_IS_OK(r_u
->status
= access_check_samr_function(acc_granted
, SA_RIGHT_GROUP_REMOVE_MEMBER
, "_samr_del_groupmem"))) {
3406 if (!sid_check_is_in_our_domain(&group_sid
))
3407 return NT_STATUS_NO_SUCH_GROUP
;
3409 sid_copy(&user_sid
, get_global_sam_sid());
3410 sid_append_rid(&user_sid
, q_u
->rid
);
3412 if (!get_domain_group_from_sid(group_sid
, &map
))
3413 return NT_STATUS_NO_SUCH_GROUP
;
3415 if ((grp
=getgrgid(map
.gid
)) == NULL
)
3416 return NT_STATUS_NO_SUCH_GROUP
;
3418 /* we need to copy the name otherwise it's overloaded in user_in_group_list */
3419 fstrcpy(grp_name
, grp
->gr_name
);
3421 /* check if the user exists before trying to remove it from the group */
3422 pdb_init_sam(&sam_pass
);
3423 if (!pdb_getsampwsid(sam_pass
, &user_sid
)) {
3424 DEBUG(5,("User %s doesn't exist.\n", pdb_get_username(sam_pass
)));
3425 pdb_free_sam(&sam_pass
);
3426 return NT_STATUS_NO_SUCH_USER
;
3429 /* if the user is not in the group */
3430 if (!user_in_unix_group_list(pdb_get_username(sam_pass
), grp_name
)) {
3431 pdb_free_sam(&sam_pass
);
3432 return NT_STATUS_MEMBER_NOT_IN_GROUP
;
3436 se_priv_copy( &se_rights
, &se_add_users
);
3437 can_add_accounts
= user_has_privileges( p
->pipe_user
.nt_user_token
, &se_rights
);
3439 /******** BEGIN SeAddUsers BLOCK *********/
3441 if ( can_add_accounts
)
3444 smb_delete_user_group(grp_name
, pdb_get_username(sam_pass
));
3446 if ( can_add_accounts
)
3449 /******** END SeAddUsers BLOCK *********/
3451 /* check if the user has been removed then ... */
3452 if (user_in_unix_group_list(pdb_get_username(sam_pass
), grp_name
)) {
3453 pdb_free_sam(&sam_pass
);
3454 return NT_STATUS_ACCESS_DENIED
; /* don't know what to reply else */
3457 pdb_free_sam(&sam_pass
);
3458 return NT_STATUS_OK
;
3462 /****************************************************************************
3463 Delete a UNIX user on demand.
3464 ****************************************************************************/
3466 static int smb_delete_user(const char *unix_user
)
3471 pstrcpy(del_script
, lp_deluser_script());
3474 all_string_sub(del_script
, "%u", unix_user
, sizeof(del_script
));
3475 ret
= smbrun(del_script
,NULL
);
3476 flush_pwnam_cache();
3477 DEBUG(ret
? 0 : 3,("smb_delete_user: Running the command `%s' gave %d\n",del_script
,ret
));
3482 /*********************************************************************
3483 _samr_delete_dom_user
3484 *********************************************************************/
3486 NTSTATUS
_samr_delete_dom_user(pipes_struct
*p
, SAMR_Q_DELETE_DOM_USER
*q_u
, SAMR_R_DELETE_DOM_USER
*r_u
)
3489 SAM_ACCOUNT
*sam_pass
=NULL
;
3491 BOOL can_add_accounts
;
3494 DEBUG(5, ("_samr_delete_dom_user: %d\n", __LINE__
));
3496 /* Find the policy handle. Open a policy on it. */
3497 if (!get_lsa_policy_samr_sid(p
, &q_u
->user_pol
, &user_sid
, &acc_granted
))
3498 return NT_STATUS_INVALID_HANDLE
;
3500 if (!NT_STATUS_IS_OK(r_u
->status
= access_check_samr_function(acc_granted
, STD_RIGHT_DELETE_ACCESS
, "_samr_delete_dom_user"))) {
3504 if (!sid_check_is_in_our_domain(&user_sid
))
3505 return NT_STATUS_CANNOT_DELETE
;
3507 /* check if the user exists before trying to delete */
3508 pdb_init_sam(&sam_pass
);
3509 if(!pdb_getsampwsid(sam_pass
, &user_sid
)) {
3510 DEBUG(5,("_samr_delete_dom_user:User %s doesn't exist.\n",
3511 sid_string_static(&user_sid
)));
3512 pdb_free_sam(&sam_pass
);
3513 return NT_STATUS_NO_SUCH_USER
;
3516 can_add_accounts
= user_has_privileges( p
->pipe_user
.nt_user_token
, &se_add_users
);
3518 /******** BEGIN SeAddUsers BLOCK *********/
3520 if ( can_add_accounts
)
3523 /* First delete the samba side....
3524 code is order to prevent unnecessary returns out of the admin
3527 if ( (ret
= pdb_delete_sam_account(sam_pass
)) == True
) {
3529 * Now delete the unix side ....
3530 * note: we don't check if the delete really happened
3531 * as the script is not necessary present
3532 * and maybe the sysadmin doesn't want to delete the unix side
3534 smb_delete_user( pdb_get_username(sam_pass
) );
3537 if ( can_add_accounts
)
3540 /******** END SeAddUsers BLOCK *********/
3543 DEBUG(5,("_samr_delete_dom_user:Failed to delete entry for user %s.\n", pdb_get_username(sam_pass
)));
3544 pdb_free_sam(&sam_pass
);
3545 return NT_STATUS_CANNOT_DELETE
;
3549 pdb_free_sam(&sam_pass
);
3551 if (!close_policy_hnd(p
, &q_u
->user_pol
))
3552 return NT_STATUS_OBJECT_NAME_INVALID
;
3554 return NT_STATUS_OK
;
3557 /*********************************************************************
3558 _samr_delete_dom_group
3559 *********************************************************************/
3561 NTSTATUS
_samr_delete_dom_group(pipes_struct
*p
, SAMR_Q_DELETE_DOM_GROUP
*q_u
, SAMR_R_DELETE_DOM_GROUP
*r_u
)
3566 fstring group_sid_str
;
3572 BOOL can_add_accounts
;
3575 DEBUG(5, ("samr_delete_dom_group: %d\n", __LINE__
));
3577 /* Find the policy handle. Open a policy on it. */
3578 if (!get_lsa_policy_samr_sid(p
, &q_u
->group_pol
, &group_sid
, &acc_granted
))
3579 return NT_STATUS_INVALID_HANDLE
;
3581 if (!NT_STATUS_IS_OK(r_u
->status
= access_check_samr_function(acc_granted
, STD_RIGHT_DELETE_ACCESS
, "_samr_delete_dom_group"))) {
3585 sid_copy(&dom_sid
, &group_sid
);
3586 sid_to_string(group_sid_str
, &dom_sid
);
3587 sid_split_rid(&dom_sid
, &group_rid
);
3589 DEBUG(10, ("sid is %s\n", group_sid_str
));
3591 /* we check if it's our SID before deleting */
3592 if (!sid_equal(&dom_sid
, get_global_sam_sid()))
3593 return NT_STATUS_NO_SUCH_GROUP
;
3595 DEBUG(10, ("lookup on Domain SID\n"));
3597 if(!get_domain_group_from_sid(group_sid
, &map
))
3598 return NT_STATUS_NO_SUCH_GROUP
;
3602 /* check if group really exists */
3603 if ( (grp
=getgrgid(gid
)) == NULL
)
3604 return NT_STATUS_NO_SUCH_GROUP
;
3606 se_priv_copy( &se_rights
, &se_add_users
);
3607 can_add_accounts
= user_has_privileges( p
->pipe_user
.nt_user_token
, &se_rights
);
3609 /******** BEGIN SeAddUsers BLOCK *********/
3611 if ( can_add_accounts
)
3614 /* delete mapping first */
3616 if ( (ret
= pdb_delete_group_mapping_entry(group_sid
)) == True
) {
3617 smb_delete_group( grp
->gr_name
);
3620 if ( can_add_accounts
)
3623 /******** END SeAddUsers BLOCK *********/
3626 DEBUG(5,("_samr_delete_dom_group: Failed to delete mapping entry for group %s.\n",
3628 return NT_STATUS_ACCESS_DENIED
;
3631 /* don't check that the unix group has been deleted. Work like
3632 _samr_delet_dom_user() */
3634 if (!close_policy_hnd(p
, &q_u
->group_pol
))
3635 return NT_STATUS_OBJECT_NAME_INVALID
;
3637 return NT_STATUS_OK
;
3640 /*********************************************************************
3641 _samr_delete_dom_alias
3642 *********************************************************************/
3644 NTSTATUS
_samr_delete_dom_alias(pipes_struct
*p
, SAMR_Q_DELETE_DOM_ALIAS
*q_u
, SAMR_R_DELETE_DOM_ALIAS
*r_u
)
3649 BOOL can_add_accounts
;
3652 DEBUG(5, ("_samr_delete_dom_alias: %d\n", __LINE__
));
3654 /* Find the policy handle. Open a policy on it. */
3655 if (!get_lsa_policy_samr_sid(p
, &q_u
->alias_pol
, &alias_sid
, &acc_granted
))
3656 return NT_STATUS_INVALID_HANDLE
;
3658 if (!NT_STATUS_IS_OK(r_u
->status
= access_check_samr_function(acc_granted
, STD_RIGHT_DELETE_ACCESS
, "_samr_delete_dom_alias"))) {
3662 DEBUG(10, ("sid is %s\n", sid_string_static(&alias_sid
)));
3664 if (!sid_check_is_in_our_domain(&alias_sid
))
3665 return NT_STATUS_NO_SUCH_ALIAS
;
3667 DEBUG(10, ("lookup on Local SID\n"));
3669 se_priv_copy( &se_rights
, &se_add_users
);
3670 can_add_accounts
= user_has_privileges( p
->pipe_user
.nt_user_token
, &se_rights
);
3672 /******** BEGIN SeAddUsers BLOCK *********/
3674 if ( can_add_accounts
)
3677 /* Have passdb delete the alias */
3678 ret
= pdb_delete_alias(&alias_sid
);
3680 if ( can_add_accounts
)
3683 /******** END SeAddUsers BLOCK *********/
3686 return NT_STATUS_ACCESS_DENIED
;
3688 if (!close_policy_hnd(p
, &q_u
->alias_pol
))
3689 return NT_STATUS_OBJECT_NAME_INVALID
;
3691 return NT_STATUS_OK
;
3694 /*********************************************************************
3695 _samr_create_dom_group
3696 *********************************************************************/
3698 NTSTATUS
_samr_create_dom_group(pipes_struct
*p
, SAMR_Q_CREATE_DOM_GROUP
*q_u
, SAMR_R_CREATE_DOM_GROUP
*r_u
)
3705 struct samr_info
*info
;
3709 BOOL can_add_accounts
;
3712 /* Find the policy handle. Open a policy on it. */
3713 if (!get_lsa_policy_samr_sid(p
, &q_u
->pol
, &dom_sid
, &acc_granted
))
3714 return NT_STATUS_INVALID_HANDLE
;
3716 if (!NT_STATUS_IS_OK(r_u
->status
= access_check_samr_function(acc_granted
, SA_RIGHT_DOMAIN_CREATE_GROUP
, "_samr_create_dom_group"))) {
3720 if (!sid_equal(&dom_sid
, get_global_sam_sid()))
3721 return NT_STATUS_ACCESS_DENIED
;
3723 unistr2_to_ascii(name
, &q_u
->uni_acct_desc
, sizeof(name
)-1);
3725 /* check if group already exist */
3726 if ((grp
=getgrnam(name
)) != NULL
)
3727 return NT_STATUS_GROUP_EXISTS
;
3729 se_priv_copy( &se_rights
, &se_add_users
);
3730 can_add_accounts
= user_has_privileges( p
->pipe_user
.nt_user_token
, &se_rights
);
3732 /******** BEGIN SeAddUsers BLOCK *********/
3734 if ( can_add_accounts
)
3737 /* check that we successfully create the UNIX group */
3739 result
= NT_STATUS_ACCESS_DENIED
;
3740 if ( (smb_create_group(name
, &gid
) == 0) && ((grp
=getgrgid(gid
)) != NULL
) ) {
3742 /* so far, so good */
3744 result
= NT_STATUS_OK
;
3746 r_u
->rid
= pdb_gid_to_group_rid( grp
->gr_gid
);
3748 /* add the group to the mapping table */
3750 sid_copy( &info_sid
, get_global_sam_sid() );
3751 sid_append_rid( &info_sid
, r_u
->rid
);
3752 sid_to_string( sid_string
, &info_sid
);
3754 /* reset the error code if we fail to add the mapping entry */
3756 if ( !add_initial_entry(grp
->gr_gid
, sid_string
, SID_NAME_DOM_GRP
, name
, NULL
) )
3757 result
= NT_STATUS_ACCESS_DENIED
;
3760 if ( can_add_accounts
)
3763 /******** END SeAddUsers BLOCK *********/
3765 /* check if we should bail out here */
3767 if ( !NT_STATUS_IS_OK(result
) )
3770 if ((info
= get_samr_info_by_sid(&info_sid
)) == NULL
)
3771 return NT_STATUS_NO_MEMORY
;
3774 /* they created it; let the user do what he wants with it */
3776 info
->acc_granted
= GENERIC_RIGHTS_GROUP_ALL_ACCESS
;
3778 /* get a (unique) handle. open a policy on it. */
3779 if (!create_policy_hnd(p
, &r_u
->pol
, free_samr_info
, (void *)info
))
3780 return NT_STATUS_OBJECT_NAME_NOT_FOUND
;
3782 return NT_STATUS_OK
;
3785 /*********************************************************************
3786 _samr_create_dom_alias
3787 *********************************************************************/
3789 NTSTATUS
_samr_create_dom_alias(pipes_struct
*p
, SAMR_Q_CREATE_DOM_ALIAS
*q_u
, SAMR_R_CREATE_DOM_ALIAS
*r_u
)
3794 struct samr_info
*info
;
3799 BOOL can_add_accounts
;
3801 /* Find the policy handle. Open a policy on it. */
3802 if (!get_lsa_policy_samr_sid(p
, &q_u
->dom_pol
, &dom_sid
, &acc_granted
))
3803 return NT_STATUS_INVALID_HANDLE
;
3805 if (!NT_STATUS_IS_OK(r_u
->status
= access_check_samr_function(acc_granted
, SA_RIGHT_DOMAIN_CREATE_ALIAS
, "_samr_create_alias"))) {
3809 if (!sid_equal(&dom_sid
, get_global_sam_sid()))
3810 return NT_STATUS_ACCESS_DENIED
;
3812 unistr2_to_ascii(name
, &q_u
->uni_acct_desc
, sizeof(name
)-1);
3814 se_priv_copy( &se_rights
, &se_add_users
);
3815 can_add_accounts
= user_has_privileges( p
->pipe_user
.nt_user_token
, &se_rights
);
3817 /******** BEGIN SeAddUsers BLOCK *********/
3819 if ( can_add_accounts
)
3822 /* Have passdb create the alias */
3823 result
= pdb_create_alias(name
, &r_u
->rid
);
3825 if ( can_add_accounts
)
3828 /******** END SeAddUsers BLOCK *********/
3830 if (!NT_STATUS_IS_OK(result
))
3833 sid_copy(&info_sid
, get_global_sam_sid());
3834 sid_append_rid(&info_sid
, r_u
->rid
);
3836 if (!NT_STATUS_IS_OK(sid_to_gid(&info_sid
, &gid
)))
3837 return NT_STATUS_ACCESS_DENIED
;
3839 /* check if the group has been successfully created */
3840 if ( getgrgid(gid
) == NULL
)
3841 return NT_STATUS_ACCESS_DENIED
;
3843 if ((info
= get_samr_info_by_sid(&info_sid
)) == NULL
)
3844 return NT_STATUS_NO_MEMORY
;
3846 /* they created it; let the user do what he wants with it */
3848 info
->acc_granted
= GENERIC_RIGHTS_ALIAS_ALL_ACCESS
;
3850 /* get a (unique) handle. open a policy on it. */
3851 if (!create_policy_hnd(p
, &r_u
->alias_pol
, free_samr_info
, (void *)info
))
3852 return NT_STATUS_OBJECT_NAME_NOT_FOUND
;
3854 return NT_STATUS_OK
;
3857 /*********************************************************************
3858 _samr_query_groupinfo
3860 sends the name/comment pair of a domain group
3861 level 1 send also the number of users of that group
3862 *********************************************************************/
3864 NTSTATUS
_samr_query_groupinfo(pipes_struct
*p
, SAMR_Q_QUERY_GROUPINFO
*q_u
, SAMR_R_QUERY_GROUPINFO
*r_u
)
3871 GROUP_INFO_CTR
*ctr
;
3875 if (!get_lsa_policy_samr_sid(p
, &q_u
->pol
, &group_sid
, &acc_granted
))
3876 return NT_STATUS_INVALID_HANDLE
;
3878 if (!NT_STATUS_IS_OK(r_u
->status
= access_check_samr_function(acc_granted
, SA_RIGHT_GROUP_LOOKUP_INFO
, "_samr_query_groupinfo"))) {
3883 ret
= get_domain_group_from_sid(group_sid
, &map
);
3886 return NT_STATUS_INVALID_HANDLE
;
3888 ctr
=TALLOC_ZERO_P(p
->mem_ctx
, GROUP_INFO_CTR
);
3890 return NT_STATUS_NO_MEMORY
;
3892 switch (q_u
->switch_level
) {
3894 ctr
->switch_value1
= 1;
3895 if(!get_memberuids(map
.gid
, &uids
, &num
))
3896 return NT_STATUS_NO_SUCH_GROUP
;
3898 init_samr_group_info1(&ctr
->group
.info1
, map
.nt_name
, map
.comment
, num
);
3902 ctr
->switch_value1
= 3;
3903 init_samr_group_info3(&ctr
->group
.info3
);
3906 ctr
->switch_value1
= 4;
3907 init_samr_group_info4(&ctr
->group
.info4
, map
.comment
);
3910 return NT_STATUS_INVALID_INFO_CLASS
;
3913 init_samr_r_query_groupinfo(r_u
, ctr
, NT_STATUS_OK
);
3915 return NT_STATUS_OK
;
3918 /*********************************************************************
3921 update a domain group's comment.
3922 *********************************************************************/
3924 NTSTATUS
_samr_set_groupinfo(pipes_struct
*p
, SAMR_Q_SET_GROUPINFO
*q_u
, SAMR_R_SET_GROUPINFO
*r_u
)
3928 GROUP_INFO_CTR
*ctr
;
3931 BOOL can_mod_accounts
;
3933 if (!get_lsa_policy_samr_sid(p
, &q_u
->pol
, &group_sid
, &acc_granted
))
3934 return NT_STATUS_INVALID_HANDLE
;
3936 if (!NT_STATUS_IS_OK(r_u
->status
= access_check_samr_function(acc_granted
, SA_RIGHT_GROUP_SET_INFO
, "_samr_set_groupinfo"))) {
3940 if (!get_domain_group_from_sid(group_sid
, &map
))
3941 return NT_STATUS_NO_SUCH_GROUP
;
3945 switch (ctr
->switch_value1
) {
3947 unistr2_to_ascii(map
.comment
, &(ctr
->group
.info1
.uni_acct_desc
), sizeof(map
.comment
)-1);
3950 unistr2_to_ascii(map
.comment
, &(ctr
->group
.info4
.uni_acct_desc
), sizeof(map
.comment
)-1);
3953 return NT_STATUS_INVALID_INFO_CLASS
;
3956 can_mod_accounts
= user_has_privileges( p
->pipe_user
.nt_user_token
, &se_add_users
);
3958 /******** BEGIN SeAddUsers BLOCK *********/
3960 if ( can_mod_accounts
)
3963 ret
= pdb_update_group_mapping_entry(&map
);
3965 if ( can_mod_accounts
)
3968 /******** End SeAddUsers BLOCK *********/
3970 return ret
? NT_STATUS_OK
: NT_STATUS_ACCESS_DENIED
;
3973 /*********************************************************************
3976 update an alias's comment.
3977 *********************************************************************/
3979 NTSTATUS
_samr_set_aliasinfo(pipes_struct
*p
, SAMR_Q_SET_ALIASINFO
*q_u
, SAMR_R_SET_ALIASINFO
*r_u
)
3982 struct acct_info info
;
3983 ALIAS_INFO_CTR
*ctr
;
3986 BOOL can_mod_accounts
;
3988 if (!get_lsa_policy_samr_sid(p
, &q_u
->alias_pol
, &group_sid
, &acc_granted
))
3989 return NT_STATUS_INVALID_HANDLE
;
3991 if (!NT_STATUS_IS_OK(r_u
->status
= access_check_samr_function(acc_granted
, SA_RIGHT_ALIAS_SET_INFO
, "_samr_set_aliasinfo"))) {
3997 switch (ctr
->level
) {
3999 if ( ctr
->alias
.info3
.description
.string
) {
4000 unistr2_to_ascii( info
.acct_desc
,
4001 ctr
->alias
.info3
.description
.string
,
4002 sizeof(info
.acct_desc
)-1 );
4006 return NT_STATUS_INVALID_INFO_CLASS
;
4009 can_mod_accounts
= user_has_privileges( p
->pipe_user
.nt_user_token
, &se_add_users
);
4011 /******** BEGIN SeAddUsers BLOCK *********/
4013 if ( can_mod_accounts
)
4016 ret
= pdb_set_aliasinfo( &group_sid
, &info
);
4018 if ( can_mod_accounts
)
4021 /******** End SeAddUsers BLOCK *********/
4023 return ret
? NT_STATUS_OK
: NT_STATUS_ACCESS_DENIED
;
4026 /*********************************************************************
4027 _samr_get_dom_pwinfo
4028 *********************************************************************/
4030 NTSTATUS
_samr_get_dom_pwinfo(pipes_struct
*p
, SAMR_Q_GET_DOM_PWINFO
*q_u
, SAMR_R_GET_DOM_PWINFO
*r_u
)
4032 /* Perform access check. Since this rpc does not require a
4033 policy handle it will not be caught by the access checks on
4034 SAMR_CONNECT or SAMR_CONNECT_ANON. */
4036 if (!pipe_access_check(p
)) {
4037 DEBUG(3, ("access denied to samr_get_dom_pwinfo\n"));
4038 r_u
->status
= NT_STATUS_ACCESS_DENIED
;
4042 /* Actually, returning zeros here works quite well :-). */
4044 return NT_STATUS_OK
;
4047 /*********************************************************************
4049 *********************************************************************/
4051 NTSTATUS
_samr_open_group(pipes_struct
*p
, SAMR_Q_OPEN_GROUP
*q_u
, SAMR_R_OPEN_GROUP
*r_u
)
4056 struct samr_info
*info
;
4057 SEC_DESC
*psd
= NULL
;
4059 uint32 des_access
= q_u
->access_mask
;
4066 if (!get_lsa_policy_samr_sid(p
, &q_u
->domain_pol
, &sid
, &acc_granted
))
4067 return NT_STATUS_INVALID_HANDLE
;
4069 status
= access_check_samr_function(acc_granted
,
4070 SA_RIGHT_DOMAIN_OPEN_ACCOUNT
, "_samr_open_group");
4072 if ( !NT_STATUS_IS_OK(status
) )
4075 /*check if access can be granted as requested by client. */
4076 make_samr_object_sd(p
->mem_ctx
, &psd
, &sd_size
, &grp_generic_mapping
, NULL
, 0);
4077 se_map_generic(&des_access
,&grp_generic_mapping
);
4079 se_priv_copy( &se_rights
, &se_add_users
);
4081 status
= access_check_samr_object(psd
, p
->pipe_user
.nt_user_token
,
4082 &se_rights
, GENERIC_RIGHTS_GROUP_WRITE
, des_access
,
4083 &acc_granted
, "_samr_open_group");
4085 if ( !NT_STATUS_IS_OK(status
) )
4088 /* this should not be hard-coded like this */
4090 if (!sid_equal(&sid
, get_global_sam_sid()))
4091 return NT_STATUS_ACCESS_DENIED
;
4093 sid_copy(&info_sid
, get_global_sam_sid());
4094 sid_append_rid(&info_sid
, q_u
->rid_group
);
4095 sid_to_string(sid_string
, &info_sid
);
4097 if ((info
= get_samr_info_by_sid(&info_sid
)) == NULL
)
4098 return NT_STATUS_NO_MEMORY
;
4100 info
->acc_granted
= acc_granted
;
4102 DEBUG(10, ("_samr_open_group:Opening SID: %s\n", sid_string
));
4104 /* check if that group really exists */
4106 ret
= get_domain_group_from_sid(info
->sid
, &map
);
4109 return NT_STATUS_NO_SUCH_GROUP
;
4111 /* get a (unique) handle. open a policy on it. */
4112 if (!create_policy_hnd(p
, &r_u
->pol
, free_samr_info
, (void *)info
))
4113 return NT_STATUS_OBJECT_NAME_NOT_FOUND
;
4115 return NT_STATUS_OK
;
4118 /*********************************************************************
4119 _samr_remove_sid_foreign_domain
4120 *********************************************************************/
4122 NTSTATUS
_samr_remove_sid_foreign_domain(pipes_struct
*p
,
4123 SAMR_Q_REMOVE_SID_FOREIGN_DOMAIN
*q_u
,
4124 SAMR_R_REMOVE_SID_FOREIGN_DOMAIN
*r_u
)
4126 DOM_SID delete_sid
, domain_sid
;
4130 sid_copy( &delete_sid
, &q_u
->sid
.sid
);
4132 DEBUG(5,("_samr_remove_sid_foreign_domain: removing SID [%s]\n",
4133 sid_string_static(&delete_sid
)));
4135 /* Find the policy handle. Open a policy on it. */
4137 if (!get_lsa_policy_samr_sid(p
, &q_u
->dom_pol
, &domain_sid
,
4139 return NT_STATUS_INVALID_HANDLE
;
4141 result
= access_check_samr_function(acc_granted
, STD_RIGHT_DELETE_ACCESS
,
4142 "_samr_remove_sid_foreign_domain");
4144 if (!NT_STATUS_IS_OK(result
))
4147 DEBUG(8, ("_samr_remove_sid_foreign_domain:sid is %s\n",
4148 sid_string_static(&domain_sid
)));
4150 /* we can only delete a user from a group since we don't have
4151 nested groups anyways. So in the latter case, just say OK */
4153 /* TODO: The above comment nowadays is bogus. Since we have nested
4154 * groups now, and aliases members are never reported out of the unix
4155 * group membership, the "just say OK" makes this call a no-op. For
4156 * us. This needs fixing however. */
4158 /* I've only ever seen this in the wild when deleting a user from
4159 * usrmgr.exe. domain_sid is the builtin domain, and the sid to delete
4160 * is the user about to be deleted. I very much suspect this is the
4161 * only application of this call. To verify this, let people report
4164 if (!sid_check_is_builtin(&domain_sid
)) {
4165 DEBUG(1,("_samr_remove_sid_foreign_domain: domain_sid = %s, "
4166 "global_sam_sid() = %s\n",
4167 sid_string_static(&domain_sid
),
4168 sid_string_static(get_global_sam_sid())));
4169 DEBUGADD(1,("please report to samba-technical@samba.org!\n"));
4170 return NT_STATUS_OK
;
4174 result
= NT_STATUS_OK
;
4179 /*******************************************************************
4181 ********************************************************************/
4183 NTSTATUS
_samr_unknown_2e(pipes_struct
*p
, SAMR_Q_UNKNOWN_2E
*q_u
, SAMR_R_UNKNOWN_2E
*r_u
)
4185 struct samr_info
*info
= NULL
;
4187 uint32 min_pass_len
,pass_hist
,flag
;
4188 time_t u_expire
, u_min_age
;
4189 NTTIME nt_expire
, nt_min_age
;
4191 time_t u_lock_duration
, u_reset_time
;
4192 NTTIME nt_lock_duration
, nt_reset_time
;
4198 uint32 num_users
=0, num_groups
=0, num_aliases
=0;
4200 uint32 account_policy_temp
;
4203 if ((ctr
= TALLOC_ZERO_P(p
->mem_ctx
, SAM_UNK_CTR
)) == NULL
)
4204 return NT_STATUS_NO_MEMORY
;
4208 r_u
->status
= NT_STATUS_OK
;
4210 DEBUG(5,("_samr_unknown_2e: %d\n", __LINE__
));
4212 /* find the policy handle. open a policy on it. */
4213 if (!find_policy_by_hnd(p
, &q_u
->domain_pol
, (void **)&info
))
4214 return NT_STATUS_INVALID_HANDLE
;
4216 switch (q_u
->switch_value
) {
4218 account_policy_get(AP_MIN_PASSWORD_LEN
, &account_policy_temp
);
4219 min_pass_len
= account_policy_temp
;
4221 account_policy_get(AP_PASSWORD_HISTORY
, &account_policy_temp
);
4222 pass_hist
= account_policy_temp
;
4224 account_policy_get(AP_USER_MUST_LOGON_TO_CHG_PASS
, &account_policy_temp
);
4225 flag
= account_policy_temp
;
4227 account_policy_get(AP_MAX_PASSWORD_AGE
, &account_policy_temp
);
4228 u_expire
= account_policy_temp
;
4230 account_policy_get(AP_MIN_PASSWORD_AGE
, &account_policy_temp
);
4231 u_min_age
= account_policy_temp
;
4233 unix_to_nt_time_abs(&nt_expire
, u_expire
);
4234 unix_to_nt_time_abs(&nt_min_age
, u_min_age
);
4236 init_unk_info1(&ctr
->info
.inf1
, (uint16
)min_pass_len
, (uint16
)pass_hist
,
4237 flag
, nt_expire
, nt_min_age
);
4241 num_users
= count_sam_users(&info
->disp_info
,
4243 num_groups
= count_sam_groups(&info
->disp_info
);
4248 account_policy_get(AP_TIME_TO_LOGOUT
, &account_policy_temp
);
4249 u_logout
= account_policy_temp
;
4251 unix_to_nt_time_abs(&nt_logout
, u_logout
);
4253 server_role
= ROLE_DOMAIN_PDC
;
4254 if (lp_server_role() == ROLE_DOMAIN_BDC
)
4255 server_role
= ROLE_DOMAIN_BDC
;
4257 /* The time call below is to get a sequence number for the sam. FIXME !!! JRA. */
4258 init_unk_info2(&ctr
->info
.inf2
, lp_serverstring(), lp_workgroup(), global_myname(), time(NULL
),
4259 num_users
, num_groups
, num_aliases
, nt_logout
, server_role
);
4262 account_policy_get(AP_TIME_TO_LOGOUT
, &account_policy_temp
);
4263 u_logout
= account_policy_temp
;
4265 unix_to_nt_time_abs(&nt_logout
, u_logout
);
4267 init_unk_info3(&ctr
->info
.inf3
, nt_logout
);
4270 init_unk_info5(&ctr
->info
.inf5
, global_myname());
4273 init_unk_info6(&ctr
->info
.inf6
);
4276 server_role
= ROLE_DOMAIN_PDC
;
4277 if (lp_server_role() == ROLE_DOMAIN_BDC
)
4278 server_role
= ROLE_DOMAIN_BDC
;
4279 init_unk_info7(&ctr
->info
.inf7
, server_role
);
4282 init_unk_info8(&ctr
->info
.inf8
, (uint32
) time(NULL
));
4285 account_policy_get(AP_LOCK_ACCOUNT_DURATION
, &account_policy_temp
);
4286 u_lock_duration
= account_policy_temp
;
4287 if (u_lock_duration
!= -1)
4288 u_lock_duration
*= 60;
4290 account_policy_get(AP_RESET_COUNT_TIME
, &account_policy_temp
);
4291 u_reset_time
= account_policy_temp
* 60;
4293 account_policy_get(AP_BAD_ATTEMPT_LOCKOUT
, &account_policy_temp
);
4294 lockout
= account_policy_temp
;
4296 unix_to_nt_time_abs(&nt_lock_duration
, u_lock_duration
);
4297 unix_to_nt_time_abs(&nt_reset_time
, u_reset_time
);
4299 init_unk_info12(&ctr
->info
.inf12
, nt_lock_duration
, nt_reset_time
, (uint16
)lockout
);
4302 return NT_STATUS_INVALID_INFO_CLASS
;
4305 init_samr_r_samr_unknown_2e(r_u
, q_u
->switch_value
, ctr
, NT_STATUS_OK
);
4307 DEBUG(5,("_samr_unknown_2e: %d\n", __LINE__
));
4312 /*******************************************************************
4314 ********************************************************************/
4316 NTSTATUS
_samr_set_dom_info(pipes_struct
*p
, SAMR_Q_SET_DOMAIN_INFO
*q_u
, SAMR_R_SET_DOMAIN_INFO
*r_u
)
4318 time_t u_expire
, u_min_age
;
4320 time_t u_lock_duration
, u_reset_time
;
4322 r_u
->status
= NT_STATUS_OK
;
4324 DEBUG(5,("_samr_set_dom_info: %d\n", __LINE__
));
4326 /* find the policy handle. open a policy on it. */
4327 if (!find_policy_by_hnd(p
, &q_u
->domain_pol
, NULL
))
4328 return NT_STATUS_INVALID_HANDLE
;
4330 DEBUG(5,("_samr_set_dom_info: switch_value: %d\n", q_u
->switch_value
));
4332 switch (q_u
->switch_value
) {
4334 u_expire
=nt_time_to_unix_abs(&q_u
->ctr
->info
.inf1
.expire
);
4335 u_min_age
=nt_time_to_unix_abs(&q_u
->ctr
->info
.inf1
.min_passwordage
);
4337 account_policy_set(AP_MIN_PASSWORD_LEN
, (uint32
)q_u
->ctr
->info
.inf1
.min_length_password
);
4338 account_policy_set(AP_PASSWORD_HISTORY
, (uint32
)q_u
->ctr
->info
.inf1
.password_history
);
4339 account_policy_set(AP_USER_MUST_LOGON_TO_CHG_PASS
, (uint32
)q_u
->ctr
->info
.inf1
.flag
);
4340 account_policy_set(AP_MAX_PASSWORD_AGE
, (int)u_expire
);
4341 account_policy_set(AP_MIN_PASSWORD_AGE
, (int)u_min_age
);
4346 u_logout
=nt_time_to_unix_abs(&q_u
->ctr
->info
.inf3
.logout
);
4347 account_policy_set(AP_TIME_TO_LOGOUT
, (int)u_logout
);
4356 u_lock_duration
=nt_time_to_unix_abs(&q_u
->ctr
->info
.inf12
.duration
);
4357 if (u_lock_duration
!= -1)
4358 u_lock_duration
/= 60;
4360 u_reset_time
=nt_time_to_unix_abs(&q_u
->ctr
->info
.inf12
.reset_count
)/60;
4362 account_policy_set(AP_LOCK_ACCOUNT_DURATION
, (int)u_lock_duration
);
4363 account_policy_set(AP_RESET_COUNT_TIME
, (int)u_reset_time
);
4364 account_policy_set(AP_BAD_ATTEMPT_LOCKOUT
, (uint32
)q_u
->ctr
->info
.inf12
.bad_attempt_lockout
);
4367 return NT_STATUS_INVALID_INFO_CLASS
;
4370 init_samr_r_set_domain_info(r_u
, NT_STATUS_OK
);
4372 DEBUG(5,("_samr_set_dom_info: %d\n", __LINE__
));