2005-10-29 15:22:35 +08:00
|
|
|
/* $OpenLDAP$ */
|
|
|
|
/* This work is part of OpenLDAP Software <http://www.openldap.org/>.
|
|
|
|
*
|
2006-01-04 07:11:52 +08:00
|
|
|
* Copyright 1999-2006 The OpenLDAP Foundation.
|
2005-10-29 15:22:35 +08:00
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted only as authorized by the OpenLDAP
|
|
|
|
* Public License.
|
|
|
|
*
|
|
|
|
* A copy of this license is available in file LICENSE in the
|
|
|
|
* top-level directory of the distribution or, alternatively, at
|
|
|
|
* <http://www.OpenLDAP.org/license.html>.
|
|
|
|
*/
|
|
|
|
/* ACKNOWLEDGEMENTS:
|
2005-10-30 16:57:06 +08:00
|
|
|
* This work was initially developed by Howard Chu for inclusion
|
2005-10-29 15:22:35 +08:00
|
|
|
* in OpenLDAP Software.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "portable.h"
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
#include <ac/stdlib.h>
|
2005-11-07 07:36:29 +08:00
|
|
|
#include <ac/time.h>
|
2005-10-29 15:22:35 +08:00
|
|
|
|
|
|
|
#include <ac/ctype.h>
|
|
|
|
#include <ac/param.h>
|
|
|
|
#include <ac/socket.h>
|
|
|
|
#include <ac/string.h>
|
|
|
|
#include <ac/unistd.h>
|
|
|
|
#include <ac/wait.h>
|
2005-11-11 07:22:40 +08:00
|
|
|
#include <ac/time.h>
|
2005-10-29 15:22:35 +08:00
|
|
|
|
|
|
|
#include <ldap.h>
|
|
|
|
#include <lutil.h>
|
2006-05-15 01:18:55 +08:00
|
|
|
#include <lber_pvt.h>
|
2005-10-29 15:22:35 +08:00
|
|
|
|
2006-01-12 21:01:38 +08:00
|
|
|
#include "slapd-common.h"
|
2006-01-09 22:21:33 +08:00
|
|
|
|
2006-01-12 21:01:38 +08:00
|
|
|
#define LOOPS 100
|
2006-01-09 22:21:33 +08:00
|
|
|
|
2005-10-30 16:57:06 +08:00
|
|
|
static int
|
2006-03-25 18:13:30 +08:00
|
|
|
do_bind( char *uri, char *dn, struct berval *pass, int maxloop,
|
|
|
|
int force, int chaserefs, int noinit, LDAP **ldp );
|
2005-10-29 15:22:35 +08:00
|
|
|
|
2005-10-30 16:57:06 +08:00
|
|
|
static int
|
2006-07-02 00:45:44 +08:00
|
|
|
do_base( char *uri, char *dn, struct berval *pass, char *base, char *filter, char *pwattr,
|
2006-05-15 01:18:55 +08:00
|
|
|
int maxloop, int force, int chaserefs, int noinit, int delay );
|
2005-10-29 15:22:35 +08:00
|
|
|
|
2005-10-30 16:57:06 +08:00
|
|
|
/* This program can be invoked two ways: if -D is used to specify a Bind DN,
|
|
|
|
* that DN will be used repeatedly for all of the Binds. If instead -b is used
|
|
|
|
* to specify a base DN, a search will be done for all "person" objects under
|
|
|
|
* that base DN. Then DNs from this list will be randomly selected for each
|
|
|
|
* Bind request. All of the users must have identical passwords. Also it is
|
|
|
|
* assumed that the users are all onelevel children of the base.
|
|
|
|
*/
|
2005-10-29 15:22:35 +08:00
|
|
|
static void
|
|
|
|
usage( char *name )
|
|
|
|
{
|
2006-03-04 00:02:34 +08:00
|
|
|
fprintf( stderr, "usage: %s "
|
2006-05-15 01:18:55 +08:00
|
|
|
"[-H uri | -h <host> [-p port]] "
|
|
|
|
"[-D <dn> [-w <passwd>]] "
|
|
|
|
"[-b <baseDN> [-f <searchfilter>] [-a pwattr]] "
|
2006-03-04 00:02:34 +08:00
|
|
|
"[-l <loops>] "
|
|
|
|
"[-L <outerloops>] "
|
|
|
|
"[-F] "
|
2006-03-25 18:13:30 +08:00
|
|
|
"[-C] "
|
2006-03-04 00:02:34 +08:00
|
|
|
"[-I] "
|
2006-06-09 17:30:36 +08:00
|
|
|
"[-i <ignore>] "
|
2006-03-04 00:02:34 +08:00
|
|
|
"[-t delay]\n",
|
|
|
|
name );
|
2005-10-29 15:22:35 +08:00
|
|
|
exit( EXIT_FAILURE );
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
main( int argc, char **argv )
|
|
|
|
{
|
|
|
|
int i;
|
2006-01-12 21:01:38 +08:00
|
|
|
char *uri = NULL;
|
2005-11-07 07:36:29 +08:00
|
|
|
char *host = "localhost";
|
2005-10-29 15:22:35 +08:00
|
|
|
char *dn = NULL;
|
2006-07-02 00:45:44 +08:00
|
|
|
char *base = NULL;
|
|
|
|
char *filter = "(objectClass=person)";
|
2006-01-09 22:21:33 +08:00
|
|
|
struct berval pass = { 0, NULL };
|
2006-05-15 01:18:55 +08:00
|
|
|
char *pwattr = NULL;
|
2005-11-07 07:36:29 +08:00
|
|
|
int port = -1;
|
|
|
|
int loops = LOOPS;
|
2006-03-04 00:02:34 +08:00
|
|
|
int outerloops = 1;
|
2005-11-11 07:22:40 +08:00
|
|
|
int force = 0;
|
2006-03-25 18:13:30 +08:00
|
|
|
int chaserefs = 0;
|
2006-02-05 00:33:12 +08:00
|
|
|
int noinit = 0;
|
2006-02-07 06:08:02 +08:00
|
|
|
int delay = 0;
|
2005-10-29 15:22:35 +08:00
|
|
|
|
2006-06-09 17:30:36 +08:00
|
|
|
tester_init( "slapd-bind", TESTER_BIND );
|
2006-01-12 21:01:38 +08:00
|
|
|
|
2006-06-09 17:30:36 +08:00
|
|
|
/* by default, tolerate invalid credentials */
|
|
|
|
tester_ignore_str2errlist( "INVALID_CREDENTIALS" );
|
|
|
|
|
|
|
|
while ( (i = getopt( argc, argv, "a:b:H:h:i:p:D:w:l:L:f:FIt:" )) != EOF ) {
|
2005-10-29 15:22:35 +08:00
|
|
|
switch( i ) {
|
2006-05-15 01:18:55 +08:00
|
|
|
case 'a':
|
|
|
|
pwattr = optarg;
|
|
|
|
break;
|
|
|
|
|
2006-03-25 18:13:30 +08:00
|
|
|
case 'b': /* base DN of a tree of user DNs */
|
2006-07-02 00:45:44 +08:00
|
|
|
base = optarg;
|
2006-03-25 18:13:30 +08:00
|
|
|
break;
|
2005-10-29 15:22:35 +08:00
|
|
|
|
2006-03-25 18:13:30 +08:00
|
|
|
case 'C':
|
|
|
|
chaserefs++;
|
|
|
|
break;
|
2006-01-09 22:21:33 +08:00
|
|
|
|
2006-03-25 18:13:30 +08:00
|
|
|
case 'H': /* the server uri */
|
2006-05-15 01:18:55 +08:00
|
|
|
uri = optarg;
|
2006-03-25 18:13:30 +08:00
|
|
|
break;
|
2005-10-29 15:22:35 +08:00
|
|
|
|
2006-03-25 18:13:30 +08:00
|
|
|
case 'h': /* the servers host */
|
2006-05-15 01:18:55 +08:00
|
|
|
host = optarg;
|
2006-03-25 18:13:30 +08:00
|
|
|
break;
|
2005-10-29 15:22:35 +08:00
|
|
|
|
2006-06-09 17:30:36 +08:00
|
|
|
case 'i':
|
|
|
|
tester_ignore_str2errlist( optarg );
|
|
|
|
break;
|
|
|
|
|
2006-03-25 18:13:30 +08:00
|
|
|
case 'p': /* the servers port */
|
|
|
|
if ( lutil_atoi( &port, optarg ) != 0 ) {
|
|
|
|
usage( argv[0] );
|
|
|
|
}
|
|
|
|
break;
|
2005-10-29 15:22:35 +08:00
|
|
|
|
2006-03-25 18:13:30 +08:00
|
|
|
case 'D':
|
2006-05-15 01:18:55 +08:00
|
|
|
dn = optarg;
|
2006-03-25 18:13:30 +08:00
|
|
|
break;
|
2005-10-29 15:22:35 +08:00
|
|
|
|
2006-03-25 18:13:30 +08:00
|
|
|
case 'w':
|
2006-07-02 02:27:53 +08:00
|
|
|
ber_str2bv( optarg, 0, 1, &pass );
|
2006-07-02 02:22:43 +08:00
|
|
|
memset( optarg, '*', pass.bv_len );
|
2006-03-25 18:13:30 +08:00
|
|
|
break;
|
2005-10-29 15:22:35 +08:00
|
|
|
|
2006-03-25 18:13:30 +08:00
|
|
|
case 'l': /* the number of loops */
|
|
|
|
if ( lutil_atoi( &loops, optarg ) != 0 ) {
|
|
|
|
usage( argv[0] );
|
|
|
|
}
|
|
|
|
break;
|
2006-03-04 00:02:34 +08:00
|
|
|
|
2006-03-25 18:13:30 +08:00
|
|
|
case 'L': /* the number of outerloops */
|
|
|
|
if ( lutil_atoi( &outerloops, optarg ) != 0 ) {
|
|
|
|
usage( argv[0] );
|
|
|
|
}
|
|
|
|
break;
|
2005-11-07 07:36:29 +08:00
|
|
|
|
2006-03-25 18:13:30 +08:00
|
|
|
case 'f':
|
|
|
|
filter = optarg;
|
|
|
|
break;
|
2005-11-11 07:22:40 +08:00
|
|
|
|
2006-03-25 18:13:30 +08:00
|
|
|
case 'F':
|
|
|
|
force++;
|
|
|
|
break;
|
2006-02-05 00:33:12 +08:00
|
|
|
|
2006-03-25 18:13:30 +08:00
|
|
|
case 'I':
|
|
|
|
/* reuse connection */
|
|
|
|
noinit++;
|
|
|
|
break;
|
2006-02-07 06:08:02 +08:00
|
|
|
|
2006-03-25 18:13:30 +08:00
|
|
|
case 't':
|
|
|
|
/* sleep between binds */
|
|
|
|
if ( lutil_atoi( &delay, optarg ) != 0 ) {
|
2005-10-29 15:22:35 +08:00
|
|
|
usage( argv[0] );
|
2006-03-25 18:13:30 +08:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
usage( argv[0] );
|
|
|
|
break;
|
2005-10-29 15:22:35 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-01-09 22:21:33 +08:00
|
|
|
if ( port == -1 && uri == NULL ) {
|
2005-10-29 15:22:35 +08:00
|
|
|
usage( argv[0] );
|
2006-01-09 22:21:33 +08:00
|
|
|
}
|
|
|
|
|
2006-01-12 21:01:38 +08:00
|
|
|
uri = tester_uri( uri, host, port );
|
2005-10-29 15:22:35 +08:00
|
|
|
|
2006-03-04 00:02:34 +08:00
|
|
|
for ( i = 0; i < outerloops; i++ ) {
|
2006-07-02 00:45:44 +08:00
|
|
|
if ( base != NULL ) {
|
|
|
|
do_base( uri, dn, &pass, base, filter, pwattr, loops,
|
2006-03-25 18:13:30 +08:00
|
|
|
force, chaserefs, noinit, delay );
|
2006-03-04 00:02:34 +08:00
|
|
|
} else {
|
2006-03-25 18:13:30 +08:00
|
|
|
do_bind( uri, dn, &pass, loops,
|
|
|
|
force, chaserefs, noinit, NULL );
|
2006-03-04 00:02:34 +08:00
|
|
|
}
|
2006-01-09 22:21:33 +08:00
|
|
|
}
|
2006-03-04 00:02:34 +08:00
|
|
|
|
2005-10-29 15:22:35 +08:00
|
|
|
exit( EXIT_SUCCESS );
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-10-30 16:57:06 +08:00
|
|
|
static int
|
2006-03-25 18:13:30 +08:00
|
|
|
do_bind( char *uri, char *dn, struct berval *pass, int maxloop,
|
|
|
|
int force, int chaserefs, int noinit, LDAP **ldp )
|
2005-10-29 15:22:35 +08:00
|
|
|
{
|
2006-02-05 00:33:12 +08:00
|
|
|
LDAP *ld = ldp ? *ldp : NULL;
|
2006-06-09 17:30:36 +08:00
|
|
|
int i, rc = -1;
|
2005-10-29 15:22:35 +08:00
|
|
|
pid_t pid = getpid();
|
|
|
|
|
|
|
|
if ( maxloop > 1 )
|
|
|
|
fprintf( stderr, "PID=%ld - Bind(%d): dn=\"%s\".\n",
|
|
|
|
(long) pid, maxloop, dn );
|
|
|
|
|
|
|
|
for ( i = 0; i < maxloop; i++ ) {
|
2006-02-05 00:33:12 +08:00
|
|
|
if ( !noinit || ld == NULL ) {
|
2005-10-29 15:22:35 +08:00
|
|
|
int version = LDAP_VERSION3;
|
2006-02-05 00:33:12 +08:00
|
|
|
ldap_initialize( &ld, uri );
|
|
|
|
if ( ld == NULL ) {
|
2006-04-08 19:01:01 +08:00
|
|
|
tester_perror( "ldap_initialize", NULL );
|
2006-02-05 00:33:12 +08:00
|
|
|
rc = -1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2005-10-29 15:22:35 +08:00
|
|
|
(void) ldap_set_option( ld, LDAP_OPT_PROTOCOL_VERSION,
|
|
|
|
&version );
|
2006-03-25 16:10:31 +08:00
|
|
|
(void) ldap_set_option( ld, LDAP_OPT_REFERRALS,
|
2006-03-25 18:13:30 +08:00
|
|
|
chaserefs ? LDAP_OPT_ON: LDAP_OPT_OFF );
|
2005-10-29 15:22:35 +08:00
|
|
|
}
|
|
|
|
|
2006-01-09 22:21:33 +08:00
|
|
|
rc = ldap_sasl_bind_s( ld, dn, LDAP_SASL_SIMPLE, pass, NULL, NULL, NULL );
|
2006-06-09 17:30:36 +08:00
|
|
|
if ( rc ) {
|
|
|
|
unsigned first = tester_ignore_err( rc );
|
|
|
|
|
|
|
|
/* if ignore.. */
|
|
|
|
if ( first ) {
|
|
|
|
/* only log if first occurrence */
|
|
|
|
if ( force < 2 || first == 1 ) {
|
|
|
|
tester_ldap_error( ld, "ldap_sasl_bind_s", NULL );
|
2006-01-22 00:27:15 +08:00
|
|
|
}
|
2006-06-09 17:30:36 +08:00
|
|
|
rc = LDAP_SUCCESS;
|
2006-01-22 00:27:15 +08:00
|
|
|
|
2006-06-09 17:30:36 +08:00
|
|
|
} else {
|
|
|
|
tester_ldap_error( ld, "ldap_sasl_bind_s", NULL );
|
|
|
|
}
|
2005-10-29 15:22:35 +08:00
|
|
|
}
|
2006-06-09 17:30:36 +08:00
|
|
|
|
2006-02-05 00:33:12 +08:00
|
|
|
if ( !noinit ) {
|
|
|
|
ldap_unbind_ext( ld, NULL, NULL );
|
|
|
|
ld = NULL;
|
|
|
|
}
|
2006-06-09 17:30:36 +08:00
|
|
|
|
|
|
|
if ( rc != LDAP_SUCCESS ) {
|
2005-10-29 15:22:35 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-02-05 00:33:12 +08:00
|
|
|
if ( maxloop > 1 ) {
|
2006-02-07 06:08:02 +08:00
|
|
|
fprintf( stderr, " PID=%ld - Bind done (%d).\n", (long) pid, rc );
|
2006-02-05 00:33:12 +08:00
|
|
|
}
|
|
|
|
|
2006-05-15 01:18:55 +08:00
|
|
|
if ( ldp && noinit ) {
|
2006-02-05 00:33:12 +08:00
|
|
|
*ldp = ld;
|
|
|
|
|
2006-02-08 03:11:51 +08:00
|
|
|
} else if ( ld != NULL ) {
|
2006-02-05 00:33:12 +08:00
|
|
|
ldap_unbind_ext( ld, NULL, NULL );
|
|
|
|
}
|
2005-10-29 15:22:35 +08:00
|
|
|
|
2005-10-30 16:57:06 +08:00
|
|
|
return rc;
|
2005-10-29 15:22:35 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-10-30 16:57:06 +08:00
|
|
|
static int
|
2006-07-02 00:45:44 +08:00
|
|
|
do_base( char *uri, char *dn, struct berval *pass, char *base, char *filter, char *pwattr,
|
2006-05-15 01:18:55 +08:00
|
|
|
int maxloop, int force, int chaserefs, int noinit, int delay )
|
2005-10-29 15:22:35 +08:00
|
|
|
{
|
|
|
|
LDAP *ld = NULL;
|
|
|
|
int i = 0;
|
|
|
|
pid_t pid = getpid();
|
|
|
|
int rc = LDAP_SUCCESS;
|
|
|
|
ber_int_t msgid;
|
|
|
|
LDAPMessage *res, *msg;
|
2006-05-15 01:18:55 +08:00
|
|
|
char **dns = NULL;
|
|
|
|
struct berval *creds = NULL;
|
2006-02-05 00:33:12 +08:00
|
|
|
char *attrs[] = { LDAP_NO_ATTRS, NULL };
|
2006-05-15 01:18:55 +08:00
|
|
|
int ndns = 0;
|
2005-11-11 07:58:24 +08:00
|
|
|
#ifdef _WIN32
|
|
|
|
DWORD beg, end;
|
|
|
|
#else
|
2005-11-11 07:22:40 +08:00
|
|
|
struct timeval beg, end;
|
2005-11-11 07:58:24 +08:00
|
|
|
#endif
|
2006-01-09 22:21:33 +08:00
|
|
|
int version = LDAP_VERSION3;
|
2006-05-15 01:18:55 +08:00
|
|
|
char *nullstr = "";
|
2005-10-29 15:22:35 +08:00
|
|
|
|
2006-08-25 23:15:13 +08:00
|
|
|
srand( pid );
|
2005-10-29 15:22:35 +08:00
|
|
|
|
2006-01-09 22:21:33 +08:00
|
|
|
ldap_initialize( &ld, uri );
|
2005-10-29 15:22:35 +08:00
|
|
|
if ( ld == NULL ) {
|
2006-04-08 19:01:01 +08:00
|
|
|
tester_perror( "ldap_initialize", NULL );
|
2005-10-29 15:22:35 +08:00
|
|
|
exit( EXIT_FAILURE );
|
|
|
|
}
|
|
|
|
|
2006-01-09 22:21:33 +08:00
|
|
|
(void) ldap_set_option( ld, LDAP_OPT_PROTOCOL_VERSION, &version );
|
2006-03-25 18:13:30 +08:00
|
|
|
(void) ldap_set_option( ld, LDAP_OPT_REFERRALS,
|
|
|
|
chaserefs ? LDAP_OPT_ON: LDAP_OPT_OFF );
|
2005-10-29 15:22:35 +08:00
|
|
|
|
2006-07-02 00:45:44 +08:00
|
|
|
rc = ldap_sasl_bind_s( ld, dn, LDAP_SASL_SIMPLE, pass, NULL, NULL, NULL );
|
2005-10-29 15:22:35 +08:00
|
|
|
if ( rc != LDAP_SUCCESS ) {
|
2006-04-08 19:01:01 +08:00
|
|
|
tester_ldap_error( ld, "ldap_sasl_bind_s", NULL );
|
2005-10-29 15:22:35 +08:00
|
|
|
exit( EXIT_FAILURE );
|
|
|
|
}
|
|
|
|
|
2006-05-15 01:18:55 +08:00
|
|
|
fprintf( stderr, "PID=%ld - Bind(%d): base=\"%s\", filter=\"%s\" attr=\"%s\".\n",
|
2006-07-02 00:45:44 +08:00
|
|
|
(long) pid, maxloop, base, filter, pwattr );
|
2006-05-15 01:18:55 +08:00
|
|
|
|
|
|
|
if ( pwattr != NULL ) {
|
|
|
|
attrs[ 0 ] = pwattr;
|
|
|
|
}
|
2006-07-02 00:45:44 +08:00
|
|
|
rc = ldap_search_ext( ld, base, LDAP_SCOPE_SUBTREE,
|
2005-10-29 15:22:35 +08:00
|
|
|
filter, attrs, 0, NULL, NULL, 0, 0, &msgid );
|
|
|
|
if ( rc != LDAP_SUCCESS ) {
|
2006-04-08 19:01:01 +08:00
|
|
|
tester_ldap_error( ld, "ldap_search_ext", NULL );
|
2005-10-29 15:22:35 +08:00
|
|
|
exit( EXIT_FAILURE );
|
|
|
|
}
|
|
|
|
|
2006-05-15 01:18:55 +08:00
|
|
|
while ( ( rc = ldap_result( ld, LDAP_RES_ANY, LDAP_MSG_ONE, NULL, &res ) ) > 0 )
|
|
|
|
{
|
2005-10-29 15:22:35 +08:00
|
|
|
BerElement *ber;
|
|
|
|
struct berval bv;
|
|
|
|
int done = 0;
|
|
|
|
|
2006-05-15 01:18:55 +08:00
|
|
|
for ( msg = ldap_first_message( ld, res ); msg;
|
|
|
|
msg = ldap_next_message( ld, msg ) )
|
|
|
|
{
|
|
|
|
switch ( ldap_msgtype( msg ) ) {
|
2005-10-29 15:22:35 +08:00
|
|
|
case LDAP_RES_SEARCH_ENTRY:
|
|
|
|
rc = ldap_get_dn_ber( ld, msg, &ber, &bv );
|
2006-05-15 01:18:55 +08:00
|
|
|
dns = realloc( dns, (ndns + 1)*sizeof(char *) );
|
|
|
|
dns[ndns] = ber_strdup( bv.bv_val );
|
|
|
|
if ( pwattr != NULL ) {
|
|
|
|
struct berval **values = ldap_get_values_len( ld, msg, pwattr );
|
|
|
|
|
|
|
|
creds = realloc( creds, (ndns + 1)*sizeof(struct berval) );
|
|
|
|
if ( values == NULL ) {
|
|
|
|
novals:;
|
2006-07-02 00:45:44 +08:00
|
|
|
creds[ndns].bv_len = 0;
|
|
|
|
creds[ndns].bv_val = nullstr;
|
2006-05-15 01:18:55 +08:00
|
|
|
|
|
|
|
} else {
|
|
|
|
static struct berval cleartext = BER_BVC( "{CLEARTEXT} " );
|
|
|
|
struct berval value = *values[ 0 ];
|
|
|
|
|
|
|
|
if ( value.bv_val[ 0 ] == '{' ) {
|
|
|
|
char *end = ber_bvchr( &value, '}' );
|
|
|
|
|
|
|
|
if ( end ) {
|
|
|
|
if ( ber_bvcmp( &value, &cleartext ) == 0 ) {
|
|
|
|
value.bv_val += cleartext.bv_len;
|
|
|
|
value.bv_len -= cleartext.bv_len;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
ldap_value_free_len( values );
|
|
|
|
goto novals;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
ber_dupbv( &creds[ndns], &value );
|
|
|
|
ldap_value_free_len( values );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ndns++;
|
2005-10-29 15:22:35 +08:00
|
|
|
ber_free( ber, 0 );
|
|
|
|
break;
|
2006-05-15 01:18:55 +08:00
|
|
|
|
2005-10-29 15:22:35 +08:00
|
|
|
case LDAP_RES_SEARCH_RESULT:
|
|
|
|
done = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if ( done )
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
ldap_msgfree( res );
|
|
|
|
if ( done ) break;
|
|
|
|
}
|
|
|
|
|
2005-11-11 07:58:24 +08:00
|
|
|
#ifdef _WIN32
|
|
|
|
beg = GetTickCount();
|
|
|
|
#else
|
2005-11-11 07:22:40 +08:00
|
|
|
gettimeofday( &beg, NULL );
|
2005-11-11 07:58:24 +08:00
|
|
|
#endif
|
2005-11-11 07:22:40 +08:00
|
|
|
|
2006-05-15 01:18:55 +08:00
|
|
|
if ( ndns == 0 ) {
|
2006-06-10 07:13:08 +08:00
|
|
|
tester_error( "No DNs" );
|
2005-11-07 07:36:29 +08:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2006-06-10 23:20:55 +08:00
|
|
|
fprintf( stderr, " PID=%ld - Bind base=\"%s\" filter=\"%s\" got %d values.\n",
|
2006-07-02 00:45:44 +08:00
|
|
|
(long) pid, base, filter, ndns );
|
2006-05-15 01:18:55 +08:00
|
|
|
|
2006-06-10 07:13:08 +08:00
|
|
|
/* Ok, got list of DNs, now start binding to each */
|
2006-02-08 03:11:51 +08:00
|
|
|
for ( i = 0; i < maxloop; i++ ) {
|
2006-08-25 23:15:13 +08:00
|
|
|
int j;
|
|
|
|
struct berval cred = { 0, NULL };
|
2006-02-05 00:33:12 +08:00
|
|
|
|
2006-08-25 23:15:13 +08:00
|
|
|
|
|
|
|
#if 0 /* use high-order bits for better randomness (Numerical Recipes in "C") */
|
|
|
|
j = rand() % ndns;
|
|
|
|
#endif
|
|
|
|
j = ((double)ndns)*rand()/(RAND_MAX + 1.0);
|
2006-02-05 00:33:12 +08:00
|
|
|
|
2006-05-15 01:18:55 +08:00
|
|
|
if ( creds && !BER_BVISEMPTY( &creds[j] ) ) {
|
2006-07-02 00:45:44 +08:00
|
|
|
cred = creds[j];
|
2006-02-05 00:33:12 +08:00
|
|
|
}
|
2006-08-25 23:15:13 +08:00
|
|
|
|
2006-07-02 00:45:44 +08:00
|
|
|
if ( do_bind( uri, dns[j], &cred, 1, force, chaserefs, noinit, &ld )
|
2006-03-25 18:13:30 +08:00
|
|
|
&& !force )
|
|
|
|
{
|
2005-10-30 16:57:06 +08:00
|
|
|
break;
|
2006-02-05 00:33:12 +08:00
|
|
|
}
|
2006-02-07 06:08:02 +08:00
|
|
|
|
|
|
|
if ( delay ) {
|
|
|
|
sleep( delay );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( ld != NULL ) {
|
|
|
|
ldap_unbind_ext( ld, NULL, NULL );
|
|
|
|
ld = NULL;
|
2005-10-29 15:22:35 +08:00
|
|
|
}
|
2006-02-05 00:33:12 +08:00
|
|
|
|
2005-11-11 07:58:24 +08:00
|
|
|
#ifdef _WIN32
|
|
|
|
end = GetTickCount();
|
|
|
|
end -= beg;
|
|
|
|
|
2006-06-09 08:11:34 +08:00
|
|
|
fprintf( stderr, " PID=%ld - Bind done %d in %d.%03d seconds.\n",
|
|
|
|
(long) pid, i, end / 1000, end % 1000 );
|
2005-11-11 07:58:24 +08:00
|
|
|
#else
|
2005-11-11 07:22:40 +08:00
|
|
|
gettimeofday( &end, NULL );
|
|
|
|
end.tv_usec -= beg.tv_usec;
|
|
|
|
if (end.tv_usec < 0 ) {
|
|
|
|
end.tv_usec += 1000000;
|
|
|
|
end.tv_sec -= 1;
|
|
|
|
}
|
|
|
|
end.tv_sec -= beg.tv_sec;
|
|
|
|
|
2006-06-09 08:11:34 +08:00
|
|
|
fprintf( stderr, " PID=%ld - Bind done %d in %ld.%06ld seconds.\n",
|
|
|
|
(long) pid, i, (long) end.tv_sec, (long) end.tv_usec );
|
2005-11-11 07:58:24 +08:00
|
|
|
#endif
|
2006-02-08 03:11:51 +08:00
|
|
|
|
2006-05-15 01:18:55 +08:00
|
|
|
if ( dns ) {
|
|
|
|
for ( i = 0; i < ndns; i++ ) {
|
|
|
|
free( dns[i] );
|
|
|
|
}
|
|
|
|
free( dns );
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( creds ) {
|
|
|
|
for ( i = 0; i < ndns; i++ ) {
|
|
|
|
if ( creds[i].bv_val != nullstr ) {
|
|
|
|
free( creds[i].bv_val );
|
|
|
|
}
|
2006-02-08 03:11:51 +08:00
|
|
|
}
|
2006-05-15 01:18:55 +08:00
|
|
|
free( creds );
|
2006-02-08 03:11:51 +08:00
|
|
|
}
|
|
|
|
|
2005-10-30 16:57:06 +08:00
|
|
|
return 0;
|
2005-10-29 15:22:35 +08:00
|
|
|
}
|