X-Git-Url: http://www.project-moonshot.org/gitweb/?p=moonshot-firefox.git;a=blobdiff_plain;f=nsHttpMoonshot.cpp;h=a09a0cee71b1f4dfa6ba6a4c8027e172861ffe2b;hp=2b4643b5e90882641541c769d1c76c88c74161a1;hb=856fcd5469ff45d0640bcf25a725986c249b4bc2;hpb=94f2eb82575ff60b8ac06f4b05b8510de47704ad diff --git a/nsHttpMoonshot.cpp b/nsHttpMoonshot.cpp index 2b4643b..a09a0ce 100644 --- a/nsHttpMoonshot.cpp +++ b/nsHttpMoonshot.cpp @@ -35,6 +35,7 @@ #define FORCE_PR_LOG 1 #include +#include "nsAutoRef.h" #include "nsCOMPtr.h" #include "nsIHttpChannel.h" #include "nsIServiceManager.h" @@ -69,6 +70,14 @@ #endif #endif +NS_SPECIALIZE_TEMPLATE +class nsAutoRefTraits : public nsPointerRefTraits +{ +public: + static void Release(nsMoonshotSessionState *ptr) { ptr->Release(); } + static void AddRef(nsMoonshotSessionState *ptr) { ptr->AddRef(); } +}; + static gss_OID_desc gss_krb5_mech_oid_desc = {9, (void *)"\x2a\x86\x48\x86\xf7\x12\x01\x02\x02"}; @@ -164,22 +173,10 @@ nsHttpMoonshot::ChallengeReceived(nsIHttpChannel *httpChannel, PRBool *identityInvalid) { nsMoonshotSessionState *session = (nsMoonshotSessionState *) *sessionState; - - // - // Use this opportunity to instantiate the session object - // that gets used later when we generate the credentials. - // - if (!session) { - session = new nsMoonshotSessionState(); - if (!session) - return(NS_ERROR_OUT_OF_MEMORY); - NS_ADDREF(*sessionState = session); - *identityInvalid = PR_TRUE; - LOG(("nsHttpMoonshot::A new session context established\n")); - } else { - LOG(("nsHttpMoonshot::Still using context from previous request\n")); - *identityInvalid = PR_FALSE; - } + if (session==NULL) + session = (nsMoonshotSessionState *) *continuationState; + *identityInvalid = + ((session==NULL) || (session->gss_state == GSS_CTX_EMPTY)) ? PR_TRUE : PR_FALSE; return NS_OK; } @@ -279,8 +276,9 @@ nsHttpMoonshot::GenerateCredentials_1_9_2(nsIHttpChannel *httpChannel, gss_buffer_desc output_token = GSS_C_EMPTY_BUFFER; gss_buffer_t in_token_ptr = GSS_C_NO_BUFFER; gss_name_t server; - nsMoonshotSessionState *session = (nsMoonshotSessionState *) *sessionState; - + nsCountedRef session(static_cast(*sessionState)); + if (!session) + session = static_cast(*continuationState); nsCOMPtr uri; nsresult rv; @@ -339,6 +337,16 @@ nsHttpMoonshot::GenerateCredentials_1_9_2(nsIHttpChannel *httpChannel, return NS_ERROR_FAILURE; } + // Create session state if none added yet. + if (!session) { + session = new nsMoonshotSessionState(); + if (!session) + return(NS_ERROR_OUT_OF_MEMORY); + LOG(("nsHttpMoonshot::A new session context established\n")); + } else { + LOG(("nsHttpMoonshot::Still using context from previous request\n")); + } + // // If the "Negotiate:" header had some data associated with it, // that data should be used as the input to this call. This may @@ -418,6 +426,9 @@ nsHttpMoonshot::GenerateCredentials_1_9_2(nsIHttpChannel *httpChannel, u = strdup(NS_LossyConvertUTF16toASCII(username).get()); p = strdup(NS_LossyConvertUTF16toASCII(password).get()); + LOG(("Acquiring credentials for user '%s' using password '%s'\n", + u, p)); + tmp_token.value = (void *) u; tmp_token.length = strlen((const char *)tmp_token.value); maj_stat = gss_import_name(&min_stat, &tmp_token, @@ -481,6 +492,13 @@ nsHttpMoonshot::GenerateCredentials_1_9_2(nsIHttpChannel *httpChannel, // TEST // session->Reset(); session->gss_state = GSS_CTX_ESTABLISHED; + if (*sessionState != session) + { + NS_ADDREF(*sessionState = session); + // clean up continuation state + if (*continuationState) + NS_RELEASE(*continuationState); + } LOG(("GSS Auth done")); } else if (major_status == GSS_S_CONTINUE_NEEDED) { // @@ -493,6 +511,11 @@ nsHttpMoonshot::GenerateCredentials_1_9_2(nsIHttpChannel *httpChannel, // // TEST session->gss_state = GSS_CTX_IN_PROGRESS; + if (*continuationState != session) + { + // Assert continuationState==NULL + NS_ADDREF(*continuationState = session); + } LOG(("GSS Auth continuing")); } @@ -525,7 +548,7 @@ nsHttpMoonshot::GenerateCredentials_1_9_2(nsIHttpChannel *httpChannel, LOG(("Sending a token of length %d\n", output_token.length)); // allocate a buffer sizeof("Negotiate" + " " + b64output_token + "\0") - *creds = (char *) malloc (strlen(NEGOTIATE_AUTH) + 1 + strlen(encoded_token) + 1); + *creds = (char *) PR_Malloc (strlen(NEGOTIATE_AUTH) + 1 + strlen(encoded_token) + 1); if (!(*creds)) { PR_Free(encoded_token); (void) gss_release_buffer(&minor_status, &output_token);