Fix for empty suffix

This commit is contained in:
Howard Chu 2011-08-26 14:57:04 -07:00
parent 4c17931f68
commit 09a6591f23
2 changed files with 52 additions and 17 deletions

View File

@ -276,14 +276,6 @@ mdb_dn2id(
Debug( LDAP_DEBUG_TRACE, "=> mdb_dn2id(\"%s\")\n", in->bv_val, 0, 0 );
if ( !in->bv_len ) {
*id = 0;
nid = 0;
goto done;
}
tmp = *in;
if ( matched ) {
matched->bv_val = dn + sizeof(dn) - 1;
matched->bv_len = 0;
@ -294,9 +286,26 @@ mdb_dn2id(
nmatched->bv_val = 0;
}
nrlen = tmp.bv_len - op->o_bd->be_nsuffix[0].bv_len;
tmp.bv_val += nrlen;
tmp.bv_len = op->o_bd->be_nsuffix[0].bv_len;
if ( !in->bv_len ) {
*id = 0;
nid = 0;
goto done;
}
tmp = *in;
if ( op->o_bd->be_nsuffix[0].bv_len ) {
nrlen = tmp.bv_len - op->o_bd->be_nsuffix[0].bv_len;
tmp.bv_val += nrlen;
tmp.bv_len = op->o_bd->be_nsuffix[0].bv_len;
} else {
for ( ptr = tmp.bv_val + tmp.bv_len - 1; ptr >= tmp.bv_val; ptr-- )
if (DN_SEPARATOR(*ptr))
break;
ptr++;
tmp.bv_len -= ptr - tmp.bv_val;
tmp.bv_val = ptr;
}
nid = 0;
key.mv_size = sizeof(ID);
@ -352,16 +361,28 @@ mdb_dn2id(
}
*id = nid;
mdb_cursor_close( cursor );
if ( matched && matched->bv_len ) {
ptr = op->o_tmpalloc( matched->bv_len+1, op->o_tmpmemctx );
strcpy( ptr, matched->bv_val );
matched->bv_val = ptr;
done:
if ( matched ) {
if ( matched->bv_len ) {
ptr = op->o_tmpalloc( matched->bv_len+1, op->o_tmpmemctx );
strcpy( ptr, matched->bv_val );
matched->bv_val = ptr;
} else {
if ( BER_BVISEMPTY( &op->o_bd->be_nsuffix[0] ) && !nid ) {
ber_dupbv( matched, (struct berval *)&slap_empty_bv );
} else {
matched->bv_val = NULL;
}
}
}
if ( nmatched ) {
nmatched->bv_len = in->bv_len - (nmatched->bv_val - in->bv_val);
if ( nmatched->bv_val ) {
nmatched->bv_len = in->bv_len - (nmatched->bv_val - in->bv_val);
} else {
*nmatched = slap_empty_bv;
}
}
done:
if( rc != 0 ) {
Debug( LDAP_DEBUG_TRACE, "<= mdb_dn2id: get failed: %s (%d)\n",
mdb_strerror( rc ), rc, 0 );

View File

@ -101,6 +101,20 @@ int mdb_id2entry(
/* fetch it */
rc = mdb_get( tid, dbi, &key, &data );
if ( rc == MDB_NOTFOUND ) {
/* Looking for root entry on an empty-dn suffix? */
if ( !id && BER_BVISEMPTY( &op->o_bd->be_nsuffix[0] )) {
struct berval gluebv = BER_BVC("glue");
Entry *r = entry_alloc();
r->e_id = 0;
attr_merge_one( r, slap_schema.si_ad_objectClass, &gluebv, NULL );
attr_merge_one( r, slap_schema.si_ad_structuralObjectClass, &gluebv, NULL );
r->e_ocflags = SLAP_OC_GLUE|SLAP_OC__END;
*e = r;
return MDB_SUCCESS;
}
}
if ( rc ) return rc;
eh.bv.bv_val = data.mv_data;