]> git.sur5r.net Git - openldap/blob - servers/slapd/tools/slapcat.c
Add CSRIMALLOC support
[openldap] / servers / slapd / tools / slapcat.c
1 /*
2  * Copyright 1998-1999 The OpenLDAP Foundation, All Rights Reserved.
3  * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
4  */
5 #include "portable.h"
6
7 #include <stdio.h>
8
9 #include <ac/stdlib.h>
10 #include <ac/ctype.h>
11 #include <ac/socket.h>
12 #include <ac/string.h>
13
14 #include "slapcommon.h"
15
16 int
17 main( int argc, char **argv )
18 {
19         ID id;
20         int rc = EXIT_SUCCESS;
21
22         slap_tool_init( "slapcat", SLAPCAT, argc, argv );
23
24         if( !be->be_entry_open &&
25                 !be->be_entry_close &&
26                 !be->be_entry_first &&
27                 !be->be_entry_next &&
28                 !be->be_entry_get )
29         {
30                 fprintf( stderr, "%s: database doesn't support necessary operations.\n",
31                         progname );
32                 exit( EXIT_FAILURE );
33         }
34
35         if( be->be_entry_open( be, 0 ) != 0 ) {
36                 fprintf( stderr, "%s: could not open database.\n",
37                         progname );
38                 exit( EXIT_FAILURE );
39         }
40
41         for ( id = be->be_entry_first( be );
42                 id != NOID;
43                 id = be->be_entry_next( be ) )
44         {
45                 char *data;
46                 int len;
47                 Entry* e = be->be_entry_get( be, id );
48
49                 if( verbose ) {
50                         printf( "# id=%08lx\n", (long) id );
51                 }
52
53                 if ( e == NULL ) {
54                         printf("# no data for entry id=%08lx\n\n", (long) id );
55                         rc = EXIT_FAILURE;
56                         if( continuemode ) continue;
57                         break;
58                 }
59
60                 data = entry2str( e, &len );
61                 entry_free( e );
62
63                 if ( data == NULL ) {
64                         printf("# bad data for entry id=%08lx\n\n", (long) id );
65                         rc = EXIT_FAILURE;
66                         if( continuemode ) continue;
67                         break;
68                 }
69
70                 fputs( data, ldiffp );
71                 fputs( "\n", ldiffp );
72         }
73
74         be->be_entry_close( be );
75
76         slap_tool_destroy();
77         return rc;
78 }