From f0101fe5a75ebd7bdd9f79277841b00014d7fff9 Mon Sep 17 00:00:00 2001 From: Luke Howard Date: Sun, 31 Jul 2005 06:45:39 +0000 Subject: [PATCH] Fix slapi_dn_beparent() logic --- servers/slapd/slapi/slapi_utils.c | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/servers/slapd/slapi/slapi_utils.c b/servers/slapd/slapi/slapi_utils.c index e12d8ab900..1b65c54d8f 100644 --- a/servers/slapd/slapi/slapi_utils.c +++ b/servers/slapd/slapi/slapi_utils.c @@ -946,11 +946,15 @@ char *slapi_dn_beparent( Slapi_PBlock *pb, const char *_dn ) Backend *be; struct berval dn, prettyDN; struct berval normalizedDN, parentDN; + char *parent = NULL; - if ( pb == NULL || pb->pb_op == NULL ) + if ( pb == NULL ) { return NULL; + } - be = pb->pb_op->o_bd; + if ( slapi_is_rootdse( _dn ) ) { + return NULL; + } dn.bv_val = (char *)_dn; dn.bv_len = strlen( _dn ); @@ -959,22 +963,19 @@ char *slapi_dn_beparent( Slapi_PBlock *pb, const char *_dn ) return NULL; } - if ( be != NULL && be_issuffix( be, &normalizedDN ) ) { - slapi_ch_free( (void **)&prettyDN.bv_val ); - slapi_ch_free( (void **)&normalizedDN.bv_val ); - return NULL; - } + be = select_backend( &dn, 0, 0 ); - dnParent( &prettyDN, &parentDN ); + if ( be == NULL || be_issuffix( be, &normalizedDN ) == 0 ) { + dnParent( &prettyDN, &parentDN ); + + if ( parentDN.bv_len != 0 ) + parent = slapi_ch_strdup( parentDN.bv_val ); + } slapi_ch_free( (void **)&prettyDN.bv_val ); slapi_ch_free( (void **)&normalizedDN.bv_val ); - if ( parentDN.bv_len == 0 ) { - return NULL; - } - - return slapi_ch_strdup( parentDN.bv_val ); + return parent; } char * -- 2.39.5