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;
43 key.flags = DB_DBT_USERMEM;
44 buf = ch_malloc( key.size );
46 buf[0] = DN_BASE_PREFIX;
48 ptr.bv_len = e->e_nname.bv_len;
49 AC_MEMCPY( ptr.bv_val, e->e_nname.bv_val, e->e_nname.bv_len );
50 ptr.bv_val[ptr.bv_len] = '\0';
53 data.data = (char *) &e->e_id;
54 data.size = sizeof( e->e_id );
56 /* store it -- don't override */
57 rc = db->put( db, txn, &key, &data, DB_NOOVERWRITE );
60 LDAP_LOG (( "db2id", LDAP_LEVEL_ERR,
61 "bdb_dn2id_add: put failed: %s %d\n",
62 db_strerror(rc), rc ));
64 Debug( LDAP_DEBUG_ANY, "=> bdb_dn2id_add: put failed: %s %d\n",
65 db_strerror(rc), rc, 0 );
70 if( !be_issuffix( be, &ptr )) {
71 buf[0] = DN_SUBTREE_PREFIX;
72 rc = bdb_idl_insert_key( be, db, txn, &key, e->e_id );
75 LDAP_LOG (( "db2id", LDAP_LEVEL_ERR,
76 "=> bdb_dn2id_add: subtree (%s) insert failed: %d\n",
79 Debug( LDAP_DEBUG_ANY,
80 "=> bdb_dn2id_add: subtree (%s) insert failed: %d\n",
86 dnParent( &ptr, &pdn );
88 key.size = pdn.bv_len + 2;
90 pdn.bv_val[-1] = DN_ONE_PREFIX;
91 key.data = pdn.bv_val-1;
94 rc = bdb_idl_insert_key( be, db, txn, &key, e->e_id );
98 LDAP_LOG (( "db2id", LDAP_LEVEL_ERR,
99 "=> bdb_dn2id_add: parent (%s) insert failed: %d\n",
102 Debug( LDAP_DEBUG_ANY,
103 "=> bdb_dn2id_add: parent (%s) insert failed: %d\n",
110 while( !be_issuffix( be, &ptr )) {
111 ptr.bv_val[-1] = DN_SUBTREE_PREFIX;
113 rc = bdb_idl_insert_key( be, db, txn, &key, e->e_id );
117 LDAP_LOG (( "db2id", LDAP_LEVEL_ERR,
118 "=> bdb_dn2id_add: subtree (%s) insert failed: %d\n",
121 Debug( LDAP_DEBUG_ANY,
122 "=> bdb_dn2id_add: subtree (%s) insert failed: %d\n",
127 dnParent( &ptr, &pdn );
129 key.size = pdn.bv_len + 2;
131 key.data = pdn.bv_val - 1;
138 LDAP_LOG (( "db2id", LDAP_LEVEL_RESULTS,
139 "<= bdb_dn2id_add: %d\n", rc ));
141 Debug( LDAP_DEBUG_TRACE, "<= bdb_dn2id_add: %d\n", rc, 0, 0 );
153 struct bdb_info *bdb = (struct bdb_info *) be->be_private;
154 DB *db = bdb->bi_dn2id->bdi_db;
158 struct berval pdn, ptr;
161 LDAP_LOG (( "db2id", LDAP_LEVEL_ARGS,
162 "=> bdb_dn2id_delete ( \"%s\", 0x08lx )\n",
163 e->e_ndn, e->e_id ));
165 Debug( LDAP_DEBUG_TRACE, "=> bdb_dn2id_delete( \"%s\", 0x%08lx )\n",
166 e->e_ndn, e->e_id, 0 );
170 key.size = e->e_nname.bv_len + 2;
171 buf = ch_malloc( key.size );
173 key.flags = DB_DBT_USERMEM;
174 buf[0] = DN_BASE_PREFIX;
176 ptr.bv_len = e->e_nname.bv_len;
177 AC_MEMCPY( ptr.bv_val, e->e_nname.bv_val, e->e_nname.bv_len );
178 ptr.bv_val[ptr.bv_len] = '\0';
181 rc = db->del( db, txn, &key, 0 );
184 LDAP_LOG (( "db2id", LDAP_LEVEL_ERR,
185 "=> bdb_dn2id_delete: delete failed: %s %d\n",
186 db_strerror(rc), rc ));
188 Debug( LDAP_DEBUG_ANY, "=> bdb_dn2id_delete: delete failed: %s %d\n",
189 db_strerror(rc), rc, 0 );
194 if( !be_issuffix( be, &ptr )) {
195 buf[0] = DN_SUBTREE_PREFIX;
196 rc = db->del( db, txn, &key, 0 );
199 LDAP_LOG (( "db2id", LDAP_LEVEL_ERR,
200 "=> bdb_dn2id_delete: subtree (%s) delete failed: %d\n",
203 Debug( LDAP_DEBUG_ANY,
204 "=> bdb_dn2id_delete: subtree (%s) delete failed: %d\n",
210 dnParent( &ptr, &pdn );
212 key.size = pdn.bv_len + 2;
214 pdn.bv_val[-1] = DN_ONE_PREFIX;
215 key.data = pdn.bv_val - 1;
218 rc = bdb_idl_delete_key( be, db, txn, &key, e->e_id );
222 LDAP_LOG (( "db2id", LDAP_LEVEL_ERR,
223 "=> bdb_dn2id_delete: parent (%s) delete failed: %d\n",
226 Debug( LDAP_DEBUG_ANY,
227 "=> bdb_dn2id_delete: parent (%s) delete failed: %d\n",
234 while( !be_issuffix( be, &ptr )) {
235 ptr.bv_val[-1] = DN_SUBTREE_PREFIX;
237 rc = bdb_idl_delete_key( be, db, txn, &key, e->e_id );
240 LDAP_LOG (( "db2id", LDAP_LEVEL_ERR,
241 "=> bdb_dn2id_delete: subtree (%s) delete failed: %d\n",
244 Debug( LDAP_DEBUG_ANY,
245 "=> bdb_dn2id_delete: subtree (%s) delete failed: %d\n",
250 dnParent( &ptr, &pdn );
252 key.size = pdn.bv_len + 2;
254 key.data = pdn.bv_val - 1;
261 LDAP_LOG (( "db2id", LDAP_LEVEL_RESULTS, "<= bdb_dn2id_delete %d\n", rc ));
263 Debug( LDAP_DEBUG_TRACE, "<= bdb_dn2id_delete %d\n", rc, 0, 0 );
278 struct bdb_info *bdb = (struct bdb_info *) be->be_private;
279 DB *db = bdb->bi_dn2id->bdi_db;
282 LDAP_LOG (( "db2id", LDAP_LEVEL_ARGS, "=> bdb_dn2id( \"%s\" )\n",
285 Debug( LDAP_DEBUG_TRACE, "=> bdb_dn2id( \"%s\" )\n", dn->bv_val, 0, 0 );
290 *id = bdb_cache_find_entry_ndn2id(be, &bdb->bi_cache, dn);
296 key.size = dn->bv_len + 2;
297 key.data = ch_malloc( key.size );
298 ((char *)key.data)[0] = DN_BASE_PREFIX;
299 AC_MEMCPY( &((char *)key.data)[1], dn->bv_val, key.size - 1 );
304 data.ulen = sizeof(ID);
305 data.flags = DB_DBT_USERMEM;
308 rc = db->get( db, txn, &key, &data, bdb->bi_db_opflags | flags);
312 LDAP_LOG (( "db2id", LDAP_LEVEL_ERR,
313 "<= bdb_dn2id: get failed %s (%d)\n",
314 db_strerror(rc), rc ));
316 Debug( LDAP_DEBUG_TRACE, "<= bdb_dn2id: get failed: %s (%d)\n",
317 db_strerror( rc ), rc, 0 );
321 LDAP_LOG (( "db2id", LDAP_LEVEL_RESULTS,
322 "<= bdb_dn2id: got id=0x%08lx\n", *id ));
324 Debug( LDAP_DEBUG_TRACE, "<= bdb_dn2id: got id=0x%08lx\n",
344 struct bdb_info *bdb = (struct bdb_info *) be->be_private;
345 DB *db = bdb->bi_dn2id->bdi_db;
351 LDAP_LOG (( "db2id", LDAP_LEVEL_ARGS,
352 "=> bdb_dn2id_matched( \"%s\" )\n", in->bv_val ));
354 Debug( LDAP_DEBUG_TRACE, "=> bdb_dn2id_matched( \"%s\" )\n", in->bv_val, 0, 0 );
358 key.size = in->bv_len + 2;
359 buf = ch_malloc( key.size );
362 dn.bv_len = key.size - 2;
363 AC_MEMCPY( dn.bv_val, in->bv_val, key.size - 1 );
368 data.ulen = sizeof(ID);
369 data.flags = DB_DBT_USERMEM;
372 dn.bv_val[-1] = DN_BASE_PREFIX;
377 cached_id = bdb_cache_find_entry_ndn2id(be, &bdb->bi_cache, &dn);
379 if (cached_id != NOID) {
382 if ( dn.bv_val != buf+1 ) {
388 rc = db->get(db, txn, &key, &data, bdb->bi_db_opflags | flags );
391 if( rc == DB_NOTFOUND ) {
394 if ( ! be_issuffix( be, &dn ) ) {
395 dnParent( &dn, &pdn );
398 LDAP_LOG (( "db2id", LDAP_LEVEL_DETAIL1,
399 "<= bdb_dn2id_matched: no match\n" ));
401 Debug( LDAP_DEBUG_TRACE,
402 "<= bdb_dn2id_matched: no match\n",
408 key.size = pdn.bv_len + 2;
410 key.data = pdn.bv_val - 1;
412 } else if ( rc == 0 ) {
413 if( data.size != sizeof( ID ) ) {
415 LDAP_LOG (( "db2id", LDAP_LEVEL_DETAIL1,
416 "<= bdb_dn2id_matched: get size mismatch:"
417 "expected %ld, got %ld\n",
418 (long) sizeof(ID), (long) data.size ));
420 Debug( LDAP_DEBUG_ANY,
421 "<= bdb_dn2id_matched: get size mismatch: "
422 "expected %ld, got %ld\n",
423 (long) sizeof(ID), (long) data.size, 0 );
427 if( dn.bv_val != buf+1 ) {
432 LDAP_LOG (( "db2id", LDAP_LEVEL_DETAIL1,
433 "<= bdb_dn2id_matched: id=0x%08lx: %s %s\n",
434 (long) *id, *id2 == 0 ? "entry" : "matched", dn.bv_val ));
436 Debug( LDAP_DEBUG_TRACE,
437 "<= bdb_dn2id_matched: id=0x%08lx: %s %s\n",
438 (long) *id, *id2 == 0 ? "entry" : "matched", dn.bv_val );
444 LDAP_LOG (( "db2id", LDAP_LEVEL_ERR,
445 "<= bdb_dn2id_matched: get failed: %s (%d)\n",
446 db_strerror(rc), rc ));
448 Debug( LDAP_DEBUG_ANY,
449 "<= bdb_dn2id_matched: get failed: %s (%d)\n",
450 db_strerror(rc), rc, 0 );
469 struct bdb_info *bdb = (struct bdb_info *) be->be_private;
470 DB *db = bdb->bi_dn2id->bdi_db;
474 LDAP_LOG (( "db2id", LDAP_LEVEL_ARGS,
475 "=> bdb_dn2id_children( %s )\n", dn->bv_val ));
477 Debug( LDAP_DEBUG_TRACE, "=> bdb_dn2id_children( %s )\n",
482 key.size = dn->bv_len + 2;
483 key.data = ch_malloc( key.size );
484 ((char *)key.data)[0] = DN_ONE_PREFIX;
485 AC_MEMCPY( &((char *)key.data)[1], dn->bv_val, key.size - 1 );
487 /* we actually could do a empty get... */
490 data.ulen = sizeof(id);
491 data.flags = DB_DBT_USERMEM;
493 data.dlen = sizeof(id);
495 rc = db->get( db, txn, &key, &data, bdb->bi_db_opflags | flags );
499 LDAP_LOG (( "db2id", LDAP_LEVEL_DETAIL1,
500 "<= bdb_dn2id_children( %s ): %schildren (%d)\n",
501 dn->bv_val, rc == 0 ? "" : ( rc == DB_NOTFOUND ? "no " :
502 db_strerror(rc)), rc ));
504 Debug( LDAP_DEBUG_TRACE, "<= bdb_dn2id_children( %s ): %schildren (%d)\n",
506 rc == 0 ? "" : ( rc == DB_NOTFOUND ? "no " :
507 db_strerror(rc) ), rc );
522 struct bdb_info *bdb = (struct bdb_info *) be->be_private;
523 DB *db = bdb->bi_dn2id->bdi_db;
526 LDAP_LOG (( "db2id", LDAP_LEVEL_ARGS,
527 "=> bdb_dn2ididl( \"%s\" )\n", dn->bv_val ));
529 Debug( LDAP_DEBUG_TRACE, "=> bdb_dn2idl( \"%s\" )\n", dn->bv_val, 0, 0 );
532 if (prefix == DN_SUBTREE_PREFIX && be_issuffix(be, dn))
534 BDB_IDL_ALL(bdb, ids);
539 key.size = dn->bv_len + 2;
541 key.flags = DB_DBT_USERMEM;
542 key.data = ch_malloc( key.size );
543 ((char *)key.data)[0] = prefix;
544 AC_MEMCPY( &((char *)key.data)[1], dn->bv_val, key.size - 1 );
546 rc = bdb_idl_fetch_key( be, db, NULL, &key, ids );
550 LDAP_LOG (( "db2id", LDAP_LEVEL_ERR,
551 "<= bdb_dn2ididl: get failed: %s (%d)\n",
552 db_strerror(rc), rc ));
554 Debug( LDAP_DEBUG_TRACE,
555 "<= bdb_dn2idl: get failed: %s (%d)\n",
556 db_strerror( rc ), rc, 0 );
561 LDAP_LOG (( "db2id", LDAP_LEVEL_RESULTS,
562 "<= bdb_dn2ididl: id=%ld first=%ld last=%ld\n",
563 (long) ids[0], (long) BDB_IDL_FIRST( ids ),
564 (long) BDB_IDL_LAST( ids ) ));
566 Debug( LDAP_DEBUG_TRACE,
567 "<= bdb_dn2idl: id=%ld first=%ld last=%ld\n",
569 (long) BDB_IDL_FIRST( ids ), (long) BDB_IDL_LAST( ids ) );
578 /* Experimental management routines for a hierarchically structured backend.
580 * Unsupported! Use at your own risk!
582 * Instead of a dn2id database, we use an id2parent database. Each entry in
583 * this database is a struct diskNode, containing the ID of the node's parent
584 * and the RDN of the node.
586 typedef struct diskNode {
592 /* In bdb_db_open() we call bdb_build_tree() which reads the entire id2parent
593 * database into memory (into an AVL tree). Next we iterate through each node
594 * of this tree, connecting each child to its parent. The nodes in this AVL
595 * tree are a struct idNode. The immediate (Onelevel) children of a node are
596 * referenced in the i_kids AVL tree. With this arrangement, there is no need
597 * to maintain the DN_ONE_PREFIX or DN_SUBTREE_PREFIX database keys. Note that
598 * the DN of an entry is constructed by walking up the list of i_parent
599 * pointers, so no full DN is stored on disk anywhere. This makes modrdn
600 * extremely efficient, even when operating on a populated subtree.
602 * The idNode tree is searched directly from the root when performing id to
603 * entry lookups. The tree is traversed using the i_kids subtrees when
604 * performing dn to id lookups.
606 typedef struct idNode {
608 struct idNode *i_parent;
611 ldap_pvt_thread_rdwr_t i_kids_rdwr;
615 /* The main AVL tree is sorted in ID order. The i_kids AVL trees are
616 * sorted in lexical order. These are the various helper routines used
617 * for the searches and sorts.
634 return strcmp(nrdn, n->i_rdn->nrdn.bv_val);
643 return a->i_id - b->i_id;
653 return strcmp(a->i_rdn->nrdn.bv_val, b->i_rdn->nrdn.bv_val);
655 /* should be slightly better without ordering drawbacks */
656 return ber_bvcmp(&a->i_rdn->nrdn, &b->i_rdn->nrdn);
659 idNode * bdb_find_id_node(
664 return avl_find(tree, (const void *)id, (AVL_CMP)node_find_cmp);
667 idNode * bdb_find_rdn_node(
672 return avl_find(tree, (const void *)nrdn, (AVL_CMP)node_frdn_cmp);
675 /* This function links a node into its parent's i_kids tree. */
683 if (a->i_rdn->parent == 0)
685 a->i_parent = bdb_find_id_node(a->i_rdn->parent, tree);
688 ldap_pvt_thread_rdwr_wlock(&a->i_parent->i_kids_rdwr);
689 rc = avl_insert( &a->i_parent->i_kids, (caddr_t) a,
690 (AVL_CMP)node_rdn_cmp, (AVL_DUP) avl_dup_error );
691 ldap_pvt_thread_rdwr_wunlock(&a->i_parent->i_kids_rdwr);
695 /* This function adds a node into the main AVL tree */
696 idNode *bdb_add_node(
704 node = (idNode *)ch_malloc(sizeof(idNode));
706 node->i_parent = NULL;
708 node->i_rdn = (diskNode *)d;
709 node->i_rdn->rdn.bv_val += (long)d;
710 node->i_rdn->nrdn.bv_val += (long)d;
711 ldap_pvt_thread_rdwr_init(&node->i_kids_rdwr);
712 avl_insert( &bdb->bi_tree, (caddr_t) node,
713 (AVL_CMP)node_add_cmp, (AVL_DUP) avl_dup_error );
715 bdb->bi_troot = node;
719 /* This function initializes the trees at startup time. */
724 struct bdb_info *bdb = (struct bdb_info *) be->be_private;
734 rc = bdb->bi_id2parent->bdi_db->cursor(
735 bdb->bi_id2parent->bdi_db, NULL, &cursor,
736 bdb->bi_db_opflags );
741 /* When be_suffix is turned into struct berval or LDAPDN
742 * life will get a lot easier... Since no DNs live on disk, we
743 * need to operate on the be_suffix to fully qualify our DNs.
744 * We need to know how many components are in the suffix DN,
745 * so we can tell where the suffix ends and our nodes begin.
747 * Note that this code always uses be_suffix[0], so defining
748 * multiple suffixes for a single backend won't work!
750 rdns = ldap_explode_dn(be->be_nsuffix[0].bv_val, 0);
751 for (i=0; rdns[i]; i++);
757 key.data = (char *)&id;
758 key.ulen = sizeof( id );
759 key.flags = DB_DBT_USERMEM;
760 data.flags = DB_DBT_MALLOC;
762 while (cursor->c_get( cursor, &key, &data, DB_NEXT ) == 0) {
763 bdb_add_node( id, data.data, bdb );
765 cursor->c_close( cursor );
767 rc = avl_apply(bdb->bi_tree, (AVL_APPLY)bdb_insert_kid, bdb->bi_tree,
773 /* This function constructs a full DN for a given id. We really should
774 * be passing idNodes directly, to save some effort...
782 struct bdb_info *bdb = (struct bdb_info *) be->be_private;
787 ldap_pvt_thread_rdwr_rlock(&bdb->bi_tree_rdwr);
788 o = bdb_find_id_node(id, bdb->bi_tree);
789 rlen = be->be_suffix[0].bv_len + 1;
790 nrlen = be->be_nsuffix[0].bv_len + 1;
791 for (n = o; n && n->i_parent; n=n->i_parent) {
792 rlen += n->i_rdn->rdn.bv_len + 1;
793 nrlen += n->i_rdn->nrdn.bv_len + 1;
795 e->e_name.bv_len = rlen - 1;
796 e->e_nname.bv_len = nrlen - 1;
797 e->e_name.bv_val = ch_malloc(rlen + nrlen);
798 e->e_nname.bv_val = e->e_name.bv_val + rlen;
799 ptr = e->e_name.bv_val;
800 nptr = e->e_nname.bv_val;
801 for (n = o; n && n->i_parent; n=n->i_parent) {
802 ptr = slap_strcopy(ptr, n->i_rdn->rdn.bv_val);
804 nptr = slap_strcopy(nptr, n->i_rdn->nrdn.bv_val);
807 ldap_pvt_thread_rdwr_runlock(&bdb->bi_tree_rdwr);
809 strcpy(ptr, be->be_suffix[0].bv_val);
810 strcpy(nptr, be->be_nsuffix[0].bv_val);
822 struct bdb_info *bdb = (struct bdb_info *) be->be_private;
825 DB *db = bdb->bi_id2parent->bdi_db;
829 nrlen = dn_rdnlen( be, &e->e_nname );
831 rlen = dn_rdnlen( be, &e->e_name );
836 d = ch_malloc(sizeof(diskNode) + rlen + nrlen + 2);
837 d->rdn.bv_len = rlen;
838 d->nrdn.bv_len = nrlen;
839 d->rdn.bv_val = (char *)(d+1);
840 d->nrdn.bv_val = d->rdn.bv_val + rlen + 1;
841 strncpy(d->rdn.bv_val, e->e_dn, rlen);
842 d->rdn.bv_val[rlen] = '\0';
843 strncpy(d->nrdn.bv_val, e->e_ndn, nrlen);
844 d->nrdn.bv_val[nrlen] = '\0';
845 d->rdn.bv_val -= (long)d;
846 d->nrdn.bv_val -= (long)d;
849 bdb_dn2id(be, txn, pdn, &d->parent);
857 key.size = sizeof(ID);
858 key.flags = DB_DBT_USERMEM;
861 data.size = sizeof(diskNode) + rlen + nrlen + 2;
862 data.flags = DB_DBT_USERMEM;
864 rc = db->put( db, txn, &key, &data, DB_NOOVERWRITE );
867 ldap_pvt_thread_rdwr_wlock(&bdb->bi_tree_rdwr);
868 n = bdb_add_node( e->e_id, data.data, bdb);
869 ldap_pvt_thread_rdwr_wunlock(&bdb->bi_tree_rdwr);
872 ldap_pvt_thread_rdwr_rlock(&bdb->bi_tree_rdwr);
873 bdb_insert_kid(n, bdb->bi_tree);
874 ldap_pvt_thread_rdwr_runlock(&bdb->bi_tree_rdwr);
889 struct bdb_info *bdb = (struct bdb_info *) be->be_private;
892 DB *db = bdb->bi_id2parent->bdi_db;
896 key.size = sizeof(e->e_id);
899 rc = db->del( db, txn, &key, 0);
901 ldap_pvt_thread_rdwr_wlock(&bdb->bi_tree_rdwr);
902 n = avl_delete(&bdb->bi_tree, (void *)e->e_id, (AVL_CMP)node_find_cmp);
905 ldap_pvt_thread_rdwr_wlock(&n->i_parent->i_kids_rdwr);
906 avl_delete(&n->i_parent->i_kids, n->i_rdn->nrdn.bv_val,
907 (AVL_CMP)node_frdn_cmp);
908 ldap_pvt_thread_rdwr_wunlock(&n->i_parent->i_kids_rdwr);
911 ldap_pvt_thread_rdwr_destroy(&n->i_kids_rdwr);
915 bdb->bi_troot = NULL;
916 ldap_pvt_thread_rdwr_wunlock(&bdb->bi_tree_rdwr);
929 struct bdb_info *bdb = (struct bdb_info *) be->be_private;
938 if (be_issuffix(be, in)) {
943 rdns = ldap_explode_dn(in->bv_val, 0);
944 for (i=0; rdns[i]; i++);
951 ldap_pvt_thread_rdwr_rlock(&bdb->bi_tree_rdwr);
952 for (--i; i>=0; i--) {
953 ldap_pvt_thread_rdwr_rlock(&p->i_kids_rdwr);
954 n = bdb_find_rdn_node(rdns[i], p->i_kids);
955 ldap_pvt_thread_rdwr_runlock(&p->i_kids_rdwr);
959 ldap_pvt_thread_rdwr_runlock(&bdb->bi_tree_rdwr);
967 return n ? 0 : DB_NOTFOUND;
977 return bdb_dn2id_matched(be, txn, dn, id, NULL);
987 struct bdb_info *bdb = (struct bdb_info *) be->be_private;
991 rc = bdb_dn2id(be, txn, dn, &id);
995 ldap_pvt_thread_rdwr_rlock(&bdb->bi_tree_rdwr);
996 n = bdb_find_id_node(id, bdb->bi_tree);
997 ldap_pvt_thread_rdwr_runlock(&bdb->bi_tree_rdwr);
1005 /* Since we don't store IDLs for onelevel or subtree, we have to construct
1006 * them on the fly... Perhaps the i_kids tree ought to just be an IDL?
1014 return bdb_idl_insert(ids, n->i_id);
1025 rc = bdb_idl_insert(ids, n->i_id);
1027 ldap_pvt_thread_rdwr_rlock(&n->i_kids_rdwr);
1028 rc = avl_apply(n->i_kids, (AVL_APPLY)insert_sub, ids, -1,
1030 ldap_pvt_thread_rdwr_runlock(&n->i_kids_rdwr);
1042 struct bdb_info *bdb = (struct bdb_info *) be->be_private;
1047 if (prefix == DN_SUBTREE_PREFIX && be_issuffix(be, dn)) {
1048 BDB_IDL_ALL(bdb, ids);
1052 rc = bdb_dn2id(be, NULL, dn, &id);
1055 ldap_pvt_thread_rdwr_rlock(&bdb->bi_tree_rdwr);
1056 n = bdb_find_id_node(id, bdb->bi_tree);
1057 ldap_pvt_thread_rdwr_runlock(&bdb->bi_tree_rdwr);
1060 ldap_pvt_thread_rdwr_rlock(&n->i_kids_rdwr);
1061 if (prefix == DN_ONE_PREFIX) {
1062 rc = avl_apply(n->i_kids, (AVL_APPLY)insert_one, ids, -1,
1065 rc = avl_apply(n->i_kids, (AVL_APPLY)insert_sub, ids, -1,
1068 ldap_pvt_thread_rdwr_runlock(&n->i_kids_rdwr);
1071 #endif /* BDB_HIER */