webfs: preauth support

This commit is contained in:
cinap_lenrek 2013-01-12 00:16:07 +01:00
parent b6a42aa49c
commit 6dc133ad99
4 changed files with 52 additions and 3 deletions

View file

@ -59,6 +59,32 @@ file yields the current values of the parameters.
Writing strings of the form
.RB `` attr " " value ''
sets a particular attribute.
.PP
The following global parameters can be set:
.TP
.B useragent
Sets the HTTP user agent string.
.TP
.B timeout
Sets the request timeout in seconds.
.TP
.BI flushauth " url"
Flushes any associated authentication information for
resources under
.I url
or all resources if no url was given.
.TP
.BI preauth " url realm"
Preauthenticates all resources under
.I url
with the given
.I realm
using HTTP Basic authentication. This will cause
.I webfs
to preemtively send the resulting authorization information
not waiting for the server to respond with an
HTTP 401 Unauthorized status.
.PP
The top-level directory also contains
numbered directories corresponding to connections, which
may be used to fetch a single URL.

View file

@ -33,5 +33,6 @@ void bureq(Buq *q, Req *r);
void buflushreq(Buq *q, Req *r);
/* http */
int authenticate(Url *u, Url *ru, char *method, char *s);
void flushauth(Url *u, char *t);
void http(char *m, Url *u, Key *shdr, Buq *qbody, Buq *qpost);

View file

@ -543,7 +543,7 @@ fsread(Req *r)
}
static char*
rootctl(char *ctl, char *arg)
rootctl(Srv *fs, char *ctl, char *arg)
{
Url *u;
@ -578,6 +578,28 @@ rootctl(char *ctl, char *arg)
return nil;
}
/* ppreemptive authentication only basic
* auth supported, ctl message of the form:
* preauth url realm
*/
if(!strcmp(ctl, "preauth")){
char *a[3], buf[256];
int rc;
if(tokenize(arg, a, nelem(a)) != 2)
return "preauth - bad field count";
if((u = saneurl(url(a[0], 0))) == nil)
return "preauth - malformed url";
snprint(buf, sizeof(buf), "BASIC realm=\"%s\"", a[1]);
srvrelease(fs);
rc = authenticate(u, u, "GET", buf);
srvacquire(fs);
freeurl(u);
if(rc == -1)
return "preauth failed";
return nil;
}
return "bad ctl message";
}
@ -670,7 +692,7 @@ fswrite(Req *r)
if(f->level == Qctl)
t = clientctl(f->client, s, t);
else
t = rootctl(s, t);
t = rootctl(r->srv, s, t);
free(s);
respond(r, t);
return;

View file

@ -311,7 +311,7 @@ hline(Hconn *h, char *data, int len, int cont)
}
}
static int
int
authenticate(Url *u, Url *ru, char *method, char *s)
{
char *user, *pass, *realm, *nonce, *opaque, *x;