summaryrefslogtreecommitdiff
path: root/passwd
diff options
context:
space:
mode:
authorrjung <rjung@13f79535-47bb-0310-9956-ffa450edef68>2013-10-03 15:22:13 +0000
committerrjung <rjung@13f79535-47bb-0310-9956-ffa450edef68>2013-10-03 15:22:13 +0000
commited29e486063a28c2ab2c7d592b66b9b3da63a73a (patch)
tree618106188c2c110476be051746efa8689612beef /passwd
parentbae7d08870e9a1aa7a8b499c475dc961acf097c3 (diff)
downloadlibapr-ed29e486063a28c2ab2c7d592b66b9b3da63a73a.tar.gz
Restructure to ensure successful mingw compilation, stdio seems very popular, too
Backport of r892159 from trunk. Restore getpassword == getpass_r hack for older Novell NDKs. partial revert of r892141 Backport of r892909 from trunk. git-svn-id: http://svn.apache.org/repos/asf/apr/apr/branches/1.5.x@1528908 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'passwd')
-rw-r--r--passwd/apr_getpass.c86
1 files changed, 44 insertions, 42 deletions
diff --git a/passwd/apr_getpass.c b/passwd/apr_getpass.c
index f31cdafc5..6e4cbef3a 100644
--- a/passwd/apr_getpass.c
+++ b/passwd/apr_getpass.c
@@ -51,6 +51,9 @@
#if APR_HAVE_STRINGS_H
#include <strings.h>
#endif
+#if APR_HAVE_STDIO_H
+#include <stdio.h>
+#endif
/* Disable getpass() support when PASS_MAX is defined and is "small",
* for an arbitrary definition of "small".
@@ -80,9 +83,9 @@
#if !defined(HAVE_GETPASS) && !defined(HAVE_GETPASSPHRASE) && !defined(HAVE_GETPASS_R)
-/* MPE, Win32, NetWare and BeOS all lack a native getpass() */
+/* MPE, Win32, and BeOS all lack a native getpass() */
-#if !defined(HAVE_TERMIOS_H) && !defined(WIN32) && !defined(NETWARE)
+#if !defined(HAVE_TERMIOS_H) && !defined(WIN32)
/*
* MPE lacks getpass() and a way to suppress stdin echo. So for now, just
* issue the prompt and read the results with echo. (Ugh).
@@ -98,46 +101,7 @@ static char *get_password(const char *prompt)
return (char *) &password;
}
-#elif defined (HAVE_TERMIOS_H)
-#include <stdio.h>
-
-static char *get_password(const char *prompt)
-{
- struct termios attr;
- static char password[MAX_STRING_LEN];
- int n=0;
- fputs(prompt, stderr);
- fflush(stderr);
-
- if (tcgetattr(STDIN_FILENO, &attr) != 0)
- return NULL;
- attr.c_lflag &= ~(ECHO);
-
- if (tcsetattr(STDIN_FILENO, TCSAFLUSH, &attr) != 0)
- return NULL;
- while ((password[n] = getchar()) != '\n') {
- if (n < sizeof(password) - 1 && password[n] >= ' ' && password[n] <= '~') {
- n++;
- } else {
- fprintf(stderr,"\n");
- fputs(prompt, stderr);
- fflush(stderr);
- n = 0;
- }
- }
-
- password[n] = '\0';
- printf("\n");
- if (n > (MAX_STRING_LEN - 1)) {
- password[MAX_STRING_LEN - 1] = '\0';
- }
-
- attr.c_lflag |= ECHO;
- tcsetattr(STDIN_FILENO, TCSANOW, &attr);
- return (char*) &password;
-}
-
-#else
+#elif defined(WIN32)
/*
* Windows lacks getpass(). So we'll re-implement it here.
@@ -208,6 +172,44 @@ static char *get_password(const char *prompt)
#endif
}
+#elif defined (HAVE_TERMIOS_H)
+
+static char *get_password(const char *prompt)
+{
+ struct termios attr;
+ static char password[MAX_STRING_LEN];
+ int n=0;
+ fputs(prompt, stderr);
+ fflush(stderr);
+
+ if (tcgetattr(STDIN_FILENO, &attr) != 0)
+ return NULL;
+ attr.c_lflag &= ~(ECHO);
+
+ if (tcsetattr(STDIN_FILENO, TCSAFLUSH, &attr) != 0)
+ return NULL;
+ while ((password[n] = getchar()) != '\n') {
+ if (n < sizeof(password) - 1 && password[n] >= ' ' && password[n] <= '~') {
+ n++;
+ } else {
+ fprintf(stderr,"\n");
+ fputs(prompt, stderr);
+ fflush(stderr);
+ n = 0;
+ }
+ }
+
+ password[n] = '\0';
+ printf("\n");
+ if (n > (MAX_STRING_LEN - 1)) {
+ password[MAX_STRING_LEN - 1] = '\0';
+ }
+
+ attr.c_lflag |= ECHO;
+ tcsetattr(STDIN_FILENO, TCSANOW, &attr);
+ return (char*) &password;
+}
+
#endif /* no getchar or _getch */
#endif /* no getpass or getpassphrase or getpass_r */