hierynomus / smbj

Server Message Block (SMB2, SMB3) implementation in Java
Other
713 stars 180 forks source link

File and Folder objects `getFilename()` returns null when enabledDFS is enabled on 0.10.1-SNAPSHOT #603

Closed nddipiazza closed 3 years ago

nddipiazza commented 3 years ago

On 0.10.1-SNAPSHOT we are getting a null filename from the Folder and File objects

Please check out this branch:

https://github.com/nddipiazza/smbj/tree/issue_603 / https://github.com/hierynomus/smbj/compare/master...nddipiazza:issue_603

And run it against any windows share:

./gradlew run  --args='-enableDfs -path "" -serverName 192.168.1.51 -share share -username administrator -domain nickis -password YOURPASSWORD'

returns a null for filename result.getFileName() when -enableDFS is enabled, and empty string when -enableDFS is not enabled.

Instead it should have been set to the share smbpath: \\192.168.1.51\share regardless if enableDfs was true or false.

0.10.0 does NOT have this issue.

This bug was introduced here:

https://github.com/hierynomus/smbj/pull/350 / https://github.com/hierynomus/smbj/commit/f6997d3f0105ed6dcc3c06c4259187c5c358d0e5

hierynomus commented 3 years ago

I've tried adding a reproduction testcase in #605, but at least there I do not get a null filename. Can you have a look to see what I'm missing?

nddipiazza commented 3 years ago

Yeah I figured it out. Like I said this bug was introduced here https://github.com/hierynomus/smbj/commit/f6997d3f0105ed6dcc3c06c4259187c5c358d0e5

This used to give you a fileName that was the full UNC path:

https://github.com/hierynomus/smbj/blob/602346cdaa946f8d77e8d033e76d8596c5f8de50/src/main/java/com/hierynomus/smbj/share/DiskEntry.java#L57

How it has been changed to return the relative path:

https://github.com/hierynomus/smbj/blob/f6997d3f0105ed6dcc3c06c4259187c5c358d0e5/src/main/java/com/hierynomus/smbj/share/DiskEntry.java#L46

We should probably go back to UNC path

    public String getFileName() {
        return name.toUncPath();
    }

Then if they want the Path they can use the SmbPath.parse() to get it. Or we can add a convenience method.

hierynomus commented 3 years ago

Thanks for the fix!