From: John Kohl Date: Thu, 18 Jan 1990 14:24:59 +0000 (+0000) Subject: add signal handling and recovery (SIGINT only) X-Git-Tag: krb5-1.0-alpha2~1262 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=0d08bc704d8c1586d180173a9abab909a95e2033;p=krb5.git add signal handling and recovery (SIGINT only) git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@120 dc483132-0cff-0310-8789-dd5450dbe970 --- diff --git a/src/lib/krb5/os/read_pwd.c b/src/lib/krb5/os/read_pwd.c index 4437cfcf9..b306ad009 100644 --- a/src/lib/krb5/os/read_pwd.c +++ b/src/lib/krb5/os/read_pwd.c @@ -23,6 +23,8 @@ static char rcsid_read_pwd_c[] = #include #include #include +#include +#include #ifdef __STDC__ #include @@ -30,9 +32,23 @@ static char rcsid_read_pwd_c[] = char *malloc(), *index(); #endif +#ifdef POSIX +#define sigtype void +#else +#define sigtype int +#endif /* POSIX */ + extern int errno; -#define cleanup(errcode) ioctl(0, TIOCSETP, (char *)&tty_savestate); return errcode; +#define cleanup(errcode) (void) signal(SIGINT, ointrfunc); ioctl(0, TIOCSETP, (char *)&tty_savestate); return errcode; + +static jmp_buf pwd_jump; + +sigtype +intr_routine() +{ + longjmp(pwd_jump, 1); +} krb5_error_code krb5_read_password(prompt, prompt2, return_pwd, size_return) @@ -44,9 +60,10 @@ int size_return; /* adapted from Kerberos v4 des/read_password.c */ struct sgttyb tty_state, tty_savestate; - char *readin_string; + char *readin_string = 0; register char *ptr; int scratchchar; + sigtype (*ointrfunc)(); /* save terminal state */ if (ioctl(0,TIOCGETP,(char *)&tty_savestate) == -1) @@ -58,6 +75,18 @@ int size_return; if (ioctl(0,TIOCSETP,(char *)&tty_state) == -1) return errno; + if (setjmp(pwd_jump)) { + /* interrupted */ + if (readin_string) { + (void) bzero(readin_string, size_return); + free(readin_string); + } + (void) bzero(return_pwd, size_return); + cleanup(KRB5_LIBOS_PWDINTR); + } + /* save intrfunc */ + ointrfunc = signal(SIGINT, intr_routine); + /* put out the prompt */ (void) fputs(prompt,stdout); (void) fflush(stdout); @@ -113,8 +142,12 @@ int size_return; free(readin_string); } + /* reset intrfunc */ + (void) signal(SIGINT, ointrfunc); + if (ioctl(0, TIOCSETP, (char *)&tty_savestate) == -1) return errno; + return 0; }