X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=clients%2Ftools%2Fldapsearch.c;h=da6831074139dffcfe6e7859ac642aa9407b9cee;hb=8045b54124f0365b3d34d9d3220256f052f2b76b;hp=00421fbc869489def796fcc7c92f81d91d4a5f0d;hpb=643864c56942f17debbf6c712e60b8017cf6f854;p=openldap diff --git a/clients/tools/ldapsearch.c b/clients/tools/ldapsearch.c index 00421fbc86..da68310741 100644 --- a/clients/tools/ldapsearch.c +++ b/clients/tools/ldapsearch.c @@ -1,6 +1,6 @@ /* $OpenLDAP$ */ /* - * Copyright 1998-1999 The OpenLDAP Foundation, All Rights Reserved. + * Copyright 1998-2000 The OpenLDAP Foundation, All Rights Reserved. * COPYING RESTRICTIONS APPLY, see COPYRIGHT file */ @@ -120,7 +120,7 @@ static char *tmpdir = NULL; static char *urlpre = NULL; static char *binddn = NULL; -static char *passwd = NULL; +static struct berval passwd = { 0, NULL }; static char *base = NULL; static char *ldaphost = NULL; static int ldapport = 0; @@ -263,7 +263,7 @@ main( int argc, char **argv ) ldapport = atoi( optarg ); break; case 'w': /* bind password */ - passwd = strdup( optarg ); + passwd.bv_val = strdup( optarg ); { char* p; @@ -271,6 +271,7 @@ main( int argc, char **argv ) *p = '*'; } } + passwd.bv_len = strlen( passwd.bv_val ); break; case 'l': /* time limit */ timelimit = atoi( optarg ); @@ -444,7 +445,7 @@ main( int argc, char **argv ) } if( urlpre == NULL ) { - urlpre = malloc( sizeof("file:///") + strlen(tmpdir) ); + urlpre = malloc( sizeof("file:////") + strlen(tmpdir) ); if( urlpre == NULL ) { perror( "malloc" ); @@ -520,7 +521,8 @@ main( int argc, char **argv ) } if (want_bindpw) { - passwd = getpass("Enter LDAP Password: "); + passwd.bv_val = getpassphrase("Enter LDAP Password: "); + passwd.bv_len = strlen( passwd.bv_val ); } if ( authmethod == LDAP_AUTH_SASL ) { @@ -549,9 +551,12 @@ main( int argc, char **argv ) return( EXIT_FAILURE ); } - if ( ldap_negotiated_sasl_bind_s( ld, binddn, sasl_authc_id, - sasl_authz_id, sasl_mech, NULL, NULL, NULL ) - != LDAP_SUCCESS ) { + rc = ldap_negotiated_sasl_bind_s( ld, binddn, sasl_authc_id, + sasl_authz_id, sasl_mech, + passwd.bv_len ? &passwd : NULL, + NULL, NULL ); + + if( rc != LDAP_SUCCESS ) { ldap_perror( ld, "ldap_negotiated_sasl_bind_s" ); return( EXIT_FAILURE ); } @@ -562,7 +567,7 @@ main( int argc, char **argv ) #endif } else { - if ( ldap_bind_s( ld, binddn, passwd, authmethod ) + if ( ldap_bind_s( ld, binddn, passwd.bv_val, authmethod ) != LDAP_SUCCESS ) { ldap_perror( ld, "ldap_bind" ); return( EXIT_FAILURE );