12 #include <sys/param.h>
20 do_search( char *host, int port, char *sbase, char *filter, int maxloop );
25 fprintf( stderr, "usage: %s [-h <host>] -p port -b <searchbase> -f <searchfiter> [-l <loops>]\n",
31 main( int argc, char **argv )
34 char *host = "localhost";
40 while ( (i = getopt( argc, argv, "h:p:b:f:l:" )) != EOF ) {
42 case 'h': /* the servers host */
43 host = strdup( optarg );
46 case 'p': /* the servers port */
47 port = atoi( optarg );
50 case 'b': /* file with search base */
51 sbase = strdup( optarg );
54 case 'f': /* the search request */
55 filter = strdup( optarg );
58 case 'l': /* number of loops */
59 loops = atoi( optarg );
68 if (( sbase == NULL ) || ( filter == NULL ) || ( port == -1 ))
71 if ( *filter == '\0' ) {
73 fprintf( stderr, "%s: invalid EMPTY search filter.\n",
79 do_search( host, port, sbase, filter, ( 4 * loops ));
86 do_search( char *host, int port, char *sbase, char *filter, int maxloop )
90 char *attrs[] = { "cn", "sn", NULL };
93 if (( ld = ldap_init( host, port )) == NULL ) {
94 perror( "ldap_init" );
98 if ( ldap_bind_s( ld, NULL, NULL, LDAP_AUTH_SIMPLE ) != LDAP_SUCCESS ) {
99 ldap_perror( ld, "ldap_bind" );
104 fprintf( stderr, "PID=%ld - Search(%d): base=\"%s\", filter=\"%s\".\n",
105 (long) pid, maxloop, sbase, filter );
107 for ( i = 0; i < maxloop; i++ ) {
111 if (( rc = ldap_search_s( ld, sbase, LDAP_SCOPE_SUBTREE,
112 filter, attrs, 0, &res )) != LDAP_SUCCESS ) {
114 ldap_perror( ld, "ldap_search" );
115 if ( rc != LDAP_NO_SUCH_OBJECT ) break;
123 fprintf( stderr, " PID=%ld - Search done.\n", (long) pid );