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, loops );
85 do_search( char *host, int port, char *sbase, char *filter, int maxloop )
89 char *attrs[] = { "cn", "sn", NULL };
91 if (( ld = ldap_init( host, port )) == NULL ) {
92 perror( "ldap_init" );
96 if ( ldap_bind_s( ld, NULL, NULL, LDAP_AUTH_SIMPLE ) != LDAP_SUCCESS ) {
97 ldap_perror( ld, "ldap_bind" );
102 fprintf( stderr, "Search(%d): base=\"%s\", filter=\"%s\".\n",
103 maxloop, sbase, filter );
105 for ( i = 0; i < maxloop; i++ ) {
108 if ( ldap_search_s( ld, sbase, LDAP_SCOPE_SUBTREE,
109 filter, attrs, 0, &res ) != LDAP_SUCCESS ) {
111 ldap_perror( ld, "ldap_search" );