(self, pkt)
| 1334 | |
| 1335 | @ATMT.action(receive_query_directory_info) |
| 1336 | def send_query_directory_response(self, pkt): |
| 1337 | self.update_smbheader(pkt) |
| 1338 | if not pkt.FileNameLen: |
| 1339 | # this is broken. |
| 1340 | return |
| 1341 | query = pkt.FileName |
| 1342 | fid = self.get_file_id(pkt) |
| 1343 | # Check for handled FileInformationClass |
| 1344 | # 0x02: FileFullDirectoryInformation |
| 1345 | # 0x03: FileBothDirectoryInformation |
| 1346 | # 0x25: FileIdBothDirectoryInformation |
| 1347 | if pkt.FileInformationClass not in [0x02, 0x03, 0x25]: |
| 1348 | # Unknown FileInformationClass |
| 1349 | resp = self.smb_header.copy() / SMB2_Error_Response() |
| 1350 | resp.Command = "SMB2_QUERY_DIRECTORY" |
| 1351 | resp.Status = "STATUS_INVALID_INFO_CLASS" |
| 1352 | self.send(resp) |
| 1353 | return |
| 1354 | # Handle SMB2_RESTART_SCANS |
| 1355 | if pkt[SMB2_Query_Directory_Request].Flags.SMB2_RESTART_SCANS: |
| 1356 | self.enumerate_index[fid] = 0 |
| 1357 | # Lookup the files |
| 1358 | try: |
| 1359 | files = self.lookup_folder( |
| 1360 | fid, |
| 1361 | query, |
| 1362 | self.enumerate_index[fid], |
| 1363 | { |
| 1364 | 0x02: FILE_FULL_DIR_INFORMATION, |
| 1365 | 0x03: FILE_BOTH_DIR_INFORMATION, |
| 1366 | 0x25: FILE_ID_BOTH_DIR_INFORMATION, |
| 1367 | }[pkt.FileInformationClass], |
| 1368 | ) |
| 1369 | except NotADirectoryError: |
| 1370 | resp = self.smb_header.copy() / SMB2_Error_Response() |
| 1371 | resp.Command = "SMB2_QUERY_DIRECTORY" |
| 1372 | resp.Status = "STATUS_INVALID_PARAMETER" |
| 1373 | self.send(resp) |
| 1374 | return |
| 1375 | if not files: |
| 1376 | # No more files ! |
| 1377 | self.enumerate_index[fid] = 0 |
| 1378 | resp = self.smb_header.copy() / SMB2_Error_Response() |
| 1379 | resp.Command = "SMB2_QUERY_DIRECTORY" |
| 1380 | resp.Status = "STATUS_NO_MORE_FILES" |
| 1381 | self.send(resp) |
| 1382 | return |
| 1383 | # Handle SMB2_RETURN_SINGLE_ENTRY |
| 1384 | if pkt[SMB2_Query_Directory_Request].Flags.SMB2_RETURN_SINGLE_ENTRY: |
| 1385 | files = files[:1] |
| 1386 | # Increment index |
| 1387 | self.enumerate_index[fid] += len(files) |
| 1388 | # Build response based on the FileInformationClass |
| 1389 | fileinfo = FileIdBothDirectoryInformation( |
| 1390 | files=files, |
| 1391 | ) |
| 1392 | self.send( |
| 1393 | self.smb_header.copy() |
nothing calls this directly
no test coverage detected