]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/back-bdb/tools.c
Import ITS#3267 fix from HEAD
[openldap] / servers / slapd / back-bdb / tools.c
index 94f6838e3221ccbaa8eec6586d3bce48b9de56ae..b4a83aa4e6e68463a6f89fca8ccc3e9bf548b616 100644 (file)
@@ -2,7 +2,7 @@
 /* $OpenLDAP$ */
 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
  *
- * Copyright 2000-2004 The OpenLDAP Foundation.
+ * Copyright 2000-2005 The OpenLDAP Foundation.
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -203,7 +203,7 @@ static int bdb_tool_next_id(
        struct berval dn = e->e_name;
        struct berval ndn = e->e_nname;
        struct berval pdn, npdn;
-       EntryInfo *ei = NULL;
+       EntryInfo *ei = NULL, eidummy;
        int rc;
 
        if (ndn.bv_len == 0) return 0;
@@ -212,6 +212,7 @@ static int bdb_tool_next_id(
        if ( ei ) bdb_cache_entryinfo_unlock( ei );
        if ( rc == DB_NOTFOUND ) {
                if ( !be_issuffix( op->o_bd, &ndn ) ) {
+                       ID eid = e->e_id;
                        dnParent( &dn, &pdn );
                        dnParent( &ndn, &npdn );
                        e->e_name = pdn;
@@ -222,6 +223,14 @@ static int bdb_tool_next_id(
                        if ( rc ) {
                                return rc;
                        }
+                       /* If parent didn't exist, it was created just now
+                        * and its ID is now in e->e_id. Make sure the current
+                        * entry gets added under the new parent ID.
+                        */
+                       if ( eid != e->e_id ) {
+                               eidummy.bei_id = e->e_id;
+                               ei = &eidummy;
+                       }
                }
                rc = bdb_next_id( op->o_bd, tid, &e->e_id );
                if ( rc ) {