X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=servers%2Fslapd%2Fback-ldbm%2Ffilterindex.c;h=e7d17af8f3daf3d55eb3ab55a533a212596e63ec;hb=1586a68219cf85e9caaafcf2259c9bc249358077;hp=8a67cd97c065f5ce486a00f1460b09a989bfa35d;hpb=6939c531700652491f4be4688c6a1f35a1ab8a18;p=openldap diff --git a/servers/slapd/back-ldbm/filterindex.c b/servers/slapd/back-ldbm/filterindex.c index 8a67cd97c0..e7d17af8f3 100644 --- a/servers/slapd/back-ldbm/filterindex.c +++ b/servers/slapd/back-ldbm/filterindex.c @@ -1,8 +1,17 @@ /* filterindex.c - generate the list of candidate entries from a filter */ /* $OpenLDAP$ */ -/* - * Copyright 1998-2003 The OpenLDAP Foundation, All Rights Reserved. - * COPYING RESTRICTIONS APPLY, see COPYRIGHT file +/* This work is part of OpenLDAP Software . + * + * Copyright 1998-2003 The OpenLDAP Foundation. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted only as authorized by the OpenLDAP + * Public License. + * + * A copy of this license is available in the file LICENSE in the + * top-level directory of the distribution or, alternatively, at + * . */ #include "portable.h" @@ -16,23 +25,23 @@ #include "back-ldbm.h" static ID_BLOCK *presence_candidates( - Backend *be, + Operation *op, AttributeDescription *desc ); static ID_BLOCK *equality_candidates( - Backend *be, AttributeAssertion *ava ); + Operation *op, AttributeAssertion *ava ); static ID_BLOCK *approx_candidates( - Backend *be, AttributeAssertion *ava ); + Operation *op, AttributeAssertion *ava ); static ID_BLOCK *substring_candidates( - Backend *be, + Operation *op, SubstringsAssertion *sub ); static ID_BLOCK *list_candidates( - Backend *be, + Operation *op, Filter *flist, int ftype ); ID_BLOCK * filter_candidates( - Backend *be, + Operation *op, Filter *f ) { @@ -47,6 +56,22 @@ filter_candidates( result = NULL; switch ( f->f_choice ) { + case SLAPD_FILTER_COMPUTED: + switch( f->f_result ) { + case SLAPD_COMPARE_UNDEFINED: + /* This technically is not the same as FALSE, but it + * certainly will produce no matches. + */ + /* FALLTHRU */ + case LDAP_COMPARE_FALSE: + result = NULL; + break; + case LDAP_COMPARE_TRUE: + result = idl_allids( op->o_bd ); + break; + } + break; + case SLAPD_FILTER_DN_ONE: #ifdef NEW_LOGGING LDAP_LOG( FILTER, DETAIL1, @@ -56,7 +81,7 @@ filter_candidates( #endif /* an error is treated as an empty list */ - if ( dn2idl( be, f->f_dn, DN_ONE_PREFIX, &result ) != 0 + if ( dn2idl( op->o_bd, f->f_dn, DN_ONE_PREFIX, &result ) != 0 && result != NULL ) { idl_free( result ); result = NULL; @@ -72,7 +97,7 @@ filter_candidates( #endif /* an error is treated as an empty list */ - if ( dn2idl( be, f->f_dn, DN_SUBTREE_PREFIX, &result ) != 0 + if ( dn2idl( op->o_bd, f->f_dn, DN_SUBTREE_PREFIX, &result ) != 0 && result != NULL ) { idl_free( result ); result = NULL; @@ -88,7 +113,7 @@ filter_candidates( Debug( LDAP_DEBUG_FILTER, "\tPRESENT\n", 0, 0, 0 ); #endif - result = presence_candidates( be, f->f_desc ); + result = presence_candidates( op, f->f_desc ); break; case LDAP_FILTER_EQUALITY: @@ -101,7 +126,7 @@ filter_candidates( Debug( LDAP_DEBUG_FILTER, "\tEQUALITY\n", 0, 0, 0 ); #endif - result = equality_candidates( be, f->f_ava ); + result = equality_candidates( op, f->f_ava ); break; case LDAP_FILTER_APPROX: @@ -114,7 +139,7 @@ filter_candidates( Debug( LDAP_DEBUG_FILTER, "\tAPPROX\n", 0, 0, 0 ); #endif - result = approx_candidates( be, f->f_ava ); + result = approx_candidates( op, f->f_ava ); break; case LDAP_FILTER_SUBSTRINGS: @@ -125,7 +150,7 @@ filter_candidates( Debug( LDAP_DEBUG_FILTER, "\tSUBSTRINGS\n", 0, 0, 0 ); #endif - result = substring_candidates( be, f->f_sub ); + result = substring_candidates( op, f->f_sub ); break; case LDAP_FILTER_GE: @@ -135,7 +160,7 @@ filter_candidates( Debug( LDAP_DEBUG_FILTER, "\tGE\n", 0, 0, 0 ); #endif - result = presence_candidates( be, f->f_ava->aa_desc ); + result = presence_candidates( op, f->f_ava->aa_desc ); break; case LDAP_FILTER_LE: @@ -145,7 +170,7 @@ filter_candidates( Debug( LDAP_DEBUG_FILTER, "\tLE\n", 0, 0, 0 ); #endif - result = presence_candidates( be, f->f_ava->aa_desc ); + result = presence_candidates( op, f->f_ava->aa_desc ); break; case LDAP_FILTER_AND: @@ -155,7 +180,7 @@ filter_candidates( Debug( LDAP_DEBUG_FILTER, "\tAND\n", 0, 0, 0 ); #endif - result = list_candidates( be, f->f_and, LDAP_FILTER_AND ); + result = list_candidates( op, f->f_and, LDAP_FILTER_AND ); break; case LDAP_FILTER_OR: @@ -165,7 +190,7 @@ filter_candidates( Debug( LDAP_DEBUG_FILTER, "\tOR\n", 0, 0, 0 ); #endif - result = list_candidates( be, f->f_or, LDAP_FILTER_OR ); + result = list_candidates( op, f->f_or, LDAP_FILTER_OR ); break; case LDAP_FILTER_NOT: @@ -181,7 +206,7 @@ filter_candidates( * list could result in matching entries be excluded from * the returned candidate list. */ - result = idl_allids( be ); + result = idl_allids( op->o_bd ); break; default: #ifdef NEW_LOGGING @@ -192,7 +217,7 @@ filter_candidates( /* unknown filters must not return NULL, to allow * extended filter processing to be done later. */ - result = idl_allids( be ); + result = idl_allids( op->o_bd ); break; } @@ -210,7 +235,7 @@ filter_candidates( static ID_BLOCK * presence_candidates( - Backend *be, + Operation *op, AttributeDescription *desc ) { @@ -219,7 +244,7 @@ presence_candidates( int rc; char *dbname; slap_mask_t mask; - struct berval prefix = {0}; + struct berval prefix = {0, NULL}; #ifdef NEW_LOGGING LDAP_LOG( FILTER, ENTRY, "presence_candidates: enter\n", 0, 0, 0 ); @@ -227,13 +252,13 @@ presence_candidates( Debug( LDAP_DEBUG_TRACE, "=> presence_candidates\n", 0, 0, 0 ); #endif - idl = idl_allids( be ); + idl = idl_allids( op->o_bd ); if( desc == slap_schema.si_ad_objectClass ) { return idl; } - rc = index_param( be, desc, LDAP_FILTER_PRESENT, + rc = index_param( op->o_bd, desc, LDAP_FILTER_PRESENT, &dbname, &mask, &prefix ); if( rc != LDAP_SUCCESS ) { @@ -262,7 +287,7 @@ presence_candidates( return idl; } - db = ldbm_cache_open( be, dbname, LDBM_SUFFIX, LDBM_WRCREAT ); + db = ldbm_cache_open( op->o_bd, dbname, LDBM_SUFFIX, LDBM_WRCREAT ); if ( db == NULL ) { #ifdef NEW_LOGGING @@ -282,7 +307,7 @@ presence_candidates( idl_free( idl ); idl = NULL; - rc = key_read( be, db, &prefix, &idl ); + rc = key_read( op->o_bd, db, &prefix, &idl ); if( rc != LDAP_SUCCESS ) { #ifdef NEW_LOGGING @@ -307,7 +332,7 @@ presence_candidates( } } - ldbm_cache_close( be, db ); + ldbm_cache_close( op->o_bd, db ); #ifdef NEW_LOGGING LDAP_LOG( FILTER, ENTRY, @@ -323,7 +348,7 @@ presence_candidates( static ID_BLOCK * equality_candidates( - Backend *be, + Operation *op, AttributeAssertion *ava ) { @@ -333,7 +358,7 @@ equality_candidates( int rc; char *dbname; slap_mask_t mask; - struct berval prefix = {0}; + struct berval prefix = {0, NULL}; struct berval *keys = NULL; MatchingRule *mr; @@ -344,9 +369,9 @@ equality_candidates( #endif - idl = idl_allids( be ); + idl = idl_allids( op->o_bd ); - rc = index_param( be, ava->aa_desc, LDAP_FILTER_EQUALITY, + rc = index_param( op->o_bd, ava->aa_desc, LDAP_FILTER_EQUALITY, &dbname, &mask, &prefix ); if( rc != LDAP_SUCCESS ) { @@ -391,7 +416,7 @@ equality_candidates( mr, &prefix, &ava->aa_value, - &keys ); + &keys, op->o_tmpmemctx ); if( rc != LDAP_SUCCESS ) { #ifdef NEW_LOGGING @@ -420,7 +445,7 @@ equality_candidates( return idl; } - db = ldbm_cache_open( be, dbname, LDBM_SUFFIX, LDBM_WRCREAT ); + db = ldbm_cache_open( op->o_bd, dbname, LDBM_SUFFIX, LDBM_WRCREAT ); if ( db == NULL ) { #ifdef NEW_LOGGING @@ -439,7 +464,7 @@ equality_candidates( ID_BLOCK *save; ID_BLOCK *tmp; - rc = key_read( be, db, &keys[i], &tmp ); + rc = key_read( op->o_bd, db, &keys[i], &tmp ); if( rc != LDAP_SUCCESS ) { idl_free( idl ); @@ -471,16 +496,16 @@ equality_candidates( } save = idl; - idl = idl_intersection( be, idl, tmp ); + idl = idl_intersection( op->o_bd, idl, tmp ); idl_free( save ); idl_free( tmp ); if( idl == NULL ) break; } - ber_bvarray_free( keys ); + ber_bvarray_free_x( keys, op->o_tmpmemctx ); - ldbm_cache_close( be, db ); + ldbm_cache_close( op->o_bd, db ); #ifdef NEW_LOGGING @@ -497,7 +522,7 @@ equality_candidates( static ID_BLOCK * approx_candidates( - Backend *be, + Operation *op, AttributeAssertion *ava ) { @@ -507,7 +532,7 @@ approx_candidates( int rc; char *dbname; slap_mask_t mask; - struct berval prefix = {0}; + struct berval prefix = {0, NULL}; struct berval *keys = NULL; MatchingRule *mr; @@ -518,9 +543,9 @@ approx_candidates( #endif - idl = idl_allids( be ); + idl = idl_allids( op->o_bd ); - rc = index_param( be, ava->aa_desc, LDAP_FILTER_APPROX, + rc = index_param( op->o_bd, ava->aa_desc, LDAP_FILTER_APPROX, &dbname, &mask, &prefix ); if( rc != LDAP_SUCCESS ) { @@ -570,7 +595,7 @@ approx_candidates( mr, &prefix, &ava->aa_value, - &keys ); + &keys, op->o_tmpmemctx ); if( rc != LDAP_SUCCESS ) { #ifdef NEW_LOGGING @@ -600,7 +625,7 @@ approx_candidates( return idl; } - db = ldbm_cache_open( be, dbname, LDBM_SUFFIX, LDBM_WRCREAT ); + db = ldbm_cache_open( op->o_bd, dbname, LDBM_SUFFIX, LDBM_WRCREAT ); if ( db == NULL ) { #ifdef NEW_LOGGING @@ -620,7 +645,7 @@ approx_candidates( ID_BLOCK *save; ID_BLOCK *tmp; - rc = key_read( be, db, &keys[i], &tmp ); + rc = key_read( op->o_bd, db, &keys[i], &tmp ); if( rc != LDAP_SUCCESS ) { idl_free( idl ); @@ -650,16 +675,16 @@ approx_candidates( } save = idl; - idl = idl_intersection( be, idl, tmp ); + idl = idl_intersection( op->o_bd, idl, tmp ); idl_free( save ); idl_free( tmp ); if( idl == NULL ) break; } - ber_bvarray_free( keys ); + ber_bvarray_free_x( keys, op->o_tmpmemctx ); - ldbm_cache_close( be, db ); + ldbm_cache_close( op->o_bd, db ); #ifdef NEW_LOGGING LDAP_LOG( FILTER, ENTRY, @@ -675,7 +700,7 @@ approx_candidates( static ID_BLOCK * list_candidates( - Backend *be, + Operation *op, Filter *flist, int ftype ) @@ -692,7 +717,7 @@ list_candidates( idl = NULL; for ( f = flist; f != NULL; f = f->f_next ) { - if ( (tmp = filter_candidates( be, f )) == NULL && + if ( (tmp = filter_candidates( op, f )) == NULL && ftype == LDAP_FILTER_AND ) { #ifdef NEW_LOGGING LDAP_LOG( FILTER, INFO, "list_candidates: NULL\n", 0, 0, 0 ); @@ -709,11 +734,11 @@ list_candidates( if ( idl == NULL ) { idl = tmp; } else if ( ftype == LDAP_FILTER_AND ) { - idl = idl_intersection( be, idl, tmp ); + idl = idl_intersection( op->o_bd, idl, tmp ); idl_free( tmp ); idl_free( tmp2 ); } else { - idl = idl_union( be, idl, tmp ); + idl = idl_union( op->o_bd, idl, tmp ); idl_free( tmp ); idl_free( tmp2 ); } @@ -732,7 +757,7 @@ list_candidates( static ID_BLOCK * substring_candidates( - Backend *be, + Operation *op, SubstringsAssertion *sub ) { @@ -742,7 +767,7 @@ substring_candidates( int rc; char *dbname; slap_mask_t mask; - struct berval prefix = {0}; + struct berval prefix = {0, NULL}; struct berval *keys = NULL; MatchingRule *mr; @@ -753,9 +778,9 @@ substring_candidates( #endif - idl = idl_allids( be ); + idl = idl_allids( op->o_bd ); - rc = index_param( be, sub->sa_desc, LDAP_FILTER_SUBSTRINGS, + rc = index_param( op->o_bd, sub->sa_desc, LDAP_FILTER_SUBSTRINGS, &dbname, &mask, &prefix ); if( rc != LDAP_SUCCESS ) { @@ -801,7 +826,7 @@ substring_candidates( mr, &prefix, sub, - &keys ); + &keys, op->o_tmpmemctx ); if( rc != LDAP_SUCCESS ) { #ifdef NEW_LOGGING @@ -831,7 +856,7 @@ substring_candidates( return idl; } - db = ldbm_cache_open( be, dbname, LDBM_SUFFIX, LDBM_WRCREAT ); + db = ldbm_cache_open( op->o_bd, dbname, LDBM_SUFFIX, LDBM_WRCREAT ); if ( db == NULL ) { #ifdef NEW_LOGGING @@ -851,7 +876,7 @@ substring_candidates( ID_BLOCK *save; ID_BLOCK *tmp; - rc = key_read( be, db, &keys[i], &tmp ); + rc = key_read( op->o_bd, db, &keys[i], &tmp ); if( rc != LDAP_SUCCESS ) { idl_free( idl ); @@ -881,16 +906,16 @@ substring_candidates( } save = idl; - idl = idl_intersection( be, idl, tmp ); + idl = idl_intersection( op->o_bd, idl, tmp ); idl_free( save ); idl_free( tmp ); if( idl == NULL ) break; } - ber_bvarray_free( keys ); + ber_bvarray_free_x( keys, op->o_tmpmemctx ); - ldbm_cache_close( be, db ); + ldbm_cache_close( op->o_bd, db ); #ifdef NEW_LOGGING LDAP_LOG( FILTER, ENTRY,