Skip to content

Commit

Permalink
Adds EOFError raise for when a session is dead
Browse files Browse the repository at this point in the history
  • Loading branch information
cgranleese-r7 committed Mar 19, 2024
1 parent 0611a3e commit 89fbf5f
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions lib/ruby_smb/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ module RubySMB
class Client
require 'ruby_smb/ntlm'
require 'ruby_smb/signing'
require 'ruby_smb/utils'
require 'ruby_smb/client/negotiation'
require 'ruby_smb/client/authentication'
require 'ruby_smb/client/tree_connect'
Expand All @@ -14,7 +13,6 @@ class Client
require 'ruby_smb/client/encryption'

include RubySMB::Signing
include RubySMB::NTLM
include RubySMB::Client::Negotiation
include RubySMB::Client::Authentication
include RubySMB::Client::TreeConnect
Expand Down Expand Up @@ -324,7 +322,7 @@ def initialize(dispatcher, smb1: true, smb2: true, smb3: true, username:, passwo
@pid = rand(0xFFFF)
@domain = domain
@local_workstation = local_workstation
@password = RubySMB::Utils.safe_encode((password||''), 'utf-8')
@password = password.encode('utf-8') || ''.encode('utf-8')
@sequence_counter = 0
@session_id = 0x00
@session_key = ''
Expand All @@ -334,7 +332,7 @@ def initialize(dispatcher, smb1: true, smb2: true, smb3: true, username:, passwo
@smb1 = smb1
@smb2 = smb2
@smb3 = smb3
@username = RubySMB::Utils.safe_encode((username||''), 'utf-8')
@username = username.encode('utf-8') || ''.encode('utf-8')
@max_buffer_size = MAX_BUFFER_SIZE
# These sizes will be modified during negotiation
@server_max_buffer_size = SERVER_MAX_BUFFER_SIZE
Expand Down Expand Up @@ -417,8 +415,8 @@ def session_setup(user, pass, domain, do_recv=true,
local_workstation: self.local_workstation, ntlm_flags: NTLM::DEFAULT_CLIENT_FLAGS)
@domain = domain
@local_workstation = local_workstation
@password = RubySMB::Utils.safe_encode((pass||''), 'utf-8')
@username = RubySMB::Utils.safe_encode((user||''), 'utf-8')
@password = pass.encode('utf-8') || ''.encode('utf-8')
@username = user.encode('utf-8') || ''.encode('utf-8')

@ntlm_client = RubySMB::NTLM::Client.new(
@username,
Expand Down Expand Up @@ -578,7 +576,7 @@ def recv_packet(encrypt: false)
raw_response = dispatcher.recv_packet
rescue RubySMB::Error::CommunicationError => e
if encrypt
raise RubySMB::Error::EncryptionError, "Communication error with the "\
raise e, "Communication error with the "\
"remote host: #{e.message}. The server supports encryption but was "\
"not able to handle the encrypted request."
else
Expand Down

0 comments on commit 89fbf5f

Please sign in to comment.