if ( sid ) {
init_sec_access( &mask, sid_access );
init_sec_ace(&ace[i++], sid, SEC_ACE_TYPE_ACCESS_ALLOWED, mask, 0);
-}
+ }
/* create the security descriptor */
TALLOC_CTX *mem_ctx;
DISP_INFO *dpi;
+ /* There are two cases to consider here:
+ 1) The SID is a domain SID and we look for an equality match, or
+ 2) This is an account SID and so we return the DISP_INFO* for our
+ domain */
+
+ if ( psid && sid_check_is_in_our_domain( psid ) ) {
+ DEBUG(10,("get_samr_dispinfo_by_sid: Replacing %s with our domain SID\n",
+ sid_str));
+ psid = get_global_sam_sid();
+ }
+
for (dpi = disp_info_list; dpi; dpi = dpi->next) {
if (sid_equal(psid, &dpi->sid)) {
return dpi;
Ensure password info is never given out. Paranioa... JRA.
********************************************************************/
-static void samr_clear_sam_passwd(SAM_ACCOUNT *sam_pass)
+static void samr_clear_sam_passwd(struct samu *sam_pass)
{
if (!sam_pass)
type[i] = SID_NAME_ALIAS;
}
} else {
- lookup_global_sam_name(name, &rid[i], &type[i]);
+ lookup_global_sam_name(name, 0, &rid[i], &type[i]);
}
if (type[i] != SID_NAME_UNKNOWN) {
*/
r_u->status = pass_oem_change(user_name, q_u->lm_newpass.pass, q_u->lm_oldhash.hash,
- q_u->nt_newpass.pass, q_u->nt_oldhash.hash);
+ q_u->nt_newpass.pass, q_u->nt_oldhash.hash, NULL);
init_samr_r_chgpasswd_user(r_u, r_u->status);
return r_u->status;
}
+/*******************************************************************
+ _samr_chgpasswd_user3
+ ********************************************************************/
+
+NTSTATUS _samr_chgpasswd_user3(pipes_struct *p, SAMR_Q_CHGPASSWD_USER3 *q_u, SAMR_R_CHGPASSWD_USER3 *r_u)
+{
+ fstring user_name;
+ fstring wks;
+ uint32 reject_reason;
+ SAM_UNK_INFO_1 *info = NULL;
+ SAMR_CHANGE_REJECT *reject = NULL;
+
+ DEBUG(5,("_samr_chgpasswd_user3: %d\n", __LINE__));
+
+ rpcstr_pull(user_name, q_u->uni_user_name.buffer, sizeof(user_name), q_u->uni_user_name.uni_str_len*2, 0);
+ rpcstr_pull(wks, q_u->uni_dest_host.buffer, sizeof(wks), q_u->uni_dest_host.uni_str_len*2,0);
+
+ DEBUG(5,("_samr_chgpasswd_user3: user: %s wks: %s\n", user_name, wks));
+
+ /*
+ * Pass the user through the NT -> unix user mapping
+ * function.
+ */
+
+ (void)map_username(user_name);
+
+ /*
+ * UNIX username case mangling not required, pass_oem_change
+ * is case insensitive.
+ */
+
+ r_u->status = pass_oem_change(user_name, q_u->lm_newpass.pass, q_u->lm_oldhash.hash,
+ q_u->nt_newpass.pass, q_u->nt_oldhash.hash, &reject_reason);
+
+ if (NT_STATUS_EQUAL(r_u->status, NT_STATUS_PASSWORD_RESTRICTION) ||
+ NT_STATUS_EQUAL(r_u->status, NT_STATUS_ACCOUNT_RESTRICTION)) {
+
+ uint32 min_pass_len,pass_hist,password_properties;
+ time_t u_expire, u_min_age;
+ NTTIME nt_expire, nt_min_age;
+ uint32 account_policy_temp;
+
+ if ((info = TALLOC_ZERO_P(p->mem_ctx, SAM_UNK_INFO_1)) == NULL) {
+ return NT_STATUS_NO_MEMORY;
+ }
+
+ if ((reject = TALLOC_ZERO_P(p->mem_ctx, SAMR_CHANGE_REJECT)) == NULL) {
+ return NT_STATUS_NO_MEMORY;
+ }
+
+ ZERO_STRUCTP(info);
+ ZERO_STRUCTP(reject);
+
+ become_root();
+
+ /* AS ROOT !!! */
+
+ pdb_get_account_policy(AP_MIN_PASSWORD_LEN, &account_policy_temp);
+ min_pass_len = account_policy_temp;
+
+ pdb_get_account_policy(AP_PASSWORD_HISTORY, &account_policy_temp);
+ pass_hist = account_policy_temp;
+
+ pdb_get_account_policy(AP_USER_MUST_LOGON_TO_CHG_PASS, &account_policy_temp);
+ password_properties = account_policy_temp;
+
+ pdb_get_account_policy(AP_MAX_PASSWORD_AGE, &account_policy_temp);
+ u_expire = account_policy_temp;
+
+ pdb_get_account_policy(AP_MIN_PASSWORD_AGE, &account_policy_temp);
+ u_min_age = account_policy_temp;
+
+ /* !AS ROOT */
+
+ unbecome_root();
+
+ unix_to_nt_time_abs(&nt_expire, u_expire);
+ unix_to_nt_time_abs(&nt_min_age, u_min_age);
+
+ init_unk_info1(info, (uint16)min_pass_len, (uint16)pass_hist,
+ password_properties, nt_expire, nt_min_age);
+
+ reject->reject_reason = reject_reason;
+ }
+
+ init_samr_r_chgpasswd_user3(r_u, r_u->status, reject, info);
+
+ DEBUG(5,("_samr_chgpasswd_user3: %d\n", __LINE__));
+
+ return r_u->status;
+}
+
/*******************************************************************
makes a SAMR_R_LOOKUP_RIDS structure.
********************************************************************/
NTSTATUS _samr_open_user(pipes_struct *p, SAMR_Q_OPEN_USER *q_u, SAMR_R_OPEN_USER *r_u)
{
- SAM_ACCOUNT *sampass=NULL;
+ struct samu *sampass=NULL;
DOM_SID sid;
POLICY_HND domain_pol = q_u->domain_pol;
POLICY_HND *user_pol = &r_u->user_pol;
if ( !NT_STATUS_IS_OK(nt_status) )
return nt_status;
- nt_status = pdb_init_sam_talloc(p->mem_ctx, &sampass);
-
- if (!NT_STATUS_IS_OK(nt_status))
- return nt_status;
+ if ( !(sampass = samu_new( p->mem_ctx )) ) {
+ return NT_STATUS_NO_MEMORY;
+ }
/* append the user's RID to it */
return NT_STATUS_NO_SUCH_USER;
}
- pdb_free_sam(&sampass);
+ TALLOC_FREE(sampass);
/* associate the user's SID and access bits with the new handle. */
if ((info = get_samr_info_by_sid(&sid)) == NULL)
static NTSTATUS get_user_info_7(TALLOC_CTX *mem_ctx, SAM_USER_INFO_7 *id7, DOM_SID *user_sid)
{
- SAM_ACCOUNT *smbpass=NULL;
+ struct samu *smbpass=NULL;
BOOL ret;
- NTSTATUS nt_status;
- nt_status = pdb_init_sam_talloc(mem_ctx, &smbpass);
+ if ( !(smbpass = samu_new( mem_ctx )) ) {
+ return NT_STATUS_NO_MEMORY;
+ }
- if (!NT_STATUS_IS_OK(nt_status)) {
- return nt_status;
+ become_root();
+ ret = pdb_getsampwsid(smbpass, user_sid);
+ unbecome_root();
+
+ if ( !ret ) {
+ DEBUG(4,("User %s not found\n", sid_string_static(user_sid)));
+ return NT_STATUS_NO_SUCH_USER;
+ }
+
+ DEBUG(3,("User:[%s]\n", pdb_get_username(smbpass) ));
+
+ ZERO_STRUCTP(id7);
+ init_sam_user_info7(id7, pdb_get_username(smbpass) );
+
+ TALLOC_FREE(smbpass);
+
+ return NT_STATUS_OK;
+}
+
+/*************************************************************************
+ get_user_info_9. Only gives out primary group SID.
+ *************************************************************************/
+static NTSTATUS get_user_info_9(TALLOC_CTX *mem_ctx, SAM_USER_INFO_9 * id9, DOM_SID *user_sid)
+{
+ struct samu *smbpass=NULL;
+ BOOL ret;
+
+ if ( !(smbpass = samu_new( mem_ctx )) ) {
+ return NT_STATUS_NO_MEMORY;
}
become_root();
DEBUG(3,("User:[%s]\n", pdb_get_username(smbpass) ));
- ZERO_STRUCTP(id7);
- init_sam_user_info7(id7, pdb_get_username(smbpass) );
+ ZERO_STRUCTP(id9);
+ init_sam_user_info9(id9, pdb_get_group_rid(smbpass) );
- pdb_free_sam(&smbpass);
+ TALLOC_FREE(smbpass);
return NT_STATUS_OK;
}
+
/*************************************************************************
get_user_info_16. Safe. Only gives out acb bits.
*************************************************************************/
static NTSTATUS get_user_info_16(TALLOC_CTX *mem_ctx, SAM_USER_INFO_16 *id16, DOM_SID *user_sid)
{
- SAM_ACCOUNT *smbpass=NULL;
+ struct samu *smbpass=NULL;
BOOL ret;
- NTSTATUS nt_status;
- nt_status = pdb_init_sam_talloc(mem_ctx, &smbpass);
-
- if (!NT_STATUS_IS_OK(nt_status)) {
- return nt_status;
+ if ( !(smbpass = samu_new( mem_ctx )) ) {
+ return NT_STATUS_NO_MEMORY;
}
become_root();
ZERO_STRUCTP(id16);
init_sam_user_info16(id16, pdb_get_acct_ctrl(smbpass) );
- pdb_free_sam(&smbpass);
+ TALLOC_FREE(smbpass);
return NT_STATUS_OK;
}
static NTSTATUS get_user_info_18(pipes_struct *p, TALLOC_CTX *mem_ctx, SAM_USER_INFO_18 * id18, DOM_SID *user_sid)
{
- SAM_ACCOUNT *smbpass=NULL;
+ struct samu *smbpass=NULL;
BOOL ret;
- NTSTATUS nt_status;
if (p->auth.auth_type != PIPE_AUTH_TYPE_NTLMSSP || p->auth.auth_type != PIPE_AUTH_TYPE_SPNEGO_NTLMSSP) {
return NT_STATUS_ACCESS_DENIED;
* Do *NOT* do become_root()/unbecome_root() here ! JRA.
*/
- nt_status = pdb_init_sam_talloc(mem_ctx, &smbpass);
-
- if (!NT_STATUS_IS_OK(nt_status)) {
- return nt_status;
+ if ( !(smbpass = samu_new( mem_ctx )) ) {
+ return NT_STATUS_NO_MEMORY;
}
ret = pdb_getsampwsid(smbpass, user_sid);
if (ret == False) {
DEBUG(4, ("User %s not found\n", sid_string_static(user_sid)));
- pdb_free_sam(&smbpass);
+ TALLOC_FREE(smbpass);
return (geteuid() == (uid_t)0) ? NT_STATUS_NO_SUCH_USER : NT_STATUS_ACCESS_DENIED;
}
DEBUG(3,("User:[%s] 0x%x\n", pdb_get_username(smbpass), pdb_get_acct_ctrl(smbpass) ));
if ( pdb_get_acct_ctrl(smbpass) & ACB_DISABLED) {
- pdb_free_sam(&smbpass);
+ TALLOC_FREE(smbpass);
return NT_STATUS_ACCOUNT_DISABLED;
}
ZERO_STRUCTP(id18);
init_sam_user_info18(id18, pdb_get_lanman_passwd(smbpass), pdb_get_nt_passwd(smbpass));
- pdb_free_sam(&smbpass);
+ TALLOC_FREE(smbpass);
return NT_STATUS_OK;
}
static NTSTATUS get_user_info_20(TALLOC_CTX *mem_ctx, SAM_USER_INFO_20 *id20, DOM_SID *user_sid)
{
- SAM_ACCOUNT *sampass=NULL;
+ struct samu *sampass=NULL;
BOOL ret;
- pdb_init_sam_talloc(mem_ctx, &sampass);
+ if ( !(sampass = samu_new( mem_ctx )) ) {
+ return NT_STATUS_NO_MEMORY;
+ }
become_root();
ret = pdb_getsampwsid(sampass, user_sid);
ZERO_STRUCTP(id20);
init_sam_user_info20A(id20, sampass);
- pdb_free_sam(&sampass);
+ TALLOC_FREE(sampass);
return NT_STATUS_OK;
}
static NTSTATUS get_user_info_21(TALLOC_CTX *mem_ctx, SAM_USER_INFO_21 *id21,
DOM_SID *user_sid, DOM_SID *domain_sid)
{
- SAM_ACCOUNT *sampass=NULL;
+ struct samu *sampass=NULL;
BOOL ret;
NTSTATUS nt_status;
- nt_status = pdb_init_sam_talloc(mem_ctx, &sampass);
- if (!NT_STATUS_IS_OK(nt_status)) {
- return nt_status;
+ if ( !(sampass = samu_new( mem_ctx )) ) {
+ return NT_STATUS_NO_MEMORY;
}
become_root();
ZERO_STRUCTP(id21);
nt_status = init_sam_user_info21A(id21, sampass, domain_sid);
- pdb_free_sam(&sampass);
+ TALLOC_FREE(sampass);
return NT_STATUS_OK;
}
/* ok! user info levels (lots: see MSDEV help), off we go... */
ctr->switch_value = q_u->switch_value;
+ DEBUG(5,("_samr_query_userinfo: user info level: %d\n", q_u->switch_value));
+
switch (q_u->switch_value) {
case 7:
ctr->info.id7 = TALLOC_ZERO_P(p->mem_ctx, SAM_USER_INFO_7);
if (!NT_STATUS_IS_OK(r_u->status = get_user_info_7(p->mem_ctx, ctr->info.id7, &info->sid)))
return r_u->status;
break;
+ case 9:
+ ctr->info.id9 = TALLOC_ZERO_P(p->mem_ctx, SAM_USER_INFO_9);
+ if (ctr->info.id9 == NULL)
+ return NT_STATUS_NO_MEMORY;
+
+ if (!NT_STATUS_IS_OK(r_u->status = get_user_info_9(p->mem_ctx, ctr->info.id9, &info->sid)))
+ return r_u->status;
+ break;
case 16:
ctr->info.id16 = TALLOC_ZERO_P(p->mem_ctx, SAM_USER_INFO_16);
if (ctr->info.id16 == NULL)
return r_u->status;
break;
-#if 0
-/* whoops - got this wrong. i think. or don't understand what's happening. */
- case 17:
- {
- NTTIME expire;
- info = (void *)&id11;
-
- expire.low = 0xffffffff;
- expire.high = 0x7fffffff;
-
- ctr->info.id = TALLOC_ZERO_P(p->mem_ctx, SAM_USER_INFO_17));
- ZERO_STRUCTP(ctr->info.id17);
- init_sam_user_info17(ctr->info.id17, &expire,
- "BROOKFIELDS$", /* name */
- 0x03ef, /* user rid */
- 0x201, /* group rid */
- 0x0080); /* acb info */
-
- break;
- }
-#endif
-
case 18:
ctr->info.id18 = TALLOC_ZERO_P(p->mem_ctx, SAM_USER_INFO_18);
if (ctr->info.id18 == NULL)
NTSTATUS _samr_query_usergroups(pipes_struct *p, SAMR_Q_QUERY_USERGROUPS *q_u, SAMR_R_QUERY_USERGROUPS *r_u)
{
- SAM_ACCOUNT *sam_pass=NULL;
- struct passwd *passwd;
+ struct samu *sam_pass=NULL;
DOM_SID sid;
DOM_SID *sids;
+ DOM_GID dom_gid;
DOM_GID *gids = NULL;
+ uint32 primary_group_rid;
size_t num_groups = 0;
gid_t *unix_gids;
size_t i, num_gids;
if (!sid_check_is_in_our_domain(&sid))
return NT_STATUS_OBJECT_TYPE_MISMATCH;
- pdb_init_sam(&sam_pass);
-
+ if ( !(sam_pass = samu_new( p->mem_ctx )) ) {
+ return NT_STATUS_NO_MEMORY;
+ }
+
become_root();
ret = pdb_getsampwsid(sam_pass, &sid);
unbecome_root();
- if (ret == False) {
- pdb_free_sam(&sam_pass);
- return NT_STATUS_NO_SUCH_USER;
- }
-
- passwd = getpwnam_alloc(pdb_get_username(sam_pass));
- if (passwd == NULL) {
- pdb_free_sam(&sam_pass);
+ if (!ret) {
+ DEBUG(10, ("pdb_getsampwsid failed for %s\n",
+ sid_string_static(&sid)));
return NT_STATUS_NO_SUCH_USER;
}
sids = NULL;
become_root();
- result = pdb_enum_group_memberships(pdb_get_username(sam_pass),
- passwd->pw_gid,
+ result = pdb_enum_group_memberships(p->mem_ctx, sam_pass,
&sids, &unix_gids, &num_groups);
unbecome_root();
- pdb_free_sam(&sam_pass);
- passwd_free(&passwd);
-
- if (!NT_STATUS_IS_OK(result))
+ if (!NT_STATUS_IS_OK(result)) {
+ DEBUG(10, ("pdb_enum_group_memberships failed for %s\n",
+ sid_string_static(&sid)));
return result;
-
- SAFE_FREE(unix_gids);
+ }
gids = NULL;
num_gids = 0;
+ dom_gid.attr = (SE_GROUP_MANDATORY|SE_GROUP_ENABLED_BY_DEFAULT|
+ SE_GROUP_ENABLED);
+
+ if (!sid_peek_check_rid(get_global_sam_sid(),
+ pdb_get_group_sid(sam_pass),
+ &primary_group_rid)) {
+ DEBUG(5, ("Group sid %s for user %s not in our domain\n",
+ sid_string_static(pdb_get_group_sid(sam_pass)),
+ pdb_get_username(sam_pass)));
+ TALLOC_FREE(sam_pass);
+ return NT_STATUS_INTERNAL_DB_CORRUPTION;
+ }
+
+ dom_gid.g_rid = primary_group_rid;
+
+ ADD_TO_ARRAY(p->mem_ctx, DOM_GID, dom_gid, &gids, &num_gids);
+
for (i=0; i<num_groups; i++) {
- uint32 rid;
if (!sid_peek_check_rid(get_global_sam_sid(),
- &(sids[i]), &rid))
+ &(sids[i]), &dom_gid.g_rid)) {
+ DEBUG(10, ("Found sid %s not in our domain\n",
+ sid_string_static(&sids[i])));
continue;
+ }
- gids = TALLOC_REALLOC_ARRAY(p->mem_ctx, gids, DOM_GID, num_gids+1);
- gids[num_gids].attr= (SE_GROUP_MANDATORY|SE_GROUP_ENABLED_BY_DEFAULT|SE_GROUP_ENABLED);
- gids[num_gids].g_rid = rid;
- num_gids += 1;
+ if (dom_gid.g_rid == primary_group_rid) {
+ /* We added the primary group directly from the
+ * sam_account. The other SIDs are unique from
+ * enum_group_memberships */
+ continue;
+ }
+
+ ADD_TO_ARRAY(p->mem_ctx, DOM_GID, dom_gid, &gids, &num_gids);
}
- SAFE_FREE(sids);
/* construct the response. lkclXXXX: gids are not copied! */
- init_samr_r_query_usergroups(r_u, num_groups, gids, r_u->status);
+ init_samr_r_query_usergroups(r_u, num_gids, gids, r_u->status);
DEBUG(5,("_samr_query_usergroups: %d\n", __LINE__));
{
struct samr_info *info = NULL;
SAM_UNK_CTR *ctr;
- uint32 min_pass_len,pass_hist,flag;
+ uint32 min_pass_len,pass_hist,password_properties;
time_t u_expire, u_min_age;
NTTIME nt_expire, nt_min_age;
pass_hist = account_policy_temp;
pdb_get_account_policy(AP_USER_MUST_LOGON_TO_CHG_PASS, &account_policy_temp);
- flag = account_policy_temp;
+ password_properties = account_policy_temp;
pdb_get_account_policy(AP_MAX_PASSWORD_AGE, &account_policy_temp);
u_expire = account_policy_temp;
unix_to_nt_time_abs(&nt_min_age, u_min_age);
init_unk_info1(&ctr->info.inf1, (uint16)min_pass_len, (uint16)pass_hist,
- flag, nt_expire, nt_min_age);
+ password_properties, nt_expire, nt_min_age);
break;
case 0x02:
This funcion will need to be updated for bdc/domain trusts.
********************************************************************/
-NTSTATUS _samr_create_user(pipes_struct *p, SAMR_Q_CREATE_USER *q_u, SAMR_R_CREATE_USER *r_u)
+NTSTATUS _samr_create_user(pipes_struct *p, SAMR_Q_CREATE_USER *q_u,
+ SAMR_R_CREATE_USER *r_u)
{
- SAM_ACCOUNT *sam_pass=NULL;
- fstring account;
+ char *account;
DOM_SID sid;
- pstring add_script;
POLICY_HND dom_pol = q_u->domain_pol;
- UNISTR2 user_account = q_u->uni_name;
uint16 acb_info = q_u->acb_info;
POLICY_HND *user_pol = &r_u->user_pol;
struct samr_info *info = NULL;
- BOOL ret;
NTSTATUS nt_status;
- struct passwd *pw;
uint32 acc_granted;
SEC_DESC *psd;
size_t sd_size;
- uint32 new_rid = 0;
/* check this, when giving away 'add computer to domain' privs */
uint32 des_access = GENERIC_RIGHTS_USER_ALL_ACCESS;
BOOL can_add_account = False;
DISP_INFO *disp_info = NULL;
/* Get the domain SID stored in the domain policy */
- if (!get_lsa_policy_samr_sid(p, &dom_pol, &sid, &acc_granted, &disp_info))
+ if (!get_lsa_policy_samr_sid(p, &dom_pol, &sid, &acc_granted,
+ &disp_info))
return NT_STATUS_INVALID_HANDLE;
- if (!NT_STATUS_IS_OK(nt_status = access_check_samr_function(acc_granted, SA_RIGHT_DOMAIN_CREATE_USER, "_samr_create_user"))) {
+ nt_status = access_check_samr_function(acc_granted,
+ SA_RIGHT_DOMAIN_CREATE_USER,
+ "_samr_create_user");
+ if (!NT_STATUS_IS_OK(nt_status)) {
return nt_status;
}
- if (!(acb_info == ACB_NORMAL || acb_info == ACB_DOMTRUST || acb_info == ACB_WSTRUST || acb_info == ACB_SVRTRUST)) {
+ if (!(acb_info == ACB_NORMAL || acb_info == ACB_DOMTRUST ||
+ acb_info == ACB_WSTRUST || acb_info == ACB_SVRTRUST)) {
/* Match Win2k, and return NT_STATUS_INVALID_PARAMETER if
this parameter is not an account type */
return NT_STATUS_INVALID_PARAMETER;
}
- rpcstr_pull(account, user_account.buffer, sizeof(account), user_account.uni_str_len*2, 0);
- strlower_m(account);
+ account = rpcstr_pull_unistr2_talloc(p->mem_ctx, &q_u->uni_name);
+ if (account == NULL) {
+ return NT_STATUS_NO_MEMORY;
+ }
nt_status = can_create(p->mem_ctx, account);
if (!NT_STATUS_IS_OK(nt_status)) {
return nt_status;
}
- /*********************************************************************
- * HEADS UP! If we have to create a new user account, we have to get
- * a new RID from somewhere. This used to be done by the passdb
- * backend. It has been moved into idmap now. Since idmap is now
- * wrapped up behind winbind, this means you have to run winbindd if you
- * want new accounts to get a new RID when "enable rid algorithm = no".
- * Tough. We now have a uniform way of allocating RIDs regardless
- * of what ever passdb backend people may use.
- * --jerry (2003-07-10)
- *********************************************************************/
-
- pw = Get_Pwnam(account);
-
/* determine which user right we need to check based on the acb_info */
if ( acb_info & ACB_WSTRUST )
{
- pstrcpy(add_script, lp_addmachine_script());
se_priv_copy( &se_rights, &se_machine_account );
- can_add_account = user_has_privileges( p->pipe_user.nt_user_token, &se_rights );
+ can_add_account = user_has_privileges(
+ p->pipe_user.nt_user_token, &se_rights );
}
/* usrmgr.exe (and net rpc trustdom grant) creates a normal user
account for domain trusts and changes the ACB flags later */
- else if ( acb_info & ACB_NORMAL && (account[strlen(account)-1] != '$') )
+ else if ( acb_info & ACB_NORMAL &&
+ (account[strlen(account)-1] != '$') )
{
- pstrcpy(add_script, lp_adduser_script());
se_priv_copy( &se_rights, &se_add_users );
- can_add_account = user_has_privileges( p->pipe_user.nt_user_token, &se_rights );
+ can_add_account = user_has_privileges(
+ p->pipe_user.nt_user_token, &se_rights );
}
- else /* implicit assumption of a BDC or domain trust account here (we already check the flags earlier) */
+ else /* implicit assumption of a BDC or domain trust account here
+ * (we already check the flags earlier) */
{
- pstrcpy(add_script, lp_addmachine_script());
if ( lp_enable_privileges() ) {
/* only Domain Admins can add a BDC or domain trust */
se_priv_copy( &se_rights, &se_priv_none );
- can_add_account = nt_token_check_domain_rid( p->pipe_user.nt_user_token, DOMAIN_GROUP_RID_ADMINS );
- }
+ can_add_account = nt_token_check_domain_rid(
+ p->pipe_user.nt_user_token,
+ DOMAIN_GROUP_RID_ADMINS );
+ }
}
DEBUG(5, ("_samr_create_user: %s can add this account : %s\n",
if ( can_add_account )
become_root();
- if ( !pw ) {
- if (*add_script) {
- int add_ret;
-
- all_string_sub(add_script, "%u", account, sizeof(add_script));
- add_ret = smbrun(add_script,NULL);
- DEBUG(add_ret ? 0 : 3,("_samr_create_user: Running the command `%s' gave %d\n", add_script, add_ret));
- }
- }
-
- /* implicit call to getpwnam() next. we have a valid SID coming out of this call */
+ nt_status = pdb_create_user(p->mem_ctx, account, acb_info,
+ &r_u->user_rid);
- flush_pwnam_cache();
- nt_status = pdb_init_sam_new(&sam_pass, account, new_rid);
-
- /* this code is order such that we have no unnecessary retuns
- out of the admin block of code */
-
- if ( NT_STATUS_IS_OK(nt_status) ) {
- pdb_set_acct_ctrl(sam_pass, acb_info, PDB_CHANGED);
-
- if ( !(ret = pdb_add_sam_account(sam_pass)) ) {
- pdb_free_sam(&sam_pass);
- DEBUG(0, ("could not add user/computer %s to passdb. Check permissions?\n",
- account));
- nt_status = NT_STATUS_ACCESS_DENIED;
- }
- }
-
if ( can_add_account )
unbecome_root();
return nt_status;
/* Get the user's SID */
+
+ sid_compose(&sid, get_global_sam_sid(), r_u->user_rid);
- sid_copy(&sid, pdb_get_user_sid(sam_pass));
-
- make_samr_object_sd(p->mem_ctx, &psd, &sd_size, &usr_generic_mapping, &sid, SAMR_USR_RIGHTS_WRITE_PW);
+ make_samr_object_sd(p->mem_ctx, &psd, &sd_size, &usr_generic_mapping,
+ &sid, SAMR_USR_RIGHTS_WRITE_PW);
se_map_generic(&des_access, &usr_generic_mapping);
nt_status = access_check_samr_object(psd, p->pipe_user.nt_user_token,
/* associate the user's SID with the new handle. */
if ((info = get_samr_info_by_sid(&sid)) == NULL) {
- pdb_free_sam(&sam_pass);
return NT_STATUS_NO_MEMORY;
}
/* get a (unique) handle. open a policy on it. */
if (!create_policy_hnd(p, user_pol, free_samr_info, (void *)info)) {
- pdb_free_sam(&sam_pass);
return NT_STATUS_OBJECT_NAME_NOT_FOUND;
}
/* After a "set" ensure we have no cached display info. */
force_flush_samr_cache(info->disp_info);
- r_u->user_rid=pdb_get_user_rid(sam_pass);
-
r_u->access_granted = acc_granted;
- pdb_free_sam(&sam_pass);
-
return NT_STATUS_OK;
}
was observed from a win98 client trying to enumerate users (when configured
user level access control on shares) --jerry */
+ if (des_access == MAXIMUM_ALLOWED_ACCESS) {
+ /* Map to max possible knowing we're filtered below. */
+ des_access = GENERIC_ALL_ACCESS;
+ }
+
se_map_generic( &des_access, &sam_generic_mapping );
info->acc_granted = des_access & (SA_RIGHT_SAM_ENUM_DOMAINS|SA_RIGHT_SAM_OPEN_DOMAIN);
ZERO_STRUCT(sid);
- if (!secrets_fetch_domain_sid(domain_name, &sid)) {
- r_u->status = NT_STATUS_NO_SUCH_DOMAIN;
+ if (strequal(domain_name, builtin_domain_name())) {
+ sid_copy(&sid, &global_sid_Builtin);
+ } else {
+ if (!secrets_fetch_domain_sid(domain_name, &sid)) {
+ r_u->status = NT_STATUS_NO_SUCH_DOMAIN;
+ }
}
DEBUG(2,("Returning domain sid for domain %s -> %s\n", domain_name, sid_string_static(&sid)));
set_user_info_7
********************************************************************/
static NTSTATUS set_user_info_7(TALLOC_CTX *mem_ctx,
- const SAM_USER_INFO_7 *id7, SAM_ACCOUNT *pwd)
+ const SAM_USER_INFO_7 *id7, struct samu *pwd)
{
fstring new_name;
NTSTATUS rc;
if (id7 == NULL) {
DEBUG(5, ("set_user_info_7: NULL id7\n"));
- pdb_free_sam(&pwd);
+ TALLOC_FREE(pwd);
return NT_STATUS_ACCESS_DENIED;
}
if(!rpcstr_pull(new_name, id7->uni_name.buffer, sizeof(new_name), id7->uni_name.uni_str_len*2, 0)) {
DEBUG(5, ("set_user_info_7: failed to get new username\n"));
- pdb_free_sam(&pwd);
+ TALLOC_FREE(pwd);
return NT_STATUS_ACCESS_DENIED;
}
rc = pdb_rename_sam_account(pwd, new_name);
- pdb_free_sam(&pwd);
+ TALLOC_FREE(pwd);
return rc;
}
set_user_info_16
********************************************************************/
-static BOOL set_user_info_16(const SAM_USER_INFO_16 *id16, SAM_ACCOUNT *pwd)
+static BOOL set_user_info_16(const SAM_USER_INFO_16 *id16, struct samu *pwd)
{
if (id16 == NULL) {
DEBUG(5, ("set_user_info_16: NULL id16\n"));
- pdb_free_sam(&pwd);
+ TALLOC_FREE(pwd);
return False;
}
/* FIX ME: check if the value is really changed --metze */
if (!pdb_set_acct_ctrl(pwd, id16->acb_info, PDB_CHANGED)) {
- pdb_free_sam(&pwd);
+ TALLOC_FREE(pwd);
return False;
}
- if(!pdb_update_sam_account(pwd)) {
- pdb_free_sam(&pwd);
+ if(!NT_STATUS_IS_OK(pdb_update_sam_account(pwd))) {
+ TALLOC_FREE(pwd);
return False;
}
- pdb_free_sam(&pwd);
+ TALLOC_FREE(pwd);
return True;
}
set_user_info_18
********************************************************************/
-static BOOL set_user_info_18(SAM_USER_INFO_18 *id18, SAM_ACCOUNT *pwd)
+static BOOL set_user_info_18(SAM_USER_INFO_18 *id18, struct samu *pwd)
{
if (id18 == NULL) {
DEBUG(2, ("set_user_info_18: id18 is NULL\n"));
- pdb_free_sam(&pwd);
+ TALLOC_FREE(pwd);
return False;
}
if (!pdb_set_lanman_passwd (pwd, id18->lm_pwd, PDB_CHANGED)) {
- pdb_free_sam(&pwd);
+ TALLOC_FREE(pwd);
return False;
}
if (!pdb_set_nt_passwd (pwd, id18->nt_pwd, PDB_CHANGED)) {
- pdb_free_sam(&pwd);
+ TALLOC_FREE(pwd);
return False;
}
if (!pdb_set_pass_changed_now (pwd)) {
- pdb_free_sam(&pwd);
+ TALLOC_FREE(pwd);
return False;
}
- if(!pdb_update_sam_account(pwd)) {
- pdb_free_sam(&pwd);
+ if(!NT_STATUS_IS_OK(pdb_update_sam_account(pwd))) {
+ TALLOC_FREE(pwd);
return False;
}
- pdb_free_sam(&pwd);
- return True;
-}
-
-/*******************************************************************
- The GROUPSID field in the SAM_ACCOUNT changed. Try to tell unix.
- ********************************************************************/
-static BOOL set_unix_primary_group(SAM_ACCOUNT *sampass)
-{
- struct group *grp;
- gid_t gid;
-
- if (!NT_STATUS_IS_OK(sid_to_gid(pdb_get_group_sid(sampass),
- &gid))) {
- DEBUG(2,("Could not get gid for primary group of "
- "user %s\n", pdb_get_username(sampass)));
- return False;
- }
-
- grp = getgrgid(gid);
-
- if (grp == NULL) {
- DEBUG(2,("Could not find primary group %lu for "
- "user %s\n", (unsigned long)gid,
- pdb_get_username(sampass)));
- return False;
- }
-
- if (smb_set_primary_group(grp->gr_name,
- pdb_get_username(sampass)) != 0) {
- DEBUG(2,("Could not set primary group for user %s to "
- "%s\n",
- pdb_get_username(sampass), grp->gr_name));
- return False;
- }
-
+ TALLOC_FREE(pwd);
return True;
}
-
/*******************************************************************
set_user_info_20
********************************************************************/
-static BOOL set_user_info_20(SAM_USER_INFO_20 *id20, SAM_ACCOUNT *pwd)
+static BOOL set_user_info_20(SAM_USER_INFO_20 *id20, struct samu *pwd)
{
if (id20 == NULL) {
DEBUG(5, ("set_user_info_20: NULL id20\n"));
copy_id20_to_sam_passwd(pwd, id20);
/* write the change out */
- if(!pdb_update_sam_account(pwd)) {
- pdb_free_sam(&pwd);
+ if(!NT_STATUS_IS_OK(pdb_update_sam_account(pwd))) {
+ TALLOC_FREE(pwd);
return False;
}
- pdb_free_sam(&pwd);
+ TALLOC_FREE(pwd);
return True;
}
set_user_info_21
********************************************************************/
-static BOOL set_user_info_21(SAM_USER_INFO_21 *id21, SAM_ACCOUNT *pwd)
+static NTSTATUS set_user_info_21(TALLOC_CTX *mem_ctx, SAM_USER_INFO_21 *id21,
+ struct samu *pwd)
{
-
+ NTSTATUS status;
+
if (id21 == NULL) {
DEBUG(5, ("set_user_info_21: NULL id21\n"));
- return False;
+ return NT_STATUS_INVALID_PARAMETER;
}
copy_id21_to_sam_passwd(pwd, id21);
* id21. I don't know if they need to be set. --jerry
*/
- if (IS_SAM_CHANGED(pwd, PDB_GROUPSID))
- set_unix_primary_group(pwd);
+ if (IS_SAM_CHANGED(pwd, PDB_GROUPSID) &&
+ !NT_STATUS_IS_OK(status = pdb_set_unix_primary_group(mem_ctx,
+ pwd))) {
+ return status;
+ }
/* write the change out */
- if(!pdb_update_sam_account(pwd)) {
- pdb_free_sam(&pwd);
- return False;
+ if(!NT_STATUS_IS_OK(status = pdb_update_sam_account(pwd))) {
+ TALLOC_FREE(pwd);
+ return status;
}
- pdb_free_sam(&pwd);
+ TALLOC_FREE(pwd);
- return True;
+ return NT_STATUS_OK;
}
/*******************************************************************
set_user_info_23
********************************************************************/
-static BOOL set_user_info_23(SAM_USER_INFO_23 *id23, SAM_ACCOUNT *pwd)
+static NTSTATUS set_user_info_23(TALLOC_CTX *mem_ctx, SAM_USER_INFO_23 *id23,
+ struct samu *pwd)
{
pstring plaintext_buf;
uint32 len;
uint16 acct_ctrl;
+ NTSTATUS status;
if (id23 == NULL) {
DEBUG(5, ("set_user_info_23: NULL id23\n"));
- return False;
+ return NT_STATUS_INVALID_PARAMETER;
}
DEBUG(5, ("Attempting administrator password change (level 23) for user %s\n",
acct_ctrl = pdb_get_acct_ctrl(pwd);
if (!decode_pw_buffer(id23->pass, plaintext_buf, 256, &len, STR_UNICODE)) {
- pdb_free_sam(&pwd);
- return False;
+ TALLOC_FREE(pwd);
+ return NT_STATUS_INVALID_PARAMETER;
}
if (!pdb_set_plaintext_passwd (pwd, plaintext_buf)) {
- pdb_free_sam(&pwd);
- return False;
+ TALLOC_FREE(pwd);
+ return NT_STATUS_ACCESS_DENIED;
}
copy_id23_to_sam_passwd(pwd, id23);
}
if(!chgpasswd(pdb_get_username(pwd), passwd, "", plaintext_buf, True)) {
- pdb_free_sam(&pwd);
- return False;
+ TALLOC_FREE(pwd);
+ return NT_STATUS_ACCESS_DENIED;
}
}
}
ZERO_STRUCT(plaintext_buf);
- if (IS_SAM_CHANGED(pwd, PDB_GROUPSID))
- set_unix_primary_group(pwd);
+ if (IS_SAM_CHANGED(pwd, PDB_GROUPSID) &&
+ (!NT_STATUS_IS_OK(status = pdb_set_unix_primary_group(mem_ctx,
+ pwd)))) {
+ TALLOC_FREE(pwd);
+ return status;
+ }
- if(!pdb_update_sam_account(pwd)) {
- pdb_free_sam(&pwd);
- return False;
+ if(!NT_STATUS_IS_OK(status = pdb_update_sam_account(pwd))) {
+ TALLOC_FREE(pwd);
+ return status;
}
- pdb_free_sam(&pwd);
+ TALLOC_FREE(pwd);
- return True;
+ return NT_STATUS_OK;
}
/*******************************************************************
set_user_info_pw
********************************************************************/
-static BOOL set_user_info_pw(uint8 *pass, SAM_ACCOUNT *pwd)
+static BOOL set_user_info_pw(uint8 *pass, struct samu *pwd)
{
uint32 len;
pstring plaintext_buf;
ZERO_STRUCT(plaintext_buf);
if (!decode_pw_buffer(pass, plaintext_buf, 256, &len, STR_UNICODE)) {
- pdb_free_sam(&pwd);
+ TALLOC_FREE(pwd);
return False;
}
if (!pdb_set_plaintext_passwd (pwd, plaintext_buf)) {
- pdb_free_sam(&pwd);
+ TALLOC_FREE(pwd);
return False;
}
}
if(!chgpasswd(pdb_get_username(pwd), passwd, "", plaintext_buf, True)) {
- pdb_free_sam(&pwd);
+ TALLOC_FREE(pwd);
return False;
}
}
DEBUG(5,("set_user_info_pw: pdb_update_pwd()\n"));
/* update the SAMBA password */
- if(!pdb_update_sam_account(pwd)) {
- pdb_free_sam(&pwd);
+ if(!NT_STATUS_IS_OK(pdb_update_sam_account(pwd))) {
+ TALLOC_FREE(pwd);
return False;
}
- pdb_free_sam(&pwd);
+ TALLOC_FREE(pwd);
return True;
}
NTSTATUS _samr_set_userinfo(pipes_struct *p, SAMR_Q_SET_USERINFO *q_u, SAMR_R_SET_USERINFO *r_u)
{
- SAM_ACCOUNT *pwd = NULL;
+ struct samu *pwd = NULL;
DOM_SID sid;
POLICY_HND *pol = &q_u->pol;
uint16 switch_value = q_u->switch_value;
return NT_STATUS_INVALID_INFO_CLASS;
}
- pdb_init_sam(&pwd);
+ if ( !(pwd = samu_new( NULL )) ) {
+ return NT_STATUS_NO_MEMORY;
+ }
become_root();
ret = pdb_getsampwsid(pwd, &sid);
unbecome_root();
if ( !ret ) {
- pdb_free_sam(&pwd);
+ TALLOC_FREE(pwd);
return NT_STATUS_NO_SUCH_USER;
}
break;
case 25:
-#if 0
- /*
- * Currently we don't really know how to unmarshall
- * the level 25 struct, and the password encryption
- * is different. This is a placeholder for when we
- * do understand it. In the meantime just return INVALID
- * info level and W2K SP2 drops down to level 23... JRA.
- */
-
if (!p->session_key.length) {
r_u->status = NT_STATUS_NO_USER_SESSION_KEY;
}
- SamOEMhashBlob(ctr->info.id25->pass, 532, &p->session_key);
+ encode_or_decode_arc4_passwd_buffer(ctr->info.id25->pass, &p->session_key);
dump_data(100, (char *)ctr->info.id25->pass, 532);
- if (!set_user_info_pw(ctr->info.id25->pass, &sid))
+ if (!set_user_info_pw(ctr->info.id25->pass, pwd))
r_u->status = NT_STATUS_ACCESS_DENIED;
break;
-#endif
- r_u->status = NT_STATUS_INVALID_INFO_CLASS;
+
+ case 26:
+ if (!p->session_key.length) {
+ r_u->status = NT_STATUS_NO_USER_SESSION_KEY;
+ }
+ encode_or_decode_arc4_passwd_buffer(ctr->info.id26->pass, &p->session_key);
+
+ dump_data(100, (char *)ctr->info.id26->pass, 516);
+
+ if (!set_user_info_pw(ctr->info.id26->pass, pwd))
+ r_u->status = NT_STATUS_ACCESS_DENIED;
break;
case 23:
dump_data(100, (char *)ctr->info.id23->pass, 516);
- if (!set_user_info_23(ctr->info.id23, pwd))
- r_u->status = NT_STATUS_ACCESS_DENIED;
+ r_u->status = set_user_info_23(p->mem_ctx,
+ ctr->info.id23, pwd);
break;
default:
NTSTATUS _samr_set_userinfo2(pipes_struct *p, SAMR_Q_SET_USERINFO2 *q_u, SAMR_R_SET_USERINFO2 *r_u)
{
- SAM_ACCOUNT *pwd = NULL;
+ struct samu *pwd = NULL;
DOM_SID sid;
SAM_USERINFO_CTR *ctr = q_u->ctr;
POLICY_HND *pol = &q_u->pol;
switch_value=ctr->switch_value;
- pdb_init_sam(&pwd);
-
+ if ( !(pwd = samu_new( NULL )) ) {
+ return NT_STATUS_NO_MEMORY;
+ }
+
become_root();
ret = pdb_getsampwsid(pwd, &sid);
unbecome_root();
if ( !ret ) {
- pdb_free_sam(&pwd);
+ TALLOC_FREE(pwd);
return NT_STATUS_NO_SUCH_USER;
}
has_enough_rights = nt_token_check_domain_rid( p->pipe_user.nt_user_token, DOMAIN_GROUP_RID_ADMINS );
}
- DEBUG(5, ("_samr_set_userinfo: %s does%s possess sufficient rights\n",
+ DEBUG(5, ("_samr_set_userinfo2: %s does%s possess sufficient rights\n",
p->pipe_user_name, has_enough_rights ? "" : " not"));
/* ================ BEGIN SeMachineAccountPrivilege BLOCK ================ */
r_u->status = NT_STATUS_ACCESS_DENIED;
break;
case 21:
- if (!set_user_info_21(ctr->info.id21, pwd))
- return NT_STATUS_ACCESS_DENIED;
+ r_u->status = set_user_info_21(p->mem_ctx,
+ ctr->info.id21, pwd);
+ break;
+ case 23:
+ if (!p->session_key.length) {
+ r_u->status = NT_STATUS_NO_USER_SESSION_KEY;
+ }
+ SamOEMhashBlob(ctr->info.id23->pass, 516, &p->session_key);
+
+ dump_data(100, (char *)ctr->info.id23->pass, 516);
+
+ r_u->status = set_user_info_23(p->mem_ctx,
+ ctr->info.id23, pwd);
+ break;
+ case 26:
+ if (!p->session_key.length) {
+ r_u->status = NT_STATUS_NO_USER_SESSION_KEY;
+ }
+ encode_or_decode_arc4_passwd_buffer(ctr->info.id26->pass, &p->session_key);
+
+ dump_data(100, (char *)ctr->info.id26->pass, 516);
+
+ if (!set_user_info_pw(ctr->info.id26->pass, pwd))
+ r_u->status = NT_STATUS_ACCESS_DENIED;
break;
default:
r_u->status = NT_STATUS_INVALID_INFO_CLASS;
NTSTATUS ntstatus2;
DOM_SID *members;
- BOOL res;
r_u->status = NT_STATUS_OK;
num_alias_rids = 0;
become_root();
- res = pdb_enum_alias_memberships(p->mem_ctx, &info->sid, members,
- q_u->num_sids1,
- &alias_rids, &num_alias_rids);
+ ntstatus1 = pdb_enum_alias_memberships(p->mem_ctx, &info->sid, members,
+ q_u->num_sids1,
+ &alias_rids, &num_alias_rids);
unbecome_root();
- if (!res)
- return NT_STATUS_UNSUCCESSFUL;
+ if (!NT_STATUS_IS_OK(ntstatus1)) {
+ return ntstatus1;
+ }
init_samr_r_query_useraliases(r_u, num_alias_rids, alias_rids,
NT_STATUS_OK);
NTSTATUS _samr_query_aliasmem(pipes_struct *p, SAMR_Q_QUERY_ALIASMEM *q_u, SAMR_R_QUERY_ALIASMEM *r_u)
{
+ NTSTATUS status;
size_t i;
size_t num_sids = 0;
DOM_SID2 *sid;
DEBUG(10, ("sid is %s\n", sid_string_static(&alias_sid)));
- if (!pdb_enum_aliasmem(&alias_sid, &sids, &num_sids))
- return NT_STATUS_NO_SUCH_ALIAS;
+ status = pdb_enum_aliasmem(&alias_sid, &sids, &num_sids);
+
+ if (!NT_STATUS_IS_OK(status)) {
+ return status;
+ }
sid = TALLOC_ZERO_ARRAY(p->mem_ctx, DOM_SID2, num_sids);
if (num_sids!=0 && sid == NULL) {
return NT_STATUS_OK;
}
-static void add_uid_to_array_unique(uid_t uid, uid_t **uids, int *num)
-{
- int i;
-
- for (i=0; i<*num; i++) {
- if ((*uids)[i] == uid)
- return;
- }
-
- *uids = SMB_REALLOC_ARRAY(*uids, uid_t, *num+1);
-
- if (*uids == NULL)
- return;
-
- (*uids)[*num] = uid;
- *num += 1;
-}
-
-
-static BOOL get_memberuids(gid_t gid, uid_t **uids, int *num)
-{
- struct group *grp;
- char **gr;
- struct sys_pwent *userlist, *user;
-
- *uids = NULL;
- *num = 0;
-
- /* We only look at our own sam, so don't care about imported stuff */
-
- winbind_off();
-
- if ((grp = getgrgid(gid)) == NULL) {
- winbind_on();
- return False;
- }
-
- /* Primary group members */
-
- userlist = getpwent_list();
-
- for (user = userlist; user != NULL; user = user->next) {
- if (user->pw_gid != gid)
- continue;
- add_uid_to_array_unique(user->pw_uid, uids, num);
- }
-
- pwent_free(userlist);
-
- /* Secondary group members */
-
- for (gr = grp->gr_mem; (*gr != NULL) && ((*gr)[0] != '\0'); gr += 1) {
- struct passwd *pw = getpwnam(*gr);
-
- if (pw == NULL)
- continue;
- add_uid_to_array_unique(pw->pw_uid, uids, num);
- }
-
- winbind_on();
-
- return True;
-}
-
/*********************************************************************
_samr_query_groupmem
*********************************************************************/
uint32 acc_granted;
SE_PRIV se_rights;
BOOL can_add_accounts;
- BOOL ret;
+ NTSTATUS ret;
DISP_INFO *disp_info = NULL;
/* Find the policy handle. Open a policy on it. */
/******** END SeAddUsers BLOCK *********/
- if (ret) {
+ if (NT_STATUS_IS_OK(ret)) {
force_flush_samr_cache(disp_info);
}
- return ret ? NT_STATUS_OK : NT_STATUS_ACCESS_DENIED;
+ return ret;
}
/*********************************************************************
uint32 acc_granted;
SE_PRIV se_rights;
BOOL can_add_accounts;
- BOOL ret;
+ NTSTATUS ret;
DISP_INFO *disp_info = NULL;
/* Find the policy handle. Open a policy on it. */
/******** END SeAddUsers BLOCK *********/
- if (ret) {
+ if (NT_STATUS_IS_OK(ret)) {
force_flush_samr_cache(disp_info);
}
- return ret ? NT_STATUS_OK : NT_STATUS_ACCESS_DENIED;
+ return ret;
}
/*********************************************************************
NTSTATUS _samr_add_groupmem(pipes_struct *p, SAMR_Q_ADD_GROUPMEM *q_u, SAMR_R_ADD_GROUPMEM *r_u)
{
DOM_SID group_sid;
- DOM_SID user_sid;
- fstring group_sid_str;
- uid_t uid;
- struct passwd *pwd;
- struct group *grp;
- fstring grp_name;
- GROUP_MAP map;
- NTSTATUS ret;
- SAM_ACCOUNT *sam_user=NULL;
- BOOL check;
+ uint32 group_rid;
uint32 acc_granted;
SE_PRIV se_rights;
BOOL can_add_accounts;
return r_u->status;
}
- sid_to_string(group_sid_str, &group_sid);
- DEBUG(10, ("sid is %s\n", group_sid_str));
-
- if (sid_compare(&group_sid, get_global_sam_sid())<=0)
- return NT_STATUS_NO_SUCH_GROUP;
-
- DEBUG(10, ("lookup on Domain SID\n"));
-
- if(!get_domain_group_from_sid(group_sid, &map))
- return NT_STATUS_NO_SUCH_GROUP;
-
- sid_copy(&user_sid, get_global_sam_sid());
- sid_append_rid(&user_sid, q_u->rid);
-
- ret = pdb_init_sam(&sam_user);
- if (!NT_STATUS_IS_OK(ret))
- return ret;
-
- check = pdb_getsampwsid(sam_user, &user_sid);
-
- if (check != True) {
- pdb_free_sam(&sam_user);
- return NT_STATUS_NO_SUCH_USER;
- }
-
- /* check a real user exist before we run the script to add a user to a group */
- if (!NT_STATUS_IS_OK(sid_to_uid(pdb_get_user_sid(sam_user), &uid))) {
- pdb_free_sam(&sam_user);
- return NT_STATUS_NO_SUCH_USER;
- }
-
- pdb_free_sam(&sam_user);
-
- if ((pwd=getpwuid_alloc(uid)) == NULL) {
- return NT_STATUS_NO_SUCH_USER;
- }
-
- if ((grp=getgrgid(map.gid)) == NULL) {
- passwd_free(&pwd);
- return NT_STATUS_NO_SUCH_GROUP;
- }
+ DEBUG(10, ("sid is %s\n", sid_string_static(&group_sid)));
- /* we need to copy the name otherwise it's overloaded in user_in_unix_group_list */
- fstrcpy(grp_name, grp->gr_name);
-
- /* if the user is already in the group */
- if(user_in_unix_group_list(pwd->pw_name, grp_name)) {
- passwd_free(&pwd);
- return NT_STATUS_MEMBER_IN_GROUP;
+ if (!sid_peek_check_rid(get_global_sam_sid(), &group_sid,
+ &group_rid)) {
+ return NT_STATUS_INVALID_HANDLE;
}
se_priv_copy( &se_rights, &se_add_users );
if ( can_add_accounts )
become_root();
-
- /*
- * ok, the group exist, the user exist, the user is not in the group,
- *
- * we can (finally) add it to the group !
- */
-
- smb_add_user_group(grp_name, pwd->pw_name);
+ r_u->status = pdb_add_groupmem(p->mem_ctx, group_rid, q_u->rid);
+
if ( can_add_accounts )
unbecome_root();
/******** END SeAddUsers BLOCK *********/
- /* check if the user has been added then ... */
- if(!user_in_unix_group_list(pwd->pw_name, grp_name)) {
- passwd_free(&pwd);
- return NT_STATUS_MEMBER_NOT_IN_GROUP; /* don't know what to reply else */
- }
-
- passwd_free(&pwd);
-
force_flush_samr_cache(disp_info);
- return NT_STATUS_OK;
+ return r_u->status;
}
/*********************************************************************
NTSTATUS _samr_del_groupmem(pipes_struct *p, SAMR_Q_DEL_GROUPMEM *q_u, SAMR_R_DEL_GROUPMEM *r_u)
{
DOM_SID group_sid;
- DOM_SID user_sid;
- SAM_ACCOUNT *sam_pass=NULL;
- GROUP_MAP map;
- fstring grp_name;
- struct group *grp;
+ uint32 group_rid;
uint32 acc_granted;
SE_PRIV se_rights;
BOOL can_add_accounts;
if (!NT_STATUS_IS_OK(r_u->status = access_check_samr_function(acc_granted, SA_RIGHT_GROUP_REMOVE_MEMBER, "_samr_del_groupmem"))) {
return r_u->status;
}
-
- if (!sid_check_is_in_our_domain(&group_sid))
- return NT_STATUS_NO_SUCH_GROUP;
-
- sid_copy(&user_sid, get_global_sam_sid());
- sid_append_rid(&user_sid, q_u->rid);
-
- if (!get_domain_group_from_sid(group_sid, &map))
- return NT_STATUS_NO_SUCH_GROUP;
-
- if ((grp=getgrgid(map.gid)) == NULL)
- return NT_STATUS_NO_SUCH_GROUP;
-
- /* we need to copy the name otherwise it's overloaded in user_in_group_list */
- fstrcpy(grp_name, grp->gr_name);
-
- /* check if the user exists before trying to remove it from the group */
- pdb_init_sam(&sam_pass);
- if (!pdb_getsampwsid(sam_pass, &user_sid)) {
- DEBUG(5,("User %s doesn't exist.\n", pdb_get_username(sam_pass)));
- pdb_free_sam(&sam_pass);
- return NT_STATUS_NO_SUCH_USER;
- }
- /* if the user is not in the group */
- if (!user_in_unix_group_list(pdb_get_username(sam_pass), grp_name)) {
- pdb_free_sam(&sam_pass);
- return NT_STATUS_MEMBER_NOT_IN_GROUP;
+ if (!sid_peek_check_rid(get_global_sam_sid(), &group_sid,
+ &group_rid)) {
+ return NT_STATUS_INVALID_HANDLE;
}
-
se_priv_copy( &se_rights, &se_add_users );
can_add_accounts = user_has_privileges( p->pipe_user.nt_user_token, &se_rights );
if ( can_add_accounts )
become_root();
- smb_delete_user_group(grp_name, pdb_get_username(sam_pass));
+ r_u->status = pdb_del_groupmem(p->mem_ctx, group_rid, q_u->rid);
if ( can_add_accounts )
unbecome_root();
/******** END SeAddUsers BLOCK *********/
- /* check if the user has been removed then ... */
- if (user_in_unix_group_list(pdb_get_username(sam_pass), grp_name)) {
- pdb_free_sam(&sam_pass);
- return NT_STATUS_ACCESS_DENIED; /* don't know what to reply else */
- }
-
- pdb_free_sam(&sam_pass);
-
force_flush_samr_cache(disp_info);
- return NT_STATUS_OK;
-
-}
-
-/****************************************************************************
- Delete a UNIX user on demand.
-****************************************************************************/
-
-static int smb_delete_user(const char *unix_user)
-{
- pstring del_script;
- int ret;
-
- pstrcpy(del_script, lp_deluser_script());
- if (! *del_script)
- return -1;
- all_string_sub(del_script, "%u", unix_user, sizeof(del_script));
- ret = smbrun(del_script,NULL);
- flush_pwnam_cache();
- DEBUG(ret ? 0 : 3,("smb_delete_user: Running the command `%s' gave %d\n",del_script,ret));
-
- return ret;
+ return r_u->status;
}
/*********************************************************************
NTSTATUS _samr_delete_dom_user(pipes_struct *p, SAMR_Q_DELETE_DOM_USER *q_u, SAMR_R_DELETE_DOM_USER *r_u )
{
DOM_SID user_sid;
- SAM_ACCOUNT *sam_pass=NULL;
+ struct samu *sam_pass=NULL;
uint32 acc_granted;
BOOL can_add_accounts;
- BOOL ret;
DISP_INFO *disp_info = NULL;
DEBUG(5, ("_samr_delete_dom_user: %d\n", __LINE__));
return NT_STATUS_CANNOT_DELETE;
/* check if the user exists before trying to delete */
- pdb_init_sam(&sam_pass);
+ if ( !(sam_pass = samu_new( NULL )) ) {
+ return NT_STATUS_NO_MEMORY;
+ }
+
if(!pdb_getsampwsid(sam_pass, &user_sid)) {
DEBUG(5,("_samr_delete_dom_user:User %s doesn't exist.\n",
sid_string_static(&user_sid)));
- pdb_free_sam(&sam_pass);
+ TALLOC_FREE(sam_pass);
return NT_STATUS_NO_SUCH_USER;
}
if ( can_add_accounts )
become_root();
- /* First delete the samba side....
- code is order to prevent unnecessary returns out of the admin
- block of code */
-
- if ( (ret = pdb_delete_sam_account(sam_pass)) == True ) {
- /*
- * Now delete the unix side ....
- * note: we don't check if the delete really happened
- * as the script is not necessary present
- * and maybe the sysadmin doesn't want to delete the unix side
- */
- smb_delete_user( pdb_get_username(sam_pass) );
- }
-
+ r_u->status = pdb_delete_user(p->mem_ctx, sam_pass);
+
if ( can_add_accounts )
unbecome_root();
/******** END SeAddUsers BLOCK *********/
- if ( !ret ) {
- DEBUG(5,("_samr_delete_dom_user:Failed to delete entry for user %s.\n", pdb_get_username(sam_pass)));
- pdb_free_sam(&sam_pass);
- return NT_STATUS_CANNOT_DELETE;
+ if ( !NT_STATUS_IS_OK(r_u->status) ) {
+ DEBUG(5,("_samr_delete_dom_user: Failed to delete entry for "
+ "user %s: %s.\n", pdb_get_username(sam_pass),
+ nt_errstr(r_u->status)));
+ TALLOC_FREE(sam_pass);
+ return r_u->status;
}
- pdb_free_sam(&sam_pass);
+ TALLOC_FREE(sam_pass);
if (!close_policy_hnd(p, &q_u->user_pol))
return NT_STATUS_OBJECT_NAME_INVALID;
NTSTATUS _samr_delete_dom_group(pipes_struct *p, SAMR_Q_DELETE_DOM_GROUP *q_u, SAMR_R_DELETE_DOM_GROUP *r_u)
{
DOM_SID group_sid;
- DOM_SID dom_sid;
uint32 group_rid;
- fstring group_sid_str;
- gid_t gid;
- struct group *grp;
- GROUP_MAP map;
uint32 acc_granted;
SE_PRIV se_rights;
BOOL can_add_accounts;
- BOOL ret;
DISP_INFO *disp_info = NULL;
DEBUG(5, ("samr_delete_dom_group: %d\n", __LINE__));
if (!NT_STATUS_IS_OK(r_u->status = access_check_samr_function(acc_granted, STD_RIGHT_DELETE_ACCESS, "_samr_delete_dom_group"))) {
return r_u->status;
}
-
- sid_copy(&dom_sid, &group_sid);
- sid_to_string(group_sid_str, &dom_sid);
- sid_split_rid(&dom_sid, &group_rid);
-
- DEBUG(10, ("sid is %s\n", group_sid_str));
-
- /* we check if it's our SID before deleting */
- if (!sid_equal(&dom_sid, get_global_sam_sid()))
- return NT_STATUS_NO_SUCH_GROUP;
- DEBUG(10, ("lookup on Domain SID\n"));
-
- if(!get_domain_group_from_sid(group_sid, &map))
- return NT_STATUS_NO_SUCH_GROUP;
-
- gid=map.gid;
+ DEBUG(10, ("sid is %s\n", sid_string_static(&group_sid)));
- /* check if group really exists */
- if ( (grp=getgrgid(gid)) == NULL)
+ if (!sid_peek_check_rid(get_global_sam_sid(), &group_sid,
+ &group_rid)) {
return NT_STATUS_NO_SUCH_GROUP;
+ }
se_priv_copy( &se_rights, &se_add_users );
can_add_accounts = user_has_privileges( p->pipe_user.nt_user_token, &se_rights );
if ( can_add_accounts )
become_root();
- /* delete mapping first */
-
- if ( (ret = pdb_delete_group_mapping_entry(group_sid)) == True ) {
- smb_delete_group( grp->gr_name );
- }
+ r_u->status = pdb_delete_dom_group(p->mem_ctx, group_rid);
if ( can_add_accounts )
unbecome_root();
/******** END SeAddUsers BLOCK *********/
- if ( !ret ) {
- DEBUG(5,("_samr_delete_dom_group: Failed to delete mapping entry for group %s.\n",
- group_sid_str));
- return NT_STATUS_ACCESS_DENIED;
+ if ( !NT_STATUS_IS_OK(r_u->status) ) {
+ DEBUG(5,("_samr_delete_dom_group: Failed to delete mapping "
+ "entry for group %s: %s\n",
+ sid_string_static(&group_sid),
+ nt_errstr(r_u->status)));
+ return r_u->status;
}
- /* don't check that the unix group has been deleted. Work like
- _samr_delet_dom_user() */
-
if (!close_policy_hnd(p, &q_u->group_pol))
return NT_STATUS_OBJECT_NAME_INVALID;
{
DOM_SID dom_sid;
DOM_SID info_sid;
- fstring name;
- fstring sid_string;
- struct group *grp;
+ const char *name;
struct samr_info *info;
uint32 acc_granted;
- gid_t gid;
SE_PRIV se_rights;
BOOL can_add_accounts;
- NTSTATUS result;
DISP_INFO *disp_info = NULL;
/* Find the policy handle. Open a policy on it. */
if (!sid_equal(&dom_sid, get_global_sam_sid()))
return NT_STATUS_ACCESS_DENIED;
- unistr2_to_ascii(name, &q_u->uni_acct_desc, sizeof(name)-1);
+ name = rpcstr_pull_unistr2_talloc(p->mem_ctx, &q_u->uni_acct_desc);
+ if (name == NULL) {
+ return NT_STATUS_NO_MEMORY;
+ }
r_u->status = can_create(p->mem_ctx, name);
if (!NT_STATUS_IS_OK(r_u->status)) {
/* check that we successfully create the UNIX group */
- result = NT_STATUS_ACCESS_DENIED;
- if ( (smb_create_group(name, &gid) == 0) && ((grp=getgrgid(gid)) != NULL) ) {
-
- /* so far, so good */
-
- result = NT_STATUS_OK;
-
- r_u->rid = pdb_gid_to_group_rid( grp->gr_gid );
-
- /* add the group to the mapping table */
-
- sid_copy( &info_sid, get_global_sam_sid() );
- sid_append_rid( &info_sid, r_u->rid );
- sid_to_string( sid_string, &info_sid );
-
- /* reset the error code if we fail to add the mapping entry */
-
- if ( !add_initial_entry(grp->gr_gid, sid_string, SID_NAME_DOM_GRP, name, NULL) )
- result = NT_STATUS_ACCESS_DENIED;
- }
+ r_u->status = pdb_create_dom_group(p->mem_ctx, name, &r_u->rid);
if ( can_add_accounts )
unbecome_root();
/* check if we should bail out here */
- if ( !NT_STATUS_IS_OK(result) )
- return result;
+ if ( !NT_STATUS_IS_OK(r_u->status) )
+ return r_u->status;
+
+ sid_compose(&info_sid, get_global_sam_sid(), r_u->rid);
if ((info = get_samr_info_by_sid(&info_sid)) == NULL)
return NT_STATUS_NO_MEMORY;
-
/* they created it; let the user do what he wants with it */
info->acc_granted = GENERIC_RIGHTS_GROUP_ALL_ACCESS;
/******** END SeAddUsers BLOCK *********/
- if (!NT_STATUS_IS_OK(result))
+ if (!NT_STATUS_IS_OK(result)) {
+ DEBUG(10, ("pdb_create_alias failed: %s\n",
+ nt_errstr(result)));
return result;
+ }
sid_copy(&info_sid, get_global_sam_sid());
sid_append_rid(&info_sid, r_u->rid);
- if (!NT_STATUS_IS_OK(sid_to_gid(&info_sid, &gid)))
+ if (!sid_to_gid(&info_sid, &gid)) {
+ DEBUG(10, ("Could not find alias just created\n"));
return NT_STATUS_ACCESS_DENIED;
+ }
/* check if the group has been successfully created */
- if ( getgrgid(gid) == NULL )
+ if ( getgrgid(gid) == NULL ) {
+ DEBUG(10, ("getgrgid(%d) of just created alias failed\n",
+ gid));
return NT_STATUS_ACCESS_DENIED;
+ }
if ((info = get_samr_info_by_sid(&info_sid)) == NULL)
return NT_STATUS_NO_MEMORY;
{
DOM_SID group_sid;
GROUP_MAP map;
- DOM_SID *sids=NULL;
- uid_t *uids;
- int num=0;
GROUP_INFO_CTR *ctr;
uint32 acc_granted;
BOOL ret;
return NT_STATUS_NO_MEMORY;
switch (q_u->switch_level) {
- case 1:
+ case 1: {
+ uint32 *members;
+ size_t num_members;
+
ctr->switch_value1 = 1;
- if(!get_memberuids(map.gid, &uids, &num))
- return NT_STATUS_NO_SUCH_GROUP;
- SAFE_FREE(uids);
- init_samr_group_info1(&ctr->group.info1, map.nt_name, map.comment, num);
- SAFE_FREE(sids);
+
+ become_root();
+ r_u->status = pdb_enum_group_members(
+ p->mem_ctx, &group_sid, &members, &num_members);
+ unbecome_root();
+
+ if (!NT_STATUS_IS_OK(r_u->status)) {
+ return r_u->status;
+ }
+
+ init_samr_group_info1(&ctr->group.info1, map.nt_name,
+ map.comment, num_members);
break;
+ }
case 3:
ctr->switch_value1 = 3;
init_samr_group_info3(&ctr->group.info3);
GROUP_MAP map;
GROUP_INFO_CTR *ctr;
uint32 acc_granted;
- BOOL ret;
+ NTSTATUS ret;
+ BOOL result;
BOOL can_mod_accounts;
DISP_INFO *disp_info = NULL;
if (!NT_STATUS_IS_OK(r_u->status = access_check_samr_function(acc_granted, SA_RIGHT_GROUP_SET_INFO, "_samr_set_groupinfo"))) {
return r_u->status;
}
-
- if (!get_domain_group_from_sid(group_sid, &map))
+
+ become_root();
+ result = get_domain_group_from_sid(group_sid, &map);
+ unbecome_root();
+ if (!result)
return NT_STATUS_NO_SUCH_GROUP;
ctr=q_u->ctr;
/******** End SeAddUsers BLOCK *********/
- if (ret) {
+ if (NT_STATUS_IS_OK(ret)) {
force_flush_samr_cache(disp_info);
}
- return ret ? NT_STATUS_OK : NT_STATUS_ACCESS_DENIED;
+ return ret;
}
/*********************************************************************
{
struct samr_info *info = NULL;
SAM_UNK_CTR *ctr;
- uint32 min_pass_len,pass_hist,flag;
+ uint32 min_pass_len,pass_hist,password_properties;
time_t u_expire, u_min_age;
NTTIME nt_expire, nt_min_age;
pass_hist = account_policy_temp;
pdb_get_account_policy(AP_USER_MUST_LOGON_TO_CHG_PASS, &account_policy_temp);
- flag = account_policy_temp;
+ password_properties = account_policy_temp;
pdb_get_account_policy(AP_MAX_PASSWORD_AGE, &account_policy_temp);
u_expire = account_policy_temp;
unix_to_nt_time_abs(&nt_min_age, u_min_age);
init_unk_info1(&ctr->info.inf1, (uint16)min_pass_len, (uint16)pass_hist,
- flag, nt_expire, nt_min_age);
+ password_properties, nt_expire, nt_min_age);
break;
case 0x02:
become_root();