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 rc = slap_str2ad( type, &desc, &text );
52 if( rc != LDAP_SUCCESS ) {
53 fprintf( stderr, "%s: unrecognized attribute type: %s\n",
58 desc = type = attr_normalize( argv[argc - 1] );
61 if ( !be->be_index_attr( be, desc ) ) {
62 fprintf( stderr, "attribute type \"%s\": no indices to generate\n",
67 if( be->be_entry_open( be, 0 ) != 0 ) {
68 fprintf( stderr, "%s: could not open database.\n",
73 for ( id = be->be_entry_first( be );
75 id = be->be_entry_next( be ) )
77 Entry* e = be->be_entry_get( be, id );
81 "entry id=%08lx: no data\n", (long) id );
83 if( continuemode ) continue;
88 printf("indexing id=%08lx dn=\"%s\"\n",
92 #ifndef SLAPD_SCHEMA_NOT_COMPAT
93 if( strcasecmp( type, "dn" ) == 0 )
95 struct berval **values;
97 struct berval *bvals[2];
100 bv.bv_len = strlen( bv.bv_val );
106 if ( be->be_index_change( be,
107 desc, values, id, SLAP_INDEX_ADD_OP ) )
111 if( !continuemode ) {
122 #ifdef SLAPD_SCHEMA_NOT_COMPAT
123 for( attr = attrs_find( e->e_attrs, desc );
125 attr = attrs_find( attr->a_next, desc ) )
127 if (( attr = attr_find( e->e_attrs, type )) != NULL )
131 if ( be->be_index_change( be,
132 desc, attr->a_vals, id, SLAP_INDEX_ADD_OP ) )
136 if( !continuemode ) {
148 (void) be->be_entry_close( be );