libcli:auth: Add decode_pwd_string_from_buffer514()
authorAndreas Schneider <asn@samba.org>
Mon, 23 Aug 2021 13:03:19 +0000 (15:03 +0200)
committerAndreas Schneider <asn@cryptomilk.org>
Thu, 28 Jul 2022 11:51:29 +0000 (11:51 +0000)
Signed-off-by: Andreas Schneider <asn@samba.org>
Reviewed-by: Stefan Metzmacher <metze@samba.org>
libcli/auth/proto.h
libcli/auth/smbencrypt.c

index c787ac2d7125b56fe99e27b41c1afc882ee7fc25..baf57308c9f06a2de54849218c5a9119adb18002 100644 (file)
@@ -221,6 +221,25 @@ bool extract_pwd_blob_from_buffer514(TALLOC_CTX *mem_ctx,
                                     const uint8_t in_buffer[514],
                                     DATA_BLOB *new_password);
 
+/**
+ * @brief Decode AES password buffer to password in the given charset.
+ *
+ * @param mem_ctx       The memory context to allocate the deocded passwrod on.
+ *
+ * @param in_buffer[514] The in buffer with the decrypted password data.
+ *
+ * @param string_charset The charset to decode to.
+ *
+ * @param decoded_password A pointer to store the blob for the decoded password.
+ *                         It ensures that the password is NULL terminated.
+ *
+ * @return true on success, false otherwise.
+ */
+bool decode_pwd_string_from_buffer514(TALLOC_CTX *mem_ctx,
+                                     const uint8_t in_buffer[514],
+                                     charset_t string_charset,
+                                     DATA_BLOB *decoded_password);
+
 /***********************************************************
  Encode an arc4 password change buffer.
 ************************************************************/
index cf141a9891f43bb8e02a358c60dad7767e5f0378..7abf6613d80c82a2d1bb230d04e318e601804070 100644 (file)
@@ -1041,6 +1041,36 @@ bool extract_pwd_blob_from_buffer514(TALLOC_CTX *mem_ctx,
        return true;
 }
 
+bool decode_pwd_string_from_buffer514(TALLOC_CTX *mem_ctx,
+                                     const uint8_t in_buffer[514],
+                                     charset_t string_charset,
+                                     DATA_BLOB *decoded_password)
+{
+       DATA_BLOB new_password = {
+               .length = 0,
+       };
+       bool ok;
+
+       ok = extract_pwd_blob_from_buffer514(mem_ctx, in_buffer, &new_password);
+       if (!ok) {
+               return false;
+       }
+
+       ok = convert_string_talloc(mem_ctx,
+                                  string_charset,
+                                  CH_UNIX,
+                                  new_password.data,
+                                  new_password.length,
+                                  (void *)&decoded_password->data,
+                                  &decoded_password->length);
+       data_blob_free(&new_password);
+       if (!ok) {
+               return false;
+       }
+
+       return true;
+}
+
 /***********************************************************
  Encode an arc4 password change buffer.
 ************************************************************/