changelog shortlog tags branches files raw gz bz2 help

Mercurial > hg > plan9front / changeset: webfs: simplify http basic auth code by using encodefmt()

changeset 4336: e2715ad95a8f
parent 4335: c4d16c3c6666
child 4337: 65bcd5bc4b8e
author: cinap_lenrek@felloff.net
date: Thu, 12 Mar 2015 17:26:49 +0100
files: sys/src/cmd/webfs/fs.c sys/src/cmd/webfs/http.c
description: webfs: simplify http basic auth code by using encodefmt()
     1.1--- a/sys/src/cmd/webfs/fs.c
     1.2+++ b/sys/src/cmd/webfs/fs.c
     1.3@@ -781,6 +781,7 @@ main(int argc, char *argv[])
     1.4 	fmtinstall('U', Ufmt);
     1.5 	fmtinstall('H', Hfmt);
     1.6 	fmtinstall('E', Efmt);
     1.7+	fmtinstall('[', encodefmt);
     1.8 
     1.9 	mtpt = "/mnt/web";
    1.10 	user = getuser();
     2.1--- a/sys/src/cmd/webfs/http.c
     2.2+++ b/sys/src/cmd/webfs/http.c
     2.3@@ -357,7 +357,6 @@ authenticate(Url *u, Url *ru, char *meth
     2.4 	pass = u->pass;
     2.5 	realm = nonce = opaque = nil;
     2.6 	if(!cistrncmp(s, "Basic ", 6)){
     2.7-		char cred[128], plain[128];
     2.8 		UserPasswd *up;
     2.9 
    2.10 		s += 6;
    2.11@@ -380,19 +379,20 @@ authenticate(Url *u, Url *ru, char *meth
    2.12 			user = up->user;
    2.13 			pass = up->passwd;
    2.14 		}
    2.15-		n = snprint(plain, sizeof(plain), "%s:%s", user ? user : "", pass ? pass : "");
    2.16+		fmtstrinit(&fmt);
    2.17+		fmtprint(&fmt, "%s:%s", user ? user : "", pass ? pass : "");
    2.18 		if(up){
    2.19 			memset(up->user, 0, strlen(up->user));
    2.20 			memset(up->passwd, 0, strlen(up->passwd));
    2.21 			free(up);
    2.22 		}
    2.23-		n = enc64(cred, sizeof(cred), (uchar*)plain, n);
    2.24-		memset(plain, 0, sizeof(plain));
    2.25-		if(n == -1)
    2.26+		if((s = fmtstrflush(&fmt)) == nil)
    2.27 			return -1;
    2.28+		n = strlen(s);
    2.29 		fmtstrinit(&fmt);
    2.30-		fmtprint(&fmt, "Basic %s", cred);
    2.31-		memset(cred, 0, sizeof(cred));
    2.32+		fmtprint(&fmt, "Basic %.*[", n, s);
    2.33+		memset(s, 0, n);
    2.34+		free(s);
    2.35 		u = saneurl(url(".", u));	/* all uris below the requested one */
    2.36 	}else
    2.37 	if(!cistrncmp(s, "Digest ", 7)){