Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix DFS recurision for missing files #239

Merged
merged 1 commit into from
Sep 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* Fix up pre authenticated session id lookups that were failing with Linux ksmbd
* Removes `logging.NullHandler()` being set in the root `smbprotocol` namespace
* Adds basic support for remote to local and vice versa file operations with `smbclient.shutil.copytree`
* Fixes DFS infinite recursion error when dealing with a file that does not exist on a DFS namespace

## 1.10.1 - 2022-11-14

Expand Down
9 changes: 9 additions & 0 deletions src/smbclient/_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,7 @@
self.raw = raw
self.results = None
self._actions = []
self._attempted_dfs_paths = set()

def __add__(self, other):
send_msg = other[0]
Expand Down Expand Up @@ -306,6 +307,14 @@
if smb_open.tree_connect.share_name == self.raw.fd.tree_connect.share_name:
continue

# Ensure we don't continuously try the same DFS referral targets if it's already been attempted.
# https://github.com/jborean93/smbprotocol/issues/228
tested_path = f"{smb_open.tree_connect.share_name}{smb_open.file_name}".lower()
if tested_path in self._attempted_dfs_paths:
continue

Check warning on line 314 in src/smbclient/_io.py

View check run for this annotation

Codecov / codecov/patch

src/smbclient/_io.py#L314

Added line #L314 was not covered by tests

self._attempted_dfs_paths.add(tested_path)

self.raw.fd = smb_open

# In case this is a transaction with an explicit open we want to reopen it with the new params
Expand Down
7 changes: 7 additions & 0 deletions tests/test_smbclient_os.py
Original file line number Diff line number Diff line change
Expand Up @@ -2131,3 +2131,10 @@ def test_broken_dfs_path(smb_real):
# error and that it doesn't continuously loop.
with pytest.raises(SMBOSError):
smbclient.listdir(dfs_path, username=smb_real[0], password=smb_real[1], port=smb_real[3])


def test_dfs_nonexisting_path(smb_dfs_share):
fake_file = ntpath.join(smb_dfs_share, "missing file.txt")

with pytest.raises(SMBOSError):
smbclient.lstat(fake_file)
Loading