From: Kurt Zeilenga Date: Fri, 13 Aug 1999 00:55:08 +0000 (+0000) Subject: Add DN_INDICES search filter and has_children support. Move id2children X-Git-Tag: TWEB_OL_BASE~228 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=70151679748f121e620b60a9a8397f8f2c484e81;p=openldap Add DN_INDICES search filter and has_children support. Move id2children behind -UDN_INDICES. --- diff --git a/servers/slapd/back-ldbm/add.c b/servers/slapd/back-ldbm/add.c index 0333fe4129..b6679f1994 100644 --- a/servers/slapd/back-ldbm/add.c +++ b/servers/slapd/back-ldbm/add.c @@ -226,10 +226,10 @@ ldbm_back_add( rc = -1; +#ifndef DN_INDICES /* * add it to the id2children index for the parent */ - if ( id2children_add( be, p, e ) != 0 ) { Debug( LDAP_DEBUG_TRACE, "id2children_add failed\n", 0, 0, 0 ); @@ -238,6 +238,7 @@ ldbm_back_add( goto return_results; } +#endif /* * Add the entry to the attribute indexes, then add it to diff --git a/servers/slapd/back-ldbm/back-ldbm.h b/servers/slapd/back-ldbm/back-ldbm.h index 377c8389f8..fac176726e 100644 --- a/servers/slapd/back-ldbm/back-ldbm.h +++ b/servers/slapd/back-ldbm/back-ldbm.h @@ -25,9 +25,12 @@ LDAP_BEGIN_DECL #define SUBLEN 3 /* #undef DN_INDICES *//* generate dn eq, subtree, and parent indices */ -#define DN_ENTRY_PREFIX '=' +#define DN_BASE_PREFIX '=' +#define DN_ONE_PREFIX '@' #define DN_SUBTREE_PREFIX '?' -#define DN_PARENT_PREFIX '@' + +#define SLAPD_FILTER_DN_ONE ((ber_tag_t) -2) +#define SLAPD_FILTER_DN_SUBTREE ((ber_tag_t) -3) /* * there is a single index for each attribute. these prefixes ensure @@ -111,12 +114,12 @@ typedef struct ldbm_dbcache { typedef struct ldbm_attrinfo { char *ai_type; /* type name (cn, sn, ...) */ int ai_indexmask; /* how the attr is indexed */ -#define INDEX_PRESENCE 0x01 -#define INDEX_EQUALITY 0x02 -#define INDEX_APPROX 0x04 -#define INDEX_SUB 0x08 -#define INDEX_UNKNOWN 0x10 -#define INDEX_FROMINIT 0x20 +#define INDEX_PRESENCE 0x0001 +#define INDEX_EQUALITY 0x0002 +#define INDEX_APPROX 0x0004 +#define INDEX_SUB 0x0008 +#define INDEX_UNKNOWN 0x0010 +#define INDEX_FROMINIT 0x1000 int ai_syntaxmask; /* what kind of syntax */ /* ...from slap.h... #define SYNTAX_CIS 0x01 diff --git a/servers/slapd/back-ldbm/delete.c b/servers/slapd/back-ldbm/delete.c index a8180b3cf1..ac6b7d6343 100644 --- a/servers/slapd/back-ldbm/delete.c +++ b/servers/slapd/back-ldbm/delete.c @@ -140,6 +140,7 @@ ldbm_back_delete( rootlock = 1; } +#ifndef DN_INDICES if ( id2children_remove( be, p, e ) != 0 ) { Debug(LDAP_DEBUG_ARGS, "<=- ldbm_back_delete: operations error %s\n", @@ -148,6 +149,7 @@ ldbm_back_delete( NULL, NULL, NULL, NULL ); goto return_results; } +#endif /* delete from dn2id mapping */ if ( dn2id_delete( be, e->e_ndn ) != 0 ) { diff --git a/servers/slapd/back-ldbm/dn2id.c b/servers/slapd/back-ldbm/dn2id.c index c82ffb2576..1353146f4a 100644 --- a/servers/slapd/back-ldbm/dn2id.c +++ b/servers/slapd/back-ldbm/dn2id.c @@ -45,7 +45,7 @@ dn2id_add( #else key.dsize = strlen( dn ) + 2; key.dptr = ch_malloc( key.dsize ); - sprintf( key.dptr, "%c%s", DN_ENTRY_PREFIX, dn ); + sprintf( key.dptr, "%c%s", DN_BASE_PREFIX, dn ); #endif data.dptr = (char *) &id; @@ -65,7 +65,7 @@ dn2id_add( if( pdn != NULL ) { key.dsize = strlen( pdn ) + 2; key.dptr = ch_malloc( key.dsize ); - sprintf( key.dptr, "%c%s", DN_PARENT_PREFIX, pdn ); + sprintf( key.dptr, "%c%s", DN_ONE_PREFIX, pdn ); rc = idl_insert_key( be, db, key, id ); free( key.dptr ); } @@ -131,48 +131,13 @@ dn2id( return( NOID ); } -#ifdef DN_INDICES - { - char *pdn = dn_parent( NULL, dn ); - - if( pdn != NULL ) { - key.dsize = strlen( pdn ) + 2; - key.dptr = ch_malloc( key.dsize ); - sprintf( key.dptr, "%c%s", DN_PARENT_PREFIX, pdn ); - (void) idl_delete_key( be, db, key, id ); - free( key.dptr ); - } - - } - - { - char **subtree = dn_subtree( NULL, dn ); - - if( subtree != NULL ) { - int i; - for( i=0; subtree[i] != NULL; i++ ) { - key.dsize = strlen( dn ) + 2; - key.dptr = ch_malloc( key.dsize ); - sprintf( key.dptr, "%c%s", DN_SUBTREE_PREFIX, dn ); - - (void) idl_delete_key( be, db, key, id ); - - free( key.dptr ); - } - - charray_free( subtree ); - } - - } -#endif - #ifndef DN_INDICES key.dptr = dn; key.dsize = strlen( key.dptr ) + 1; #else key.dsize = strlen( dn ) + 2; key.dptr = ch_malloc( key.dsize ); - sprintf( key.dptr, "%c%s", DN_ENTRY_PREFIX, dn ); + sprintf( key.dptr, "%c%s", DN_BASE_PREFIX, dn ); #endif data = ldbm_cache_fetch( db, key ); @@ -196,6 +161,43 @@ dn2id( return( id ); } +#ifdef DN_INDICES +ID_BLOCK * +dn2idl( + Backend *be, + char *dn, + int prefix +) +{ + DBCache *db; + Datum key; + ID_BLOCK *idl; + + ldbm_datum_init( key ); + + Debug( LDAP_DEBUG_TRACE, "=> dn2idl( \"%c%s\" )\n", prefix, dn, 0 ); + + if ( (db = ldbm_cache_open( be, "dn2id", LDBM_SUFFIX, LDBM_WRCREAT )) + == NULL ) { + Debug( LDAP_DEBUG_ANY, "<= dn2idl could not open dn2id%s\n", + LDBM_SUFFIX, 0, 0 ); + return NULL; + } + + key.dsize = strlen( dn ) + 2; + key.dptr = ch_malloc( key.dsize ); + sprintf( key.dptr, "%c%s", prefix, dn ); + + idl = idl_fetch( be, db, key ); + + ldbm_cache_close( be, db ); + + free( key.dptr ); + + return( idl ); +} +#endif + int dn2id_delete( Backend *be, @@ -224,7 +226,7 @@ dn2id_delete( #else key.dsize = strlen( dn ) + 2; key.dptr = ch_malloc( key.dsize ); - sprintf( key.dptr, "%c%s", DN_ENTRY_PREFIX, dn ); + sprintf( key.dptr, "%c%s", DN_BASE_PREFIX, dn ); #endif rc = ldbm_cache_delete( db, key ); diff --git a/servers/slapd/back-ldbm/filterindex.c b/servers/slapd/back-ldbm/filterindex.c index 074872e642..370dc230ab 100644 --- a/servers/slapd/back-ldbm/filterindex.c +++ b/servers/slapd/back-ldbm/filterindex.c @@ -40,6 +40,17 @@ filter_candidates( result = NULL; switch ( f->f_choice ) { +#ifdef DN_INDICES + case SLAPD_FILTER_DN_ONE: + Debug( LDAP_DEBUG_FILTER, "\tDN ONE\n", 0, 0, 0 ); + result = dn2idl( be, f->f_dn, DN_ONE_PREFIX ); + break; + + case SLAPD_FILTER_DN_SUBTREE: + Debug( LDAP_DEBUG_FILTER, "\tDN SUBTREE\n", 0, 0, 0 ); + result = dn2idl( be, f->f_dn, DN_SUBTREE_PREFIX ); + break; +#endif case LDAP_FILTER_EQUALITY: Debug( LDAP_DEBUG_FILTER, "\tEQUALITY\n", 0, 0, 0 ); result = ava_candidates( be, &f->f_ava, LDAP_FILTER_EQUALITY ); diff --git a/servers/slapd/back-ldbm/id2children.c b/servers/slapd/back-ldbm/id2children.c index 34eeafdf6d..c5bc3f0524 100644 --- a/servers/slapd/back-ldbm/id2children.c +++ b/servers/slapd/back-ldbm/id2children.c @@ -14,6 +14,7 @@ #include "slap.h" #include "back-ldbm.h" +#ifndef DN_INDICES int id2children_add( Backend *be, @@ -102,6 +103,7 @@ id2children_remove( Debug( LDAP_DEBUG_TRACE, "<= id2children_remove 0\n", 0, 0, 0 ); return( 0 ); } +#endif int has_children( @@ -113,12 +115,15 @@ has_children( Datum key; int rc = 0; ID_BLOCK *idl; +#ifndef DN_INDICES char buf[20]; +#endif ldbm_datum_init( key ); Debug( LDAP_DEBUG_TRACE, "=> has_children( %ld )\n", p->e_id , 0, 0 ); +#ifndef DN_INDICES if ( (db = ldbm_cache_open( be, "id2children", LDBM_SUFFIX, LDBM_WRCREAT )) == NULL ) { Debug( LDAP_DEBUG_ANY, @@ -131,6 +136,20 @@ has_children( key.dptr = buf; key.dsize = strlen( buf ) + 1; +#else + if ( (db = ldbm_cache_open( be, "dn2id", LDBM_SUFFIX, + LDBM_WRCREAT )) == NULL ) { + Debug( LDAP_DEBUG_ANY, + "<= has_children -1 could not open \"dn2id%s\"\n", + LDBM_SUFFIX, 0, 0 ); + return( 0 ); + } + + key.dsize = strlen( p->e_ndn ) + 2; + key.dptr = ch_malloc( key.dsize ); + sprintf( key.dptr, "%c%s", DN_ONE_PREFIX, p->e_ndn ); +#endif + idl = idl_fetch( be, db, key ); ldbm_cache_close( be, db ); diff --git a/servers/slapd/back-ldbm/init.c b/servers/slapd/back-ldbm/init.c index 79c1974269..bc61fe9ccb 100644 --- a/servers/slapd/back-ldbm/init.c +++ b/servers/slapd/back-ldbm/init.c @@ -128,6 +128,7 @@ ldbm_back_db_init( /* default database directory */ li->li_directory = ch_strdup( DEFAULT_DB_DIRECTORY ); +#ifndef DN_INDICES /* always index dn, id2children, objectclass (used in some searches) */ if ( !at_find( "dn" ) ) { argv[ 0 ] = "dn"; @@ -144,6 +145,7 @@ ldbm_back_db_init( argv[ 2 ] = NULL; attr_index_config( li, "ldbm id2children initialization", 0, 2, argv, 1 ); +#endif argv[ 0 ] = "objectclass"; argv[ 1 ] = "pres,eq"; argv[ 2 ] = NULL; diff --git a/servers/slapd/back-ldbm/proto-back-ldbm.h b/servers/slapd/back-ldbm/proto-back-ldbm.h index f490e321ce..341a09ead2 100644 --- a/servers/slapd/back-ldbm/proto-back-ldbm.h +++ b/servers/slapd/back-ldbm/proto-back-ldbm.h @@ -76,6 +76,7 @@ int ldbm_cache_delete LDAP_P(( DBCache *db, Datum key )); int dn2id_add LDAP_P(( Backend *be, char *dn, ID id )); ID dn2id LDAP_P(( Backend *be, char *dn )); +ID_BLOCK *dn2idl LDAP_P(( Backend *be, char *dn, int prefix )); int dn2id_delete LDAP_P(( Backend *be, char *dn )); Entry * dn2entry_rw LDAP_P(( Backend *be, char *dn, Entry **matched, int rw )); diff --git a/servers/slapd/back-ldbm/search.c b/servers/slapd/back-ldbm/search.c index 9589c2fd9c..6c2cc6169c 100644 --- a/servers/slapd/back-ldbm/search.c +++ b/servers/slapd/back-ldbm/search.c @@ -400,28 +400,40 @@ search_candidates( lf->f_choice = LDAP_FILTER_AND; lf->f_and = (Filter *) ch_malloc( sizeof(Filter) ); +#ifndef DN_INDICES lf->f_and->f_choice = LDAP_FILTER_SUBSTRINGS; lf->f_and->f_sub_type = ch_strdup( "dn" ); lf->f_and->f_sub_initial = NULL; lf->f_and->f_sub_any = NULL; lf->f_and->f_sub_final = ch_strdup( e->e_ndn ); +#else + lf->f_and->f_choice = SLAPD_FILTER_DN_SUBTREE; + lf->f_and->f_dn = e->e_ndn; +#endif lf->f_and->f_next = f; f = lf; } else if ( scope == LDAP_SCOPE_ONELEVEL ) { +#ifndef DN_INDICES char buf[16]; +#endif lf = (Filter *) ch_malloc( sizeof(Filter) ); lf->f_next = NULL; lf->f_choice = LDAP_FILTER_AND; lf->f_and = (Filter *) ch_malloc( sizeof(Filter) ); +#ifndef DN_INDICES lf->f_and->f_choice = LDAP_FILTER_EQUALITY; lf->f_and->f_ava.ava_type = ch_strdup( "id2children" ); sprintf( buf, "%ld", e != NULL ? e->e_id : 0 ); lf->f_and->f_ava.ava_value.bv_val = ch_strdup( buf ); lf->f_and->f_ava.ava_value.bv_len = strlen( buf ); +#else + lf->f_and->f_choice = SLAPD_FILTER_DN_ONE; + lf->f_and->f_dn = e->e_ndn; +#endif lf->f_and->f_next = f; f = lf; @@ -434,8 +446,13 @@ search_candidates( /* free up filter additions we allocated above */ if( lf != NULL ) { +#ifndef DN_INDICES lf->f_and->f_next = NULL; filter_free( lf ); +#else + free( lf->f_and ); + free( lf ); +#endif } if( af != NULL ) { diff --git a/servers/slapd/slap.h b/servers/slapd/slap.h index 56e732d5e4..4792c0bb41 100644 --- a/servers/slapd/slap.h +++ b/servers/slapd/slap.h @@ -149,6 +149,8 @@ typedef struct slap_filter { char *f_un_sub_final; } f_un_sub; } f_un; + +#define f_dn f_un.f_un_type /* used for DN indices */ #define f_type f_un.f_un_type #define f_ava f_un.f_un_ava #define f_avtype f_un.f_un_ava.ava_type diff --git a/servers/slapd/tools/ldif2id2children.c b/servers/slapd/tools/ldif2id2children.c index 180002e8dc..ae07c18d83 100644 --- a/servers/slapd/tools/ldif2id2children.c +++ b/servers/slapd/tools/ldif2id2children.c @@ -24,7 +24,10 @@ main( int argc, char **argv ) int lineno, elineno; int lmax; ID id; - DBCache *db, *db2; + DBCache *db; +#ifndef DN_INDICES + DBCache *db2; +#endif Backend *be = NULL; struct ldbminfo *li; struct berval bv; @@ -92,7 +95,7 @@ main( int argc, char **argv ) #else key.dsize = strlen( val ) + 2; key.dptr = ch_malloc( key.dsize ); - sprintf( key.dptr, "%c%s", DN_ENTRY_PREFIX, val ); + sprintf( key.dptr, "%c%s", DN_BASE_PREFIX, val ); #endif data.dptr = (char *) &id; data.dsize = sizeof(ID); @@ -112,7 +115,7 @@ main( int argc, char **argv ) key.dsize = strlen( pdn ) + 2; key.dptr = ch_malloc( key.dsize ); sprintf( key.dptr, "%c%s", - DN_PARENT_PREFIX, pdn ); + DN_ONE_PREFIX, pdn ); rc = idl_insert_key( be, db, key, id ); free( key.dptr ); } @@ -155,6 +158,8 @@ main( int argc, char **argv ) if ( buf ) free( buf ); + +#ifndef DN_INDICES /* * next, make the id2children index */ @@ -240,6 +245,12 @@ main( int argc, char **argv ) ldbm_cache_close( be, db2 ); ldbm_cache_close( be, db ); #endif +#else +#ifdef SLAP_CLEANUP + ldbm_cache_close( be, db ); +#endif +#endif + slap_shutdown(dbnum); slap_destroy();