mirror of
https://git.openldap.org/openldap/openldap.git
synced 2025-01-18 11:05:48 +08:00
Fix for empty suffix
This commit is contained in:
parent
4c17931f68
commit
09a6591f23
@ -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 );
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user