summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorcinap_lenrek <cinap_lenrek@gmx.de>2013-01-12 00:16:07 +0100
committercinap_lenrek <cinap_lenrek@gmx.de>2013-01-12 00:16:07 +0100
commit6dc133ad99486167343885af1860d4e85a0f946c (patch)
tree62df9633ef90276bdc78fa964b195a82899feb5c
parentb6a42aa49c1dcbad21afbbdc3aeb1be6cd032548 (diff)
webfs: preauth support
-rw-r--r--sys/man/4/webfs26
-rw-r--r--sys/src/cmd/webfs/fns.h1
-rw-r--r--sys/src/cmd/webfs/fs.c26
-rw-r--r--sys/src/cmd/webfs/http.c2
4 files changed, 52 insertions, 3 deletions
diff --git a/sys/man/4/webfs b/sys/man/4/webfs
index 2a50a54ab..4c00d3595 100644
--- a/sys/man/4/webfs
+++ b/sys/man/4/webfs
@@ -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.
diff --git a/sys/src/cmd/webfs/fns.h b/sys/src/cmd/webfs/fns.h
index 9cd6f2ae2..5646bd36b 100644
--- a/sys/src/cmd/webfs/fns.h
+++ b/sys/src/cmd/webfs/fns.h
@@ -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);
diff --git a/sys/src/cmd/webfs/fs.c b/sys/src/cmd/webfs/fs.c
index b513ec114..626228c30 100644
--- a/sys/src/cmd/webfs/fs.c
+++ b/sys/src/cmd/webfs/fs.c
@@ -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;
diff --git a/sys/src/cmd/webfs/http.c b/sys/src/cmd/webfs/http.c
index 50f84dd63..f9cb50a21 100644
--- a/sys/src/cmd/webfs/http.c
+++ b/sys/src/cmd/webfs/http.c
@@ -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;