r25678: reformat getpass() replacement code
authorStefan Metzmacher <metze@samba.org>
Wed, 17 Oct 2007 12:00:09 +0000 (14:00 +0200)
committerStefan Metzmacher <metze@samba.org>
Fri, 21 Dec 2007 04:43:10 +0000 (05:43 +0100)
metze
(cherry picked from commit 3e8f43e3cf97f10be4717978643ef3edca8650a5)
(This used to be commit 78da4477a7ef920ff77b41abb841465511b8db31)

source4/lib/replace/getpass.c

index f6a72ad86a2fc321fd0dbc8c81c9e90bfd070e5d..eb69e68f19ddfe4d0a76b57de68979d062b5d280 100644 (file)
@@ -140,69 +140,65 @@ static void catch_signal(int signum,void (*handler)(int ))
 
 char *getsmbpass(const char *prompt)
 {
-  FILE *in, *out;
-  int echo_off;
-  static char buf[256];
-  static size_t bufsize = sizeof(buf);
-  size_t nread;
-
-  /* Catch problematic signals */
-  catch_signal(SIGINT, SIGNAL_CAST SIG_IGN);
-
-  /* Try to write to and read from the terminal if we can.
-     If we can't open the terminal, use stderr and stdin.  */
-
-  in = fopen ("/dev/tty", "w+");
-  if (in == NULL)
-    {
-      in = stdin;
-      out = stderr;
-    }
-  else
-    out = in;
-
-  setvbuf(in, NULL, _IONBF, 0);
-
-  /* Turn echoing off if it is on now.  */
-
-  if (tcgetattr (fileno (in), &t) == 0)
-    {
-         if (ECHO_IS_ON(t))
-       {
-               TURN_ECHO_OFF(t);
-               echo_off = tcsetattr (fileno (in), TCSAFLUSH, &t) == 0;
-               TURN_ECHO_ON(t);
+       FILE *in, *out;
+       int echo_off;
+       static char buf[256];
+       static size_t bufsize = sizeof(buf);
+       size_t nread;
+
+       /* Catch problematic signals */
+       catch_signal(SIGINT, SIGNAL_CAST SIG_IGN);
+
+       /* Try to write to and read from the terminal if we can.
+               If we can't open the terminal, use stderr and stdin.  */
+
+       in = fopen ("/dev/tty", "w+");
+       if (in == NULL) {
+               in = stdin;
+               out = stderr;
+       } else {
+               out = in;
        }
-      else
-       echo_off = 0;
-    }
-  else
-    echo_off = 0;
-
-  /* Write the prompt.  */
-  fputs (prompt, out);
-  fflush (out);
-
-  /* Read the password.  */
-  buf[0] = 0;
-  fgets(buf, bufsize, in);
-  nread = strlen(buf);
-  if (buf[nread - 1] == '\n')
-    buf[nread - 1] = '\0';
-
-  /* Restore echoing.  */
-  if (echo_off)
-    (void) tcsetattr (fileno (in), TCSANOW, &t);
-
-  if (in != stdin)
-    /* We opened the terminal; now close it.  */
-    fclose (in);
-
-  /* Catch problematic signals */
-  catch_signal(SIGINT, SIGNAL_CAST SIG_DFL);
-
-  printf("\n");
-  return buf;
+
+       setvbuf(in, NULL, _IONBF, 0);
+
+       /* Turn echoing off if it is on now.  */
+
+       if (tcgetattr (fileno (in), &t) == 0) {
+               if (ECHO_IS_ON(t)) {
+                       TURN_ECHO_OFF(t);
+                       echo_off = tcsetattr (fileno (in), TCSAFLUSH, &t) == 0;
+                       TURN_ECHO_ON(t);
+               } else {
+                       echo_off = 0;
+               }
+       } else {
+               echo_off = 0;
+       }
+
+       /* Write the prompt.  */
+       fputs(prompt, out);
+       fflush(out);
+
+       /* Read the password.  */
+       buf[0] = 0;
+       fgets(buf, bufsize, in);
+       nread = strlen(buf);
+       if (buf[nread - 1] == '\n')
+               buf[nread - 1] = '\0';
+
+       /* Restore echoing.  */
+       if (echo_off)
+               tcsetattr (fileno (in), TCSANOW, &t);
+
+       if (in != stdin) /* We opened the terminal; now close it.  */
+               fclose(in);
+
+       /* Catch problematic signals */
+       catch_signal(SIGINT, SIGNAL_CAST SIG_DFL);
+
+       printf("\n");
+       return buf;
 }
 
 #else