TalAloni / SMBLibrary

Free, Open Source, User-Mode SMB 1.0/CIFS, SMB 2.0, SMB 2.1 and SMB 3.0 server and client library
GNU Lesser General Public License v3.0
712 stars 182 forks source link

Failed to get file list State is STATUS_NO_MORE_FILES #68

Closed yika-aixi closed 3 years ago

yika-aixi commented 3 years ago

The example code I refer to: https://github.com/TalAloni/SMBLibrary/blob/master/ClientExamples.md#connect-to-share-and-list-files-and-directories---smb2

System Ver: Windows10

No Enable: SMB 1.0

Shared Folder File Count: 6

image

TalAloni commented 3 years ago

STATUS_NO_MORE_FILES means success - it's not an error.

yika-aixi commented 3 years ago

STATUS_NO_MORE_FILES means success - it's not an error.

Oh, okay, thanks

guyharris commented 11 months ago

STATUS_NO_MORE_FILES means success - it's not an error.

To quote a comment I made elsewhere (an Illumos issue and a Wireshark issue) about this:

Where in [MS-SMB2] is it stated that only Status values with STATUS_SEVERITY_ERROR in the upper 2 bits indicate an error?

In 3.2.5.15 Receiving an SMB2 QUERY_DIRECTORY Response it says:

If the Status field of the SMB2 header of the response indicates an error, the client MUST return the received status code to the calling application.

If the Status field of the SMB2 header of the response indicates success, the client MUST copy the received information in the SMB2 QUERY_DIRECTORY Response following the SMB2 header that is described by the OutputBufferOffset and OutputBufferLength into the buffer that is provided by the calling application. The client MUST return success and the OutputBufferLength to the application.

If the Status field can indicate anything other than an error or success, they don't indicate what to do. Perhaps this is a failure on their part (unfortunately, I can't find a GitHub repository for the open specifications in which to file an issue), rather than "error" and "success" being the only two possibilities. They don't indicate what "error" means - Status != STATUS_SUCCESS, (Status & 0xC0000000) == 0xC0000000, or something else, nor do they indicate what "success" means - Status == STATUS_SUCCESS, (Status & 0xC0000000) != 0xC0000000, or something ese.

3.3.4.4 Sending an Error Response says "An error code other than one of the following indicates a failure:" and lists, after that:

In particular, it does not list STATUS_NO_MORE_FILES or list an SMB2 QUERY_DIRECTORY Response.

First, we do have sample from windows response, with STATUS_NO_MORE_FILES, they only do set StructureSize field (to have mandatory value 9) and the rest is zeroes.

That's insistinguishable from what 2.2.2 SMB2 ERROR Response says is an ERROR response with:

so the response from Windows could well be an ERROR response.

BTW, FindNextFileW() is documented as failing with GetLastError() returning ERROR_NO_MORE_FILES if there are no more files, so the Windows SMB2 kernel client probably hands STATUS_NO_MORE_FILES up to userland in that case.