11 #include <sys/param.h>
19 do_search( char *host, int port, char *sbase, char *filter, int maxloop );
24 fprintf( stderr, "usage: %s [-h <host>] -p port -b <searchbase> -f <searchfiter> [-l <loops>]\n",
30 main( int argc, char **argv )
33 char *host = "localhost";
39 while ( (i = getopt( argc, argv, "h:p:b:f:l:" )) != EOF ) {
41 case 'h': /* the servers host */
42 host = strdup( optarg );
45 case 'p': /* the servers port */
46 port = atoi( optarg );
49 case 'b': /* file with search base */
50 sbase = strdup( optarg );
53 case 'f': /* the search request */
54 filter = strdup( optarg );
57 case 'l': /* number of loops */
58 loops = atoi( optarg );
67 if (( sbase == NULL ) || ( filter == NULL ) || ( port == -1 ))
70 if ( *filter == '\0' ) {
72 fprintf( stderr, "%s: invalid EMPTY search filter.\n",
78 do_search( host, port, sbase, filter, ( 4 * loops ));
85 do_search( char *host, int port, char *sbase, char *filter, int maxloop )
89 char *attrs[] = { "cn", "sn", NULL };
92 if (( ld = ldap_init( host, port )) == NULL ) {
93 perror( "ldap_init" );
97 if ( ldap_bind_s( ld, NULL, NULL, LDAP_AUTH_SIMPLE ) != LDAP_SUCCESS ) {
98 ldap_perror( ld, "ldap_bind" );
103 fprintf( stderr, "PID=%ld - Search(%d): base=\"%s\", filter=\"%s\".\n",
104 pid, maxloop, sbase, filter );
106 for ( i = 0; i < maxloop; i++ ) {
110 if (( rc = ldap_search_s( ld, sbase, LDAP_SCOPE_SUBTREE,
111 filter, attrs, 0, &res )) != LDAP_SUCCESS ) {
113 ldap_perror( ld, "ldap_search" );
114 if ( rc != LDAP_NO_SUCH_OBJECT ) break;
122 fprintf( stderr, " PID=%ld - Search done.\n", pid );