summaryrefslogtreecommitdiff
path: root/source3
diff options
context:
space:
mode:
authorStefan Metzmacher <metze@samba.org>2007-10-05 15:55:19 +0200
committerStefan Metzmacher <metze@samba.org>2007-10-15 13:20:39 +0200
commit7fedf44effb5fab80e64764019f9e66f256376d3 (patch)
treee701198207724e109749191c78ed62eca9249be0 /source3
parent2ecbed36b22e7147462018d9bcbe8e45d85a45c2 (diff)
downloadsamba-7fedf44effb5fab80e64764019f9e66f256376d3.tar.gz
samba-7fedf44effb5fab80e64764019f9e66f256376d3.tar.bz2
samba-7fedf44effb5fab80e64764019f9e66f256376d3.zip
reformat getpass() replacement code
metze (This used to be commit 3e8f43e3cf97f10be4717978643ef3edca8650a5)
Diffstat (limited to 'source3')
-rw-r--r--source3/lib/replace/getpass.c120
1 files changed, 58 insertions, 62 deletions
diff --git a/source3/lib/replace/getpass.c b/source3/lib/replace/getpass.c
index f6a72ad86a..eb69e68f19 100644
--- a/source3/lib/replace/getpass.c
+++ b/source3/lib/replace/getpass.c
@@ -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