2 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
4 * Copyright 1998-2009 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 Pierangelo Masarati for inclusion
19 * in OpenLDAP Software. Code portions borrowed from slapcat.c;
20 * contributors are Kurt Zeilenga and Jong Hyuk Choi
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 slapschema( int argc, char **argv )
47 int rc = EXIT_SUCCESS;
48 const char *progname = "slapschema";
49 Connection conn = { 0 };
50 OperationBuffer opbuf;
56 slap_tool_init( progname, SLAPCAT, argc, argv );
58 requestBSF = ( sub_ndn.bv_len || filter );
61 (void) SIGNAL( SIGPIPE, slapcat_sig );
64 (void) SIGNAL( SIGHUP, slapcat_sig );
66 (void) SIGNAL( SIGINT, slapcat_sig );
67 (void) SIGNAL( SIGTERM, slapcat_sig );
69 if( !be->be_entry_open ||
70 !be->be_entry_close ||
71 !( be->be_entry_first || be->be_entry_first_x ) ||
75 fprintf( stderr, "%s: database doesn't support necessary operations.\n",
80 if( be->be_entry_open( be, 0 ) != 0 ) {
81 fprintf( stderr, "%s: could not open database.\n",
86 thrctx = ldap_pvt_thread_pool_context();
87 connection_fake_init( &conn, &opbuf, thrctx );
89 op->o_tmpmemctx = NULL;
93 if ( !requestBSF && be->be_entry_first ) {
94 id = be->be_entry_first( be );
97 if ( be->be_entry_first_x ) {
98 id = be->be_entry_first_x( be,
99 sub_ndn.bv_len ? &sub_ndn : NULL, scope, filter );
102 assert( be->be_entry_first != NULL );
104 id = be->be_entry_first( be );
108 for ( ; id != NOID; id = be->be_entry_next( be ) ) {
110 char textbuf[SLAP_TEXT_BUFLEN];
111 size_t textlen = sizeof(textbuf);
112 const char *text = NULL;
117 e = be->be_entry_get( be, id );
119 printf("# no data for entry id=%08lx\n\n", (long) id );
121 if( continuemode ) continue;
126 if ( sub_ndn.bv_len && !dnIsSuffixScope( &e->e_nname, &sub_ndn, scope ) )
128 be_entry_release_r( op, e );
133 if ( filter != NULL ) {
134 int rc = test_filter( NULL, e, filter );
135 if ( rc != LDAP_COMPARE_TRUE ) {
136 be_entry_release_r( op, e );
143 printf( "# id=%08lx\n", (long) id );
146 rc = entry_schema_check( op, e, NULL, 0, 0, NULL,
147 &text, textbuf, textlen );
148 if ( rc != LDAP_SUCCESS ) {
149 fprintf( ldiffp->fp, "# (%d) %s%s%s\n",
150 rc, ldap_err2string( rc ),
153 fprintf( ldiffp->fp, "dn: %s\n\n", e->e_name.bv_val );
156 be_entry_release_r( op, e );
159 be->be_entry_close( be );
161 if ( slap_tool_destroy() )