diff options
author | Todd C. Miller <millert@cvs.openbsd.org> | 1996-09-27 20:40:18 +0000 |
---|---|---|
committer | Todd C. Miller <millert@cvs.openbsd.org> | 1996-09-27 20:40:18 +0000 |
commit | a802db671f203ab9196367db459b30104399987d (patch) | |
tree | bbe7cf1fdc42c02ead223e18c23b38315fe82bf1 /lib/libskey | |
parent | fa6a09b54e98c39000009800f494eba1b766707d (diff) |
Nicer echo on/off in its own function.
Diffstat (limited to 'lib/libskey')
-rw-r--r-- | lib/libskey/skeysubr.c | 58 |
1 files changed, 35 insertions, 23 deletions
diff --git a/lib/libskey/skeysubr.c b/lib/libskey/skeysubr.c index 9cd20eef327..6c3f9ea985a 100644 --- a/lib/libskey/skeysubr.c +++ b/lib/libskey/skeysubr.c @@ -10,7 +10,7 @@ * * S/KEY misc routines. * - * $Id: skeysubr.c,v 1.2 1996/09/27 15:39:00 millert Exp $ + * $Id: skeysubr.c,v 1.3 1996/09/27 20:40:17 millert Exp $ */ #include <stdio.h> @@ -31,11 +31,11 @@ static void trapped __ARGS((int sig)); static void f_MD4 __ARGS ((char *x)); static void f_MD5 __ARGS ((char *x)); +static void skey_echo __ARGS ((int)); static int keycrunch_MD4 __ARGS ((char *result, char *seed, char *passwd)); static int keycrunch_MD5 __ARGS ((char *result, char *seed, char *passwd)); static int skey_MDX = 0; -static int skey_echo; /* * Crunch a key: @@ -188,43 +188,37 @@ rip(buf) *buf = '\0'; } +/* Read in secret password (turns off echo) */ char * readpass(buf, n) char *buf; int n; { - struct termios term; void (*old_handler) __P(()); + /* Turn off echoing */ + skey_echo(0); + /* Catch SIGINT and save old signal handler */ old_handler = signal(SIGINT, trapped); - /* Turn off echoing */ - (void) tcgetattr(fileno(stdin), &term); - if ((skey_echo = (term.c_lflag & ECHO))) { - term.c_lflag &= ~ECHO; - (void)tcsetattr(fileno(stdin), TCSAFLUSH|TCSASOFT, &term); - } - (void)fgets(buf, n, stdin); rip(buf); (void)putc('\n', stderr); (void)fflush(stderr); - /* Restore echo and signal handler */ - if (skey_echo) { - term.c_lflag |= ECHO; - (void)tcsetattr(fileno(stdin), TCSAFLUSH|TCSASOFT, &term); - } + /* Restore signal handler and turn echo back on */ if (old_handler != SIG_ERR) (void)signal(SIGINT, old_handler); + skey_echo(1); sevenbit(buf); return buf; } +/* Read in an s/key OTP (does not turn off echo) */ char * readskey(buf, n) char *buf; @@ -241,6 +235,7 @@ readskey(buf, n) return buf; } +/* Signal handler for trapping ^C */ static void trapped(sig) int sig; @@ -248,14 +243,8 @@ trapped(sig) (void)fputs("^C\n", stderr); (void)fflush(stderr); - /* Turn on echo if we turned it off */ - if (skey_echo) { - struct termios term; - - (void) tcgetattr(fileno(stdin), &term); - term.c_lflag |= ECHO; - (void)tcsetattr(fileno(stdin), TCSAFLUSH|TCSASOFT, &term); - } + /* Turn on echo if necesary */ + skey_echo(1); exit(-1); } @@ -394,3 +383,26 @@ skey_get_MDX() return skey_MDX; } + +/* Turn echo on/off */ +static void +skey_echo(action) + int action; +{ + static struct termios term; + static int echo = 0; + + if (action == 0) { + /* Turn echo off */ + (void) tcgetattr(fileno(stdin), &term); + if ((echo = (term.c_lflag & ECHO))) { + term.c_lflag &= ~ECHO; + (void) tcsetattr(fileno(stdin), TCSAFLUSH|TCSASOFT, &term); + } + } else if (action && echo) { + /* Turn echo on */ + term.c_lflag |= ECHO; + (void) tcsetattr(fileno(stdin), TCSAFLUSH|TCSASOFT, &term); + echo = 0; + } +} |