ruby_smb 1.0.3 → 1.0.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (108) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +0 -0
  3. data.tar.gz.sig +0 -0
  4. data/lib/ruby_smb/client.rb +26 -4
  5. data/lib/ruby_smb/client/authentication.rb +43 -25
  6. data/lib/ruby_smb/client/echo.rb +20 -2
  7. data/lib/ruby_smb/client/negotiation.rb +27 -12
  8. data/lib/ruby_smb/client/tree_connect.rb +20 -14
  9. data/lib/ruby_smb/error.rb +40 -1
  10. data/lib/ruby_smb/generic_packet.rb +33 -4
  11. data/lib/ruby_smb/smb1/dcerpc.rb +7 -2
  12. data/lib/ruby_smb/smb1/file.rb +60 -11
  13. data/lib/ruby_smb/smb1/packet/close_request.rb +2 -5
  14. data/lib/ruby_smb/smb1/packet/close_response.rb +2 -1
  15. data/lib/ruby_smb/smb1/packet/echo_request.rb +2 -4
  16. data/lib/ruby_smb/smb1/packet/echo_response.rb +2 -1
  17. data/lib/ruby_smb/smb1/packet/empty_packet.rb +7 -0
  18. data/lib/ruby_smb/smb1/packet/logoff_request.rb +2 -4
  19. data/lib/ruby_smb/smb1/packet/logoff_response.rb +2 -1
  20. data/lib/ruby_smb/smb1/packet/negotiate_request.rb +2 -5
  21. data/lib/ruby_smb/smb1/packet/negotiate_response.rb +3 -7
  22. data/lib/ruby_smb/smb1/packet/negotiate_response_extended.rb +4 -4
  23. data/lib/ruby_smb/smb1/packet/nt_create_andx_request.rb +2 -4
  24. data/lib/ruby_smb/smb1/packet/nt_create_andx_response.rb +2 -1
  25. data/lib/ruby_smb/smb1/packet/nt_trans/create_request.rb +2 -1
  26. data/lib/ruby_smb/smb1/packet/nt_trans/create_response.rb +2 -1
  27. data/lib/ruby_smb/smb1/packet/nt_trans/request.rb +2 -4
  28. data/lib/ruby_smb/smb1/packet/nt_trans/response.rb +2 -1
  29. data/lib/ruby_smb/smb1/packet/read_andx_request.rb +2 -5
  30. data/lib/ruby_smb/smb1/packet/read_andx_response.rb +2 -1
  31. data/lib/ruby_smb/smb1/packet/session_setup_legacy_request.rb +2 -1
  32. data/lib/ruby_smb/smb1/packet/session_setup_legacy_response.rb +2 -1
  33. data/lib/ruby_smb/smb1/packet/session_setup_request.rb +2 -5
  34. data/lib/ruby_smb/smb1/packet/session_setup_response.rb +2 -1
  35. data/lib/ruby_smb/smb1/packet/trans/peek_nmpipe_request.rb +0 -1
  36. data/lib/ruby_smb/smb1/packet/trans/peek_nmpipe_response.rb +3 -2
  37. data/lib/ruby_smb/smb1/packet/trans/request.rb +2 -5
  38. data/lib/ruby_smb/smb1/packet/trans/response.rb +2 -1
  39. data/lib/ruby_smb/smb1/packet/trans/transact_nmpipe_request.rb +1 -1
  40. data/lib/ruby_smb/smb1/packet/trans/transact_nmpipe_response.rb +1 -1
  41. data/lib/ruby_smb/smb1/packet/trans2/find_first2_request.rb +2 -1
  42. data/lib/ruby_smb/smb1/packet/trans2/find_first2_response.rb +8 -2
  43. data/lib/ruby_smb/smb1/packet/trans2/find_next2_request.rb +2 -1
  44. data/lib/ruby_smb/smb1/packet/trans2/find_next2_response.rb +8 -2
  45. data/lib/ruby_smb/smb1/packet/trans2/open2_request.rb +2 -1
  46. data/lib/ruby_smb/smb1/packet/trans2/open2_response.rb +2 -1
  47. data/lib/ruby_smb/smb1/packet/trans2/request.rb +2 -4
  48. data/lib/ruby_smb/smb1/packet/trans2/request_secondary.rb +2 -4
  49. data/lib/ruby_smb/smb1/packet/trans2/response.rb +2 -1
  50. data/lib/ruby_smb/smb1/packet/trans2/set_file_information_request.rb +2 -1
  51. data/lib/ruby_smb/smb1/packet/trans2/set_file_information_response.rb +2 -1
  52. data/lib/ruby_smb/smb1/packet/tree_connect_request.rb +2 -4
  53. data/lib/ruby_smb/smb1/packet/tree_connect_response.rb +13 -3
  54. data/lib/ruby_smb/smb1/packet/tree_disconnect_request.rb +2 -4
  55. data/lib/ruby_smb/smb1/packet/tree_disconnect_response.rb +2 -1
  56. data/lib/ruby_smb/smb1/packet/write_andx_request.rb +2 -5
  57. data/lib/ruby_smb/smb1/packet/write_andx_response.rb +2 -1
  58. data/lib/ruby_smb/smb1/pipe.rb +8 -3
  59. data/lib/ruby_smb/smb1/tree.rb +40 -2
  60. data/lib/ruby_smb/smb2/dcerpc.rb +7 -2
  61. data/lib/ruby_smb/smb2/file.rb +97 -1
  62. data/lib/ruby_smb/smb2/packet/close_request.rb +2 -4
  63. data/lib/ruby_smb/smb2/packet/close_response.rb +2 -1
  64. data/lib/ruby_smb/smb2/packet/create_request.rb +2 -4
  65. data/lib/ruby_smb/smb2/packet/create_response.rb +2 -1
  66. data/lib/ruby_smb/smb2/packet/echo_request.rb +2 -4
  67. data/lib/ruby_smb/smb2/packet/echo_response.rb +2 -1
  68. data/lib/ruby_smb/smb2/packet/error_packet.rb +7 -0
  69. data/lib/ruby_smb/smb2/packet/ioctl_request.rb +2 -5
  70. data/lib/ruby_smb/smb2/packet/ioctl_response.rb +2 -1
  71. data/lib/ruby_smb/smb2/packet/logoff_request.rb +2 -4
  72. data/lib/ruby_smb/smb2/packet/logoff_response.rb +2 -1
  73. data/lib/ruby_smb/smb2/packet/negotiate_request.rb +2 -5
  74. data/lib/ruby_smb/smb2/packet/negotiate_response.rb +2 -1
  75. data/lib/ruby_smb/smb2/packet/query_directory_request.rb +2 -4
  76. data/lib/ruby_smb/smb2/packet/query_directory_response.rb +8 -2
  77. data/lib/ruby_smb/smb2/packet/read_request.rb +2 -4
  78. data/lib/ruby_smb/smb2/packet/read_response.rb +2 -1
  79. data/lib/ruby_smb/smb2/packet/session_setup_request.rb +2 -5
  80. data/lib/ruby_smb/smb2/packet/session_setup_response.rb +2 -1
  81. data/lib/ruby_smb/smb2/packet/set_info_request.rb +2 -4
  82. data/lib/ruby_smb/smb2/packet/set_info_response.rb +2 -1
  83. data/lib/ruby_smb/smb2/packet/tree_connect_request.rb +2 -5
  84. data/lib/ruby_smb/smb2/packet/tree_connect_response.rb +8 -2
  85. data/lib/ruby_smb/smb2/packet/tree_disconnect_request.rb +2 -4
  86. data/lib/ruby_smb/smb2/packet/tree_disconnect_response.rb +2 -1
  87. data/lib/ruby_smb/smb2/packet/write_request.rb +2 -4
  88. data/lib/ruby_smb/smb2/packet/write_response.rb +2 -1
  89. data/lib/ruby_smb/smb2/pipe.rb +9 -9
  90. data/lib/ruby_smb/smb2/tree.rb +44 -6
  91. data/lib/ruby_smb/version.rb +1 -1
  92. data/spec/lib/ruby_smb/client_spec.rb +123 -11
  93. data/spec/lib/ruby_smb/generic_packet_spec.rb +52 -4
  94. data/spec/lib/ruby_smb/smb1/file_spec.rb +182 -1
  95. data/spec/lib/ruby_smb/smb1/packet/{error_packet_spec.rb → empty_packet_spec.rb} +21 -0
  96. data/spec/lib/ruby_smb/smb1/packet/trans2/find_first2_response_spec.rb +11 -2
  97. data/spec/lib/ruby_smb/smb1/packet/trans2/find_next2_response_spec.rb +11 -2
  98. data/spec/lib/ruby_smb/smb1/packet/tree_connect_response_spec.rb +40 -0
  99. data/spec/lib/ruby_smb/smb1/pipe_spec.rb +63 -2
  100. data/spec/lib/ruby_smb/smb1/tree_spec.rb +44 -7
  101. data/spec/lib/ruby_smb/smb2/file_spec.rb +295 -2
  102. data/spec/lib/ruby_smb/smb2/packet/error_packet_spec.rb +51 -0
  103. data/spec/lib/ruby_smb/smb2/packet/query_directory_response_spec.rb +8 -0
  104. data/spec/lib/ruby_smb/smb2/packet/tree_connect_response_spec.rb +8 -0
  105. data/spec/lib/ruby_smb/smb2/pipe_spec.rb +69 -3
  106. data/spec/lib/ruby_smb/smb2/tree_spec.rb +214 -0
  107. metadata +6 -4
  108. metadata.gz.sig +0 -0
@@ -4,6 +4,8 @@ module RubySMB
4
4
  # An SMB2 Close Response Packet as defined in
5
5
  # [2.2.16 SMB2 CLOSE Response](https://msdn.microsoft.com/en-us/library/cc246524.aspx)
6
6
  class CloseResponse < RubySMB::GenericPacket
7
+ COMMAND = RubySMB::SMB2::Commands::CLOSE
8
+
7
9
  endian :little
8
10
 
9
11
  smb2_header :smb2_header
@@ -20,7 +22,6 @@ module RubySMB
20
22
 
21
23
  def initialize_instance
22
24
  super
23
- smb2_header.command = RubySMB::SMB2::Commands::CLOSE
24
25
  smb2_header.flags.reply = 1
25
26
  end
26
27
  end
@@ -4,6 +4,8 @@ module RubySMB
4
4
  # An SMB2 Create Request Packet as defined in
5
5
  # [2.2.13 SMB2 CREATE Request](https://msdn.microsoft.com/en-us/library/cc246502.aspx)
6
6
  class CreateRequest < RubySMB::GenericPacket
7
+ COMMAND = RubySMB::SMB2::Commands::CREATE
8
+
7
9
  require 'ruby_smb/smb1/bit_field/create_options'
8
10
 
9
11
  endian :little
@@ -44,10 +46,6 @@ module RubySMB
44
46
 
45
47
  array :context, label: 'Contexts', type: :create_context, read_until: :eof
46
48
 
47
- def initialize_instance
48
- super
49
- smb2_header.command = RubySMB::SMB2::Commands::CREATE
50
- end
51
49
  end
52
50
  end
53
51
  end
@@ -4,6 +4,8 @@ module RubySMB
4
4
  # An SMB2 Create Response Packet as defined in
5
5
  # [2.2.14 SMB2 CREATE Response](https://msdn.microsoft.com/en-us/library/cc246512.aspx)
6
6
  class CreateResponse < RubySMB::GenericPacket
7
+ COMMAND = RubySMB::SMB2::Commands::CREATE
8
+
7
9
  endian :little
8
10
  smb2_header :smb2_header
9
11
  uint16 :structure_size, label: 'Structure Size', initial_value: 89
@@ -26,7 +28,6 @@ module RubySMB
26
28
 
27
29
  def initialize_instance
28
30
  super
29
- smb2_header.command = RubySMB::SMB2::Commands::CREATE
30
31
  smb2_header.flags.reply = 1
31
32
  end
32
33
  end
@@ -4,15 +4,13 @@ module RubySMB
4
4
  # An SMB2 Echo Request Packet as defined in
5
5
  # [2.2.28 SMB2 ECHO Request](https://msdn.microsoft.com/en-us/library/cc246540.aspx)
6
6
  class EchoRequest < RubySMB::GenericPacket
7
+ COMMAND = RubySMB::SMB2::Commands::ECHO
8
+
7
9
  endian :little
8
10
  smb2_header :smb2_header
9
11
  uint16 :structure_size, label: 'Structure Size', initial_value: 4
10
12
  uint16 :reserved
11
13
 
12
- def initialize_instance
13
- super
14
- smb2_header.command = RubySMB::SMB2::Commands::ECHO
15
- end
16
14
  end
17
15
  end
18
16
  end
@@ -4,6 +4,8 @@ module RubySMB
4
4
  # An SMB2 Echo response Packet as defined in
5
5
  # [2.2.29 SMB2 ECHO Response](https://msdn.microsoft.com/en-us/library/cc246541.aspx)
6
6
  class EchoResponse < RubySMB::GenericPacket
7
+ COMMAND = RubySMB::SMB2::Commands::ECHO
8
+
7
9
  endian :little
8
10
  smb2_header :smb2_header
9
11
  uint16 :structure_size, label: 'Structure Size', initial_value: 4
@@ -11,7 +13,6 @@ module RubySMB
11
13
 
12
14
  def initialize_instance
13
15
  super
14
- smb2_header.command = RubySMB::SMB2::Commands::ECHO
15
16
  smb2_header.flags.reply = 1
16
17
  end
17
18
  end
@@ -3,10 +3,17 @@ module RubySMB
3
3
  module Packet
4
4
  # An SMB2 Error packet for when an incomplete response comes back
5
5
  class ErrorPacket < RubySMB::GenericPacket
6
+ attr_accessor :original_command
7
+
6
8
  endian :little
7
9
  smb2_header :smb2_header
8
10
  uint16 :structure_size, label: 'Structure Size', initial_value: 4
9
11
  uint8 :error_data
12
+
13
+ def valid?
14
+ return smb2_header.protocol == RubySMB::SMB2::SMB2_PROTOCOL_ID &&
15
+ smb2_header.command == @original_command
16
+ end
10
17
  end
11
18
  end
12
19
  end
@@ -4,6 +4,8 @@ module RubySMB
4
4
  # An SMB2 Ioctl Request Packet as defined in
5
5
  # [2.2.31 SMB2 IOCTL Request](https://msdn.microsoft.com/en-us/library/cc246545.aspx)
6
6
  class IoctlRequest < RubySMB::GenericPacket
7
+ COMMAND = RubySMB::SMB2::Commands::IOCTL
8
+
7
9
  endian :little
8
10
 
9
11
  smb2_header :smb2_header
@@ -30,11 +32,6 @@ module RubySMB
30
32
  uint32 :reserved2, label: 'Reserved Space'
31
33
  string :buffer, label: 'Input Buffer', read_length: -> { input_count + output_count }
32
34
 
33
- def initialize_instance
34
- super
35
- smb2_header.command = RubySMB::SMB2::Commands::IOCTL
36
- end
37
-
38
35
  # Calculates the value for the input_offset field.
39
36
  # If the input buffer is empty then this should be set to 0,
40
37
  # otherwise it should return the absolute offset of the input buffer.
@@ -4,6 +4,8 @@ module RubySMB
4
4
  # An SMB2 Ioctl Response Packet as defined in
5
5
  # [2.2.32 SMB2 IOCTL Response](https://msdn.microsoft.com/en-us/library/cc246548.aspx)
6
6
  class IoctlResponse < RubySMB::GenericPacket
7
+ COMMAND = RubySMB::SMB2::Commands::IOCTL
8
+
7
9
  endian :little
8
10
 
9
11
  smb2_header :smb2_header
@@ -22,7 +24,6 @@ module RubySMB
22
24
  def initialize_instance
23
25
  super
24
26
  smb2_header.flags.reply = 1
25
- smb2_header.command = RubySMB::SMB2::Commands::IOCTL
26
27
  end
27
28
 
28
29
  def input_data
@@ -4,15 +4,13 @@ module RubySMB
4
4
  # An SMB2 LOGOFF Request Packet as defined in
5
5
  # [2.2.7 SMB2 LOGOFF Request](https://msdn.microsoft.com/en-us/library/cc246565.aspx)
6
6
  class LogoffRequest < RubySMB::GenericPacket
7
+ COMMAND = RubySMB::SMB2::Commands::LOGOFF
8
+
7
9
  endian :little
8
10
  smb2_header :smb2_header
9
11
  uint16 :structure_size, label: 'Structure Size', initial_value: 4
10
12
  uint16 :reserved, label: 'Reserved Space'
11
13
 
12
- def initialize_instance
13
- super
14
- smb2_header.command = RubySMB::SMB2::Commands::LOGOFF
15
- end
16
14
  end
17
15
  end
18
16
  end
@@ -4,6 +4,8 @@ module RubySMB
4
4
  # An SMB2 LOGOFF Response Packet as defined in
5
5
  # [2.2.8 SMB2 LOGOFF Response](https://msdn.microsoft.com/en-us/library/cc246566.aspx)
6
6
  class LogoffResponse < RubySMB::GenericPacket
7
+ COMMAND = RubySMB::SMB2::Commands::LOGOFF
8
+
7
9
  endian :little
8
10
  smb2_header :smb2_header
9
11
  uint16 :structure_size, label: 'Structure Size', initial_value: 4
@@ -11,7 +13,6 @@ module RubySMB
11
13
 
12
14
  def initialize_instance
13
15
  super
14
- smb2_header.command = RubySMB::SMB2::Commands::LOGOFF
15
16
  smb2_header.flags.reply = 1
16
17
  end
17
18
  end
@@ -4,6 +4,8 @@ module RubySMB
4
4
  # An SMB2 NEGOTIATE Request packet as defined by
5
5
  # [2.2.3 SMB2 NEGOTIATE Request](https://msdn.microsoft.com/en-us/library/cc246543.aspx)
6
6
  class NegotiateRequest < RubySMB::GenericPacket
7
+ COMMAND = RubySMB::SMB2::Commands::NEGOTIATE
8
+
7
9
  endian :little
8
10
  smb2_header :smb2_header
9
11
  uint16 :structure_size, label: 'Structure Size', initial_value: 36
@@ -15,11 +17,6 @@ module RubySMB
15
17
  file_time :client_start_time, label: 'Client Start Time', initial_value: 0
16
18
  array :dialects, label: 'Dialects', type: :uint16, read_until: :eof
17
19
 
18
- def initialize_instance
19
- super
20
- smb2_header.command = RubySMB::SMB2::Commands::NEGOTIATE
21
- end
22
-
23
20
  # Adds a dialect to the Dialects array and increments the dialect count
24
21
  #
25
22
  # @param [Fixnum] the numeric code for the dialect you wish to add
@@ -4,6 +4,8 @@ module RubySMB
4
4
  # An SMB2 NEGOTIATE Response packet as defined by
5
5
  # [2.2.4 SMB2 NEGOTIATE Response](https://msdn.microsoft.com/en-us/library/cc246561.aspx)
6
6
  class NegotiateResponse < RubySMB::GenericPacket
7
+ COMMAND = RubySMB::SMB2::Commands::NEGOTIATE
8
+
7
9
  endian :little
8
10
  smb2_header :smb2_header
9
11
  uint16 :structure_size, label: 'Structure Size', initial_value: 65
@@ -24,7 +26,6 @@ module RubySMB
24
26
 
25
27
  def initialize_instance
26
28
  super
27
- smb2_header.command = RubySMB::SMB2::Commands::NEGOTIATE
28
29
  smb2_header.flags.reply = 1
29
30
  end
30
31
  end
@@ -4,6 +4,8 @@ module RubySMB
4
4
  # An SMB2 Query Directory Request Packet as defined in
5
5
  # [2.2.33 SMB2 QUERY_DIRECTORY Request](https://msdn.microsoft.com/en-us/library/cc246551.aspx)
6
6
  class QueryDirectoryRequest < RubySMB::GenericPacket
7
+ COMMAND = RubySMB::SMB2::Commands::QUERY_DIRECTORY
8
+
7
9
  endian :little
8
10
  smb2_header :smb2_header
9
11
  uint16 :structure_size, label: 'Structure Size', initial_value: 33
@@ -25,10 +27,6 @@ module RubySMB
25
27
  uint32 :output_length, label: 'Output Buffer Length'
26
28
  string16 :name, label: 'Name/Search Pattern'
27
29
 
28
- def initialize_instance
29
- super
30
- smb2_header.command = RubySMB::SMB2::Commands::QUERY_DIRECTORY
31
- end
32
30
  end
33
31
  end
34
32
  end
@@ -4,6 +4,8 @@ module RubySMB
4
4
  # An SMB2 Query Directory Response Packet as defined in
5
5
  # [2.2.34 SMB2 QUERY_DIRECTORY Response](https://msdn.microsoft.com/en-us/library/cc246552.aspx)
6
6
  class QueryDirectoryResponse < RubySMB::GenericPacket
7
+ COMMAND = RubySMB::SMB2::Commands::QUERY_DIRECTORY
8
+
7
9
  endian :little
8
10
  smb2_header :smb2_header
9
11
  uint16 :structure_size, label: 'Structure Size', initial_value: 9
@@ -13,7 +15,6 @@ module RubySMB
13
15
 
14
16
  def initialize_instance
15
17
  super
16
- smb2_header.command = RubySMB::SMB2::Commands::QUERY_DIRECTORY
17
18
  smb2_header.flags.reply = 1
18
19
  end
19
20
 
@@ -23,6 +24,7 @@ module RubySMB
23
24
  #
24
25
  # @param klass [Class] the FileInformationClass class to read the data as
25
26
  # @return [array<BinData::Record>] An array of structs holding the requested information
27
+ # @raise [RubySMB::Error::InvalidPacket] if the string buffer is not a valid File Information
26
28
  def results(klass)
27
29
  information_classes = []
28
30
  blob = buffer.to_binary_s.dup
@@ -35,7 +37,11 @@ module RubySMB
35
37
  blob.slice!(0, length)
36
38
  end
37
39
 
38
- information_classes << klass.read(data)
40
+ begin
41
+ information_classes << klass.read(data)
42
+ rescue IOError
43
+ raise RubySMB::Error::InvalidPacket, "Invalid #{klass} File Information in the string buffer"
44
+ end
39
45
  end
40
46
  information_classes
41
47
  end
@@ -4,6 +4,8 @@ module RubySMB
4
4
  # An SMB2 Read Request Packet as defined in
5
5
  # [2.2.19 SMB2 READ Request](https://msdn.microsoft.com/en-us/library/cc246527.aspx)
6
6
  class ReadRequest < RubySMB::GenericPacket
7
+ COMMAND = RubySMB::SMB2::Commands::READ
8
+
7
9
  endian :little
8
10
 
9
11
  smb2_header :smb2_header
@@ -20,10 +22,6 @@ module RubySMB
20
22
  uint16 :channel_length, label: 'Read Channel Info Length'
21
23
  string :buffer, label: 'Read Channel info Buffer', initial_value: 0x00
22
24
 
23
- def initialize_instance
24
- super
25
- smb2_header.command = RubySMB::SMB2::Commands::READ
26
- end
27
25
  end
28
26
  end
29
27
  end
@@ -4,6 +4,8 @@ module RubySMB
4
4
  # An SMB2 Read Response Packet as defined in
5
5
  # [2.2.20 SMB2 READ Response](https://msdn.microsoft.com/en-us/library/cc246531.aspx)
6
6
  class ReadResponse < RubySMB::GenericPacket
7
+ COMMAND = RubySMB::SMB2::Commands::READ
8
+
7
9
  endian :little
8
10
 
9
11
  smb2_header :smb2_header
@@ -17,7 +19,6 @@ module RubySMB
17
19
 
18
20
  def initialize_instance
19
21
  super
20
- smb2_header.command = RubySMB::SMB2::Commands::READ
21
22
  smb2_header.flags.reply = 1
22
23
  end
23
24
  end
@@ -4,6 +4,8 @@ module RubySMB
4
4
  # An SMB2 SessionSetupRequest Packet as defined in
5
5
  # [2.2.5 SMB2 SESSION_SETUP Request](https://msdn.microsoft.com/en-us/library/cc246563.aspx)
6
6
  class SessionSetupRequest < RubySMB::GenericPacket
7
+ COMMAND = RubySMB::SMB2::Commands::SESSION_SETUP
8
+
7
9
  endian :little
8
10
  smb2_header :smb2_header
9
11
  uint16 :structure_size, label: 'Structure Size', initial_value: 25
@@ -16,11 +18,6 @@ module RubySMB
16
18
  uint64 :previous_session_id, label: 'Previous Session ID'
17
19
  string :buffer, label: 'Security Buffer', length: -> { security_buffer_length }
18
20
 
19
- def initialize_instance
20
- super
21
- smb2_header.command = RubySMB::SMB2::Commands::SESSION_SETUP
22
- end
23
-
24
21
  # Takes a serialized NTLM Type 1 message and wraps it in the GSS ASN1 encoding
25
22
  # and inserts it into the {RubySMB::SMB2::Packet::SessionSetupRequest#buffer}
26
23
  # as well as updating the {RubySMB::SMB2::Packet::SessionSetupRequest#security_buffer_length}
@@ -4,6 +4,8 @@ module RubySMB
4
4
  # An SMB2 SessionSetupResponse Packet as defined in
5
5
  # [2.2.6 SMB2 SESSION_SETUP Response](https://msdn.microsoft.com/en-us/library/cc246564.aspx)
6
6
  class SessionSetupResponse < RubySMB::GenericPacket
7
+ COMMAND = RubySMB::SMB2::Commands::SESSION_SETUP
8
+
7
9
  endian :little
8
10
  smb2_header :smb2_header
9
11
  uint16 :structure_size, label: 'Structure Size', initial_value: 9
@@ -14,7 +16,6 @@ module RubySMB
14
16
 
15
17
  def initialize_instance
16
18
  super
17
- smb2_header.command = RubySMB::SMB2::Commands::SESSION_SETUP
18
19
  smb2_header.flags.reply = 1
19
20
  end
20
21
 
@@ -4,6 +4,8 @@ module RubySMB
4
4
  # An SMB2 Set Info Request Packet as defined in
5
5
  # [2.2.39 SMB2 SET_INFO Request](https://msdn.microsoft.com/en-us/library/cc246560.aspx)
6
6
  class SetInfoRequest < RubySMB::GenericPacket
7
+ COMMAND = RubySMB::SMB2::Commands::SET_INFO
8
+
7
9
  include RubySMB::Fscc::FileInformation
8
10
 
9
11
  endian :little
@@ -48,10 +50,6 @@ module RubySMB
48
50
  file_id_full_directory_information FILE_ID_FULL_DIRECTORY_INFORMATION, label: 'File Id Full Directory Information'
49
51
  end
50
52
 
51
- def initialize_instance
52
- super
53
- smb2_header.command = RubySMB::SMB2::Commands::SET_INFO
54
- end
55
53
  end
56
54
  end
57
55
  end
@@ -4,6 +4,8 @@ module RubySMB
4
4
  # An SMB2 Read Response Packet as defined in
5
5
  # [2.2.40 SMB2 SET_INFO Response](https://msdn.microsoft.com/en-us/library/cc246562.aspx)
6
6
  class SetInfoResponse < RubySMB::GenericPacket
7
+ COMMAND = RubySMB::SMB2::Commands::SET_INFO
8
+
7
9
  endian :little
8
10
 
9
11
  smb2_header :smb2_header
@@ -11,7 +13,6 @@ module RubySMB
11
13
 
12
14
  def initialize_instance
13
15
  super
14
- smb2_header.command = RubySMB::SMB2::Commands::SET_INFO
15
16
  smb2_header.flags.reply = 1
16
17
  end
17
18
  end
@@ -4,6 +4,8 @@ module RubySMB
4
4
  # An SMB2 TreeConnectRequest Packet as defined in
5
5
  # [2.2.9 SMB2 TREE_CONNECT Request](https://msdn.microsoft.com/en-us/library/cc246567.aspx)
6
6
  class TreeConnectRequest < RubySMB::GenericPacket
7
+ COMMAND = RubySMB::SMB2::Commands::TREE_CONNECT
8
+
7
9
  endian :little
8
10
  smb2_header :smb2_header
9
11
  uint16 :structure_size, label: 'Structure Size', initial_value: 9
@@ -12,11 +14,6 @@ module RubySMB
12
14
  uint16 :path_length, label: 'Path Length', initial_value: -> { path.length }
13
15
  string :path, label: 'Path Buffer'
14
16
 
15
- def initialize_instance
16
- super
17
- smb2_header.command = RubySMB::SMB2::Commands::TREE_CONNECT
18
- end
19
-
20
17
  def encode_path(path)
21
18
  self.path = path.encode('utf-16le')
22
19
  end
@@ -4,6 +4,8 @@ module RubySMB
4
4
  # An SMB2 TreeConnectResponse Packet as defined in
5
5
  # [2.2.10 SMB2 TREE_CONNECT Response](https://msdn.microsoft.com/en-us/library/cc246499.aspx)
6
6
  class TreeConnectResponse < RubySMB::GenericPacket
7
+ COMMAND = RubySMB::SMB2::Commands::TREE_CONNECT
8
+
7
9
  endian :little
8
10
  smb2_header :smb2_header
9
11
  uint16 :structure_size, label: 'Structure Size', initial_value: 16
@@ -15,7 +17,6 @@ module RubySMB
15
17
 
16
18
  def initialize_instance
17
19
  super
18
- smb2_header.command = RubySMB::SMB2::Commands::TREE_CONNECT
19
20
  smb2_header.flags.reply = 1
20
21
  end
21
22
 
@@ -25,12 +26,17 @@ module RubySMB
25
26
  #
26
27
  # @return [RubySMB::SMB2::BitField::DirectoryAccessMask] if a directory was connected to
27
28
  # @return [RubySMB::SMB2::BitField::FileAccessMask] if anything else was connected to
29
+ # @raise [RubySMB::Error::InvalidBitField] if ACCESS_MASK bit field is not valid
28
30
  def access_rights
29
31
  if is_directory?
30
32
  maximal_access
31
33
  else
32
34
  mask = maximal_access.to_binary_s
33
- RubySMB::SMB2::BitField::FileAccessMask.read(mask)
35
+ begin
36
+ RubySMB::SMB2::BitField::FileAccessMask.read(mask)
37
+ rescue IOError
38
+ raise RubySMB::Error::InvalidBitField, 'Invalid ACCESS_MASK for the Maximal Share Access Rights'
39
+ end
34
40
  end
35
41
  end
36
42