module RubySMB::Client::Utils

Attributes

auth_user[RW]
evasion_opts[RW]
last_file_id[RW]
native_lm[RW]
native_os[RW]
open_files[RW]
send_lm[RW]
send_ntlm[RW]
spnopt[RW]
tree_connects[RW]
use_lanman_key[RW]
use_ntlmv2[RW]
usentlm2_session[RW]
verify_signature[RW]

Public Instance Methods

close(file_id = last_file_id, tree_id = last_tree_id, do_recv = true) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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() click to toggle source
# File lib/ruby_smb/client/utils.rb, line 19
def last_file
  @open_files[@last_file_id]
end
last_tree() click to toggle source
# File lib/ruby_smb/client/utils.rb, line 15
def last_tree
  @tree_connects.last
end
last_tree_id() click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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) click to toggle source
# 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) click to toggle source

Writes data to an open file handle

# 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