X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=servers%2Fslapd%2Fback-bdb%2Fdn2id.c;h=528c57815f15089372f2b11178150b740a4b9c08;hb=82c1b0d1f0a27e374961c910473f549878e81e24;hp=62f6f13023db73768956461a095b66af6fbe83ca;hpb=593ce2def41f612c650be74cafde22be228330e8;p=openldap diff --git a/servers/slapd/back-bdb/dn2id.c b/servers/slapd/back-bdb/dn2id.c index 62f6f13023..528c57815f 100644 --- a/servers/slapd/back-bdb/dn2id.c +++ b/servers/slapd/back-bdb/dn2id.c @@ -2,7 +2,7 @@ /* $OpenLDAP$ */ /* This work is part of OpenLDAP Software . * - * Copyright 2000-2003 The OpenLDAP Foundation. + * Copyright 2000-2004 The OpenLDAP Foundation. * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -122,10 +122,11 @@ bdb_dn2id_add( #ifndef BDB_MULTIPLE_SUFFIXES } - while( !be_issuffix( op->o_bd, &ptr )) { + while( !be_issuffix( op->o_bd, &ptr )) #else - for (;;) { + for (;;) #endif + { ptr.bv_val[-1] = DN_SUBTREE_PREFIX; rc = bdb_idl_insert_key( op->o_bd, db, txn, &key, e->e_id ); @@ -427,19 +428,19 @@ bdb_dn2idl( DBT key; struct bdb_info *bdb = (struct bdb_info *) op->o_bd->be_private; DB *db = bdb->bi_dn2id->bdi_db; - int prefix = op->ors_scope == LDAP_SCOPE_SUBTREE ? DN_SUBTREE_PREFIX : - DN_ONE_PREFIX; + int prefix = ( op->ors_scope == LDAP_SCOPE_ONELEVEL ) + ? DN_ONE_PREFIX : DN_SUBTREE_PREFIX; #ifdef NEW_LOGGING - LDAP_LOG ( INDEX, ARGS, - "=> bdb_dn2ididl( \"%s\" )\n", e->e_nname.bv_val, 0, 0 ); + LDAP_LOG ( INDEX, ARGS, "=> bdb_dn2ididl( \"%s\" )\n", + e->e_nname.bv_val, 0, 0 ); #else - Debug( LDAP_DEBUG_TRACE, "=> bdb_dn2idl( \"%s\" )\n", e->e_nname.bv_val, 0, 0 ); + Debug( LDAP_DEBUG_TRACE, "=> bdb_dn2idl( \"%s\" )\n", + e->e_nname.bv_val, 0, 0 ); #endif #ifndef BDB_MULTIPLE_SUFFIXES - if (prefix == DN_SUBTREE_PREFIX && BEI(e)->bei_parent->bei_id == 0 ) - { + if ( prefix == DN_SUBTREE_PREFIX && BEI(e)->bei_parent->bei_id == 0 ) { BDB_IDL_ALL(bdb, ids); return 0; } @@ -629,6 +630,18 @@ hdb_dn2id_add( key.size = sizeof(ID); key.flags = DB_DBT_USERMEM; + /* Need to make dummy root node once. Subsequent attempts + * will fail harmlessly. + */ + if ( eip->bei_id == 0 ) { + diskNode dummy = {0}; + data.data = &dummy; + data.size = sizeof(diskNode); + data.flags = DB_DBT_USERMEM; + + db->put( db, txn, &key, &data, DB_NODUPDATA ); + } + #ifdef SLAP_IDL_CACHE if ( bdb->bi_idl_cache_size ) { bdb_idl_cache_del( bdb, db, &key ); @@ -1092,19 +1105,20 @@ hdb_dn2idl( #endif #ifndef BDB_MULTIPLE_SUFFIXES - if ( op->ors_scope == LDAP_SCOPE_SUBTREE && - BEI(e)->bei_parent->bei_id == 0 ) { + if ( op->ors_scope != LDAP_SCOPE_ONELEVEL && + BEI(e)->bei_parent->bei_id == 0 ) + { BDB_IDL_ALL( bdb, ids ); return 0; } #endif cx.id = e->e_id; - cx.ei = BEI(e); + cx.ei = e->e_id ? BEI(e) : &bdb->bi_cache.c_dntree; cx.bdb = bdb; cx.db = cx.bdb->bi_dn2id->bdi_db; - cx.prefix = op->ors_scope == LDAP_SCOPE_SUBTREE ? DN_SUBTREE_PREFIX : - DN_ONE_PREFIX; + cx.prefix = op->ors_scope == LDAP_SCOPE_ONELEVEL + ? DN_ONE_PREFIX : DN_SUBTREE_PREFIX; cx.ids = ids; cx.buf = stack; cx.op = op;