libcli/smb: send SMB2_NETNAME_NEGOTIATE_CONTEXT_ID
authorStefan Metzmacher <metze@samba.org>
Thu, 25 Jul 2019 12:38:26 +0000 (14:38 +0200)
committerStefan Metzmacher <metze@samba.org>
Thu, 1 Aug 2019 14:21:36 +0000 (14:21 +0000)
Note: Unlike the current documentation, the utf16 string
is not null-terminated, that matches Windows Server 1903
as a client.

BUG: https://bugzilla.samba.org/show_bug.cgi?id=14055
RN: Add the target server name of SMB 3.1.1 connections
as a hint to load balancers or servers with "multi-tenancy"
support.

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Aurelien Aptel <aaptel@suse.com>
libcli/smb/smbXcli_base.c

index 98c928795eca348827f37272ca1ae337a3196395..0375101b03405f9e2d33a92bac36b9371c6e1021 100644 (file)
@@ -4771,6 +4771,8 @@ static struct tevent_req *smbXcli_negprot_smb2_subreq(struct smbXcli_negprot_sta
        if (state->conn->max_protocol >= PROTOCOL_SMB3_10) {
                NTSTATUS status;
                struct smb2_negotiate_contexts c = { .num_contexts = 0, };
+               uint8_t *netname_utf16 = NULL;
+               size_t netname_utf16_len = 0;
                uint32_t offset;
                DATA_BLOB b;
                uint8_t p[38];
@@ -4803,6 +4805,21 @@ static struct tevent_req *smbXcli_negprot_smb2_subreq(struct smbXcli_negprot_sta
                        return NULL;
                }
 
+               ok = convert_string_talloc(state, CH_UNIX, CH_UTF16,
+                                          state->conn->remote_name,
+                                          strlen(state->conn->remote_name),
+                                          &netname_utf16, &netname_utf16_len);
+               if (!ok) {
+                       return NULL;
+               }
+
+               status = smb2_negotiate_context_add(state, &c,
+                                       SMB2_NETNAME_NEGOTIATE_CONTEXT_ID,
+                                       netname_utf16, netname_utf16_len);
+               if (!NT_STATUS_IS_OK(status)) {
+                       return NULL;
+               }
+
                status = smb2_negotiate_context_push(state, &b, c);
                if (!NT_STATUS_IS_OK(status)) {
                        return NULL;