X-Git-Url: https://asedeno.scripts.mit.edu/gitweb/?a=blobdiff_plain;f=unix%2Fuxcons.c;h=abad00db0ef7a065460fd04a1496e9562874b422;hb=48eafd66aa274c32fc8169a0d36619663905c210;hp=73126c021b5024cf475aef8ed99d4ebbf309f472;hpb=f030975da7bb38c196caa936ccf8c33ec8437654;p=PuTTY.git diff --git a/unix/uxcons.c b/unix/uxcons.c index 73126c02..abad00db 100644 --- a/unix/uxcons.c +++ b/unix/uxcons.c @@ -7,6 +7,7 @@ #include #include #include +#include #include #include @@ -70,12 +71,44 @@ void notify_remote_exit(void *frontend) { } -void timer_change_notify(long next) +void timer_change_notify(unsigned long next) { } -int verify_ssh_host_key(void *frontend, char *host, int port, char *keytype, - char *keystr, char *fingerprint, +/* + * Wrapper around Unix read(2), suitable for use on a file descriptor + * that's been set into nonblocking mode. Handles EAGAIN/EWOULDBLOCK + * by means of doing a one-fd select and then trying again; all other + * errors (including errors from select) are returned to the caller. + */ +static int block_and_read(int fd, void *buf, size_t len) +{ + int ret; + + while ((ret = read(fd, buf, len)) < 0 && ( +#ifdef EAGAIN + (errno == EAGAIN) || +#endif +#ifdef EWOULDBLOCK + (errno == EWOULDBLOCK) || +#endif + 0)) { + + fd_set rfds; + FD_ZERO(&rfds); + FD_SET(fd, &rfds); + ret = select(fd+1, &rfds, NULL, NULL, NULL); + assert(ret != 0); + if (ret < 0) + return ret; + assert(FD_ISSET(fd, &rfds)); + } + + return ret; +} + +int verify_ssh_host_key(void *frontend, char *host, int port, + const char *keytype, char *keystr, char *fingerprint, void (*callback)(void *ctx, int result), void *ctx) { int ret; @@ -163,7 +196,7 @@ int verify_ssh_host_key(void *frontend, char *host, int port, char *keytype, newmode.c_lflag |= ECHO | ISIG | ICANON; tcsetattr(0, TCSANOW, &newmode); line[0] = '\0'; - if (read(0, line, sizeof(line) - 1) <= 0) + if (block_and_read(0, line, sizeof(line) - 1) <= 0) /* handled below */; tcsetattr(0, TCSANOW, &oldmode); } @@ -216,7 +249,7 @@ int askalg(void *frontend, const char *algtype, const char *algname, newmode.c_lflag |= ECHO | ISIG | ICANON; tcsetattr(0, TCSANOW, &newmode); line[0] = '\0'; - if (read(0, line, sizeof(line) - 1) <= 0) + if (block_and_read(0, line, sizeof(line) - 1) <= 0) /* handled below */; tcsetattr(0, TCSANOW, &oldmode); } @@ -270,7 +303,7 @@ int askappend(void *frontend, Filename *filename, newmode.c_lflag |= ECHO | ISIG | ICANON; tcsetattr(0, TCSANOW, &newmode); line[0] = '\0'; - if (read(0, line, sizeof(line) - 1) <= 0) + if (block_and_read(0, line, sizeof(line) - 1) <= 0) /* handled below */; tcsetattr(0, TCSANOW, &oldmode); } @@ -364,7 +397,8 @@ static void console_prompt_text(FILE *outfp, const char *data, int len) fflush(outfp); } -int console_get_userpass_input(prompts_t *p, unsigned char *in, int inlen) +int console_get_userpass_input(prompts_t *p, const unsigned char *in, + int inlen) { size_t curr_prompt; FILE *outfp = NULL;