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

Method _listPath_SMB1

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

Source from the content-addressed store, hash-verified

2170 self._pushToArray(messages_history, m)
2171
2172 def _listPath_SMB1(self, service_name, path, callback, errback, search, pattern, timeout = 30):
2173 if not self.has_authenticated:
2174 raise NotReadyError('SMB connection not authenticated')
2175
2176 expiry_time = time.time() + timeout
2177 path = path.replace('/', '\\')
2178 if not path.endswith('\\'):
2179 path += '\\'
2180 messages_history = [ ]
2181 results = [ ]
2182
2183 def sendFindFirst(tid, support_dfs=False):
2184 setup_bytes = struct.pack('<H', 0x0001) # TRANS2_FIND_FIRST2 sub-command. See [MS-CIFS]: 2.2.6.2.1
2185 params_bytes = \
2186 struct.pack('<HHHHI',
2187 search & 0xFFFF, # SearchAttributes (need to restrict the values due to introduction of SMB_FILE_ATTRIBUTE_INCL_NORMAL)
2188 100, # SearchCount
2189 0x0006, # Flags: SMB_FIND_CLOSE_AT_EOS | SMB_FIND_RETURN_RESUME_KEYS
2190 0x0104, # InfoLevel: SMB_FIND_FILE_BOTH_DIRECTORY_INFO
2191 0x0000) # SearchStorageType (seems to be ignored by Windows)
2192 if support_dfs:
2193 params_bytes += ("\\" + self.remote_name + "\\" + service_name + path + pattern + '\0').encode('UTF-16LE')
2194 else:
2195 params_bytes += (path + pattern + '\0').encode('UTF-16LE')
2196
2197 m = SMBMessage(ComTransaction2Request(max_params_count = 10,
2198 max_data_count = 16644,
2199 max_setup_count = 0,
2200 params_bytes = params_bytes,
2201 setup_bytes = setup_bytes))
2202 m.tid = tid
2203 if support_dfs:
2204 m.flags2 |= SMB_FLAGS2_DFS
2205 self._sendSMBMessage(m)
2206 self.pending_requests[m.mid] = _PendingRequest(m.mid, expiry_time, findFirstCB, errback)
2207 self._pushToArray(messages_history, m)
2208
2209 def decodeFindStruct(data_bytes):
2210 # SMB_FIND_FILE_BOTH_DIRECTORY_INFO structure. See [MS-CIFS]: 2.2.8.1.7 and [MS-SMB]: 2.2.8.1.1
2211 info_format = '<IIQQQQQQIIIBB24s'
2212 info_size = struct.calcsize(info_format)
2213
2214 data_length = len(data_bytes)
2215 offset = 0
2216 while offset < data_length:
2217 if offset + info_size > data_length:
2218 return data_bytes[offset:]
2219
2220 next_offset, _, \
2221 create_time, last_access_time, last_write_time, last_attr_change_time, \
2222 file_size, alloc_size, file_attributes, filename_length, ea_size, \
2223 short_name_length, _, short_name = struct.unpack(info_format, data_bytes[offset:offset+info_size])
2224
2225 offset2 = offset + info_size
2226 if offset2 + filename_length > data_length:
2227 return data_bytes[offset:]
2228
2229 filename = DataFaultToleranceStrategy.data_bytes_decode(data_bytes[offset2:offset2+filename_length])

Callers 2

listCBMethod · 0.95

Calls 5

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

Tested by

no test coverage detected