vnc: don't prompt for password on auth_respond() failure
This commit is contained in:
parent
5d353d62fe
commit
5cc1cb1820
1 changed files with 3 additions and 100 deletions
|
@ -4,10 +4,6 @@
|
|||
|
||||
char *serveraddr;
|
||||
|
||||
/*
|
||||
* Encrypt n bytes using the password
|
||||
* as key, padded with zeros to 8 bytes.
|
||||
*/
|
||||
enum
|
||||
{
|
||||
VerLen = 12
|
||||
|
@ -15,97 +11,6 @@ enum
|
|||
|
||||
static char version[VerLen+1] = "RFB 003.003\n";
|
||||
|
||||
static uchar tab[256];
|
||||
|
||||
/* VNC reverses the bits of each byte before using as a des key */
|
||||
static void
|
||||
mktab(void)
|
||||
{
|
||||
int i, j, k;
|
||||
static int once;
|
||||
|
||||
if(once)
|
||||
return;
|
||||
once = 1;
|
||||
|
||||
for(i=0; i<256; i++){
|
||||
j=i;
|
||||
tab[i] = 0;
|
||||
for(k=0; k<8; k++){
|
||||
tab[i] = (tab[i]<<1) | (j&1);
|
||||
j >>= 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
vncencrypt(uchar *buf, int n, char *pw)
|
||||
{
|
||||
uchar *p;
|
||||
uchar key[9];
|
||||
DESstate s;
|
||||
|
||||
mktab();
|
||||
memset(key, 0, sizeof key);
|
||||
strncpy((char*)key, pw, 8);
|
||||
for(p=key; *p; p++)
|
||||
*p = tab[*p];
|
||||
|
||||
setupDESstate(&s, key, nil);
|
||||
desECBencrypt(buf, n, &s);
|
||||
}
|
||||
|
||||
static int
|
||||
readln(char *prompt, char *line, int len)
|
||||
{
|
||||
char *p;
|
||||
int fd, ctl, n, nr;
|
||||
|
||||
fd = open("/dev/cons", ORDWR);
|
||||
if(fd < 0)
|
||||
sysfatal("couldn't open cons");
|
||||
ctl = open("/dev/consctl", OWRITE);
|
||||
if(ctl < 0)
|
||||
sysfatal("couldn't open consctl");
|
||||
write(ctl, "rawon", 5);
|
||||
fprint(fd, "%s", prompt);
|
||||
nr = 0;
|
||||
p = line;
|
||||
for(;;){
|
||||
n = read(fd, p, 1);
|
||||
if(n < 0){
|
||||
close(fd);
|
||||
close(ctl);
|
||||
return -1;
|
||||
}
|
||||
if(n == 0 || *p == '\n' || *p == '\r'){
|
||||
*p = '\0';
|
||||
write(fd, "\n", 1);
|
||||
close(fd);
|
||||
close(ctl);
|
||||
return nr;
|
||||
}
|
||||
if(*p == '\b'){
|
||||
if(nr > 0){
|
||||
nr--;
|
||||
p--;
|
||||
}
|
||||
}else if(*p == 21){ /* cntrl-u */
|
||||
fprint(fd, "\n%s", prompt);
|
||||
nr = 0;
|
||||
p = line;
|
||||
}else{
|
||||
nr++;
|
||||
p++;
|
||||
}
|
||||
if(nr == len){
|
||||
fprint(fd, "line too long; try again\n%s", prompt);
|
||||
nr = 0;
|
||||
p = line;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
vncsrvhandshake(Vnc *v)
|
||||
{
|
||||
|
@ -145,7 +50,7 @@ vnchandshake(Vnc *v)
|
|||
int
|
||||
vncauth(Vnc *v, char *keypattern)
|
||||
{
|
||||
char pw[128], *reason;
|
||||
char *reason;
|
||||
uchar chal[VncChalLen];
|
||||
ulong auth;
|
||||
char *p, *server;
|
||||
|
@ -180,10 +85,8 @@ vncauth(Vnc *v, char *keypattern)
|
|||
*p = 0;
|
||||
if(auth_respond(chal, VncChalLen, nil, 0, chal, VncChalLen, auth_getkey,
|
||||
"proto=vnc role=client server=%s %s", server, keypattern) != VncChalLen){
|
||||
/* BUG This is for drawterm users who don't start their own factotums */
|
||||
readln("password: ", pw, sizeof(pw));
|
||||
vncencrypt(chal, VncChalLen, pw);
|
||||
memset(pw, 0, sizeof pw);
|
||||
free(server);
|
||||
return -1;
|
||||
}
|
||||
free(server);
|
||||
vncwrbytes(v, chal, VncChalLen);
|
||||
|
|
Loading…
Reference in a new issue