10 #include <ac/unistd.h>
13 #ifdef HAVE_SYS_PARAM_H
14 #include <sys/param.h>
23 do_search( char *host, int port, char *sbase, char *filter, int maxloop );
28 fprintf( stderr, "usage: %s [-h <host>] -p port -b <searchbase> -f <searchfiter> [-l <loops>]\n",
34 main( int argc, char **argv )
37 char *host = "localhost";
43 while ( (i = getopt( argc, argv, "h:p:b:f:l:" )) != EOF ) {
45 case 'h': /* the servers host */
46 host = strdup( optarg );
49 case 'p': /* the servers port */
50 port = atoi( optarg );
53 case 'b': /* file with search base */
54 sbase = strdup( optarg );
57 case 'f': /* the search request */
58 filter = strdup( optarg );
61 case 'l': /* number of loops */
62 loops = atoi( optarg );
71 if (( sbase == NULL ) || ( filter == NULL ) || ( port == -1 ))
74 if ( *filter == '\0' ) {
76 fprintf( stderr, "%s: invalid EMPTY search filter.\n",
82 do_search( host, port, sbase, filter, ( 4 * loops ));
89 do_search( char *host, int port, char *sbase, char *filter, int maxloop )
93 char *attrs[] = { "cn", "sn", NULL };
96 if (( ld = ldap_init( host, port )) == NULL ) {
97 perror( "ldap_init" );
101 if ( ldap_bind_s( ld, NULL, NULL, LDAP_AUTH_SIMPLE ) != LDAP_SUCCESS ) {
102 ldap_perror( ld, "ldap_bind" );
107 fprintf( stderr, "PID=%ld - Search(%d): base=\"%s\", filter=\"%s\".\n",
108 (long) pid, maxloop, sbase, filter );
110 for ( i = 0; i < maxloop; i++ ) {
114 if (( rc = ldap_search_s( ld, sbase, LDAP_SCOPE_SUBTREE,
115 filter, attrs, 0, &res )) != LDAP_SUCCESS ) {
117 ldap_perror( ld, "ldap_search" );
118 if ( rc != LDAP_NO_SUCH_OBJECT ) break;
126 fprintf( stderr, " PID=%ld - Search done.\n", (long) pid );