(self, service_name, path, callback, errback, search, pattern, timeout = 30)
| 603 | connectSrvSvc(self.connected_trees[path]) |
| 604 | |
| 605 | def _listPath_SMB2(self, service_name, path, callback, errback, search, pattern, timeout = 30): |
| 606 | if not self.has_authenticated: |
| 607 | raise NotReadyError('SMB connection not authenticated') |
| 608 | |
| 609 | expiry_time = time.time() + timeout |
| 610 | path = path.replace('/', '\\') |
| 611 | if path.startswith('\\'): |
| 612 | path = path[1:] |
| 613 | if path.endswith('\\'): |
| 614 | path = path[:-1] |
| 615 | messages_history = [ ] |
| 616 | results = [ ] |
| 617 | |
| 618 | def sendCreate(tid): |
| 619 | create_context_data = binascii.unhexlify(b""" |
| 620 | 28 00 00 00 10 00 04 00 00 00 18 00 10 00 00 00 |
| 621 | 44 48 6e 51 00 00 00 00 00 00 00 00 00 00 00 00 |
| 622 | 00 00 00 00 00 00 00 00 18 00 00 00 10 00 04 00 |
| 623 | 00 00 18 00 00 00 00 00 4d 78 41 63 00 00 00 00 |
| 624 | 00 00 00 00 10 00 04 00 00 00 18 00 00 00 00 00 |
| 625 | 51 46 69 64 00 00 00 00 |
| 626 | """.replace(b' ', b'').replace(b'\n', b'')) |
| 627 | m = SMB2Message(SMB2CreateRequest(path, |
| 628 | file_attributes = 0, |
| 629 | access_mask = FILE_READ_DATA | FILE_READ_ATTRIBUTES | SYNCHRONIZE, |
| 630 | share_access = FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, |
| 631 | oplock = SMB2_OPLOCK_LEVEL_NONE, |
| 632 | impersonation = SEC_IMPERSONATE, |
| 633 | create_options = FILE_DIRECTORY_FILE, |
| 634 | create_disp = FILE_OPEN, |
| 635 | create_context_data = create_context_data)) |
| 636 | m.tid = tid |
| 637 | self._sendSMBMessage(m) |
| 638 | self.pending_requests[m.mid] = _PendingRequest(m.mid, expiry_time, createCB, errback, tid = tid) |
| 639 | self._pushToArray(messages_history, m) |
| 640 | |
| 641 | def createCB(create_message, **kwargs): |
| 642 | self._pushToArray(messages_history, create_message) |
| 643 | if create_message.status == 0: |
| 644 | sendQuery(kwargs['tid'], create_message.payload.fid, b'') |
| 645 | elif create_message.status == 0xC0000034: # [MS-ERREF]: STATUS_OBJECT_NAME_INVALID |
| 646 | errback(OperationFailure('Failed to list %s on %s: Path not found' % ( path, service_name ), messages_history)) |
| 647 | else: |
| 648 | errback(OperationFailure('Failed to list %s on %s: Unable to open directory' % ( path, service_name ), messages_history)) |
| 649 | |
| 650 | def sendQuery(tid, fid, data_buf): |
| 651 | m = SMB2Message(SMB2QueryDirectoryRequest(fid, pattern, |
| 652 | info_class = 0x25, # FileIdBothDirectoryInformation |
| 653 | flags = 0, |
| 654 | output_buf_len = self.max_transact_size)) |
| 655 | m.tid = tid |
| 656 | self._sendSMBMessage(m) |
| 657 | self.pending_requests[m.mid] = _PendingRequest(m.mid, expiry_time, queryCB, errback, tid = tid, fid = fid, data_buf = data_buf) |
| 658 | self._pushToArray(messages_history, m) |
| 659 | |
| 660 | def queryCB(query_message, **kwargs): |
| 661 | self._pushToArray(messages_history, query_message) |
| 662 | if query_message.status == 0: |
no test coverage detected