Module: RubySMB::Client::TreeConnect
- Included in:
- RubySMB::Client
- Defined in:
- lib/ruby_smb/client/tree_connect.rb
Overview
This module contains all of the methods for a client to connect to a remote share or named pipe.
Instance Method Summary collapse
-
#smb1_tree_connect(share, password: nil) ⇒ RubySMB::SMB1::Tree
Sends a request to connect to a remote Tree and returns the SMB1::Tree.
-
#smb1_tree_from_response(share, response) ⇒ RubySMB::SMB1::Tree
Parses a Tree structure from a Tree Connect Response.
-
#smb2_tree_connect(share) ⇒ RubySMB::SMB2::Tree
Sends a request to connect to a remote Tree and returns the SMB2::Tree.
-
#smb2_tree_from_response(share, response) ⇒ RubySMB::SMB2::Tree
Parses a Tree structure from a Tree Connect Response.
Instance Method Details
#smb1_tree_connect(share, password: nil) ⇒ RubySMB::SMB1::Tree
Sends a request to connect to a remote Tree and returns the SMB1::Tree
17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/ruby_smb/client/tree_connect.rb', line 17 def smb1_tree_connect(share, password: nil) request = RubySMB::SMB1::Packet::TreeConnectRequest.new request.smb_header.tid = 65_535 if password pass_bytes = password + "\x00".b request.parameter_block.password_length = pass_bytes.length request.data_block.password = pass_bytes end request.data_block.path = share raw_response = send_recv(request) response = RubySMB::SMB1::Packet::TreeConnectResponse.read(raw_response) smb1_tree_from_response(share, response) end |
#smb1_tree_from_response(share, response) ⇒ RubySMB::SMB1::Tree
Parses a Tree structure from a Tree Connect Response
38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/ruby_smb/client/tree_connect.rb', line 38 def smb1_tree_from_response(share, response) unless response.valid? raise RubySMB::Error::InvalidPacket.new( expected_proto: RubySMB::SMB1::SMB_PROTOCOL_ID, expected_cmd: RubySMB::SMB1::Packet::TreeConnectResponse::COMMAND, packet: response ) end unless response.status_code == WindowsError::NTStatus::STATUS_SUCCESS raise RubySMB::Error::UnexpectedStatusCode, response.status_code end RubySMB::SMB1::Tree.new(client: self, share: share, response: response) end |
#smb2_tree_connect(share) ⇒ RubySMB::SMB2::Tree
Sends a request to connect to a remote Tree and returns the SMB2::Tree
61 62 63 64 65 66 67 68 |
# File 'lib/ruby_smb/client/tree_connect.rb', line 61 def smb2_tree_connect(share) request = RubySMB::SMB2::Packet::TreeConnectRequest.new request.smb2_header.tree_id = 65_535 request.path = share raw_response = send_recv(request) response = RubySMB::SMB2::Packet::TreeConnectResponse.read(raw_response) smb2_tree_from_response(share, response) end |
#smb2_tree_from_response(share, response) ⇒ RubySMB::SMB2::Tree
Parses a Tree structure from a Tree Connect Response
77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/ruby_smb/client/tree_connect.rb', line 77 def smb2_tree_from_response(share, response) unless response.valid? raise RubySMB::Error::InvalidPacket.new( expected_proto: RubySMB::SMB2::SMB2_PROTOCOL_ID, expected_cmd: RubySMB::SMB2::Packet::TreeConnectResponse::COMMAND, packet: response ) end unless response.status_code == WindowsError::NTStatus::STATUS_SUCCESS raise RubySMB::Error::UnexpectedStatusCode, response.status_code end RubySMB::SMB2::Tree.new(client: self, share: share, response: response, encrypt: response.share_flags.encrypt == 1) end |