3 * Copyright 1998-2000 The OpenLDAP Foundation, All Rights Reserved.
4 * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
10 #include <ac/stdlib.h>
13 #include <ac/string.h>
14 #include <ac/socket.h>
15 #include <ac/unistd.h>
17 #include "slapcommon.h"
20 main( int argc, char **argv )
23 #ifdef SLAPD_SCHEMA_NOT_COMPAT
24 AttributeDescription *desc;
30 int rc = EXIT_SUCCESS;
32 slap_tool_init( "slapindex", SLAPINDEX, argc, argv );
34 if( !be->be_entry_open &&
35 !be->be_entry_close &&
36 !be->be_entry_first &&
40 !be->be_index_change )
42 fprintf( stderr, "%s: database doesn't support necessary operations.\n",
47 #ifdef SLAPD_SCHEMA_NOT_COMPAT
48 type = argv[argc - 1];
50 if( strcasecmp( type, "dn" ) == 0 ) {
54 rc = slap_str2ad( type, &desc, &text );
56 if( rc != LDAP_SUCCESS ) {
57 fprintf( stderr, "%s: unrecognized attribute type: %s\n",
63 desc = type = attr_normalize( argv[argc - 1] );
66 if ( !be->be_index_attr( be, desc ) ) {
67 fprintf( stderr, "attribute type \"%s\": no indices to generate\n",
72 if( be->be_entry_open( be, 0 ) != 0 ) {
73 fprintf( stderr, "%s: could not open database.\n",
78 for ( id = be->be_entry_first( be );
80 id = be->be_entry_next( be ) )
82 struct berval **values;
83 Entry* e = be->be_entry_get( be, id );
85 struct berval *bvals[2];
89 "entry id=%08lx: no data\n", (long) id );
91 if( continuemode ) continue;
96 printf("indexing id=%08lx dn=\"%s\"\n",
100 #ifdef SLAPD_SCHEMA_NOT_COMPAT
103 if( strcasecmp( type, "dn" ) == 0 )
106 bv.bv_val = e->e_ndn;
107 bv.bv_len = strlen( bv.bv_val );
113 if ( be->be_index_change( be,
114 desc, values, id, SLAP_INDEX_ADD_OP ) )
118 if( !continuemode ) {
127 #ifdef SLAPD_SCHEMA_NOT_COMPAT
128 for( attr = attrs_find( e->e_attrs, desc );
130 attr = attrs_find( attr, desc ) )
132 if (( attr = attr_find( e->e_attrs, type )) != NULL )
136 if ( be->be_index_change( be,
137 desc, attr->a_vals, id, SLAP_INDEX_ADD_OP ) )
141 if( !continuemode ) {
153 (void) be->be_entry_close( be );