10 #include <ac/unistd.h>
13 #ifdef HAVE_SYS_PARAM_H
14 #include <sys/param.h>
22 do_read( char *host, int port, char *entry, int maxloop );
27 fprintf( stderr, "usage: %s [-h <host>] -p port -e <entry> [-l <loops>]\n",
33 main( int argc, char **argv )
36 char *host = "localhost";
41 while ( (i = getopt( argc, argv, "h:p:e:l:" )) != EOF ) {
43 case 'h': /* the servers host */
44 host = strdup( optarg );
47 case 'p': /* the servers port */
48 port = atoi( optarg );
51 case 'e': /* file with entry search request */
52 entry = strdup( optarg );
55 case 'l': /* the number of loops */
56 loops = atoi( optarg );
65 if (( entry == NULL ) || ( port == -1 ))
68 if ( *entry == '\0' ) {
70 fprintf( stderr, "%s: invalid EMPTY entry DN.\n",
76 do_read( host, port, entry, ( 4 * loops ));
83 do_read( char *host, int port, char *entry, int maxloop )
87 char *attrs[] = { "cn", "sn", NULL };
88 char *filter = "(objectclass=*)";
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, "PID=%ld - Read(%d): entry=\"%s\".\n",
103 (long) pid, maxloop, entry );
105 for ( i = 0; i < maxloop; i++ ) {
109 if (( rc = ldap_search_s( ld, entry, LDAP_SCOPE_BASE,
110 filter, attrs, 0, &res )) != LDAP_SUCCESS ) {
112 ldap_perror( ld, "ldap_read" );
113 if ( rc != LDAP_NO_SUCH_OBJECT ) break;
121 fprintf( stderr, " PID=%ld - Read done.\n", (long) pid );