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 );
|
int force, int chaserefs, int noinit, LDAP **ldp );
|
||||||
|
|
||||||
static int
|
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 );
|
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,
|
/* 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 );
|
exit( EXIT_FAILURE );
|
||||||
}
|
}
|
||||||
|
|
||||||
static char *filter = "(objectClass=person)";
|
|
||||||
|
|
||||||
int
|
int
|
||||||
main( int argc, char **argv )
|
main( int argc, char **argv )
|
||||||
{
|
{
|
||||||
@ -82,7 +80,8 @@ main( int argc, char **argv )
|
|||||||
char *uri = NULL;
|
char *uri = NULL;
|
||||||
char *host = "localhost";
|
char *host = "localhost";
|
||||||
char *dn = NULL;
|
char *dn = NULL;
|
||||||
struct berval base = { 0, NULL };
|
char *base = NULL;
|
||||||
|
char *filter = "(objectClass=person)";
|
||||||
struct berval pass = { 0, NULL };
|
struct berval pass = { 0, NULL };
|
||||||
char *pwattr = NULL;
|
char *pwattr = NULL;
|
||||||
int port = -1;
|
int port = -1;
|
||||||
@ -105,7 +104,7 @@ main( int argc, char **argv )
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case 'b': /* base DN of a tree of user DNs */
|
case 'b': /* base DN of a tree of user DNs */
|
||||||
ber_str2bv( optarg, 0, 0, &base );
|
base = optarg;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'C':
|
case 'C':
|
||||||
@ -183,8 +182,8 @@ main( int argc, char **argv )
|
|||||||
uri = tester_uri( uri, host, port );
|
uri = tester_uri( uri, host, port );
|
||||||
|
|
||||||
for ( i = 0; i < outerloops; i++ ) {
|
for ( i = 0; i < outerloops; i++ ) {
|
||||||
if ( base.bv_val != NULL ) {
|
if ( base != NULL ) {
|
||||||
do_base( uri, &base, &pass, pwattr, loops,
|
do_base( uri, dn, &pass, base, filter, pwattr, loops,
|
||||||
force, chaserefs, noinit, delay );
|
force, chaserefs, noinit, delay );
|
||||||
} else {
|
} else {
|
||||||
do_bind( uri, dn, &pass, loops,
|
do_bind( uri, dn, &pass, loops,
|
||||||
@ -267,7 +266,7 @@ do_bind( char *uri, char *dn, struct berval *pass, int maxloop,
|
|||||||
|
|
||||||
|
|
||||||
static int
|
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 )
|
int maxloop, int force, int chaserefs, int noinit, int delay )
|
||||||
{
|
{
|
||||||
LDAP *ld = NULL;
|
LDAP *ld = NULL;
|
||||||
@ -286,7 +285,6 @@ do_base( char *uri, struct berval *base, struct berval *pass, char *pwattr,
|
|||||||
struct timeval beg, end;
|
struct timeval beg, end;
|
||||||
#endif
|
#endif
|
||||||
int version = LDAP_VERSION3;
|
int version = LDAP_VERSION3;
|
||||||
struct berval pw = { 0, NULL };
|
|
||||||
char *nullstr = "";
|
char *nullstr = "";
|
||||||
|
|
||||||
srand(pid);
|
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,
|
(void) ldap_set_option( ld, LDAP_OPT_REFERRALS,
|
||||||
chaserefs ? LDAP_OPT_ON: LDAP_OPT_OFF );
|
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 ) {
|
if ( rc != LDAP_SUCCESS ) {
|
||||||
tester_ldap_error( ld, "ldap_sasl_bind_s", NULL );
|
tester_ldap_error( ld, "ldap_sasl_bind_s", NULL );
|
||||||
exit( EXIT_FAILURE );
|
exit( EXIT_FAILURE );
|
||||||
}
|
}
|
||||||
|
|
||||||
fprintf( stderr, "PID=%ld - Bind(%d): base=\"%s\", filter=\"%s\" attr=\"%s\".\n",
|
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 ) {
|
if ( pwattr != NULL ) {
|
||||||
attrs[ 0 ] = pwattr;
|
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 );
|
filter, attrs, 0, NULL, NULL, 0, 0, &msgid );
|
||||||
if ( rc != LDAP_SUCCESS ) {
|
if ( rc != LDAP_SUCCESS ) {
|
||||||
tester_ldap_error( ld, "ldap_search_ext", NULL );
|
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) );
|
creds = realloc( creds, (ndns + 1)*sizeof(struct berval) );
|
||||||
if ( values == NULL ) {
|
if ( values == NULL ) {
|
||||||
novals:;
|
novals:;
|
||||||
if ( pass != NULL ) {
|
|
||||||
ber_dupbv( &creds[ndns], pass );
|
|
||||||
|
|
||||||
} else {
|
|
||||||
creds[ndns].bv_len = 0;
|
creds[ndns].bv_len = 0;
|
||||||
creds[ndns].bv_val = nullstr;
|
creds[ndns].bv_val = nullstr;
|
||||||
}
|
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
static struct berval cleartext = BER_BVC( "{CLEARTEXT} " );
|
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",
|
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 */
|
/* Ok, got list of DNs, now start binding to each */
|
||||||
for ( i = 0; i < maxloop; i++ ) {
|
for ( i = 0; i < maxloop; i++ ) {
|
||||||
int j, k;
|
int j, k;
|
||||||
struct berval *cred = pass;
|
struct berval cred = { 0, NULL };
|
||||||
|
|
||||||
for ( j = 0, k = 0; k < ndns; k++) {
|
for ( j = 0, k = 0; k < ndns; k++) {
|
||||||
j = rand() % ndns;
|
j = rand() % ndns;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( creds && !BER_BVISEMPTY( &creds[j] ) ) {
|
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 )
|
&& !force )
|
||||||
{
|
{
|
||||||
break;
|
break;
|
||||||
|
@ -355,17 +355,21 @@ retry:;
|
|||||||
|
|
||||||
if ( rc ) {
|
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 ignore.. */
|
||||||
if ( first ) {
|
if ( first ) {
|
||||||
/* only log if first occurrence */
|
/* only log if first occurrence */
|
||||||
if ( force < 2 || first == 1 ) {
|
if ( force < 2 || first == 1 ) {
|
||||||
tester_ldap_error( ld, "ldap_search_ext_s", NULL );
|
tester_ldap_error( ld, buf, NULL );
|
||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* busy needs special handling */
|
/* 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 ) {
|
if ( rc == LDAP_BUSY && do_retry > 0 ) {
|
||||||
ldap_unbind_ext( ld, NULL, NULL );
|
ldap_unbind_ext( ld, NULL, NULL );
|
||||||
ld = NULL;
|
ld = NULL;
|
||||||
|
@ -671,19 +671,24 @@ main( int argc, char **argv )
|
|||||||
if ( DOREQ( bnum, j ) ) {
|
if ( DOREQ( bnum, j ) ) {
|
||||||
int jj = j % bnum;
|
int jj = j % bnum;
|
||||||
|
|
||||||
|
if ( battrs[jj] != NULL ) {
|
||||||
|
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 - 4] = breqs[jj];
|
||||||
bargs[banum - 2] = bcreds[jj];
|
bargs[banum - 2] = bcreds[jj];
|
||||||
bargs[banum - 1] = NULL;
|
bargs[banum - 1] = NULL;
|
||||||
if ( battrs[jj] != NULL ) {
|
|
||||||
bargs[banum - 5] = "-b";
|
|
||||||
bargs[banum - 3] = "-f";
|
|
||||||
bargs[banum - 1] = "-a";
|
|
||||||
bargs[banum] = battrs[jj];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fork_child( bcmd, bargs );
|
fork_child( bcmd, bargs );
|
||||||
bargs[banum - 5] = "-D";
|
bargs[banum - 1] = NULL;
|
||||||
bargs[banum - 3] = "-w";
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user