#include <ldap.h>
static char *binddn = NULL;
-static char *passwd = NULL;
+static struct berval passwd = { 0, NULL};
static char *ldaphost = NULL;
static int ldapport = 0;
static int prune = 0;
binddn = strdup( optarg );
break;
case 'w': /* password */
- passwd = strdup( optarg );
+ passwd.bv_val = strdup( optarg );
{
char* p;
*p = '*';
}
}
+ passwd.bv_len = strlen( passwd.bv_val );
break;
case 'f': /* read DNs from a file */
if (( fp = fopen( optarg, "r" )) == NULL ) {
}
if (want_bindpw)
- passwd = getpass("Enter LDAP Password: ");
+ passwd.bv_val = getpass("Enter LDAP Password: ");
+ passwd.bv_len = strlen( passwd.bv_val );
if ( authmethod == LDAP_AUTH_SASL ) {
#ifdef HAVE_CYRUS_SASL
return( EXIT_FAILURE );
}
- if ( ldap_negotiated_sasl_bind_s( ld, binddn, sasl_authc_id,
- sasl_authz_id, sasl_mech, NULL, NULL, NULL )
- != LDAP_SUCCESS ) {
- ldap_perror( ld, "ldap_sasl_bind" );
+ 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 );
}
#else
#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 );
static char *prog;
static char *binddn = NULL;
-static char *passwd = NULL;
+static struct berval passwd = { 0, NULL};
static char *ldaphost = NULL;
static int ldapport = 0;
#ifdef HAVE_CYRUS_SASL
binddn = strdup( optarg );
break;
case 'w': /* password */
- passwd = strdup( optarg );
+ passwd.bv_val = strdup( optarg );
{
char* p;
*p = '*';
}
}
+ passwd.bv_len = strlen( passwd.bv_val );
break;
case 'd':
debug |= atoi( optarg );
}
if (want_bindpw)
- passwd = getpass("Enter LDAP Password: ");
+ passwd.bv_val = getpass("Enter LDAP Password: ");
+ passwd.bv_len = strlen( passwd.bv_val );
if ( authmethod == LDAP_AUTH_SASL ) {
#ifdef HAVE_CYRUS_SASL
return( EXIT_FAILURE );
}
- if ( ldap_negotiated_sasl_bind_s( ld, binddn, sasl_authc_id,
- sasl_authz_id, sasl_mech, NULL, NULL, NULL )
- != LDAP_SUCCESS ) {
- ldap_perror( ld, "ldap_sasl_bind" );
+ 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 );
}
#else
#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 );
#include <ldap.h>
static char *binddn = NULL;
-static char *passwd = NULL;
+static struct berval passwd = { 0, NULL};
static char *ldaphost = NULL;
static int ldapport = 0;
#ifdef HAVE_CYRUS_SASL
version = LDAP_VERSION3; /* This option => force V3 */
break;
case 'w': /* password */
- passwd = strdup( optarg );
+ passwd.bv_val = strdup( optarg );
{
char* p;
*p = '*';
}
}
+ passwd.bv_len = strlen( passwd.bv_val );
break;
case 'd':
debug |= atoi( optarg );
}
if (want_bindpw)
- passwd = getpass("Enter LDAP Password: ");
+ passwd.bv_val = getpass("Enter LDAP Password: ");
+ passwd.bv_len = strlen( passwd.bv_val );
if ( authmethod == LDAP_AUTH_SASL ) {
#ifdef HAVE_CYRUS_SASL
return( EXIT_FAILURE );
}
- if ( ldap_negotiated_sasl_bind_s( ld, binddn, sasl_authc_id,
- sasl_authz_id, sasl_mech, NULL, NULL, NULL )
- != LDAP_SUCCESS ) {
- ldap_perror( ld, "ldap_sasl_bind" );
+ 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 );
}
#else
#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 );
char *dn = NULL;
char *binddn = NULL;
- char *bindpw = NULL;
+ struct berval passwd = { 0, NULL};
char *newpw = NULL;
char *oldpw = NULL;
break;
case 'w': /* bind password */
- bindpw = strdup (optarg);
-
+ passwd.bv_val = strdup (optarg);
{
char* p;
*p = '*';
}
}
+ passwd.bv_len = strlen( passwd.bv_val );
break;
case 'I':
binddn = dn;
dn = NULL;
- if( bindpw == NULL ) bindpw = oldpw;
+ if( passwd.bv_val == NULL ) {
+ passwd.bv_val = oldpw;
+ passwd.bv_len = oldpw == NULL ? 0 : strlen( oldpw );
+ }
}
- if (want_bindpw && bindpw == NULL ) {
+ if (want_bindpw && passwd.bv_val == NULL ) {
/* handle bind password */
fprintf( stderr, "Bind DN: %s\n", binddn );
- bindpw = strdup( getpass("Enter bind password: "));
+ passwd.bv_val = strdup( getpass("Enter bind password: "));
+ passwd.bv_len = strlen( passwd.bv_val );
}
if ( debug ) {
return( EXIT_FAILURE );
}
- if ( ldap_negotiated_sasl_bind_s( ld, binddn, sasl_authc_id,
- sasl_authz_id, sasl_mech, NULL, NULL, NULL )
- != LDAP_SUCCESS ) {
- ldap_perror( ld, "ldap_sasl_bind" );
+ rc = ldap_negotiated_sasl_bind_s( ld, binddn, sasl_authc_id,
+ sasl_authz_id, sasl_mech,
+ bindpw.bv_len ? &bindpw : NULL,
+ NULL, NULL );
+
+ if( rc != LDAP_SUCCESS ) {
+ ldap_perror( ld, "ldap_negotiated_sasl_bind_s" );
return( EXIT_FAILURE );
}
#else
#endif
}
else {
- if ( ldap_bind_s( ld, binddn, bindpw, authmethod )
+ if ( ldap_bind_s( ld, binddn, passwd.bv_val, authmethod )
!= LDAP_SUCCESS ) {
ldap_perror( ld, "ldap_bind" );
return( EXIT_FAILURE );