From 4c7bfdefeed88d95ef34dcdf4feeddc2773852f1 Mon Sep 17 00:00:00 2001 From: Jordan Borean Date: Mon, 7 Nov 2022 06:04:42 +1000 Subject: [PATCH] Fix negotiate request context padding When using a negotiate request with a hostname that is a multiple of 8 bytes the code will add 8 extra padding bytes. While this works on some servers others are stricter and can fail the request. This commit fixes up the padding to ensure no padding is used if the length of a context request aligns with the 8 byte boundary it is in. --- CHANGELOG.md | 1 + src/smbprotocol/connection.py | 6 +- tests/test_connection.py | 161 ++++++++++++++++++++++++++++++++++ 3 files changed, 164 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 5b6fc046..a24e44a7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ * Migrated project layout to a `src` based structure rather than including it in the project root * Allow `smbclient.copyfile` to copy files on the same server and not just the same share * Improve DFS opens by setting the DFS operation header flag when opening a file on a share marked as a DFS share +* Fix negotiate request padding when using a hostname with a length of 8 characters ## 1.9.0 - 2022-02-01 diff --git a/src/smbprotocol/connection.py b/src/smbprotocol/connection.py index 3565d4ac..ed9212a9 100644 --- a/src/smbprotocol/connection.py +++ b/src/smbprotocol/connection.py @@ -307,9 +307,7 @@ def _parse_negotiate_context_entry(self, data): data_length = struct.unpack("