CloudSoda / go-smb2

Client implementation of the SMB 2 & 3 protocols
BSD 2-Clause "Simplified" License
12 stars 5 forks source link

Share pathname should use hostname when available in TREE_CONNECT requests #18

Closed arashpayan closed 9 months ago

arashpayan commented 10 months ago

When performing a TREE_CONNECT request servers sometimes vary their response based on the server component of the share path (e.g. \\server\share). The library just passes the resolved IP address from the net.Conn that was passed to it, but that causes problems for users. In particular, missing shares and incorrect file listings. Some public examples of this problem:

https://github.com/hirochachacha/go-smb2/issues/40 https://github.com/rclone/rclone/issues/6672 and possibly this: https://github.com/rclone/rclone/issues/6515

We need to include the server hostname in the share path sent with the TREE_CONNECT request to avoid these problems.

Per consultation with @ncw (https://github.com/rclone/rclone/issues/6672#issuecomment-1823260480), we'll still allow the user to provide their own net.Conn if they like.

arashpayan commented 10 months ago

Relevant part of the SMB2 spec https://learn.microsoft.com/en-us/openspecs/windows_protocols/ms-smb2/832d2130-22e8-4afb-aafd-b30bb0901798:

The full share pathname is Unicode in the form "\server\share" for the request. The server component of the path MUST be less than 256 characters in length, and it MUST be a NetBIOS name, a fully qualified domain name (FQDN), or a textual IPv4 or IPv6 address. The share component of the path MUST be less than or equal to 80 characters in length. The share name MUST NOT contain any invalid characters, as specified in [MS-FSCC] section [2.1.6]

arashpayan commented 9 months ago

Fixed with commit f3ec8ae2c891ee40aab4d251873aab5db51f7cf8.