]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
libcli:auth: Add encode_pw_buffer_from_str()
authorAndreas Schneider <asn@samba.org>
Thu, 19 Aug 2021 09:29:04 +0000 (11:29 +0200)
committerAndreas Schneider <asn@cryptomilk.org>
Thu, 28 Jul 2022 11:51:28 +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 4d584d07f88b928220fe1bf2fcc8f3c9793f3c67..8a33e3b5c89c7f3f35de35cd2aa09ea1fe1024a2 100644 (file)
@@ -188,6 +188,21 @@ bool decode_pw_buffer(TALLOC_CTX *ctx,
                      size_t *new_pw_len,
                      charset_t string_charset);
 
+/**
+ * @brief Encode an password buffer before we encrypt it.
+ *
+ * @param buffer[514]   The buffer to encode into.
+ *
+ * @param password      The password we want to encode into the buffer.
+ *
+ * @param string_flags  String flags for encoding (e.g. STR_UNICODE).
+ *
+ * @return true on success, false otherwise.
+ */
+bool encode_pwd_buffer514_from_str(uint8_t buffer[514],
+                                  const char *password,
+                                  uint32_t string_flags);
+
 /***********************************************************
  Encode an arc4 password change buffer.
 ************************************************************/
index c89ac243ba4ec7e42e926b8a0cc7b60fe9150dd1..934995c87fa446314b82476a706cfef84809171e 100644 (file)
@@ -27,6 +27,7 @@
 #include "../lib/crypto/crypto.h"
 #include "../libcli/auth/libcli_auth.h"
 #include "../librpc/gen_ndr/ndr_ntlmssp.h"
+#include "lib/util/bytearray.h"
 
 #include "lib/crypto/gnutls_helpers.h"
 #include <gnutls/gnutls.h>
@@ -989,6 +990,31 @@ bool decode_pw_buffer(TALLOC_CTX *ctx,
        return true;
 }
 
+#define MAX_PASSWORD_LEN 256
+
+/*
+ * [MS-SAMR] 2.2.6.32 This creates the buffer to be sent. It is of type
+ * SAMPR_USER_PASSWORD_AES.
+ */
+bool encode_pwd_buffer514_from_str(uint8_t buffer[514],
+                                  const char *password,
+                                  uint32_t string_flags)
+{
+       ssize_t pw_len;
+
+       pw_len = _encode_pwd_buffer_from_str(buffer + 2,
+                                            password,
+                                            string_flags,
+                                            ENCODE_ORDER_PASSWORD_FIRST);
+       if (pw_len < 0) {
+               return false;
+       }
+
+       PUSH_LE_U16(buffer, 0, pw_len);
+
+       return true;
+}
+
 /***********************************************************
  Encode an arc4 password change buffer.
 ************************************************************/