X-Git-Url: https://asedeno.scripts.mit.edu/gitweb/?a=blobdiff_plain;f=unix%2Fuxcons.c;h=716f3fc533d653ccb0b6fa9751124d3df0a7d22f;hb=095072fa46b2d7b8beafaddb2f873d2f500a1e10;hp=abad00db0ef7a065460fd04a1496e9562874b422;hpb=bea758a7ae0507e0d4a24b370f8401661cc1a2c8;p=PuTTY.git diff --git a/unix/uxcons.c b/unix/uxcons.c index abad00db..716f3fc5 100644 --- a/unix/uxcons.c +++ b/unix/uxcons.c @@ -12,6 +12,10 @@ #include #include #include +#include +#ifndef HAVE_NO_SYS_SELECT_H +#include +#endif #include "putty.h" #include "storage.h" @@ -97,7 +101,9 @@ static int block_and_read(int fd, void *buf, size_t len) fd_set rfds; FD_ZERO(&rfds); FD_SET(fd, &rfds); - ret = select(fd+1, &rfds, NULL, NULL, NULL); + do { + ret = select(fd+1, &rfds, NULL, NULL, NULL); + } while (ret < 0 && errno == EINTR); assert(ret != 0); if (ret < 0) return ret; @@ -264,6 +270,59 @@ int askalg(void *frontend, const char *algtype, const char *algname, } } +int askhk(void *frontend, const char *algname, const char *betteralgs, + void (*callback)(void *ctx, int result), void *ctx) +{ + static const char msg[] = + "The first host key type we have stored for this server\n" + "is %s, which is below the configured warning threshold.\n" + "The server also provides the following types of host key\n" + "above the threshold, which we do not have stored:\n" + "%s\n" + "Continue with connection? (y/n) "; + static const char msg_batch[] = + "The first host key type we have stored for this server\n" + "is %s, which is below the configured warning threshold.\n" + "The server also provides the following types of host key\n" + "above the threshold, which we do not have stored:\n" + "%s\n" + "Connection abandoned.\n"; + static const char abandoned[] = "Connection abandoned.\n"; + + char line[32]; + struct termios cf; + + premsg(&cf); + if (console_batch_mode) { + fprintf(stderr, msg_batch, algname, betteralgs); + return 0; + } + + fprintf(stderr, msg, algname, betteralgs); + fflush(stderr); + + { + struct termios oldmode, newmode; + tcgetattr(0, &oldmode); + newmode = oldmode; + newmode.c_lflag |= ECHO | ISIG | ICANON; + tcsetattr(0, TCSANOW, &newmode); + line[0] = '\0'; + if (block_and_read(0, line, sizeof(line) - 1) <= 0) + /* handled below */; + tcsetattr(0, TCSANOW, &oldmode); + } + + if (line[0] == 'y' || line[0] == 'Y') { + postmsg(&cf); + return 1; + } else { + fprintf(stderr, abandoned); + postmsg(&cf); + return 0; + } +} + /* * Ask whether to wipe a session log file before writing to it. * Returns 2 for wipe, 1 for append, 0 for cancel (don't log).