summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGuenter Knauf <fuankg@apache.org>2011-02-15 11:38:59 +0000
committerGuenter Knauf <fuankg@apache.org>2011-02-15 11:38:59 +0000
commit82788c6010a207261b43ca916911d72e96f54805 (patch)
treef71f0e4216fce504169575582f1e9d4586a98227
parent7eade706f61e1decce800995a6d9f8c2f069b18f (diff)
downloadapr-82788c6010a207261b43ca916911d72e96f54805.tar.gz
Backport of r454774, r467596, r663342, r663941.
git-svn-id: https://svn.apache.org/repos/asf/apr/apr/branches/0.9.x@1070850 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r--passwd/apr_getpass.c41
1 files changed, 28 insertions, 13 deletions
diff --git a/passwd/apr_getpass.c b/passwd/apr_getpass.c
index 723532d5f..be32d417e 100644
--- a/passwd/apr_getpass.c
+++ b/passwd/apr_getpass.c
@@ -48,6 +48,12 @@
#include <strings.h>
#endif
+/* Disable getpass() support when PASS_MAX is defined and is "small",
+ * for an arbitrary definition of "small". */
+#if defined(HAVE_GETPASS) && defined(PASS_MAX) && PASS_MAX < 32
+#undef HAVE_GETPASS
+#endif
+
#if defined(HAVE_TERMIOS_H) && !defined(HAVE_GETPASS)
#include <termios.h>
#endif
@@ -64,7 +70,7 @@
#define ERR_OVERFLOW 5
-#ifndef HAVE_GETPASS
+#if !defined(HAVE_GETPASS) && !defined(HAVE_GETPASSPHRASE) && !defined(HAVE_GETPASS_R)
/* MPE, Win32, NetWare and BeOS all lack a native getpass() */
@@ -74,7 +80,7 @@
* issue the prompt and read the results with echo. (Ugh).
*/
-static char *getpass(const char *prompt)
+static char *get_password(const char *prompt)
{
static char password[MAX_STRING_LEN];
@@ -87,7 +93,7 @@ static char *getpass(const char *prompt)
#elif defined (HAVE_TERMIOS_H)
#include <stdio.h>
-static char *getpass(const char *prompt)
+static char *get_password(const char *prompt)
{
struct termios attr;
static char password[MAX_STRING_LEN];
@@ -129,7 +135,7 @@ static char *getpass(const char *prompt)
* Windows lacks getpass(). So we'll re-implement it here.
*/
-static char *getpass(const char *prompt)
+static char *get_password(const char *prompt)
{
/* WCE lacks console. So the getpass is unsuported
* The only way is to use the GUI so the getpass should be implemented
@@ -196,11 +202,11 @@ static char *getpass(const char *prompt)
#endif /* no getchar or _getch */
-#endif /* no getpass */
+#endif /* no getpass or getpassphrase or getpass_r */
/*
- * Use the OS getpass() routine (or our own) to obtain a password from
- * the input stream.
+ * Use the OS getpass() / getpass_r() / getpassphrase() routine (or our own)
+ * to obtain a password from the input stream.
*
* Exit values:
* 0: Success
@@ -215,18 +221,27 @@ static char *getpass(const char *prompt)
APR_DECLARE(apr_status_t) apr_password_get(const char *prompt, char *pwbuf, apr_size_t *bufsiz)
{
-#ifdef HAVE_GETPASSPHRASE
- char *pw_got = getpassphrase(prompt);
+ apr_status_t rv = APR_SUCCESS;
+#if defined(HAVE_GETPASS_R)
+ if (getpass_r(prompt, pwbuf, *bufsiz) == NULL)
+ return APR_EINVAL;
#else
+#if defined(HAVE_GETPASSPHRASE)
+ char *pw_got = getpassphrase(prompt);
+#elif defined(HAVE_GETPASS)
char *pw_got = getpass(prompt);
+#else /* use the replacement implementation above */
+ char *pw_got = get_password(prompt);
#endif
+
if (!pw_got)
return APR_EINVAL;
- apr_cpystrn(pwbuf, pw_got, *bufsiz);
- memset(pw_got, 0, strlen(pw_got));
if (strlen(pw_got) >= *bufsiz) {
- return APR_ENAMETOOLONG;
+ rv = APR_ENAMETOOLONG;
}
- return APR_SUCCESS;
+ apr_cpystrn(pwbuf, pw_got, *bufsiz);
+ memset(pw_got, 0, strlen(pw_got));
+#endif /* HAVE_GETPASS_R */
+ return rv;
}