From 3fce8e0e8078db28c2ce3bb72dbd883bc4824f30 Mon Sep 17 00:00:00 2001 From: Howard Chu Date: Sat, 8 Dec 2001 08:41:39 +0000 Subject: [PATCH] Turned dn_parent into dn_parent1, returning in-place pointer. Made dn_parent return ch_strdup of dn_parent1 for compatibility. --- servers/slapd/dn.c | 36 +++++++++++++++++++++++------------- servers/slapd/proto-slap.h | 1 + 2 files changed, 24 insertions(+), 13 deletions(-) diff --git a/servers/slapd/dn.c b/servers/slapd/dn.c index 07f5fbe200..c88eb3c49b 100644 --- a/servers/slapd/dn.c +++ b/servers/slapd/dn.c @@ -313,11 +313,11 @@ dn_match( const char *val, const char *asserted ) } /* - * dn_parent - return a copy of the dn of dn's parent + * dn_parent1 - return the dn's parent, in-place */ char * -dn_parent( +dn_parent1( Backend *be, const char *dn ) { @@ -361,12 +361,28 @@ dn_parent( if ( *s == '"' ) { inquote = 1; } else if ( DN_SEPARATOR( *s ) ) { - return ch_strdup( &s[1] ); + return (char *)s + 1; } } } - return ch_strdup( "" ); + return ""; +} + +/* + * dn_parent - return a copy of the dn of dn's parent + */ + +char * +dn_parent( + Backend *be, + const char *dn +) +{ + dn = dn_parent1( be, dn ); + if( dn != NULL ) + dn = ch_strdup( dn ); + return (char *)dn; } char * dn_rdn( @@ -428,20 +444,14 @@ char **dn_subtree( Backend *be, const char *dn ) { - char *child, *parent; char **subtree = NULL; - child = ch_strdup( dn ); - do { - charray_add( &subtree, child ); - - parent = dn_parent( be, child ); + charray_add( &subtree, dn ); - free( child ); + dn = dn_parent1( be, dn ); - child = parent; - } while ( child != NULL ); + } while ( dn != NULL ); return subtree; } diff --git a/servers/slapd/proto-slap.h b/servers/slapd/proto-slap.h index 8b3539f745..c1342c65b1 100644 --- a/servers/slapd/proto-slap.h +++ b/servers/slapd/proto-slap.h @@ -319,6 +319,7 @@ LDAP_SLAPD_F (char *) dn_validate LDAP_P(( char *dn )); LDAP_SLAPD_F (char *) dn_normalize LDAP_P(( char *dn )); LDAP_SLAPD_F (int) dn_match LDAP_P(( const char *val, const char *asserted )); LDAP_SLAPD_F (char *) dn_parent LDAP_P(( Backend *be, const char *dn )); +LDAP_SLAPD_F (char *) dn_parent1 LDAP_P(( Backend *be, const char *dn )); LDAP_SLAPD_F (char **) dn_subtree LDAP_P(( Backend *be, const char *dn )); LDAP_SLAPD_F (char *) dn_rdn LDAP_P(( Backend *be, const char *dn )); LDAP_SLAPD_F (int) dn_issuffix LDAP_P(( const char *dn, const char *suffix )); -- 2.39.5