|
|
b6b438 |
From a2b0dcbb525b7aa3a6f79ca8f8cca4ef7fc2f8f7 Mon Sep 17 00:00:00 2001
|
|
|
b6b438 |
From: Andreas Schneider <asn@samba.org>
|
|
|
b6b438 |
Date: Tue, 16 Jul 2019 15:45:51 +0200
|
|
|
b6b438 |
Subject: [PATCH 060/187] s3:rpcclient: Use a stackframe for temporary memory
|
|
|
b6b438 |
|
|
|
b6b438 |
Signed-off-by: Andreas Schneider <asn@samba.org>
|
|
|
b6b438 |
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
|
|
|
b6b438 |
(cherry picked from commit 9158a6ba8693070f3b2b71dd15089488869ab6cd)
|
|
|
b6b438 |
---
|
|
|
b6b438 |
source3/rpcclient/cmd_samr.c | 56 +++++++++++++++++++++++++-----------
|
|
|
b6b438 |
1 file changed, 39 insertions(+), 17 deletions(-)
|
|
|
b6b438 |
|
|
|
b6b438 |
diff --git a/source3/rpcclient/cmd_samr.c b/source3/rpcclient/cmd_samr.c
|
|
|
b6b438 |
index b1b7c06515c..0cd8b50058e 100644
|
|
|
b6b438 |
--- a/source3/rpcclient/cmd_samr.c
|
|
|
b6b438 |
+++ b/source3/rpcclient/cmd_samr.c
|
|
|
b6b438 |
@@ -3043,6 +3043,7 @@ static NTSTATUS cmd_samr_setuserinfo_int(struct rpc_pipe_client *cli,
|
|
|
b6b438 |
DATA_BLOB session_key;
|
|
|
b6b438 |
uint8_t password_expired = 0;
|
|
|
b6b438 |
struct dcerpc_binding_handle *b = cli->binding_handle;
|
|
|
b6b438 |
+ TALLOC_CTX *frame = NULL;
|
|
|
b6b438 |
|
|
|
b6b438 |
if (argc < 4) {
|
|
|
b6b438 |
printf("Usage: %s username level password [password_expired]\n",
|
|
|
b6b438 |
@@ -3050,6 +3051,8 @@ static NTSTATUS cmd_samr_setuserinfo_int(struct rpc_pipe_client *cli,
|
|
|
b6b438 |
return NT_STATUS_INVALID_PARAMETER;
|
|
|
b6b438 |
}
|
|
|
b6b438 |
|
|
|
b6b438 |
+ frame = talloc_stackframe();
|
|
|
b6b438 |
+
|
|
|
b6b438 |
user = argv[1];
|
|
|
b6b438 |
level = atoi(argv[2]);
|
|
|
b6b438 |
param = argv[3];
|
|
|
b6b438 |
@@ -3058,18 +3061,18 @@ static NTSTATUS cmd_samr_setuserinfo_int(struct rpc_pipe_client *cli,
|
|
|
b6b438 |
password_expired = atoi(argv[4]);
|
|
|
b6b438 |
}
|
|
|
b6b438 |
|
|
|
b6b438 |
- status = cli_get_session_key(mem_ctx, cli, &session_key);
|
|
|
b6b438 |
+ status = cli_get_session_key(frame, cli, &session_key);
|
|
|
b6b438 |
if (!NT_STATUS_IS_OK(status)) {
|
|
|
b6b438 |
- return status;
|
|
|
b6b438 |
+ goto done;
|
|
|
b6b438 |
}
|
|
|
b6b438 |
|
|
|
b6b438 |
status = init_samr_CryptPassword(param, &session_key, &pwd_buf);
|
|
|
b6b438 |
if (!NT_STATUS_IS_OK(status)) {
|
|
|
b6b438 |
- return status;
|
|
|
b6b438 |
+ goto done;
|
|
|
b6b438 |
}
|
|
|
b6b438 |
status = init_samr_CryptPasswordEx(param, &session_key, &pwd_buf_ex);
|
|
|
b6b438 |
if (!NT_STATUS_IS_OK(status)) {
|
|
|
b6b438 |
- return status;
|
|
|
b6b438 |
+ goto done;
|
|
|
b6b438 |
}
|
|
|
b6b438 |
nt_lm_owf_gen(param, nt_hash, lm_hash);
|
|
|
b6b438 |
|
|
|
b6b438 |
@@ -3078,14 +3081,22 @@ static NTSTATUS cmd_samr_setuserinfo_int(struct rpc_pipe_client *cli,
|
|
|
b6b438 |
{
|
|
|
b6b438 |
DATA_BLOB in,out;
|
|
|
b6b438 |
in = data_blob_const(nt_hash, 16);
|
|
|
b6b438 |
- out = data_blob_talloc_zero(mem_ctx, 16);
|
|
|
b6b438 |
+ out = data_blob_talloc_zero(frame, 16);
|
|
|
b6b438 |
+ if (out.data == NULL) {
|
|
|
b6b438 |
+ status = NT_STATUS_NO_MEMORY;
|
|
|
b6b438 |
+ goto done;
|
|
|
b6b438 |
+ }
|
|
|
b6b438 |
sess_crypt_blob(&out, &in, &session_key, true);
|
|
|
b6b438 |
memcpy(nt_hash, out.data, out.length);
|
|
|
b6b438 |
}
|
|
|
b6b438 |
{
|
|
|
b6b438 |
DATA_BLOB in,out;
|
|
|
b6b438 |
in = data_blob_const(lm_hash, 16);
|
|
|
b6b438 |
- out = data_blob_talloc_zero(mem_ctx, 16);
|
|
|
b6b438 |
+ out = data_blob_talloc_zero(frame, 15);
|
|
|
b6b438 |
+ if (out.data == NULL) {
|
|
|
b6b438 |
+ status = NT_STATUS_NO_MEMORY;
|
|
|
b6b438 |
+ goto done;
|
|
|
b6b438 |
+ }
|
|
|
b6b438 |
sess_crypt_blob(&out, &in, &session_key, true);
|
|
|
b6b438 |
memcpy(lm_hash, out.data, out.length);
|
|
|
b6b438 |
}
|
|
|
b6b438 |
@@ -3118,18 +3129,26 @@ static NTSTATUS cmd_samr_setuserinfo_int(struct rpc_pipe_client *cli,
|
|
|
b6b438 |
{
|
|
|
b6b438 |
DATA_BLOB in,out;
|
|
|
b6b438 |
in = data_blob_const(nt_hash, 16);
|
|
|
b6b438 |
- out = data_blob_talloc_zero(mem_ctx, 16);
|
|
|
b6b438 |
+ out = data_blob_talloc_zero(frame, 16);
|
|
|
b6b438 |
+ if (out.data == NULL) {
|
|
|
b6b438 |
+ status = NT_STATUS_NO_MEMORY;
|
|
|
b6b438 |
+ goto done;
|
|
|
b6b438 |
+ }
|
|
|
b6b438 |
sess_crypt_blob(&out, &in, &session_key, true);
|
|
|
b6b438 |
info.info21.nt_owf_password.array =
|
|
|
b6b438 |
- (uint16_t *)talloc_memdup(mem_ctx, out.data, 16);
|
|
|
b6b438 |
+ (uint16_t *)talloc_memdup(frame, out.data, 16);
|
|
|
b6b438 |
}
|
|
|
b6b438 |
{
|
|
|
b6b438 |
DATA_BLOB in,out;
|
|
|
b6b438 |
in = data_blob_const(lm_hash, 16);
|
|
|
b6b438 |
- out = data_blob_talloc_zero(mem_ctx, 16);
|
|
|
b6b438 |
+ out = data_blob_talloc_zero(frame, 16);
|
|
|
b6b438 |
sess_crypt_blob(&out, &in, &session_key, true);
|
|
|
b6b438 |
info.info21.lm_owf_password.array =
|
|
|
b6b438 |
- (uint16_t *)talloc_memdup(mem_ctx, out.data, 16);
|
|
|
b6b438 |
+ (uint16_t *)talloc_memdup(frame, out.data, 16);
|
|
|
b6b438 |
+ if (out.data == NULL) {
|
|
|
b6b438 |
+ status = NT_STATUS_NO_MEMORY;
|
|
|
b6b438 |
+ goto done;
|
|
|
b6b438 |
+ }
|
|
|
b6b438 |
}
|
|
|
b6b438 |
|
|
|
b6b438 |
break;
|
|
|
b6b438 |
@@ -3175,7 +3194,7 @@ static NTSTATUS cmd_samr_setuserinfo_int(struct rpc_pipe_client *cli,
|
|
|
b6b438 |
|
|
|
b6b438 |
/* Get sam policy handle */
|
|
|
b6b438 |
|
|
|
b6b438 |
- status = rpccli_try_samr_connects(cli, mem_ctx,
|
|
|
b6b438 |
+ status = rpccli_try_samr_connects(cli, frame,
|
|
|
b6b438 |
MAXIMUM_ALLOWED_ACCESS,
|
|
|
b6b438 |
&connect_pol);
|
|
|
b6b438 |
if (!NT_STATUS_IS_OK(status)) {
|
|
|
b6b438 |
@@ -3184,7 +3203,7 @@ static NTSTATUS cmd_samr_setuserinfo_int(struct rpc_pipe_client *cli,
|
|
|
b6b438 |
|
|
|
b6b438 |
/* Get domain policy handle */
|
|
|
b6b438 |
|
|
|
b6b438 |
- status = dcerpc_samr_OpenDomain(b, mem_ctx,
|
|
|
b6b438 |
+ status = dcerpc_samr_OpenDomain(b, frame,
|
|
|
b6b438 |
&connect_pol,
|
|
|
b6b438 |
access_mask,
|
|
|
b6b438 |
&domain_sid,
|
|
|
b6b438 |
@@ -3200,7 +3219,7 @@ static NTSTATUS cmd_samr_setuserinfo_int(struct rpc_pipe_client *cli,
|
|
|
b6b438 |
|
|
|
b6b438 |
user_rid = strtol(user, NULL, 0);
|
|
|
b6b438 |
if (user_rid) {
|
|
|
b6b438 |
- status = dcerpc_samr_OpenUser(b, mem_ctx,
|
|
|
b6b438 |
+ status = dcerpc_samr_OpenUser(b, frame,
|
|
|
b6b438 |
&domain_pol,
|
|
|
b6b438 |
access_mask,
|
|
|
b6b438 |
user_rid,
|
|
|
b6b438 |
@@ -3222,7 +3241,7 @@ static NTSTATUS cmd_samr_setuserinfo_int(struct rpc_pipe_client *cli,
|
|
|
b6b438 |
|
|
|
b6b438 |
init_lsa_String(&lsa_acct_name, user);
|
|
|
b6b438 |
|
|
|
b6b438 |
- status = dcerpc_samr_LookupNames(b, mem_ctx,
|
|
|
b6b438 |
+ status = dcerpc_samr_LookupNames(b, frame,
|
|
|
b6b438 |
&domain_pol,
|
|
|
b6b438 |
1,
|
|
|
b6b438 |
&lsa_acct_name,
|
|
|
b6b438 |
@@ -3242,7 +3261,7 @@ static NTSTATUS cmd_samr_setuserinfo_int(struct rpc_pipe_client *cli,
|
|
|
b6b438 |
return NT_STATUS_INVALID_NETWORK_RESPONSE;
|
|
|
b6b438 |
}
|
|
|
b6b438 |
|
|
|
b6b438 |
- status = dcerpc_samr_OpenUser(b, mem_ctx,
|
|
|
b6b438 |
+ status = dcerpc_samr_OpenUser(b, frame,
|
|
|
b6b438 |
&domain_pol,
|
|
|
b6b438 |
access_mask,
|
|
|
b6b438 |
rids.ids[0],
|
|
|
b6b438 |
@@ -3258,14 +3277,14 @@ static NTSTATUS cmd_samr_setuserinfo_int(struct rpc_pipe_client *cli,
|
|
|
b6b438 |
|
|
|
b6b438 |
switch (opcode) {
|
|
|
b6b438 |
case NDR_SAMR_SETUSERINFO:
|
|
|
b6b438 |
- status = dcerpc_samr_SetUserInfo(b, mem_ctx,
|
|
|
b6b438 |
+ status = dcerpc_samr_SetUserInfo(b, frame,
|
|
|
b6b438 |
&user_pol,
|
|
|
b6b438 |
level,
|
|
|
b6b438 |
&info,
|
|
|
b6b438 |
&result);
|
|
|
b6b438 |
break;
|
|
|
b6b438 |
case NDR_SAMR_SETUSERINFO2:
|
|
|
b6b438 |
- status = dcerpc_samr_SetUserInfo2(b, mem_ctx,
|
|
|
b6b438 |
+ status = dcerpc_samr_SetUserInfo2(b, frame,
|
|
|
b6b438 |
&user_pol,
|
|
|
b6b438 |
level,
|
|
|
b6b438 |
&info,
|
|
|
b6b438 |
@@ -3283,7 +3302,10 @@ static NTSTATUS cmd_samr_setuserinfo_int(struct rpc_pipe_client *cli,
|
|
|
b6b438 |
DEBUG(0,("result: %s\n", nt_errstr(status)));
|
|
|
b6b438 |
goto done;
|
|
|
b6b438 |
}
|
|
|
b6b438 |
+
|
|
|
b6b438 |
+ status = NT_STATUS_OK;
|
|
|
b6b438 |
done:
|
|
|
b6b438 |
+ TALLOC_FREE(frame);
|
|
|
b6b438 |
return status;
|
|
|
b6b438 |
}
|
|
|
b6b438 |
|
|
|
b6b438 |
--
|
|
|
b6b438 |
2.23.0
|
|
|
b6b438 |
|