You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@apr.apache.org by fu...@apache.org on 2011/02/15 12:38:59 UTC
svn commit: r1070850 - /apr/apr/branches/0.9.x/passwd/apr_getpass.c
Author: fuankg
Date: Tue Feb 15 11:38:59 2011
New Revision: 1070850
URL: http://svn.apache.org/viewvc?rev=1070850&view=rev
Log:
Backport of r454774, r467596, r663342, r663941.
Modified:
apr/apr/branches/0.9.x/passwd/apr_getpass.c
Modified: apr/apr/branches/0.9.x/passwd/apr_getpass.c
URL: http://svn.apache.org/viewvc/apr/apr/branches/0.9.x/passwd/apr_getpass.c?rev=1070850&r1=1070849&r2=1070850&view=diff
==============================================================================
--- apr/apr/branches/0.9.x/passwd/apr_getpass.c (original)
+++ apr/apr/branches/0.9.x/passwd/apr_getpass.c Tue Feb 15 11:38:59 2011
@@ -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;
}