jborean93 / smbprotocol

Python SMBv2 and v3 Client
MIT License
318 stars 73 forks source link

STATUS_NETWORK_SESSION_EXPIRED not handled #90

Open rob-blackbourn opened 3 years ago

rob-blackbourn commented 3 years ago

I have a long running process. After "a while" it fails to write with the following:

Traceback (most recent call last):
  File "/home/worker/venv/lib/python3.8/site-packages/smbclient/_io.py", line 368, in open
    open_result = self.fd.create(
  File "/home/worker/venv/lib/python3.8/site-packages/smbprotocol/open.py", line 1213, in create
    return self._create_response(request)
  File "/home/worker/venv/lib/python3.8/site-packages/smbprotocol/open.py", line 1219, in _create_response
    response = self.connection.receive(request)
  File "/home/worker/venv/lib/python3.8/site-packages/smbprotocol/connection.py", line 928, in receive
    raise SMBResponseException(response)
smbprotocol.exceptions.SMBResponseException: Received unexpected status from the server: Unknown error. (3221226332) UNKNOWN_ENUM: 0xc000035c

Looking here I can see this corresponds to STATUS_NETWORK_SESSION_EXPIRED.

Is there a way to handle this?

jborean93 commented 3 years ago

Unfortunately this isn't implement yet, the docs for re authenticating an expired session can be found at https://docs.microsoft.com/en-us/openspecs/windows_protocols/ms-smb2/d11845f6-c848-4255-960a-eb8f46f3e703 but a lot of this logic is internal in the session.py file.

You could try to reset your connection after that pause with smbclient.reset_connection_cache() to ensure the subsequent commands are done with a new session.

rob-blackbourn commented 3 years ago

Thanks. I'll give that a try.