(self, service_name, path, callback, errback, timeout = 30)
| 1417 | sendCreate(self.connected_trees[service_name]) |
| 1418 | |
| 1419 | def _createDirectory_SMB2(self, service_name, path, callback, errback, timeout = 30): |
| 1420 | if not self.has_authenticated: |
| 1421 | raise NotReadyError('SMB connection not authenticated') |
| 1422 | |
| 1423 | expiry_time = time.time() + timeout |
| 1424 | path = path.replace('/', '\\') |
| 1425 | if path.startswith('\\'): |
| 1426 | path = path[1:] |
| 1427 | if path.endswith('\\'): |
| 1428 | path = path[:-1] |
| 1429 | messages_history = [ ] |
| 1430 | |
| 1431 | def sendCreate(tid): |
| 1432 | create_context_data = binascii.unhexlify(b""" |
| 1433 | 28 00 00 00 10 00 04 00 00 00 18 00 10 00 00 00 |
| 1434 | 44 48 6e 51 00 00 00 00 00 00 00 00 00 00 00 00 |
| 1435 | 00 00 00 00 00 00 00 00 18 00 00 00 10 00 04 00 |
| 1436 | 00 00 18 00 00 00 00 00 4d 78 41 63 00 00 00 00 |
| 1437 | 00 00 00 00 10 00 04 00 00 00 18 00 00 00 00 00 |
| 1438 | 51 46 69 64 00 00 00 00 |
| 1439 | """.replace(b' ', b'').replace(b'\n', b'')) |
| 1440 | m = SMB2Message(SMB2CreateRequest(path, |
| 1441 | file_attributes = 0, |
| 1442 | access_mask = FILE_READ_DATA | FILE_WRITE_DATA | FILE_READ_EA | FILE_WRITE_EA | FILE_READ_ATTRIBUTES | FILE_WRITE_ATTRIBUTES | READ_CONTROL | DELETE | SYNCHRONIZE, |
| 1443 | share_access = 0, |
| 1444 | oplock = SMB2_OPLOCK_LEVEL_NONE, |
| 1445 | impersonation = SEC_IMPERSONATE, |
| 1446 | create_options = FILE_DIRECTORY_FILE | FILE_SYNCHRONOUS_IO_NONALERT, |
| 1447 | create_disp = FILE_CREATE, |
| 1448 | create_context_data = create_context_data)) |
| 1449 | m.tid = tid |
| 1450 | self._sendSMBMessage(m) |
| 1451 | self.pending_requests[m.mid] = _PendingRequest(m.mid, int(time.time()) + timeout, createCB, errback, tid = tid) |
| 1452 | self._pushToArray(messages_history, m) |
| 1453 | |
| 1454 | def createCB(create_message, **kwargs): |
| 1455 | self._pushToArray(messages_history, create_message) |
| 1456 | if create_message.status == 0: |
| 1457 | closeFid(kwargs['tid'], create_message.payload.fid) |
| 1458 | else: |
| 1459 | errback(OperationFailure('Failed to create directory %s on %s: Create failed' % ( path, service_name ), messages_history)) |
| 1460 | |
| 1461 | def closeFid(tid, fid): |
| 1462 | m = SMB2Message(SMB2CloseRequest(fid)) |
| 1463 | m.tid = tid |
| 1464 | self._sendSMBMessage(m) |
| 1465 | self.pending_requests[m.mid] = _PendingRequest(m.mid, int(time.time()) + timeout, closeCB, errback) |
| 1466 | self._pushToArray(messages_history, m) |
| 1467 | |
| 1468 | def closeCB(close_message, **kwargs): |
| 1469 | callback(path) |
| 1470 | |
| 1471 | if service_name not in self.connected_trees: |
| 1472 | def connectCB(connect_message, **kwargs): |
| 1473 | self._pushToArray(messages_history, connect_message) |
| 1474 | if connect_message.status == 0: |
| 1475 | self.connected_trees[service_name] = connect_message.tid |
| 1476 | sendCreate(connect_message.tid) |
nothing calls this directly
no test coverage detected