Skip to content

Commit a9454e0

Browse files
committed
Handle STATUS_NETWORK_SESSION_EXPIRED as net use does
1 parent 727a0ff commit a9454e0

1 file changed

Lines changed: 8 additions & 0 deletions

File tree

lib/ruby_smb/client.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -517,6 +517,14 @@ def send_recv(packet, encrypt: false)
517517
break
518518
end unless version == 'SMB1'
519519

520+
# Handle STATUS_NETWORK_SESSION_EXPIRED. The 'net use' client upon receiving this error will automatically attempt
521+
# to re-authenticate, which makes relaying ntlm authentication to multiple targets possible. This block ensures
522+
# ruby_smb behaves in the same manner as 'net use'.
523+
if smb2_header && smb2_header.nt_status == WindowsError::NTStatus::STATUS_NETWORK_SESSION_EXPIRED
524+
session_setup(self.username, self.password, self.domain, local_workstation: self.local_workstation, ntlm_flags: NTLM::DEFAULT_CLIENT_FLAGS)
525+
raw_response = send_recv(packet, encrypt: encrypt) # Retry the request after re-authentication
526+
end
527+
520528
self.sequence_counter += 1 if signing_required && !session_key.empty?
521529
# update the SMB2 message ID according to the received Credit Charged
522530
self.smb2_message_id += smb2_header.credit_charge - 1 if smb2_header && self.server_supports_multi_credit

0 commit comments

Comments
 (0)