32
30
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)
33
getUserPass(const char *url, char *creds, bool find_proxy)
40
35
const char *host = getHostURL(url);
41
36
int port = getPortURL(url);
42
37
const char *dir, *dirend;
43
38
struct httpAuth *a;
39
struct httpAuth *found = NULL;
45
40
int l, d1len, d2len;
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
42
getDirURL(url, &dir, &dirend);
65
43
d2len = dirend - dir;
67
45
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);
46
if(found == NULL && a->proxy == find_proxy &&
47
stringEqualCI(a->host, host) && a->port == port) {
49
/* Directory match not done for proxy records. */
50
d1len = strlen(a->directory);
53
if(memcmp(a->directory, dir, d1len))
56
} else /* not proxy */
62
strcpy(creds, found->user_password);
64
return (found != NULL);
87
68
addWebAuthorization(const char *url,
88
int realm, const char *user, const char *password, bool proxy)
69
int realm, const char *credentials, bool proxy)
90
71
struct httpAuth *a;
136
117
a->host = cloneString(host);
137
strcpy(a->user, user);
138
strcpy(a->password, password);
139
118
if(dir && !a->directory)
140
119
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);
121
a->user_password = cloneString(credentials);
149
122
debugPrint(3, "%s authorization for %s%s",
150
123
updated ? "updated" : "new", a->host, a->directory);
151
125
} /* addWebAuthorization */