Fix problems with sites which require authentication if we don't have any

credentials


git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@24752 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
rfm 2007-03-02 11:53:20 +00:00
parent 7c6c308075
commit 4a89c7967e
3 changed files with 150 additions and 108 deletions

View file

@ -1,3 +1,10 @@
2007-03-02 Richard Frith-Macdonald <rfm@gnu.org>
* Source/GSHTTPURLHandle.m: Cope with nil authentication info
* Source/GSHTTPAuthentication.m: Cope with nil credential and
catch exceptions in lock protected areas (there shouldn't be
any, but best to be safe).
2007-03-01 Nicola Pero <nicola.pero@meta-innovation.com> 2007-03-01 Nicola Pero <nicola.pero@meta-innovation.com>
* Source/NSBundle.m ([NSBundle +bundleForLibrary:]): Fixed paths * Source/NSBundle.m ([NSBundle +bundleForLibrary:]): Fixed paths

View file

@ -100,7 +100,8 @@ static GSMimeParser *mimeParser = nil;
NSInvalidArgumentException); NSInvalidArgumentException);
[storeLock lock]; [storeLock lock];
NS_DURING
{
/* /*
* Keep track of known protection spaces so we don't make lots of * Keep track of known protection spaces so we don't make lots of
* duplicate copies, but share one copy between authentication objects. * duplicate copies, but share one copy between authentication objects.
@ -126,14 +127,23 @@ static GSMimeParser *mimeParser = nil;
authentication = [[GSHTTPAuthentication alloc] authentication = [[GSHTTPAuthentication alloc]
initWithCredential: credential initWithCredential: credential
inProtectionSpace: space]; inProtectionSpace: space];
[cDict setObject: authentication forKey: [authentication credential]]; if (authentication != nil)
}
else
{ {
RETAIN(authentication); [cDict setObject: authentication
forKey: [authentication credential]];
RELEASE(authentication);
} }
}
AUTORELEASE(RETAIN(authentication));
}
NS_HANDLER
{
[storeLock unlock]; [storeLock unlock];
return AUTORELEASE(authentication); [localException raise];
}
NS_ENDHANDLER
[storeLock unlock];
return authentication;
} }
+ (NSURLProtectionSpace*) protectionSpaceForAuthentication: (NSString*)auth + (NSURLProtectionSpace*) protectionSpaceForAuthentication: (NSString*)auth
@ -219,14 +229,9 @@ static GSMimeParser *mimeParser = nil;
+ (NSURLProtectionSpace *) protectionSpaceForURL: (NSURL*)URL + (NSURLProtectionSpace *) protectionSpaceForURL: (NSURL*)URL
{ {
NSURLProtectionSpace *space = nil; NSURLProtectionSpace *space = nil;
NSString *found = nil;
NSString *scheme; NSString *scheme;
NSNumber *port; NSNumber *port;
NSString *server; NSString *server;
NSDictionary *sDict;
NSArray *keys;
unsigned count;
NSString *path;
scheme = [URL scheme]; scheme = [URL scheme];
port = [URL port]; port = [URL port];
@ -248,7 +253,16 @@ static GSMimeParser *mimeParser = nil;
server = [NSString stringWithFormat: @"%@://%@:%@", server = [NSString stringWithFormat: @"%@://%@:%@",
scheme, [URL host], port]; scheme, [URL host], port];
} }
[storeLock lock]; [storeLock lock];
NS_DURING
{
NSString *found = nil;
NSDictionary *sDict;
NSArray *keys;
unsigned count;
NSString *path;
sDict = [domainMap objectForKey: server]; sDict = [domainMap objectForKey: server];
keys = [sDict allKeys]; keys = [sDict allKeys];
count = [keys count]; count = [keys count];
@ -268,19 +282,23 @@ static GSMimeParser *mimeParser = nil;
} }
if (found != nil) if (found != nil)
{ {
space = RETAIN([sDict objectForKey: found]); space = AUTORELEASE(RETAIN([sDict objectForKey: found]));
} }
}
NS_HANDLER
{
[storeLock unlock]; [storeLock unlock];
return AUTORELEASE(space); [localException raise];
}
NS_ENDHANDLER
[storeLock unlock];
return space;
} }
+ (void) setProtectionSpace: (NSURLProtectionSpace *)space + (void) setProtectionSpace: (NSURLProtectionSpace *)space
forDomains: (NSArray*)domains forDomains: (NSArray*)domains
baseURL: (NSURL*)base baseURL: (NSURL*)base
{ {
NSEnumerator *e;
NSString *domain;
/* /*
* If there are no URIs specified, everything on the * If there are no URIs specified, everything on the
* host of the base URL is in the protection space * host of the base URL is in the protection space
@ -291,7 +309,11 @@ static GSMimeParser *mimeParser = nil;
} }
[storeLock lock]; [storeLock lock];
e = [domains objectEnumerator]; NS_DURING
{
NSEnumerator *e = [domains objectEnumerator];
NSString *domain;
while ((domain = [e nextObject]) != nil) while ((domain = [e nextObject]) != nil)
{ {
NSURL *u; NSURL *u;
@ -341,6 +363,13 @@ static GSMimeParser *mimeParser = nil;
} }
[sDict setObject: space forKey: [u path]]; [sDict setObject: space forKey: [u path]];
} }
}
NS_HANDLER
{
[storeLock unlock];
[localException raise];
}
NS_ENDHANDLER
[storeLock unlock]; [storeLock unlock];
} }

View file

@ -452,19 +452,20 @@ static void debugWrite(GSHTTPURLHandle *handle, NSData *data)
NSURLCredential *cred; NSURLCredential *cred;
NSString *method; NSString *method;
/* /* Create credential from user and password stored in the URL.
* Create credential from user and password * Returns nil if we have no username or password.
* stored in the URL.
*/ */
cred = [[NSURLCredential alloc] cred = [[NSURLCredential alloc]
initWithUser: [u user] initWithUser: [u user]
password: [u password] password: [u password]
persistence: NSURLCredentialPersistenceForSession]; persistence: NSURLCredentialPersistenceForSession];
/* Create authentication from credential ... returns nil if
* we have no credential.
*/
authentication = [GSHTTPAuthentication authentication = [GSHTTPAuthentication
authenticationWithCredential: cred authenticationWithCredential: cred
inProtectionSpace: space]; inProtectionSpace: space];
RELEASE(cred); RELEASE(cred);
method = [request objectForKey: GSHTTPPropertyMethodKey]; method = [request objectForKey: GSHTTPPropertyMethodKey];
@ -483,8 +484,12 @@ static void debugWrite(GSHTTPURLHandle *handle, NSData *data)
auth = [authentication authorizationForAuthentication: nil auth = [authentication authorizationForAuthentication: nil
method: method method: method
path: [u path]]; path: [u path]];
/* If authentication is nil then auth will also be nil
NSMapInsert(wProperties, (void*)@"Authorization", (void*)auth); */
if (auth != nil)
{
[self writeProperty: auth forKey: @"Authorization"];
}
} }
} }
@ -634,7 +639,7 @@ static void debugWrite(GSHTTPURLHandle *handle, NSData *data)
NSString *ac; NSString *ac;
GSHTTPAuthentication *authentication; GSHTTPAuthentication *authentication;
NSString *method; NSString *method;
NSString *a; NSString *auth;
ac = [ah value]; ac = [ah value];
space = [GSHTTPAuthentication space = [GSHTTPAuthentication
@ -646,6 +651,7 @@ static void debugWrite(GSHTTPURLHandle *handle, NSData *data)
/* /*
* Create credential from user and password * Create credential from user and password
* stored in the URL. * stored in the URL.
* Returns nil if we have no username or password.
*/ */
cred = [[NSURLCredential alloc] cred = [[NSURLCredential alloc]
initWithUser: [url user] initWithUser: [url user]
@ -655,11 +661,11 @@ static void debugWrite(GSHTTPURLHandle *handle, NSData *data)
/* /*
* Get the digest object and ask it for a header * Get the digest object and ask it for a header
* to use for authorisation. * to use for authorisation.
* Returns nil if we have no credential.
*/ */
authentication = [GSHTTPAuthentication authentication = [GSHTTPAuthentication
authenticationWithCredential: cred authenticationWithCredential: cred
inProtectionSpace: space]; inProtectionSpace: space];
RELEASE(cred); RELEASE(cred);
} }
else else
@ -680,12 +686,12 @@ static void debugWrite(GSHTTPURLHandle *handle, NSData *data)
} }
} }
a = [authentication authorizationForAuthentication: ac auth = [authentication authorizationForAuthentication: ac
method: method method: method
path: [url path]]; path: [url path]];
if (a != nil) if (auth != nil)
{ {
[self writeProperty: a forKey: @"Authorization"]; [self writeProperty: auth forKey: @"Authorization"];
[self _tryLoadInBackground: u]; [self _tryLoadInBackground: u];
return; // Retrying. return; // Retrying.
} }