]> git.sur5r.net Git - openldap/commitdiff
Fix dnParent to return "" for root
authorHoward Chu <hyc@openldap.org>
Tue, 1 Jan 2002 13:32:10 +0000 (13:32 +0000)
committerHoward Chu <hyc@openldap.org>
Tue, 1 Jan 2002 13:32:10 +0000 (13:32 +0000)
servers/slapd/back-bdb/add.c
servers/slapd/back-bdb/modrdn.c
servers/slapd/back-bdb/tools.c
servers/slapd/dn.c

index 9ff3295b2eaa0f978d8dbe37dbae4d64e1dbcc08..a3b49793f0b05c7e01e6742e8bfce6e3d3fe8c86 100644 (file)
@@ -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;
index 77c04fa12e948e95fe93987da1da0a11c480fa35..8c3ef8bc733e6428fe2ee0d7a4bd7d1b73f9ebb2 100644 (file)
@@ -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;
index 2e102ae0aed42b264387793f75197832ae1a4902..148f1e20fbf4fbe8a06c7131d3218f1344a511a3 100644 (file)
@@ -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;
index cb7c33d41c22f0d29d5243c6eb5989dc40dd66c2..0dfb081817f3ded6eb457a307fa6771c4627f68c 100644 (file)
@@ -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++;