]> git.sur5r.net Git - openldap/blob - servers/slapd/tools/slapcat.c
Add OpenLDAP RCSid to *.[ch] in clients, libraries, and servers.
[openldap] / servers / slapd / tools / slapcat.c
1 /* $OpenLDAP$ */
2 /*
3  * Copyright 1998-1999 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
23         slap_tool_init( "slapcat", SLAPCAT, argc, argv );
24
25         if( !be->be_entry_open &&
26                 !be->be_entry_close &&
27                 !be->be_entry_first &&
28                 !be->be_entry_next &&
29                 !be->be_entry_get )
30         {
31                 fprintf( stderr, "%s: database doesn't support necessary operations.\n",
32                         progname );
33                 exit( EXIT_FAILURE );
34         }
35
36         if( be->be_entry_open( be, 0 ) != 0 ) {
37                 fprintf( stderr, "%s: could not open database.\n",
38                         progname );
39                 exit( EXIT_FAILURE );
40         }
41
42         for ( id = be->be_entry_first( be );
43                 id != NOID;
44                 id = be->be_entry_next( be ) )
45         {
46                 char *data;
47                 int len;
48                 Entry* e = be->be_entry_get( be, id );
49
50                 if( verbose ) {
51                         printf( "# id=%08lx\n", (long) id );
52                 }
53
54                 if ( e == NULL ) {
55                         printf("# no data for entry id=%08lx\n\n", (long) id );
56                         rc = EXIT_FAILURE;
57                         if( continuemode ) continue;
58                         break;
59                 }
60
61                 data = entry2str( e, &len );
62                 entry_free( e );
63
64                 if ( data == NULL ) {
65                         printf("# bad data for entry id=%08lx\n\n", (long) id );
66                         rc = EXIT_FAILURE;
67                         if( continuemode ) continue;
68                         break;
69                 }
70
71                 fputs( data, ldiffp );
72                 fputs( "\n", ldiffp );
73         }
74
75         be->be_entry_close( be );
76
77         slap_tool_destroy();
78         return rc;
79 }