Receiving an SMB_COM_READ_ANDX Request

When a server receives an SMB_COM_READ_ANDX request, message handling proceeds as follows:

The server MUST verify that the FID represents a valid Server.Open (has an entry in the SMB connection's Server.Connection.FileOpenTable). If the FID is not valid, the server MUST return an error response with a status of STATUS_INVALID_HANDLE (ERRDOS/ERRbadfid).

The server MUST verify that the user represented by the UID in the request has permission to read from the file as described in section If the user does not have sufficient permissions, the server MUST send an error response with a status of STATUS_ACCESS_DENIED (ERRDOS/ERRnoaccess) and MUST increase Server.Statistics.sts0_permerrors by 1. If the UID that is presented is different from the UID that opened the file, the server MUST send the error response with a Status of STATUS_INVALID_HANDLE (ERRDOS/ERRbaduid).

The server MUST attempt to read from the underlying object store for the Server.Open identified by the FID in the request. The server MUST start reading at the offset indicated by either the 32-bit offset in Offset or the 64-bit offset formed by combining OffsetHigh and Offset. If WordCount is 10 (0x0A), the client is using 32-bit offsets; if it is 12 (0x0C), the client is using 64-bit offsets.

The server MUST attempt to read MaxCountOfBytesToReturn number of bytes from the file.<299>

The server might read fewer than MaxCountOfBytesToReturn bytes if an end of file (EOF) event is encountered. A read request starting at or beyond the end of the file returns zero bytes.

If reading the requested number of bytes would lead to a response message size larger than the established Server.Connection.ClientMaxBufferSize and Server.Connection.ClientCapabilities does not have CAP_LARGE_READX set, the server MUST abort the connection to the client. If Server.Connection.ClientCapabilities has CAP_LARGE_READX set, the response message can exceed the negotiated buffer size if the FID refers to a disk file.

If the read request was made to a named pipe or I/O device, the following additional rules apply:

  • The server MUST NOT read a number of bytes from named pipes or I/O devices greater than can be transmitted in a message less than or equal to Server.Connection.ClientMaxBufferSize in size, even if CAP_LARGE_READX was negotiated.

  • The server MUST wait to send a response until MinCountOfBytesToReturn are read from the named pipe or I/O device.

  • If Timeout is greater than zero, the server SHOULD<300> wait to send the response until either MinCountOfBytesToReturn are read or the Timeout (in milliseconds) elapses. If Timeout is greater than zero and it elapses before MinCountOfBytesToReturn bytes are read, the server SHOULD send a response with an error status indicating that the time-out occurred and SHOULD also respond with any bytes already read. If Timeout is zero and no data is currently available, the server SHOULD send a successful response with the DataLength field set to zero.

  • If the Timeout value is -1 (0xFFFFFFFF, "wait forever") then the server MUST wait until there are at least MinCountOfBytesToReturn bytes of data read from the device before returning a response to the client.

  • If the Timeout value is -2 (0xFFFFFFFE, "default") the server MUST wait for the default time-out associated with the named pipe or I/O device.

If the operation is successful, the server MUST construct an SMB_COM_READ_ANDX Response (section message with the following additional requirements:

  • If the request was to a named pipe, Available MUST be set to the number of bytes remaining to be read from the named pipe, which can be zero. Otherwise, the server MUST set the Available field to -1(0xFFFF).

  • The DataLength field MUST be set to the length, in bytes, of the data read by the server.

  • The DataOffset field MUST be set to the offset, in bytes and relative to the start of the SMB Header (section, of the data read by the server.

  • The Pad field MUST pad the SMB_Data.Data field to an appropriate boundary.

  • The Data field MUST contain the data that was read from the requested file.

If the request is to read from a named pipe in message mode, and the message is larger than MaxCountOfBytesToReturn bytes, the server MUST respond with a complete SMB_COM_READ_ANDX response (not an error response) and the Status field of the response MUST contain STATUS_BUFFER_OVERFLOW (ERRDOS/ERRmoredata). Any other error MUST generate an error response message.

The response MUST be sent to the client as described in section