1 /* dn2id.c - routines to deal with the dn2id index */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 * Copyright 2000-2005 The OpenLDAP Foundation.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted only as authorized by the OpenLDAP
12 * A copy of this license is available in the file LICENSE in the
13 * top-level directory of the distribution or, alternatively, at
14 * <http://www.OpenLDAP.org/license.html>.
20 #include <ac/string.h>
34 struct bdb_info *bdb = (struct bdb_info *) op->o_bd->be_private;
35 DB *db = bdb->bi_dn2id->bdi_db;
40 struct berval ptr, pdn;
42 Debug( LDAP_DEBUG_TRACE, "=> bdb_dn2id_add( \"%s\", 0x%08lx )\n",
43 e->e_ndn, (long) e->e_id, 0 );
44 assert( e->e_id != NOID );
47 key.size = e->e_nname.bv_len + 2;
49 key.flags = DB_DBT_USERMEM;
50 buf = op->o_tmpalloc( key.size, op->o_tmpmemctx );
52 buf[0] = DN_BASE_PREFIX;
54 ptr.bv_len = e->e_nname.bv_len;
55 AC_MEMCPY( ptr.bv_val, e->e_nname.bv_val, e->e_nname.bv_len );
56 ptr.bv_val[ptr.bv_len] = '\0';
60 data.size = sizeof( nid );
61 BDB_ID2DISK( e->e_id, &nid );
63 /* store it -- don't override */
64 rc = db->put( db, txn, &key, &data, DB_NOOVERWRITE );
66 Debug( LDAP_DEBUG_ANY, "=> bdb_dn2id_add: put failed: %s %d\n",
67 db_strerror(rc), rc, 0 );
71 #ifndef BDB_MULTIPLE_SUFFIXES
72 if( !be_issuffix( op->o_bd, &ptr ))
75 buf[0] = DN_SUBTREE_PREFIX;
76 rc = db->put( db, txn, &key, &data, DB_NOOVERWRITE );
78 Debug( LDAP_DEBUG_ANY,
79 "=> bdb_dn2id_add: subtree (%s) put failed: %d\n",
84 #ifdef BDB_MULTIPLE_SUFFIXES
85 if( !be_issuffix( op->o_bd, &ptr ))
88 dnParent( &ptr, &pdn );
90 key.size = pdn.bv_len + 2;
92 pdn.bv_val[-1] = DN_ONE_PREFIX;
93 key.data = pdn.bv_val-1;
96 rc = bdb_idl_insert_key( op->o_bd, db, txn, &key, e->e_id );
99 Debug( LDAP_DEBUG_ANY,
100 "=> bdb_dn2id_add: parent (%s) insert failed: %d\n",
106 #ifndef BDB_MULTIPLE_SUFFIXES
107 while( !be_issuffix( op->o_bd, &ptr ))
112 ptr.bv_val[-1] = DN_SUBTREE_PREFIX;
114 rc = bdb_idl_insert_key( op->o_bd, db, txn, &key, e->e_id );
117 Debug( LDAP_DEBUG_ANY,
118 "=> bdb_dn2id_add: subtree (%s) insert failed: %d\n",
122 #ifdef BDB_MULTIPLE_SUFFIXES
123 if( be_issuffix( op->o_bd, &ptr )) break;
125 dnParent( &ptr, &pdn );
127 key.size = pdn.bv_len + 2;
129 key.data = pdn.bv_val - 1;
135 op->o_tmpfree( buf, op->o_tmpmemctx );
136 Debug( LDAP_DEBUG_TRACE, "<= bdb_dn2id_add: %d\n", rc, 0, 0 );
147 struct bdb_info *bdb = (struct bdb_info *) op->o_bd->be_private;
148 DB *db = bdb->bi_dn2id->bdi_db;
152 struct berval pdn, ptr;
154 Debug( LDAP_DEBUG_TRACE, "=> bdb_dn2id_delete( \"%s\", 0x%08lx )\n",
155 e->e_ndn, e->e_id, 0 );
158 key.size = e->e_nname.bv_len + 2;
159 buf = op->o_tmpalloc( key.size, op->o_tmpmemctx );
161 key.flags = DB_DBT_USERMEM;
162 buf[0] = DN_BASE_PREFIX;
164 ptr.bv_len = e->e_nname.bv_len;
165 AC_MEMCPY( ptr.bv_val, e->e_nname.bv_val, e->e_nname.bv_len );
166 ptr.bv_val[ptr.bv_len] = '\0';
169 rc = db->del( db, txn, &key, 0 );
171 Debug( LDAP_DEBUG_ANY, "=> bdb_dn2id_delete: delete failed: %s %d\n",
172 db_strerror(rc), rc, 0 );
176 #ifndef BDB_MULTIPLE_SUFFIXES
177 if( !be_issuffix( op->o_bd, &ptr ))
180 buf[0] = DN_SUBTREE_PREFIX;
181 rc = db->del( db, txn, &key, 0 );
183 Debug( LDAP_DEBUG_ANY,
184 "=> bdb_dn2id_delete: subtree (%s) delete failed: %d\n",
189 #ifdef BDB_MULTIPLE_SUFFIXES
190 if( !be_issuffix( op->o_bd, &ptr ))
193 dnParent( &ptr, &pdn );
195 key.size = pdn.bv_len + 2;
197 pdn.bv_val[-1] = DN_ONE_PREFIX;
198 key.data = pdn.bv_val - 1;
201 rc = bdb_idl_delete_key( op->o_bd, db, txn, &key, e->e_id );
204 Debug( LDAP_DEBUG_ANY,
205 "=> bdb_dn2id_delete: parent (%s) delete failed: %d\n",
211 #ifndef BDB_MULTIPLE_SUFFIXES
212 while( !be_issuffix( op->o_bd, &ptr ))
217 ptr.bv_val[-1] = DN_SUBTREE_PREFIX;
219 rc = bdb_idl_delete_key( op->o_bd, db, txn, &key, e->e_id );
221 Debug( LDAP_DEBUG_ANY,
222 "=> bdb_dn2id_delete: subtree (%s) delete failed: %d\n",
226 #ifdef BDB_MULTIPLE_SUFFIXES
227 if( be_issuffix( op->o_bd, &ptr )) break;
229 dnParent( &ptr, &pdn );
231 key.size = pdn.bv_len + 2;
233 key.data = pdn.bv_val - 1;
239 op->o_tmpfree( buf, op->o_tmpmemctx );
240 Debug( LDAP_DEBUG_TRACE, "<= bdb_dn2id_delete %d\n", rc, 0, 0 );
251 struct bdb_info *bdb = (struct bdb_info *) op->o_bd->be_private;
252 DB *db = bdb->bi_dn2id->bdi_db;
257 Debug( LDAP_DEBUG_TRACE, "=> bdb_dn2id(\"%s\")\n", dn->bv_val, 0, 0 );
259 key.size = dn->bv_len + 2;
260 key.data = op->o_tmpalloc( key.size, op->o_tmpmemctx );
261 ((char *)key.data)[0] = DN_BASE_PREFIX;
262 AC_MEMCPY( &((char *)key.data)[1], dn->bv_val, key.size - 1 );
267 data.ulen = sizeof(ID);
268 data.flags = DB_DBT_USERMEM;
271 rc = db->get( db, txn, &key, &data, bdb->bi_db_opflags );
274 Debug( LDAP_DEBUG_TRACE, "<= bdb_dn2id: get failed: %s (%d)\n",
275 db_strerror( rc ), rc, 0 );
277 BDB_DISK2ID( &nid, &ei->bei_id );
278 Debug( LDAP_DEBUG_TRACE, "<= bdb_dn2id: got id=0x%08lx\n",
282 op->o_tmpfree( key.data, op->o_tmpmemctx );
293 struct bdb_info *bdb = (struct bdb_info *) op->o_bd->be_private;
294 DB *db = bdb->bi_dn2id->bdi_db;
298 Debug( LDAP_DEBUG_TRACE, "=> bdb_dn2id_children(\"%s\")\n",
299 e->e_nname.bv_val, 0, 0 );
301 key.size = e->e_nname.bv_len + 2;
302 key.data = op->o_tmpalloc( key.size, op->o_tmpmemctx );
303 ((char *)key.data)[0] = DN_ONE_PREFIX;
304 AC_MEMCPY( &((char *)key.data)[1], e->e_nname.bv_val, key.size - 1 );
306 if ( bdb->bi_idl_cache_size ) {
307 rc = bdb_idl_cache_get( bdb, db, &key, NULL );
308 if ( rc != LDAP_NO_SUCH_OBJECT ) {
309 op->o_tmpfree( key.data, op->o_tmpmemctx );
313 /* we actually could do a empty get... */
316 data.ulen = sizeof(id);
317 data.flags = DB_DBT_USERMEM;
319 data.dlen = sizeof(id);
321 rc = db->get( db, txn, &key, &data, bdb->bi_db_opflags );
322 op->o_tmpfree( key.data, op->o_tmpmemctx );
324 Debug( LDAP_DEBUG_TRACE, "<= bdb_dn2id_children(\"%s\"): %s (%d)\n",
326 rc == 0 ? "" : ( rc == DB_NOTFOUND ? "no " :
327 db_strerror(rc) ), rc );
341 struct bdb_info *bdb = (struct bdb_info *) op->o_bd->be_private;
342 DB *db = bdb->bi_dn2id->bdi_db;
343 int prefix = ( op->ors_scope == LDAP_SCOPE_ONELEVEL )
344 ? DN_ONE_PREFIX : DN_SUBTREE_PREFIX;
346 Debug( LDAP_DEBUG_TRACE, "=> bdb_dn2idl(\"%s\")\n",
347 e->e_nname.bv_val, 0, 0 );
349 #ifndef BDB_MULTIPLE_SUFFIXES
350 if ( prefix == DN_SUBTREE_PREFIX && BEI(e)->bei_parent->bei_id == 0 ) {
351 BDB_IDL_ALL(bdb, ids);
357 key.size = e->e_nname.bv_len + 2;
359 key.flags = DB_DBT_USERMEM;
360 key.data = op->o_tmpalloc( key.size, op->o_tmpmemctx );
361 ((char *)key.data)[0] = prefix;
362 AC_MEMCPY( &((char *)key.data)[1], e->e_nname.bv_val, key.size - 1 );
364 rc = bdb_idl_fetch_key( op->o_bd, db, NULL, &key, ids, NULL, 0 );
367 Debug( LDAP_DEBUG_TRACE,
368 "<= bdb_dn2idl: get failed: %s (%d)\n",
369 db_strerror( rc ), rc, 0 );
372 Debug( LDAP_DEBUG_TRACE,
373 "<= bdb_dn2idl: id=%ld first=%ld last=%ld\n",
375 (long) BDB_IDL_FIRST( ids ), (long) BDB_IDL_LAST( ids ) );
378 op->o_tmpfree( key.data, op->o_tmpmemctx );
383 /* Experimental management routines for a hierarchically structured database.
385 * Unsupported! Use at your own risk!
386 * -- Howard Chu, Symas Corp. 2003.
388 * Instead of a ldbm-style dn2id database, we use a hierarchical one. Each
389 * entry in this database is a struct diskNode, keyed by entryID and with
390 * the data containing the RDN and entryID of the node's children. We use
391 * a B-Tree with sorted duplicates to store all the children of a node under
392 * the same key. Also, the first item under the key contains the entry's own
393 * rdn and the ID of the node's parent, to allow bottom-up tree traversal as
394 * well as top-down. To keep this info first in the list, the nrdnlen is set
395 * to the negative of its value.
397 * The diskNode is a variable length structure. This definition is not
398 * directly usable for in-memory manipulation.
400 typedef struct diskNode {
407 /* Sort function for the sorted duplicate data items of a dn2id key.
408 * Sorts based on normalized RDN, in length order.
416 signed char *u = (signed char *)&(((diskNode *)(usrkey->data))->nrdnlen);
417 signed char *c = (signed char *)&(((diskNode *)(curkey->data))->nrdnlen);
420 /* data is not aligned, cannot compare directly */
421 #ifdef WORDS_BIGENDIAN
422 for( i = 0; i < (int)sizeof(short); i++)
424 for( i = sizeof(short)-1; i >= 0; i--)
430 return strcmp( u+sizeof(short), c+sizeof(short) );
433 /* This function constructs a full DN for a given entry.
440 int rlen = 0, nrlen = 0;
444 /* count length of all DN components */
445 for ( ei = BEI(e); ei && ei->bei_id; ei=ei->bei_parent ) {
446 rlen += ei->bei_rdn.bv_len + 1;
447 nrlen += ei->bei_nrdn.bv_len + 1;
448 if (ei->bei_modrdns > max) max = ei->bei_modrdns;
451 /* See if the entry DN was invalidated by a subtree rename */
453 if ( BEI(e)->bei_modrdns >= max ) {
456 /* We found a mismatch, tell the caller to lock it */
457 if ( checkit == 1 ) {
460 /* checkit == 2. do the fix. */
461 free( e->e_name.bv_val );
462 free( e->e_nname.bv_val );
465 e->e_name.bv_len = rlen - 1;
466 e->e_nname.bv_len = nrlen - 1;
467 e->e_name.bv_val = ch_malloc(rlen);
468 e->e_nname.bv_val = ch_malloc(nrlen);
469 ptr = e->e_name.bv_val;
470 nptr = e->e_nname.bv_val;
471 for ( ei = BEI(e); ei && ei->bei_id; ei=ei->bei_parent ) {
472 ptr = lutil_strcopy(ptr, ei->bei_rdn.bv_val);
473 nptr = lutil_strcopy(nptr, ei->bei_nrdn.bv_val);
474 if ( ei->bei_parent ) {
479 BEI(e)->bei_modrdns = max;
486 /* We add two elements to the DN2ID database - a data item under the parent's
487 * entryID containing the child's RDN and entryID, and an item under the
488 * child's entryID containing the parent's entryID.
497 struct bdb_info *bdb = (struct bdb_info *) op->o_bd->be_private;
498 DB *db = bdb->bi_dn2id->bdi_db;
505 nrlen = dn_rdnlen( op->o_bd, &e->e_nname );
507 rlen = dn_rdnlen( op->o_bd, &e->e_name );
509 nrlen = e->e_nname.bv_len;
510 rlen = e->e_name.bv_len;
513 d = op->o_tmpalloc(sizeof(diskNode) + rlen + nrlen, op->o_tmpmemctx);
514 BDB_ID2DISK( e->e_id, &d->entryID );
516 ptr = lutil_strncopy( d->nrdn, e->e_nname.bv_val, nrlen );
518 ptr = lutil_strncopy( ptr, e->e_name.bv_val, rlen );
524 key.size = sizeof(ID);
525 key.flags = DB_DBT_USERMEM;
526 BDB_ID2DISK( eip->bei_id, &nid );
528 /* Need to make dummy root node once. Subsequent attempts
529 * will fail harmlessly.
531 if ( eip->bei_id == 0 ) {
532 diskNode dummy = {0};
534 data.size = sizeof(diskNode);
535 data.flags = DB_DBT_USERMEM;
537 db->put( db, txn, &key, &data, DB_NODUPDATA );
540 if ( bdb->bi_idl_cache_size ) {
541 bdb_idl_cache_del( bdb, db, &key );
544 data.size = sizeof(diskNode) + rlen + nrlen;
545 data.flags = DB_DBT_USERMEM;
547 rc = db->put( db, txn, &key, &data, DB_NODUPDATA );
553 d->nrdnlen = 0 - nrlen;
555 rc = db->put( db, txn, &key, &data, DB_NODUPDATA );
558 op->o_tmpfree( d, op->o_tmpmemctx );
570 struct bdb_info *bdb = (struct bdb_info *) op->o_bd->be_private;
571 DB *db = bdb->bi_dn2id->bdi_db;
579 key.size = sizeof(ID);
582 key.flags = DB_DBT_USERMEM;
583 BDB_ID2DISK( eip->bei_id, &nid );
586 data.size = sizeof(diskNode) + BEI(e)->bei_nrdn.bv_len;
587 data.ulen = data.size;
588 data.dlen = data.size;
589 data.flags = DB_DBT_USERMEM | DB_DBT_PARTIAL;
591 if ( bdb->bi_idl_cache_size ) {
592 bdb_idl_cache_del( bdb, db, &key );
594 rc = db->cursor( db, txn, &cursor, bdb->bi_db_opflags );
597 d = op->o_tmpalloc( data.size, op->o_tmpmemctx );
598 BDB_ID2DISK( e->e_id, &d->entryID );
599 d->nrdnlen = BEI(e)->bei_nrdn.bv_len;
600 strcpy( d->nrdn, BEI(e)->bei_nrdn.bv_val );
603 /* Delete our ID from the parent's list */
604 rc = cursor->c_get( cursor, &key, &data, DB_GET_BOTH | DB_RMW );
606 rc = cursor->c_del( cursor, 0 );
608 /* Delete our ID from the tree. With sorted duplicates, this
609 * will leave any child nodes still hanging around. This is OK
610 * for modrdn, which will add our info back in later.
613 BDB_ID2DISK( e->e_id, &nid );
614 rc = cursor->c_get( cursor, &key, &data, DB_SET | DB_RMW );
616 rc = cursor->c_del( cursor, 0 );
618 cursor->c_close( cursor );
619 op->o_tmpfree( d, op->o_tmpmemctx );
632 struct bdb_info *bdb = (struct bdb_info *) op->o_bd->be_private;
633 DB *db = bdb->bi_dn2id->bdi_db;
641 nrlen = dn_rdnlen( op->o_bd, in );
642 if (!nrlen) nrlen = in->bv_len;
645 key.size = sizeof(ID);
647 key.ulen = sizeof(ID);
648 key.flags = DB_DBT_USERMEM;
649 BDB_ID2DISK( ei->bei_parent->bei_id, &idp );
652 data.size = sizeof(diskNode) + nrlen;
653 data.ulen = data.size * 3;
654 data.flags = DB_DBT_USERMEM;
656 rc = db->cursor( db, txn, &cursor, bdb->bi_db_opflags );
659 d = op->o_tmpalloc( data.size * 3, op->o_tmpmemctx );
661 ptr = lutil_strncopy( d->nrdn, in->bv_val, nrlen );
665 rc = cursor->c_get( cursor, &key, &data, DB_GET_BOTH );
667 BDB_DISK2ID( &d->entryID, &ei->bei_id );
668 ei->bei_rdn.bv_len = data.size - sizeof(diskNode) - nrlen;
669 ptr = d->nrdn + nrlen + 1;
670 ber_str2bv( ptr, ei->bei_rdn.bv_len, 1, &ei->bei_rdn );
671 if ( !ei->bei_parent->bei_dkids ) {
673 /* How many children does the parent have? */
674 /* FIXME: do we need to lock the parent
675 * entryinfo? Seems safe...
677 cursor->c_count( cursor, &dkids, 0 );
678 ei->bei_parent->bei_dkids = dkids;
681 cursor->c_close( cursor );
682 op->o_tmpfree( d, op->o_tmpmemctx );
694 struct bdb_info *bdb = (struct bdb_info *) op->o_bd->be_private;
695 DB *db = bdb->bi_dn2id->bdi_db;
705 key.size = sizeof(ID);
707 key.ulen = sizeof(ID);
708 key.flags = DB_DBT_USERMEM;
709 BDB_ID2DISK( ei->bei_id, &nid );
712 data.flags = DB_DBT_USERMEM;
714 rc = db->cursor( db, txn, &cursor, bdb->bi_db_opflags );
717 data.ulen = sizeof(diskNode) + (SLAP_LDAPDN_MAXLEN * 2);
718 d = op->o_tmpalloc( data.ulen, op->o_tmpmemctx );
721 rc = cursor->c_get( cursor, &key, &data, DB_SET );
723 if (d->nrdnlen >= 0) {
727 BDB_DISK2ID( &d->entryID, idp );
728 ei->bei_nrdn.bv_len = 0 - d->nrdnlen;
729 ber_str2bv( d->nrdn, ei->bei_nrdn.bv_len, 1, &ei->bei_nrdn );
730 ei->bei_rdn.bv_len = data.size - sizeof(diskNode) -
732 ptr = d->nrdn + ei->bei_nrdn.bv_len + 1;
733 ber_str2bv( ptr, ei->bei_rdn.bv_len, 1, &ei->bei_rdn );
734 /* How many children does this node have? */
735 cursor->c_count( cursor, &dkids, 0 );
736 ei->bei_dkids = dkids;
739 cursor->c_close( cursor );
740 op->o_tmpfree( d, op->o_tmpmemctx );
750 struct bdb_info *bdb = (struct bdb_info *) op->o_bd->be_private;
751 DB *db = bdb->bi_dn2id->bdi_db;
759 key.size = sizeof(ID);
761 key.flags = DB_DBT_USERMEM;
762 BDB_ID2DISK( e->e_id, &id );
764 /* IDL cache is in host byte order */
765 if ( bdb->bi_idl_cache_size ) {
766 rc = bdb_idl_cache_get( bdb, db, &key, NULL );
767 if ( rc != LDAP_NO_SUCH_OBJECT ) {
775 data.ulen = sizeof(d);
776 data.flags = DB_DBT_USERMEM | DB_DBT_PARTIAL;
777 data.dlen = sizeof(d);
779 rc = db->cursor( db, txn, &cursor, bdb->bi_db_opflags );
782 rc = cursor->c_get( cursor, &key, &data, DB_SET );
785 rc = cursor->c_count( cursor, &dkids, 0 );
787 BEI(e)->bei_dkids = dkids;
788 if ( dkids < 2 ) rc = DB_NOTFOUND;
791 cursor->c_close( cursor );
796 * We can't just use bdb_idl_fetch_key because
797 * 1 - our data items are longer than just an entry ID
798 * 2 - our data items are sorted alphabetically by nrdn, not by ID.
800 * We descend the tree recursively, so we define this cookie
801 * to hold our necessary state information. The bdb_dn2idl_internal
802 * function uses this cookie when calling itself.
805 struct dn2id_cookie {
806 struct bdb_info *bdb;
816 ID tmp[BDB_IDL_DB_SIZE];
829 EntryInfo *ei = data;
832 bdb_idl_insert( idl, ei->bei_id );
838 struct dn2id_cookie *cx
841 if ( cx->bdb->bi_idl_cache_size ) {
842 cx->key.data = &cx->id;
843 cx->rc = bdb_idl_cache_get(cx->bdb, cx->db, &cx->key, cx->tmp);
844 if ( cx->rc == DB_NOTFOUND ) {
847 if ( cx->rc == LDAP_SUCCESS ) {
851 BDB_IDL_ZERO( cx->tmp );
854 cx->ei = bdb_cache_find_info( cx->bdb, cx->id );
856 cx->rc = DB_NOTFOUND;
861 bdb_cache_entryinfo_lock( cx->ei );
863 /* If number of kids in the cache differs from on-disk, load
864 * up all the kids from the database
866 if ( cx->ei->bei_ckids+1 != cx->ei->bei_dkids ) {
868 db_recno_t dkids = cx->ei->bei_dkids;
869 ei.bei_parent = cx->ei;
871 bdb_cache_entryinfo_unlock( cx->ei );
873 cx->rc = cx->db->cursor( cx->db, NULL, &cx->dbc,
874 cx->bdb->bi_db_opflags );
875 if ( cx->rc ) return cx->rc;
877 cx->data.data = &cx->dbuf;
878 cx->data.ulen = sizeof(ID);
879 cx->data.dlen = sizeof(ID);
880 cx->data.flags = DB_DBT_USERMEM | DB_DBT_PARTIAL;
882 /* The first item holds the parent ID. Ignore it. */
883 cx->key.data = &cx->nid;
884 cx->rc = cx->dbc->c_get( cx->dbc, &cx->key, &cx->data, DB_SET );
886 cx->dbc->c_close( cx->dbc );
887 if ( cx->rc == DB_NOTFOUND ) goto saveit;
891 /* If the on-disk count is zero we've never checked it.
895 cx->dbc->c_count( cx->dbc, &dkids, 0 );
896 cx->ei->bei_dkids = dkids;
899 cx->data.data = cx->buf;
900 cx->data.ulen = BDB_IDL_UM_SIZE * sizeof(ID);
901 cx->data.flags = DB_DBT_USERMEM;
903 /* Fetch the rest of the IDs in a loop... */
904 while ( (cx->rc = cx->dbc->c_get( cx->dbc, &cx->key, &cx->data,
905 DB_MULTIPLE | DB_NEXT_DUP )) == 0 ) {
908 DB_MULTIPLE_INIT( cx->ptr, &cx->data );
910 DB_MULTIPLE_NEXT( cx->ptr, &cx->data, j, len );
913 diskNode *d = (diskNode *)j;
916 BDB_DISK2ID( &d->entryID, &ei.bei_id );
917 AC_MEMCPY( &nrlen, &d->nrdnlen, sizeof(d->nrdnlen) );
918 ei.bei_nrdn.bv_len = nrlen;
919 /* nrdn/rdn are set in-place.
920 * hdb_cache_load will copy them as needed
922 ei.bei_nrdn.bv_val = d->nrdn;
923 ei.bei_rdn.bv_len = len - sizeof(diskNode)
924 - ei.bei_nrdn.bv_len;
925 ei.bei_rdn.bv_val = d->nrdn + ei.bei_nrdn.bv_len + 1;
926 bdb_idl_insert( cx->tmp, ei.bei_id );
927 hdb_cache_load( cx->bdb, &ei, &ei2 );
931 cx->rc = cx->dbc->c_close( cx->dbc );
933 /* The in-memory cache is in sync with the on-disk data.
934 * do we have any kids?
937 if ( cx->ei->bei_ckids > 0 ) {
938 /* Walk the kids tree; order is irrelevant since bdb_idl_insert
939 * will insert in sorted order.
941 avl_apply( cx->ei->bei_kids, apply_func,
942 cx->tmp, -1, AVL_POSTORDER );
944 bdb_cache_entryinfo_unlock( cx->ei );
948 if ( cx->bdb->bi_idl_cache_max_size ) {
949 cx->key.data = &cx->id;
950 bdb_idl_cache_put( cx->bdb, cx->db, &cx->key, cx->tmp, cx->rc );
954 if ( !BDB_IDL_IS_ZERO( cx->tmp )) {
955 if ( cx->prefix == DN_SUBTREE_PREFIX ) {
956 if (cx->ei->bei_state & CACHE_ENTRY_NO_GRANDKIDS) {
957 bdb_idl_union( cx->ids, cx->tmp );
960 EntryInfo *ei = cx->ei;
962 save = cx->op->o_tmpalloc( BDB_IDL_SIZEOF( cx->tmp ),
963 cx->op->o_tmpmemctx );
964 BDB_IDL_CPY( save, cx->tmp );
965 bdb_idl_union( cx->ids, cx->tmp );
968 for ( cx->id = bdb_idl_first( save, &idcurs );
970 cx->id = bdb_idl_next( save, &idcurs )) {
971 BDB_ID2DISK( cx->id, &cx->nid );
973 hdb_dn2idl_internal( cx );
974 if ( !BDB_IDL_IS_ZERO( cx->tmp ))
977 cx->op->o_tmpfree( save, cx->op->o_tmpmemctx );
978 if ( nokids ) ei->bei_state |= CACHE_ENTRY_NO_GRANDKIDS;
980 /* Make sure caller knows it had kids! */
985 BDB_IDL_CPY( cx->ids, cx->tmp );
998 struct bdb_info *bdb = (struct bdb_info *)op->o_bd->be_private;
999 struct dn2id_cookie cx;
1001 Debug( LDAP_DEBUG_TRACE, "=> hdb_dn2idl(\"%s\")\n",
1002 e->e_nname.bv_val, 0, 0 );
1004 #ifndef BDB_MULTIPLE_SUFFIXES
1005 if ( op->ors_scope != LDAP_SCOPE_ONELEVEL &&
1006 BEI(e)->bei_parent->bei_id == 0 )
1008 BDB_IDL_ALL( bdb, ids );
1014 BDB_ID2DISK( cx.id, &cx.nid );
1015 cx.ei = e->e_id ? BEI(e) : &bdb->bi_cache.c_dntree;
1017 cx.db = cx.bdb->bi_dn2id->bdi_db;
1018 cx.prefix = op->ors_scope == LDAP_SCOPE_ONELEVEL
1019 ? DN_ONE_PREFIX : DN_SUBTREE_PREFIX;
1024 BDB_IDL_ZERO( ids );
1025 if ( cx.prefix == DN_SUBTREE_PREFIX ) {
1026 bdb_idl_insert( ids, cx.id );
1030 cx.key.ulen = sizeof(ID);
1031 cx.key.size = sizeof(ID);
1032 cx.key.flags = DB_DBT_USERMEM;
1036 return hdb_dn2idl_internal(&cx);
1038 #endif /* BDB_HIER */