mirror of
https://git.openldap.org/openldap/openldap.git
synced 2025-01-24 13:24:56 +08:00
need to be bound to lookup userPassword; cleanup
This commit is contained in:
parent
5dcb4828d7
commit
a9c7c243c1
@ -45,7 +45,7 @@ do_bind( char *uri, char *dn, struct berval *pass, int maxloop,
|
||||
int force, int chaserefs, int noinit, LDAP **ldp );
|
||||
|
||||
static int
|
||||
do_base( char *uri, struct berval *base, struct berval *pass, char *pwattr,
|
||||
do_base( char *uri, char *dn, struct berval *pass, char *base, char *filter, char *pwattr,
|
||||
int maxloop, int force, int chaserefs, int noinit, int delay );
|
||||
|
||||
/* This program can be invoked two ways: if -D is used to specify a Bind DN,
|
||||
@ -73,8 +73,6 @@ usage( char *name )
|
||||
exit( EXIT_FAILURE );
|
||||
}
|
||||
|
||||
static char *filter = "(objectClass=person)";
|
||||
|
||||
int
|
||||
main( int argc, char **argv )
|
||||
{
|
||||
@ -82,7 +80,8 @@ main( int argc, char **argv )
|
||||
char *uri = NULL;
|
||||
char *host = "localhost";
|
||||
char *dn = NULL;
|
||||
struct berval base = { 0, NULL };
|
||||
char *base = NULL;
|
||||
char *filter = "(objectClass=person)";
|
||||
struct berval pass = { 0, NULL };
|
||||
char *pwattr = NULL;
|
||||
int port = -1;
|
||||
@ -105,7 +104,7 @@ main( int argc, char **argv )
|
||||
break;
|
||||
|
||||
case 'b': /* base DN of a tree of user DNs */
|
||||
ber_str2bv( optarg, 0, 0, &base );
|
||||
base = optarg;
|
||||
break;
|
||||
|
||||
case 'C':
|
||||
@ -183,8 +182,8 @@ main( int argc, char **argv )
|
||||
uri = tester_uri( uri, host, port );
|
||||
|
||||
for ( i = 0; i < outerloops; i++ ) {
|
||||
if ( base.bv_val != NULL ) {
|
||||
do_base( uri, &base, &pass, pwattr, loops,
|
||||
if ( base != NULL ) {
|
||||
do_base( uri, dn, &pass, base, filter, pwattr, loops,
|
||||
force, chaserefs, noinit, delay );
|
||||
} else {
|
||||
do_bind( uri, dn, &pass, loops,
|
||||
@ -267,7 +266,7 @@ do_bind( char *uri, char *dn, struct berval *pass, int maxloop,
|
||||
|
||||
|
||||
static int
|
||||
do_base( char *uri, struct berval *base, struct berval *pass, char *pwattr,
|
||||
do_base( char *uri, char *dn, struct berval *pass, char *base, char *filter, char *pwattr,
|
||||
int maxloop, int force, int chaserefs, int noinit, int delay )
|
||||
{
|
||||
LDAP *ld = NULL;
|
||||
@ -286,7 +285,6 @@ do_base( char *uri, struct berval *base, struct berval *pass, char *pwattr,
|
||||
struct timeval beg, end;
|
||||
#endif
|
||||
int version = LDAP_VERSION3;
|
||||
struct berval pw = { 0, NULL };
|
||||
char *nullstr = "";
|
||||
|
||||
srand(pid);
|
||||
@ -301,19 +299,19 @@ do_base( char *uri, struct berval *base, struct berval *pass, char *pwattr,
|
||||
(void) ldap_set_option( ld, LDAP_OPT_REFERRALS,
|
||||
chaserefs ? LDAP_OPT_ON: LDAP_OPT_OFF );
|
||||
|
||||
rc = ldap_sasl_bind_s( ld, NULL, LDAP_SASL_SIMPLE, &pw, NULL, NULL, NULL );
|
||||
rc = ldap_sasl_bind_s( ld, dn, LDAP_SASL_SIMPLE, pass, NULL, NULL, NULL );
|
||||
if ( rc != LDAP_SUCCESS ) {
|
||||
tester_ldap_error( ld, "ldap_sasl_bind_s", NULL );
|
||||
exit( EXIT_FAILURE );
|
||||
}
|
||||
|
||||
fprintf( stderr, "PID=%ld - Bind(%d): base=\"%s\", filter=\"%s\" attr=\"%s\".\n",
|
||||
(long) pid, maxloop, base->bv_val, filter, pwattr );
|
||||
(long) pid, maxloop, base, filter, pwattr );
|
||||
|
||||
if ( pwattr != NULL ) {
|
||||
attrs[ 0 ] = pwattr;
|
||||
}
|
||||
rc = ldap_search_ext( ld, base->bv_val, LDAP_SCOPE_SUBTREE,
|
||||
rc = ldap_search_ext( ld, base, LDAP_SCOPE_SUBTREE,
|
||||
filter, attrs, 0, NULL, NULL, 0, 0, &msgid );
|
||||
if ( rc != LDAP_SUCCESS ) {
|
||||
tester_ldap_error( ld, "ldap_search_ext", NULL );
|
||||
@ -340,13 +338,8 @@ do_base( char *uri, struct berval *base, struct berval *pass, char *pwattr,
|
||||
creds = realloc( creds, (ndns + 1)*sizeof(struct berval) );
|
||||
if ( values == NULL ) {
|
||||
novals:;
|
||||
if ( pass != NULL ) {
|
||||
ber_dupbv( &creds[ndns], pass );
|
||||
|
||||
} else {
|
||||
creds[ndns].bv_len = 0;
|
||||
creds[ndns].bv_val = nullstr;
|
||||
}
|
||||
creds[ndns].bv_len = 0;
|
||||
creds[ndns].bv_val = nullstr;
|
||||
|
||||
} else {
|
||||
static struct berval cleartext = BER_BVC( "{CLEARTEXT} " );
|
||||
@ -399,21 +392,21 @@ novals:;
|
||||
}
|
||||
|
||||
fprintf( stderr, " PID=%ld - Bind base=\"%s\" filter=\"%s\" got %d values.\n",
|
||||
(long) pid, base->bv_val, filter, ndns );
|
||||
(long) pid, base, filter, ndns );
|
||||
|
||||
/* Ok, got list of DNs, now start binding to each */
|
||||
for ( i = 0; i < maxloop; i++ ) {
|
||||
int j, k;
|
||||
struct berval *cred = pass;
|
||||
struct berval cred = { 0, NULL };
|
||||
|
||||
for ( j = 0, k = 0; k < ndns; k++) {
|
||||
j = rand() % ndns;
|
||||
}
|
||||
|
||||
if ( creds && !BER_BVISEMPTY( &creds[j] ) ) {
|
||||
cred = &creds[j];
|
||||
cred = creds[j];
|
||||
}
|
||||
if ( do_bind( uri, dns[j], cred, 1, force, chaserefs, noinit, &ld )
|
||||
if ( do_bind( uri, dns[j], &cred, 1, force, chaserefs, noinit, &ld )
|
||||
&& !force )
|
||||
{
|
||||
break;
|
||||
|
@ -354,18 +354,22 @@ retry:;
|
||||
}
|
||||
|
||||
if ( rc ) {
|
||||
unsigned first = tester_ignore_err( rc );
|
||||
unsigned first = tester_ignore_err( rc );
|
||||
char buf[ BUFSIZ ];
|
||||
|
||||
snprintf( buf, sizeof( buf ), "ldap_search_ext_s(%s)", entry );
|
||||
|
||||
/* if ignore.. */
|
||||
if ( first ) {
|
||||
/* only log if first occurrence */
|
||||
if ( force < 2 || first == 1 ) {
|
||||
tester_ldap_error( ld, "ldap_search_ext_s", NULL );
|
||||
tester_ldap_error( ld, buf, NULL );
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
/* busy needs special handling */
|
||||
tester_ldap_error( ld, "ldap_search_ext_s", NULL );
|
||||
tester_ldap_error( ld, buf, NULL );
|
||||
if ( rc == LDAP_BUSY && do_retry > 0 ) {
|
||||
ldap_unbind_ext( ld, NULL, NULL );
|
||||
ld = NULL;
|
||||
|
@ -671,19 +671,24 @@ main( int argc, char **argv )
|
||||
if ( DOREQ( bnum, j ) ) {
|
||||
int jj = j % bnum;
|
||||
|
||||
bargs[banum - 4] = breqs[jj];
|
||||
bargs[banum - 2] = bcreds[jj];
|
||||
bargs[banum - 1] = NULL;
|
||||
if ( battrs[jj] != NULL ) {
|
||||
bargs[banum - 5] = "-b";
|
||||
bargs[banum - 3] = "-f";
|
||||
bargs[banum - 1] = "-a";
|
||||
bargs[banum] = battrs[jj];
|
||||
bargs[banum - 4] = manager ? manager : "";
|
||||
bargs[banum - 2] = passwd ? passwd : "";
|
||||
|
||||
bargs[banum - 1] = "-b";
|
||||
bargs[banum] = breqs[jj];
|
||||
bargs[banum + 1] = "-f";
|
||||
bargs[banum + 2] = bcreds[jj];
|
||||
bargs[banum + 3] = "-a";
|
||||
bargs[banum + 4] = battrs[jj];
|
||||
} else {
|
||||
bargs[banum - 4] = breqs[jj];
|
||||
bargs[banum - 2] = bcreds[jj];
|
||||
bargs[banum - 1] = NULL;
|
||||
}
|
||||
|
||||
fork_child( bcmd, bargs );
|
||||
bargs[banum - 5] = "-D";
|
||||
bargs[banum - 3] = "-w";
|
||||
bargs[banum - 1] = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user