1 /* dn2id.c - routines to deal with the dn2id index */
4 * Copyright 1998-2002 The OpenLDAP Foundation, All Rights Reserved.
5 * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
11 #include <ac/string.h>
24 struct bdb_info *bdb = (struct bdb_info *) be->be_private;
25 DB *db = bdb->bi_dn2id->bdi_db;
29 struct berval ptr, pdn;
32 LDAP_LOG (( "db2id", LDAP_LEVEL_ARGS, "bdb_dn2id_add( \"%s\", 0x%08lx )\n",
33 e->e_ndn, (long) e->e_id ));
35 Debug( LDAP_DEBUG_TRACE, "=> bdb_dn2id_add( \"%s\", 0x%08lx )\n",
36 e->e_ndn, (long) e->e_id, 0 );
38 assert( e->e_id != NOID );
41 key.size = e->e_nname.bv_len + 2;
42 buf = ch_malloc( key.size );
44 buf[0] = DN_BASE_PREFIX;
46 ptr.bv_len = e->e_nname.bv_len;
47 AC_MEMCPY( ptr.bv_val, e->e_nname.bv_val, e->e_nname.bv_len );
48 ptr.bv_val[ptr.bv_len] = '\0';
51 data.data = (char *) &e->e_id;
52 data.size = sizeof( e->e_id );
54 /* store it -- don't override */
55 rc = db->put( db, txn, &key, &data, DB_NOOVERWRITE );
58 LDAP_LOG (( "db2id", LDAP_LEVEL_ERR,
59 "bdb_dn2id_add: put failed: %s %d\n",
60 db_strerror(rc), rc ));
62 Debug( LDAP_DEBUG_ANY, "=> bdb_dn2id_add: put failed: %s %d\n",
63 db_strerror(rc), rc, 0 );
68 if( !be_issuffix( be, &ptr )) {
69 buf[0] = DN_SUBTREE_PREFIX;
70 rc = bdb_idl_insert_key( be, db, txn, &key, e->e_id );
73 LDAP_LOG (( "db2id", LDAP_LEVEL_ERR,
74 "=> bdb_dn2id_add: subtree (%s) insert failed: %d\n",
77 Debug( LDAP_DEBUG_ANY,
78 "=> bdb_dn2id_add: subtree (%s) insert failed: %d\n",
84 dnParent( &ptr, &pdn );
86 key.size = pdn.bv_len + 2;
87 pdn.bv_val[-1] = DN_ONE_PREFIX;
88 key.data = pdn.bv_val-1;
91 rc = bdb_idl_insert_key( be, db, txn, &key, e->e_id );
95 LDAP_LOG (( "db2id", LDAP_LEVEL_ERR,
96 "=> bdb_dn2id_add: parent (%s) insert failed: %d\n",
99 Debug( LDAP_DEBUG_ANY,
100 "=> bdb_dn2id_add: parent (%s) insert failed: %d\n",
107 while( !be_issuffix( be, &ptr )) {
108 ptr.bv_val[-1] = DN_SUBTREE_PREFIX;
110 rc = bdb_idl_insert_key( be, db, txn, &key, e->e_id );
114 LDAP_LOG (( "db2id", LDAP_LEVEL_ERR,
115 "=> bdb_dn2id_add: subtree (%s) insert failed: %d\n",
118 Debug( LDAP_DEBUG_ANY,
119 "=> bdb_dn2id_add: subtree (%s) insert failed: %d\n",
124 dnParent( &ptr, &pdn );
126 key.size = pdn.bv_len + 2;
127 key.data = pdn.bv_val - 1;
134 LDAP_LOG (( "db2id", LDAP_LEVEL_RESULTS,
135 "<= bdb_dn2id_add: %d\n", rc ));
137 Debug( LDAP_DEBUG_TRACE, "<= bdb_dn2id_add: %d\n", rc, 0, 0 );
149 struct bdb_info *bdb = (struct bdb_info *) be->be_private;
150 DB *db = bdb->bi_dn2id->bdi_db;
154 struct berval pdn, ptr;
157 LDAP_LOG (( "db2id", LDAP_LEVEL_ARGS,
158 "=> bdb_dn2id_delete ( \"%s\", 0x08lx )\n",
159 e->e_ndn, e->e_id ));
161 Debug( LDAP_DEBUG_TRACE, "=> bdb_dn2id_delete( \"%s\", 0x%08lx )\n",
162 e->e_ndn, e->e_id, 0 );
166 key.size = e->e_nname.bv_len + 2;
167 buf = ch_malloc( key.size );
169 key.flags = DB_DBT_USERMEM;
170 buf[0] = DN_BASE_PREFIX;
172 ptr.bv_len = e->e_nname.bv_len;
173 AC_MEMCPY( ptr.bv_val, e->e_nname.bv_val, e->e_nname.bv_len );
174 ptr.bv_val[ptr.bv_len] = '\0';
177 rc = db->del( db, txn, &key, 0 );
180 LDAP_LOG (( "db2id", LDAP_LEVEL_ERR,
181 "=> bdb_dn2id_delete: delete failed: %s %d\n",
182 db_strerror(rc), rc ));
184 Debug( LDAP_DEBUG_ANY, "=> bdb_dn2id_delete: delete failed: %s %d\n",
185 db_strerror(rc), rc, 0 );
190 if( !be_issuffix( be, &ptr )) {
191 buf[0] = DN_SUBTREE_PREFIX;
192 rc = bdb_idl_delete_key( be, db, txn, &key, e->e_id );
195 LDAP_LOG (( "db2id", LDAP_LEVEL_ERR,
196 "=> bdb_dn2id_delete: subtree (%s) delete failed: %d\n",
199 Debug( LDAP_DEBUG_ANY,
200 "=> bdb_dn2id_delete: subtree (%s) delete failed: %d\n",
206 dnParent( &ptr, &pdn );
208 key.size = pdn.bv_len + 2;
209 pdn.bv_val[-1] = DN_ONE_PREFIX;
210 key.data = pdn.bv_val - 1;
213 rc = bdb_idl_delete_key( be, db, txn, &key, e->e_id );
217 LDAP_LOG (( "db2id", LDAP_LEVEL_ERR,
218 "=> bdb_dn2id_delete: parent (%s) delete failed: %d\n",
221 Debug( LDAP_DEBUG_ANY,
222 "=> bdb_dn2id_delete: parent (%s) delete failed: %d\n",
229 while( !be_issuffix( be, &ptr )) {
230 ptr.bv_val[-1] = DN_SUBTREE_PREFIX;
232 rc = bdb_idl_delete_key( be, db, txn, &key, e->e_id );
235 LDAP_LOG (( "db2id", LDAP_LEVEL_ERR,
236 "=> bdb_dn2id_delete: subtree (%s) delete failed: %d\n",
239 Debug( LDAP_DEBUG_ANY,
240 "=> bdb_dn2id_delete: subtree (%s) delete failed: %d\n",
245 dnParent( &ptr, &pdn );
247 key.size = pdn.bv_len + 2;
248 key.data = pdn.bv_val - 1;
255 LDAP_LOG (( "db2id", LDAP_LEVEL_RESULTS, "<= bdb_dn2id_delete %d\n", rc ));
257 Debug( LDAP_DEBUG_TRACE, "<= bdb_dn2id_delete %d\n", rc, 0, 0 );
271 struct bdb_info *bdb = (struct bdb_info *) be->be_private;
272 DB *db = bdb->bi_dn2id->bdi_db;
275 LDAP_LOG (( "db2id", LDAP_LEVEL_ARGS, "=> bdb_dn2id( \"%s\" )\n",
278 Debug( LDAP_DEBUG_TRACE, "=> bdb_dn2id( \"%s\" )\n", dn->bv_val, 0, 0 );
283 *id = bdb_cache_find_entry_ndn2id(be, &bdb->bi_cache, dn);
289 key.size = dn->bv_len + 2;
290 key.data = ch_malloc( key.size );
291 ((char *)key.data)[0] = DN_BASE_PREFIX;
292 AC_MEMCPY( &((char *)key.data)[1], dn->bv_val, key.size - 1 );
297 data.ulen = sizeof(ID);
298 data.flags = DB_DBT_USERMEM;
301 rc = db->get( db, txn, &key, &data, bdb->bi_db_opflags );
305 LDAP_LOG (( "db2id", LDAP_LEVEL_ERR,
306 "<= bdb_dn2id: get failed %s (%d)\n",
307 db_strerror(rc), rc ));
309 Debug( LDAP_DEBUG_TRACE, "<= bdb_dn2id: get failed: %s (%d)\n",
310 db_strerror( rc ), rc, 0 );
314 LDAP_LOG (( "db2id", LDAP_LEVEL_RESULTS,
315 "<= bdb_dn2id: got id=0x%08lx\n", *id ));
317 Debug( LDAP_DEBUG_TRACE, "<= bdb_dn2id: got id=0x%08lx\n",
336 struct bdb_info *bdb = (struct bdb_info *) be->be_private;
337 DB *db = bdb->bi_dn2id->bdi_db;
343 LDAP_LOG (( "db2id", LDAP_LEVEL_ARGS,
344 "=> bdb_dn2id_matched( \"%s\" )\n", in->bv_val ));
346 Debug( LDAP_DEBUG_TRACE, "=> bdb_dn2id_matched( \"%s\" )\n", in->bv_val, 0, 0 );
350 key.size = in->bv_len + 2;
351 buf = ch_malloc( key.size );
354 dn.bv_len = key.size - 2;
355 AC_MEMCPY( dn.bv_val, in->bv_val, key.size - 1 );
360 data.ulen = sizeof(ID);
361 data.flags = DB_DBT_USERMEM;
364 dn.bv_val[-1] = DN_BASE_PREFIX;
369 cached_id = bdb_cache_find_entry_ndn2id(be, &bdb->bi_cache, &dn);
371 if (cached_id != NOID) {
374 if ( dn.bv_val != buf+1 ) {
380 rc = db->get(db, txn, &key, &data, bdb->bi_db_opflags );
383 if( rc == DB_NOTFOUND ) {
386 if ( ! be_issuffix( be, &dn ) ) {
387 dnParent( &dn, &pdn );
390 LDAP_LOG (( "db2id", LDAP_LEVEL_DETAIL1,
391 "<= bdb_dn2id_matched: no match\n" ));
393 Debug( LDAP_DEBUG_TRACE,
394 "<= bdb_dn2id_matched: no match\n",
400 key.size = pdn.bv_len + 2;
402 key.data = pdn.bv_val - 1;
404 } else if ( rc == 0 ) {
405 if( data.size != sizeof( ID ) ) {
407 LDAP_LOG (( "db2id", LDAP_LEVEL_DETAIL1,
408 "<= bdb_dn2id_matched: get size mismatch:"
409 "expected %ld, got %ld\n",
410 (long) sizeof(ID), (long) data.size ));
412 Debug( LDAP_DEBUG_ANY,
413 "<= bdb_dn2id_matched: get size mismatch: "
414 "expected %ld, got %ld\n",
415 (long) sizeof(ID), (long) data.size, 0 );
419 if( dn.bv_val != buf+1 ) {
424 LDAP_LOG (( "db2id", LDAP_LEVEL_DETAIL1,
425 "<= bdb_dn2id_matched: id=0x%08lx: %s %s\n",
426 (long) *id, *id2 == 0 ? "entry" : "matched", dn.bv_val ));
428 Debug( LDAP_DEBUG_TRACE,
429 "<= bdb_dn2id_matched: id=0x%08lx: %s %s\n",
430 (long) *id, *id2 == 0 ? "entry" : "matched", dn.bv_val );
436 LDAP_LOG (( "db2id", LDAP_LEVEL_ERR,
437 "<= bdb_dn2id_matched: get failed: %s (%d)\n",
438 db_strerror(rc), rc ));
440 Debug( LDAP_DEBUG_ANY,
441 "<= bdb_dn2id_matched: get failed: %s (%d)\n",
442 db_strerror(rc), rc, 0 );
460 struct bdb_info *bdb = (struct bdb_info *) be->be_private;
461 DB *db = bdb->bi_dn2id->bdi_db;
465 LDAP_LOG (( "db2id", LDAP_LEVEL_ARGS,
466 "=> bdb_dn2id_children( %s )\n", dn->bv_val ));
468 Debug( LDAP_DEBUG_TRACE, "=> bdb_dn2id_children( %s )\n",
473 key.size = dn->bv_len + 2;
474 key.data = ch_malloc( key.size );
475 ((char *)key.data)[0] = DN_ONE_PREFIX;
476 AC_MEMCPY( &((char *)key.data)[1], dn->bv_val, key.size - 1 );
478 /* we actually could do a empty get... */
481 data.ulen = sizeof(id);
482 data.flags = DB_DBT_USERMEM;
484 data.dlen = sizeof(id);
486 rc = db->get( db, txn, &key, &data, bdb->bi_db_opflags );
490 LDAP_LOG (( "db2id", LDAP_LEVEL_DETAIL1,
491 "<= bdb_dn2id_children( %s ): %schildren (%d)\n",
492 dn->bv_val, rc == 0 ? "" : ( rc == DB_NOTFOUND ? "no " :
493 db_strerror(rc)), rc ));
495 Debug( LDAP_DEBUG_TRACE, "<= bdb_dn2id_children( %s ): %schildren (%d)\n",
497 rc == 0 ? "" : ( rc == DB_NOTFOUND ? "no " :
498 db_strerror(rc) ), rc );
513 struct bdb_info *bdb = (struct bdb_info *) be->be_private;
514 DB *db = bdb->bi_dn2id->bdi_db;
517 LDAP_LOG (( "db2id", LDAP_LEVEL_ARGS,
518 "=> bdb_dn2ididl( \"%s\" )\n", dn->bv_val ));
520 Debug( LDAP_DEBUG_TRACE, "=> bdb_dn2idl( \"%s\" )\n", dn->bv_val, 0, 0 );
523 if (prefix == DN_SUBTREE_PREFIX && be_issuffix(be, dn))
525 BDB_IDL_ALL(bdb, ids);
530 key.size = dn->bv_len + 2;
531 key.data = ch_malloc( key.size );
532 ((char *)key.data)[0] = prefix;
533 AC_MEMCPY( &((char *)key.data)[1], dn->bv_val, key.size - 1 );
535 rc = bdb_idl_fetch_key( be, db, NULL, &key, ids );
539 LDAP_LOG (( "db2id", LDAP_LEVEL_ERR,
540 "<= bdb_dn2ididl: get failed: %s (%d)\n",
541 db_strerror(rc), rc ));
543 Debug( LDAP_DEBUG_TRACE,
544 "<= bdb_dn2idl: get failed: %s (%d)\n",
545 db_strerror( rc ), rc, 0 );
550 LDAP_LOG (( "db2id", LDAP_LEVEL_RESULTS,
551 "<= bdb_dn2ididl: id=%ld first=%ld last=%ld\n",
552 (long) ids[0], (long) BDB_IDL_FIRST( ids ),
553 (long) BDB_IDL_LAST( ids ) ));
555 Debug( LDAP_DEBUG_TRACE,
556 "<= bdb_dn2idl: id=%ld first=%ld last=%ld\n",
558 (long) BDB_IDL_FIRST( ids ), (long) BDB_IDL_LAST( ids ) );
567 /* Experimental management routines for a hierarchically structured backend.
569 * Unsupported! Use at your own risk!
571 * Instead of a dn2id database, we use an id2parent database. Each entry in
572 * this database is a struct diskNode, containing the ID of the node's parent
573 * and the RDN of the node.
575 typedef struct diskNode {
581 /* In bdb_db_open() we call bdb_build_tree() which reads the entire id2parent
582 * database into memory (into an AVL tree). Next we iterate through each node
583 * of this tree, connecting each child to its parent. The nodes in this AVL
584 * tree are a struct idNode. The immediate (Onelevel) children of a node are
585 * referenced in the i_kids AVL tree. With this arrangement, there is no need
586 * to maintain the DN_ONE_PREFIX or DN_SUBTREE_PREFIX database keys. Note that
587 * the DN of an entry is constructed by walking up the list of i_parent
588 * pointers, so no full DN is stored on disk anywhere. This makes modrdn
589 * extremely efficient, even when operating on a populated subtree.
591 * The idNode tree is searched directly from the root when performing id to
592 * entry lookups. The tree is traversed using the i_kids subtrees when
593 * performing dn to id lookups.
595 typedef struct idNode {
597 struct idNode *i_parent;
600 ldap_pvt_thread_rdwr_t i_kids_rdwr;
604 /* The main AVL tree is sorted in ID order. The i_kids AVL trees are
605 * sorted in lexical order. These are the various helper routines used
606 * for the searches and sorts.
623 return strcmp(nrdn, n->i_rdn->nrdn.bv_val);
632 return a->i_id - b->i_id;
642 return strcmp(a->i_rdn->nrdn.bv_val, b->i_rdn->nrdn.bv_val);
644 /* should be slightly better without ordering drawbacks */
645 return ber_bvcmp(&a->i_rdn->nrdn, &b->i_rdn->nrdn);
648 idNode * bdb_find_id_node(
653 return avl_find(tree, (const void *)id, (AVL_CMP)node_find_cmp);
656 idNode * bdb_find_rdn_node(
661 return avl_find(tree, (const void *)nrdn, (AVL_CMP)node_frdn_cmp);
664 /* This function links a node into its parent's i_kids tree. */
672 if (a->i_rdn->parent == 0)
674 a->i_parent = bdb_find_id_node(a->i_rdn->parent, tree);
677 ldap_pvt_thread_rdwr_wlock(&a->i_parent->i_kids_rdwr);
678 rc = avl_insert( &a->i_parent->i_kids, (caddr_t) a,
679 (AVL_CMP)node_rdn_cmp, (AVL_DUP) avl_dup_error );
680 ldap_pvt_thread_rdwr_wunlock(&a->i_parent->i_kids_rdwr);
684 /* This function adds a node into the main AVL tree */
685 idNode *bdb_add_node(
693 node = (idNode *)ch_malloc(sizeof(idNode));
695 node->i_parent = NULL;
697 node->i_rdn = (diskNode *)d;
698 node->i_rdn->rdn.bv_val += (long)d;
699 node->i_rdn->nrdn.bv_val += (long)d;
700 ldap_pvt_thread_rdwr_init(&node->i_kids_rdwr);
701 avl_insert( &bdb->bi_tree, (caddr_t) node,
702 (AVL_CMP)node_add_cmp, (AVL_DUP) avl_dup_error );
704 bdb->bi_troot = node;
708 /* This function initializes the trees at startup time. */
713 struct bdb_info *bdb = (struct bdb_info *) be->be_private;
723 rc = bdb->bi_id2parent->bdi_db->cursor(
724 bdb->bi_id2parent->bdi_db, NULL, &cursor,
725 bdb->bi_db_opflags );
730 /* When be_suffix is turned into struct berval or LDAPDN
731 * life will get a lot easier... Since no DNs live on disk, we
732 * need to operate on the be_suffix to fully qualify our DNs.
733 * We need to know how many components are in the suffix DN,
734 * so we can tell where the suffix ends and our nodes begin.
736 * Note that this code always uses be_suffix[0], so defining
737 * multiple suffixes for a single backend won't work!
739 rdns = ldap_explode_dn(be->be_nsuffix[0]->bv_val, 0);
740 for (i=0; rdns[i]; i++);
746 key.data = (char *)&id;
747 key.ulen = sizeof( id );
748 key.flags = DB_DBT_USERMEM;
749 data.flags = DB_DBT_MALLOC;
751 while (cursor->c_get( cursor, &key, &data, DB_NEXT ) == 0) {
752 bdb_add_node( id, data.data, bdb );
754 cursor->c_close( cursor );
756 rc = avl_apply(bdb->bi_tree, (AVL_APPLY)bdb_insert_kid, bdb->bi_tree,
762 /* This function constructs a full DN for a given id. We really should
763 * be passing idNodes directly, to save some effort...
771 struct bdb_info *bdb = (struct bdb_info *) be->be_private;
776 ldap_pvt_thread_rdwr_rlock(&bdb->bi_tree_rdwr);
777 o = bdb_find_id_node(id, bdb->bi_tree);
778 rlen = be->be_suffix[0]->bv_len + 1;
779 nrlen = be->be_nsuffix[0]->bv_len + 1;
780 for (n = o; n && n->i_parent; n=n->i_parent) {
781 rlen += n->i_rdn->rdn.bv_len + 1;
782 nrlen += n->i_rdn->nrdn.bv_len + 1;
784 e->e_name.bv_len = rlen - 1;
785 e->e_nname.bv_len = nrlen - 1;
786 e->e_name.bv_val = ch_malloc(rlen + nrlen);
787 e->e_nname.bv_val = e->e_name.bv_val + rlen;
788 ptr = e->e_name.bv_val;
789 nptr = e->e_nname.bv_val;
790 for (n = o; n && n->i_parent; n=n->i_parent) {
791 ptr = slap_strcopy(ptr, n->i_rdn->rdn.bv_val);
793 nptr = slap_strcopy(nptr, n->i_rdn->nrdn.bv_val);
796 ldap_pvt_thread_rdwr_runlock(&bdb->bi_tree_rdwr);
798 strcpy(ptr, be->be_suffix[0]->bv_val);
799 strcpy(nptr, be->be_nsuffix[0]->bv_val);
811 struct bdb_info *bdb = (struct bdb_info *) be->be_private;
814 DB *db = bdb->bi_id2parent->bdi_db;
818 nrlen = dn_rdnlen( be, &e->e_nname );
820 rlen = dn_rdnlen( be, &e->e_name );
825 d = ch_malloc(sizeof(diskNode) + rlen + nrlen + 2);
826 d->rdn.bv_len = rlen;
827 d->nrdn.bv_len = nrlen;
828 d->rdn.bv_val = (char *)(d+1);
829 d->nrdn.bv_val = d->rdn.bv_val + rlen + 1;
830 strncpy(d->rdn.bv_val, e->e_dn, rlen);
831 d->rdn.bv_val[rlen] = '\0';
832 strncpy(d->nrdn.bv_val, e->e_ndn, nrlen);
833 d->nrdn.bv_val[nrlen] = '\0';
834 d->rdn.bv_val -= (long)d;
835 d->nrdn.bv_val -= (long)d;
838 bdb_dn2id(be, txn, pdn, &d->parent);
846 key.size = sizeof(ID);
847 key.flags = DB_DBT_USERMEM;
850 data.size = sizeof(diskNode) + rlen + nrlen + 2;
851 data.flags = DB_DBT_USERMEM;
853 rc = db->put( db, txn, &key, &data, DB_NOOVERWRITE );
856 ldap_pvt_thread_rdwr_wlock(&bdb->bi_tree_rdwr);
857 n = bdb_add_node( e->e_id, data.data, bdb);
858 ldap_pvt_thread_rdwr_wunlock(&bdb->bi_tree_rdwr);
861 ldap_pvt_thread_rdwr_rlock(&bdb->bi_tree_rdwr);
862 bdb_insert_kid(n, bdb->bi_tree);
863 ldap_pvt_thread_rdwr_runlock(&bdb->bi_tree_rdwr);
878 struct bdb_info *bdb = (struct bdb_info *) be->be_private;
881 DB *db = bdb->bi_id2parent->bdi_db;
885 key.size = sizeof(e->e_id);
888 rc = db->del( db, txn, &key, 0);
890 ldap_pvt_thread_rdwr_wlock(&bdb->bi_tree_rdwr);
891 n = avl_delete(&bdb->bi_tree, (void *)e->e_id, (AVL_CMP)node_find_cmp);
894 ldap_pvt_thread_rdwr_wlock(&n->i_parent->i_kids_rdwr);
895 avl_delete(&n->i_parent->i_kids, n->i_rdn->nrdn.bv_val,
896 (AVL_CMP)node_frdn_cmp);
897 ldap_pvt_thread_rdwr_wunlock(&n->i_parent->i_kids_rdwr);
900 ldap_pvt_thread_rdwr_destroy(&n->i_kids_rdwr);
904 bdb->bi_troot = NULL;
905 ldap_pvt_thread_rdwr_wunlock(&bdb->bi_tree_rdwr);
918 struct bdb_info *bdb = (struct bdb_info *) be->be_private;
927 if (be_issuffix(be, in)) {
932 rdns = ldap_explode_dn(in->bv_val, 0);
933 for (i=0; rdns[i]; i++);
940 ldap_pvt_thread_rdwr_rlock(&bdb->bi_tree_rdwr);
941 for (--i; i>=0; i--) {
942 ldap_pvt_thread_rdwr_rlock(&p->i_kids_rdwr);
943 n = bdb_find_rdn_node(rdns[i], p->i_kids);
944 ldap_pvt_thread_rdwr_runlock(&p->i_kids_rdwr);
948 ldap_pvt_thread_rdwr_runlock(&bdb->bi_tree_rdwr);
956 return n ? 0 : DB_NOTFOUND;
966 return bdb_dn2id_matched(be, txn, dn, id, NULL);
976 struct bdb_info *bdb = (struct bdb_info *) be->be_private;
980 rc = bdb_dn2id(be, txn, dn, &id);
984 ldap_pvt_thread_rdwr_rlock(&bdb->bi_tree_rdwr);
985 n = bdb_find_id_node(id, bdb->bi_tree);
986 ldap_pvt_thread_rdwr_runlock(&bdb->bi_tree_rdwr);
994 /* Since we don't store IDLs for onelevel or subtree, we have to construct
995 * them on the fly... Perhaps the i_kids tree ought to just be an IDL?
1003 return bdb_idl_insert(ids, n->i_id);
1014 rc = bdb_idl_insert(ids, n->i_id);
1016 ldap_pvt_thread_rdwr_rlock(&n->i_kids_rdwr);
1017 rc = avl_apply(n->i_kids, (AVL_APPLY)insert_sub, ids, -1,
1019 ldap_pvt_thread_rdwr_runlock(&n->i_kids_rdwr);
1031 struct bdb_info *bdb = (struct bdb_info *) be->be_private;
1036 if (prefix == DN_SUBTREE_PREFIX && be_issuffix(be, dn)) {
1037 BDB_IDL_ALL(bdb, ids);
1041 rc = bdb_dn2id(be, NULL, dn, &id);
1044 ldap_pvt_thread_rdwr_rlock(&bdb->bi_tree_rdwr);
1045 n = bdb_find_id_node(id, bdb->bi_tree);
1046 ldap_pvt_thread_rdwr_runlock(&bdb->bi_tree_rdwr);
1049 ldap_pvt_thread_rdwr_rlock(&n->i_kids_rdwr);
1050 if (prefix == DN_ONE_PREFIX) {
1051 rc = avl_apply(n->i_kids, (AVL_APPLY)insert_one, ids, -1,
1054 rc = avl_apply(n->i_kids, (AVL_APPLY)insert_sub, ids, -1,
1057 ldap_pvt_thread_rdwr_runlock(&n->i_kids_rdwr);
1060 #endif /* BDB_HIER */