2005-08-09 23:06:39 +00:00
|
|
|
/* vim:set ts=4 sw=4 sts=4 et cindent: */
|
2012-05-21 11:12:37 +00:00
|
|
|
/* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
2005-08-09 23:06:39 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// HTTP Negotiate Authentication Support Module
|
|
|
|
//
|
|
|
|
// Described by IETF Internet draft: draft-brezak-kerberos-http-00.txt
|
|
|
|
// (formerly draft-brezak-spnego-http-04.txt)
|
|
|
|
//
|
|
|
|
// Also described here:
|
|
|
|
// http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnsecure/html/http-sso-1.asp
|
|
|
|
//
|
|
|
|
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
2005-08-18 15:22:33 +00:00
|
|
|
#include "nsAuth.h"
|
2005-08-09 23:06:39 +00:00
|
|
|
#include "nsHttpNegotiateAuth.h"
|
|
|
|
|
2010-06-17 18:33:42 +00:00
|
|
|
#include "nsIHttpAuthenticableChannel.h"
|
2006-08-01 21:28:31 +00:00
|
|
|
#include "nsIProxiedChannel.h"
|
2005-08-09 23:06:39 +00:00
|
|
|
#include "nsIAuthModule.h"
|
|
|
|
#include "nsIServiceManager.h"
|
|
|
|
#include "nsIPrefService.h"
|
|
|
|
#include "nsIPrefBranch.h"
|
2005-08-09 23:06:49 +00:00
|
|
|
#include "nsIProxyInfo.h"
|
2005-08-09 23:06:39 +00:00
|
|
|
#include "nsIURI.h"
|
|
|
|
#include "nsCOMPtr.h"
|
|
|
|
#include "nsString.h"
|
|
|
|
#include "nsNetCID.h"
|
|
|
|
#include "plbase64.h"
|
|
|
|
#include "plstr.h"
|
|
|
|
#include "prprf.h"
|
|
|
|
#include "prlog.h"
|
|
|
|
#include "prmem.h"
|
2012-02-17 15:24:31 +00:00
|
|
|
#include "prnetdb.h"
|
2012-10-26 13:32:10 +00:00
|
|
|
#include "mozilla/Likely.h"
|
2005-08-09 23:06:39 +00:00
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
static const char kNegotiate[] = "Negotiate";
|
|
|
|
static const char kNegotiateAuthTrustedURIs[] = "network.negotiate-auth.trusted-uris";
|
|
|
|
static const char kNegotiateAuthDelegationURIs[] = "network.negotiate-auth.delegation-uris";
|
2005-08-09 23:06:49 +00:00
|
|
|
static const char kNegotiateAuthAllowProxies[] = "network.negotiate-auth.allow-proxies";
|
2012-02-17 15:24:31 +00:00
|
|
|
static const char kNegotiateAuthAllowNonFqdn[] = "network.negotiate-auth.allow-non-fqdn";
|
2005-08-18 15:22:33 +00:00
|
|
|
static const char kNegotiateAuthSSPI[] = "network.auth.use-sspi";
|
2005-08-09 23:06:39 +00:00
|
|
|
|
|
|
|
#define kNegotiateLen (sizeof(kNegotiate)-1)
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
NS_IMETHODIMP
|
2012-08-22 15:56:38 +00:00
|
|
|
nsHttpNegotiateAuth::GetAuthFlags(uint32_t *flags)
|
2005-08-09 23:06:39 +00:00
|
|
|
{
|
|
|
|
//
|
|
|
|
// Negotiate Auth creds should not be reused across multiple requests.
|
|
|
|
// Only perform the negotiation when it is explicitly requested by the
|
|
|
|
// server. Thus, do *NOT* use the "REUSABLE_CREDENTIALS" flag here.
|
|
|
|
//
|
|
|
|
// CONNECTION_BASED is specified instead of REQUEST_BASED since we need
|
|
|
|
// to complete a sequence of transactions with the server over the same
|
|
|
|
// connection.
|
|
|
|
//
|
|
|
|
*flags = CONNECTION_BASED | IDENTITY_IGNORED;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// Always set *identityInvalid == FALSE here. This
|
|
|
|
// will prevent the browser from popping up the authentication
|
|
|
|
// prompt window. Because GSSAPI does not have an API
|
|
|
|
// for fetching initial credentials (ex: A Kerberos TGT),
|
|
|
|
// there is no correct way to get the users credentials.
|
|
|
|
//
|
|
|
|
NS_IMETHODIMP
|
2010-06-17 18:33:42 +00:00
|
|
|
nsHttpNegotiateAuth::ChallengeReceived(nsIHttpAuthenticableChannel *authChannel,
|
2005-08-09 23:06:39 +00:00
|
|
|
const char *challenge,
|
2011-09-29 06:19:26 +00:00
|
|
|
bool isProxyAuth,
|
2005-08-09 23:06:39 +00:00
|
|
|
nsISupports **sessionState,
|
|
|
|
nsISupports **continuationState,
|
2011-09-29 06:19:26 +00:00
|
|
|
bool *identityInvalid)
|
2005-08-09 23:06:39 +00:00
|
|
|
{
|
|
|
|
nsIAuthModule *module = (nsIAuthModule *) *continuationState;
|
|
|
|
|
2011-10-17 14:59:28 +00:00
|
|
|
*identityInvalid = false;
|
2005-08-09 23:06:39 +00:00
|
|
|
if (module)
|
|
|
|
return NS_OK;
|
|
|
|
|
|
|
|
nsresult rv;
|
|
|
|
|
|
|
|
nsCOMPtr<nsIURI> uri;
|
2010-06-17 18:33:42 +00:00
|
|
|
rv = authChannel->GetURI(getter_AddRefs(uri));
|
2005-08-09 23:06:39 +00:00
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t req_flags = nsIAuthModule::REQ_DEFAULT;
|
2012-09-02 02:35:17 +00:00
|
|
|
nsAutoCString service;
|
2005-08-09 23:06:49 +00:00
|
|
|
|
|
|
|
if (isProxyAuth) {
|
|
|
|
if (!TestBoolPref(kNegotiateAuthAllowProxies)) {
|
|
|
|
LOG(("nsHttpNegotiateAuth::ChallengeReceived proxy auth blocked\n"));
|
|
|
|
return NS_ERROR_ABORT;
|
|
|
|
}
|
|
|
|
|
2013-07-25 16:54:11 +00:00
|
|
|
req_flags |= nsIAuthModule::REQ_PROXY_AUTH;
|
2005-08-09 23:06:49 +00:00
|
|
|
nsCOMPtr<nsIProxyInfo> proxyInfo;
|
2010-06-17 18:33:42 +00:00
|
|
|
authChannel->GetProxyInfo(getter_AddRefs(proxyInfo));
|
2005-08-09 23:06:49 +00:00
|
|
|
NS_ENSURE_STATE(proxyInfo);
|
|
|
|
|
2005-08-09 23:06:51 +00:00
|
|
|
proxyInfo->GetHost(service);
|
2005-08-09 23:06:39 +00:00
|
|
|
}
|
2005-08-09 23:06:49 +00:00
|
|
|
else {
|
2012-02-17 15:24:31 +00:00
|
|
|
bool allowed = TestNonFqdn(uri) ||
|
|
|
|
TestPref(uri, kNegotiateAuthTrustedURIs);
|
2005-08-09 23:06:49 +00:00
|
|
|
if (!allowed) {
|
|
|
|
LOG(("nsHttpNegotiateAuth::ChallengeReceived URI blocked\n"));
|
|
|
|
return NS_ERROR_ABORT;
|
|
|
|
}
|
2005-08-09 23:06:39 +00:00
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool delegation = TestPref(uri, kNegotiateAuthDelegationURIs);
|
2005-08-09 23:06:49 +00:00
|
|
|
if (delegation) {
|
|
|
|
LOG((" using REQ_DELEGATE\n"));
|
|
|
|
req_flags |= nsIAuthModule::REQ_DELEGATE;
|
|
|
|
}
|
2005-08-09 23:06:39 +00:00
|
|
|
|
2005-08-09 23:06:49 +00:00
|
|
|
rv = uri->GetAsciiHost(service);
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
LOG((" service = %s\n", service.get()));
|
2005-08-09 23:06:39 +00:00
|
|
|
|
|
|
|
//
|
|
|
|
// The correct service name for IIS servers is "HTTP/f.q.d.n", so
|
|
|
|
// construct the proper service name for passing to "gss_import_name".
|
|
|
|
//
|
|
|
|
// TODO: Possibly make this a configurable service name for use
|
|
|
|
// with non-standard servers that use stuff like "khttp/f.q.d.n"
|
|
|
|
// instead.
|
|
|
|
//
|
|
|
|
service.Insert("HTTP@", 0);
|
|
|
|
|
2005-08-18 15:22:33 +00:00
|
|
|
const char *contractID;
|
|
|
|
if (TestBoolPref(kNegotiateAuthSSPI)) {
|
|
|
|
LOG((" using negotiate-sspi\n"));
|
|
|
|
contractID = NS_AUTH_MODULE_CONTRACTID_PREFIX "negotiate-sspi";
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
LOG((" using negotiate-gss\n"));
|
|
|
|
contractID = NS_AUTH_MODULE_CONTRACTID_PREFIX "negotiate-gss";
|
|
|
|
}
|
|
|
|
|
|
|
|
rv = CallCreateInstance(contractID, &module);
|
|
|
|
|
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
LOG((" Failed to load Negotiate Module \n"));
|
2005-08-09 23:06:39 +00:00
|
|
|
return rv;
|
2005-08-18 15:22:33 +00:00
|
|
|
}
|
2005-08-09 23:06:39 +00:00
|
|
|
|
2012-07-30 14:20:58 +00:00
|
|
|
rv = module->Init(service.get(), req_flags, nullptr, nullptr, nullptr);
|
2005-08-18 15:22:33 +00:00
|
|
|
|
2005-08-09 23:06:39 +00:00
|
|
|
if (NS_FAILED(rv)) {
|
|
|
|
NS_RELEASE(module);
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
|
|
|
*continuationState = module;
|
|
|
|
return NS_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
NS_IMPL_ISUPPORTS1(nsHttpNegotiateAuth, nsIHttpAuthenticator)
|
|
|
|
|
|
|
|
//
|
|
|
|
// GenerateCredentials
|
|
|
|
//
|
|
|
|
// This routine is responsible for creating the correct authentication
|
|
|
|
// blob to pass to the server that requested "Negotiate" authentication.
|
|
|
|
//
|
|
|
|
NS_IMETHODIMP
|
2010-06-17 18:33:42 +00:00
|
|
|
nsHttpNegotiateAuth::GenerateCredentials(nsIHttpAuthenticableChannel *authChannel,
|
2005-08-09 23:06:39 +00:00
|
|
|
const char *challenge,
|
2011-09-29 06:19:26 +00:00
|
|
|
bool isProxyAuth,
|
2014-01-04 15:02:17 +00:00
|
|
|
const char16_t *domain,
|
|
|
|
const char16_t *username,
|
|
|
|
const char16_t *password,
|
2005-08-09 23:06:39 +00:00
|
|
|
nsISupports **sessionState,
|
|
|
|
nsISupports **continuationState,
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t *flags,
|
2005-08-09 23:06:39 +00:00
|
|
|
char **creds)
|
|
|
|
{
|
|
|
|
// ChallengeReceived must have been called previously.
|
|
|
|
nsIAuthModule *module = (nsIAuthModule *) *continuationState;
|
|
|
|
NS_ENSURE_TRUE(module, NS_ERROR_NOT_INITIALIZED);
|
|
|
|
|
2010-02-06 15:06:48 +00:00
|
|
|
*flags = USING_INTERNAL_IDENTITY;
|
|
|
|
|
2005-08-09 23:06:39 +00:00
|
|
|
LOG(("nsHttpNegotiateAuth::GenerateCredentials() [challenge=%s]\n", challenge));
|
|
|
|
|
|
|
|
NS_ASSERTION(creds, "null param");
|
|
|
|
|
|
|
|
#ifdef DEBUG
|
2011-09-29 06:19:26 +00:00
|
|
|
bool isGssapiAuth =
|
2005-08-09 23:06:39 +00:00
|
|
|
!PL_strncasecmp(challenge, kNegotiate, kNegotiateLen);
|
2005-08-09 23:06:50 +00:00
|
|
|
NS_ASSERTION(isGssapiAuth, "Unexpected challenge");
|
2005-08-09 23:06:39 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
//
|
|
|
|
// If the "Negotiate:" header had some data associated with it,
|
|
|
|
// that data should be used as the input to this call. This may
|
|
|
|
// be a continuation of an earlier call because GSSAPI authentication
|
|
|
|
// often takes multiple round-trips to complete depending on the
|
|
|
|
// context flags given. We want to use MUTUAL_AUTHENTICATION which
|
|
|
|
// generally *does* require multiple round-trips. Don't assume
|
|
|
|
// auth can be completed in just 1 call.
|
|
|
|
//
|
|
|
|
unsigned int len = strlen(challenge);
|
|
|
|
|
|
|
|
void *inToken, *outToken;
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t inTokenLen, outTokenLen;
|
2005-08-09 23:06:39 +00:00
|
|
|
|
|
|
|
if (len > kNegotiateLen) {
|
|
|
|
challenge += kNegotiateLen;
|
|
|
|
while (*challenge == ' ')
|
|
|
|
challenge++;
|
|
|
|
len = strlen(challenge);
|
|
|
|
|
2009-11-19 22:12:43 +00:00
|
|
|
// strip off any padding (see bug 230351)
|
|
|
|
while (challenge[len - 1] == '=')
|
|
|
|
len--;
|
|
|
|
|
2005-08-09 23:06:39 +00:00
|
|
|
inTokenLen = (len * 3)/4;
|
|
|
|
inToken = malloc(inTokenLen);
|
|
|
|
if (!inToken)
|
|
|
|
return (NS_ERROR_OUT_OF_MEMORY);
|
|
|
|
|
|
|
|
//
|
|
|
|
// Decode the response that followed the "Negotiate" token
|
|
|
|
//
|
2013-04-03 01:06:20 +00:00
|
|
|
if (PL_Base64Decode(challenge, len, (char *) inToken) == nullptr) {
|
2005-08-09 23:06:39 +00:00
|
|
|
free(inToken);
|
|
|
|
return(NS_ERROR_UNEXPECTED);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
//
|
|
|
|
// Initializing, don't use an input token.
|
|
|
|
//
|
2012-07-30 14:20:58 +00:00
|
|
|
inToken = nullptr;
|
2005-08-09 23:06:39 +00:00
|
|
|
inTokenLen = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsresult rv = module->GetNextToken(inToken, inTokenLen, &outToken, &outTokenLen);
|
|
|
|
|
|
|
|
free(inToken);
|
|
|
|
|
|
|
|
if (NS_FAILED(rv))
|
|
|
|
return rv;
|
|
|
|
|
|
|
|
if (outTokenLen == 0) {
|
|
|
|
LOG((" No output token to send, exiting"));
|
|
|
|
return NS_ERROR_FAILURE;
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// base64 encode the output token.
|
|
|
|
//
|
2012-07-30 14:20:58 +00:00
|
|
|
char *encoded_token = PL_Base64Encode((char *)outToken, outTokenLen, nullptr);
|
2005-08-09 23:06:39 +00:00
|
|
|
|
|
|
|
nsMemory::Free(outToken);
|
|
|
|
|
|
|
|
if (!encoded_token)
|
|
|
|
return NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
|
|
|
|
LOG((" Sending a token of length %d\n", outTokenLen));
|
|
|
|
|
|
|
|
// allocate a buffer sizeof("Negotiate" + " " + b64output_token + "\0")
|
|
|
|
*creds = (char *) nsMemory::Alloc(kNegotiateLen + 1 + strlen(encoded_token) + 1);
|
2012-10-26 13:32:10 +00:00
|
|
|
if (MOZ_UNLIKELY(!*creds))
|
2005-08-09 23:06:39 +00:00
|
|
|
rv = NS_ERROR_OUT_OF_MEMORY;
|
|
|
|
else
|
|
|
|
sprintf(*creds, "%s %s", kNegotiate, encoded_token);
|
|
|
|
|
|
|
|
PR_Free(encoded_token);
|
|
|
|
return rv;
|
|
|
|
}
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool
|
2005-08-09 23:06:49 +00:00
|
|
|
nsHttpNegotiateAuth::TestBoolPref(const char *pref)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIPrefBranch> prefs = do_GetService(NS_PREFSERVICE_CONTRACTID);
|
|
|
|
if (!prefs)
|
2011-10-17 14:59:28 +00:00
|
|
|
return false;
|
2005-08-09 23:06:49 +00:00
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool val;
|
2005-08-09 23:06:49 +00:00
|
|
|
nsresult rv = prefs->GetBoolPref(pref, &val);
|
|
|
|
if (NS_FAILED(rv))
|
2011-10-17 14:59:28 +00:00
|
|
|
return false;
|
2005-08-09 23:06:49 +00:00
|
|
|
|
|
|
|
return val;
|
|
|
|
}
|
|
|
|
|
2012-02-17 15:24:31 +00:00
|
|
|
bool
|
|
|
|
nsHttpNegotiateAuth::TestNonFqdn(nsIURI *uri)
|
|
|
|
{
|
2012-09-02 02:35:17 +00:00
|
|
|
nsAutoCString host;
|
2012-02-17 15:24:31 +00:00
|
|
|
PRNetAddr addr;
|
|
|
|
|
|
|
|
if (!TestBoolPref(kNegotiateAuthAllowNonFqdn))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (NS_FAILED(uri->GetAsciiHost(host)))
|
|
|
|
return false;
|
|
|
|
|
|
|
|
// return true if host does not contain a dot and is not an ip address
|
|
|
|
return !host.IsEmpty() && host.FindChar('.') == kNotFound &&
|
|
|
|
PR_StringToNetAddr(host.BeginReading(), &addr) != PR_SUCCESS;
|
|
|
|
}
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool
|
2005-08-09 23:06:39 +00:00
|
|
|
nsHttpNegotiateAuth::TestPref(nsIURI *uri, const char *pref)
|
|
|
|
{
|
|
|
|
nsCOMPtr<nsIPrefBranch> prefs = do_GetService(NS_PREFSERVICE_CONTRACTID);
|
|
|
|
if (!prefs)
|
2011-10-17 14:59:28 +00:00
|
|
|
return false;
|
2005-08-09 23:06:39 +00:00
|
|
|
|
2012-09-02 02:35:17 +00:00
|
|
|
nsAutoCString scheme, host;
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t port;
|
2005-08-09 23:06:39 +00:00
|
|
|
|
|
|
|
if (NS_FAILED(uri->GetScheme(scheme)))
|
2011-10-17 14:59:28 +00:00
|
|
|
return false;
|
2005-08-09 23:06:39 +00:00
|
|
|
if (NS_FAILED(uri->GetAsciiHost(host)))
|
2011-10-17 14:59:28 +00:00
|
|
|
return false;
|
2005-08-09 23:06:39 +00:00
|
|
|
if (NS_FAILED(uri->GetPort(&port)))
|
2011-10-17 14:59:28 +00:00
|
|
|
return false;
|
2005-08-09 23:06:39 +00:00
|
|
|
|
|
|
|
char *hostList;
|
|
|
|
if (NS_FAILED(prefs->GetCharPref(pref, &hostList)) || !hostList)
|
2011-10-17 14:59:28 +00:00
|
|
|
return false;
|
2005-08-09 23:06:39 +00:00
|
|
|
|
|
|
|
// pseudo-BNF
|
|
|
|
// ----------
|
|
|
|
//
|
|
|
|
// url-list base-url ( base-url "," LWS )*
|
|
|
|
// base-url ( scheme-part | host-part | scheme-part host-part )
|
|
|
|
// scheme-part scheme "://"
|
|
|
|
// host-part host [":" port]
|
|
|
|
//
|
|
|
|
// for example:
|
|
|
|
// "https://, http://office.foo.com"
|
|
|
|
//
|
|
|
|
|
|
|
|
char *start = hostList, *end;
|
|
|
|
for (;;) {
|
|
|
|
// skip past any whitespace
|
|
|
|
while (*start == ' ' || *start == '\t')
|
|
|
|
++start;
|
|
|
|
end = strchr(start, ',');
|
|
|
|
if (!end)
|
|
|
|
end = start + strlen(start);
|
|
|
|
if (start == end)
|
|
|
|
break;
|
|
|
|
if (MatchesBaseURI(scheme, host, port, start, end))
|
2011-10-17 14:59:28 +00:00
|
|
|
return true;
|
2005-08-09 23:06:39 +00:00
|
|
|
if (*end == '\0')
|
|
|
|
break;
|
|
|
|
start = end + 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
nsMemory::Free(hostList);
|
2011-10-17 14:59:28 +00:00
|
|
|
return false;
|
2005-08-09 23:06:39 +00:00
|
|
|
}
|
|
|
|
|
2011-09-29 06:19:26 +00:00
|
|
|
bool
|
2005-08-09 23:06:39 +00:00
|
|
|
nsHttpNegotiateAuth::MatchesBaseURI(const nsCSubstring &matchScheme,
|
|
|
|
const nsCSubstring &matchHost,
|
2012-08-22 15:56:38 +00:00
|
|
|
int32_t matchPort,
|
2005-08-09 23:06:39 +00:00
|
|
|
const char *baseStart,
|
|
|
|
const char *baseEnd)
|
|
|
|
{
|
|
|
|
// check if scheme://host:port matches baseURI
|
|
|
|
|
|
|
|
// parse the base URI
|
|
|
|
const char *hostStart, *schemeEnd = strstr(baseStart, "://");
|
|
|
|
if (schemeEnd) {
|
|
|
|
// the given scheme must match the parsed scheme exactly
|
|
|
|
if (!matchScheme.Equals(Substring(baseStart, schemeEnd)))
|
2011-10-17 14:59:28 +00:00
|
|
|
return false;
|
2005-08-09 23:06:39 +00:00
|
|
|
hostStart = schemeEnd + 3;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
hostStart = baseStart;
|
|
|
|
|
|
|
|
// XXX this does not work for IPv6-literals
|
|
|
|
const char *hostEnd = strchr(hostStart, ':');
|
2006-06-26 00:05:15 +00:00
|
|
|
if (hostEnd && hostEnd < baseEnd) {
|
2005-08-09 23:06:39 +00:00
|
|
|
// the given port must match the parsed port exactly
|
|
|
|
int port = atoi(hostEnd + 1);
|
2012-08-22 15:56:38 +00:00
|
|
|
if (matchPort != (int32_t) port)
|
2011-10-17 14:59:28 +00:00
|
|
|
return false;
|
2005-08-09 23:06:39 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
hostEnd = baseEnd;
|
|
|
|
|
|
|
|
|
|
|
|
// if we didn't parse out a host, then assume we got a match.
|
|
|
|
if (hostStart == hostEnd)
|
2011-10-17 14:59:28 +00:00
|
|
|
return true;
|
2005-08-09 23:06:39 +00:00
|
|
|
|
2012-08-22 15:56:38 +00:00
|
|
|
uint32_t hostLen = hostEnd - hostStart;
|
2005-08-09 23:06:39 +00:00
|
|
|
|
2005-08-09 23:06:41 +00:00
|
|
|
// matchHost must either equal host or be a subdomain of host
|
|
|
|
if (matchHost.Length() < hostLen)
|
2011-10-17 14:59:28 +00:00
|
|
|
return false;
|
2005-08-09 23:06:39 +00:00
|
|
|
|
|
|
|
const char *end = matchHost.EndReading();
|
|
|
|
if (PL_strncasecmp(end - hostLen, hostStart, hostLen) == 0) {
|
|
|
|
// if matchHost ends with host from the base URI, then make sure it is
|
|
|
|
// either an exact match, or prefixed with a dot. we don't want
|
|
|
|
// "foobar.com" to match "bar.com"
|
|
|
|
if (matchHost.Length() == hostLen ||
|
|
|
|
*(end - hostLen) == '.' ||
|
|
|
|
*(end - hostLen - 1) == '.')
|
2011-10-17 14:59:28 +00:00
|
|
|
return true;
|
2005-08-09 23:06:39 +00:00
|
|
|
}
|
|
|
|
|
2011-10-17 14:59:28 +00:00
|
|
|
return false;
|
2005-08-09 23:06:39 +00:00
|
|
|
}
|