3 * Copyright 1998-1999 The OpenLDAP Foundation, All Rights Reserved.
4 * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
10 #include <ac/stdlib.h>
13 #include <ac/socket.h>
14 #include <ac/string.h>
15 #include <ac/unistd.h>
18 #ifdef HAVE_SYS_PARAM_H
19 #include <sys/param.h>
27 do_search( char *host, int port, char *sbase, char *filter, int maxloop );
32 fprintf( stderr, "usage: %s [-h <host>] -p port -b <searchbase> -f <searchfiter> [-l <loops>]\n",
38 main( int argc, char **argv )
41 char *host = "localhost";
47 while ( (i = getopt( argc, argv, "h:p:b:f:l:" )) != EOF ) {
49 case 'h': /* the servers host */
50 host = strdup( optarg );
53 case 'p': /* the servers port */
54 port = atoi( optarg );
57 case 'b': /* file with search base */
58 sbase = strdup( optarg );
61 case 'f': /* the search request */
62 filter = strdup( optarg );
65 case 'l': /* number of loops */
66 loops = atoi( optarg );
75 if (( sbase == NULL ) || ( filter == NULL ) || ( port == -1 ))
78 if ( *filter == '\0' ) {
80 fprintf( stderr, "%s: invalid EMPTY search filter.\n",
86 do_search( host, port, sbase, filter, ( 4 * loops ));
93 do_search( char *host, int port, char *sbase, char *filter, int maxloop )
97 char *attrs[] = { "cn", "sn", NULL };
100 if (( ld = ldap_init( host, port )) == NULL ) {
101 perror( "ldap_init" );
102 exit( EXIT_FAILURE );
105 if ( ldap_bind_s( ld, NULL, NULL, LDAP_AUTH_SIMPLE ) != LDAP_SUCCESS ) {
106 ldap_perror( ld, "ldap_bind" );
107 exit( EXIT_FAILURE );
111 fprintf( stderr, "PID=%ld - Search(%d): base=\"%s\", filter=\"%s\".\n",
112 (long) pid, maxloop, sbase, filter );
114 for ( i = 0; i < maxloop; i++ ) {
118 if (( rc = ldap_search_s( ld, sbase, LDAP_SCOPE_SUBTREE,
119 filter, attrs, 0, &res )) != LDAP_SUCCESS ) {
121 ldap_perror( ld, "ldap_search" );
122 if ( rc != LDAP_NO_SUCH_OBJECT ) break;
130 fprintf( stderr, " PID=%ld - Search done.\n", (long) pid );