3 * Copyright 1998-1999 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, ( 4 * loops ));
91 do_search( char *host, int port, char *sbase, char *filter, int maxloop )
95 char *attrs[] = { "cn", "sn", NULL };
98 if (( ld = ldap_init( host, port )) == NULL ) {
99 perror( "ldap_init" );
100 exit( EXIT_FAILURE );
103 if ( ldap_bind_s( ld, NULL, NULL, LDAP_AUTH_SIMPLE ) != LDAP_SUCCESS ) {
104 ldap_perror( ld, "ldap_bind" );
105 exit( EXIT_FAILURE );
109 fprintf( stderr, "PID=%ld - Search(%d): base=\"%s\", filter=\"%s\".\n",
110 (long) pid, maxloop, sbase, filter );
112 for ( i = 0; i < maxloop; i++ ) {
116 if (( rc = ldap_search_s( ld, sbase, LDAP_SCOPE_SUBTREE,
117 filter, attrs, 0, &res )) != LDAP_SUCCESS ) {
119 ldap_perror( ld, "ldap_search" );
120 if ( rc != LDAP_NO_SUCH_OBJECT ) break;
128 fprintf( stderr, " PID=%ld - Search done.\n", (long) pid );