From afbe346d3ca5179817c1fc7573b15ea89695bab2 Mon Sep 17 00:00:00 2001 From: Fumitoshi UKAI Date: Tue, 19 Feb 2002 15:50:17 +0000 Subject: [w3m-dev 03057] Re: Bug#134350: w3m: Forgets (http auth) login information upon reload (or almost anything else) * etc.c (find_auth): add `file' check file as well * etc.c (find_auth_cookie): add `file' * etc.c (add_auth_cookie): add `file' * file.c (AuthBasicCred): add "Basic " * file.c (AuthDigestCred): add "Digest " * file.c (getAuthCookie): if h_auth == NULL, get recorded cookie * file.c (get_auth_cookie): get recorded cookie * file.c (loadGeneralFile): don't clear add_auth_cookie_flag by redirection add_auth_cookie if authorization is required and passed * fm.h (auth_cookie): add file * ftp.c (openFTP): follow change auth_cookie * proto.h (get_auth_cookie): added * proto.h (find_auth_cookie): add `file' * proto.h (add_auth_cookie): add `file' * url.c (openURL): get_auth_cookie From: Fumitoshi UKAI --- file.c | 40 +++++++++++++++++++++++++++++----------- 1 file changed, 29 insertions(+), 11 deletions(-) (limited to 'file.c') diff --git a/file.c b/file.c index eddbc12..79ab3bf 100644 --- a/file.c +++ b/file.c @@ -1,4 +1,4 @@ -/* $Id: file.c,v 1.69 2002/02/08 11:18:10 ukai Exp $ */ +/* $Id: file.c,v 1.70 2002/02/19 15:50:18 ukai Exp $ */ #include "fm.h" #include #include "myctype.h" @@ -1006,7 +1006,7 @@ AuthBasicCred(struct http_auth *ha, Str uname, Str pw, ParsedURL *pu, Str s = Strdup(uname); Strcat_char(s, ':'); Strcat(s, pw); - return encodeB(s->ptr); + return Strnew_m_charp("Basic ", encodeB(s->ptr)->ptr, NULL); } #ifdef USE_DIGEST_AUTH @@ -1154,7 +1154,7 @@ AuthDigestCred(struct http_auth *ha, Str uname, Str pw, ParsedURL *pu, * [nonce-count] | [auth-param] ) */ - tmp = Strnew_m_charp("username=\"", uname->ptr, "\"", NULL); + tmp = Strnew_m_charp("Digest username=\"", uname->ptr, "\"", NULL); Strcat_m_charp(tmp, ", realm=", get_auth_param(ha->param, "realm")->ptr, NULL); Strcat_m_charp(tmp, ", nonce=", @@ -1292,7 +1292,10 @@ getAuthCookie(struct http_auth *hauth, char *auth_header, TextListItem *i, **i0; int a_found; int auth_header_len = strlen(auth_header); - char *realm = qstr_unquote(get_auth_param(hauth->param, "realm"))->ptr; + char *realm = NULL; + + if (hauth) + realm = qstr_unquote(get_auth_param(hauth->param, "realm"))->ptr; a_found = FALSE; for (i0 = &(extra_header->first), i = *i0; i != NULL; @@ -1303,6 +1306,8 @@ getAuthCookie(struct http_auth *hauth, char *auth_header, } } if (a_found) { + if (!realm) + return NULL; /* This means that *-Authenticate: header is received after * Authorization: header is sent to the server. */ @@ -1318,8 +1323,8 @@ getAuthCookie(struct http_auth *hauth, char *auth_header, * extra_header */ } else - ss = find_auth_cookie(pu->host, pu->port, realm); - if (ss == NULL) { + ss = find_auth_cookie(pu->host, pu->port, pu->file, realm); + if (realm && ss == NULL) { if (QuietMessage) return ss; /* input username and password */ @@ -1372,14 +1377,21 @@ getAuthCookie(struct http_auth *hauth, char *auth_header, } if (ss) { tmp = Strnew_charp(auth_header); - Strcat_m_charp(tmp, " ", hauth->scheme, NULL); - Strcat(tmp, ss); - Strcat_charp(tmp, "\r\n"); + Strcat_m_charp(tmp, " ", ss->ptr, "\r\n", NULL); pushText(extra_header, tmp->ptr); } return ss; } +void +get_auth_cookie(char *auth_header, + TextList *extra_header, ParsedURL *pu, HRequest *hr, + FormList *request) +{ + getAuthCookie(NULL, auth_header, extra_header, pu, hr, request); +} + + static int same_url_p(ParsedURL *pu1, ParsedURL *pu2) @@ -1599,7 +1611,6 @@ loadGeneralFile(char *path, ParsedURL *volatile current, char *referer, tpath = tmp->ptr; request = NULL; UFclose(&f); - add_auth_cookie_flag = 0; current = New(ParsedURL); copyParsedURL(current, &pu); t_buf->bufferprop |= BP_REDIRECTED; @@ -1607,6 +1618,12 @@ loadGeneralFile(char *path, ParsedURL *volatile current, char *referer, goto load_doc; } } + if (add_auth_cookie_flag && realm && ss) { + /* If authorization is required and passed */ + add_auth_cookie(pu.host, pu.port, pu.file, + qstr_unquote(realm)->ptr, ss); + add_auth_cookie_flag = 0; + } if ((p = checkHeader(t_buf, "WWW-Authenticate:")) != NULL && http_response_code == 401) { /* Authentication needed */ @@ -1652,7 +1669,8 @@ loadGeneralFile(char *path, ParsedURL *volatile current, char *referer, /* XXX: RFC2617 3.2.3 Authentication-Info: ? */ if (add_auth_cookie_flag) /* If authorization is required and passed */ - add_auth_cookie(pu.host, pu.port, qstr_unquote(realm)->ptr, ss); + add_auth_cookie(pu.host, pu.port, pu.file, + qstr_unquote(realm)->ptr, ss); if (status == HTST_CONNECT) { of = &f; goto load_doc; -- cgit v1.2.3