class RubySMB::SMB2::Packet::NegotiateRequest
An SMB2
NEGOTIATE Request packet as defined by [2.2.3 SMB2
NEGOTIATE Request](msdn.microsoft.com/en-us/library/cc246543.aspx)
Constants
- COMMAND
Public Instance Methods
Adds a dialect to the Dialects array
@param [Fixnum] the numeric code for the dialect you wish to add @return [Array<Fixnum>] the array of all currently selected dialects @raise [ArgumentError] if the dialect is not an Integer
# File lib/ruby_smb/smb2/packet/negotiate_request.rb, line 34 def add_dialect(dialect) raise ArgumentError, 'Must be a number' unless dialect.is_a? Integer self.dialects << dialect end
Adds a Negotiate Context to the negotiate_context_list
@param [NegotiateContext] the Negotiate Context structure you wish to add @return [Array<Fixnum>] the array of all currently added Negotiate Contexts @raise [ArgumentError] if the dialect is not a NegotiateContext
structure
# File lib/ruby_smb/smb2/packet/negotiate_request.rb, line 58 def add_negotiate_context(nc) raise ArgumentError, 'Must be a NegotiateContext' unless nc.is_a? NegotiateContext previous_element = negotiate_context_list.last || negotiate_context_list pad_length = pad_length(previous_element) self.negotiate_context_list << nc self.negotiate_context_list.last.pad = "\x00" * pad_length self.negotiate_context_list end
Find the first Negotiate Context structure that matches the given context type
@param [Integer] the Negotiate Context structure you wish to add @return [NegotiateContext] the Negotiate Context structure or nil if not found
# File lib/ruby_smb/smb2/packet/negotiate_request.rb, line 73 def find_negotiate_context(type) negotiate_context_list.find { |nc| nc.context_type == type } end
Takes an array of dialects and sets it on the packet. Also updates the dialect_count field appropriately. Will erase any previously set dialects.
@param [Array<Fixnum>] the array of dialects to set @return [Array<Fixnum>] the current value of the dialects array
# File lib/ruby_smb/smb2/packet/negotiate_request.rb, line 45 def set_dialects(add_dialects = []) self.dialects = [] add_dialects.each do |dialect| add_dialect(dialect) end dialects end
Private Instance Methods
Return true if the dialect version requires Negotiate Contexts
# File lib/ruby_smb/smb2/packet/negotiate_request.rb, line 87 def has_negotiate_context? dialects.any? { |dialect| dialect.to_i == 0x0311 } end
Determines the correct length for the padding, so that the next field is 8-byte aligned.
# File lib/ruby_smb/smb2/packet/negotiate_request.rb, line 81 def pad_length(prev_element) offset = (prev_element.abs_offset + prev_element.to_binary_s.length) % 8 (8 - offset) % 8 end