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;
53 slap_tool_init( progname, SLAPCAT, argc, argv );
56 (void) SIGNAL( SIGPIPE, slapcat_sig );
59 (void) SIGNAL( SIGHUP, slapcat_sig );
61 (void) SIGNAL( SIGINT, slapcat_sig );
62 (void) SIGNAL( SIGTERM, slapcat_sig );
64 if( !be->be_entry_open ||
65 !be->be_entry_close ||
66 !be->be_entry_first ||
70 fprintf( stderr, "%s: database doesn't support necessary operations.\n",
75 if( be->be_entry_open( be, 0 ) != 0 ) {
76 fprintf( stderr, "%s: could not open database.\n",
81 connection_fake_init( &conn, &opbuf, &conn );
83 op->o_tmpmemctx = NULL;
86 for ( id = be->be_entry_first( be );
88 id = be->be_entry_next( be ) )
91 char textbuf[SLAP_TEXT_BUFLEN];
92 size_t textlen = sizeof(textbuf);
93 const char *text = NULL;
98 e = be->be_entry_get( be, id );
100 printf("# no data for entry id=%08lx\n\n", (long) id );
102 if( continuemode ) continue;
106 if( sub_ndn.bv_len && !dnIsSuffix( &e->e_nname, &sub_ndn ) ) {
107 be_entry_release_r( op, e );
111 if( filter != NULL ) {
112 int rc = test_filter( NULL, e, filter );
113 if( rc != LDAP_COMPARE_TRUE ) {
114 be_entry_release_r( op, e );
120 printf( "# id=%08lx\n", (long) id );
123 rc = entry_schema_check( op, e, NULL, 0, 0, NULL,
124 &text, textbuf, textlen );
125 if ( rc != LDAP_SUCCESS ) {
126 fprintf( ldiffp->fp, "# (%d) %s%s%s\n",
127 rc, ldap_err2string( rc ),
130 fprintf( ldiffp->fp, "dn: %s\n\n", e->e_name.bv_val );
133 be_entry_release_r( op, e );
136 be->be_entry_close( be );
138 if ( slap_tool_destroy() )