1524bc
From c82322be0012f8bf467d75681bd82322eba11145 Mon Sep 17 00:00:00 2001
1524bc
From: Andreas Schneider <asn@samba.org>
1524bc
Date: Tue, 9 Jul 2019 13:01:49 +0200
1524bc
Subject: [PATCH 020/187] s4:libnet: Use encode_rc4_passwd_buffer() in
1524bc
 libnet_SetPassword_samr_handle_26()
1524bc
1524bc
BUG: https://bugzilla.samba.org/show_bug.cgi?id=14031
1524bc
1524bc
Signed-off-by: Andreas Schneider <asn@samba.org>
1524bc
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
1524bc
(cherry picked from commit 5afa402bb7ba11a8eefc6e14047eeec1f3327681)
1524bc
---
1524bc
 source4/libnet/libnet_passwd.c | 47 ++++++++--------------------------
1524bc
 1 file changed, 11 insertions(+), 36 deletions(-)
1524bc
1524bc
diff --git a/source4/libnet/libnet_passwd.c b/source4/libnet/libnet_passwd.c
1524bc
index 97ce7f58ddf..0beea077bd0 100644
1524bc
--- a/source4/libnet/libnet_passwd.c
1524bc
+++ b/source4/libnet/libnet_passwd.c
1524bc
@@ -23,6 +23,7 @@
1524bc
 #include "../lib/crypto/crypto.h"
1524bc
 #include "libcli/auth/libcli_auth.h"
1524bc
 #include "librpc/gen_ndr/ndr_samr_c.h"
1524bc
+#include "source4/librpc/rpc/dcerpc.h"
1524bc
 
1524bc
 #include "lib/crypto/gnutls_helpers.h"
1524bc
 #include <gnutls/gnutls.h>
1524bc
@@ -276,10 +277,6 @@ static NTSTATUS libnet_SetPassword_samr_handle_26(struct libnet_context *ctx, TA
1524bc
 	struct samr_SetUserInfo2 sui;
1524bc
 	union samr_UserInfo u_info;
1524bc
 	DATA_BLOB session_key;
1524bc
-	DATA_BLOB confounded_session_key = data_blob_talloc(mem_ctx, NULL, 16);
1524bc
-	uint8_t confounder[16];	
1524bc
-	gnutls_hash_hd_t hash_hnd = NULL;
1524bc
-	int rc;
1524bc
 
1524bc
 	if (r->samr_handle.in.info21) {
1524bc
 		return NT_STATUS_INVALID_PARAMETER_MIX;
1524bc
@@ -287,9 +284,8 @@ static NTSTATUS libnet_SetPassword_samr_handle_26(struct libnet_context *ctx, TA
1524bc
 
1524bc
 	/* prepare samr_SetUserInfo2 level 26 */
1524bc
 	ZERO_STRUCT(u_info);
1524bc
-	encode_pw_buffer(u_info.info26.password.data, r->samr_handle.in.newpassword, STR_UNICODE);
1524bc
 	u_info.info26.password_expired = 0;
1524bc
-	
1524bc
+
1524bc
 	status = dcerpc_fetch_session_key(r->samr_handle.in.dcerpc_pipe, &session_key);
1524bc
 	if (!NT_STATUS_IS_OK(status)) {
1524bc
 		r->samr_handle.out.error_string = talloc_asprintf(mem_ctx,
1524bc
@@ -297,38 +293,18 @@ static NTSTATUS libnet_SetPassword_samr_handle_26(struct libnet_context *ctx, TA
1524bc
 								  nt_errstr(status));
1524bc
 		return status;
1524bc
 	}
1524bc
-	
1524bc
-	generate_random_buffer((uint8_t *)confounder, 16);
1524bc
-
1524bc
-	rc = gnutls_hash_init(&hash_hnd, GNUTLS_DIG_MD5);
1524bc
-	if (rc < 0) {
1524bc
-		status = gnutls_error_to_ntstatus(rc, NT_STATUS_HASH_NOT_SUPPORTED);
1524bc
-		goto out;
1524bc
-	}
1524bc
 
1524bc
-	rc = gnutls_hash(hash_hnd, confounder, 16);
1524bc
-	if (rc < 0) {
1524bc
-		gnutls_hash_deinit(hash_hnd, NULL);
1524bc
-		status = gnutls_error_to_ntstatus(rc, NT_STATUS_HASH_NOT_SUPPORTED);
1524bc
-		goto out;
1524bc
-	}
1524bc
-	rc = gnutls_hash(hash_hnd, session_key.data, session_key.length);
1524bc
-	if (rc < 0) {
1524bc
-		gnutls_hash_deinit(hash_hnd, NULL);
1524bc
-		status = gnutls_error_to_ntstatus(rc, NT_STATUS_HASH_NOT_SUPPORTED);
1524bc
-		goto out;
1524bc
+	status = encode_rc4_passwd_buffer(r->samr_handle.in.newpassword,
1524bc
+					  &session_key,
1524bc
+					  &u_info.info26.password);
1524bc
+	if (!NT_STATUS_IS_OK(status)) {
1524bc
+		r->samr_handle.out.error_string =
1524bc
+			talloc_asprintf(mem_ctx,
1524bc
+					"encode_rc4_passwd_buffer failed: %s",
1524bc
+					nt_errstr(status));
1524bc
+		return status;
1524bc
 	}
1524bc
 
1524bc
-	gnutls_hash_deinit(hash_hnd, confounded_session_key.data);
1524bc
-
1524bc
-	arcfour_crypt_blob(u_info.info26.password.data, 516, &confounded_session_key);
1524bc
-	ZERO_ARRAY_LEN(confounded_session_key.data,
1524bc
-		       confounded_session_key.length);
1524bc
-	data_blob_free(&confounded_session_key);
1524bc
-
1524bc
-	memcpy(&u_info.info26.password.data[516], confounder, 16);
1524bc
-	ZERO_ARRAY(confounder);
1524bc
-
1524bc
 	sui.in.user_handle = r->samr_handle.in.user_handle;
1524bc
 	sui.in.info = &u_info;
1524bc
 	sui.in.level = 26;
1524bc
@@ -346,7 +322,6 @@ static NTSTATUS libnet_SetPassword_samr_handle_26(struct libnet_context *ctx, TA
1524bc
 					  r->samr_handle.in.account_name, nt_errstr(status));
1524bc
 	}
1524bc
 
1524bc
-out:
1524bc
 	return status;
1524bc
 }
1524bc
 
1524bc
-- 
1524bc
2.23.0
1524bc