hierynomus / smbj

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

Exception is null when calling getDiskShare().list(smbDirectoryPath) on a DFS folder #697

Closed vjorge closed 2 years ago

vjorge commented 2 years ago

Hi, I have a SMB server that has on the root share normal directories and other DFS based shares, when performing a directory list the error is thrown:

Cannot invoke "java.util.Set.contains(Object)" because the return value of "com.hierynomus.mssmb2.messages.SMB2CreateResponse.getFileAttributes()" is null

Debugging the code I could find that if fails on the following function:

    protected DiskEntry getDiskEntry(SMB2CreateResponseContext responseContext) {
        SMB2CreateResponse response = responseContext.resp;

            if (response.getFileAttributes().contains(FILE_ATTRIBUTE_DIRECTORY)) {
                return new Directory(response.getFileId(), responseContext.share, responseContext.target);
            } else {
                return new File(response.getFileId(), responseContext.share, responseContext.target);
            }
    }

When the response.getFileAttributes() is evaluated it throws an exception because the value of getFileAttributes() is null as well as any other folder related information, the SMB2CreateResponseContext Header contains:

dialect=null, creditCharge=1, creditRequest=0, creditResponse=33, message=SMB2_CREATE, messageId=62, asyncId=0, sessionId=1381004522554057, treeId=1, status=0xc0000257, flags=9, nextCommandOffset=0

I have tested with a DFS folder with and without permissions, with same error, is there a way to avoid code termination and detected that no permissions exist and create the Directory object anyway?

If I set the DFS folder as a part of the share path it works fine, but if is on the same level then it fails on getDiskShare().getFileInformation(DFSsharepath);

Many thanks.

Martin0815123 commented 2 years ago

Hi,

i got the same error,

I use SmbConfig config = SmbConfig.builder().... and add the following code now: .withDialects(SMB2Dialect.SMB_2_1, SMB2Dialect.SMB_2_0_2, SMB2Dialect.SMB_3_0)

SMB_2_1, SMB_2_0_2 is the default in version 0.10.0 ! SMB_3_1_1, SMB_3_0_2, SMB_3_0, SMB_2_1, SMB_2_0_2 is the default in version 0.11.3 !

So the problem in my case is the "SMB_3_1_1", I don't have a real explanation for this. Maybe it helps you.

P.S. smbj 0.10.0 works without this change, I need the change for 0.11.3

best regards Martin

bangert commented 2 years ago

@vjorge @Martin0815123 could you check the latest 0.11.5 release, which i believe has DFS related fixes.

Martin0815123 commented 2 years ago

Hi bangert,

you are right, with 0.11.5 the null pointer has disappeared (in my case)!

best regards Martin

hierynomus commented 2 years ago

Closing this issue, thanks for the ping. @vjorge If this persists, feel free to reopen.

andershermansen commented 2 years ago

I'm getting this error with 0.11.5 connecting to a DFS share. I tried with .withDialects(SMB2Dialect.SMB_2_1, SMB2Dialect.SMB_2_0_2) but it does not fix the issue for me.