shithub: riscv

Download patch

ref: ae5fb4ab78d7dd776a056045f673129f5a1cc779
parent: cf37a1010f7c9aabce1d3598d5a62489eb01d48c
author: cinap_lenrek <[email protected]>
date: Sun Jul 31 16:06:56 EDT 2016

auth/factotum: use common readcons() function from libauthsrv

--- a/sys/src/cmd/auth/factotum/dat.h
+++ b/sys/src/cmd/auth/factotum/dat.h
@@ -194,8 +194,6 @@
 void		closekey(Key*);
 uchar	*convAI2M(AuthInfo*, uchar*, int);
 void		disablekey(Key*);
-char		*estrappend(char*, char*, ...);
-#pragma varargck argpos estrappend 2
 int		failure(Fsstate*, char*, ...);
 Keyinfo*	mkkeyinfo(Keyinfo*, Fsstate*, Attr*);
 int		findkey(Key**, Keyinfo*, char*, ...);
@@ -209,7 +207,6 @@
 int 		phaseerror(Fsstate*, char*);
 char		*phasename(Fsstate*, int, char*);
 void 		promptforhostowner(void);
-char		*readcons(char*, char*, int);
 int		replacekey(Key*, int before);
 char		*safecpy(char*, char*, int);
 Attr		*setattr(Attr*, char*, ...);
--- a/sys/src/cmd/auth/factotum/util.c
+++ b/sys/src/cmd/auth/factotum/util.c
@@ -687,22 +687,6 @@
 	return name;
 }
 
-static int
-outin(char *prompt, char *def, int len)
-{
-	char *s;
-
-	s = readcons(prompt, def, 0);
-	if(s == nil)
-		return -1;
-	if(s == nil)
-		sysfatal("s==nil???");
-	strncpy(def, s, len);
-	def[len-1] = 0;
-	free(s);
-	return strlen(def);
-}
-
 /*
  *  get host owner and set it
  */
@@ -709,109 +693,18 @@
 void
 promptforhostowner(void)
 {
-	char owner[64], *p;
+	char *p;
 
 	/* hack for bitsy; can't prompt during boot */
-	if(p = getenv("user")){
-		writehostowner(p);
+	p = getenv("user");
+	while(p == nil || *p == 0){
 		free(p);
-		return;
+		p = readcons("user", "glenda", 0);
+		if(p == nil)
+			return;
 	}
+	writehostowner(p);
 	free(p);
-
-	strcpy(owner, "glenda");
-	do{
-		outin("user", owner, sizeof(owner));
-	} while(*owner == 0);
-	writehostowner(owner);
-}
-
-char*
-estrappend(char *s, char *fmt, ...)
-{
-	char *t;
-	va_list arg;
-
-	va_start(arg, fmt);
-	t = vsmprint(fmt, arg);
-	if(t == nil)
-		sysfatal("out of memory");
-	va_end(arg);
-	s = erealloc(s, strlen(s)+strlen(t)+1);
-	strcat(s, t);
-	free(t);
-	return s;
-}
-
-
-/*
- *  prompt for a string with a possible default response
- */
-char*
-readcons(char *prompt, char *def, int raw)
-{
-	int fdin, fdout, ctl, n;
-	char line[10];
-	char *s;
-
-	fdin = open("/dev/cons", OREAD);
-	if(fdin < 0)
-		fdin = 0;
-	fdout = open("/dev/cons", OWRITE);
-	if(fdout < 0)
-		fdout = 1;
-	if(def != nil)
-		fprint(fdout, "%s[%s]: ", prompt, def);
-	else
-		fprint(fdout, "%s: ", prompt);
-	if(raw){
-		ctl = open("/dev/consctl", OWRITE);
-		if(ctl >= 0)
-			write(ctl, "rawon", 5);
-	} else
-		ctl = -1;
-	s = estrdup("");
-	for(;;){
-		n = read(fdin, line, 1);
-		if(n == 0){
-		Error:
-			close(fdin);
-			close(fdout);
-			if(ctl >= 0)
-				close(ctl);
-			free(s);
-			return nil;
-		}
-		if(n < 0)
-			goto Error;
-		if(line[0] == 0x7f)
-			goto Error;
-		if(n == 0 || line[0] == '\n' || line[0] == '\r'){
-			if(raw){
-				write(ctl, "rawoff", 6);
-				write(fdout, "\n", 1);
-			}
-			close(ctl);
-			close(fdin);
-			close(fdout);
-			if(*s == 0 && def != nil)
-				s = estrappend(s, "%s", def);
-			return s;
-		}
-		if(line[0] == '\b'){
-			if(strlen(s) > 0)
-				s[strlen(s)-1] = 0;
-		} else if(line[0] == 0x15) {	/* ^U: line kill */
-			if(def != nil)
-				fprint(fdout, "\n%s[%s]: ", prompt, def);
-			else
-				fprint(fdout, "\n%s: ", prompt);
-			
-			s[0] = 0;
-		} else {
-			s = estrappend(s, "%c", line[0]);
-		}
-	}
 }
 
 /*