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-2011 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>
26 /* Management routines for a hierarchically structured database.
28 * Instead of a ldbm-style dn2id database, we use a hierarchical one. Each
29 * entry in this database is a struct diskNode, keyed by entryID and with
30 * the data containing the RDN and entryID of the node's children. We use
31 * a B-Tree with sorted duplicates to store all the children of a node under
32 * the same key. Also, the first item under the key contains the entry's own
33 * rdn and the ID of the node's parent, to allow bottom-up tree traversal as
34 * well as top-down. To keep this info first in the list, the high bit of all
35 * subsequent nrdnlen's is always set. This means we can only accomodate
36 * RDNs up to length 32767, but that's fine since full DNs are already
39 * The diskNode is a variable length structure. This definition is not
40 * directly usable for in-memory manipulation.
42 typedef struct diskNode {
43 unsigned char nrdnlen[2];
45 char rdn[1]; /* variable placement */
46 unsigned char entryID[sizeof(ID)]; /* variable placement */
49 /* Sort function for the sorted duplicate data items of a dn2id key.
50 * Sorts based on normalized RDN, in length order.
54 const MDB_val *usrkey,
61 un = (diskNode *)usrkey->mv_data;
62 cn = (diskNode *)curkey->mv_data;
64 /* data is not aligned, cannot compare directly */
65 rc = un->nrdnlen[0] - cn->nrdnlen[0];
67 rc = un->nrdnlen[1] - cn->nrdnlen[1];
70 nrlen = (un->nrdnlen[0] << 8) | un->nrdnlen[1];
71 return strncmp( un->nrdn, cn->nrdn, nrlen );
75 /* This function constructs a full DN for a given entry.
82 int rlen = 0, nrlen = 0;
89 /* count length of all DN components */
90 for ( ei = BEI(e); ei && ei->bei_id; ei=ei->bei_parent ) {
91 rlen += ei->bei_rdn.bv_len + 1;
92 nrlen += ei->bei_nrdn.bv_len + 1;
93 if (ei->bei_modrdns > max) max = ei->bei_modrdns;
96 /* See if the entry DN was invalidated by a subtree rename */
98 if ( BEI(e)->bei_modrdns >= max ) {
101 /* We found a mismatch, tell the caller to lock it */
102 if ( checkit == 1 ) {
105 /* checkit == 2. do the fix. */
106 free( e->e_name.bv_val );
107 free( e->e_nname.bv_val );
110 e->e_name.bv_len = rlen - 1;
111 e->e_nname.bv_len = nrlen - 1;
112 e->e_name.bv_val = ch_malloc(rlen);
113 e->e_nname.bv_val = ch_malloc(nrlen);
114 ptr = e->e_name.bv_val;
115 nptr = e->e_nname.bv_val;
116 for ( ei = BEI(e); ei && ei->bei_id; ei=ei->bei_parent ) {
117 ptr = lutil_strcopy(ptr, ei->bei_rdn.bv_val);
118 nptr = lutil_strcopy(nptr, ei->bei_nrdn.bv_val);
119 if ( ei->bei_parent ) {
124 BEI(e)->bei_modrdns = max;
125 if ( ptr > e->e_name.bv_val ) ptr[-1] = '\0';
126 if ( nptr > e->e_nname.bv_val ) nptr[-1] = '\0';
132 /* We add two elements to the DN2ID database - a data item under the parent's
133 * entryID containing the child's RDN and entryID, and an item under the
134 * child's entryID containing the parent's entryID.
143 struct mdb_info *mdb = (struct mdb_info *) op->o_bd->be_private;
144 MDB_dbi dbi = mdb->mi_dn2id;
151 Debug( LDAP_DEBUG_TRACE, "=> mdb_dn2id_add 0x%lx: \"%s\"\n",
152 e->e_id, e->e_ndn, 0 );
154 nrlen = dn_rdnlen( op->o_bd, &e->e_nname );
156 rlen = dn_rdnlen( op->o_bd, &e->e_name );
158 nrlen = e->e_nname.bv_len;
159 rlen = e->e_name.bv_len;
162 d = op->o_tmpalloc(sizeof(diskNode) + rlen + nrlen, op->o_tmpmemctx);
163 d->nrdnlen[1] = nrlen & 0xff;
164 d->nrdnlen[0] = (nrlen >> 8) | 0x80;
165 ptr = lutil_strncopy( d->nrdn, e->e_nname.bv_val, nrlen );
167 ptr = lutil_strncopy( ptr, e->e_name.bv_val, rlen );
169 memcpy( ptr, &e->e_id, sizeof( ID ));
171 key.mv_size = sizeof(ID);
176 /* Need to make dummy root node once. Subsequent attempts
177 * will fail harmlessly.
180 diskNode dummy = {{0, 0}, "", "", ""};
181 data.mv_data = &dummy;
182 data.mv_size = sizeof(diskNode);
184 mdb_put( txn, dbi, &key, &data, MDB_NODUPDATA );
188 data.mv_size = sizeof(diskNode) + rlen + nrlen;
190 rc = mdb_put( txn, dbi, &key, &data, MDB_NODUPDATA );
194 memcpy( ptr, &pid, sizeof( ID ));
195 d->nrdnlen[0] ^= 0x80;
197 rc = mdb_put( txn, dbi, &key, &data, MDB_NODUPDATA );
200 op->o_tmpfree( d, op->o_tmpmemctx );
201 Debug( LDAP_DEBUG_TRACE, "<= mdb_dn2id_add 0x%lx: %d\n", e->e_id, rc, 0 );
213 struct mdb_info *mdb = (struct mdb_info *) op->o_bd->be_private;
214 MDB_dbi dbi = mdb->mi_dn2id;
220 Debug( LDAP_DEBUG_TRACE, "=> mdb_dn2id_delete 0x%lx: \"%s\"\n",
221 e->e_id, e->e_ndn, 0 );
223 key.mv_size = sizeof(ID);
227 nrlen = dn_rdnlen( op->o_bd, &e->e_nname );
228 data.mv_size = sizeof(diskNode) + nrlen - sizeof(ID) - 1;
230 d = op->o_tmpalloc( data.mv_size, op->o_tmpmemctx );
231 d->nrdnlen[1] = nrlen & 0xff;
232 d->nrdnlen[0] = (nrlen >> 8) | 0x80;
233 memcpy( d->nrdn, e->e_nname.bv_val, nrlen );
236 /* Delete our ID from the parent's list */
237 rc = mdb_del( txn, dbi, &key, &data, MDB_DEL_DUP );
239 /* Delete our ID from the tree. With sorted duplicates, this
240 * will leave any child nodes still hanging around. This is OK
241 * for modrdn, which will add our info back in later.
245 d->nrdnlen[0] ^= 0x80;
246 rc = mdb_del( txn, dbi, &key, &data, MDB_DEL_DUP );
249 op->o_tmpfree( d, op->o_tmpmemctx );
251 Debug( LDAP_DEBUG_TRACE, "<= mdb_dn2id_delete 0x%lx: %d\n", e->e_id, rc, 0 );
255 /* return last found ID in *id if no match */
262 struct berval *matched )
264 struct mdb_info *mdb = (struct mdb_info *) op->o_bd->be_private;
266 MDB_dbi dbi = mdb->mi_dn2id;
271 char dn[SLAP_LDAPDN_MAXLEN];
275 Debug( LDAP_DEBUG_TRACE, "=> mdb_dn2id(\"%s\")\n", in->bv_val, 0, 0 );
286 matched->bv_val = dn + sizeof(dn) - 1;
288 *matched->bv_val-- = '\0';
291 nrlen = tmp.bv_len - op->o_bd->be_nsuffix[0].bv_len;
293 tmp.bv_len = op->o_bd->be_nsuffix[0].bv_len;
295 key.mv_size = sizeof(ID);
297 rc = mdb_cursor_open( txn, dbi, &cursor );
304 data.mv_size = sizeof(diskNode) + tmp.bv_len;
305 d = op->o_tmpalloc( data.mv_size, op->o_tmpmemctx );
306 d->nrdnlen[1] = tmp.bv_len & 0xff;
307 d->nrdnlen[0] = (tmp.bv_len >> 8) | 0x80;
308 ptr = lutil_strncopy( d->nrdn, tmp.bv_val, tmp.bv_len );
311 rc = mdb_cursor_get( cursor, &key, &data, MDB_GET_BOTH );
312 op->o_tmpfree( d, op->o_tmpmemctx );
315 ptr = (char *) data.mv_data + data.mv_size - sizeof(ID);
316 memcpy( &nid, ptr, sizeof(ID));
318 /* grab the non-normalized RDN */
322 rlen = data.mv_size - sizeof(diskNode) - tmp.bv_len;
323 matched->bv_len += rlen;
324 matched->bv_val -= rlen + 1;
325 ptr = lutil_strcopy( matched->bv_val, d->rdn + tmp.bv_len );
331 if ( tmp.bv_val > in->bv_val ) {
332 for (ptr = tmp.bv_val - 2; ptr > in->bv_val &&
333 !DN_SEPARATOR(*ptr); ptr--) /* empty */;
334 if ( ptr >= in->bv_val ) {
335 if (DN_SEPARATOR(*ptr)) ptr++;
336 tmp.bv_len = tmp.bv_val - ptr - 1;
344 mdb_cursor_close( cursor );
345 if ( matched && matched->bv_len ) {
346 ptr = op->o_tmpalloc( matched->bv_len+1, op->o_tmpmemctx );
347 strcpy( ptr, matched->bv_val );
348 matched->bv_val = ptr;
353 Debug( LDAP_DEBUG_TRACE, "<= mdb_dn2id: get failed: %s (%d)\n",
354 mdb_strerror( rc ), rc, 0 );
356 Debug( LDAP_DEBUG_TRACE, "<= mdb_dn2id: got id=0x%lx\n",
363 /* return IDs from root to parent of DN */
371 struct mdb_info *mdb = (struct mdb_info *) op->o_bd->be_private;
373 MDB_dbi dbi = mdb->mi_dn2id;
381 Debug( LDAP_DEBUG_TRACE, "=> mdb_dn2sups(\"%s\")\n", in->bv_val, 0, 0 );
389 nrlen = tmp.bv_len - op->o_bd->be_nsuffix[0].bv_len;
391 tmp.bv_len = op->o_bd->be_nsuffix[0].bv_len;
393 key.mv_size = sizeof(ID);
395 rc = mdb_cursor_open( txn, dbi, &cursor );
402 data.mv_size = sizeof(diskNode) + tmp.bv_len;
403 d = op->o_tmpalloc( data.mv_size, op->o_tmpmemctx );
404 d->nrdnlen[1] = tmp.bv_len & 0xff;
405 d->nrdnlen[0] = (tmp.bv_len >> 8) | 0x80;
406 ptr = lutil_strncopy( d->nrdn, tmp.bv_val, tmp.bv_len );
409 rc = mdb_cursor_get( cursor, &key, &data, MDB_GET_BOTH );
410 op->o_tmpfree( d, op->o_tmpmemctx );
412 mdb_cursor_close( cursor );
415 ptr = (char *) data.mv_data + data.mv_size - sizeof(ID);
416 memcpy( &nid, ptr, sizeof(ID));
419 mdb_idl_insert( ids, pid );
421 if ( tmp.bv_val > in->bv_val ) {
422 for (ptr = tmp.bv_val - 2; ptr > in->bv_val &&
423 !DN_SEPARATOR(*ptr); ptr--) /* empty */;
424 if ( ptr >= in->bv_val ) {
425 if (DN_SEPARATOR(*ptr)) ptr++;
426 tmp.bv_len = tmp.bv_val - ptr - 1;
436 Debug( LDAP_DEBUG_TRACE, "<= mdb_dn2sups: get failed: %s (%d)\n",
437 mdb_strerror( rc ), rc, 0 );
451 struct mdb_info *mdb = (struct mdb_info *) op->o_bd->be_private;
452 DB *db = mdb->bi_dn2id->bdi_db;
461 key.size = sizeof(ID);
463 key.ulen = sizeof(ID);
464 key.flags = DB_DBT_USERMEM;
465 MDB_ID2DISK( ei->bei_id, &nid );
468 data.flags = DB_DBT_USERMEM;
470 rc = db->cursor( db, txn, &cursor, mdb->bi_db_opflags );
473 data.ulen = sizeof(diskNode) + (SLAP_LDAPDN_MAXLEN * 2);
474 d = op->o_tmpalloc( data.ulen, op->o_tmpmemctx );
477 rc = cursor->c_get( cursor, &key, &data, DB_SET );
479 if (d->nrdnlen[0] & 0x80) {
483 ptr = (char *) data.data + data.size - sizeof(ID);
484 MDB_DISK2ID( ptr, idp );
485 ei->bei_nrdn.bv_len = (d->nrdnlen[0] << 8) | d->nrdnlen[1];
486 ber_str2bv( d->nrdn, ei->bei_nrdn.bv_len, 1, &ei->bei_nrdn );
487 ei->bei_rdn.bv_len = data.size - sizeof(diskNode) -
489 ptr = d->nrdn + ei->bei_nrdn.bv_len + 1;
490 ber_str2bv( ptr, ei->bei_rdn.bv_len, 1, &ei->bei_rdn );
491 /* How many children does this node have? */
492 cursor->c_count( cursor, &dkids, 0 );
493 ei->bei_dkids = dkids;
496 cursor->c_close( cursor );
497 op->o_tmpfree( d, op->o_tmpmemctx );
508 struct mdb_info *mdb = (struct mdb_info *) op->o_bd->be_private;
509 MDB_dbi dbi = mdb->mi_dn2id;
515 key.mv_size = sizeof(ID);
519 rc = mdb_cursor_open( txn, dbi, &cursor );
522 rc = mdb_cursor_get( cursor, &key, &data, MDB_SET );
525 rc = mdb_cursor_count( cursor, &dkids );
527 if ( dkids < 2 ) rc = MDB_NOTFOUND;
530 mdb_cursor_close( cursor );
541 struct berval *nname )
543 struct mdb_info *mdb = (struct mdb_info *) op->o_bd->be_private;
544 MDB_dbi dbi = mdb->mi_dn2id;
548 char dn[SLAP_LDAPDN_MAXLEN], ndn[SLAP_LDAPDN_MAXLEN], *ptr;
552 key.mv_size = sizeof(ID);
555 rc = mdb_cursor_open( txn, dbi, cursp );
569 rc = mdb_cursor_get( cursor, &key, &data, MDB_SET );
572 ptr += data.mv_size - sizeof(ID);
573 memcpy( &id, ptr, sizeof(ID) );
575 nrlen = (d->nrdnlen[0] << 8) | d->nrdnlen[1];
580 /* copy name and trailing NUL */
581 memcpy( nptr, d->nrdn, nrlen+1 );
582 rlen = data.mv_size - sizeof(diskNode) - nrlen;
583 memcpy( dptr, d->nrdn+nrlen+1, rlen+1 );
588 name->bv_len = dptr - dn;
589 nname->bv_len = nptr - ndn;
590 name->bv_val = op->o_tmpalloc( name->bv_len + 1, op->o_tmpmemctx );
591 nname->bv_val = op->o_tmpalloc( nname->bv_len + 1, op->o_tmpmemctx );
592 memcpy( name->bv_val, dn, name->bv_len );
593 name->bv_val[name->bv_len] = '\0';
594 memcpy( nname->bv_val, ndn, nname->bv_len );
595 nname->bv_val[nname->bv_len] = '\0';
600 /* Find each id in ids that is a child of base and move it to res.
610 struct mdb_info *mdb = (struct mdb_info *) op->o_bd->be_private;
611 MDB_dbi dbi = mdb->mi_dn2id;
614 ID ida, id, cid, ci0, idc = 0;
618 key.mv_size = sizeof(ID);
622 rc = mdb_cursor_open( txn, dbi, &cursor );
625 ida = mdb_idl_first( ids, &cid );
627 /* Don't bother moving out of ids if it's a range */
628 if (!MDB_IDL_IS_RANGE(ids)) {
633 while (ida != NOID) {
637 rc = mdb_cursor_get( cursor, &key, &data, MDB_SET );
639 /* not found, move on to next */
648 ptr += data.mv_size - sizeof(ID);
649 memcpy( &id, ptr, sizeof(ID) );
663 if ( op->ors_scope == LDAP_SCOPE_ONELEVEL )
666 ida = mdb_idl_next( ids, &cid );
668 if (!MDB_IDL_IS_RANGE( ids ))
671 mdb_cursor_close( cursor );
675 /* See if base is a child of any of the scopes
685 struct mdb_info *mdb = (struct mdb_info *) op->o_bd->be_private;
686 MDB_dbi dbi = mdb->mi_dn2id;
694 key.mv_size = sizeof(ID);
697 rc = mdb_cursor_open( txn, dbi, cursp );
705 rc = mdb_cursor_get( cursor, &key, &data, MDB_SET );
709 ptr += data.mv_size - sizeof(ID);
710 memcpy( &id, ptr, sizeof(ID) );
711 x = mdb_idl_search( scopes, id );
712 if ( scopes[x] == id )
714 if ( op->ors_scope == LDAP_SCOPE_ONELEVEL )
722 * We can't just use mdb_idl_fetch_key because
723 * 1 - our data items are longer than just an entry ID
724 * 2 - our data items are sorted alphabetically by nrdn, not by ID.
726 * We descend the tree recursively, so we define this cookie
727 * to hold our necessary state information. The mdb_dn2idl_internal
728 * function uses this cookie when calling itself.
731 struct dn2id_cookie {
732 struct mdb_info *mdb;
757 EntryInfo *ei = data;
760 mdb_idl_append_one( idl, ei->bei_id );
766 struct dn2id_cookie *cx
769 MDB_IDL_ZERO( cx->tmp );
771 if ( cx->mdb->bi_idl_cache_size ) {
772 char *ptr = ((char *)&cx->id)-1;
775 cx->key.size = sizeof(ID)+1;
776 if ( cx->prefix == DN_SUBTREE_PREFIX ) {
777 ID *ids = cx->depth ? cx->tmp : cx->ids;
779 cx->rc = mdb_idl_cache_get(cx->mdb, cx->db, &cx->key, ids);
780 if ( cx->rc == LDAP_SUCCESS ) {
782 mdb_idl_append( cx->ids, cx->tmp );
788 *ptr = DN_ONE_PREFIX;
789 cx->rc = mdb_idl_cache_get(cx->mdb, cx->db, &cx->key, cx->tmp);
790 if ( cx->rc == LDAP_SUCCESS ) {
793 if ( cx->rc == DB_NOTFOUND ) {
798 mdb_cache_entryinfo_lock( cx->ei );
800 /* If number of kids in the cache differs from on-disk, load
801 * up all the kids from the database
803 if ( cx->ei->bei_ckids+1 != cx->ei->bei_dkids ) {
805 db_recno_t dkids = cx->ei->bei_dkids;
806 ei.bei_parent = cx->ei;
808 /* Only one thread should load the cache */
809 while ( cx->ei->bei_state & CACHE_ENTRY_ONELEVEL ) {
810 mdb_cache_entryinfo_unlock( cx->ei );
811 ldap_pvt_thread_yield();
812 mdb_cache_entryinfo_lock( cx->ei );
813 if ( cx->ei->bei_ckids+1 == cx->ei->bei_dkids ) {
818 cx->ei->bei_state |= CACHE_ENTRY_ONELEVEL;
820 mdb_cache_entryinfo_unlock( cx->ei );
822 cx->rc = cx->db->cursor( cx->db, NULL, &cx->dbc,
823 cx->mdb->bi_db_opflags );
827 cx->data.data = &cx->dbuf;
828 cx->data.ulen = sizeof(ID);
829 cx->data.dlen = sizeof(ID);
830 cx->data.flags = DB_DBT_USERMEM | DB_DBT_PARTIAL;
832 /* The first item holds the parent ID. Ignore it. */
833 cx->key.data = &cx->nid;
834 cx->key.size = sizeof(ID);
835 cx->rc = cx->dbc->c_get( cx->dbc, &cx->key, &cx->data, DB_SET );
837 cx->dbc->c_close( cx->dbc );
841 /* If the on-disk count is zero we've never checked it.
845 cx->dbc->c_count( cx->dbc, &dkids, 0 );
846 cx->ei->bei_dkids = dkids;
849 cx->data.data = cx->buf;
850 cx->data.ulen = MDB_IDL_UM_SIZE * sizeof(ID);
851 cx->data.flags = DB_DBT_USERMEM;
854 /* Fetch the rest of the IDs in a loop... */
855 while ( (cx->rc = cx->dbc->c_get( cx->dbc, &cx->key, &cx->data,
856 DB_MULTIPLE | DB_NEXT_DUP )) == 0 ) {
860 DB_MULTIPLE_INIT( ptr, &cx->data );
862 DB_MULTIPLE_NEXT( ptr, &cx->data, j, len );
865 diskNode *d = (diskNode *)j;
868 MDB_DISK2ID( j + len - sizeof(ID), &ei.bei_id );
869 nrlen = ((d->nrdnlen[0] ^ 0x80) << 8) | d->nrdnlen[1];
870 ei.bei_nrdn.bv_len = nrlen;
871 /* nrdn/rdn are set in-place.
872 * mdb_cache_load will copy them as needed
874 ei.bei_nrdn.bv_val = d->nrdn;
875 ei.bei_rdn.bv_len = len - sizeof(diskNode)
876 - ei.bei_nrdn.bv_len;
877 ei.bei_rdn.bv_val = d->nrdn + ei.bei_nrdn.bv_len + 1;
878 mdb_idl_append_one( cx->tmp, ei.bei_id );
879 mdb_cache_load( cx->mdb, &ei, &ei2 );
885 cx->rc = cx->dbc->c_close( cx->dbc );
887 mdb_cache_entryinfo_lock( cx->ei );
888 cx->ei->bei_state &= ~CACHE_ENTRY_ONELEVEL;
889 mdb_cache_entryinfo_unlock( cx->ei );
894 /* The in-memory cache is in sync with the on-disk data.
895 * do we have any kids?
899 if ( cx->ei->bei_ckids > 0 ) {
900 /* Walk the kids tree; order is irrelevant since mdb_idl_sort
901 * will sort it later.
903 avl_apply( cx->ei->bei_kids, apply_func,
904 cx->tmp, -1, AVL_POSTORDER );
906 mdb_cache_entryinfo_unlock( cx->ei );
909 if ( !MDB_IDL_IS_RANGE( cx->tmp ) && cx->tmp[0] > 3 )
910 mdb_idl_sort( cx->tmp, cx->buf );
911 if ( cx->mdb->bi_idl_cache_max_size && !MDB_IDL_IS_ZERO( cx->tmp )) {
912 char *ptr = ((char *)&cx->id)-1;
914 cx->key.size = sizeof(ID)+1;
915 *ptr = DN_ONE_PREFIX;
916 mdb_idl_cache_put( cx->mdb, cx->db, &cx->key, cx->tmp, cx->rc );
920 if ( !MDB_IDL_IS_ZERO( cx->tmp )) {
921 if ( cx->prefix == DN_SUBTREE_PREFIX ) {
922 mdb_idl_append( cx->ids, cx->tmp );
924 if ( !(cx->ei->bei_state & CACHE_ENTRY_NO_GRANDKIDS)) {
926 EntryInfo *ei = cx->ei;
928 save = cx->op->o_tmpalloc( MDB_IDL_SIZEOF( cx->tmp ),
929 cx->op->o_tmpmemctx );
930 MDB_IDL_CPY( save, cx->tmp );
934 for ( cx->id = mdb_idl_first( save, &idcurs );
936 cx->id = mdb_idl_next( save, &idcurs )) {
939 if ( mdb_cache_find_id( cx->op, cx->txn, cx->id, &cx->ei,
944 if ( !( ei2->bei_state & CACHE_ENTRY_NO_KIDS )) {
945 MDB_ID2DISK( cx->id, &cx->nid );
946 mdb_dn2idl_internal( cx );
947 if ( !MDB_IDL_IS_ZERO( cx->tmp ))
950 mdb_cache_entryinfo_lock( ei2 );
952 mdb_cache_entryinfo_unlock( ei2 );
956 cx->op->o_tmpfree( save, cx->op->o_tmpmemctx );
958 mdb_cache_entryinfo_lock( ei );
959 ei->bei_state |= CACHE_ENTRY_NO_GRANDKIDS;
960 mdb_cache_entryinfo_unlock( ei );
963 /* Make sure caller knows it had kids! */
968 MDB_IDL_CPY( cx->ids, cx->tmp );
983 struct mdb_info *mdb = (struct mdb_info *)op->o_bd->be_private;
984 struct dn2id_cookie cx;
986 Debug( LDAP_DEBUG_TRACE, "=> mdb_dn2idl(\"%s\")\n",
989 #ifndef MDB_MULTIPLE_SUFFIXES
990 if ( op->ors_scope != LDAP_SCOPE_ONELEVEL &&
992 ( ei->bei_parent->bei_id == 0 && op->o_bd->be_suffix[0].bv_len )))
994 MDB_IDL_ALL( mdb, ids );
1000 MDB_ID2DISK( cx.id, &cx.nid );
1003 cx.db = cx.mdb->bi_dn2id->bdi_db;
1004 cx.prefix = (op->ors_scope == LDAP_SCOPE_ONELEVEL) ?
1005 DN_ONE_PREFIX : DN_SUBTREE_PREFIX;
1008 cx.buf = stack + MDB_IDL_UM_SIZE;
1014 if ( cx.prefix == DN_SUBTREE_PREFIX ) {
1018 MDB_IDL_ZERO( ids );
1020 if ( cx.ei->bei_state & CACHE_ENTRY_NO_KIDS )
1021 return LDAP_SUCCESS;
1024 cx.key.ulen = sizeof(ID);
1025 cx.key.size = sizeof(ID);
1026 cx.key.flags = DB_DBT_USERMEM;
1030 mdb_dn2idl_internal(&cx);
1031 if ( cx.need_sort ) {
1032 char *ptr = ((char *)&cx.id)-1;
1033 if ( !MDB_IDL_IS_RANGE( cx.ids ) && cx.ids[0] > 3 )
1034 mdb_idl_sort( cx.ids, cx.tmp );
1036 cx.key.size = sizeof(ID)+1;
1039 if ( cx.mdb->bi_idl_cache_max_size )
1040 mdb_idl_cache_put( cx.mdb, cx.db, &cx.key, cx.ids, cx.rc );
1043 if ( cx.rc == DB_NOTFOUND )
1044 cx.rc = LDAP_SUCCESS;