3 * Copyright 1998-1999 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 )
24 int rc = EXIT_SUCCESS;
26 slap_tool_init( "slapindex", SLAPINDEX, argc, argv );
28 if( !be->be_entry_open &&
29 !be->be_entry_close &&
30 !be->be_entry_first &&
34 !be->be_index_change )
36 fprintf( stderr, "%s: database doesn't support necessary operations.\n",
41 #ifdef SLAPD_SCHEMA_NOT_COMPAT
42 type = argv[argc - 1];
44 type = attr_normalize( argv[argc - 1] );
47 if ( !be->be_index_attr( be, type ) ) {
48 fprintf( stderr, "attribute type \"%s\": no indices to generate\n",
53 if( be->be_entry_open( be, 0 ) != 0 ) {
54 fprintf( stderr, "%s: could not open database.\n",
59 for ( id = be->be_entry_first( be );
61 id = be->be_entry_next( be ) )
63 struct berval **values;
64 Entry* e = be->be_entry_get( be, id );
66 struct berval *bvals[2];
70 "entry id=%08lx: no data\n", (long) id );
72 if( continuemode ) continue;
77 printf("indexing id=%08lx dn=\"%s\"\n",
81 if( strcasecmp( type, "dn" ) == 0 ) {
83 bv.bv_len = strlen( bv.bv_val );
90 Attribute *attr = attr_find( e->e_attrs, type );
97 values = attr->a_vals;
100 if ( be->be_index_change( be,
101 type, values, id, SLAP_INDEX_ADD_OP ) )
105 if( !continuemode ) {
114 (void) be->be_entry_close( be );