miketeo/pysmb

Can't get file list on DFS shared folder

alisichkin opened this issue · 6 comments

Hello!

Can't get file list on Cisco VPN (Cisco Any Connect 4.10) - for directory level more than two.
When I try to get file list using function listPath - I get an error: Failed to list ILI_APPL_WRITE on DFS: Unable to open directory

from smb.SMBConnection import SMBConnection

conn = SMBConnection(username="xxx", password="xxx", my_name="localMachine", remote_name="ClusterCO2DFS", domain="GKSM", use_ntlm_v2=True, sign_options=SMBConnection.SIGN_WHEN_SUPPORTED)
connected = conn.connect("172.16.4.160", 139)

if connected:
    try:
        files = conn.listPath("DFS", "/ILI_APPL_WRITE")
        for file in files:
            if not file.isDirectory:
                print(f"{file.filename}")
    finally:
        conn.close()

When I try to execute command <files = conn.listPath("DFS", "/")> - command runs successfully.
When I try to connect and get file list from remote computer without VPN - everything runs without error.

I get same error from Windows 7 (Python 3.8.8), Windows 10 (Python 3.10) and Debian 10 (Python 3.7.3)

Sincerely,
Alexander.

Exception has occurred: OperationFailure
Failed to list ILI_APPL_WRITE on DFS: Unable to open directory
==================== SMB Message 0 ====================
SMB Header:

Command: 0x03 (SMB2_COM_TREE_CONNECT)
Status: 0x00000000
Flags: 0x08
PID: 8304
MID: 3
TID: 0
Data: 46 bytes
b'09000000480026005c005c0043004c005500530054004500520043004f0032004400460053005c00440046005300'
SMB Data Packet (hex):

b'fe534d4240000000000000000300000008000000000000000300000000000000702000000000000081060038a60600002d523c15a94b0eeef45044b7765e298d09000000480026005c005c0043004c005500530054004500520043004f0032004400460053005c00440046005300'
==================== SMB Message 1 ====================
SMB Header:

Command: 0x03 (SMB2_COM_TREE_CONNECT)
Status: 0x00000000
Flags: 0x09
PID: 8304
MID: 3
TID: 1
Data: 16 bytes
b'100001003008000008000000a9001200'
SMB Data Packet (hex):

b'fe534d4240000000000000000300010009000000000000000300000000000000702000000100000081060038a6060000e70eb777cc9563e875389a47eb085117100001003008000008000000a9001200'
==================== SMB Message 2 ====================
SMB Header:

Command: 0x05 (SMB2_COM_CREATE)
Status: 0x00000000
Flags: 0x08
PID: 8304
MID: 4
TID: 1
Data: 176 bytes
b'390000000200000000000000000000000000000000000000890010000000000007000000010000000100000078001c00980000005800000049004c0049005f004100500050004c005f0057005200490054004500000000002800000010000400000018001000000044486e510000000000000000000000000000000000000000180000001000040000001800000000004d78416300000000000000001000040000001800000000005146696400000000'
SMB Data Packet (hex):

b'fe534d4240000000000000000500000008000000000000000400000000000000702000000100000081060038a6060000f467e58c1ad8e7ee100cd869dcbb6313390000000200000000000000000000000000000000000000890010000000000007000000010000000100000078001c00980000005800000049004c0049005f004100500050004c005f0057005200490054004500000000002800000010000400000018001000000044486e510000000000000000000000000000000000000000180000001000040000001800000000004d78416300000000000000001000040000001800000000005146696400000000'
==================== SMB Message 3 ====================
SMB Header:

Command: 0x05 (SMB2_COM_CREATE)
Status: 0xC0000257
Flags: 0x09
PID: 8304
MID: 4
TID: 1
Data: 9 bytes
b'090000000000000000'
SMB Data Packet (hex):

b'fe534d4240000000570200c00500010009000000000000000400000000000000702000000100000081060038a6060000e50d2463457b4890aff226484af85e34090000000000000000'
File "C:\Source\Python\amtSMB.py", line 13, in
files = conn.listPath("DFS", "/ILI_APPL_WRITE")

@alisichkin Part of the path is mounted on DFS which is not supported by pysmb. Unfortunately, I don't have the time to work on DFS support due to my time commitments in work and family.

That is, the error is related to DFS - Distributed File System, not VPN, as I assumed ?
P.S.
Family is a sacred

Without knowing how the VPN is being configured, I can't really say for sure.
But you are right to have doubts over it since your script is working when it does not communicate over the VPN.
Does the file transfer work if you try to access using Windows explorer over the VPN?

Unfortunately - I did not test the DFS share in the office. I'm working remotely - so I tested pysmb by connected between my computer and my laptop. I tried to use another python library - smbprotocol - which, as author said, support DFS. But get an error - STATUS_PATH_NOT_COVERED - it indicates that the portion of the DFS namespace accessed by the client is not contained in the DFS root target server.
P.S.

import smbclient

smbclient.register_session(server='ClusterCO2DFS', username='xxxxx', password='xxxx', auth_protocol='ntlm')
dir = smbclient.listdir(r"\\ClusterCO2DFS\DFS") #work
dir = smbclient.listdir(r"\\ClusterCO2DFS\DFS\<one more>") #error - NtStatus error returned 'STATUS_PATH_NOT_COVERED'
print(f"{dir}")

P.S.S.
I found many references to DFS in the pysmb library code - support_dfs/SMB_FLAGS2_DFS, etc.
Version 1.1.14, 2015-02-01 (Download)
Add support for DFS shares in listPath(). Thanks to humberry (github) for raising the issue and helping with the testing.

Perhaps just need to specify some parameter - what share is DFS ?

The error is related to DFS. I used another library - smbprotocol - its supports working with DFS.
I did my work using smbprotocol.

@alisichkin Hi. Could you tell please how you fixed the problem with the DFS in smbprotocol, cause I also get STATUS_PATH_NOT_COVERED error. Maybe some code snippet?