]> git.sur5r.net Git - openldap/blob - tests/slapd-read.c
Silence libtool if `make -s' is running
[openldap] / tests / slapd-read.c
1 #include "portable.h"
2
3 #include <stdio.h>
4
5 #include <ac/string.h>
6 #include <ac/ctype.h>
7 #include <ac/socket.h>
8 #include <ac/unistd.h>
9 #include <ac/wait.h>
10
11 #include <sys/param.h>
12
13 #include "lber.h"
14 #include "ldap.h"
15
16 #define LOOPS   100
17
18 static void
19 do_read( char *host, int port, char *entry, int maxloop );
20
21 static void
22 usage( char *name )
23 {
24         fprintf( stderr, "usage: %s [-h <host>] -p port -e <entry> [-l <loops>]\n",
25                         name );
26         exit( 1 );
27 }
28
29 int
30 main( int argc, char **argv )
31 {
32         int             i, j;
33         char        *host = "localhost";
34         int                     port = -1;
35         char            *entry = NULL;
36         int                     loops = LOOPS;
37
38         while ( (i = getopt( argc, argv, "h:p:e:l:" )) != EOF ) {
39                 switch( i ) {
40                         case 'h':               /* the servers host */
41                                 host = strdup( optarg );
42                         break;
43
44                         case 'p':               /* the servers port */
45                                 port = atoi( optarg );
46                                 break;
47
48                         case 'e':               /* file with entry search request */
49                                 entry = strdup( optarg );
50                                 break;
51
52                         case 'l':               /* the number of loops */
53                                 loops = atoi( optarg );
54                                 break;
55
56                         default:
57                                 usage( argv[0] );
58                                 break;
59                 }
60         }
61
62         if (( entry == NULL ) || ( port == -1 ))
63                 usage( argv[0] );
64
65         if ( *entry == '\0' ) {
66
67                 fprintf( stderr, "%s: invalid EMPTY entry DN.\n",
68                                 argv[0] );
69                 exit( 1 );
70
71         }
72
73         do_read( host, port, entry, ( 4 * loops ));
74
75         exit( 0 );
76 }
77
78
79 static void
80 do_read( char *host, int port, char *entry, int maxloop )
81 {
82         LDAP    *ld;
83         int     i;
84         char    *attrs[] = { "cn", "sn", NULL };
85         char    *filter = "(objectclass=*)";
86         pid_t   pid = getpid();
87
88         if (( ld = ldap_init( host, port )) == NULL ) {
89                 perror( "ldap_init" );
90                 exit( 1 );
91         }
92
93         if ( ldap_bind_s( ld, NULL, NULL, LDAP_AUTH_SIMPLE ) != LDAP_SUCCESS ) {
94                 ldap_perror( ld, "ldap_bind" );
95                  exit( 1 );
96         }
97
98
99         fprintf( stderr, "PID=%ld - Read(%d): entry=\"%s\".\n",
100                                 pid, maxloop, entry );
101
102         for ( i = 0; i < maxloop; i++ ) {
103                 LDAPMessage *res;
104                 int         rc;
105
106                 if (( rc = ldap_search_s( ld, entry, LDAP_SCOPE_BASE,
107                                 filter, attrs, 0, &res )) != LDAP_SUCCESS ) {
108
109                         ldap_perror( ld, "ldap_read" );
110                         if ( rc != LDAP_NO_SUCH_OBJECT ) break;
111                         continue;
112
113                 }
114
115                 ldap_msgfree( res );
116         }
117
118         fprintf( stderr, " PID=%ld - Read done.\n", pid );
119
120         ldap_unbind( ld );
121 }
122
123