From ca8dac8b85339801a69a8cdbbe1fd888a27e26de Mon Sep 17 00:00:00 2001 From: "richm%stanfordalumni.org" Date: Fri, 11 Feb 2005 20:02:47 +0000 Subject: [PATCH] Fix bug 281140 - patch submitted by ulf@loop.to The getpass() function on HP-UX only allows 8 characters. Since there is not (yet?) a better function, this fix allows up to 256 character passwords using the raw tty interfaces for no echo. --- directory/c-sdk/ldap/clients/tools/common.c | 42 +++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/directory/c-sdk/ldap/clients/tools/common.c b/directory/c-sdk/ldap/clients/tools/common.c index c96dcf3cb61..41a599ec6e6 100644 --- a/directory/c-sdk/ldap/clients/tools/common.c +++ b/directory/c-sdk/ldap/clients/tools/common.c @@ -51,6 +51,10 @@ #include #include /* for time() and ctime() */ +#if defined(HPUX) +#include /* for tcgetattr and tcsetattr */ +#endif /* HPUX */ + static LDAP_REBINDPROC_CALLBACK get_rebind_credentials; static void print_library_info( const LDAPAPIInfo *aip, FILE *fp ); static int wait4result( LDAP *ld, int msgid, struct berval **servercredp, @@ -689,10 +693,48 @@ ldaptool_process_args( int argc, char **argv, char *extra_opts, #if defined(SOLARIS) /* 256 characters on Solaris */ passwd = getpassphrase(password_string); +#else +#if defined(HPUX) + /* HP-UX has deprecated their password asking function, so we have + * to resort to doing it the hard way . . . */ + char pbuf[257]; + struct termios termstat; + tcflag_t savestat; + + fputs(password_string, stdout); + fflush(stdout); + + if(tcgetattr(fileno(stdin), &termstat) < 0) { + perror( "tcgetattr" ); + exit( LDAP_LOCAL_ERROR ); + } + savestat = termstat.c_lflag; + termstat.c_lflag &= ~(ECHO | ECHOE | ECHOK); + termstat.c_lflag |= (ICANON | ECHONL); + if(tcsetattr(fileno(stdin), TCSANOW, &termstat) < 0) { + perror( "tcgetattr" ); + exit( LDAP_LOCAL_ERROR ); + } + if (fgets(pbuf,256,stdin) == NULL) { + passwd = NULL; + } else { + char *tmp; + passwd = NULL; + tmp = strchr(pbuf,'\n'); + if (tmp) + *tmp = '\0'; + passwd = strdup(pbuf); + } + termstat.c_lflag = savestat; + if(tcsetattr(fileno(stdin), TCSANOW, &termstat) < 0) { + perror( "tcgetattr" ); + exit( LDAP_LOCAL_ERROR ); + } #else /* limited to 16 chars on Tru64, 32 on AIX */ passwd = getpass(password_string); #endif +#endif #endif } else if (password_fp != NULL) {