3 * Copyright 1998-2000 The OpenLDAP Foundation, All Rights Reserved.
4 * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
10 #include <ac/stdlib.h>
14 #include <ac/socket.h>
15 #include <ac/string.h>
16 #include <ac/unistd.h>
25 do_search( char *host, int port, char *sbase, char *filter, int maxloop );
30 fprintf( stderr, "usage: %s [-h <host>] -p port -b <searchbase> -f <searchfiter> [-l <loops>]\n",
36 main( int argc, char **argv )
39 char *host = "localhost";
45 while ( (i = getopt( argc, argv, "h:p:b:f:l:" )) != EOF ) {
47 case 'h': /* the servers host */
48 host = strdup( optarg );
51 case 'p': /* the servers port */
52 port = atoi( optarg );
55 case 'b': /* file with search base */
56 sbase = strdup( optarg );
59 case 'f': /* the search request */
60 filter = strdup( optarg );
63 case 'l': /* number of loops */
64 loops = atoi( optarg );
73 if (( sbase == NULL ) || ( filter == NULL ) || ( port == -1 ))
76 if ( *filter == '\0' ) {
78 fprintf( stderr, "%s: invalid EMPTY search filter.\n",
84 do_search( host, port, sbase, filter, ( 5 * loops ));
90 do_search( char *host, int port, char *sbase, char *filter, int maxloop )
94 char *attrs[] = { "cn", "sn", NULL };
97 if (( ld = ldap_init( host, port )) == NULL ) {
98 perror( "ldap_init" );
102 if ( ldap_bind_s( ld, NULL, NULL, LDAP_AUTH_SIMPLE ) != LDAP_SUCCESS ) {
103 ldap_perror( ld, "ldap_bind" );
104 exit( EXIT_FAILURE );
108 fprintf( stderr, "PID=%ld - Search(%d): base=\"%s\", filter=\"%s\".\n",
109 (long) pid, maxloop, sbase, filter );
111 for ( i = 0; i < maxloop; i++ ) {
115 if (( rc = ldap_search_s( ld, sbase, LDAP_SCOPE_SUBTREE,
116 filter, attrs, 0, &res )) != LDAP_SUCCESS ) {
118 ldap_perror( ld, "ldap_search" );
119 if ( rc != LDAP_NO_SUCH_OBJECT ) break;
127 fprintf( stderr, " PID=%ld - Search done.\n", (long) pid );