2
* user password authorization for web access
3
* (c) 2002 Mikulas Patocka
4
* This file is part of the Links project, released under GPL.
6
* Modified by Karl Dahlke for integration with edbrowse.
14
static const char *const realmDesc[] = {
15
"", "Basic ", "Digest "
19
struct httpAuth *next;
20
struct httpAuth *prev;
21
char user[MAXUSERPASS];
22
char password[MAXUSERPASS];
23
/* These strings are allocated. */
26
char *user_password_encoded;
32
static struct listHead authlist = { &authlist, &authlist };
34
/* This string is included in the outgoing http header.
35
* It could include both a proxy and a host authorization.
36
* Not that I understand any of the proxy stuff. */
38
getAuthString(const char *url)
40
const char *host = getHostURL(url);
41
int port = getPortURL(url);
42
const char *dir, *dirend;
48
foreach(a, authlist) {
49
if(a->proxy && stringEqualCI(a->host, host) && a->port == port) {
51
stringAndString(&r, &l, "Proxy-Authorization: ");
52
stringAndString(&r, &l, realmDesc[a->realm]);
53
stringAndString(&r, &l, a->user_password_encoded);
54
stringAndString(&r, &l, eol);
58
/* Skip past the proxy directive */
59
url = getDataURL(url);
60
host = getHostURL(url);
61
port = getPortURL(url);
64
getDirURL(url, &dir, &dirend);
67
foreach(a, authlist) {
68
if(!a->proxy && stringEqualCI(a->host, host) && a->port == port) {
69
d1len = strlen(a->directory);
72
if(memcmp(a->directory, dir, d1len))
76
stringAndString(&r, &l, "Authorization: ");
77
stringAndString(&r, &l, realmDesc[a->realm]);
78
stringAndString(&r, &l, a->user_password_encoded);
79
stringAndString(&r, &l, eol);
87
addWebAuthorization(const char *url,
88
int realm, const char *user, const char *password, bool proxy)
92
const char *dir = 0, *dirend;
94
bool urlProx = isProxyURL(url);
100
setError(MSG_ProxyAuth);
104
url = getDataURL(url);
106
host = getHostURL(url);
107
port = getPortURL(url);
109
getDirURL(url, &dir, &dirend);
113
/* See if we've done this one before. */
114
foreach(a, authlist) {
115
if(a->proxy == proxy &&
118
stringEqualCI(a->host, host) &&
120
dl == strlen(a->directory) && !memcmp(a->directory, dir, dl))) {
121
nzFree(a->user_password_encoded);
126
if(a == (struct httpAuth *)&authlist) {
128
a = allocZeroMem(sizeof (struct httpAuth));
129
addToListFront(&authlist, a);
136
a->host = cloneString(host);
137
strcpy(a->user, user);
138
strcpy(a->password, password);
139
if(dir && !a->directory)
140
a->directory = pullString1(dir, dirend);
142
/* Now compute the user password encoded */
143
p = allocMem(strlen(user) + strlen(password) + 2);
147
a->user_password_encoded = base64Encode(p, strlen(p), false);
149
debugPrint(3, "%s authorization for %s%s",
150
updated ? "updated" : "new", a->host, a->directory);
151
} /* addWebAuthorization */