From b2809cb330d4192918d4323e4e117b145bf058d7 Mon Sep 17 00:00:00 2001 From: Howard Chu Date: Tue, 1 Jan 2002 13:32:10 +0000 Subject: [PATCH] Fix dnParent to return "" for root --- servers/slapd/back-bdb/add.c | 8 ++++---- servers/slapd/back-bdb/modrdn.c | 4 ++-- servers/slapd/back-bdb/tools.c | 4 ++-- servers/slapd/dn.c | 10 +++++++++- 4 files changed, 17 insertions(+), 9 deletions(-) diff --git a/servers/slapd/back-bdb/add.c b/servers/slapd/back-bdb/add.c index 9ff3295b2e..a3b49793f0 100644 --- a/servers/slapd/back-bdb/add.c +++ b/servers/slapd/back-bdb/add.c @@ -93,11 +93,11 @@ retry: rc = txn_abort( ltid ); * If the parent does not exist, only allow the "root" user to * add the entry. */ - pdn.bv_val = dn_parent( be, e->e_nname.bv_val ); - if (pdn.bv_val == NULL) - pdn.bv_len = 0; + pdn.bv_val = dn_parent( be, e->e_ndn ); + if (pdn.bv_val && *pdn.bv_val) + pdn.bv_len = e->e_nname.bv_len - (pdn.bv_val - e->e_ndn); else - pdn.bv_len = e->e_nname.bv_len - (pdn.bv_val - e->e_nname.bv_val); + pdn.bv_len = 0; if( pdn.bv_len != 0 ) { Entry *matched = NULL; diff --git a/servers/slapd/back-bdb/modrdn.c b/servers/slapd/back-bdb/modrdn.c index 77c04fa12e..8c3ef8bc73 100644 --- a/servers/slapd/back-bdb/modrdn.c +++ b/servers/slapd/back-bdb/modrdn.c @@ -160,7 +160,7 @@ retry: /* transaction retry */ } p_ndn.bv_val = dn_parent( be, e->e_ndn ); - if (p_ndn.bv_val) + if (p_ndn.bv_val && *p_ndn.bv_val) p_ndn.bv_len = e->e_nname.bv_len - (p_ndn.bv_val - e->e_ndn); else p_ndn.bv_len = 0; @@ -207,7 +207,7 @@ retry: /* transaction retry */ p_ndn.bv_val, 0, 0 ); p_dn.bv_val = dn_parent( be, e->e_dn ); - if (p_dn.bv_val) + if (p_dn.bv_val && *p_dn.bv_val) p_dn.bv_len = e->e_name.bv_len - (p_dn.bv_val - e->e_dn); else p_dn.bv_len = 0; diff --git a/servers/slapd/back-bdb/tools.c b/servers/slapd/back-bdb/tools.c index 2e102ae0ae..148f1e20fb 100644 --- a/servers/slapd/back-bdb/tools.c +++ b/servers/slapd/back-bdb/tools.c @@ -146,7 +146,7 @@ ID bdb_tool_entry_put( /* add dn2id indices */ pdn.bv_val = dn_parent( be, e->e_ndn ); - if (pdn.bv_val) + if (pdn.bv_val && *pdn.bv_val) pdn.bv_len = e->e_nname.bv_len - (pdn.bv_val - e->e_ndn); else pdn.bv_len = 0; @@ -242,7 +242,7 @@ int bdb_tool_entry_reindex( /* add dn2id indices */ pdn.bv_val = dn_parent( be, e->e_ndn ); - if (pdn.bv_val) + if (pdn.bv_val && *pdn.bv_val) pdn.bv_len = e->e_nname.bv_len - (pdn.bv_val - e->e_ndn); else pdn.bv_len = 0; diff --git a/servers/slapd/dn.c b/servers/slapd/dn.c index cb7c33d41c..0dfb081817 100644 --- a/servers/slapd/dn.c +++ b/servers/slapd/dn.c @@ -232,6 +232,7 @@ LDAPDN_rewrite( LDAPDN *dn, unsigned flags ) slap_syntax_transform_func *transf = NULL; MatchingRule *mr; struct berval bv = { 0, NULL }; + int do_sort = 0; assert( ava ); @@ -244,6 +245,7 @@ LDAPDN_rewrite( LDAPDN *dn, unsigned flags ) } ava->la_private = ( void * )ad; + do_sort = 1; } /* @@ -285,7 +287,7 @@ LDAPDN_rewrite( LDAPDN *dn, unsigned flags ) ava->la_value = bv; } - AVA_Sort( rdn, iAVA ); + if( do_sort ) AVA_Sort( rdn, iAVA ); } } @@ -649,6 +651,12 @@ dnParent( return rc; } + /* Parent is root */ + if (*p == '\0') { + *pdn = ""; + return LDAP_SUCCESS; + } + assert( DN_SEPARATOR( p[ 0 ] ) ); p++; -- 2.39.5