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