12 #ifdef HAVE_SYS_PARAM_H
13 #include <sys/param.h>
22 do_search( char *host, int port, char *sbase, char *filter, int maxloop );
27 fprintf( stderr, "usage: %s [-h <host>] -p port -b <searchbase> -f <searchfiter> [-l <loops>]\n",
33 main( int argc, char **argv )
36 char *host = "localhost";
42 while ( (i = getopt( argc, argv, "h:p:b:f:l:" )) != EOF ) {
44 case 'h': /* the servers host */
45 host = strdup( optarg );
48 case 'p': /* the servers port */
49 port = atoi( optarg );
52 case 'b': /* file with search base */
53 sbase = strdup( optarg );
56 case 'f': /* the search request */
57 filter = strdup( optarg );
60 case 'l': /* number of loops */
61 loops = atoi( optarg );
70 if (( sbase == NULL ) || ( filter == NULL ) || ( port == -1 ))
73 if ( *filter == '\0' ) {
75 fprintf( stderr, "%s: invalid EMPTY search filter.\n",
81 do_search( host, port, sbase, filter, ( 4 * loops ));
88 do_search( char *host, int port, char *sbase, char *filter, int maxloop )
92 char *attrs[] = { "cn", "sn", NULL };
95 if (( ld = ldap_init( host, port )) == NULL ) {
96 perror( "ldap_init" );
100 if ( ldap_bind_s( ld, NULL, NULL, LDAP_AUTH_SIMPLE ) != LDAP_SUCCESS ) {
101 ldap_perror( ld, "ldap_bind" );
106 fprintf( stderr, "PID=%ld - Search(%d): base=\"%s\", filter=\"%s\".\n",
107 (long) pid, maxloop, sbase, filter );
109 for ( i = 0; i < maxloop; i++ ) {
113 if (( rc = ldap_search_s( ld, sbase, LDAP_SCOPE_SUBTREE,
114 filter, attrs, 0, &res )) != LDAP_SUCCESS ) {
116 ldap_perror( ld, "ldap_search" );
117 if ( rc != LDAP_NO_SUCH_OBJECT ) break;
125 fprintf( stderr, " PID=%ld - Search done.\n", (long) pid );