(self, service_name, path, callback, errback, timeout = 30)
| 1485 | sendCreate(self.connected_trees[service_name]) |
| 1486 | |
| 1487 | def _deleteDirectory_SMB2(self, service_name, path, callback, errback, timeout = 30): |
| 1488 | if not self.has_authenticated: |
| 1489 | raise NotReadyError('SMB connection not authenticated') |
| 1490 | |
| 1491 | expiry_time = time.time() + timeout |
| 1492 | path = path.replace('/', '\\') |
| 1493 | if path.startswith('\\'): |
| 1494 | path = path[1:] |
| 1495 | if path.endswith('\\'): |
| 1496 | path = path[:-1] |
| 1497 | messages_history = [ ] |
| 1498 | |
| 1499 | def sendCreate(tid): |
| 1500 | create_context_data = binascii.unhexlify(b""" |
| 1501 | 28 00 00 00 10 00 04 00 00 00 18 00 10 00 00 00 |
| 1502 | 44 48 6e 51 00 00 00 00 00 00 00 00 00 00 00 00 |
| 1503 | 00 00 00 00 00 00 00 00 18 00 00 00 10 00 04 00 |
| 1504 | 00 00 18 00 00 00 00 00 4d 78 41 63 00 00 00 00 |
| 1505 | 00 00 00 00 10 00 04 00 00 00 18 00 00 00 00 00 |
| 1506 | 51 46 69 64 00 00 00 00 |
| 1507 | """.replace(b' ', b'').replace(b'\n', b'')) |
| 1508 | m = SMB2Message(SMB2CreateRequest(path, |
| 1509 | file_attributes = 0, |
| 1510 | access_mask = DELETE | FILE_READ_ATTRIBUTES, |
| 1511 | share_access = FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE, |
| 1512 | oplock = SMB2_OPLOCK_LEVEL_NONE, |
| 1513 | impersonation = SEC_IMPERSONATE, |
| 1514 | create_options = FILE_DIRECTORY_FILE, |
| 1515 | create_disp = FILE_OPEN, |
| 1516 | create_context_data = create_context_data)) |
| 1517 | m.tid = tid |
| 1518 | self._sendSMBMessage(m) |
| 1519 | self.pending_requests[m.mid] = _PendingRequest(m.mid, int(time.time()) + timeout, createCB, errback, tid = tid) |
| 1520 | self._pushToArray(messages_history, m) |
| 1521 | |
| 1522 | def createCB(open_message, **kwargs): |
| 1523 | self._pushToArray(messages_history, open_message) |
| 1524 | if open_message.status == 0: |
| 1525 | sendDelete(kwargs['tid'], open_message.payload.fid) |
| 1526 | else: |
| 1527 | errback(OperationFailure('Failed to delete %s on %s: Unable to open directory' % ( path, service_name ), messages_history)) |
| 1528 | |
| 1529 | def sendDelete(tid, fid): |
| 1530 | m = SMB2Message(SMB2SetInfoRequest(fid, |
| 1531 | additional_info = 0, |
| 1532 | info_type = SMB2_INFO_FILE, |
| 1533 | file_info_class = 0x0d, # SMB2_FILE_DISPOSITION_INFO |
| 1534 | data = b'\x01')) |
| 1535 | m.tid = tid |
| 1536 | self._sendSMBMessage(m) |
| 1537 | self.pending_requests[m.mid] = _PendingRequest(m.mid, int(time.time()) + timeout, deleteCB, errback, tid = tid, fid = fid) |
| 1538 | self._pushToArray(messages_history, m) |
| 1539 | |
| 1540 | def deleteCB(delete_message, **kwargs): |
| 1541 | self._pushToArray(messages_history, delete_message) |
| 1542 | if delete_message.status == 0: |
| 1543 | closeFid(kwargs['tid'], kwargs['fid'], status = 0) |
| 1544 | else: |
no test coverage detected