MCPcopy Create free account
hub / github.com/PierreGode/Ragnar / _retrieveFileFromOffset_SMB2

Method _retrieveFileFromOffset_SMB2

pager_lib/smb/base.py:905–1047  ·  view source on GitHub ↗
(self, service_name, path, file_obj, callback, errback, starting_offset, max_length, timeout = 30, show_progress = False, tqdm_kwargs = { })

Source from the content-addressed store, hash-verified

903 return self._retrieveFileFromOffset(service_name, path, file_obj, callback, errback, 0, -1, timeout)
904
905 def _retrieveFileFromOffset_SMB2(self, service_name, path, file_obj, callback, errback, starting_offset, max_length, timeout = 30, show_progress = False, tqdm_kwargs = { }):
906 if not self.has_authenticated:
907 raise NotReadyError('SMB connection not authenticated')
908
909 expiry_time = time.time() + timeout
910 path = path.replace('/', '\\')
911 if path.startswith('\\'):
912 path = path[1:]
913 if path.endswith('\\'):
914 path = path[:-1]
915 messages_history = [ ]
916 results = [ ]
917
918 def sendCreate(tid):
919 create_context_data = binascii.unhexlify(b"""
92028 00 00 00 10 00 04 00 00 00 18 00 10 00 00 00
92144 48 6e 51 00 00 00 00 00 00 00 00 00 00 00 00
92200 00 00 00 00 00 00 00 18 00 00 00 10 00 04 00
92300 00 18 00 00 00 00 00 4d 78 41 63 00 00 00 00
92400 00 00 00 10 00 04 00 00 00 18 00 00 00 00 00
92551 46 69 64 00 00 00 00
926""".replace(b' ', b'').replace(b'\n', b''))
927 m = SMB2Message(SMB2CreateRequest(path,
928 file_attributes = 0,
929 access_mask = FILE_READ_DATA | FILE_READ_EA | FILE_READ_ATTRIBUTES | READ_CONTROL | SYNCHRONIZE,
930 share_access = FILE_SHARE_READ | FILE_SHARE_WRITE,
931 oplock = SMB2_OPLOCK_LEVEL_NONE,
932 impersonation = SEC_IMPERSONATE,
933 create_options = FILE_SEQUENTIAL_ONLY | FILE_NON_DIRECTORY_FILE,
934 create_disp = FILE_OPEN,
935 create_context_data = create_context_data))
936 m.tid = tid
937 self._sendSMBMessage(m)
938 self.pending_requests[m.mid] = _PendingRequest(m.mid, expiry_time, createCB, errback, tid = tid)
939 self._pushToArray(messages_history, m)
940
941 def createCB(create_message, **kwargs):
942 self._pushToArray(messages_history, create_message)
943 if create_message.status == 0:
944 m = SMB2Message(SMB2QueryInfoRequest(create_message.payload.fid,
945 flags = 0,
946 additional_info = 0,
947 info_type = SMB2_INFO_FILE,
948 file_info_class = 0x05, # FileStandardInformation [MS-FSCC] 2.4
949 input_buf = b'',
950 output_buf_len = 4096))
951 m.tid = kwargs['tid']
952 self._sendSMBMessage(m)
953 self.pending_requests[m.mid] = _PendingRequest(m.mid, expiry_time, infoCB, errback,
954 tid = kwargs['tid'],
955 fid = create_message.payload.fid,
956 file_attributes = create_message.payload.file_attributes)
957 self._pushToArray(messages_history, m)
958 else:
959 errback(OperationFailure('Failed to retrieve %s on %s: Unable to open file' % ( path, service_name ), messages_history))
960
961 def infoCB(info_message, **kwargs):
962 self._pushToArray(messages_history, info_message)

Callers

nothing calls this directly

Calls 5

_pushToArrayMethod · 0.95
NotReadyErrorClass · 0.85
SMB2MessageClass · 0.85
_PendingRequestClass · 0.85

Tested by

no test coverage detected