]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/back-mdb/filterindex.c
ITS#8146 tweak prev commit
[openldap] / servers / slapd / back-mdb / filterindex.c
index e2142e1dfe721d4fc471d39a36244945b8cdd73b..162dba9ae2ea81614c57c0222ad078c3ebe655e0 100644 (file)
@@ -2,7 +2,7 @@
 /* $OpenLDAP$ */
 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
  *
- * Copyright 2000-2013 The OpenLDAP Foundation.
+ * Copyright 2000-2015 The OpenLDAP Foundation.
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -211,6 +211,31 @@ mdb_filter_candidates(
                /* Must not return NULL, otherwise extended filters break */
                MDB_IDL_ALL( ids );
        }
+       if ( ids[2] == NOID && MDB_IDL_IS_RANGE( ids )) {
+               struct mdb_info *mdb = (struct mdb_info *) op->o_bd->be_private;
+               ID last;
+
+               if ( mdb->mi_nextid ) {
+                       last = mdb->mi_nextid - 1;
+               } else {
+                       MDB_cursor *mc;
+                       MDB_val key;
+
+                       last = 0;
+                       rc = mdb_cursor_open( rtxn, mdb->mi_id2entry, &mc );
+                       if ( !rc ) {
+                               rc = mdb_cursor_get( mc, &key, NULL, MDB_LAST );
+                               if ( !rc )
+                                       memcpy( &last, key.mv_data, sizeof( last ));
+                               mdb_cursor_close( mc );
+                       }
+               }
+               if ( last ) {
+                       ids[2] = last;
+               } else {
+                       MDB_IDL_ZERO( ids );
+               }
+       }
 
 out:
        Debug( LDAP_DEBUG_FILTER,
@@ -696,6 +721,10 @@ equality_candidates(
                        ids[0] = 1;
                        ids[1] = id;
                }
+               if ( rc == MDB_NOTFOUND ) {
+                       MDB_IDL_ZERO( ids );
+                       rc = 0;
+               }
                return rc;
        }