Module: RubySMB::Client::Utils
- Included in:
- RubySMB::Client
- Defined in:
- lib/ruby_smb/client/utils.rb
Instance Attribute Summary collapse
-
#auth_user ⇒ Object
Returns the value of attribute auth_user.
-
#evasion_opts ⇒ Object
Returns the value of attribute evasion_opts.
-
#last_file_id ⇒ Object
Returns the value of attribute last_file_id.
-
#native_lm ⇒ Object
Returns the value of attribute native_lm.
-
#native_os ⇒ Object
Returns the value of attribute native_os.
-
#open_files ⇒ Object
Returns the value of attribute open_files.
-
#send_lm ⇒ Object
Returns the value of attribute send_lm.
-
#send_ntlm ⇒ Object
Returns the value of attribute send_ntlm.
-
#spnopt ⇒ Object
Returns the value of attribute spnopt.
-
#tree_connects ⇒ Object
Returns the value of attribute tree_connects.
-
#use_lanman_key ⇒ Object
Returns the value of attribute use_lanman_key.
-
#use_ntlmv2 ⇒ Object
Returns the value of attribute use_ntlmv2.
-
#usentlm2_session ⇒ Object
Returns the value of attribute usentlm2_session.
-
#verify_signature ⇒ Object
Returns the value of attribute verify_signature.
Instance Method Summary collapse
- #close(file_id = last_file_id, tree_id = last_tree_id, do_recv = true) ⇒ Object
- #create_pipe(path, disposition = RubySMB::Dispositions::FILE_OPEN_IF) ⇒ Object
- #delete(path, tree_id = last_tree_id, do_recv = true) ⇒ Object
- #last_file ⇒ Object
- #last_tree ⇒ Object
- #last_tree_id ⇒ Object
- #open(path, disposition = RubySMB::Dispositions::FILE_OPEN, write: false, read: true, pipe: false) ⇒ Object
- #read(file_id = last_file_id, offset = 0, length = last_file.size, do_recv = true) ⇒ Object
- #tree_disconnect(tree_id = last_tree_id, do_recv = true) ⇒ Object
-
#write(file_id = last_file_id, offset = 0, data = '', do_recv = true) ⇒ Object
Writes data to an open file handle.
Instance Attribute Details
#auth_user ⇒ Object
Returns the value of attribute auth_user.
11 12 13 |
# File 'lib/ruby_smb/client/utils.rb', line 11 def auth_user @auth_user end |
#evasion_opts ⇒ Object
Returns the value of attribute evasion_opts.
9 10 11 |
# File 'lib/ruby_smb/client/utils.rb', line 9 def evasion_opts @evasion_opts end |
#last_file_id ⇒ Object
Returns the value of attribute last_file_id.
13 14 15 |
# File 'lib/ruby_smb/client/utils.rb', line 13 def last_file_id @last_file_id end |
#native_lm ⇒ Object
Returns the value of attribute native_lm.
11 12 13 |
# File 'lib/ruby_smb/client/utils.rb', line 11 def native_lm @native_lm end |
#native_os ⇒ Object
Returns the value of attribute native_os.
11 12 13 |
# File 'lib/ruby_smb/client/utils.rb', line 11 def native_os @native_os end |
#open_files ⇒ Object
Returns the value of attribute open_files.
6 7 8 |
# File 'lib/ruby_smb/client/utils.rb', line 6 def open_files @open_files end |
#send_lm ⇒ Object
Returns the value of attribute send_lm.
8 9 10 |
# File 'lib/ruby_smb/client/utils.rb', line 8 def send_lm @send_lm end |
#send_ntlm ⇒ Object
Returns the value of attribute send_ntlm.
8 9 10 |
# File 'lib/ruby_smb/client/utils.rb', line 8 def send_ntlm @send_ntlm end |
#spnopt ⇒ Object
Returns the value of attribute spnopt.
8 9 10 |
# File 'lib/ruby_smb/client/utils.rb', line 8 def spnopt @spnopt end |
#tree_connects ⇒ Object
Returns the value of attribute tree_connects.
5 6 7 |
# File 'lib/ruby_smb/client/utils.rb', line 5 def tree_connects @tree_connects end |
#use_lanman_key ⇒ Object
Returns the value of attribute use_lanman_key.
8 9 10 |
# File 'lib/ruby_smb/client/utils.rb', line 8 def use_lanman_key @use_lanman_key end |
#use_ntlmv2 ⇒ Object
Returns the value of attribute use_ntlmv2.
8 9 10 |
# File 'lib/ruby_smb/client/utils.rb', line 8 def use_ntlmv2 @use_ntlmv2 end |
#usentlm2_session ⇒ Object
Returns the value of attribute usentlm2_session.
8 9 10 |
# File 'lib/ruby_smb/client/utils.rb', line 8 def usentlm2_session @usentlm2_session end |
#verify_signature ⇒ Object
Returns the value of attribute verify_signature.
11 12 13 |
# File 'lib/ruby_smb/client/utils.rb', line 11 def verify_signature @verify_signature end |
Instance Method Details
#close(file_id = last_file_id, tree_id = last_tree_id, do_recv = true) ⇒ Object
65 66 67 |
# File 'lib/ruby_smb/client/utils.rb', line 65 def close(file_id = last_file_id, tree_id = last_tree_id, do_recv = true) @open_files[file_id].close end |
#create_pipe(path, disposition = RubySMB::Dispositions::FILE_OPEN_IF) ⇒ Object
44 45 46 |
# File 'lib/ruby_smb/client/utils.rb', line 44 def create_pipe(path, disposition=RubySMB::Dispositions::FILE_OPEN_IF) open(path, disposition, write: true, read: true, pipe: true) end |
#delete(path, tree_id = last_tree_id, do_recv = true) ⇒ Object
58 59 60 61 62 63 |
# File 'lib/ruby_smb/client/utils.rb', line 58 def delete(path, tree_id = last_tree_id, do_recv = true) tree = @tree_connects.detect{ |tree| tree.id == tree_id } file = tree.open_file(filename: path.sub(/^\\/, ''), delete: true) file.delete file.close end |
#last_file ⇒ Object
19 20 21 |
# File 'lib/ruby_smb/client/utils.rb', line 19 def last_file @open_files[@last_file_id] end |
#last_tree ⇒ Object
15 16 17 |
# File 'lib/ruby_smb/client/utils.rb', line 15 def last_tree @tree_connects.last end |
#last_tree_id ⇒ Object
23 24 25 |
# File 'lib/ruby_smb/client/utils.rb', line 23 def last_tree_id last_tree.id end |
#open(path, disposition = RubySMB::Dispositions::FILE_OPEN, write: false, read: true, pipe: false) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/ruby_smb/client/utils.rb', line 27 def open(path, disposition=RubySMB::Dispositions::FILE_OPEN, write: false, read: true, pipe: false) if pipe file = last_tree.open_pipe(filename: path, write: write, read: read, disposition: disposition) else file = last_tree.open_file(filename: path, write: write, read: read, disposition: disposition) end @last_file_id = if file.respond_to?(:guid) # SMB2 uses guid file.guid.to_binary_s elsif file.respond_to?(:fid) # SMB1 uses fid file.fid.to_binary_s end @open_files[@last_file_id] = file @last_file_id end |
#read(file_id = last_file_id, offset = 0, length = last_file.size, do_recv = true) ⇒ Object
53 54 55 56 |
# File 'lib/ruby_smb/client/utils.rb', line 53 def read(file_id = last_file_id, offset = 0, length = last_file.size, do_recv = true) data = @open_files[file_id].send_recv_read(read_length: length, offset: offset) data.bytes end |
#tree_disconnect(tree_id = last_tree_id, do_recv = true) ⇒ Object
69 70 71 |
# File 'lib/ruby_smb/client/utils.rb', line 69 def tree_disconnect(tree_id = last_tree_id, do_recv = true) @tree_connects.detect{|tree| tree.id == tree_id }.disconnect! end |
#write(file_id = last_file_id, offset = 0, data = '', do_recv = true) ⇒ Object
Writes data to an open file handle
49 50 51 |
# File 'lib/ruby_smb/client/utils.rb', line 49 def write(file_id = last_file_id, offset = 0, data = '', do_recv = true) @open_files[file_id].send_recv_write(data: data, offset: offset) end |