]> Pileus Git - ~andy/fetchmail/blobdiff - getpass.c
Credit John Beck's fixes.
[~andy/fetchmail] / getpass.c
index c2f8d140a96332d954085fa45970a101133e0938..3c19ba7c832fb9f3825c3b98c6d29e7cd5024351 100644 (file)
--- a/getpass.c
+++ b/getpass.c
@@ -9,7 +9,7 @@
   description:         getpass() replacement which allows for long passwords.
                 This version hacked by Wilfred Teiken, allowing the
                 password to be piped to fetchmail.
-
  ***********************************************************************/
 
 #include "config.h"
 #include <stdio.h>
 #include <signal.h>
 #include <fcntl.h>
+#include <stdlib.h>
 #if defined(HAVE_UNISTD_H)
 #include <unistd.h>
 #endif
 #include "fetchmail.h"
+#include "i18n.h"
 
 #define INPUT_BUF_SIZE PASSWORDLEN
 
@@ -54,35 +56,31 @@ static int ttyfd;
 #endif
 #endif
 
-void save_tty_state();
-void disable_tty_echo();
-void restore_tty_state();
+static void save_tty_state(void);
+static void disable_tty_echo(void);
+static void restore_tty_state(void);
+static RETSIGTYPE sigint_handler(int);
 
-char *getpassword(prompt)
-char *prompt;
+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);
+    fputs(GT_("ERROR: no support for getpassword() routine\n"),stderr);
     exit(1);
 #endif
-
-#endif /* !(defined(HAVE_TCSETATTR) || ... */
-
+#else
     register char *p;
-    register c;
+    register int c;
     FILE *fi;
     static char pbuf[INPUT_BUF_SIZE];
-    RETSIGTYPE (*sig)();
-    RETSIGTYPE sigint_handler();
-    int istty = (tcgetpgrp(0) != -1);
+    SIGHANDLERTYPE sig = 0;    /* initialization pacifies -Wall */
 
-    /* get the file descriptor for the input device */
+    int istty = isatty(0);
 
+    /* get the file descriptor for the actual input device if it's a tty */
     if (istty)
     {
        if ((fi = fdopen(open("/dev/tty", 2), "r")) == NULL)
@@ -103,7 +101,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();
@@ -129,17 +127,16 @@ 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) || ... */
 }
 
-
-void
-save_tty_state ()
+static void save_tty_state (void)
 {
 #if defined(HAVE_TCSETATTR)
     tcgetattr(ttyfd, &termb);
@@ -155,9 +152,7 @@ save_tty_state ()
 #endif
 }
 
-
-void
-disable_tty_echo() 
+static void disable_tty_echo(void) 
 {
     /* turn off echo on the tty */
 #if defined(HAVE_TCSETATTR)
@@ -174,10 +169,7 @@ disable_tty_echo()
 #endif
 }
 
-
-
-void
-restore_tty_state()
+static void restore_tty_state(void)
 {
     /* restore previous tty echo state */
 #if defined(HAVE_TCSETATTR)
@@ -194,9 +186,12 @@ restore_tty_state()
 #endif
 }
 
-
-RETSIGTYPE sigint_handler()
+static RETSIGTYPE 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 */