Entry *e )
{
struct bdb_info *bdb = (struct bdb_info *) be->be_private;
- char *pdn = NULL;
+ struct berval pdn;
Entry *p = NULL;
int rc;
const char *text;
* If the parent does not exist, only allow the "root" user to
* add the entry.
*/
- pdn = dn_parent( be, e->e_nname.bv_val );
+ pdn.bv_val = dn_parent( be, e->e_nname.bv_val );
+ if (pdn.bv_val == NULL)
+ pdn.bv_len = 0;
+ else
+ pdn.bv_len = e->e_nname.bv_len - (pdn.bv_val - e->e_nname.bv_val);
- if( pdn != NULL && *pdn != '\0' ) {
+ if( pdn.bv_len != 0 ) {
Entry *matched = NULL;
- struct berval pbv;
-
- pbv.bv_val = pdn;
- pbv.bv_len = e->e_nname.bv_len - (pdn - e->e_nname.bv_val);
/* get parent */
- rc = bdb_dn2entry( be, ltid, &pbv, &p, &matched, 0 );
+ rc = bdb_dn2entry( be, ltid, &pdn, &p, &matched, 0 );
switch( rc ) {
case 0:
} else {
Debug( LDAP_DEBUG_TRACE, "bdb_add: %s denied\n",
- pdn == NULL ? "suffix" : "entry at root",
+ pdn.bv_len == 0 ? "suffix" : "entry at root",
0, 0 );
rc = LDAP_INSUFFICIENT_ACCESS;
goto return_results;
}
/* dn2id index */
- rc = bdb_dn2id_add( be, ltid, pdn, e );
+ rc = bdb_dn2id_add( be, ltid, &pdn, e );
if ( rc != 0 ) {
Debug( LDAP_DEBUG_TRACE, "bdb_add: dn2id_add failed: %s (%d)\n",
db_strerror(rc), rc, 0 );
bdb_dn2id_add(
BackendDB *be,
DB_TXN *txn,
- char *pdn,
+ struct berval *pbv,
Entry *e )
{
struct bdb_info *bdb = (struct bdb_info *) be->be_private;
DB *db = bdb->bi_dn2id->bdi_db;
int rc;
DBT key, data;
- char *buf, *ptr;
+ char *buf, *ptr, *pdn;
Debug( LDAP_DEBUG_TRACE, "=> bdb_dn2id_add( \"%s\", 0x%08lx )\n",
e->e_ndn, (long) e->e_id, 0 );
bdb_dn2id_add(
BackendDB *be,
DB_TXN *txn,
- char *pdn,
+ struct berval *pdn,
Entry *e )
{
struct bdb_info *bdb = (struct bdb_info *) be->be_private;
}
p_ndn.bv_val = dn_parent( be, e->e_ndn );
- p_ndn.bv_len = e->e_nname.bv_len - (p_ndn.bv_val - 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;
np_ndn = &p_ndn;
if ( p_ndn.bv_len != 0 ) {
/* Make sure parent entry exist and we can write its
p_ndn.bv_val, 0, 0 );
p_dn.bv_val = dn_parent( be, e->e_dn );
- p_dn.bv_len = e->e_name.bv_len - (p_dn.bv_val - 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;
Debug( LDAP_DEBUG_TRACE,
"bdb_modrdn: parent dn=%s\n",
e->e_nname = *new_ndn;
/* add new one */
- rc = bdb_dn2id_add( be, ltid, np_ndn->bv_val, e );
+ rc = bdb_dn2id_add( be, ltid, np_ndn, e );
if ( rc != 0 ) {
switch( rc ) {
case DB_LOCK_DEADLOCK:
int bdb_dn2id_add(
BackendDB *be,
DB_TXN *tid,
- char *pdn,
+ struct berval *pdn,
Entry *e );
int bdb_dn2id_delete(
int rc;
struct bdb_info *bdb = (struct bdb_info *) be->be_private;
DB_TXN *tid = NULL;
- char *pdn;
+ struct berval pdn;
assert( be != NULL );
assert( slapMode & SLAP_TOOL_MODE );
}
/* add dn2id indices */
- pdn = dn_parent( be, e->e_ndn );
- rc = bdb_dn2id_add( be, tid, pdn, e );
+ pdn.bv_val = dn_parent( be, e->e_ndn );
+ if (pdn.bv_val)
+ pdn.bv_len = e->e_nname.bv_len - (pdn.bv_val - e->e_ndn);
+ else
+ pdn.bv_len = 0;
+ rc = bdb_dn2id_add( be, tid, &pdn, e );
if( rc != 0 ) {
Debug( LDAP_DEBUG_ANY,
"=> bdb_tool_entry_put: dn2id_add failed: %s (%d)\n",
int rc;
Entry *e;
DB_TXN *tid = NULL;
- char *pdn;
+ struct berval pdn;
Debug( LDAP_DEBUG_ARGS, "=> bdb_tool_entry_reindex( %ld )\n",
(long) id, 0, 0 );
(long) id, e->e_dn, 0 );
/* add dn2id indices */
- pdn = dn_parent( be, e->e_ndn );
- rc = bdb_dn2id_add( be, tid, pdn, e );
+ pdn.bv_val = dn_parent( be, e->e_ndn );
+ if (pdn.bv_val)
+ pdn.bv_len = e->e_nname.bv_len - (pdn.bv_val - e->e_ndn);
+ else
+ pdn.bv_len = 0;
+ rc = bdb_dn2id_add( be, tid, &pdn, e );
if( rc != 0 && rc != DB_KEYEXIST ) {
Debug( LDAP_DEBUG_ANY,
"=> bdb_tool_entry_reindex: dn2id_add failed: %s (%d)\n",
}
p_ndn.bv_val = dn_parent( be, e->e_ndn );
- p_ndn.bv_len = e->e_nname.bv_len - (p_ndn.bv_val - 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 ( p_ndn.bv_len != 0 ) {
/* Make sure parent entry exist and we can write its
#endif
p_dn.bv_val = dn_parent( be, e->e_dn );
- p_dn.bv_len = e->e_name.bv_len - (p_dn.bv_val - 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;
#ifdef NEW_LOGGING
LDAP_LOG(( "backend", LDAP_LEVEL_DETAIL1,