behind -UDN_INDICES.
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 );
goto return_results;
}
+#endif
/*
* Add the entry to the attribute indexes, then add it to
#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
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
rootlock = 1;
}
+#ifndef DN_INDICES
if ( id2children_remove( be, p, e ) != 0 ) {
Debug(LDAP_DEBUG_ARGS,
"<=- ldbm_back_delete: operations error %s\n",
NULL, NULL, NULL, NULL );
goto return_results;
}
+#endif
/* delete from dn2id mapping */
if ( dn2id_delete( be, e->e_ndn ) != 0 ) {
#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;
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 );
}
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 );
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,
#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 );
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 );
#include "slap.h"
#include "back-ldbm.h"
+#ifndef DN_INDICES
int
id2children_add(
Backend *be,
Debug( LDAP_DEBUG_TRACE, "<= id2children_remove 0\n", 0, 0, 0 );
return( 0 );
}
+#endif
int
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,
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 );
/* 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";
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;
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 ));
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;
/* 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 ) {
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
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;
#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);
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 );
}
if ( buf )
free( buf );
+
+#ifndef DN_INDICES
/*
* next, make the id2children index
*/
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();