X-Git-Url: http://pileus.org/git/?a=blobdiff_plain;f=getpass.c;h=c1624299eb43d75a494420ce7694c83aa0f93903;hb=87bcf29364c4640edb87cc2186b965d1a564d70c;hp=dc6ea426966475744337f9000c2b736b7b01862e;hpb=acb741c73356b37fbc9dac0ffb7739cc63170433;p=~andy%2Ffetchmail diff --git a/getpass.c b/getpass.c index dc6ea426..c1624299 100644 --- a/getpass.c +++ b/getpass.c @@ -17,67 +17,32 @@ #include #include #include -#if defined(HAVE_UNISTD_H) +#include #include -#endif #include "fetchmail.h" -#include "i18n.h" +#include "gettext.h" #define INPUT_BUF_SIZE PASSWORDLEN -#if defined(HAVE_TERMIOS_H) && defined(HAVE_TCSETATTR) -# include -#else -#if defined(HAVE_TERMIO_H) -# include -# include -#else -#if defined(HAVE_SGTTY_H) -# include -#endif -#endif -#endif +#include static int ttyfd; -#if defined(HAVE_TCSETATTR) - static struct termios termb; - static tcflag_t flags; -#else -#if defined(HAVE_TERMIO_H) - static struct termio termb; - static unsigned short flags; -#else -#if defined(HAVE_STTY) - static struct sgttyb ttyb; - static int flags; -#endif -#endif -#endif - -void static save_tty_state(void); -void static disable_tty_echo(void); -void static restore_tty_state(void); -static RETSIGTYPE sigint_handler(int); - -char *getpassword(prompt) -char *prompt; +static struct termios termb; +static tcflag_t flags; + +static void save_tty_state(void); +static void disable_tty_echo(void); +static void restore_tty_state(void); +static void sigint_handler(int); + +char *fm_getpassword(char *prompt) { -#if !(defined(HAVE_TCSETATTR) || defined(HAVE_TERMIO_H) || defined(HAVE_STTY)) -#if defined(HAVE_GETPASS) - char *getpass(); - return getpass(prompt); -#else - fputs(_("ERROR: no support for getpassword() routine\n"),stderr); - exit(1); -#endif -#else register char *p; register int c; FILE *fi; static char pbuf[INPUT_BUF_SIZE]; - RETSIGTYPE (*sig)(int) = 0; /* initialization pacifies -Wall */ - RETSIGTYPE sigint_handler(int); + SIGHANDLERTYPE sig = 0; /* initialization pacifies -Wall */ int istty = isatty(0); @@ -102,7 +67,7 @@ char *prompt; /* now that we have the current tty state, we can catch SIGINT and exit gracefully */ - sig = signal(SIGINT, sigint_handler); + sig = set_signal_handler(SIGINT, sigint_handler); /* turn off echo on the tty */ disable_tty_echo(); @@ -128,69 +93,40 @@ char *prompt; restore_tty_state(); /* restore previous state of SIGINT */ - signal(SIGINT, sig); + set_signal_handler(SIGINT, sig); } if (fi != stdin) - fclose(fi); + fclose(fi); /* not checking should be safe, file mode was "r" */ return(pbuf); -#endif /* !(defined(HAVE_TCSETATTR) || ... */ } static void save_tty_state (void) { -#if defined(HAVE_TCSETATTR) tcgetattr(ttyfd, &termb); flags = termb.c_lflag; -#else -#if defined(HAVE_TERMIO_H) - ioctl(ttyfd, TCGETA, (char *) &termb); - flags = termb.c_lflag; -#else /* we HAVE_STTY */ - gtty(ttyfd, &ttyb); - flags = ttyb.sg_flags; -#endif -#endif } static void disable_tty_echo(void) { /* turn off echo on the tty */ -#if defined(HAVE_TCSETATTR) termb.c_lflag &= ~ECHO; tcsetattr(ttyfd, TCSAFLUSH, &termb); -#else -#if defined(HAVE_TERMIO_H) - termb.c_lflag &= ~ECHO; - ioctl(ttyfd, TCSETA, (char *) &termb); -#else /* we HAVE_STTY */ - ttyb.sg_flags &= ~ECHO; - stty(ttyfd, &ttyb); -#endif -#endif } static void restore_tty_state(void) { /* restore previous tty echo state */ -#if defined(HAVE_TCSETATTR) termb.c_lflag = flags; tcsetattr(ttyfd, TCSAFLUSH, &termb); -#else -#if defined(HAVE_TERMIO_H) - termb.c_lflag = flags; - ioctl(ttyfd, TCSETA, (char *) &termb); -#else /* we HAVE_STTY */ - ttyb.sg_flags = flags; - stty(ttyfd, &ttyb); -#endif -#endif } -static RETSIGTYPE sigint_handler(int signum) +static void sigint_handler(int signum) { + (void)signum; restore_tty_state(); - error(1, 0, _("\nCaught signal... bailing out.")); + report(stderr, GT_("\nCaught SIGINT... bailing out.\n")); + exit(1); } /* getpass.c ends here */