1 /* $OpenLDAP: pkg/ldap/servers/slapd/slapcat.c,v 1.7.2.6 2008/04/14 18:45:07 quanah Exp $ */
2 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
4 * Copyright 1998-2008 The OpenLDAP Foundation.
5 * Portions Copyright 1998-2003 Kurt D. Zeilenga.
6 * Portions Copyright 2003 IBM Corporation.
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted only as authorized by the OpenLDAP
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>.
18 * This work was initially developed by Kurt Zeilenga for inclusion
19 * in OpenLDAP Software. Additional signficant contributors include
27 #include <ac/stdlib.h>
29 #include <ac/socket.h>
30 #include <ac/string.h>
32 #include "slapcommon.h"
35 static volatile sig_atomic_t gotsig
;
38 slapcat_sig( int sig
)
44 slapcat( int argc
, char **argv
)
47 int rc
= EXIT_SUCCESS
;
49 const char *progname
= "slapcat";
51 slap_tool_init( progname
, SLAPCAT
, argc
, argv
);
54 (void) SIGNAL( SIGPIPE
, slapcat_sig
);
57 (void) SIGNAL( SIGHUP
, slapcat_sig
);
59 (void) SIGNAL( SIGINT
, slapcat_sig
);
60 (void) SIGNAL( SIGTERM
, slapcat_sig
);
62 if( !be
->be_entry_open
||
63 !be
->be_entry_close
||
64 !be
->be_entry_first
||
68 fprintf( stderr
, "%s: database doesn't support necessary operations.\n",
73 if( be
->be_entry_open( be
, 0 ) != 0 ) {
74 fprintf( stderr
, "%s: could not open database.\n",
80 for ( id
= be
->be_entry_first( be
);
82 id
= be
->be_entry_next( be
) )
91 e
= be
->be_entry_get( be
, id
);
93 printf("# no data for entry id=%08lx\n\n", (long) id
);
95 if( continuemode
) continue;
99 if( sub_ndn
.bv_len
&& !dnIsSuffix( &e
->e_nname
, &sub_ndn
) ) {
100 be_entry_release_r( &op
, e
);
104 if( filter
!= NULL
) {
105 int rc
= test_filter( NULL
, e
, filter
);
106 if( rc
!= LDAP_COMPARE_TRUE
) {
107 be_entry_release_r( &op
, e
);
113 printf( "# id=%08lx\n", (long) id
);
116 data
= entry2str( e
, &len
);
117 be_entry_release_r( &op
, e
);
119 if ( data
== NULL
) {
120 printf("# bad data for entry id=%08lx\n\n", (long) id
);
122 if( continuemode
) continue;
126 if ( fputs( data
, ldiffp
->fp
) == EOF
||
127 fputs( "\n", ldiffp
->fp
) == EOF
) {
128 fprintf(stderr
, "%s: error writing output.\n",
135 be
->be_entry_close( be
);