java.lang.Object
org.codelibs.jcifs.smb.internal.smb2.ServerMessageBlock2
- All Implemented Interfaces:
CommonServerMessageBlock,Message
- Direct Known Subclasses:
ServerMessageBlock2Request,ServerMessageBlock2Response,Smb2CancelRequest
Base class for SMB2/SMB3 protocol messages.
This abstract class provides common functionality for all SMB2/SMB3
message types including encoding, decoding, and message handling.
- Author:
- mbechler
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected static final shortSMB2 cancel commandprotected static final shortSMB2 change notify commandprotected static final shortSMB2 close file commandprotected static final shortSMB2 create/open file commandprotected static final shortSMB2 echo/keepalive commandstatic final intFlag indicating this is an asynchronous command.static final intFlag indicating the operation is a DFS operation.static final intMask for message priority bits.static final intFlag indicating this operation is related to the previous operation in a compound request.static final intFlag indicating this is a replay operation.static final intFlag indicating the message is a response from server to client.static final intFlag indicating the message is signed.protected static final shortSMB2 flush file commandprotected static final shortSMB2 IO control commandprotected static final shortSMB2 lock file commandprotected static final shortSMB2 logoff commandprotected static final shortSMB2 negotiate protocol commandprotected static final shortSMB2 opportunistic lock break notificationprotected static final shortSMB2 query directory commandprotected static final shortSMB2 query info commandprotected static final shortSMB2 read file commandprotected static final shortSMB2 session setup commandprotected static final shortSMB2 set info commandprotected static final shortSMB2 tree connect commandprotected static final shortSMB2 tree disconnect commandprotected static final shortSMB2 write file command -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedServerMessageBlock2(Configuration config) Constructor for SMB2 message block with configuration.protectedServerMessageBlock2(Configuration config, int command) Constructor for SMB2 message block with configuration and command. -
Method Summary
Modifier and TypeMethodDescriptionfinal voidaddFlags(int flag) Adds the specified flags to this message.booleanChains another message to this message for compound operations.final voidclearFlags(int flag) Clears the specified flags from this message.intdecode(byte[] buffer, int bufferIndex) Decode message data from the given byte arrayintdecode(byte[] buffer, int bufferIndex, boolean compound) Decodes the SMB2 message from the buffer.intencode(byte[] dst, int dstIndex) Encodes this message into a byte array.booleanfinal longGets the asynchronous identifier for this message.final intGets the SMB command.protected ConfigurationGets the configuration object for this message.final intGets the credit count for this message.final intGets the credit charge for this message.Gets the signing digest for this message.final byteGets the error context count for this message.final byte[]Gets the error data associated with this message.final intgetFlags()Gets the flags for this message.final intGets the header start position for this message.final intGets the total length of this message.final longgetMid()Gets the message ID.protected ServerMessageBlock2getNext()Gets the next message in the compound chain.final intGets the offset to the next compound command in the message chain.byte[]Gets the raw payload of the message.Gets the response associated with this message.longGets the session identifier for this message.final intGets the status code for this message.final intGets the tree identifier for this message.inthashCode()protected voidhaveResponse(byte[] buffer, int start, int len) Called when a response has been received and decoded.booleanisAsync()Checks whether this message is an asynchronous message.protected booleanChecks if this message has an error status.booleanDetermines whether to retain the message payload.protected final intpad8(int dstIndex) Calculates padding needed to align to 8-byte boundary from header start.protected abstract intreadBytesWireFormat(byte[] buffer, int bufferIndex) Reads the message body from the wire format.protected intreadErrorResponse(byte[] buffer, int bufferIndex) Read error response from bufferprotected intreadHeaderWireFormat(byte[] buffer, int bufferIndex) Reads the SMB2 header from the wire format.voidreset()Resets this message to its initial state.voidIndicate that this message should retain it's raw payloadfinal voidsetAsyncId(long asyncId) Sets the asynchronous identifier for this message.final voidsetCommand(int command) Sets the SMB command.final voidsetCredit(int credit) Sets the credit count for this message.voidsetDigest(SMBSigningDigest digest) Sets the signing digest for this message.voidsetExtendedSecurity(boolean extendedSecurity) Sets whether extended security is enabled.final voidsetMid(long mid) Sets the message ID.protected voidSets the next message in the compound chain.voidsetRawPayload(byte[] rawPayload) Sets the raw payload of the message.voidsetReadSize(int readSize) Sets the read size for this message.voidSets the response for this message.final voidsetSessionId(long sessionId) Sets the session ID.final voidsetTreeId(int treeId) Sets the tree identifier for this message.voidsetUid(int uid) Sets the user ID.protected static final intsize8(int size) Rounds up the size to 8-byte alignment.protected static final intsize8(int size, int align) Rounds up the size to the specified alignment.toString()protected abstract intwriteBytesWireFormat(byte[] dst, int dstIndex) Writes the message body to the wire format.protected intwriteHeaderWireFormat(byte[] dst, int dstIndex) Writes the SMB2 header to the wire format.
-
Field Details
-
SMB2_NEGOTIATE
protected static final short SMB2_NEGOTIATESMB2 negotiate protocol command- See Also:
-
SMB2_SESSION_SETUP
protected static final short SMB2_SESSION_SETUPSMB2 session setup command- See Also:
-
SMB2_LOGOFF
protected static final short SMB2_LOGOFFSMB2 logoff command- See Also:
-
SMB2_TREE_CONNECT
protected static final short SMB2_TREE_CONNECTSMB2 tree connect command- See Also:
-
SMB2_TREE_DISCONNECT
protected static final short SMB2_TREE_DISCONNECTSMB2 tree disconnect command- See Also:
-
SMB2_CREATE
protected static final short SMB2_CREATESMB2 create/open file command- See Also:
-
SMB2_CLOSE
protected static final short SMB2_CLOSESMB2 close file command- See Also:
-
SMB2_FLUSH
protected static final short SMB2_FLUSHSMB2 flush file command- See Also:
-
SMB2_READ
protected static final short SMB2_READSMB2 read file command- See Also:
-
SMB2_WRITE
protected static final short SMB2_WRITESMB2 write file command- See Also:
-
SMB2_LOCK
protected static final short SMB2_LOCKSMB2 lock file command- See Also:
-
SMB2_IOCTL
protected static final short SMB2_IOCTLSMB2 IO control command- See Also:
-
SMB2_CANCEL
protected static final short SMB2_CANCELSMB2 cancel command- See Also:
-
SMB2_ECHO
protected static final short SMB2_ECHOSMB2 echo/keepalive command- See Also:
-
SMB2_QUERY_DIRECTORY
protected static final short SMB2_QUERY_DIRECTORYSMB2 query directory command- See Also:
-
SMB2_CHANGE_NOTIFY
protected static final short SMB2_CHANGE_NOTIFYSMB2 change notify command- See Also:
-
SMB2_QUERY_INFO
protected static final short SMB2_QUERY_INFOSMB2 query info command- See Also:
-
SMB2_SET_INFO
protected static final short SMB2_SET_INFOSMB2 set info command- See Also:
-
SMB2_OPLOCK_BREAK
protected static final short SMB2_OPLOCK_BREAKSMB2 opportunistic lock break notification- See Also:
-
SMB2_FLAGS_SERVER_TO_REDIR
public static final int SMB2_FLAGS_SERVER_TO_REDIRFlag indicating the message is a response from server to client.- See Also:
-
SMB2_FLAGS_ASYNC_COMMAND
public static final int SMB2_FLAGS_ASYNC_COMMANDFlag indicating this is an asynchronous command.- See Also:
-
SMB2_FLAGS_RELATED_OPERATIONS
public static final int SMB2_FLAGS_RELATED_OPERATIONSFlag indicating this operation is related to the previous operation in a compound request.- See Also:
-
SMB2_FLAGS_SIGNED
public static final int SMB2_FLAGS_SIGNEDFlag indicating the message is signed.- See Also:
-
SMB2_FLAGS_PRIORITY_MASK
public static final int SMB2_FLAGS_PRIORITY_MASKMask for message priority bits.- See Also:
-
SMB2_FLAGS_DFS_OPERATIONS
public static final int SMB2_FLAGS_DFS_OPERATIONSFlag indicating the operation is a DFS operation.- See Also:
-
SMB2_FLAGS_REPLAY_OPERATION
public static final int SMB2_FLAGS_REPLAY_OPERATIONFlag indicating this is a replay operation.- See Also:
-
-
Constructor Details
-
ServerMessageBlock2
Constructor for SMB2 message block with configuration.- Parameters:
config- the configuration object
-
ServerMessageBlock2
Constructor for SMB2 message block with configuration and command.- Parameters:
config- the configuration objectcommand- the SMB2 command code
-
-
Method Details
-
getConfig
Gets the configuration object for this message.- Returns:
- the configuration object
-
reset
public void reset()Description copied from interface:CommonServerMessageBlockResets this message to its initial state.- Specified by:
resetin interfaceCommonServerMessageBlock
-
getCommand
public final int getCommand()Description copied from interface:CommonServerMessageBlockGets the SMB command.- Specified by:
getCommandin interfaceCommonServerMessageBlock- Returns:
- the command
-
getNextCommandOffset
public final int getNextCommandOffset()Gets the offset to the next compound command in the message chain.- Returns:
- offset to next compound command
-
setReadSize
public void setReadSize(int readSize) Sets the read size for this message.- Parameters:
readSize- the readSize to set
-
isAsync
public boolean isAsync()Checks whether this message is an asynchronous message.- Returns:
- the async
-
setCommand
public final void setCommand(int command) Description copied from interface:CommonServerMessageBlockSets the SMB command.- Specified by:
setCommandin interfaceCommonServerMessageBlock- Parameters:
command- the command to set
-
getTreeId
public final int getTreeId()Gets the tree identifier for this message.- Returns:
- the treeId
-
setTreeId
public final void setTreeId(int treeId) Sets the tree identifier for this message.- Parameters:
treeId- the treeId to set
-
getAsyncId
public final long getAsyncId()Gets the asynchronous identifier for this message.- Returns:
- the asyncId
-
setAsyncId
public final void setAsyncId(long asyncId) Sets the asynchronous identifier for this message.- Parameters:
asyncId- the asyncId to set
-
getCredit
public final int getCredit()Gets the credit count for this message.- Returns:
- the credit
-
setCredit
public final void setCredit(int credit) Sets the credit count for this message.- Parameters:
credit- the credit to set
-
getCreditCharge
public final int getCreditCharge()Gets the credit charge for this message.- Returns:
- the creditCharge
-
retainPayload
public void retainPayload()Description copied from interface:MessageIndicate that this message should retain it's raw payload- Specified by:
retainPayloadin interfaceMessage
-
isRetainPayload
public boolean isRetainPayload()Description copied from interface:MessageDetermines whether to retain the message payload.- Specified by:
isRetainPayloadin interfaceMessage- Returns:
- whether to retain the message payload
-
getRawPayload
public byte[] getRawPayload()Description copied from interface:MessageGets the raw payload of the message.- Specified by:
getRawPayloadin interfaceMessage- Returns:
- the raw response message
-
setRawPayload
public void setRawPayload(byte[] rawPayload) Description copied from interface:MessageSets the raw payload of the message.- Specified by:
setRawPayloadin interfaceMessage- Parameters:
rawPayload- the raw message payload to set
-
getDigest
Gets the signing digest for this message.- Specified by:
getDigestin interfaceCommonServerMessageBlock- Returns:
- the signing digest
- See Also:
-
setDigest
Sets the signing digest for this message.- Specified by:
setDigestin interfaceCommonServerMessageBlock- Parameters:
digest- the signing digest to set- See Also:
-
getStatus
public final int getStatus()Gets the status code for this message.- Returns:
- the status
-
getSessionId
public long getSessionId()Gets the session identifier for this message.- Returns:
- the sessionId
-
setSessionId
public final void setSessionId(long sessionId) Description copied from interface:CommonServerMessageBlockSets the session ID.- Specified by:
setSessionIdin interfaceCommonServerMessageBlock- Parameters:
sessionId- the sessionId to set
-
setExtendedSecurity
public void setExtendedSecurity(boolean extendedSecurity) Sets whether extended security is enabled.- Specified by:
setExtendedSecurityin interfaceCommonServerMessageBlock- Parameters:
extendedSecurity- true to enable extended security- See Also:
-
setUid
public void setUid(int uid) Sets the user ID.- Specified by:
setUidin interfaceCommonServerMessageBlock- Parameters:
uid- the user ID to set- See Also:
-
getFlags
public final int getFlags()Gets the flags for this message.- Returns:
- the flags
-
addFlags
public final void addFlags(int flag) Adds the specified flags to this message.- Parameters:
flag- the flags to add
-
clearFlags
public final void clearFlags(int flag) Clears the specified flags from this message.- Parameters:
flag- the flags to clear
-
getMid
public final long getMid()Description copied from interface:CommonServerMessageBlockGets the message ID.- Specified by:
getMidin interfaceCommonServerMessageBlock- Returns:
- the mid
-
setMid
public final void setMid(long mid) Description copied from interface:CommonServerMessageBlockSets the message ID.- Specified by:
setMidin interfaceCommonServerMessageBlock- Parameters:
mid- the mid to set
-
chain
Chains another message to this message for compound operations.- Parameters:
n- the message to chain- Returns:
- whether chaining was successful
-
getNext
Gets the next message in the compound chain.- Returns:
- the next message or null if this is the last message
-
setNext
Sets the next message in the compound chain.- Parameters:
n- the next message
-
getResponse
Description copied from interface:CommonServerMessageBlockGets the response associated with this message.- Specified by:
getResponsein interfaceCommonServerMessageBlock- Returns:
- the response
-
setResponse
Sets the response for this message.- Specified by:
setResponsein interfaceCommonServerMessageBlock- Parameters:
msg- the response message to set- See Also:
-
getErrorData
public final byte[] getErrorData()Gets the error data associated with this message.- Returns:
- the errorData
-
getErrorContextCount
public final byte getErrorContextCount()Gets the error context count for this message.- Returns:
- the errorContextCount
-
getHeaderStart
public final int getHeaderStart()Gets the header start position for this message.- Returns:
- the headerStart
-
getLength
public final int getLength()Gets the total length of this message.- Returns:
- the length
-
encode
public int encode(byte[] dst, int dstIndex) Description copied from interface:CommonServerMessageBlockEncodes this message into a byte array.- Specified by:
encodein interfaceCommonServerMessageBlock- Parameters:
dst- the destination byte arraydstIndex- the starting index in the destination array- Returns:
- message length
-
size8
protected static final int size8(int size) Rounds up the size to 8-byte alignment.- Parameters:
size- the size to align- Returns:
- the aligned size
-
size8
protected static final int size8(int size, int align) Rounds up the size to the specified alignment.- Parameters:
size- the size to alignalign- the alignment boundary- Returns:
- the aligned size
-
pad8
protected final int pad8(int dstIndex) Calculates padding needed to align to 8-byte boundary from header start.- Parameters:
dstIndex- the current destination index- Returns:
- number of padding bytes needed
-
decode
Description copied from interface:CommonServerMessageBlockDecode message data from the given byte array- Specified by:
decodein interfaceCommonServerMessageBlock- Parameters:
buffer- the byte array containing the message databufferIndex- the starting index in the buffer- Returns:
- message length
- Throws:
SMBProtocolDecodingException- if decoding fails
-
decode
public int decode(byte[] buffer, int bufferIndex, boolean compound) throws SMBProtocolDecodingException Decodes the SMB2 message from the buffer.- Parameters:
buffer- the buffer containing the messagebufferIndex- the starting position in the buffercompound- whether this is part of a compound chain- Returns:
- decoded length
- Throws:
SMBProtocolDecodingException- if decoding fails
-
isErrorResponseStatus
protected boolean isErrorResponseStatus()Checks if this message has an error status.- Returns:
- true if the message has an error status
-
haveResponse
Called when a response has been received and decoded.- Parameters:
buffer- the buffer containing the responsestart- the starting position in the bufferlen- the length of the response- Throws:
SMBProtocolDecodingException- if processing fails
-
readErrorResponse
Read error response from buffer- Parameters:
buffer- the buffer to read frombufferIndex- the starting index in the buffer- Returns:
- the number of bytes read
- Throws:
SMBProtocolDecodingException- if decoding fails
-
writeHeaderWireFormat
protected int writeHeaderWireFormat(byte[] dst, int dstIndex) Writes the SMB2 header to the wire format.- Parameters:
dst- the destination bufferdstIndex- the starting position in the buffer- Returns:
- number of bytes written
-
readHeaderWireFormat
protected int readHeaderWireFormat(byte[] buffer, int bufferIndex) Reads the SMB2 header from the wire format.- Parameters:
buffer- the buffer to read frombufferIndex- the starting position in the buffer- Returns:
- number of bytes read
-
writeBytesWireFormat
protected abstract int writeBytesWireFormat(byte[] dst, int dstIndex) Writes the message body to the wire format.- Parameters:
dst- the destination bufferdstIndex- the starting position in the buffer- Returns:
- number of bytes written
-
readBytesWireFormat
protected abstract int readBytesWireFormat(byte[] buffer, int bufferIndex) throws SMBProtocolDecodingException Reads the message body from the wire format.- Parameters:
buffer- the buffer to read frombufferIndex- the starting position in the buffer- Returns:
- number of bytes read
- Throws:
SMBProtocolDecodingException- if decoding fails
-
hashCode
public int hashCode() -
equals
-
toString
-