📄 htaabrow.c
字号:
} FREE(HTAA_composeAuthResult); /* From previous call */ if (IsProxy) { /* ** Proxy Authorization required. - AJL */ CTRACE((tfp, "Composing Proxy Authorization for %s:%d/%s\n", hostname, portnumber, docname)); if (proxy_portnumber != portnumber || !proxy_hostname || !proxy_docname || !hostname || !docname || 0 != strcmp(proxy_hostname, hostname) || 0 != strcmp(proxy_docname, docname)) { retry = NO; proxy_portnumber = portnumber; if (hostname) StrAllocCopy(proxy_hostname, hostname); else FREE(proxy_hostname); if (docname) StrAllocCopy(proxy_docname, docname); else FREE(proxy_docname); } else { retry = YES; } if (!proxy_setup || !retry) proxy_setup = HTAASetup_lookup(hostname, portnumber, docname, IsProxy); if (!proxy_setup) return NULL; switch (scheme = HTAA_selectScheme(proxy_setup)) { case HTAA_BASIC: case HTAA_PUBKEY: auth_string = compose_auth_string(scheme, proxy_setup, IsProxy); break; case HTAA_KERBEROS_V4: /* OTHER AUTHENTICATION ROUTINES ARE CALLED HERE */ default: { char *msg = NULL; HTSprintf0(&msg, "%s `%s'", gettext("This client doesn't know how to compose proxy authorization information for scheme"), HTAAScheme_name(scheme)); HTAlert(msg); FREE(msg); auth_string = NULL; } } /* switch scheme */ proxy_setup->retry = NO; if (!auth_string) /* ** Signal a failure. - FM */ return NULL; /* Added by marca. */ if (*auth_string == '\0') { /* ** Signal an abort. - FM */ StrAllocCopy(HTAA_composeAuthResult, ""); return(HTAA_composeAuthResult); } len = strlen(auth_string) + strlen((char *)HTAAScheme_name(scheme)) + 26; if ((HTAA_composeAuthResult = typecallocn(char, len)) == 0) outofmem(__FILE__, "HTAA_composeAuth"); strcpy(HTAA_composeAuthResult, "Proxy-Authorization: "); } else { /* ** Normal WWW authorization. */ CTRACE((tfp, "Composing Authorization for %s:%d/%s\n", hostname, portnumber, docname)); if (current_portnumber != portnumber || !current_hostname || !current_docname || !hostname || !docname || 0 != strcmp(current_hostname, hostname) || 0 != strcmp(current_docname, docname)) { retry = NO; current_portnumber = portnumber; if (hostname) StrAllocCopy(current_hostname, hostname); else FREE(current_hostname); if (docname) StrAllocCopy(current_docname, docname); else FREE(current_docname); } else { retry = YES; } if (!current_setup || !retry) current_setup = HTAASetup_lookup(hostname, portnumber, docname, IsProxy); if (!current_setup) return NULL; switch (scheme = HTAA_selectScheme(current_setup)) { case HTAA_BASIC: case HTAA_PUBKEY: auth_string = compose_auth_string(scheme, current_setup, IsProxy); break; case HTAA_KERBEROS_V4: /* OTHER AUTHENTICATION ROUTINES ARE CALLED HERE */ default: { char *msg = 0; HTSprintf0(&msg, "%s `%s'", gettext("This client doesn't know how to compose authorization information for scheme"), HTAAScheme_name(scheme)); HTAlert(msg); FREE(msg); auth_string = NULL; } } /* switch scheme */ current_setup->retry = NO; if (!auth_string) /* ** Signal a failure. - FM */ return NULL; /* Added by marca. */ if (*auth_string == '\0') { /* ** Signal an abort. - FM */ StrAllocCopy(HTAA_composeAuthResult, ""); return(HTAA_composeAuthResult); } len = strlen(auth_string) + strlen((char *)HTAAScheme_name(scheme)) + 20; if ((HTAA_composeAuthResult = typecallocn(char, len)) == 0) outofmem(__FILE__, "HTAA_composeAuth"); strcpy(HTAA_composeAuthResult, "Authorization: "); } strcat(HTAA_composeAuthResult, HTAAScheme_name(scheme)); strcat(HTAA_composeAuthResult, " "); strcat(HTAA_composeAuthResult, auth_string); return HTAA_composeAuthResult;}/* BROWSER PUBLIC HTAA_shouldRetryWithAuth()**** DETERMINES IF WE SHOULD RETRY THE SERVER** WITH AUTHORIZATION** (OR IF ALREADY RETRIED, WITH A DIFFERENT** USERNAME AND/OR PASSWORD (IF MISSPELLED))** ON ENTRY:** start_of_headers is the first block already read from socket,** but status line skipped; i.e., points to the** start of the header section.** length is the remaining length of the first block.** soc is the socket to read the rest of server reply.** IsProxy should be TRUE if this is a proxy.**** This function should only be called when** server has replied with a 401 (Unauthorized)** status code.** ON EXIT:** returns YES, if connection should be retried.** The node containing all the necessary** information is** * either constructed if it does not exist** * or password is reset to NULL to indicate** that username and password should be** reprompted when composing Authorization:** field (in function HTAA_composeAuth()).** NO, otherwise.*/PUBLIC BOOL HTAA_shouldRetryWithAuth ARGS4( char *, start_of_headers, int, length, int, soc, BOOL, IsProxy){ HTAAScheme scheme; char *line = NULL; int num_schemes = 0; HTList *valid_schemes = HTList_new(); HTAssocList **scheme_specifics = NULL; char *template = NULL; char *temp = NULL; /* ** Setup atexit() freeing if not done already. - FM */ if (!free_HTAAGlobalsSet) {#ifdef LY_FIND_LEAKS atexit(free_HTAAGlobals);#endif free_HTAAGlobalsSet = TRUE; } /* ** Read server reply header lines */ CTRACE((tfp, "Server reply header lines:\n")); HTAA_setupReader(start_of_headers, length, soc); while (NULL != (line = HTAA_getUnfoldedLine()) && *line != '\0') { CTRACE((tfp, "%s\n", line)); if (strchr(line, ':')) { /* Valid header line */ char *p = line; char *fieldname = HTNextField(&p); char *arg1 = HTNextField(&p); char *args = p; if ((IsProxy && 0==strcasecomp(fieldname, "Proxy-Authenticate:")) || (!IsProxy && 0==strcasecomp(fieldname, "WWW-Authenticate:"))) { if (!(arg1 && *arg1 && args && *args)) { HTSprintf0(&temp, gettext("Invalid header '%s%s%s%s%s'"), line, ((arg1 && *arg1) ? " " : ""), ((arg1 && *arg1) ? arg1 : ""), ((args && *args) ? " " : ""), ((args && *args) ? args : "")); HTAlert(temp); FREE(temp); } else if (HTAA_UNKNOWN != (scheme = HTAAScheme_enum(arg1))) { HTList_addObject(valid_schemes, (void*)scheme); if (!scheme_specifics) { int i; scheme_specifics = typecallocn(HTAssocList *, HTAA_MAX_SCHEMES); if (!scheme_specifics) outofmem(__FILE__, "HTAA_shouldRetryWithAuth"); for (i=0; i < HTAA_MAX_SCHEMES; i++) scheme_specifics[i] = NULL; } scheme_specifics[scheme] = HTAA_parseArgList(args); num_schemes++; } else { CTRACE((tfp, "Unknown scheme `%s' %s\n", NONNULL(arg1), (IsProxy ? "in Proxy-Authenticate: field" : "in WWW-Authenticate: field"))); } } else if (!IsProxy && 0==strcasecomp(fieldname, "WWW-Protection-Template:")) { CTRACE((tfp, "Protection template set to `%s'\n", arg1)); StrAllocCopy(template, arg1); } } /* if a valid header line */ else { CTRACE((tfp, "Invalid header line `%s' ignored\n", line)); } /* else invalid header line */ FREE(line); } /* while header lines remain */ FREE(line); /* ** So should we retry with authorization? */ if (IsProxy) { if (num_schemes == 0) { /* ** No proxy authorization valid */ proxy_setup = NULL; return NO; } /* ** Doing it for proxy. -AJL */ if (proxy_setup && proxy_setup->server) { /* ** We have already tried with proxy authorization. ** Either we don't have access or username or ** password was misspelled. ** ** Update scheme-specific parameters ** (in case they have expired by chance). */ HTAASetup_updateSpecifics(proxy_setup, scheme_specifics); if (NO == HTConfirm(AUTH_FAILED_PROMPT)) { proxy_setup = NULL; return NO; } else { /* ** Re-ask username+password (if misspelled). */ proxy_setup->retry = YES; return YES; } } else { /* ** proxy_setup == NULL, i.e., we have a ** first connection to a protected server or ** the server serves a wider set of documents ** than we expected so far. */ HTAAServer *server = HTAAServer_lookup(proxy_hostname, proxy_portnumber, IsProxy); if (!server) { server = HTAAServer_new(proxy_hostname, proxy_portnumber, IsProxy); } if (!template) /* Proxy matches everything -AJL */ StrAllocCopy(template, "*"); proxy_setup = HTAASetup_new(server, template, valid_schemes, scheme_specifics); FREE(template); HTAlert(gettext("Proxy authorization required -- retrying")); return YES; } /* Never reached */ } /* ** Normal WWW authorization. */ if (num_schemes == 0) { /* ** No authorization valid. */ current_setup = NULL; return NO; } if (current_setup && current_setup->server) { /* ** So we have already tried with WWW authorization. ** Either we don't have access or username or ** password was misspelled. ** ** Update scheme-specific parameters ** (in case they have expired by chance). */ HTAASetup_updateSpecifics(current_setup, scheme_specifics); if (NO == HTConfirm(AUTH_FAILED_PROMPT)) { current_setup = NULL; return NO; } else { /* ** Re-ask username+password (if misspelled). */ current_setup->retry = YES; return YES; } } else { /* ** current_setup == NULL, i.e., we have a ** first connection to a protected server or ** the server serves a wider set of documents ** than we expected so far. */ HTAAServer *server = HTAAServer_lookup(current_hostname, current_portnumber, IsProxy); if (!server) { server = HTAAServer_new(current_hostname, current_portnumber, IsProxy); } if (!template) template = HTAA_makeProtectionTemplate(current_docname); current_setup = HTAASetup_new(server, template, valid_schemes, scheme_specifics); FREE(template); HTAlert(gettext("Access without authorization denied -- retrying")); return YES; } /* Never reached */}/*** This function clears all authorization information by** invoking the free_HTAAGlobals() function, which normally** is invoked at exit. It allows a browser command to do** this at any time, for example, if the user is leaving** the terminal for a period of time, but does not want** to end the current session. - FM*/PUBLIC void HTClearHTTPAuthInfo NOARGS{ /* ** Need code to check cached documents against the ** protection templates, and do something to ensure ** that any protected documents no longer can be ** accessed without a new retrieval. - FM */ /* ** Now free all of the authorization info, and ** reset the free_HTAAGlobalsSet flag. - FM */ free_HTAAGlobals(); free_HTAAGlobalsSet = FALSE;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -