Camino only - Bug 370112: Fall back to generic-port items when searching keychain. r=josh sr=mento.

This commit is contained in:
stuart.morgan%alumni.case.edu 2007-02-12 21:59:33 +00:00
Родитель 35e7e1950b
Коммит 975e3bebc6
1 изменённых файлов: 16 добавлений и 6 удалений

Просмотреть файл

@ -81,12 +81,6 @@
attributes[usedAttributes].length = strlen(hostString);
++usedAttributes;
}
if (port != kAnyPort) {
attributes[usedAttributes].tag = kSecPortItemAttr;
attributes[usedAttributes].data = (void*)(&port);
attributes[usedAttributes].length = sizeof(port);
++usedAttributes;
}
if (protocol) {
attributes[usedAttributes].tag = kSecProtocolItemAttr;
attributes[usedAttributes].data = (void*)(&protocol);
@ -124,6 +118,22 @@
}
CFRelease(searchRef);
// Safari (and possibly others) store some things without ports, so we always
// search without a port. If any results match the port we wanted then
// discard all the other results; if not discard any non-generic entries
if (port != kAnyPort) {
NSMutableArray* exactMatches = [NSMutableArray array];
for (int i = [matchingItems count] - 1; i >= 0; --i) {
KeychainItem* item = [matchingItems objectAtIndex:i];
if ([item port] == port)
[exactMatches insertObject:item atIndex:0];
else if ([item port] != kAnyPort)
[matchingItems removeObjectAtIndex:i];
}
if ([exactMatches count] > 0)
matchingItems = exactMatches;
}
return matchingItems;
}