ID mdb_tool_dn2id_get( Backend *be, struct berval *dn ) { struct mdb_info *mdb; Operation op = {0}; Opheader ohdr = {0}; ID id; int rc; if ( BER_BVISEMPTY(dn) ) return 0; mdb = (struct mdb_info *) be->be_private; if ( !txn ) { rc = mdb_txn_begin( mdb->mi_dbenv, NULL, (slapMode & SLAP_TOOL_READONLY) != 0 ? MDB_RDONLY : 0, &txn ); if ( rc ) return NOID; } op.o_hdr = &ohdr; op.o_bd = be; op.o_tmpmemctx = NULL; op.o_tmpmfuncs = &ch_mfuncs; rc = mdb_dn2id( &op, txn, NULL, dn, &id, NULL, NULL ); if ( rc == MDB_NOTFOUND ) return NOID; return id; }
int mdb_dn2entry( Operation *op, MDB_txn *tid, MDB_cursor *m2, struct berval *dn, Entry **e, ID *nsubs, int matched ) { struct mdb_info *mdb = (struct mdb_info *) op->o_bd->be_private; int rc, rc2; ID id = NOID; struct berval mbv, nmbv; MDB_cursor *mc; Debug(LDAP_DEBUG_TRACE, "mdb_dn2entry(\"%s\")\n", dn->bv_val ? dn->bv_val : "", 0, 0 ); *e = NULL; rc = mdb_dn2id( op, tid, m2, dn, &id, nsubs, &mbv, &nmbv ); if ( rc ) { if ( matched ) { rc2 = mdb_cursor_open( tid, mdb->mi_id2entry, &mc ); if ( rc2 == MDB_SUCCESS ) { rc2 = mdb_id2entry( op, mc, id, e ); mdb_cursor_close( mc ); } } } else { rc = mdb_cursor_open( tid, mdb->mi_id2entry, &mc ); if ( rc == MDB_SUCCESS ) { rc = mdb_id2entry( op, mc, id, e ); mdb_cursor_close(mc); } } if ( *e ) { (*e)->e_name = mbv; if ( rc == MDB_SUCCESS ) ber_dupbv_x( &(*e)->e_nname, dn, op->o_tmpmemctx ); else ber_dupbv_x( &(*e)->e_nname, &nmbv, op->o_tmpmemctx ); } else { op->o_tmpfree( mbv.bv_val, op->o_tmpmemctx ); } return rc; }
static int equality_candidates( Operation *op, MDB_txn *rtxn, AttributeAssertion *ava, ID *ids, ID *tmp ) { MDB_dbi dbi; int i; int rc; slap_mask_t mask; struct berval prefix = {0, NULL}; struct berval *keys = NULL; MatchingRule *mr; Debug( LDAP_DEBUG_TRACE, "=> mdb_equality_candidates (%s)\n", ava->aa_desc->ad_cname.bv_val, 0, 0 ); if ( ava->aa_desc == slap_schema.si_ad_entryDN ) { ID id; rc = mdb_dn2id( op, rtxn, NULL, &ava->aa_value, &id, NULL, NULL, NULL ); if ( rc == LDAP_SUCCESS ) { /* exactly one ID can match */ ids[0] = 1; ids[1] = id; } if ( rc == MDB_NOTFOUND ) { MDB_IDL_ZERO( ids ); rc = 0; } return rc; } MDB_IDL_ALL( ids ); rc = mdb_index_param( op->o_bd, ava->aa_desc, LDAP_FILTER_EQUALITY, &dbi, &mask, &prefix ); if ( rc == LDAP_INAPPROPRIATE_MATCHING ) { Debug( LDAP_DEBUG_ANY, "<= mdb_equality_candidates: (%s) not indexed\n", ava->aa_desc->ad_cname.bv_val, 0, 0 ); return 0; } if( rc != LDAP_SUCCESS ) { Debug( LDAP_DEBUG_ANY, "<= mdb_equality_candidates: (%s) " "index_param failed (%d)\n", ava->aa_desc->ad_cname.bv_val, rc, 0 ); return 0; } mr = ava->aa_desc->ad_type->sat_equality; if( !mr ) { return 0; } if( !mr->smr_filter ) { return 0; } rc = (mr->smr_filter)( LDAP_FILTER_EQUALITY, mask, ava->aa_desc->ad_type->sat_syntax, mr, &prefix, &ava->aa_value, &keys, op->o_tmpmemctx ); if( rc != LDAP_SUCCESS ) { Debug( LDAP_DEBUG_TRACE, "<= mdb_equality_candidates: (%s, %s) " "MR filter failed (%d)\n", prefix.bv_val, ava->aa_desc->ad_cname.bv_val, rc ); return 0; } if( keys == NULL ) { Debug( LDAP_DEBUG_TRACE, "<= mdb_equality_candidates: (%s) no keys\n", ava->aa_desc->ad_cname.bv_val, 0, 0 ); return 0; } for ( i= 0; keys[i].bv_val != NULL; i++ ) { rc = mdb_key_read( op->o_bd, rtxn, dbi, &keys[i], tmp, NULL, 0 ); if( rc == MDB_NOTFOUND ) { MDB_IDL_ZERO( ids ); rc = 0; break; } else if( rc != LDAP_SUCCESS ) { Debug( LDAP_DEBUG_TRACE, "<= mdb_equality_candidates: (%s) " "key read failed (%d)\n", ava->aa_desc->ad_cname.bv_val, rc, 0 ); break; } if( MDB_IDL_IS_ZERO( tmp ) ) { Debug( LDAP_DEBUG_TRACE, "<= mdb_equality_candidates: (%s) NULL\n", ava->aa_desc->ad_cname.bv_val, 0, 0 ); MDB_IDL_ZERO( ids ); break; } if ( i == 0 ) { MDB_IDL_CPY( ids, tmp ); } else { mdb_idl_intersection( ids, tmp ); } if( MDB_IDL_IS_ZERO( ids ) ) break; } ber_bvarray_free_x( keys, op->o_tmpmemctx ); Debug( LDAP_DEBUG_TRACE, "<= mdb_equality_candidates: id=%ld, first=%ld, last=%ld\n", (long) ids[0], (long) MDB_IDL_FIRST(ids), (long) MDB_IDL_LAST(ids) ); return( rc ); }
static int ext_candidates( Operation *op, MDB_txn *rtxn, MatchingRuleAssertion *mra, ID *ids, ID *tmp, ID *stack) { #ifdef LDAP_COMP_MATCH /* * Currently Only Component Indexing for componentFilterMatch is supported * Indexing for an extensible filter is not supported yet */ if ( mra->ma_cf ) { return comp_candidates ( op, rtxn, mra, mra->ma_cf, ids, tmp, stack); } #endif if ( mra->ma_desc == slap_schema.si_ad_entryDN ) { int rc; ID id; MDB_IDL_ZERO( ids ); if ( mra->ma_rule == slap_schema.si_mr_distinguishedNameMatch ) { base: rc = mdb_dn2id( op, rtxn, NULL, &mra->ma_value, &id, NULL, NULL, NULL ); if ( rc == MDB_SUCCESS ) { mdb_idl_insert( ids, id ); } return 0; } else if ( mra->ma_rule && mra->ma_rule->smr_match == dnRelativeMatch && dnIsSuffix( &mra->ma_value, op->o_bd->be_nsuffix )) { int scope; if ( mra->ma_rule == slap_schema.si_mr_dnSuperiorMatch ) { mdb_dn2sups( op, rtxn, &mra->ma_value, ids ); return 0; } if ( mra->ma_rule == slap_schema.si_mr_dnSubtreeMatch ) scope = LDAP_SCOPE_SUBTREE; else if ( mra->ma_rule == slap_schema.si_mr_dnOneLevelMatch ) scope = LDAP_SCOPE_ONELEVEL; else if ( mra->ma_rule == slap_schema.si_mr_dnSubordinateMatch ) scope = LDAP_SCOPE_SUBORDINATE; else goto base; /* scope = LDAP_SCOPE_BASE; */ #if 0 if ( scope > LDAP_SCOPE_BASE ) { ei = NULL; rc = mdb_cache_find_ndn( op, rtxn, &mra->ma_value, &ei ); if ( ei ) mdb_cache_entryinfo_unlock( ei ); if ( rc == LDAP_SUCCESS ) { int sc = op->ors_scope; op->ors_scope = scope; rc = mdb_dn2idl( op, rtxn, &mra->ma_value, ei, ids, stack ); op->ors_scope = sc; } return 0; } #endif } } MDB_IDL_ALL( ids ); return 0; }
static int mdb_tool_next_id( Operation *op, MDB_txn *tid, Entry *e, struct berval *text, int hole ) { struct mdb_info *mdb = (struct mdb_info *) op->o_bd->be_private; struct berval dn = e->e_name; struct berval ndn = e->e_nname; struct berval pdn, npdn, nmatched; ID id, pid = 0; int rc; if (ndn.bv_len == 0) { e->e_id = 0; return 0; } rc = mdb_dn2id( op, tid, mcp, &ndn, &id, NULL, &nmatched ); if ( rc == MDB_NOTFOUND ) { if ( !be_issuffix( op->o_bd, &ndn ) ) { ID eid = e->e_id; dnParent( &ndn, &npdn ); if ( nmatched.bv_len != npdn.bv_len ) { dnParent( &dn, &pdn ); e->e_name = pdn; e->e_nname = npdn; rc = mdb_tool_next_id( op, tid, e, text, 1 ); e->e_name = dn; e->e_nname = ndn; if ( rc ) { return rc; } /* If parent didn't exist, it was created just now * and its ID is now in e->e_id. Make sure the current * entry gets added under the new parent ID. */ if ( eid != e->e_id ) { pid = e->e_id; } } else { pid = id; } } rc = mdb_next_id( op->o_bd, idcursor, &e->e_id ); if ( rc ) { snprintf( text->bv_val, text->bv_len, "next_id failed: %s (%d)", mdb_strerror(rc), rc ); Debug( LDAP_DEBUG_ANY, "=> mdb_tool_next_id: %s\n", text->bv_val, 0, 0 ); return rc; } rc = mdb_dn2id_add( op, mcp, mcd, pid, e ); if ( rc ) { snprintf( text->bv_val, text->bv_len, "dn2id_add failed: %s (%d)", mdb_strerror(rc), rc ); Debug( LDAP_DEBUG_ANY, "=> mdb_tool_next_id: %s\n", text->bv_val, 0, 0 ); } else if ( hole ) { MDB_val key, data; if ( nholes == nhmax - 1 ) { if ( holes == hbuf ) { holes = ch_malloc( nhmax * sizeof(dn_id) * 2 ); AC_MEMCPY( holes, hbuf, sizeof(hbuf) ); } else { holes = ch_realloc( holes, nhmax * sizeof(dn_id) * 2 ); } nhmax *= 2; } ber_dupbv( &holes[nholes].dn, &ndn ); holes[nholes++].id = e->e_id; key.mv_size = sizeof(ID); key.mv_data = &e->e_id; data.mv_size = 0; data.mv_data = NULL; rc = mdb_cursor_put( idcursor, &key, &data, MDB_NOOVERWRITE ); if ( rc == MDB_KEYEXIST ) rc = 0; if ( rc ) { snprintf( text->bv_val, text->bv_len, "dummy id2entry add failed: %s (%d)", mdb_strerror(rc), rc ); Debug( LDAP_DEBUG_ANY, "=> mdb_tool_next_id: %s\n", text->bv_val, 0, 0 ); } } } else if ( !hole ) { unsigned i, j; e->e_id = id; for ( i=0; i<nholes; i++) { if ( holes[i].id == e->e_id ) { free(holes[i].dn.bv_val); for (j=i;j<nholes;j++) holes[j] = holes[j+1]; holes[j].id = 0; nholes--; break; } else if ( holes[i].id > e->e_id ) { break; } } } return rc; }