ref: 7e7cc2c8d78a1e5e61f6c71051f8039365314ec4
parent: 69af2676b0c62a79370158b9a6ee1263d614ac88
author: cinap_lenrek <cinap_lenrek@felloff.net>
date: Thu Mar 12 13:26:49 EDT 2015
webfs: simplify http basic auth code by using encodefmt()
--- a/sys/src/cmd/webfs/fs.c
+++ b/sys/src/cmd/webfs/fs.c
@@ -781,6 +781,7 @@
fmtinstall('U', Ufmt);
fmtinstall('H', Hfmt);
fmtinstall('E', Efmt);
+ fmtinstall('[', encodefmt);
mtpt = "/mnt/web";
user = getuser();
--- a/sys/src/cmd/webfs/http.c
+++ b/sys/src/cmd/webfs/http.c
@@ -357,7 +357,6 @@
pass = u->pass;
realm = nonce = opaque = nil;
if(!cistrncmp(s, "Basic ", 6)){
- char cred[128], plain[128];
UserPasswd *up;
s += 6;
@@ -380,19 +379,20 @@
user = up->user;
pass = up->passwd;
}
- n = snprint(plain, sizeof(plain), "%s:%s", user ? user : "", pass ? pass : "");
+ fmtstrinit(&fmt);
+ fmtprint(&fmt, "%s:%s", user ? user : "", pass ? pass : "");
if(up){
memset(up->user, 0, strlen(up->user));
memset(up->passwd, 0, strlen(up->passwd));
free(up);
}
- n = enc64(cred, sizeof(cred), (uchar*)plain, n);
- memset(plain, 0, sizeof(plain));
- if(n == -1)
+ if((s = fmtstrflush(&fmt)) == nil)
return -1;
+ n = strlen(s);
fmtstrinit(&fmt);
- fmtprint(&fmt, "Basic %s", cred);
- memset(cred, 0, sizeof(cred));
+ fmtprint(&fmt, "Basic %.*[", n, s);
+ memset(s, 0, n);
+ free(s);
u = saneurl(url(".", u)); /* all uris below the requested one */
}else
if(!cistrncmp(s, "Digest ", 7)){