code: drawterm

Download patch

ref: df8c7d8fd8b3e2d81c887a5072d72f179fd0691e
parent: 2f3f38b844da4296ea6dddab4ac4936d012ad047
author: cinap_lenrek <cinap_lenrek@felloff.net>
date: Tue Nov 21 15:53:54 EST 2017

use $PASS environment variable secstore/p9any password

--- a/cpu.c
+++ b/cpu.c
@@ -18,7 +18,7 @@
 static int	readstr(int, char*, int);
 static char 	*keyspec = "";
 static AuthInfo *p9any(int);
-static int	getkey(Authkey*, char*, char*, char*);
+static int	getkey(Authkey*, char*, char*, char*, char*);
 static int	findkey(Authkey*, char*, char*, char*);
 
 static char	*host;
@@ -35,7 +35,7 @@
 
 char *authserver;
 char *secstore;
-char *user;
+char *user, *pass;
 char secstorebuf[65536];
 
 char*
@@ -238,6 +238,7 @@
 	char *s, *cmd = nil;
 
 	user = getenv("USER");
+	pass = getenv("PASS");
 	host = getenv("cpu");
 	authserver = getenv("auth");
 
@@ -324,7 +325,7 @@
 		if(secstore == nil)
 			secstore = authserver;
 	 	if(havesecstore(secstore, user)){
-			s = secstorefetch(secstore, user, nil);
+			s = secstorefetch(secstore, user, pass);
 			if(s){
 				if(strlen(s) >= sizeof secstorebuf)
 					sysfatal("secstore data too big");
@@ -695,7 +696,7 @@
 		sysfatal("cannot read ticket request in p9sk1: %r");
 
 	if(!findkey(&authkey, user, tr.authdom, proto)){
-again:		if(!getkey(&authkey, user, tr.authdom, proto))
+again:		if(!getkey(&authkey, user, tr.authdom, proto, pass))
 			sysfatal("no password");
 	}
 
@@ -714,6 +715,8 @@
 	m = convM2T(tbuf, n, &t, &authkey);
 	if(m <= 0 || t.num != AuthTc){
 		print("?password mismatch with auth server\n");
+		if(pass != nil && *pass)
+			sysfatal("wrong password");
 		goto again;
 	}
 	n -= m;
@@ -881,13 +884,17 @@
 }
 
 static int
-getkey(Authkey *key, char *user, char *dom, char *proto)
+getkey(Authkey *key, char *user, char *dom, char *proto, char *pass)
 {
-	char buf[1024], *pass;
+	char buf[1024];
 
-	snprint(buf, sizeof buf, "%s@%s %s password", user, dom, proto);
-	pass = readcons(buf, nil, 1);
-	memset(buf, 0, sizeof buf);
+	if(pass != nil && *pass)
+		pass = estrdup(pass);
+	else {
+		snprint(buf, sizeof buf, "%s@%s %s password", user, dom, proto);
+		pass = readcons(buf, nil, 1);
+		memset(buf, 0, sizeof buf);
+	}
 	if(pass != nil){
 		snprint(secstorebuf, sizeof(secstorebuf), "key proto=%q dom=%q user=%q !password=%q\n",
 			proto, dom, user, pass);