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