Class: RubySMB::SMB2::Packet::NegotiateRequest

Inherits:
GenericPacket
  • Object
show all
Defined in:
lib/ruby_smb/smb2/packet/negotiate_request.rb

Overview

An SMB2 NEGOTIATE Request packet as defined by 2.2.3 SMB2 NEGOTIATE Request

Constant Summary collapse

COMMAND =
RubySMB::SMB2::Commands::NEGOTIATE

Instance Method Summary collapse

Methods inherited from GenericPacket

describe, #display, fields_hashed, format_field, from_hex, #initialize_instance, #packet_smb_version, read, #status_code, #valid?, walk_fields

Instance Method Details

#add_dialect(dialect) ⇒ Array<Fixnum>

Adds a dialect to the Dialects array

Parameters:

  • the (Fixnum)

    numeric code for the dialect you wish to add

Returns:

  • (Array<Fixnum>)

    the array of all currently selected dialects

Raises:

  • (ArgumentError)

    if the dialect is not an Integer



34
35
36
37
# 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

#add_negotiate_context(nc) ⇒ Array<Fixnum>

Adds a Negotiate Context to the #negotiate_context_list

Parameters:

Returns:

  • (Array<Fixnum>)

    the array of all currently added Negotiate Contexts

Raises:

  • (ArgumentError)

    if the dialect is not a NegotiateContext structure



58
59
60
61
62
63
64
65
# 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_negotiate_context(type) ⇒ NegotiateContext

Find the first Negotiate Context structure that matches the given context type

not found

Parameters:

  • the (Integer)

    Negotiate Context structure you wish to add

Returns:



73
74
75
# 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

#set_dialects(add_dialects = []) ⇒ Array<Fixnum>

Takes an array of dialects and sets it on the packet. Also updates the dialect_count field appropriately. Will erase any previously set dialects.

Parameters:

  • the (Array<Fixnum>)

    array of dialects to set

Returns:

  • (Array<Fixnum>)

    the current value of the dialects array



45
46
47
48
49
50
51
# 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