1 /* dn2id.c - routines to deal with the dn2id index */
4 * Copyright 1998-2003 The OpenLDAP Foundation, All Rights Reserved.
5 * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
11 #include <ac/string.h>
26 struct bdb_info *bdb = (struct bdb_info *) be->be_private;
27 DB *db = bdb->bi_dn2id->bdi_db;
31 struct berval ptr, pdn;
34 LDAP_LOG ( INDEX, ARGS, "bdb_dn2id_add( \"%s\", 0x%08lx )\n",
35 e->e_ndn, (long) e->e_id, 0 );
37 Debug( LDAP_DEBUG_TRACE, "=> bdb_dn2id_add( \"%s\", 0x%08lx )\n",
38 e->e_ndn, (long) e->e_id, 0 );
40 assert( e->e_id != NOID );
43 key.size = e->e_nname.bv_len + 2;
45 key.flags = DB_DBT_USERMEM;
46 buf = sl_malloc( key.size, ctx );
48 buf[0] = DN_BASE_PREFIX;
50 ptr.bv_len = e->e_nname.bv_len;
51 AC_MEMCPY( ptr.bv_val, e->e_nname.bv_val, e->e_nname.bv_len );
52 ptr.bv_val[ptr.bv_len] = '\0';
55 data.data = (char *) &e->e_id;
56 data.size = sizeof( e->e_id );
58 /* store it -- don't override */
59 rc = db->put( db, txn, &key, &data, DB_NOOVERWRITE );
62 LDAP_LOG ( INDEX, ERR, "bdb_dn2id_add: put failed: %s %d\n",
63 db_strerror(rc), rc, 0 );
65 Debug( LDAP_DEBUG_ANY, "=> bdb_dn2id_add: put failed: %s %d\n",
66 db_strerror(rc), rc, 0 );
71 #ifndef BDB_MULTIPLE_SUFFIXES
72 if( !be_issuffix( be, &ptr )) {
74 buf[0] = DN_SUBTREE_PREFIX;
75 rc = db->put( db, txn, &key, &data, DB_NOOVERWRITE );
78 LDAP_LOG ( INDEX, ERR,
79 "=> bdb_dn2id_add: subtree (%s) put failed: %d\n",
82 Debug( LDAP_DEBUG_ANY,
83 "=> bdb_dn2id_add: subtree (%s) put failed: %d\n",
89 #ifdef BDB_MULTIPLE_SUFFIXES
90 if( !be_issuffix( be, &ptr )) {
92 dnParent( &ptr, &pdn );
94 key.size = pdn.bv_len + 2;
96 pdn.bv_val[-1] = DN_ONE_PREFIX;
97 key.data = pdn.bv_val-1;
100 rc = bdb_idl_insert_key( be, db, txn, &key, e->e_id );
104 LDAP_LOG ( INDEX, ERR,
105 "=> bdb_dn2id_add: parent (%s) insert failed: %d\n",
108 Debug( LDAP_DEBUG_ANY,
109 "=> bdb_dn2id_add: parent (%s) insert failed: %d\n",
114 #ifndef BDB_MULTIPLE_SUFFIXES
117 while( !be_issuffix( be, &ptr )) {
121 ptr.bv_val[-1] = DN_SUBTREE_PREFIX;
123 rc = bdb_idl_insert_key( be, db, txn, &key, e->e_id );
127 LDAP_LOG ( INDEX, ERR,
128 "=> bdb_dn2id_add: subtree (%s) insert failed: %d\n",
131 Debug( LDAP_DEBUG_ANY,
132 "=> bdb_dn2id_add: subtree (%s) insert failed: %d\n",
137 #ifdef BDB_MULTIPLE_SUFFIXES
138 if( be_issuffix( be, &ptr )) break;
140 dnParent( &ptr, &pdn );
142 key.size = pdn.bv_len + 2;
144 key.data = pdn.bv_val - 1;
147 #ifdef BDB_MULTIPLE_SUFFIXES
154 LDAP_LOG ( INDEX, RESULTS, "<= bdb_dn2id_add: %d\n", rc, 0, 0 );
156 Debug( LDAP_DEBUG_TRACE, "<= bdb_dn2id_add: %d\n", rc, 0, 0 );
169 struct bdb_info *bdb = (struct bdb_info *) be->be_private;
170 DB *db = bdb->bi_dn2id->bdi_db;
174 struct berval pdn, ptr;
177 LDAP_LOG ( INDEX, ARGS,
178 "=> bdb_dn2id_delete ( \"%s\", 0x%08lx )\n", e->e_ndn, e->e_id, 0);
180 Debug( LDAP_DEBUG_TRACE, "=> bdb_dn2id_delete( \"%s\", 0x%08lx )\n",
181 e->e_ndn, e->e_id, 0 );
185 key.size = e->e_nname.bv_len + 2;
186 buf = sl_malloc( key.size, ctx );
188 key.flags = DB_DBT_USERMEM;
189 buf[0] = DN_BASE_PREFIX;
191 ptr.bv_len = e->e_nname.bv_len;
192 AC_MEMCPY( ptr.bv_val, e->e_nname.bv_val, e->e_nname.bv_len );
193 ptr.bv_val[ptr.bv_len] = '\0';
196 rc = db->del( db, txn, &key, 0 );
199 LDAP_LOG ( INDEX, ERR,
200 "=> bdb_dn2id_delete: delete failed: %s %d\n",
201 db_strerror(rc), rc, 0 );
203 Debug( LDAP_DEBUG_ANY, "=> bdb_dn2id_delete: delete failed: %s %d\n",
204 db_strerror(rc), rc, 0 );
209 #ifndef BDB_MULTIPLE_SUFFIXES
210 if( !be_issuffix( be, &ptr )) {
212 buf[0] = DN_SUBTREE_PREFIX;
213 rc = db->del( db, txn, &key, 0 );
216 LDAP_LOG ( INDEX, ERR,
217 "=> bdb_dn2id_delete: subtree (%s) delete failed: %d\n",
220 Debug( LDAP_DEBUG_ANY,
221 "=> bdb_dn2id_delete: subtree (%s) delete failed: %d\n",
227 #ifdef BDB_MULTIPLE_SUFFIXES
228 if( !be_issuffix( be, &ptr )) {
230 dnParent( &ptr, &pdn );
232 key.size = pdn.bv_len + 2;
234 pdn.bv_val[-1] = DN_ONE_PREFIX;
235 key.data = pdn.bv_val - 1;
238 rc = bdb_idl_delete_key( be, db, txn, &key, e->e_id );
242 LDAP_LOG ( INDEX, ERR,
243 "=> bdb_dn2id_delete: parent (%s) delete failed: %d\n",
246 Debug( LDAP_DEBUG_ANY,
247 "=> bdb_dn2id_delete: parent (%s) delete failed: %d\n",
252 #ifndef BDB_MULTIPLE_SUFFIXES
255 while( !be_issuffix( be, &ptr )) {
259 ptr.bv_val[-1] = DN_SUBTREE_PREFIX;
261 rc = bdb_idl_delete_key( be, db, txn, &key, e->e_id );
264 LDAP_LOG ( INDEX, ERR,
265 "=> bdb_dn2id_delete: subtree (%s) delete failed: %d\n",
268 Debug( LDAP_DEBUG_ANY,
269 "=> bdb_dn2id_delete: subtree (%s) delete failed: %d\n",
274 #ifdef BDB_MULTIPLE_SUFFIXES
275 if( be_issuffix( be, &ptr )) break;
277 dnParent( &ptr, &pdn );
279 key.size = pdn.bv_len + 2;
281 key.data = pdn.bv_val - 1;
284 #ifdef BDB_MULTIPLE_SUFFIXES
291 LDAP_LOG ( INDEX, RESULTS, "<= bdb_dn2id_delete %d\n", rc, 0, 0 );
293 Debug( LDAP_DEBUG_TRACE, "<= bdb_dn2id_delete %d\n", rc, 0, 0 );
308 struct bdb_info *bdb = (struct bdb_info *) be->be_private;
309 DB *db = bdb->bi_dn2id->bdi_db;
312 LDAP_LOG ( INDEX, ARGS, "=> bdb_dn2id( \"%s\" )\n", dn->bv_val, 0, 0 );
314 Debug( LDAP_DEBUG_TRACE, "=> bdb_dn2id( \"%s\" )\n", dn->bv_val, 0, 0 );
317 key.size = dn->bv_len + 2;
318 key.data = sl_malloc( key.size, ctx );
319 ((char *)key.data)[0] = DN_BASE_PREFIX;
320 AC_MEMCPY( &((char *)key.data)[1], dn->bv_val, key.size - 1 );
324 data.data = &ei->bei_id;
325 data.ulen = sizeof(ID);
326 data.flags = DB_DBT_USERMEM;
329 rc = db->get( db, txn, &key, &data, bdb->bi_db_opflags );
333 LDAP_LOG ( INDEX, ERR, "<= bdb_dn2id: get failed %s (%d)\n",
334 db_strerror(rc), rc, 0 );
336 Debug( LDAP_DEBUG_TRACE, "<= bdb_dn2id: get failed: %s (%d)\n",
337 db_strerror( rc ), rc, 0 );
341 LDAP_LOG ( INDEX, RESULTS,
342 "<= bdb_dn2id: got id=0x%08lx\n", ei->bei_id, 0, 0 );
344 Debug( LDAP_DEBUG_TRACE, "<= bdb_dn2id: got id=0x%08lx\n",
349 sl_free( key.data, ctx );
360 struct bdb_info *bdb = (struct bdb_info *) op->o_bd->be_private;
361 DB *db = bdb->bi_dn2id->bdi_db;
366 LDAP_LOG ( INDEX, ARGS,
367 "=> bdb_dn2id_children( %s )\n", e->e_nname.bv_val, 0, 0 );
369 Debug( LDAP_DEBUG_TRACE, "=> bdb_dn2id_children( %s )\n",
370 e->e_nname.bv_val, 0, 0 );
373 key.size = e->e_nname.bv_len + 2;
374 key.data = sl_malloc( key.size, op->o_tmpmemctx );
375 ((char *)key.data)[0] = DN_ONE_PREFIX;
376 AC_MEMCPY( &((char *)key.data)[1], e->e_nname.bv_val, key.size - 1 );
378 #ifdef SLAP_IDL_CACHE
379 if ( bdb->bi_idl_cache_size ) {
380 rc = bdb_idl_cache_get( bdb, db, &key, NULL );
381 if ( rc != LDAP_NO_SUCH_OBJECT ) {
382 sl_free( key.data, op->o_tmpmemctx );
387 /* we actually could do a empty get... */
390 data.ulen = sizeof(id);
391 data.flags = DB_DBT_USERMEM;
393 data.dlen = sizeof(id);
395 rc = db->get( db, txn, &key, &data, bdb->bi_db_opflags );
396 sl_free( key.data, op->o_tmpmemctx );
399 LDAP_LOG ( INDEX, DETAIL1,
400 "<= bdb_dn2id_children( %s ): %s (%d)\n",
401 e->e_nname.bv_val, rc == 0 ? "" : ( rc == DB_NOTFOUND ? "no " :
402 db_strerror(rc)), rc );
404 Debug( LDAP_DEBUG_TRACE, "<= bdb_dn2id_children( %s ): %s (%d)\n",
406 rc == 0 ? "" : ( rc == DB_NOTFOUND ? "no " :
407 db_strerror(rc) ), rc );
424 struct bdb_info *bdb = (struct bdb_info *) be->be_private;
425 DB *db = bdb->bi_dn2id->bdi_db;
428 LDAP_LOG ( INDEX, ARGS,
429 "=> bdb_dn2ididl( \"%s\" )\n", dn->bv_val, 0, 0 );
431 Debug( LDAP_DEBUG_TRACE, "=> bdb_dn2idl( \"%s\" )\n", dn->bv_val, 0, 0 );
434 #ifndef BDB_MULTIPLE_SUFFIXES
435 if (prefix == DN_SUBTREE_PREFIX && be_issuffix(be, dn))
437 BDB_IDL_ALL(bdb, ids);
443 key.size = dn->bv_len + 2;
445 key.flags = DB_DBT_USERMEM;
446 key.data = sl_malloc( key.size, ctx );
447 ((char *)key.data)[0] = prefix;
448 AC_MEMCPY( &((char *)key.data)[1], dn->bv_val, key.size - 1 );
450 rc = bdb_idl_fetch_key( be, db, NULL, &key, ids );
454 LDAP_LOG ( INDEX, ERR,
455 "<= bdb_dn2ididl: get failed: %s (%d)\n", db_strerror(rc), rc, 0 );
457 Debug( LDAP_DEBUG_TRACE,
458 "<= bdb_dn2idl: get failed: %s (%d)\n",
459 db_strerror( rc ), rc, 0 );
464 LDAP_LOG ( INDEX, RESULTS,
465 "<= bdb_dn2ididl: id=%ld first=%ld last=%ld\n",
466 (long) ids[0], (long) BDB_IDL_FIRST( ids ),
467 (long) BDB_IDL_LAST( ids ) );
469 Debug( LDAP_DEBUG_TRACE,
470 "<= bdb_dn2idl: id=%ld first=%ld last=%ld\n",
472 (long) BDB_IDL_FIRST( ids ), (long) BDB_IDL_LAST( ids ) );
476 sl_free( key.data, ctx );
481 /* Experimental management routines for a hierarchically structured database.
483 * Unsupported! Use at your own risk!
484 * -- Howard Chu, Symas Corp. 2003.
486 * Instead of a ldbm-style dn2id database, we use a hierarchical one. Each
487 * entry in this database is a struct diskNode, keyed by entryID and with
488 * the data containing the RDN and entryID of the node's children. We use
489 * a B-Tree with sorted duplicates to store all the children of a node under
490 * the same key. Also, the first item under the key contains the entry's own
491 * rdn and the ID of the node's parent, to allow bottom-up tree traversal as
492 * well as top-down. To keep this info first in the list, the nrdnlen is set
493 * to the negative of its value.
495 * The diskNode is a variable length structure. This definition is not
496 * directly usable for in-memory manipulation.
498 typedef struct diskNode {
505 /* Sort function for the sorted duplicate data items of a dn2id key.
506 * Sorts based on normalized RDN, in length order.
515 diskNode *usr = usrkey->data;
516 diskNode *cur = curkey->data;
517 short curlen, usrlen;
522 /* Make sure to detect negative values in the nrdnlen */
523 ptr = (char *)&usr->nrdnlen;
524 pt2 = (unsigned char *)(ptr+1);
526 usrlen = ptr[0] << 8 | *pt2;
528 ptr = (char *)&cur->nrdnlen;
529 pt2 = (unsigned char *)(ptr+1);
531 curlen = ptr[0] << 8 | *pt2;
533 rc = usrlen - curlen;
535 if ( rc == 0 ) rc = strncmp( usr->nrdn, cur->nrdn, usrlen );
539 /* This function constructs a full DN for a given entry.
547 int rlen = 0, nrlen = 0;
551 for ( ei = BEI(e); ei && ei->bei_id; ei=ei->bei_parent ) {
552 rlen += ei->bei_rdn.bv_len + 1;
553 nrlen += ei->bei_nrdn.bv_len + 1;
554 if (ei->bei_modrdns > max) max = ei->bei_modrdns;
557 /* See if the entry DN was invalidated by a subtree rename */
559 if ( BEI(e)->bei_modrdns >= max ) {
562 /* We found a mismatch, tell the caller to lock it */
563 if ( checkit == 1 ) {
566 /* checkit == 2. do the fix. */
567 free( e->e_name.bv_val );
570 e->e_name.bv_len = rlen - 1;
571 e->e_nname.bv_len = nrlen - 1;
572 e->e_name.bv_val = ch_malloc(rlen + nrlen);
573 e->e_nname.bv_val = e->e_name.bv_val + rlen;
574 ptr = e->e_name.bv_val;
575 nptr = e->e_nname.bv_val;
576 for ( ei = BEI(e); ei && ei->bei_id; ei=ei->bei_parent ) {
577 ptr = lutil_strcopy(ptr, ei->bei_rdn.bv_val);
578 nptr = lutil_strcopy(nptr, ei->bei_nrdn.bv_val);
579 if ( ei->bei_parent ) {
584 BEI(e)->bei_modrdns = max;
591 /* We add two elements to the DN2ID database - a data item under the parent's
592 * entryID containing the child's RDN and entryID, and an item under the
593 * child's entryID containing the parent's entryID.
603 struct bdb_info *bdb = (struct bdb_info *) be->be_private;
604 DB *db = bdb->bi_dn2id->bdi_db;
610 nrlen = dn_rdnlen( be, &e->e_nname );
612 rlen = dn_rdnlen( be, &e->e_name );
614 nrlen = e->e_nname.bv_len;
615 rlen = e->e_name.bv_len;
618 d = sl_malloc(sizeof(diskNode) + rlen + nrlen, ctx);
619 d->entryID = e->e_id;
621 ptr = lutil_strncopy( d->nrdn, e->e_nname.bv_val, nrlen );
623 ptr = lutil_strncopy( ptr, e->e_name.bv_val, rlen );
628 key.data = &eip->bei_id;
629 key.size = sizeof(ID);
630 key.flags = DB_DBT_USERMEM;
632 #ifdef SLAP_IDL_CACHE
633 if ( bdb->bi_idl_cache_size ) {
634 bdb_idl_cache_del( bdb, db, &key );
638 data.size = sizeof(diskNode) + rlen + nrlen;
639 data.flags = DB_DBT_USERMEM;
641 rc = db->put( db, txn, &key, &data, DB_NODUPDATA );
645 d->entryID = eip->bei_id;
646 d->nrdnlen = 0 - nrlen;
648 rc = db->put( db, txn, &key, &data, DB_NODUPDATA );
664 struct bdb_info *bdb = (struct bdb_info *) be->be_private;
665 DB *db = bdb->bi_dn2id->bdi_db;
672 key.size = sizeof(ID);
674 key.data = &eip->bei_id;
675 key.flags = DB_DBT_USERMEM;
678 data.size = sizeof(diskNode) + BEI(e)->bei_nrdn.bv_len;
679 data.ulen = data.size;
680 data.dlen = data.size;
681 data.flags = DB_DBT_USERMEM | DB_DBT_PARTIAL;
683 #ifdef SLAP_IDL_CACHE
684 if ( bdb->bi_idl_cache_size ) {
685 bdb_idl_cache_del( bdb, db, &key );
688 rc = db->cursor( db, txn, &cursor, bdb->bi_db_opflags );
691 d = sl_malloc( data.size, ctx );
692 d->entryID = e->e_id;
693 d->nrdnlen = BEI(e)->bei_nrdn.bv_len;
694 strcpy( d->nrdn, BEI(e)->bei_nrdn.bv_val );
697 /* Delete our ID from the parent's list */
698 rc = cursor->c_get( cursor, &key, &data, DB_GET_BOTH | DB_RMW );
700 rc = cursor->c_del( cursor, 0 );
702 /* Delete our ID from the tree. With sorted duplicates, this
703 * will leave any child nodes still hanging around. This is OK
704 * for modrdn, which will add our info back in later.
708 rc = cursor->c_get( cursor, &key, &data, DB_SET );
710 rc = cursor->c_del( cursor, 0 );
712 cursor->c_close( cursor );
726 struct bdb_info *bdb = (struct bdb_info *) be->be_private;
727 DB *db = bdb->bi_dn2id->bdi_db;
733 ID idp = ei->bei_parent->bei_id;
735 nrlen = dn_rdnlen( be, in );
736 if (!nrlen) nrlen = in->bv_len;
739 key.size = sizeof(ID);
741 key.ulen = sizeof(ID);
742 key.flags = DB_DBT_USERMEM;
745 data.size = sizeof(diskNode) + nrlen;
746 data.ulen = data.size * 3;
747 data.flags = DB_DBT_USERMEM;
749 rc = db->cursor( db, txn, &cursor, bdb->bi_db_opflags );
752 d = sl_malloc( data.size * 3, ctx );
754 ptr = lutil_strncopy( d->nrdn, in->bv_val, nrlen );
758 rc = cursor->c_get( cursor, &key, &data, DB_GET_BOTH );
759 cursor->c_close( cursor );
762 AC_MEMCPY( &ei->bei_id, &d->entryID, sizeof(ID) );
763 ei->bei_rdn.bv_len = data.size - sizeof(diskNode) - nrlen;
764 ptr = d->nrdn + nrlen + 1;
765 ei->bei_rdn.bv_val = ch_malloc( ei->bei_rdn.bv_len + 1 );
766 strcpy( ei->bei_rdn.bv_val, ptr );
781 struct bdb_info *bdb = (struct bdb_info *) be->be_private;
782 DB *db = bdb->bi_dn2id->bdi_db;
791 key.size = sizeof(ID);
792 key.data = &ei->bei_id;
793 key.ulen = sizeof(ID);
794 key.flags = DB_DBT_USERMEM;
797 data.flags = DB_DBT_USERMEM;
799 rc = db->cursor( db, txn, &cursor, bdb->bi_db_opflags );
802 data.ulen = sizeof(diskNode) + (SLAP_LDAPDN_MAXLEN * 2);
803 d = sl_malloc( data.ulen, ctx );
806 rc = cursor->c_get( cursor, &key, &data, DB_SET );
807 cursor->c_close( cursor );
809 if (d->nrdnlen >= 0) {
812 AC_MEMCPY( idp, &d->entryID, sizeof(ID) );
813 ei->bei_nrdn.bv_len = 0 - d->nrdnlen;
814 ber_str2bv( d->nrdn, ei->bei_nrdn.bv_len, 1, &ei->bei_nrdn );
815 ei->bei_rdn.bv_len = data.size - sizeof(diskNode) -
817 ptr = d->nrdn + ei->bei_nrdn.bv_len + 1;
818 ber_str2bv( ptr, ei->bei_rdn.bv_len, 1, &ei->bei_rdn );
830 struct bdb_info *bdb = (struct bdb_info *) op->o_bd->be_private;
831 DB *db = bdb->bi_dn2id->bdi_db;
839 key.size = sizeof(ID);
841 key.flags = DB_DBT_USERMEM;
843 #ifdef SLAP_IDL_CACHE
844 if ( bdb->bi_idl_cache_size ) {
845 rc = bdb_idl_cache_get( bdb, db, &key, NULL );
846 if ( rc != LDAP_NO_SUCH_OBJECT ) {
853 data.ulen = sizeof(d);
854 data.flags = DB_DBT_USERMEM | DB_DBT_PARTIAL;
855 data.dlen = sizeof(d);
857 rc = db->cursor( db, txn, &cursor, bdb->bi_db_opflags );
860 rc = cursor->c_get( cursor, &key, &data, DB_SET );
862 rc = cursor->c_get( cursor, &key, &data, DB_NEXT_DUP );
864 cursor->c_close( cursor );
869 * We can't just use bdb_idl_fetch_key because
870 * 1 - our data items are longer than just an entry ID
871 * 2 - our data items are sorted alphabetically by nrdn, not by ID.
873 * We descend the tree recursively, so we define this cookie
874 * to hold our necessary state information. The bdb_dn2idl_internal
875 * function uses this cookie when calling itself.
878 struct dn2id_cookie {
879 struct bdb_info *bdb;
887 ID tmp[BDB_IDL_DB_SIZE];
897 struct dn2id_cookie *cx
900 #ifdef SLAP_IDL_CACHE
901 if ( cx->bdb->bi_idl_cache_size ) {
902 cx->rc = bdb_idl_cache_get(cx->bdb, cx->db, &cx->key, cx->tmp);
903 if ( cx->rc == DB_NOTFOUND ) {
906 if ( cx->rc == LDAP_SUCCESS ) {
912 cx->rc = cx->db->cursor( cx->db, NULL, &cx->dbc,
913 cx->bdb->bi_db_opflags );
914 if ( cx->rc ) return cx->rc;
915 BDB_IDL_ZERO( cx->tmp );
917 cx->data.data = &cx->dbuf;
918 cx->data.ulen = sizeof(ID);
919 cx->data.dlen = sizeof(ID);
920 cx->data.flags = DB_DBT_USERMEM | DB_DBT_PARTIAL;
922 /* The first item holds the parent ID. Ignore it. */
923 cx->rc = cx->dbc->c_get( cx->dbc, &cx->key, &cx->data, DB_SET );
924 if ( cx->rc == DB_NOTFOUND ) goto saveit;
925 if ( cx->rc ) return cx->rc;
927 cx->data.data = cx->buf;
928 cx->data.ulen = BDB_IDL_UM_SIZE * sizeof(ID);
929 cx->data.flags = DB_DBT_USERMEM;
931 /* Fetch the rest of the IDs in a loop... */
932 while ( (cx->rc = cx->dbc->c_get( cx->dbc, &cx->key, &cx->data,
933 DB_MULTIPLE | DB_NEXT_DUP )) == 0 ) {
936 DB_MULTIPLE_INIT( cx->ptr, &cx->data );
938 DB_MULTIPLE_NEXT( cx->ptr, &cx->data, j, len );
940 AC_MEMCPY( &cx->dbuf, j, sizeof(ID) );
941 bdb_idl_insert( cx->tmp, cx->dbuf );
945 cx->dbc->c_close( cx->dbc );
947 /* If we got some records, treat as success */
948 if (!BDB_IDL_IS_ZERO(cx->tmp)) {
953 #ifdef SLAP_IDL_CACHE
954 if ( cx->bdb->bi_idl_cache_max_size ) {
955 bdb_idl_cache_put( cx->bdb, cx->db, &cx->key, cx->tmp, cx->rc );
959 if ( cx->prefix == DN_SUBTREE_PREFIX ) {
962 save = sl_malloc( BDB_IDL_SIZEOF( cx->tmp ), cx->ctx );
963 BDB_IDL_CPY( save, cx->tmp );
964 bdb_idl_union( cx->ids, cx->tmp );
967 for ( cx->id = bdb_idl_first( save, &idcurs );
969 cx->id = bdb_idl_next( save, &idcurs )) {
970 bdb_dn2idl_internal( cx );
972 sl_free( save, cx->ctx );
975 BDB_IDL_CPY( cx->ids, cx->tmp );
990 struct dn2id_cookie cx;
991 EntryInfo *ei = (EntryInfo *)dn;
993 #ifndef BDB_MULTIPLE_SUFFIXES
994 if ( ei->bei_parent->bei_id == 0 ) {
995 struct bdb_info *bdb = (struct bdb_info *)be->be_private;
996 BDB_IDL_ALL( bdb, ids );
1002 cx.bdb = (struct bdb_info *)be->be_private;
1003 cx.db = cx.bdb->bi_dn2id->bdi_db;
1009 BDB_IDL_ZERO( ids );
1010 if ( prefix == DN_SUBTREE_PREFIX ) {
1011 bdb_idl_insert( ids, cx.id );
1015 cx.key.data = &cx.id;
1016 cx.key.ulen = sizeof(ID);
1017 cx.key.size = sizeof(ID);
1018 cx.key.flags = DB_DBT_USERMEM;
1022 return bdb_dn2idl_internal(&cx);
1024 #endif /* BDB_HIER */