w3m

Unnamed repository; edit this file to name it for gitweb.
git clone https://logand.com/git/w3m.git/
Log | Files | Refs | README

commit ef90f037562ca922813c74c19532838eddd806f9
parent 19b7a891a961cff95a942ab93794a60e0dacfcab
Author: ukai <ukai>
Date:   Tue, 19 Feb 2002 15:50:17 +0000

[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  <ukai@debian.or.jp>

Diffstat:
MChangeLog | 21+++++++++++++++++++++
Metc.c | 17+++++++++++------
Mfile.c | 38++++++++++++++++++++++++++++----------
Mfm.h | 1+
Mftp.c | 4++--
Mproto.h | 8++++++--
Murl.c | 1+
7 files changed, 70 insertions(+), 20 deletions(-)

diff --git a/ChangeLog b/ChangeLog @@ -1,5 +1,26 @@ 2002-02-20 Fumitoshi UKAI <ukai@debian.or.jp> + * [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 + +2002-02-20 Fumitoshi UKAI <ukai@debian.or.jp> + * [w3m-dev 03058] mailer * NEWS: rc: mailer * fm.h (Mailer): change default diff --git a/etc.c b/etc.c @@ -888,40 +888,45 @@ correct_irrtag(int status) /* authentication */ struct auth_cookie * -find_auth(char *host, int port, char *realm) +find_auth(char *host, int port, char *file, char *realm) { struct auth_cookie *p; for (p = Auth_cookie; p != NULL; p = p->next) { if (!Strcasecmp_charp(p->host, host) && - p->port == port && !Strcasecmp_charp(p->realm, realm)) + p->port == port && + ((realm && !Strcasecmp_charp(p->realm, realm)) || + (p->file && file && !Strcasecmp_charp(p->file, file)))) return p; } return NULL; } Str -find_auth_cookie(char *host, int port, char *realm) +find_auth_cookie(char *host, int port, char *file, char *realm) { - struct auth_cookie *p = find_auth(host, port, realm); + struct auth_cookie *p = find_auth(host, port, file, realm); if (p) return p->cookie; return NULL; } void -add_auth_cookie(char *host, int port, char *realm, Str cookie) +add_auth_cookie(char *host, int port, char *file, char *realm, Str cookie) { struct auth_cookie *p; - p = find_auth(host, port, realm); + p = find_auth(host, port, file, realm); if (p) { + if (realm && p->realm == NULL) + p->realm = Strnew_charp(realm); p->cookie = cookie; return; } p = New(struct auth_cookie); p->host = Strnew_charp(host); p->port = port; + p->file = file ? Strnew_charp(file) : NULL; p->realm = Strnew_charp(realm); p->cookie = cookie; p->next = Auth_cookie; diff --git a/file.c b/file.c @@ -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; diff --git a/fm.h b/fm.h @@ -600,6 +600,7 @@ struct html_feed_environ { struct auth_cookie { Str host; int port; + Str file; Str realm; Str cookie; struct auth_cookie *next; diff --git a/ftp.c b/ftp.c @@ -411,7 +411,7 @@ openFTP(ParsedURL *pu) if (pu->pass) pass = pu->pass; else if (pu->user) { - pwd = find_auth_cookie(pu->host, pu->port, pu->user); + pwd = find_auth_cookie(pu->host, pu->port, pu->file, pu->user); if (pwd == NULL) { if (fmInitialized) { term_raw(); @@ -441,7 +441,7 @@ openFTP(ParsedURL *pu) if (FtpError(s)) return NULL; if (add_auth_cookie_flag) - add_auth_cookie(pu->host, pu->port, pu->user, pwd); + add_auth_cookie(pu->host, pu->port, pu->file, pu->user, pwd); if (pu->file == NULL || *pu->file == '\0') goto ftp_dir; else diff --git a/proto.h b/proto.h @@ -128,6 +128,9 @@ extern char *acceptableEncoding(); extern int dir_exist(char *path); extern Str convertLine(URLFile *uf, Str line, char *code, int mode); extern Buffer *loadFile(char *path); +extern void get_auth_cookie(char *auth_header, + TextList *extra_header, ParsedURL *pu, + HRequest *hr, FormList *request); extern Buffer *loadGeneralFile(char *path, ParsedURL *current, char *referer, int flag, FormList *request); extern int is_boundary(int, int); @@ -512,8 +515,9 @@ extern Buffer *dirBuffer(char *dirname); extern void set_environ(char *var, char *value); extern FILE *localcgi_post(char *, char *, FormList *, char *); extern FILE *localcgi_get(char *, char *, char *); -extern Str find_auth_cookie(char *host, int port, char *realm); -extern void add_auth_cookie(char *host, int port, char *realm, Str cookie); +extern Str find_auth_cookie(char *host, int port, char *file, char *realm); +extern void add_auth_cookie(char *host, int port, char *file, char *realm, + Str cookie); extern char *last_modified(Buffer *buf); extern Str romanNumeral(int n); extern Str romanAlphabet(int n); diff --git a/url.c b/url.c @@ -1535,6 +1535,7 @@ openURL(char *url, ParsedURL *pu, ParsedURL *current, #ifdef USE_SSL case SCM_HTTPS: #endif /* USE_SSL */ + get_auth_cookie("Authorization:", extra_header, pu, hr, request); if (pu->file == NULL) pu->file = allocStr("/", -1); if (request && request->method == FORM_METHOD_POST && request->body)