DB *db = bdb->bi_dn2id->bdi_db;
int rc;
DBT key, data;
- char *buf, *ptr, *pdn;
+ char *buf;
+ struct berval ptr, pdn;
Debug( LDAP_DEBUG_TRACE, "=> bdb_dn2id_add( \"%s\", 0x%08lx )\n",
e->e_ndn, (long) e->e_id, 0 );
buf = ch_malloc( key.size );
key.data = buf;
buf[0] = DN_BASE_PREFIX;
- ptr = buf + 1;
- AC_MEMCPY( ptr, e->e_ndn, key.size - 1 );
+ ptr.bv_val = buf + 1;
+ ptr.bv_len = e->e_nname.bv_len;
+ AC_MEMCPY( ptr.bv_val, e->e_nname.bv_val, e->e_nname.bv_len );
+ ptr.bv_val[ptr.bv_len] = '\0';
DBTzero( &data );
data.data = (char *) &e->e_id;
goto done;
}
- if( !be_issuffix( be, ptr )) {
+ if( !be_issuffix( be, &ptr )) {
buf[0] = DN_SUBTREE_PREFIX;
rc = bdb_idl_insert_key( be, db, txn, &key, e->e_id );
if( rc != 0 ) {
Debug( LDAP_DEBUG_ANY,
"=> bdb_dn2id_add: subtree (%s) insert failed: %d\n",
- ptr, rc, 0 );
+ ptr.bv_val, rc, 0 );
goto done;
}
- rc = dnParent( ptr, (const char **)&pdn );
+ rc = dnParent( &ptr, &pdn );
if ( rc != LDAP_SUCCESS ) {
Debug( LDAP_DEBUG_ANY,
"=> bdb_dn2id_add: dnParent(\"%s\") failed\n",
- ptr, 0, 0 );
+ ptr.bv_val, 0, 0 );
goto done;
}
- key.size -= pdn - ptr;
- pdn[-1] = DN_ONE_PREFIX;
- key.data = pdn - 1;
+ key.size = pdn.bv_len + 2;
+ pdn.bv_val[-1] = DN_ONE_PREFIX;
+ key.data = pdn.bv_val-1;
ptr = pdn;
rc = bdb_idl_insert_key( be, db, txn, &key, e->e_id );
if( rc != 0 ) {
Debug( LDAP_DEBUG_ANY,
"=> bdb_dn2id_add: parent (%s) insert failed: %d\n",
- ptr, rc, 0 );
+ ptr.bv_val, rc, 0 );
goto done;
}
}
- while( !be_issuffix( be, ptr )) {
- ptr[-1] = DN_SUBTREE_PREFIX;
+ while( !be_issuffix( be, &ptr )) {
+ ptr.bv_val[-1] = DN_SUBTREE_PREFIX;
rc = bdb_idl_insert_key( be, db, txn, &key, e->e_id );
if( rc != 0 ) {
Debug( LDAP_DEBUG_ANY,
"=> bdb_dn2id_add: subtree (%s) insert failed: %d\n",
- ptr, rc, 0 );
+ ptr.bv_val, rc, 0 );
break;
}
- rc = dnParent( ptr, &pdn );
+ rc = dnParent( &ptr, &pdn );
if ( rc != LDAP_SUCCESS ) {
Debug( LDAP_DEBUG_ANY,
"=> bdb_dn2id_add: dnParent(\"%s\") failed\n",
- ptr, 0, 0 );
+ ptr.bv_val, 0, 0 );
goto done;
}
- key.size -= pdn - ptr;
- key.data = pdn - 1;
+ key.size = pdn.bv_len + 2;
+ key.data = pdn.bv_val - 1;
ptr = pdn;
}
bdb_dn2id_delete(
BackendDB *be,
DB_TXN *txn,
- char *pdn,
+ char *pdnc,
Entry *e )
{
struct bdb_info *bdb = (struct bdb_info *) be->be_private;
DB *db = bdb->bi_dn2id->bdi_db;
int rc;
DBT key;
- char *buf, *ptr;
+ char *buf;
+ struct berval pdn, ptr;
Debug( LDAP_DEBUG_TRACE, "=> bdb_dn2id_delete( \"%s\", 0x%08lx )\n",
e->e_ndn, e->e_id, 0 );
key.data = buf;
key.flags = DB_DBT_USERMEM;
buf[0] = DN_BASE_PREFIX;
- ptr = buf+1;
- AC_MEMCPY( ptr, e->e_ndn, key.size - 1 );
+ ptr.bv_val = buf+1;
+ ptr.bv_len = e->e_nname.bv_len;
+ AC_MEMCPY( ptr.bv_val, e->e_nname.bv_val, e->e_nname.bv_len );
+ ptr.bv_val[ptr.bv_len] = '\0';
/* delete it */
rc = db->del( db, txn, &key, 0 );
goto done;
}
- if( !be_issuffix( be, ptr )) {
+ if( !be_issuffix( be, &ptr )) {
buf[0] = DN_SUBTREE_PREFIX;
rc = bdb_idl_delete_key( be, db, txn, &key, e->e_id );
if( rc != 0 ) {
Debug( LDAP_DEBUG_ANY,
"=> bdb_dn2id_delete: subtree (%s) delete failed: %d\n",
- ptr, rc, 0 );
+ ptr.bv_val, rc, 0 );
goto done;
}
- rc = dnParent( ptr, &pdn );
+ rc = dnParent( &ptr, &pdn );
if ( rc != LDAP_SUCCESS ) {
Debug( LDAP_DEBUG_ANY,
"=> bdb_dn2id_delete: dnParent(\"%s\") failed\n",
- ptr, 0, 0 );
+ ptr.bv_val, 0, 0 );
goto done;
}
- key.size -= pdn - ptr;
- pdn[-1] = DN_ONE_PREFIX;
- key.data = pdn - 1;
+ key.size = pdn.bv_len + 2;
+ pdn.bv_val[-1] = DN_ONE_PREFIX;
+ key.data = pdn.bv_val - 1;
ptr = pdn;
rc = bdb_idl_delete_key( be, db, txn, &key, e->e_id );
if( rc != 0 ) {
Debug( LDAP_DEBUG_ANY,
"=> bdb_dn2id_delete: parent (%s) delete failed: %d\n",
- ptr, rc, 0 );
+ ptr.bv_val, rc, 0 );
goto done;
}
}
- while( !be_issuffix( be, ptr )) {
- ptr[-1] = DN_SUBTREE_PREFIX;
+ while( !be_issuffix( be, &ptr )) {
+ ptr.bv_val[-1] = DN_SUBTREE_PREFIX;
rc = bdb_idl_delete_key( be, db, txn, &key, e->e_id );
if( rc != 0 ) {
Debug( LDAP_DEBUG_ANY,
"=> bdb_dn2id_delete: subtree (%s) delete failed: %d\n",
- ptr, rc, 0 );
+ ptr.bv_val, rc, 0 );
goto done;
}
- rc = dnParent( ptr, &pdn );
+ rc = dnParent( &ptr, &pdn );
if ( rc != LDAP_SUCCESS ) {
Debug( LDAP_DEBUG_ANY,
"=> bdb_dn2id_delete: dnParent(\"%s\") failed\n",
- ptr, 0, 0 );
+ ptr.bv_val, 0, 0 );
goto done;
}
- key.size -= pdn - ptr;
- key.data = pdn - 1;
+ key.size = pdn.bv_len + 2;
+ key.data = pdn.bv_val - 1;
ptr = pdn;
}
}
if( rc == DB_NOTFOUND ) {
- char *pdn = NULL;
+ struct berval pdn;
- if ( ! be_issuffix( be, dn.bv_val ) ) {
- rc = dnParent( dn.bv_val, &pdn );
+ if ( ! be_issuffix( be, &dn ) ) {
+ rc = dnParent( &dn, &pdn );
if ( rc != LDAP_SUCCESS ) {
Debug( LDAP_DEBUG_TRACE,
"<= bdb_dn2id_matched: dnParent(\"%s\") failed\n",
- dn, 0, 0 );
+ dn.bv_val, 0, 0 );
break;
}
- }
-
- if( pdn == NULL || *pdn == '\0' ) {
+ } else {
Debug( LDAP_DEBUG_TRACE,
"<= bdb_dn2id_matched: no match\n",
0, 0, 0 );
break;
}
- key.size -= pdn - dn.bv_val;
- dn.bv_val = pdn;
- dn.bv_len = key.size - 2;
- key.data = pdn - 1;
+ key.size = pdn.bv_len + 2;
+ dn = pdn;
+ key.data = pdn.bv_val - 1;
} else if ( rc == 0 ) {
if( data.size != sizeof( ID ) ) {
Debug( LDAP_DEBUG_TRACE, "=> bdb_dn2idl( \"%s\" )\n", dn->bv_val, 0, 0 );
- if (prefix == DN_SUBTREE_PREFIX && be_issuffix(be, dn->bv_val))
+ if (prefix == DN_SUBTREE_PREFIX && be_issuffix(be, dn))
{
BDB_IDL_ALL(bdb, ids);
return 0;
return DB_NOTFOUND;
p = bdb->bi_troot;
- if (be_issuffix(be, in->bv_val)) {
+ if (be_issuffix(be, in)) {
*id = p->i_id;
return 0;
}
ID id;
idNode *n;
- if (prefix == DN_SUBTREE_PREFIX && be_issuffix(be, dn->bv_val)) {
+ if (prefix == DN_SUBTREE_PREFIX && be_issuffix(be, dn)) {
BDB_IDL_ALL(bdb, ids);
return 0;
}
goto done;
}
- if ( be_issuffix( be, e->e_nname.bv_val ) ) {
- p_ndn.bv_len = 0;
- p_ndn.bv_val = "";
+ if ( be_issuffix( be, &e->e_nname ) ) {
+ p_ndn = slap_empty_bv;
} else {
- rc = dnParent( e->e_nname.bv_val, (const char **)&p_ndn.bv_val );
+ rc = dnParent( &e->e_nname, &p_ndn );
if ( rc != LDAP_SUCCESS ) {
text = "internal error";
goto return_results;
}
- p_ndn.bv_len = e->e_nname.bv_len - (p_ndn.bv_val - e->e_nname.bv_val);
}
np_ndn = &p_ndn;
if ( p_ndn.bv_len != 0 ) {
"bdb_modrdn: wr to children of entry %s OK\n",
p_ndn.bv_val, 0, 0 );
- if ( be_issuffix( be, e->e_name.bv_val ) ) {
- p_dn.bv_len = 0;
- p_dn.bv_val = "";
+ if ( p_ndn.bv_val == slap_empty_bv.bv_val ) {
+ p_dn = slap_empty_bv;
} else {
- rc = dnParent( e->e_name.bv_val, &p_dn.bv_val );
+ rc = dnParent( &e->e_name, &p_dn );
if ( rc != LDAP_SUCCESS ) {
text = "internal error";
goto return_results;
}
- p_dn.bv_len = e->e_name.bv_len - (p_dn.bv_val - e->e_name.bv_val);
}
Debug( LDAP_DEBUG_TRACE,
/* no parent, modrdn entry directly under root */
isroot = be_isroot( be, &op->o_ndn );
if ( ! isroot ) {
- if ( be_issuffix( be, "" ) || be_isupdate( be, &op->o_ndn ) ) {
+ if ( be_issuffix( be, (struct berval *)&slap_empty_bv )
+ || be_isupdate( be, &op->o_ndn ) ) {
p = (Entry *)&slap_entry_root;
/* no parent, modrdn entry directly under root */
if ( ! isroot ) {
- if ( be_issuffix( be, "" ) || be_isupdate( be, &op->o_ndn ) ) {
+ if ( be_issuffix( be, (struct berval *)&slap_empty_bv )
+ || be_isupdate( be, &op->o_ndn ) ) {
np = (Entry *)&slap_entry_root;
/* check parent for "children" acl */
/* need to skip alias which deref into scope */
if( scope & LDAP_SCOPE_ONELEVEL ) {
- char *pdn;
- ber_len_t plen;
+ struct berval pdn;
- if ( dnParent( e->e_nname.bv_val, &pdn ) == LDAP_SUCCESS ) {
- plen = e->e_nname.bv_len - ( pdn - e->e_nname.bv_val );
- if ( plen != realbase.bv_len || strcmp( pdn, realbase.bv_val ) ) {
+ if ( dnParent( &e->e_nname, &pdn ) == LDAP_SUCCESS ) {
+ if ( ber_bvcmp( pdn, &realbase ) ) {
goto loop_continue;
}
}
/* if it matches the filter and scope, send it */
rc = test_filter( be, conn, op, e, filter );
if ( rc == LDAP_COMPARE_TRUE ) {
- char *dn;
+ struct berval dn;
/* check scope */
if ( !scopeok && scope == LDAP_SCOPE_ONELEVEL ) {
- if ( be_issuffix( be, e->e_nname.bv_val ) ) {
+ if ( be_issuffix( be, &e->e_nname ) ) {
scopeok = (realbase.bv_len == 0);
} else {
- dnParent( e->e_nname.bv_val, (const char **)&dn );
- scopeok = (dn == realbase.bv_val)
- ? 1
- : (strcmp( dn, realbase.bv_val ) ? 0 : 1 );
+ dnParent( &e->e_nname, &dn );
+ scopeok = dn_match( &dn, &realbase );
}
} else if ( !scopeok && scope == LDAP_SCOPE_SUBTREE ) {
}
/* add dn2id indices */
- if ( be_issuffix( be, e->e_nname.bv_val ) ) {
- pdn.bv_len = 0;
- pdn.bv_val = "";
+ if ( be_issuffix( be, &e->e_nname ) ) {
+ pdn = slap_empty_bv;
} else {
- rc = dnParent( e->e_nname.bv_val, &pdn.bv_val );
+ rc = dnParent( &e->e_nname, &pdn );
if ( rc != LDAP_SUCCESS ) {
Debug( LDAP_DEBUG_ANY, "=> bdb_tool_entry_put: "
"dnParent(\"%s\") failed\n",
goto done;
}
- pdn.bv_len = e->e_nname.bv_len - (pdn.bv_val - e->e_nname.bv_val);
}
rc = bdb_dn2id_add( be, tid, &pdn, e );
if( rc != 0 ) {
(long) id, e->e_dn, 0 );
/* add dn2id indices */
- if ( be_issuffix( be, e->e_nname.bv_val ) ) {
- pdn.bv_len = 0;
- pdn.bv_val = "";
+ if ( be_issuffix( be, &e->e_nname ) ) {
+ pdn = slap_empty_bv;
} else {
- rc = dnParent( e->e_nname.bv_val, &pdn.bv_val );
+ rc = dnParent( &e->e_nname, &pdn );
if ( rc != LDAP_SUCCESS ) {
Debug( LDAP_DEBUG_ANY, "=> bdb_tool_entry_reindex: "
"dnParent(\"%s\") failed\n",
e->e_nname.bv_val, 0, 0 );
goto done;
}
- pdn.bv_len = e->e_nname.bv_len - (pdn.bv_val - e->e_nname.bv_val);
}
rc = bdb_dn2id_add( be, tid, &pdn, e );
if( rc != 0 && rc != DB_KEYEXIST ) {