From 3894bd332b2c3444b1d67688cc5e8b63a0031dc4 Mon Sep 17 00:00:00 2001 From: Pierangelo Masarati Date: Thu, 17 Jan 2002 22:36:53 +0000 Subject: [PATCH] fix dnParent to return '' if the dn is a rdn --- servers/slapd/dn.c | 58 ++++++++++++++++++++++++---------------------- 1 file changed, 30 insertions(+), 28 deletions(-) diff --git a/servers/slapd/dn.c b/servers/slapd/dn.c index 7165ff0530..532b38c7d8 100644 --- a/servers/slapd/dn.c +++ b/servers/slapd/dn.c @@ -556,6 +556,36 @@ dnMatch( return( LDAP_SUCCESS ); } +/* + * dnParent - dn's parent, in-place + * + * note: the incoming dn is assumed to be normalized/prettyfied, + * so that escaped rdn/ava separators are in '\'+hexpair form + */ +int +dnParent( + const char *dn, + const char **pdn ) +{ + const char *p; + + p = strchr( dn, ',' ); + + /* one-level dn */ + if ( p == NULL ) { + *pdn = ""; + return LDAP_SUCCESS; + } + + assert( DN_SEPARATOR( p[ 0 ] ) ); + p++; + + assert( ATTR_LEADCHAR( p[ 0 ] ) ); + *pdn = p; + + return LDAP_SUCCESS; +} + #ifdef SLAP_DN_MIGRATION /* * these routines are provided for migration purposes only! @@ -602,34 +632,6 @@ dn_normalize( char *dn ) return dn; } -/* - * dnParent - dn's parent, in-place - * - * note: the incoming dn is assumed to be normalized/prettyfied, - * so that escaped rdn/ava separators are in '\'+hexpair form - */ -int -dnParent( - const char *dn, - const char **pdn ) -{ - const char *p; - - p = strchr( dn, ',' ); - - if ( p == NULL ) { - return LDAP_INVALID_DN_SYNTAX; - } - - assert( DN_SEPARATOR( p[ 0 ] ) ); - p++; - - assert( ! ASCII_SPACE( p[ 0 ] ) ); - *pdn = p; - - return LDAP_SUCCESS; -} - /* * dn_parent - return the dn's parent, in-place * FIXME: should be replaced by dnParent() -- 2.39.5