op->o_private = &opinfo;
/* get entry for read/modify/write */
- rc = bdb_dn2entry( be, ltid, ndn->bv_val, &e, &matched, DB_RMW );
+ rc = bdb_dn2entry( be, ltid, ndn, &e, &matched, DB_RMW );
switch( rc ) {
case 0:
pdn = dn_parent( be, ndn->bv_val );
if( pdn != NULL && *pdn != '\0' ) {
+ struct berval pbv;
+
+ pbv.bv_len = ndn->bv_len - (pdn - ndn->bv_val);
+ pbv.bv_val = pdn;
/* get parent */
- rc = bdb_dn2entry( be, ltid, pdn, &p, NULL, 0 );
+ rc = bdb_dn2entry( be, ltid, &pbv, &p, NULL, 0 );
switch( rc ) {
case 0:
goto done;
}
- rc = bdb_dn2id_children( be, ltid, e->e_ndn );
+ rc = bdb_dn2id_children( be, ltid, &e->e_nname );
if( rc != DB_NOTFOUND ) {
switch( rc ) {
case DB_LOCK_DEADLOCK:
bdb_dn2id(
BackendDB *be,
DB_TXN *txn,
- const char *dn,
+ struct berval *dn,
ID *id )
{
int rc;
struct bdb_info *bdb = (struct bdb_info *) be->be_private;
DB *db = bdb->bi_dn2id->bdi_db;
- Debug( LDAP_DEBUG_TRACE, "=> bdb_dn2id( \"%s\" )\n", dn, 0, 0 );
+ Debug( LDAP_DEBUG_TRACE, "=> bdb_dn2id( \"%s\" )\n", dn->bv_val, 0, 0 );
DBTzero( &key );
- key.size = strlen( dn ) + 2;
+ key.size = dn->bv_len + 2;
key.data = ch_malloc( key.size );
((char *)key.data)[0] = DN_BASE_PREFIX;
- AC_MEMCPY( &((char *)key.data)[1], dn, key.size - 1 );
+ AC_MEMCPY( &((char *)key.data)[1], dn->bv_val, key.size - 1 );
/* store the ID */
DBTzero( &data );
bdb_dn2id_matched(
BackendDB *be,
DB_TXN *txn,
- const char *in,
+ struct berval *in,
ID *id,
char **matchedDN )
{
DBT key, data;
struct bdb_info *bdb = (struct bdb_info *) be->be_private;
DB *db = bdb->bi_dn2id->bdi_db;
- const char *dn = in;
+ char *buf, *dn;
- Debug( LDAP_DEBUG_TRACE, "=> bdb_dn2id_matched( \"%s\" )\n", dn, 0, 0 );
+ Debug( LDAP_DEBUG_TRACE, "=> bdb_dn2id_matched( \"%s\" )\n", in->bv_val, 0, 0 );
DBTzero( &key );
- key.size = strlen( dn ) + 2;
- key.data = ch_malloc( key.size );
- ((char *)key.data)[0] = DN_BASE_PREFIX;
+ key.size = in->bv_len + 2;
+ buf = ch_malloc( key.size );
+ key.data = buf;
+ dn = buf+1;
+ AC_MEMCPY( dn, in->bv_val, key.size - 1 );
/* store the ID */
DBTzero( &data );
*matchedDN = NULL;
while(1) {
- AC_MEMCPY( &((char *)key.data)[1], dn, key.size - 1 );
+ dn[-1] = DN_BASE_PREFIX;
*id = NOID;
break;
}
+ key.size -= pdn - dn;
dn = pdn;
- key.size = strlen( dn ) + 2;
+ key.data = pdn - 1;
} else if ( rc == 0 ) {
if( data.size != sizeof( ID ) ) {
(long) sizeof(ID), (long) data.size, 0 );
}
- if( in != dn ) {
+ if( dn != buf+1 ) {
*matchedDN = (char *) dn;
}
}
}
- ch_free( key.data );
+ ch_free( buf );
return rc;
}
bdb_dn2id_children(
BackendDB *be,
DB_TXN *txn,
- const char *dn )
+ struct berval *dn )
{
int rc;
DBT key, data;
ID id;
Debug( LDAP_DEBUG_TRACE, "=> bdb_dn2id_children( %s )\n",
- dn, 0, 0 );
+ dn->bv_val, 0, 0 );
DBTzero( &key );
- key.size = strlen( dn ) + 2;
+ key.size = dn->bv_len + 2;
key.data = ch_malloc( key.size );
((char *)key.data)[0] = DN_ONE_PREFIX;
- AC_MEMCPY( &((char *)key.data)[1], dn, key.size - 1 );
+ AC_MEMCPY( &((char *)key.data)[1], dn->bv_val, key.size - 1 );
/* we actually could do a empty get... */
DBTzero( &data );
int
bdb_dn2idl(
BackendDB *be,
- const char *dn,
+ struct berval *dn,
int prefix,
ID *ids )
{
struct bdb_info *bdb = (struct bdb_info *) be->be_private;
DB *db = bdb->bi_dn2id->bdi_db;
- Debug( LDAP_DEBUG_TRACE, "=> bdb_dn2idl( \"%s\" )\n", dn, 0, 0 );
+ Debug( LDAP_DEBUG_TRACE, "=> bdb_dn2idl( \"%s\" )\n", dn->bv_val, 0, 0 );
- if (prefix == DN_SUBTREE_PREFIX && be_issuffix(be, dn))
+ if (prefix == DN_SUBTREE_PREFIX && be_issuffix(be, dn->bv_val))
{
BDB_IDL_ALL(bdb, ids);
return 0;
}
DBTzero( &key );
- key.size = strlen( dn ) + 2;
+ key.size = dn->bv_len + 2;
key.data = ch_malloc( key.size );
((char *)key.data)[0] = prefix;
- AC_MEMCPY( &((char *)key.data)[1], dn, key.size - 1 );
+ AC_MEMCPY( &((char *)key.data)[1], dn->bv_val, key.size - 1 );
rc = bdb_idl_fetch_key( be, db, NULL, &key, ids );
* Note that this code always uses be_suffix[0], so defining
* multiple suffixes for a single backend won't work!
*/
- bdb->bi_sufflen = be->be_suffix[0]->bv_len;
-
rdns = ldap_explode_dn(be->be_nsuffix[0]->bv_val, 0);
for (i=0; rdns[i]; i++);
bdb->bi_nrdns = i;
ldap_pvt_thread_rdwr_rlock(&bdb->bi_tree_rdwr);
o = bdb_find_id_node(id, bdb->bi_tree);
- rlen = bdb->bi_sufflen + 1;
+ rlen = be->be_suffix[0]->bv_len + 1;
nrlen = be->be_nsuffix[0]->bv_len + 1;
for (n = o; n; n=n->i_parent) {
rlen += n->i_rdn->rdn.bv_len + 1;
nrlen += n->i_rdn->nrdn.bv_len + 1;
}
- e->e_dn = ch_malloc(rlen + nrlen);
- e->e_ndn = e->e_dn + rlen;
- ptr = e->e_dn;
- nptr = e->e_ndn;
+ e->e_name.bv_len = rlen - 1;
+ e->e_nname.bv_len = nrlen - 1;
+ e->e_name.bv_val = ch_malloc(rlen + nrlen);
+ e->e_nname.bv_val = e->e_name.bv_val + rlen;
+ ptr = e->e_name.bv_val;
+ nptr = e->e_nname.bv_val;
for (n = o; n; n=n->i_parent) {
ptr = slap_strcopy(ptr, n->i_rdn->rdn.bv_val);
*ptr++ = ',';
bdb_dn2id_matched(
BackendDB *be,
DB_TXN *txn,
- const char *in,
+ struct berval *in,
ID *id,
char **matchedDN )
{
return DB_NOTFOUND;
p = bdb->bi_troot;
- if (be_issuffix(be, in)) {
+ if (be_issuffix(be, in->bv_val)) {
*id = p->i_id;
return 0;
}
- rdns = ldap_explode_dn(in, 0);
+ rdns = ldap_explode_dn(in->bv_val, 0);
for (i=0; rdns[i]; i++);
i -= bdb->bi_nrdns;
if (i < 0)
bdb_dn2id(
BackendDB *be,
DB_TXN *txn,
- const char *dn,
+ struct berval *dn,
ID *id )
{
return bdb_dn2id_matched(be, txn, dn, id, NULL);
bdb_dn2id_children(
BackendDB *be,
DB_TXN *txn,
- const char *dn )
+ struct berval *dn )
{
int rc;
struct bdb_info *bdb = (struct bdb_info *) be->be_private;
int
bdb_dn2idl(
BackendDB *be,
- const char *dn,
+ struct berval *dn,
int prefix,
ID *ids )
{
ID id;
idNode *n;
- if (prefix == DN_SUBTREE_PREFIX && be_issuffix(be, dn)) {
+ if (prefix == DN_SUBTREE_PREFIX && be_issuffix(be, dn->bv_val)) {
BDB_IDL_ALL(bdb, ids);
return 0;
}