]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/tools/slapindex.c
Fix the logic for checking if backend DB has all necessary functions.
[openldap] / servers / slapd / tools / slapindex.c
index ba63e7079950a4be29311b1b06d449d42d7f8499..86aff99b4cece141f4af3e95af2c617856dbb7be 100644 (file)
@@ -1,6 +1,6 @@
 /* $OpenLDAP$ */
 /*
- * Copyright 1998-1999 The OpenLDAP Foundation, All Rights Reserved.
+ * Copyright 1998-2000 The OpenLDAP Foundation, All Rights Reserved.
  * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
  */
 #include "portable.h"
 int
 main( int argc, char **argv )
 {
-       char            *type;
        ID id;
        int rc = EXIT_SUCCESS;
 
        slap_tool_init( "slapindex", SLAPINDEX, argc, argv );
 
-       if( !be->be_entry_open &&
-               !be->be_entry_close &&
-               !be->be_entry_first &&
-               !be->be_entry_next &&
-               !be->be_entry_get &&
-               !be->be_index_attr &&
-               !be->be_index_change )
+       if( !be->be_entry_open ||
+               !be->be_entry_close ||
+               !be->be_entry_first ||
+               !be->be_entry_next  ||
+               !be->be_entry_reindex )
        {
                fprintf( stderr, "%s: database doesn't support necessary operations.\n",
                        progname );
                exit( EXIT_FAILURE );
        }
 
-       type = attr_normalize( argv[argc - 1] );
-
-       if ( !be->be_index_attr( be, type ) ) {
-               fprintf( stderr, "attribute type \"%s\": no indices to generate\n",
-                       type );
-               exit( EXIT_FAILURE );
-       }
-
        if( be->be_entry_open( be, 0 ) != 0 ) {
                fprintf( stderr, "%s: could not open database.\n",
                        progname );
@@ -56,60 +45,23 @@ main( int argc, char **argv )
                id != NOID;
                id = be->be_entry_next( be ) )
        {
-               struct berval **values;
-               Entry* e = be->be_entry_get( be, id );
-               struct berval bv;
-               struct berval *bvals[2];
-
-               if ( e == NULL ) {
-                       fprintf( stderr,
-                               "entry id=%08lx: no data\n", (long) id );
-                       rc = EXIT_FAILURE;
-                       if( continuemode ) continue;
-                       break;
-               }
+               int rtn;
 
                if( verbose ) {
-                       printf("indexing id=%08lx dn=\"%s\"\n",
-                               id, e->e_dn );
+                       printf("indexing id=%08lx\n", (long) id );
                }
 
-               if( strcasecmp( type, "dn" ) == 0 ) {
-                       bv.bv_val = e->e_ndn;
-                       bv.bv_len = strlen( bv.bv_val );
-                       bvals[0] = &bv;
-                       bvals[1] = NULL;
-
-                       values = bvals;
+               rtn =  be->be_entry_reindex( be, id );
 
-               } else {
-                       Attribute *attr = attr_find( e->e_attrs, type );
-
-                       if( attr == NULL ) {
-                               entry_free( e );
-                               continue;
-                       }
-
-                       values = attr->a_vals;
-               }
-
-               if ( be->be_index_change( be,
-                       type, values, id, SLAP_INDEX_ADD_OP ) )
-               {
+               if( rtn != LDAP_SUCCESS ) {
                        rc = EXIT_FAILURE;
-
-                       if( !continuemode ) {
-                               entry_free( e );
-                               break;
-                       }
+                       if( continuemode ) continue;
+                       break;
                }
-
-               entry_free( e );
        }
 
        (void) be->be_entry_close( be );
 
        slap_tool_destroy();
-
        return( rc );
 }