]> git.sur5r.net Git - openldap/blob - servers/slapd/tools/slapcat.c
Implement slapcat -s <dn>: Only dump a subtree of the database.
[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( verbose ) {
58                         printf( "# id=%08lx\n", (long) id );
59                 }
60
61                 if ( e == NULL ) {
62                         printf("# no data for entry id=%08lx\n\n", (long) id );
63                         rc = EXIT_FAILURE;
64                         if( continuemode ) continue;
65                         break;
66                 }
67
68                 data = entry2str( e, &len );
69                 be_entry_release_r( &op, e );
70
71                 if ( data == NULL ) {
72                         printf("# bad data for entry id=%08lx\n\n", (long) id );
73                         rc = EXIT_FAILURE;
74                         if( continuemode ) continue;
75                         break;
76                 }
77
78                 fputs( data, ldiffp );
79                 fputs( "\n", ldiffp );
80         }
81
82         be->be_entry_close( be );
83
84         slap_tool_destroy();
85         return rc;
86 }