(connId, smbServer, recvPacket, parameters, data, maxDataCount)
| 991 | |
| 992 | @staticmethod |
| 993 | def findFirst2(connId, smbServer, recvPacket, parameters, data, maxDataCount): |
| 994 | connData = smbServer.getConnectionData(connId) |
| 995 | |
| 996 | respSetup = b'' |
| 997 | respParameters = b'' |
| 998 | respData = b'' |
| 999 | findFirst2Parameters = smb.SMBFindFirst2_Parameters(recvPacket['Flags2'], data=parameters) |
| 1000 | |
| 1001 | if recvPacket['Tid'] in connData['ConnectedShares']: |
| 1002 | path = connData['ConnectedShares'][recvPacket['Tid']]['path'] |
| 1003 | |
| 1004 | searchResult, searchCount, errorCode = findFirst2(path, |
| 1005 | decodeSMBString(recvPacket['Flags2'], |
| 1006 | findFirst2Parameters['FileName']), |
| 1007 | findFirst2Parameters['InformationLevel'], |
| 1008 | findFirst2Parameters['SearchAttributes'], |
| 1009 | pktFlags=recvPacket['Flags2']) |
| 1010 | |
| 1011 | if searchCount > 0: |
| 1012 | respParameters = smb.SMBFindFirst2Response_Parameters() |
| 1013 | endOfSearch = 1 |
| 1014 | sid = 0x80 # default SID |
| 1015 | searchCount = 0 |
| 1016 | totalData = 0 |
| 1017 | for i in enumerate(searchResult): |
| 1018 | # i[1].dump() |
| 1019 | data = i[1].getData() |
| 1020 | lenData = len(data) |
| 1021 | if (totalData + lenData) >= maxDataCount or (i[0] + 1) > findFirst2Parameters['SearchCount']: |
| 1022 | # We gotta stop here and continue on a find_next2 |
| 1023 | endOfSearch = 0 |
| 1024 | # Simple way to generate a fid |
| 1025 | if len(connData['SIDs']) == 0: |
| 1026 | sid = 1 |
| 1027 | else: |
| 1028 | sid = list(connData['SIDs'].keys())[-1] + 1 |
| 1029 | # Store the remaining search results in the ConnData SID |
| 1030 | connData['SIDs'][sid] = searchResult[i[0]:] |
| 1031 | respParameters['LastNameOffset'] = totalData |
| 1032 | break |
| 1033 | else: |
| 1034 | searchCount += 1 |
| 1035 | respData += data |
| 1036 | |
| 1037 | padLen = (8 - (lenData % 8)) % 8 |
| 1038 | respData += b'\xaa' * padLen |
| 1039 | totalData += lenData + padLen |
| 1040 | |
| 1041 | respParameters['SID'] = sid |
| 1042 | respParameters['EndOfSearch'] = endOfSearch |
| 1043 | respParameters['SearchCount'] = searchCount |
| 1044 | |
| 1045 | # If we've empty files and errorCode was not already set, we return NO_SUCH_FILE |
| 1046 | elif errorCode == 0: |
| 1047 | errorCode = STATUS_NO_SUCH_FILE |
| 1048 | else: |
| 1049 | errorCode = STATUS_SMB_BAD_TID |
| 1050 |
nothing calls this directly
no test coverage detected