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

Method _getAttributes_SMB1

pager_lib/smb/base.py:2384–2443  ·  view source on GitHub ↗
(self, service_name, path, callback, errback, timeout = 30)

Source from the content-addressed store, hash-verified

2382 sendFindFirst(self.connected_trees[service_name])
2383
2384 def _getAttributes_SMB1(self, service_name, path, callback, errback, timeout = 30):
2385 if not self.has_authenticated:
2386 raise NotReadyError('SMB connection not authenticated')
2387
2388 expiry_time = time.time() + timeout
2389 path = path.replace('/', '\\')
2390 if path.startswith('\\'):
2391 path = path[1:]
2392 if path.endswith('\\'):
2393 path = path[:-1]
2394 messages_history = [ ]
2395
2396 def sendQuery(tid):
2397 setup_bytes = struct.pack('<H', 0x0005) # TRANS2_QUERY_PATH_INFORMATION sub-command. See [MS-CIFS]: 2.2.6.6.1
2398 params_bytes = \
2399 struct.pack('<HI',
2400 0x0107, # SMB_QUERY_FILE_ALL_INFO ([MS-CIFS] 2.2.2.3.3)
2401 0x0000) # Reserved
2402 params_bytes += (path + '\0').encode('UTF-16LE')
2403
2404 m = SMBMessage(ComTransaction2Request(max_params_count = 2,
2405 max_data_count = 65535,
2406 max_setup_count = 0,
2407 params_bytes = params_bytes,
2408 setup_bytes = setup_bytes))
2409 m.tid = tid
2410 self._sendSMBMessage(m)
2411 self.pending_requests[m.mid] = _PendingRequest(m.mid, expiry_time, queryCB, errback)
2412 self._pushToArray(messages_history, m)
2413
2414 def queryCB(query_message, **kwargs):
2415 self._pushToArray(messages_history, query_message)
2416 if not query_message.status.hasError:
2417 info_format = '<QQQQIIQQ'
2418 info_size = struct.calcsize(info_format)
2419 create_time, last_access_time, last_write_time, last_attr_change_time, \
2420 file_attributes, _, alloc_size, file_size = struct.unpack(info_format, query_message.payload.data_bytes[:info_size])
2421 filename = self._extractLastPathComponent(path)
2422
2423 info = SharedFile(convertFILETIMEtoEpoch(create_time), convertFILETIMEtoEpoch(last_access_time), convertFILETIMEtoEpoch(last_write_time), convertFILETIMEtoEpoch(last_attr_change_time),
2424 file_size, alloc_size, file_attributes, filename, filename)
2425 callback(info)
2426 else:
2427 errback(OperationFailure('Failed to get attributes for %s on %s: Read failed' % ( path, service_name ), messages_history))
2428
2429 if service_name not in self.connected_trees:
2430 def connectCB(connect_message, **kwargs):
2431 self._pushToArray(messages_history, connect_message)
2432 if not connect_message.status.hasError:
2433 self.connected_trees[service_name] = connect_message.tid
2434 sendQuery(connect_message.tid)
2435 else:
2436 errback(OperationFailure('Failed to get attributes for %s on %s: Unable to connect to shared device' % ( path, service_name ), messages_history))
2437
2438 m = SMBMessage(ComTreeConnectAndxRequest(r'\\%s\%s' % ( self.remote_name.upper(), service_name ), SERVICE_ANY, ''))
2439 self._sendSMBMessage(m)
2440 self.pending_requests[m.mid] = _PendingRequest(m.mid, expiry_time, connectCB, errback, path = service_name)
2441 self._pushToArray(messages_history, m)

Callers

nothing calls this directly

Calls 5

_pushToArrayMethod · 0.95
NotReadyErrorClass · 0.85
SMBMessageClass · 0.85
_PendingRequestClass · 0.85

Tested by

no test coverage detected