Use getpassphrase() instead of getpass() if available.

This commit is contained in:
Kurt Zeilenga 2000-05-19 18:41:26 +00:00
parent 72db2b73dc
commit 8045b54124
11 changed files with 48 additions and 31 deletions

View file

@ -318,7 +318,7 @@ main( int argc, char **argv )
} }
if (want_bindpw) if (want_bindpw)
passwd.bv_val = getpass("Enter LDAP Password: "); passwd.bv_val = getpassphrase("Enter LDAP Password: ");
passwd.bv_len = strlen( passwd.bv_val ); passwd.bv_len = strlen( passwd.bv_val );
if ( authmethod == LDAP_AUTH_SASL ) { if ( authmethod == LDAP_AUTH_SASL ) {

View file

@ -382,7 +382,7 @@ main( int argc, char **argv )
} }
if (want_bindpw) if (want_bindpw)
passwd.bv_val = getpass("Enter LDAP Password: "); passwd.bv_val = getpassphrase("Enter LDAP Password: ");
passwd.bv_len = strlen( passwd.bv_val ); passwd.bv_len = strlen( passwd.bv_val );
if ( authmethod == LDAP_AUTH_SASL ) { if ( authmethod == LDAP_AUTH_SASL ) {

View file

@ -365,7 +365,7 @@ main(int argc, char **argv)
} }
if (want_bindpw) if (want_bindpw)
passwd.bv_val = getpass("Enter LDAP Password: "); passwd.bv_val = getpassphrase("Enter LDAP Password: ");
passwd.bv_len = strlen( passwd.bv_val ); passwd.bv_len = strlen( passwd.bv_val );
if ( authmethod == LDAP_AUTH_SASL ) { if ( authmethod == LDAP_AUTH_SASL ) {

View file

@ -246,8 +246,8 @@ main( int argc, char *argv[] )
if( want_oldpw && oldpw == NULL ) { if( want_oldpw && oldpw == NULL ) {
/* prompt for old password */ /* prompt for old password */
char *ckoldpw; char *ckoldpw;
newpw = strdup(getpass("Old password: ")); newpw = strdup(getpassphrase("Old password: "));
ckoldpw = getpass("Re-enter old password: "); ckoldpw = getpassphrase("Re-enter old password: ");
if( strncmp( oldpw, ckoldpw, strlen(oldpw) )) { if( strncmp( oldpw, ckoldpw, strlen(oldpw) )) {
fprintf( stderr, "passwords do not match\n" ); fprintf( stderr, "passwords do not match\n" );
@ -258,8 +258,8 @@ main( int argc, char *argv[] )
if( want_newpw && newpw == NULL ) { if( want_newpw && newpw == NULL ) {
/* prompt for new password */ /* prompt for new password */
char *cknewpw; char *cknewpw;
newpw = strdup(getpass("New password: ")); newpw = strdup(getpassphrase("New password: "));
cknewpw = getpass("Re-enter new password: "); cknewpw = getpassphrase("Re-enter new password: ");
if( strncmp( newpw, cknewpw, strlen(newpw) )) { if( strncmp( newpw, cknewpw, strlen(newpw) )) {
fprintf( stderr, "passwords do not match\n" ); fprintf( stderr, "passwords do not match\n" );
@ -280,7 +280,7 @@ main( int argc, char *argv[] )
if (want_bindpw && passwd.bv_val == NULL ) { if (want_bindpw && passwd.bv_val == NULL ) {
/* handle bind password */ /* handle bind password */
fprintf( stderr, "Bind DN: %s\n", binddn ); fprintf( stderr, "Bind DN: %s\n", binddn );
passwd.bv_val = strdup( getpass("Enter bind password: ")); passwd.bv_val = strdup( getpassphrase("Enter bind password: "));
passwd.bv_len = strlen( passwd.bv_val ); passwd.bv_len = strlen( passwd.bv_val );
} }

View file

@ -521,7 +521,7 @@ main( int argc, char **argv )
} }
if (want_bindpw) { if (want_bindpw) {
passwd.bv_val = getpass("Enter LDAP Password: "); passwd.bv_val = getpassphrase("Enter LDAP Password: ");
passwd.bv_len = strlen( passwd.bv_val ); passwd.bv_len = strlen( passwd.bv_val );
} }

View file

@ -50,7 +50,7 @@ int
auth( char *who, int implicit ) auth( char *who, int implicit )
{ {
int rc; /* return code from ldap_bind() */ int rc; /* return code from ldap_bind() */
char *passwd = NULL; /* returned by getpass() */ char *passwd = NULL; /* returned by getpassphrase() */
char **rdns; /* for fiddling with the DN */ char **rdns; /* for fiddling with the DN */
int authmethod; int authmethod;
int name_provided; /* was a name passed in? */ int name_provided; /* was a name passed in? */
@ -241,7 +241,7 @@ auth( char *who, int implicit )
authmethod = LDAP_AUTH_SIMPLE; authmethod = LDAP_AUTH_SIMPLE;
sprintf(prompt, " Enter your LDAP password: "); sprintf(prompt, " Enter your LDAP password: ");
do { do {
passwd = getpass(prompt); passwd = getpassphrase(prompt);
} while (passwd != NULL && *passwd == '\0'); } while (passwd != NULL && *passwd == '\0');
if (passwd == NULL) { if (passwd == NULL) {
(void) ldap_value_free(rdns); (void) ldap_value_free(rdns);
@ -352,7 +352,7 @@ krbgetpass( char *user, char *inst, char *realm, char *pw, C_Block key )
sprintf(prompt, " Enter Kerberos password for %s: ", kauth_name ); sprintf(prompt, " Enter Kerberos password for %s: ", kauth_name );
#endif #endif
do { do {
passwd = getpass(prompt); passwd = getpassphrase(prompt);
} while (passwd != NULL && *passwd == '\0'); } while (passwd != NULL && *passwd == '\0');
if (passwd == NULL) { if (passwd == NULL) {
return(-1); return(-1);

25
configure vendored
View file

@ -15539,6 +15539,7 @@ for ac_func in \
getgrgid \ getgrgid \
gethostname \ gethostname \
getpass \ getpass \
getpassphrase \
getpwuid \ getpwuid \
getpwnam \ getpwnam \
getspnam \ getspnam \
@ -15580,12 +15581,12 @@ for ac_func in \
do do
echo $ac_n "checking for $ac_func""... $ac_c" 1>&6 echo $ac_n "checking for $ac_func""... $ac_c" 1>&6
echo "configure:15584: checking for $ac_func" >&5 echo "configure:15585: checking for $ac_func" >&5
if eval "test \"\${ac_cv_func_$ac_func+set}\" = set"; then if eval "test \"\${ac_cv_func_$ac_func+set}\" = set"; then
echo $ac_n "(cached) $ac_c" 1>&6 echo $ac_n "(cached) $ac_c" 1>&6
else else
cat > conftest.$ac_ext <<EOF cat > conftest.$ac_ext <<EOF
#line 15589 "configure" #line 15590 "configure"
#include "confdefs.h" #include "confdefs.h"
/* System header to define __stub macros and hopefully few prototypes, /* System header to define __stub macros and hopefully few prototypes,
which can conflict with char $ac_func(); below. */ which can conflict with char $ac_func(); below. */
@ -15609,7 +15610,7 @@ f = $ac_func;
; return 0; } ; return 0; }
EOF EOF
if { (eval echo configure:15613: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then if { (eval echo configure:15614: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
rm -rf conftest* rm -rf conftest*
eval "ac_cv_func_$ac_func=yes" eval "ac_cv_func_$ac_func=yes"
else else
@ -15637,12 +15638,12 @@ done
for ac_func in getopt tempnam for ac_func in getopt tempnam
do do
echo $ac_n "checking for $ac_func""... $ac_c" 1>&6 echo $ac_n "checking for $ac_func""... $ac_c" 1>&6
echo "configure:15641: checking for $ac_func" >&5 echo "configure:15642: checking for $ac_func" >&5
if eval "test \"\${ac_cv_func_$ac_func+set}\" = set"; then if eval "test \"\${ac_cv_func_$ac_func+set}\" = set"; then
echo $ac_n "(cached) $ac_c" 1>&6 echo $ac_n "(cached) $ac_c" 1>&6
else else
cat > conftest.$ac_ext <<EOF cat > conftest.$ac_ext <<EOF
#line 15646 "configure" #line 15647 "configure"
#include "confdefs.h" #include "confdefs.h"
/* System header to define __stub macros and hopefully few prototypes, /* System header to define __stub macros and hopefully few prototypes,
which can conflict with char $ac_func(); below. */ which can conflict with char $ac_func(); below. */
@ -15666,7 +15667,7 @@ f = $ac_func;
; return 0; } ; return 0; }
EOF EOF
if { (eval echo configure:15670: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then if { (eval echo configure:15671: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
rm -rf conftest* rm -rf conftest*
eval "ac_cv_func_$ac_func=yes" eval "ac_cv_func_$ac_func=yes"
else else
@ -15703,13 +15704,13 @@ fi
# Check Configuration # Check Configuration
echo $ac_n "checking declaration of sys_errlist""... $ac_c" 1>&6 echo $ac_n "checking declaration of sys_errlist""... $ac_c" 1>&6
echo "configure:15707: checking declaration of sys_errlist" >&5 echo "configure:15708: checking declaration of sys_errlist" >&5
if eval "test \"\${ol_cv_dcl_sys_errlist+set}\" = set"; then if eval "test \"\${ol_cv_dcl_sys_errlist+set}\" = set"; then
echo $ac_n "(cached) $ac_c" 1>&6 echo $ac_n "(cached) $ac_c" 1>&6
else else
cat > conftest.$ac_ext <<EOF cat > conftest.$ac_ext <<EOF
#line 15713 "configure" #line 15714 "configure"
#include "confdefs.h" #include "confdefs.h"
#include <stdio.h> #include <stdio.h>
@ -15722,7 +15723,7 @@ int main() {
char *c = (char *) *sys_errlist char *c = (char *) *sys_errlist
; return 0; } ; return 0; }
EOF EOF
if { (eval echo configure:15726: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then if { (eval echo configure:15727: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then
rm -rf conftest* rm -rf conftest*
ol_cv_dcl_sys_errlist=yes ol_cv_dcl_sys_errlist=yes
ol_cv_have_sys_errlist=yes ol_cv_have_sys_errlist=yes
@ -15745,20 +15746,20 @@ EOF
echo $ac_n "checking existence of sys_errlist""... $ac_c" 1>&6 echo $ac_n "checking existence of sys_errlist""... $ac_c" 1>&6
echo "configure:15749: checking existence of sys_errlist" >&5 echo "configure:15750: checking existence of sys_errlist" >&5
if eval "test \"\${ol_cv_have_sys_errlist+set}\" = set"; then if eval "test \"\${ol_cv_have_sys_errlist+set}\" = set"; then
echo $ac_n "(cached) $ac_c" 1>&6 echo $ac_n "(cached) $ac_c" 1>&6
else else
cat > conftest.$ac_ext <<EOF cat > conftest.$ac_ext <<EOF
#line 15755 "configure" #line 15756 "configure"
#include "confdefs.h" #include "confdefs.h"
#include <errno.h> #include <errno.h>
int main() { int main() {
char *c = (char *) *sys_errlist char *c = (char *) *sys_errlist
; return 0; } ; return 0; }
EOF EOF
if { (eval echo configure:15762: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then if { (eval echo configure:15763: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then
rm -rf conftest* rm -rf conftest*
ol_cv_have_sys_errlist=yes ol_cv_have_sys_errlist=yes
else else

View file

@ -2138,6 +2138,7 @@ AC_CHECK_FUNCS( \
getgrgid \ getgrgid \
gethostname \ gethostname \
getpass \ getpass \
getpassphrase \
getpwuid \ getpwuid \
getpwnam \ getpwnam \
getspnam \ getspnam \

View file

@ -27,10 +27,17 @@
/* note: callers of crypt(3) should include <ac/crypt.h> */ /* note: callers of crypt(3) should include <ac/crypt.h> */
#ifndef HAVE_GETPASS #if defined(HAVE_GETPASSPHRASE)
LIBLUTIL_F(char*)(getpass) LDAP_P((const char *getpass)); LIBC_F(char*)(getpassphrase)();
#else
#elif defined(HAVE_GETPASS)
#define getpassphrase(p) getpass(p)
LIBC_F(char*)(getpass)(); LIBC_F(char*)(getpass)();
#else
#define NEED_GETPASSPHRASE 1
#define getpassphrase(p) lutil_getpass(p)
LIBLUTIL_F(char*)(lutil_getpass) LDAP_P((const char *getpass));
#endif #endif
/* getopt() defines may be in separate include file */ /* getopt() defines may be in separate include file */

View file

@ -166,6 +166,9 @@
/* Define if you have the getpass function. */ /* Define if you have the getpass function. */
#undef HAVE_GETPASS #undef HAVE_GETPASS
/* Define if you have the getpassphrase function. */
#undef HAVE_GETPASSPHRASE
/* Define if you have the getpwnam function. */ /* Define if you have the getpwnam function. */
#undef HAVE_GETPWNAM #undef HAVE_GETPWNAM

View file

@ -17,8 +17,6 @@
#include "portable.h" #include "portable.h"
#ifndef HAVE_GETPASS
#include <stdio.h> #include <stdio.h>
#include <ac/stdlib.h> #include <ac/stdlib.h>
@ -30,6 +28,8 @@
#include <ac/time.h> #include <ac/time.h>
#include <ac/unistd.h> #include <ac/unistd.h>
#ifdef NEED_GETPASSPHRASE
#ifdef HAVE_FCNTL_H #ifdef HAVE_FCNTL_H
#include <fcntl.h> #include <fcntl.h>
#endif #endif
@ -44,16 +44,19 @@
#include "ldap_defaults.h" #include "ldap_defaults.h"
char * char *
getpass( const char *prompt ) lutil_getpass( const char *prompt )
{ {
#if !defined(HAVE_POSIX_TERMIOS) && !defined(HAVE_SGTTY_H) #if !defined(HAVE_POSIX_TERMIOS) && !defined(HAVE_SGTTY_H)
static char buf[256]; static char buf[256];
int i, c; int i, c;
if( prompt == NULL ) prompt = "Password: ";
#ifdef DEBUG #ifdef DEBUG
if (debug & D_TRACE) if (debug & D_TRACE)
printf("->getpass(%s)\n", prompt); printf("->getpass(%s)\n", prompt);
#endif #endif
printf("%s", prompt); printf("%s", prompt);
i = 0; i = 0;
while ( (c = getch()) != EOF && c != '\n' && c != '\r' ) while ( (c = getch()) != EOF && c != '\n' && c != '\r' )
@ -73,6 +76,8 @@ getpass( const char *prompt )
FILE *fi; FILE *fi;
RETSIGTYPE (*sig)( int sig ); RETSIGTYPE (*sig)( int sig );
if( prompt == NULL ) prompt = "Password: ";
#ifdef DEBUG #ifdef DEBUG
if (debug & D_TRACE) if (debug & D_TRACE)
printf("->getpass(%s)\n", prompt); printf("->getpass(%s)\n", prompt);
@ -155,4 +160,4 @@ getpass( const char *prompt )
#endif #endif
} }
#endif /* !HAVE_GETPASS */ #endif /* !NEED_GETPASSPHRASE */