* add the entry.
*/
- pdn.bv_val = dn_parent( be, e->e_ndn );
- if (pdn.bv_val && pdn.bv_val[0])
- pdn.bv_len = e->e_nname.bv_len - (pdn.bv_val - e->e_ndn);
- else
- pdn.bv_len = 0;
+ if ( be_issuffix( be, &e->e_nname ) ) {
+ pdn = slap_empty_bv;
+ } else {
+ rc = dnParent( &e->e_nname, &pdn );
+ /* dnParent always returns success */
+ }
if( pdn.bv_len ) {
Entry *matched = NULL;
/* no parent, must be adding entry to root */
if ( !be_isroot( be, &op->o_ndn ) ) {
- 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;
rc = access_allowed( be, conn, op, p,
}
/* delete from parent's id2children entry */
- if( (pdn.bv_val = dn_parent( be, e->e_ndn )) != NULL && pdn.bv_val[ 0 ] != '\0' ) {
- pdn.bv_len = e->e_nname.bv_len - (pdn.bv_val - e->e_ndn);
+ if( !be_issuffix( be, &e->e_nname ) && dnParent( &e->e_nname, &pdn ) == LDAP_SUCCESS
+ && pdn.bv_len ) {
if( (p = dn2entry_w( be, &pdn, NULL )) == NULL) {
#ifdef NEW_LOGGING
LDAP_LOG(( "backend", LDAP_LEVEL_ERR,
} else {
/* no parent, must be root to delete */
if( ! be_isroot( be, &op->o_ndn ) ) {
- 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;
rc = access_allowed( be, conn, op, p,
int rc, flags;
DBCache *db;
Datum key, data;
- char *buf, *ptr, *pdn;
+ char *buf;
+ struct berval ptr, pdn;
#ifdef NEW_LOGGING
LDAP_LOG(( "backend", LDAP_LEVEL_ENTRY,
buf = ch_malloc( key.dsize );
key.dptr = buf;
buf[0] = DN_BASE_PREFIX;
- ptr = buf + 1;
- strcpy( ptr, dn->bv_val );
+ ptr.bv_val = buf + 1;
+ ptr.bv_len = dn->bv_len;
+ strcpy( ptr.bv_val, dn->bv_val );
ldbm_datum_init( data );
data.dptr = (char *) &id;
flags = LDBM_INSERT;
rc = ldbm_cache_store( db, key, data, flags );
- if ( rc != -1 && !be_issuffix( be, ptr )) {
+ if ( rc != -1 && !be_issuffix( be, &ptr )) {
buf[0] = DN_SUBTREE_PREFIX;
ldap_pvt_thread_mutex_lock( &db->dbc_write_mutex );
rc = idl_insert_key( be, db, key, id );
ldap_pvt_thread_mutex_unlock( &db->dbc_write_mutex );
- }
-
- if ( rc != -1 ) {
- pdn = dn_parent( be, ptr );
- if( pdn != NULL ) {
- pdn[-1] = DN_ONE_PREFIX;
- key.dsize -= pdn - ptr;
- key.dptr = pdn - 1;
- ldap_pvt_thread_mutex_lock( &db->dbc_write_mutex );
- rc = idl_insert_key( be, db, key, id );
- ldap_pvt_thread_mutex_unlock( &db->dbc_write_mutex );
+ if ( rc != -1 ) {
+ rc = dnParent( &ptr, &pdn );
+
+ if( rc == LDAP_SUCCESS ) {
+ pdn.bv_val[-1] = DN_ONE_PREFIX;
+ key.dsize = pdn.bv_len + 2;
+ key.dptr = pdn.bv_val - 1;
+ ptr = pdn;
+ ldap_pvt_thread_mutex_lock( &db->dbc_write_mutex );
+ rc = idl_insert_key( be, db, key, id );
+ ldap_pvt_thread_mutex_unlock( &db->dbc_write_mutex );
+ }
}
}
- while ( rc != -1 && pdn != NULL ) {
- if ( be_issuffix( be, pdn ))
- break;
-
- pdn[-1] = DN_SUBTREE_PREFIX;
+ while ( rc != -1 && !be_issuffix( be, &ptr )) {
+ ptr.bv_val[-1] = DN_SUBTREE_PREFIX;
ldap_pvt_thread_mutex_lock( &db->dbc_write_mutex );
rc = idl_insert_key( be, db, key, id );
ldap_pvt_thread_mutex_unlock( &db->dbc_write_mutex );
if( rc != 0 ) break;
+ rc = dnParent( &ptr, &pdn );
+ key.dsize = pdn.bv_len + 2;
+ key.dptr = pdn.bv_val - 1;
ptr = pdn;
- pdn = dn_parent( be, pdn );
- key.dsize -= pdn - ptr;
- key.dptr = pdn - 1;
}
free( buf );
assert( idlp != NULL );
*idlp = NULL;
- if ( prefix == DN_SUBTREE_PREFIX && be_issuffix(be, dn->bv_val) ) {
+ if ( prefix == DN_SUBTREE_PREFIX && be_issuffix(be, dn) ) {
*idlp = idl_allids( be );
return 0;
}
DBCache *db;
Datum key;
int rc;
- char *buf, *ptr, *pdn;
+ char *buf;
+ struct berval ptr, pdn;
#ifdef NEW_LOGGING
LDAP_LOG(( "backend", LDAP_LEVEL_ENTRY,
buf = ch_malloc( key.dsize );
key.dptr = buf;
buf[0] = DN_BASE_PREFIX;
- ptr = buf + 1;
- strcpy( ptr, dn->bv_val );
+ ptr.bv_val = buf + 1;
+ ptr.bv_len = dn->bv_len;
+ strcpy( ptr.bv_val, dn->bv_val );
rc = ldbm_cache_delete( db, key );
- if( !be_issuffix( be, ptr )) {
+ if( !be_issuffix( be, &ptr )) {
buf[0] = DN_SUBTREE_PREFIX;
ldap_pvt_thread_mutex_lock( &db->dbc_write_mutex );
(void) idl_delete_key( be, db, key, id );
ldap_pvt_thread_mutex_unlock( &db->dbc_write_mutex );
- }
- pdn = dn_parent( be, ptr );
+ rc = dnParent( &ptr, &pdn );
- if( pdn != NULL ) {
- pdn[-1] = DN_ONE_PREFIX;
- key.dsize -= pdn - ptr;
- key.dptr = pdn - 1;
+ if( rc == LDAP_SUCCESS ) {
+ pdn.bv_val[-1] = DN_ONE_PREFIX;
+ key.dsize = pdn.bv_len + 2;
+ key.dptr = pdn.bv_val - 1;
+ ptr = pdn;
- ldap_pvt_thread_mutex_lock( &db->dbc_write_mutex );
- (void) idl_delete_key( be, db, key, id );
- ldap_pvt_thread_mutex_unlock( &db->dbc_write_mutex );
+ ldap_pvt_thread_mutex_lock( &db->dbc_write_mutex );
+ (void) idl_delete_key( be, db, key, id );
+ ldap_pvt_thread_mutex_unlock( &db->dbc_write_mutex );
+ }
}
- while ( pdn != NULL ) {
- if ( be_issuffix( be, pdn ))
- break;
-
- pdn[-1] = DN_SUBTREE_PREFIX;
+ while ( rc != -1 && !be_issuffix( be, &ptr )) {
+ ptr.bv_val[-1] = DN_SUBTREE_PREFIX;
ldap_pvt_thread_mutex_lock( &db->dbc_write_mutex );
(void) idl_delete_key( be, db, key, id );
ldap_pvt_thread_mutex_unlock( &db->dbc_write_mutex );
+ rc = dnParent( &ptr, &pdn );
+ key.dsize = pdn.bv_len + 2;
+ key.dptr = pdn.bv_val - 1;
ptr = pdn;
- pdn = dn_parent( be, pdn );
- key.dsize -= pdn - ptr;
- key.dptr = pdn - 1;
}
free( buf );
if( matched == NULL ) return NULL;
/* entry does not exist - see how much of the dn does exist */
- /* dn_parent checks returns NULL if dn is suffix */
- if ( (pdn.bv_val = dn_parent( be, dn->bv_val )) != NULL && *pdn.bv_val ) {
- pdn.bv_len = dn->bv_len - (pdn.bv_val - dn->bv_val);
+ if ( !be_issuffix( be, dn ) && dnParent( dn, &pdn ) == LDAP_SUCCESS
+ && pdn.bv_len ) {
/* get entry with reader lock */
if ( (e = dn2entry_r( be, &pdn, matched )) != NULL ) {
*matched = e;
goto return_results;
}
- p_ndn.bv_val = dn_parent( be, e->e_ndn );
- if ( p_ndn.bv_val )
- p_ndn.bv_len = e->e_nname.bv_len - (p_ndn.bv_val - e->e_ndn);
- else
- p_ndn.bv_len = 0;
+ if ( be_issuffix( be, &e->e_nname ) ) {
+ p_ndn = slap_empty_bv ;
+ } else {
+ dnParent( &e->e_nname, &p_ndn );
+ }
if ( p_ndn.bv_len != 0 ) {
/* Make sure parent entry exist and we can write its
p_ndn.bv_val, 0, 0 );
#endif
- p_dn.bv_val = dn_parent( be, e->e_dn );
- if ( p_dn.bv_val )
- p_dn.bv_len = e->e_name.bv_len - (p_dn.bv_val - e->e_dn);
- else
- p_dn.bv_len = 0;
+ if ( p_ndn.bv_val == slap_empty_bv.bv_val ) {
+ p_dn = slap_empty_bv;
+ } else {
+ dnParent( &e->e_name, &p_dn );
+ }
#ifdef NEW_LOGGING
LDAP_LOG(( "backend", LDAP_LEVEL_DETAIL1,
/* no parent, must be root to modify rdn */
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;
rc = access_allowed( be, conn, op, p,
}
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;
rc = access_allowed( be, conn, op, np,
/* need to skip alias which deref into scope */
if( scope & LDAP_SCOPE_ONELEVEL ) {
- char *pdn = dn_parent( NULL, e->e_ndn );
- if ( pdn != NULL ) {
- if( strcmp( pdn, realbase.bv_val ) ) {
- goto loop_continue;
- }
+ struct berval pdn;
+ dnParent( &e->e_nname, &pdn );
+ if ( ber_bvcmp( &pdn, &realbase ) ) {
+ goto loop_continue;
}
} else if ( dnIsSuffix( &e->e_nname, &realbase ) ) {
if ( !manageDSAit && scope != LDAP_SCOPE_BASE &&
is_entry_referral( e ) )
{
- char *dn;
+ struct berval dn;
/* check scope */
if ( !scopeok && scope == LDAP_SCOPE_ONELEVEL ) {
- if ( (dn = dn_parent( be, e->e_ndn )) != NULL ) {
- scopeok = (dn == realbase.bv_val)
- ? 1
- : (strcmp( dn, realbase.bv_val ) ? 0 : 1 );
+ if ( !be_issuffix( be, &e->e_nname ) ) {
+ dnParent( &e->e_nname, &dn );
+ scopeok = dn_match( &dn, &realbase );
} else {
scopeok = (realbase.bv_len == 0);
}
/* if it matches the filter and scope, send it */
if ( test_filter( be, conn, op, e, filter ) == LDAP_COMPARE_TRUE ) {
- char *dn;
+ struct berval dn;
/* check scope */
if ( !scopeok && scope == LDAP_SCOPE_ONELEVEL ) {
- if ( (dn = dn_parent( be, e->e_ndn )) != NULL ) {
- scopeok = (dn == realbase.bv_val)
- ? 1
- : (strcmp( dn, realbase.bv_val ) ? 0 : 1 );
+ if ( !be_issuffix( be, &e->e_nname ) ) {
+ dnParent( &e->e_nname, &dn );
+ scopeok = dn_match( &dn, &realbase );
} else {
scopeok = (realbase.bv_len == 0);
}
/* try with parent/ancestors */
if ( ndn->bv_len ) {
- p_ndn.bv_val = dn_parent( NULL, ndn->bv_val );
+ dnParent( ndn, &p_ndn );
}
if ( p_ndn.bv_val == NULL ) {
int err = LDAP_SUCCESS;
LDAPRDN *rdn = NULL;
- char *parent = NULL;
+ struct berval parent = { 0, NULL };
char *matched = NULL;
const char *text = NULL;
#endif /* HAVE_SETPWFILE */
/* Handle a query for the base of this backend */
- if ( be_issuffix( be, nbase->bv_val ) ) {
+ if ( be_issuffix( be, nbase ) ) {
struct berval vals[2];
vals[1].bv_val = NULL;
}
} else {
- parent = dn_parent( be, nbase->bv_val );
+ if (! be_issuffix( be, nbase ) ) {
+ dnParent( nbase, &parent );
+ }
/* This backend is only one layer deep. Don't answer requests for
* anything deeper than that.
*/
- if( !be_issuffix( be, parent ) ) {
+ if( !be_issuffix( be, &parent ) ) {
int i;
for( i=0; be->be_nsuffix[i] != NULL; i++ ) {
if( dnIsSuffix( nbase, be->be_nsuffix[i] ) ) {
}
if ( (pw = getpwnam( rdn[0][0]->la_value.bv_val )) == NULL ) {
- matched = parent;
+ matched = parent.bv_val;
err = LDAP_NO_SUCH_OBJECT;
goto done;
}