static NTSTATUS get_user_info_5(TALLOC_CTX *mem_ctx,
struct samr_UserInfo5 *r,
- DOM_SID *user_sid,
+ struct samu *pw,
DOM_SID *domain_sid)
{
- struct samu *pw = NULL;
- bool ret;
const DOM_SID *sid_user, *sid_group;
uint32_t rid, primary_gid;
NTTIME last_logon, last_logoff, last_password_change,
ZERO_STRUCTP(r);
- if (!(pw = samu_new(mem_ctx))) {
- return NT_STATUS_NO_MEMORY;
- }
-
- become_root();
- ret = pdb_getsampwsid(pw, user_sid);
- unbecome_root();
-
- if (ret == False) {
- DEBUG(4,("User %s not found\n", sid_string_dbg(user_sid)));
- TALLOC_FREE(pw);
- return NT_STATUS_NO_SUCH_USER;
- }
-
- samr_clear_sam_passwd(pw);
-
- DEBUG(3,("User:[%s]\n", pdb_get_username(pw)));
-
sid_user = pdb_get_user_sid(pw);
if (!sid_peek_check_rid(domain_sid, sid_user, &rid)) {
"the domain sid %s. Failing operation.\n",
pdb_get_username(pw), sid_string_dbg(sid_user),
sid_string_dbg(domain_sid)));
- TALLOC_FREE(pw);
return NT_STATUS_UNSUCCESSFUL;
}
"which conflicts with the domain sid %s. Failing operation.\n",
pdb_get_username(pw), sid_string_dbg(sid_group),
sid_string_dbg(domain_sid)));
- TALLOC_FREE(pw);
return NT_STATUS_UNSUCCESSFUL;
}
acct_expiry,
pdb_get_acct_ctrl(pw));
- TALLOC_FREE(pw);
-
return NT_STATUS_OK;
}
static NTSTATUS get_user_info_7(TALLOC_CTX *mem_ctx,
struct samr_UserInfo7 *r,
- DOM_SID *user_sid)
+ struct samu *smbpass)
{
- struct samu *smbpass=NULL;
- bool ret;
const char *account_name = NULL;
ZERO_STRUCTP(r);
- if ( !(smbpass = samu_new( mem_ctx )) ) {
- return NT_STATUS_NO_MEMORY;
- }
-
- become_root();
- ret = pdb_getsampwsid(smbpass, user_sid);
- unbecome_root();
-
- if ( !ret ) {
- DEBUG(4,("User %s not found\n", sid_string_dbg(user_sid)));
- return NT_STATUS_NO_SUCH_USER;
- }
-
account_name = talloc_strdup(mem_ctx, pdb_get_username(smbpass));
if (!account_name) {
- TALLOC_FREE(smbpass);
return NT_STATUS_NO_MEMORY;
}
- TALLOC_FREE(smbpass);
-
- DEBUG(3,("User:[%s]\n", account_name));
init_samr_user_info7(r, account_name);
static NTSTATUS get_user_info_9(TALLOC_CTX *mem_ctx,
struct samr_UserInfo9 *r,
- DOM_SID *user_sid)
+ struct samu *smbpass)
{
- struct samu *smbpass=NULL;
- bool ret;
-
ZERO_STRUCTP(r);
- if ( !(smbpass = samu_new( mem_ctx )) ) {
- return NT_STATUS_NO_MEMORY;
- }
-
- become_root();
- ret = pdb_getsampwsid(smbpass, user_sid);
- unbecome_root();
-
- if (ret==False) {
- DEBUG(4,("User %s not found\n", sid_string_dbg(user_sid)));
- TALLOC_FREE(smbpass);
- return NT_STATUS_NO_SUCH_USER;
- }
-
- DEBUG(3,("User:[%s]\n", pdb_get_username(smbpass) ));
-
init_samr_user_info9(r, pdb_get_group_rid(smbpass));
- TALLOC_FREE(smbpass);
-
return NT_STATUS_OK;
}
static NTSTATUS get_user_info_16(TALLOC_CTX *mem_ctx,
struct samr_UserInfo16 *r,
- DOM_SID *user_sid)
+ struct samu *smbpass)
{
- struct samu *smbpass=NULL;
- bool ret;
-
ZERO_STRUCTP(r);
- if ( !(smbpass = samu_new( mem_ctx )) ) {
- return NT_STATUS_NO_MEMORY;
- }
-
- become_root();
- ret = pdb_getsampwsid(smbpass, user_sid);
- unbecome_root();
-
- if (ret==False) {
- DEBUG(4,("User %s not found\n", sid_string_dbg(user_sid)));
- TALLOC_FREE(smbpass);
- return NT_STATUS_NO_SUCH_USER;
- }
-
- DEBUG(3,("User:[%s]\n", pdb_get_username(smbpass) ));
-
init_samr_user_info16(r, pdb_get_acct_ctrl(smbpass));
- TALLOC_FREE(smbpass);
-
return NT_STATUS_OK;
}
return NT_STATUS_ACCOUNT_DISABLED;
}
- init_samr_user_info18(r, pdb_get_lanman_passwd(smbpass),
- pdb_get_nt_passwd(smbpass));
+ init_samr_user_info18(r,
+ pdb_get_lanman_passwd(smbpass),
+ pdb_get_nt_passwd(smbpass),
+ 0 /* FIXME */);
TALLOC_FREE(smbpass);
static NTSTATUS get_user_info_20(TALLOC_CTX *mem_ctx,
struct samr_UserInfo20 *r,
- DOM_SID *user_sid)
+ struct samu *sampass)
{
- struct samu *sampass=NULL;
- bool ret;
const char *munged_dial = NULL;
DATA_BLOB blob;
NTSTATUS status;
ZERO_STRUCTP(r);
- if ( !(sampass = samu_new( mem_ctx )) ) {
- return NT_STATUS_NO_MEMORY;
- }
-
- become_root();
- ret = pdb_getsampwsid(sampass, user_sid);
- unbecome_root();
-
- if (ret == False) {
- DEBUG(4,("User %s not found\n", sid_string_dbg(user_sid)));
- TALLOC_FREE(sampass);
- return NT_STATUS_NO_SUCH_USER;
- }
-
munged_dial = pdb_get_munged_dial(sampass);
- samr_clear_sam_passwd(sampass);
-
DEBUG(3,("User:[%s] has [%s] (length: %d)\n", pdb_get_username(sampass),
munged_dial, (int)strlen(munged_dial)));
status = init_samr_parameters_string(mem_ctx, &blob, ¶meters);
data_blob_free(&blob);
- TALLOC_FREE(sampass);
if (!NT_STATUS_IS_OK(status)) {
return status;
}
static NTSTATUS get_user_info_21(TALLOC_CTX *mem_ctx,
struct samr_UserInfo21 *r,
- DOM_SID *user_sid,
+ struct samu *pw,
DOM_SID *domain_sid)
{
NTSTATUS status;
- struct samu *pw = NULL;
- bool ret;
const DOM_SID *sid_user, *sid_group;
uint32_t rid, primary_gid;
NTTIME last_logon, last_logoff, last_password_change,
ZERO_STRUCTP(r);
- if (!(pw = samu_new(mem_ctx))) {
- return NT_STATUS_NO_MEMORY;
- }
-
- become_root();
- ret = pdb_getsampwsid(pw, user_sid);
- unbecome_root();
-
- if (ret == False) {
- DEBUG(4,("User %s not found\n", sid_string_dbg(user_sid)));
- TALLOC_FREE(pw);
- return NT_STATUS_NO_SUCH_USER;
- }
-
- samr_clear_sam_passwd(pw);
-
- DEBUG(3,("User:[%s]\n", pdb_get_username(pw)));
-
sid_user = pdb_get_user_sid(pw);
if (!sid_peek_check_rid(domain_sid, sid_user, &rid)) {
"the domain sid %s. Failing operation.\n",
pdb_get_username(pw), sid_string_dbg(sid_user),
sid_string_dbg(domain_sid)));
- TALLOC_FREE(pw);
return NT_STATUS_UNSUCCESSFUL;
}
"which conflicts with the domain sid %s. Failing operation.\n",
pdb_get_username(pw), sid_string_dbg(sid_group),
sid_string_dbg(domain_sid)));
- TALLOC_FREE(pw);
return NT_STATUS_UNSUCCESSFUL;
}
status = init_samr_parameters_string(mem_ctx, &blob, ¶meters);
data_blob_free(&blob);
if (!NT_STATUS_IS_OK(status)) {
- TALLOC_FREE(pw);
return status;
}
pdb_get_logon_count(pw),
0, /* country_code */
0, /* code_page */
- 0, /* nt_password_set */
0, /* lm_password_set */
+ 0, /* nt_password_set */
password_expired);
- TALLOC_FREE(pw);
return NT_STATUS_OK;
}
struct samr_info *info = NULL;
DOM_SID domain_sid;
uint32 rid;
+ bool ret = false;
+ struct samu *pwd = NULL;
/* search for the handle */
if (!find_policy_by_hnd(p, r->in.user_handle, (void **)(void *)&info))
DEBUG(5,("_samr_QueryUserInfo: user info level: %d\n", r->in.level));
+ if (!(pwd = samu_new(p->mem_ctx))) {
+ return NT_STATUS_NO_MEMORY;
+ }
+
+ become_root();
+ ret = pdb_getsampwsid(pwd, &info->sid);
+ unbecome_root();
+
+ if (ret == false) {
+ DEBUG(4,("User %s not found\n", sid_string_dbg(&info->sid)));
+ TALLOC_FREE(pwd);
+ return NT_STATUS_NO_SUCH_USER;
+ }
+
+ DEBUG(3,("User:[%s]\n", pdb_get_username(pwd)));
+
+ samr_clear_sam_passwd(pwd);
+
switch (r->in.level) {
case 5:
- status = get_user_info_5(p->mem_ctx, &user_info->info5, &info->sid, &domain_sid);
- if (!NT_STATUS_IS_OK(status)) {
- return status;
- }
+ status = get_user_info_5(p->mem_ctx, &user_info->info5, pwd, &domain_sid);
break;
case 7:
- status = get_user_info_7(p->mem_ctx, &user_info->info7, &info->sid);
- if (!NT_STATUS_IS_OK(status)) {
- return status;
- }
+ status = get_user_info_7(p->mem_ctx, &user_info->info7, pwd);
break;
case 9:
- status = get_user_info_9(p->mem_ctx, &user_info->info9, &info->sid);
- if (!NT_STATUS_IS_OK(status)) {
- return status;
- }
+ status = get_user_info_9(p->mem_ctx, &user_info->info9, pwd);
break;
case 16:
- status = get_user_info_16(p->mem_ctx, &user_info->info16, &info->sid);
- if (!NT_STATUS_IS_OK(status)) {
- return status;
- }
+ status = get_user_info_16(p->mem_ctx, &user_info->info16, pwd);
break;
-
case 18:
+ /* level 18 is special */
status = get_user_info_18(p, p->mem_ctx, &user_info->info18, &info->sid);
- if (!NT_STATUS_IS_OK(status)) {
- return status;
- }
break;
-
case 20:
- status = get_user_info_20(p->mem_ctx, &user_info->info20, &info->sid);
- if (!NT_STATUS_IS_OK(status)) {
- return status;
- }
+ status = get_user_info_20(p->mem_ctx, &user_info->info20, pwd);
break;
-
case 21:
- status = get_user_info_21(p->mem_ctx, &user_info->info21,
- &info->sid, &domain_sid);
- if (!NT_STATUS_IS_OK(status)) {
- return status;
- }
+ status = get_user_info_21(p->mem_ctx, &user_info->info21, pwd, &domain_sid);
break;
-
default:
- return NT_STATUS_INVALID_INFO_CLASS;
+ status = NT_STATUS_INVALID_INFO_CLASS;
+ break;
}
+ TALLOC_FREE(pwd);
+
*r->out.info = user_info;
DEBUG(5,("_samr_QueryUserInfo: %d\n", __LINE__));
set_user_info_18
********************************************************************/
-static bool set_user_info_18(struct samr_UserInfo18 *id18,
- struct samu *pwd)
+static NTSTATUS set_user_info_18(struct samr_UserInfo18 *id18,
+ TALLOC_CTX *mem_ctx,
+ DATA_BLOB *session_key,
+ struct samu *pwd)
{
if (id18 == NULL) {
DEBUG(2, ("set_user_info_18: id18 is NULL\n"));
- return False;
+ return NT_STATUS_INVALID_PARAMETER;
}
- if (!pdb_set_lanman_passwd (pwd, id18->lm_pwd.hash, PDB_CHANGED)) {
- return False;
+ if (id18->nt_pwd_active || id18->lm_pwd_active) {
+ if (!session_key->length) {
+ return NT_STATUS_NO_USER_SESSION_KEY;
+ }
}
- if (!pdb_set_nt_passwd (pwd, id18->nt_pwd.hash, PDB_CHANGED)) {
- return False;
+
+ if (id18->nt_pwd_active) {
+
+ DATA_BLOB in, out;
+
+ in = data_blob_const(id18->nt_pwd.hash, 16);
+ out = data_blob_talloc_zero(mem_ctx, 16);
+
+ sess_crypt_blob(&out, &in, session_key, false);
+
+ if (!pdb_set_nt_passwd(pwd, out.data, PDB_CHANGED)) {
+ return NT_STATUS_ACCESS_DENIED;
+ }
}
- if (!pdb_set_pass_last_set_time (pwd, time(NULL), PDB_CHANGED)) {
- return False;
+
+ if (id18->lm_pwd_active) {
+
+ DATA_BLOB in, out;
+
+ in = data_blob_const(id18->lm_pwd.hash, 16);
+ out = data_blob_talloc_zero(mem_ctx, 16);
+
+ sess_crypt_blob(&out, &in, session_key, false);
+
+ if (!pdb_set_lanman_passwd(pwd, out.data, PDB_CHANGED)) {
+ return NT_STATUS_ACCESS_DENIED;
+ }
}
- if(!NT_STATUS_IS_OK(pdb_update_sam_account(pwd))) {
- return False;
- }
+ if (id18->password_expired) {
+ pdb_set_pass_last_set_time(pwd, 0, PDB_CHANGED);
+ } else {
+ /* FIXME */
+ pdb_set_pass_last_set_time(pwd, time(NULL), PDB_CHANGED);
+ }
- return True;
+ return pdb_update_sam_account(pwd);
}
/*******************************************************************
{
char *plaintext_buf = NULL;
uint32 len = 0;
- uint16 acct_ctrl;
+ uint32_t acct_ctrl;
NTSTATUS status;
if (id23 == NULL) {
return NT_STATUS_ACCESS_DENIED;
}
+ if ((id23->info.fields_present & SAMR_FIELD_NT_PASSWORD_PRESENT) ||
+ (id23->info.fields_present & SAMR_FIELD_LM_PASSWORD_PRESENT)) {
- DEBUG(5, ("Attempting administrator password change (level 23) for user %s\n",
- pdb_get_username(pwd)));
-
- acct_ctrl = pdb_get_acct_ctrl(pwd);
+ DEBUG(5, ("Attempting administrator password change (level 23) for user %s\n",
+ pdb_get_username(pwd)));
- if (!decode_pw_buffer(mem_ctx,
- id23->password.data,
- &plaintext_buf,
- &len,
- STR_UNICODE)) {
- return NT_STATUS_WRONG_PASSWORD;
- }
+ if (!decode_pw_buffer(mem_ctx,
+ id23->password.data,
+ &plaintext_buf,
+ &len,
+ STR_UNICODE)) {
+ return NT_STATUS_WRONG_PASSWORD;
+ }
- if (!pdb_set_plaintext_passwd (pwd, plaintext_buf)) {
- return NT_STATUS_ACCESS_DENIED;
+ if (!pdb_set_plaintext_passwd (pwd, plaintext_buf)) {
+ return NT_STATUS_ACCESS_DENIED;
+ }
}
copy_id23_to_sam_passwd(pwd, id23);
+ acct_ctrl = pdb_get_acct_ctrl(pwd);
+
/* if it's a trust account, don't update /etc/passwd */
if ( ( (acct_ctrl & ACB_DOMTRUST) == ACB_DOMTRUST ) ||
( (acct_ctrl & ACB_WSTRUST) == ACB_WSTRUST) ||
( (acct_ctrl & ACB_SVRTRUST) == ACB_SVRTRUST) ) {
DEBUG(5, ("Changing trust account. Not updating /etc/passwd\n"));
- } else {
+ } else if (plaintext_buf) {
/* update the UNIX password */
if (lp_unix_password_sync() ) {
struct passwd *passwd;
}
}
- memset(plaintext_buf, '\0', strlen(plaintext_buf));
+ if (plaintext_buf) {
+ memset(plaintext_buf, '\0', strlen(plaintext_buf));
+ }
if (IS_SAM_CHANGED(pwd, PDB_GROUPSID) &&
(!NT_STATUS_IS_OK(status = pdb_set_unix_primary_group(mem_ctx,
case 18:
/* Used by AS/U JRA. */
- if (!set_user_info_18(&info->info18, pwd)) {
- status = NT_STATUS_ACCESS_DENIED;
- }
+ status = set_user_info_18(&info->info18,
+ p->mem_ctx,
+ &p->server_info->user_session_key,
+ pwd);
break;
case 20: