]> git.sur5r.net Git - openldap/blob - servers/slapd/slapcat.c
fix negative counters; prepare for imrpved count of sent data
[openldap] / servers / slapd / slapcat.c
1 /* $OpenLDAP$ */
2 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
3  *
4  * Copyright 1998-2004 The OpenLDAP Foundation.
5  * Portions Copyright 1998-2003 Kurt D. Zeilenga.
6  * Portions Copyright 2003 IBM Corporation.
7  * All rights reserved.
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted only as authorized by the OpenLDAP
11  * Public License.
12  *
13  * A copy of this license is available in file LICENSE in the
14  * top-level directory of the distribution or, alternatively, at
15  * <http://www.OpenLDAP.org/license.html>.
16  */
17 /* ACKNOWLEDGEMENTS:
18  * This work was initially developed by Kurt Zeilenga for inclusion
19  * in OpenLDAP Software.  Additional signficant contributors include
20  *    Jong Hyuk Choi
21  */
22
23 #include "portable.h"
24
25 #include <stdio.h>
26
27 #include <ac/stdlib.h>
28 #include <ac/ctype.h>
29 #include <ac/socket.h>
30 #include <ac/string.h>
31
32 #include "slapcommon.h"
33
34 int
35 slapcat( int argc, char **argv )
36 {
37         ID id;
38         int rc = EXIT_SUCCESS;
39         Operation op = {0};
40         const char *progname = "slapcat";
41
42         slap_tool_init( progname, SLAPCAT, argc, argv );
43
44         if( !be->be_entry_open ||
45                 !be->be_entry_close ||
46                 !be->be_entry_first ||
47                 !be->be_entry_next ||
48                 !be->be_entry_get )
49         {
50                 fprintf( stderr, "%s: database doesn't support necessary operations.\n",
51                         progname );
52                 exit( EXIT_FAILURE );
53         }
54
55         if( be->be_entry_open( be, 0 ) != 0 ) {
56                 fprintf( stderr, "%s: could not open database.\n",
57                         progname );
58                 exit( EXIT_FAILURE );
59         }
60
61         for ( id = be->be_entry_first( be );
62                 id != NOID;
63                 id = be->be_entry_next( be ) )
64         {
65                 char *data;
66                 int len;
67                 Entry* e = be->be_entry_get( be, id );
68                 op.o_bd = be;
69
70                 if ( e == NULL ) {
71                         printf("# no data for entry id=%08lx\n\n", (long) id );
72                         rc = EXIT_FAILURE;
73                         if( continuemode ) continue;
74                         break;
75                 }
76
77                 if( sub_ndn.bv_len && !dnIsSuffix( &e->e_nname, &sub_ndn ) ) {
78                         be_entry_release_r( &op, e );
79                         continue;
80                 }
81
82                 if( filter != NULL ) {
83                         int rc = test_filter( NULL, e, filter );
84                         if( rc != LDAP_COMPARE_TRUE ) {
85                                 be_entry_release_r( &op, e );
86                                 continue;
87                         }
88                 }
89
90                 if ( retrieve_ctxcsn == 0 ) {
91                         if ( is_entry_syncProviderSubentry( e ) ) {
92                                 be_entry_release_r( &op, e );
93                                 continue;
94                         }
95                 }
96
97                 if ( retrieve_synccookie == 0 ) {
98                         if ( is_entry_syncConsumerSubentry( e ) ) {
99                                 be_entry_release_r( &op, e );
100                                 continue;
101                         }
102                 }
103
104                 if( verbose ) {
105                         printf( "# id=%08lx\n", (long) id );
106                 }
107
108                 data = entry2str( e, &len );
109                 be_entry_release_r( &op, e );
110
111                 if ( data == NULL ) {
112                         printf("# bad data for entry id=%08lx\n\n", (long) id );
113                         rc = EXIT_FAILURE;
114                         if( continuemode ) continue;
115                         break;
116                 }
117
118                 fputs( data, ldiffp );
119                 fputs( "\n", ldiffp );
120         }
121
122         be->be_entry_close( be );
123
124         slap_tool_destroy();
125         return rc;
126 }