ruby_smb 3.1.1 → 3.1.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (77) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +1 -2
  3. data/examples/file_server.rb +8 -1
  4. data/examples/virtual_file_server.rb +143 -0
  5. data/lib/ruby_smb/fscc/file_information/file_access_information.rb +15 -0
  6. data/lib/ruby_smb/fscc/file_information/file_alignment_information.rb +45 -0
  7. data/lib/ruby_smb/fscc/file_information/file_all_information.rb +23 -0
  8. data/lib/ruby_smb/fscc/file_information/file_basic_information.rb +20 -0
  9. data/lib/ruby_smb/fscc/file_information/file_both_directory_information.rb +3 -3
  10. data/lib/ruby_smb/fscc/file_information/file_directory_information.rb +3 -3
  11. data/lib/ruby_smb/fscc/file_information/file_ea_information.rb +1 -0
  12. data/lib/ruby_smb/fscc/file_information/file_full_directory_information.rb +3 -3
  13. data/lib/ruby_smb/fscc/file_information/file_id_both_directory_information.rb +3 -3
  14. data/lib/ruby_smb/fscc/file_information/file_id_full_directory_information.rb +3 -3
  15. data/lib/ruby_smb/fscc/file_information/file_internal_information.rb +15 -0
  16. data/lib/ruby_smb/fscc/file_information/file_mode_information.rb +29 -0
  17. data/lib/ruby_smb/fscc/file_information/file_name_information.rb +16 -0
  18. data/lib/ruby_smb/fscc/file_information/file_names_information.rb +1 -1
  19. data/lib/ruby_smb/fscc/file_information/file_normalized_name_information.rb +16 -0
  20. data/lib/ruby_smb/fscc/file_information/file_position_information.rb +15 -0
  21. data/lib/ruby_smb/fscc/file_information/file_rename_information.rb +1 -1
  22. data/lib/ruby_smb/fscc/file_information/file_standard_information.rb +20 -0
  23. data/lib/ruby_smb/fscc/file_information/file_stream_information.rb +3 -0
  24. data/lib/ruby_smb/fscc/file_information.rb +41 -8
  25. data/lib/ruby_smb/fscc/file_system_information/file_fs_attribute_information.rb +1 -0
  26. data/lib/ruby_smb/fscc/file_system_information/file_fs_volume_information.rb +1 -0
  27. data/lib/ruby_smb/fscc/file_system_information.rb +4 -0
  28. data/lib/ruby_smb/gss/provider/ntlm.rb +16 -3
  29. data/lib/ruby_smb/gss/provider.rb +10 -1
  30. data/lib/ruby_smb/server/server_client/session_setup.rb +4 -2
  31. data/lib/ruby_smb/server/server_client.rb +9 -1
  32. data/lib/ruby_smb/server/session.rb +5 -1
  33. data/lib/ruby_smb/server/share/provider/disk/processor/close.rb +9 -5
  34. data/lib/ruby_smb/server/share/provider/disk/processor/create.rb +2 -2
  35. data/lib/ruby_smb/server/share/provider/disk/processor/query.rb +2 -2
  36. data/lib/ruby_smb/server/share/provider/disk/processor/read.rb +15 -14
  37. data/lib/ruby_smb/server/share/provider/disk/processor.rb +76 -12
  38. data/lib/ruby_smb/server/share/provider/disk.rb +8 -2
  39. data/lib/ruby_smb/server/share/provider/virtual_disk/virtual_file.rb +85 -0
  40. data/lib/ruby_smb/server/share/provider/virtual_disk/virtual_pathname.rb +196 -0
  41. data/lib/ruby_smb/server/share/provider/virtual_disk/virtual_stat.rb +175 -0
  42. data/lib/ruby_smb/server/share/provider/virtual_disk.rb +116 -0
  43. data/lib/ruby_smb/server/share/provider.rb +1 -0
  44. data/lib/ruby_smb/server.rb +13 -3
  45. data/lib/ruby_smb/smb2/tree.rb +1 -0
  46. data/lib/ruby_smb/version.rb +1 -1
  47. data/spec/lib/ruby_smb/fscc/file_information/file_access_information_spec.rb +21 -0
  48. data/spec/lib/ruby_smb/fscc/file_information/file_alignment_information_spec.rb +21 -0
  49. data/spec/lib/ruby_smb/fscc/file_information/file_all_information_spec.rb +61 -0
  50. data/spec/lib/ruby_smb/fscc/file_information/file_basic_information_spec.rb +41 -0
  51. data/spec/lib/ruby_smb/fscc/file_information/file_both_directory_information_spec.rb +59 -10
  52. data/spec/lib/ruby_smb/fscc/file_information/file_directory_information_spec.rb +30 -12
  53. data/spec/lib/ruby_smb/fscc/file_information/file_ea_information_spec.rb +21 -0
  54. data/spec/lib/ruby_smb/fscc/file_information/file_full_directory_information_spec.rb +30 -12
  55. data/spec/lib/ruby_smb/fscc/file_information/file_id_both_directory_information_spec.rb +63 -10
  56. data/spec/lib/ruby_smb/fscc/file_information/file_id_full_directory_information_spec.rb +30 -12
  57. data/spec/lib/ruby_smb/fscc/file_information/file_internal_information_spec.rb +21 -0
  58. data/spec/lib/ruby_smb/fscc/file_information/file_mode_information_spec.rb +21 -0
  59. data/spec/lib/ruby_smb/fscc/file_information/file_name_information_spec.rb +44 -0
  60. data/spec/lib/ruby_smb/fscc/file_information/file_names_information_spec.rb +30 -12
  61. data/spec/lib/ruby_smb/fscc/file_information/file_network_open_information_spec.rb +51 -0
  62. data/spec/lib/ruby_smb/fscc/file_information/file_normalized_name_information_spec.rb +44 -0
  63. data/spec/lib/ruby_smb/fscc/file_information/file_position_information_spec.rb +21 -0
  64. data/spec/lib/ruby_smb/fscc/file_information/file_rename_information_spec.rb +1 -1
  65. data/spec/lib/ruby_smb/fscc/file_information/file_standard_information_spec.rb +41 -0
  66. data/spec/lib/ruby_smb/fscc/file_information/file_stream_information_spec.rb +51 -0
  67. data/spec/lib/ruby_smb/fscc/file_information_spec.rb +14 -0
  68. data/spec/lib/ruby_smb/fscc/file_system_information/file_fs_attribute_information_spec.rb +46 -0
  69. data/spec/lib/ruby_smb/fscc/file_system_information/file_fs_volume_information_spec.rb +51 -0
  70. data/spec/lib/ruby_smb/fscc/file_system_information_spec.rb +14 -0
  71. data/spec/lib/ruby_smb/server/server_client_spec.rb +15 -0
  72. data/spec/lib/ruby_smb/server/share/provider/virtual_disk/virtual_pathname_spec.rb +581 -0
  73. data/spec/lib/ruby_smb/server/share/provider/virtual_disk/virtual_stat_spec.rb +207 -0
  74. data/spec/lib/ruby_smb/server/share/provider/virtual_disk_spec.rb +122 -0
  75. data.tar.gz.sig +0 -0
  76. metadata +57 -2
  77. metadata.gz.sig +0 -0
@@ -3,7 +3,7 @@ require 'spec_helper'
3
3
  RSpec.describe RubySMB::Fscc::FileInformation::FileRenameInformation do
4
4
  it 'references the correct class level' do
5
5
  expect(described_class).to be_const_defined(:CLASS_LEVEL)
6
- expect(described_class::CLASS_LEVEL).to be RubySMB::Fscc::FileInformation::FILE_ID_FULL_DIRECTORY_INFORMATION
6
+ expect(described_class::CLASS_LEVEL).to be RubySMB::Fscc::FileInformation::FILE_RENAME_INFORMATION
7
7
  end
8
8
 
9
9
  subject(:struct) { described_class.new }
@@ -0,0 +1,41 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe RubySMB::Fscc::FileInformation::FileStandardInformation do
4
+ it 'references the correct class level' do
5
+ expect(described_class).to be_const_defined(:CLASS_LEVEL)
6
+ expect(described_class::CLASS_LEVEL).to be RubySMB::Fscc::FileInformation::FILE_STANDARD_INFORMATION
7
+ end
8
+
9
+ subject(:struct) { described_class.new }
10
+
11
+ it { should respond_to :allocation_size }
12
+ it { should respond_to :end_of_file }
13
+ it { should respond_to :number_of_links }
14
+ it { should respond_to :delete_pending }
15
+ it { should respond_to :directory }
16
+
17
+ it 'is little endian' do
18
+ expect(described_class.fields.instance_variable_get(:@hints)[:endian]).to eq :little
19
+ end
20
+
21
+ it 'tracks the allocation size in a Int64 field' do
22
+ expect(struct.allocation_size).to be_a BinData::Int64le
23
+ end
24
+
25
+ it 'tracks the file size in a Int64 field' do
26
+ expect(struct.end_of_file).to be_a BinData::Int64le
27
+ end
28
+
29
+ it 'tracks the number of links in a Uint32 field' do
30
+ expect(struct.number_of_links).to be_a BinData::Uint32le
31
+ end
32
+
33
+ it 'tracks if a delete is pending in a Int8 field' do
34
+ expect(struct.delete_pending).to be_a BinData::Int8
35
+ end
36
+
37
+ it 'tracks if it is a directory in a Int8 field' do
38
+ expect(struct.directory).to be_a BinData::Int8
39
+ end
40
+
41
+ end
@@ -0,0 +1,51 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe RubySMB::Fscc::FileInformation::FileStreamInformation do
4
+ it 'references the correct class level' do
5
+ expect(described_class).to be_const_defined(:CLASS_LEVEL)
6
+ expect(described_class::CLASS_LEVEL).to be RubySMB::Fscc::FileInformation::FILE_STREAM_INFORMATION
7
+ end
8
+
9
+ subject(:struct) { described_class.new }
10
+
11
+ it { should respond_to :next_entry_offset }
12
+ it { should respond_to :stream_name_length }
13
+ it { should respond_to :stream_size }
14
+ it { should respond_to :stream_allocation_size }
15
+ it { should respond_to :stream_name }
16
+
17
+ it 'is little endian' do
18
+ expect(described_class.fields.instance_variable_get(:@hints)[:endian]).to eq :little
19
+ end
20
+
21
+ it 'tracks the next entry offset in a Uint32 field' do
22
+ expect(struct.next_entry_offset).to be_a BinData::Uint32le
23
+ end
24
+
25
+ it 'tracks the stream name length in a Uint32 field' do
26
+ expect(struct.stream_name_length).to be_a BinData::Uint32le
27
+ end
28
+
29
+ it 'tracks the stream size in a Int64 field' do
30
+ expect(struct.stream_size).to be_a BinData::Int64le
31
+ end
32
+
33
+ it 'tracks the stream allocation size in a Int64 field' do
34
+ expect(struct.stream_allocation_size).to be_a BinData::Int64le
35
+ end
36
+
37
+ it 'tracks the stream name in a String16 field' do
38
+ expect(struct.stream_name).to be_a RubySMB::Field::String16
39
+ end
40
+
41
+ it 'tracks the length of the stream_name field' do
42
+ struct.stream_name = 'Hello.txt'
43
+ expect(struct.stream_name_length).to eq struct.stream_name.do_num_bytes
44
+ end
45
+
46
+ it 'automatically encodes the stream name in UTF-16LE' do
47
+ name = 'Hello_world.txt'
48
+ struct.stream_name = name
49
+ expect(struct.stream_name.force_encoding('utf-16le')).to eq name.encode('utf-16le')
50
+ end
51
+ end
@@ -0,0 +1,14 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe RubySMB::Fscc::FileInformation do
4
+
5
+ describe '#name' do
6
+ it 'maps constant names to their value' do
7
+ expect(described_class.name(RubySMB::Fscc::FileInformation::FILE_DIRECTORY_INFORMATION)).to eq :FILE_DIRECTORY_INFORMATION
8
+ end
9
+
10
+ it 'returns nil for values that do not exist' do
11
+ expect(described_class.name(-1)).to be_nil
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,46 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe RubySMB::Fscc::FileSystemInformation::FileFsAttributeInformation do
4
+ it 'references the correct class level' do
5
+ expect(described_class).to be_const_defined(:CLASS_LEVEL)
6
+ expect(described_class::CLASS_LEVEL).to be RubySMB::Fscc::FileSystemInformation::FILE_FS_ATTRIBUTE_INFORMATION
7
+ end
8
+
9
+ subject(:struct) { described_class.new }
10
+
11
+ it { should respond_to :file_system_attributes }
12
+ it { should respond_to :maximum_component_name_length }
13
+ it { should respond_to :file_system_name_length }
14
+ it { should respond_to :file_system_name }
15
+
16
+ it 'is little endian' do
17
+ expect(described_class.fields.instance_variable_get(:@hints)[:endian]).to eq :little
18
+ end
19
+
20
+ it 'tracks the file system attributes in a struct field' do
21
+ expect(struct.file_system_attributes).to be_a BinData::Struct
22
+ end
23
+
24
+ it 'tracks the maximum component name length in a Int32 field' do
25
+ expect(struct.maximum_component_name_length).to be_a BinData::Int32le
26
+ end
27
+
28
+ it 'tracks the file system name length in a Uint32 field' do
29
+ expect(struct.file_system_name_length).to be_a BinData::Uint32le
30
+ end
31
+
32
+ it 'tracks the file system name in a String16 field' do
33
+ expect(struct.file_system_name).to be_a RubySMB::Field::String16
34
+ end
35
+
36
+ it 'tracks the length of the file_system_name field' do
37
+ struct.file_system_name = 'NTFS'
38
+ expect(struct.file_system_name_length).to eq struct.file_system_name.do_num_bytes
39
+ end
40
+
41
+ it 'automatically encodes the file system name in UTF-16LE' do
42
+ name = 'NTFS'
43
+ struct.file_system_name = name
44
+ expect(struct.file_system_name.force_encoding('utf-16le')).to eq name.encode('utf-16le')
45
+ end
46
+ end
@@ -0,0 +1,51 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe RubySMB::Fscc::FileSystemInformation::FileFsVolumeInformation do
4
+ it 'references the correct class level' do
5
+ expect(described_class).to be_const_defined(:CLASS_LEVEL)
6
+ expect(described_class::CLASS_LEVEL).to be RubySMB::Fscc::FileSystemInformation::FILE_FS_VOLUME_INFORMATION
7
+ end
8
+
9
+ subject(:struct) { described_class.new }
10
+
11
+ it { should respond_to :volume_creation_time }
12
+ it { should respond_to :volume_serial_number }
13
+ it { should respond_to :volume_label_length }
14
+ it { should respond_to :supports_objects }
15
+ it { should respond_to :volume_label }
16
+
17
+ it 'is little endian' do
18
+ expect(described_class.fields.instance_variable_get(:@hints)[:endian]).to eq :little
19
+ end
20
+
21
+ it 'tracks the volume creation time in a FileTime field' do
22
+ expect(struct.volume_creation_time).to be_a RubySMB::Field::FileTime
23
+ end
24
+
25
+ it 'tracks the volume serial number in a Uint32 field' do
26
+ expect(struct.volume_serial_number).to be_a BinData::Uint32le
27
+ end
28
+
29
+ it 'tracks the volume label length in a Uint32 field' do
30
+ expect(struct.volume_label_length).to be_a BinData::Uint32le
31
+ end
32
+
33
+ it 'tracks if it supports objects in a Uint8 field' do
34
+ expect(struct.supports_objects).to be_a BinData::Uint8
35
+ end
36
+
37
+ it 'tracks the volume label in a String16 field' do
38
+ expect(struct.volume_label).to be_a RubySMB::Field::String16
39
+ end
40
+
41
+ it 'tracks the length of the volume_label field' do
42
+ struct.volume_label = 'NTFS'
43
+ expect(struct.volume_label_length).to eq struct.volume_label.do_num_bytes
44
+ end
45
+
46
+ it 'automatically encodes the file system name in UTF-16LE' do
47
+ name = 'NTFS'
48
+ struct.volume_label = name
49
+ expect(struct.volume_label.force_encoding('utf-16le')).to eq name.encode('utf-16le')
50
+ end
51
+ end
@@ -0,0 +1,14 @@
1
+ require 'spec_helper'
2
+
3
+ RSpec.describe RubySMB::Fscc::FileSystemInformation do
4
+
5
+ describe '#name' do
6
+ it 'maps constant names to their value' do
7
+ expect(described_class.name(RubySMB::Fscc::FileSystemInformation::FILE_FS_VOLUME_INFORMATION)).to eq :FILE_FS_VOLUME_INFORMATION
8
+ end
9
+
10
+ it 'returns nil for values that do not exist' do
11
+ expect(described_class.name(-1)).to be_nil
12
+ end
13
+ end
14
+ end
@@ -5,6 +5,7 @@ RSpec.describe RubySMB::Server::ServerClient do
5
5
  subject(:server_client) { described_class.new(server, dispatcher) }
6
6
 
7
7
  it { is_expected.to respond_to :dialect }
8
+ it { is_expected.to respond_to :dispatcher }
8
9
  it { is_expected.to respond_to :session_table }
9
10
 
10
11
  describe '#disconnect!' do
@@ -31,6 +32,20 @@ RSpec.describe RubySMB::Server::ServerClient do
31
32
  end
32
33
  end
33
34
 
35
+ describe '#peerhost' do
36
+ it 'returns the peer IP address' do
37
+ expect(server_client).to receive(:getpeername).and_return(Socket.sockaddr_in(4444, '127.0.0.1'))
38
+ expect(server_client.peerhost).to eq '127.0.0.1'
39
+ end
40
+ end
41
+
42
+ describe '#peerport' do
43
+ it 'returns the peer IP port' do
44
+ expect(server_client).to receive(:getpeername).and_return(Socket.sockaddr_in(4444, '127.0.0.1'))
45
+ expect(server_client.peerport).to eq 4444
46
+ end
47
+ end
48
+
34
49
  describe '#process_gss' do
35
50
  before(:each) do
36
51
  expect(server_client.instance_eval { @gss_authenticator }).to receive(:process).and_call_original