*/
/* Set *res = LDIF filename path for the normalized DN */
-static void
-dn2path( BackendDB *be, struct berval *dn, struct berval *res )
+static int
+ndn2path( Operation *op, struct berval *dn, struct berval *res, int empty_ok )
{
+ BackendDB *be = op->o_bd;
struct ldif_info *li = (struct ldif_info *) be->be_private;
struct berval *suffixdn = &be->be_nsuffix[0];
const char *start, *end, *next, *p;
assert( !BER_BVISNULL( suffixdn ) );
assert( dnIsSuffix( dn, suffixdn ) );
+ if ( dn->bv_len == 0 && !empty_ok ) {
+ return LDAP_UNWILLING_TO_PERFORM;
+ }
+
start = dn->bv_val;
end = start + dn->bv_len;
res->bv_len = ptr - res->bv_val;
assert( res->bv_len <= len );
+
+ return LDAP_SUCCESS;
}
/*
dnParent( &op->o_req_dn, &pdn );
dnParent( &op->o_req_ndn, &pndn );
- dn2path( op->o_bd, &op->o_req_ndn, &path );
+ rc = ndn2path( op, &op->o_req_ndn, &path, 0 );
+ if ( rc != LDAP_SUCCESS ) {
+ goto done;
+ }
+
rc = ldif_read_entry( op, path.bv_val, &pdn, &pndn, entryp, text );
if ( rc == LDAP_SUCCESS && pathp != NULL ) {
} else {
SLAP_FREE( path.bv_val );
}
+ done:
return rc;
}
bvl->savech = *trunc;
*trunc = '\0';
+ /* Insertion sort */
for ( prev = listp; (ptr = *prev) != NULL; prev = &ptr->next ) {
int cmp = strcmp( BVL_NAME( bvl ), BVL_NAME( ptr ));
if ( cmp < 0 || (cmp == 0 && bvl->inum < ptr->inum) )
struct berval path;
struct berval pdn, pndn;
- dn2path( op->o_bd, &op->o_req_ndn, &path );
+ (void) ndn2path( op, &op->o_req_ndn, &path, 1 );
if ( !BER_BVISEMPTY( &op->o_req_ndn ) ) {
/* Read baseObject */
dnParent( &op->o_req_dn, &pdn );
char **need_dir,
const char **text )
{
- BackendDB *be = op->o_bd;
- struct ldif_info *li = (struct ldif_info *) be->be_private;
+ struct ldif_info *li = (struct ldif_info *) op->o_bd->be_private;
struct berval *ndn = &e->e_nname;
struct berval ppath = BER_BVNULL;
struct stat st;
Entry *parent = NULL;
- int rc = LDAP_SUCCESS;
+ int rc;
if ( op->o_abandon )
return SLAPD_ABANDON;
- dn2path( be, ndn, dnpath );
+ rc = ndn2path( op, ndn, dnpath, 0 );
+ if ( rc != LDAP_SUCCESS ) {
+ return rc;
+ }
if ( stat( dnpath->bv_val, &st ) == 0 ) { /* entry .ldif file */
rc = LDAP_ALREADY_EXISTS;
if ( min_dnlen == 0 ) {
/* Catch root DSE (empty DN), it is not a referral */
min_dnlen = 1;
- if ( BER_BVISEMPTY( &ndn ) )
- return LDAP_SUCCESS;
+ }
+ if ( ndn2path( op, &ndn, &path, 0 ) != LDAP_SUCCESS ) {
+ return LDAP_SUCCESS; /* Root DSE again */
}
entryp = get_manageDSAit( op ) ? NULL : &entry;
- dn2path( op->o_bd, &ndn, &path );
ldap_pvt_thread_rdwr_rlock( &li->li_rdwr );
for (;;) {
goto done;
}
- dn2path( op->o_bd, &op->o_req_ndn, &path );
+ rc = ndn2path( op, &op->o_req_ndn, &path, 0 );
+ if ( rc != LDAP_SUCCESS ) {
+ goto done;
+ }
+
ldif2dir_len( path );
ldif2dir_name( path );
if ( rmdir( path.bv_val ) < 0 ) {