webfs: preauth support
This commit is contained in:
parent
b6a42aa49c
commit
6dc133ad99
4 changed files with 52 additions and 3 deletions
|
@ -59,6 +59,32 @@ file yields the current values of the parameters.
|
||||||
Writing strings of the form
|
Writing strings of the form
|
||||||
.RB `` attr " " value ''
|
.RB `` attr " " value ''
|
||||||
sets a particular attribute.
|
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
|
The top-level directory also contains
|
||||||
numbered directories corresponding to connections, which
|
numbered directories corresponding to connections, which
|
||||||
may be used to fetch a single URL.
|
may be used to fetch a single URL.
|
||||||
|
|
|
@ -33,5 +33,6 @@ void bureq(Buq *q, Req *r);
|
||||||
void buflushreq(Buq *q, Req *r);
|
void buflushreq(Buq *q, Req *r);
|
||||||
|
|
||||||
/* http */
|
/* http */
|
||||||
|
int authenticate(Url *u, Url *ru, char *method, char *s);
|
||||||
void flushauth(Url *u, char *t);
|
void flushauth(Url *u, char *t);
|
||||||
void http(char *m, Url *u, Key *shdr, Buq *qbody, Buq *qpost);
|
void http(char *m, Url *u, Key *shdr, Buq *qbody, Buq *qpost);
|
||||||
|
|
|
@ -543,7 +543,7 @@ fsread(Req *r)
|
||||||
}
|
}
|
||||||
|
|
||||||
static char*
|
static char*
|
||||||
rootctl(char *ctl, char *arg)
|
rootctl(Srv *fs, char *ctl, char *arg)
|
||||||
{
|
{
|
||||||
Url *u;
|
Url *u;
|
||||||
|
|
||||||
|
@ -578,6 +578,28 @@ rootctl(char *ctl, char *arg)
|
||||||
return nil;
|
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";
|
return "bad ctl message";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -670,7 +692,7 @@ fswrite(Req *r)
|
||||||
if(f->level == Qctl)
|
if(f->level == Qctl)
|
||||||
t = clientctl(f->client, s, t);
|
t = clientctl(f->client, s, t);
|
||||||
else
|
else
|
||||||
t = rootctl(s, t);
|
t = rootctl(r->srv, s, t);
|
||||||
free(s);
|
free(s);
|
||||||
respond(r, t);
|
respond(r, t);
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -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)
|
authenticate(Url *u, Url *ru, char *method, char *s)
|
||||||
{
|
{
|
||||||
char *user, *pass, *realm, *nonce, *opaque, *x;
|
char *user, *pass, *realm, *nonce, *opaque, *x;
|
||||||
|
|
Loading…
Reference in a new issue