]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/back-bdb/tools.c
Cleanup prev commit
[openldap] / servers / slapd / back-bdb / tools.c
index 604471c57aa4bb700a44aa349ed04506b426987d..d79bc18d6e562f843d1a492b0f392aa0c206a0f9 100644 (file)
@@ -2,7 +2,7 @@
 /* $OpenLDAP$ */
 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
  *
- * Copyright 2000-2006 The OpenLDAP Foundation.
+ * Copyright 2000-2007 The OpenLDAP Foundation.
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -262,9 +262,8 @@ int bdb_tool_id2entry_get(
 
 Entry* bdb_tool_entry_get( BackendDB *be, ID id )
 {
-       int rc, off;
+       int rc;
        Entry *e = NULL;
-       char *dptr;
 
        assert( be != NULL );
        assert( slapMode & SLAP_TOOL_MODE );
@@ -273,7 +272,7 @@ Entry* bdb_tool_entry_get( BackendDB *be, ID id )
        data.flags ^= DB_DBT_PARTIAL;
        data.ulen = 0;
     rc = cursor->c_get( cursor, &key, &data, DB_CURRENT );
-       if ( rc != ENOMEM ) goto leave;
+       if ( rc != DB_BUFFER_SMALL ) goto leave;
 
        /* Allocate a block and retrieve the data */
        eh.bv.bv_len = eh.nvals * sizeof( struct berval ) + data.size;
@@ -286,6 +285,7 @@ Entry* bdb_tool_entry_get( BackendDB *be, ID id )
        eh.data += eoff;
 
     rc = cursor->c_get( cursor, &key, &data, DB_CURRENT );
+       if ( rc ) goto leave;
 
 #ifdef SLAP_ZONE_ALLOC
        /* FIXME: will add ctx later */
@@ -423,6 +423,9 @@ bdb_tool_index_add(
 {
        struct bdb_info *bdb = (struct bdb_info *) op->o_bd->be_private;
 
+       if ( !bdb->bi_nattrs )
+               return 0;
+
        if ( slapMode & SLAP_TOOL_QUICK ) {
                IndexRec *ir;
                int i, rc;
@@ -576,7 +579,8 @@ done:
 
 int bdb_tool_entry_reindex(
        BackendDB *be,
-       ID id )
+       ID id,
+       AttributeDescription **adv )
 {
        struct bdb_info *bi = (struct bdb_info *) be->be_private;
        int rc;
@@ -596,6 +600,45 @@ int bdb_tool_entry_reindex(
                return 0;
        }
 
+       /* Check for explicit list of attrs to index */
+       if ( adv ) {
+               int i, j, n;
+
+               /* count */
+               for ( n = 0; adv[n]; n++ ) ;
+
+               /* insertion sort */
+               for ( i = 0; i < n; i++ ) {
+                       AttributeDescription *ad = adv[i];
+                       for ( j = i-1; j>=0; j--) {
+                               if ( SLAP_PTRCMP( adv[j], ad ) <= 0 ) break;
+                               adv[j+1] = adv[j];
+                       }
+                       adv[j+1] = ad;
+               }
+
+               for ( i = 0; adv[i]; i++ ) {
+                       if ( bi->bi_attrs[i]->ai_desc != adv[i] ) {
+                               for ( j = i+1; j < bi->bi_nattrs; j++ ) {
+                                       if ( bi->bi_attrs[j]->ai_desc == adv[i] ) {
+                                               AttrInfo *ai = bi->bi_attrs[i];
+                                               bi->bi_attrs[i] = bi->bi_attrs[j];
+                                               bi->bi_attrs[j] = ai;
+                                               break;
+                                       }
+                               }
+                               if ( j == bi->bi_nattrs ) {
+                                       Debug( LDAP_DEBUG_ANY,
+                                               LDAP_XSTRING(bdb_tool_entry_reindex)
+                                               ": no index configured for %s\n",
+                                               adv[i]->ad_cname.bv_val, 0, 0 );
+                                       return -1;
+                               }
+                       }
+               }
+               bi->bi_nattrs = i;
+       }
+
        /* Get the first attribute to index */
        if (bi->bi_linear_index && !index_nattrs) {
                index_nattrs = bi->bi_nattrs - 1;