1524bc
From 6125794925d054da191cf6c21a76ceb904848710 Mon Sep 17 00:00:00 2001
1524bc
From: Andreas Schneider <asn@samba.org>
1524bc
Date: Wed, 29 May 2019 14:57:52 +0200
1524bc
Subject: [PATCH 010/187] libcli:auth: Return NTSTATUS for
1524bc
 encode_or_decode_arc4_passwd_buffer()
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 57dd415ba49b9621deddf604a5bf148c10ebc37e)
1524bc
---
1524bc
 libcli/auth/proto.h                   |  3 ++-
1524bc
 libcli/auth/smbencrypt.c              | 10 ++++++++--
1524bc
 source3/rpc_server/samr/srv_samr_nt.c | 10 ++++++++--
1524bc
 3 files changed, 18 insertions(+), 5 deletions(-)
1524bc
1524bc
diff --git a/libcli/auth/proto.h b/libcli/auth/proto.h
1524bc
index afd7f0d148d..651f1139cf5 100644
1524bc
--- a/libcli/auth/proto.h
1524bc
+++ b/libcli/auth/proto.h
1524bc
@@ -184,7 +184,8 @@ bool decode_pw_buffer(TALLOC_CTX *ctx,
1524bc
 /***********************************************************
1524bc
  Decode an arc4 encrypted password change buffer.
1524bc
 ************************************************************/
1524bc
-void encode_or_decode_arc4_passwd_buffer(unsigned char pw_buf[532], const DATA_BLOB *psession_key);
1524bc
+NTSTATUS encode_or_decode_arc4_passwd_buffer(unsigned char pw_buf[532],
1524bc
+					     const DATA_BLOB *psession_key);
1524bc
 
1524bc
 /***********************************************************
1524bc
  encode a password buffer with an already unicode password.  The
1524bc
diff --git a/libcli/auth/smbencrypt.c b/libcli/auth/smbencrypt.c
1524bc
index a74ccf09b02..ae97f3cc93e 100644
1524bc
--- a/libcli/auth/smbencrypt.c
1524bc
+++ b/libcli/auth/smbencrypt.c
1524bc
@@ -843,27 +843,32 @@ bool decode_pw_buffer(TALLOC_CTX *ctx,
1524bc
  Decode an arc4 encrypted password change buffer.
1524bc
 ************************************************************/
1524bc
 
1524bc
-void encode_or_decode_arc4_passwd_buffer(unsigned char pw_buf[532], const DATA_BLOB *psession_key)
1524bc
+NTSTATUS encode_or_decode_arc4_passwd_buffer(unsigned char pw_buf[532],
1524bc
+					     const DATA_BLOB *psession_key)
1524bc
 {
1524bc
 	gnutls_hash_hd_t hash_hnd = NULL;
1524bc
 	unsigned char key_out[16];
1524bc
+	NTSTATUS status;
1524bc
 	int rc;
1524bc
 
1524bc
 	/* Confounder is last 16 bytes. */
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, &pw_buf[516], 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, psession_key->data, psession_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
 	}
1524bc
 	gnutls_hash_deinit(hash_hnd, key_out);
1524bc
@@ -873,8 +878,9 @@ void encode_or_decode_arc4_passwd_buffer(unsigned char pw_buf[532], const DATA_B
1524bc
 
1524bc
 	ZERO_ARRAY(key_out);
1524bc
 
1524bc
+	status = NT_STATUS_OK;
1524bc
 out:
1524bc
-	return;
1524bc
+	return status;
1524bc
 }
1524bc
 
1524bc
 /***********************************************************
1524bc
diff --git a/source3/rpc_server/samr/srv_samr_nt.c b/source3/rpc_server/samr/srv_samr_nt.c
1524bc
index 124d6d38cd7..c2be8bfc19a 100644
1524bc
--- a/source3/rpc_server/samr/srv_samr_nt.c
1524bc
+++ b/source3/rpc_server/samr/srv_samr_nt.c
1524bc
@@ -5185,9 +5185,12 @@ NTSTATUS _samr_SetUserInfo(struct pipes_struct *p,
1524bc
 			if(!NT_STATUS_IS_OK(status)) {
1524bc
 				break;
1524bc
 			}
1524bc
-			encode_or_decode_arc4_passwd_buffer(
1524bc
+			status = encode_or_decode_arc4_passwd_buffer(
1524bc
 				info->info25.password.data,
1524bc
 				&session_key);
1524bc
+			if (!NT_STATUS_IS_OK(status)) {
1524bc
+				break;
1524bc
+			}
1524bc
 
1524bc
 			dump_data(100, info->info25.password.data, 532);
1524bc
 
1524bc
@@ -5201,9 +5204,12 @@ NTSTATUS _samr_SetUserInfo(struct pipes_struct *p,
1524bc
 			if(!NT_STATUS_IS_OK(status)) {
1524bc
 				break;
1524bc
 			}
1524bc
-			encode_or_decode_arc4_passwd_buffer(
1524bc
+			status = encode_or_decode_arc4_passwd_buffer(
1524bc
 				info->info26.password.data,
1524bc
 				&session_key);
1524bc
+			if (!NT_STATUS_IS_OK(status)) {
1524bc
+				break;
1524bc
+			}
1524bc
 
1524bc
 			dump_data(100, info->info26.password.data, 516);
1524bc
 
1524bc
-- 
1524bc
2.23.0
1524bc