10 #include <ac/unistd.h>
13 #ifdef HAVE_SYS_PARAM_H
14 #include <sys/param.h>
23 do_read( char *host, int port, char *entry, int maxloop );
28 fprintf( stderr, "usage: %s [-h <host>] -p port -e <entry> [-l <loops>]\n",
34 main( int argc, char **argv )
37 char *host = "localhost";
42 while ( (i = getopt( argc, argv, "h:p:e:l:" )) != EOF ) {
44 case 'h': /* the servers host */
45 host = strdup( optarg );
48 case 'p': /* the servers port */
49 port = atoi( optarg );
52 case 'e': /* file with entry search request */
53 entry = strdup( optarg );
56 case 'l': /* the number of loops */
57 loops = atoi( optarg );
66 if (( entry == NULL ) || ( port == -1 ))
69 if ( *entry == '\0' ) {
71 fprintf( stderr, "%s: invalid EMPTY entry DN.\n",
77 do_read( host, port, entry, ( 4 * loops ));
84 do_read( char *host, int port, char *entry, int maxloop )
88 char *attrs[] = { "cn", "sn", NULL };
89 char *filter = "(objectclass=*)";
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 - Read(%d): entry=\"%s\".\n",
104 (long) pid, maxloop, entry );
106 for ( i = 0; i < maxloop; i++ ) {
110 if (( rc = ldap_search_s( ld, entry, LDAP_SCOPE_BASE,
111 filter, attrs, 0, &res )) != LDAP_SUCCESS ) {
113 ldap_perror( ld, "ldap_read" );
114 if ( rc != LDAP_NO_SUCH_OBJECT ) break;
122 fprintf( stderr, " PID=%ld - Read done.\n", (long) pid );