auth/factotum: use common readcons() function from libauthsrv
This commit is contained in:
parent
cf37a1010f
commit
ae5fb4ab78
2 changed files with 7 additions and 117 deletions
|
@ -194,8 +194,6 @@ int canusekey(Fsstate*, Key*);
|
|||
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 @@ char *mkcap(char*, char*);
|
|||
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*, ...);
|
||||
|
|
|
@ -687,131 +687,24 @@ phasename(Fsstate *fss, int phase, char *tmp)
|
|||
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
|
||||
*/
|
||||
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);
|
||||
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]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
Loading…
Reference in a new issue