]> git.sur5r.net Git - openldap/commitdiff
Better fix for ITS#3063, #3186
authorHoward Chu <hyc@openldap.org>
Sat, 12 Jun 2004 07:39:24 +0000 (07:39 +0000)
committerHoward Chu <hyc@openldap.org>
Sat, 12 Jun 2004 07:39:24 +0000 (07:39 +0000)
servers/slapd/back-bdb/add.c
servers/slapd/back-bdb/cache.c
servers/slapd/back-bdb/search.c
servers/slapd/back-bdb/tools.c

index 22da9a6a37f7e848fdda7eb3b2f54a2b5c734914..476043febe5cdc61f20072f005d60cef05e7b810 100644 (file)
@@ -380,38 +380,6 @@ retry:     /* transaction retry */
                goto return_results;
        }
 
-       /* This is the first add to a root DB, need to make the suffix glue */
-       if ( op->o_bd->be_nsuffix[0].bv_len == 0 && ei->bei_id == 0 ) {
-               Entry e_root = {0};
-               e_root.e_name.bv_val = "";
-               e_root.e_nname.bv_val = "";
-               e_root.e_id = 1;
-               rs->sr_err = bdb_dn2id_add( op, lt2, ei, &e_root );
-
-               /* Just give up on any failure. */
-               if ( rs->sr_err ) {
-                       rs->sr_err = LDAP_OTHER;
-                       goto return_results;
-               }
-
-               /* Get a new ID for the actual entry */
-               if ( op->oq_add.rs_e->e_id == 1 ) {
-                       rs->sr_err = bdb_next_id( op->o_bd, NULL, &op->oq_add.rs_e->e_id );
-                       if (rs->sr_err) {
-                               rs->sr_err = LDAP_OTHER;
-                               goto return_results;
-                       }
-               }
-
-               /* Get new EntryInfo */
-               rs->sr_err = bdb_dn2entry( op, ltid, &op->ora_e->e_nname, &ei,
-               1, locker, &lock );
-               if (rs->sr_err != DB_NOTFOUND) {
-                       rs->sr_err = LDAP_OTHER;
-                       goto return_results;
-               }
-       }
-
        /* dn2id index */
        rs->sr_err = bdb_dn2id_add( op, lt2, ei, op->oq_add.rs_e );
        if ( rs->sr_err != 0 ) {
index d6dd3661657ccd2801d6ad2af4d71d8c7df8b391..e1fcc9812efb307c5bf4b198209140d3328d701c 100644 (file)
@@ -290,6 +290,16 @@ bdb_cache_find_ndn(
                ptr = ndn->bv_val + ndn->bv_len - op->o_bd->be_nsuffix[0].bv_len;
                ei.bei_nrdn.bv_val = ptr;
                ei.bei_nrdn.bv_len = op->o_bd->be_nsuffix[0].bv_len;
+               /* Skip to next rdn if suffix is empty */
+               if ( ei.bei_nrdn.bv_len == 0 ) {
+                       for (ptr = ei.bei_nrdn.bv_val - 2; ptr > ndn->bv_val
+                               && !DN_SEPARATOR(*ptr); ptr--) /* empty */;
+                       if ( ptr >= ndn->bv_val ) {
+                               if (DN_SEPARATOR(*ptr)) ptr++;
+                               ei.bei_nrdn.bv_len = ei.bei_nrdn.bv_val - ptr;
+                               ei.bei_nrdn.bv_val = ptr;
+                       }
+               }
                eip = &bdb->bi_cache.c_dntree;
        }
        
index b42b9b406e8345adb949b4b0b78273d58c2f8f32..7a91c99c0b9a9aa4e1cfd903b0675633fa611914 100644 (file)
@@ -524,7 +524,7 @@ bdb_do_search( Operation *op, SlapReply *rs, Operation *sop,
                ei_root.bei_e = &e_root;
                ei_root.bei_parent = &ei_root;
                e_root.e_private = &ei_root;
-               e_root.e_id = 1;
+               e_root.e_id = 0;
                e_root.e_nname.bv_val="";
                e_root.e_name.bv_val="";
                ei = &ei_root;
@@ -988,7 +988,7 @@ id2entry_retry:
 #endif
                case LDAP_SCOPE_SUBTREE: {
                        EntryInfo *tmp;
-                       for (tmp = BEI(e); tmp->bei_parent;
+                       for (tmp = BEI(e); tmp;
                                 tmp = tmp->bei_parent ) {
                                if ( tmp->bei_id == base.e_id ) {
                                        scopeok = 1;
index 0ae213d0329ab338aae29c37e7be7e51dbc13314..6484e4db9e285d61ef2add639e2525312771b916 100644 (file)
@@ -68,19 +68,12 @@ int bdb_tool_entry_close(
 
        if( nholes ) {
                unsigned i;
-               int fail=0, warn=1;
+               fprintf( stderr, "Error, entries missing!\n");
                for (i=0; i<nholes; i++) {
-                       if (holes[i].dn.bv_len) {
-                               fail=1;
-                               if (warn) {
-                                       fprintf( stderr, "Error, entries missing!\n");
-                                       warn=0;
-                               }
-                               fprintf(stderr, "  entry %ld: %s\n",
-                                       holes[i].id, holes[i].dn.bv_val);
-                       }
+                       fprintf(stderr, "  entry %ld: %s\n",
+                               holes[i].id, holes[i].dn.bv_val);
                }
-               if (fail) return -1;
+               return -1;
        }
                        
        return 0;
@@ -211,21 +204,25 @@ static int bdb_tool_next_id(
        int hole )
 {
        struct bdb_info *bdb = (struct bdb_info *) op->o_bd->be_private;
-       struct berval dn = e->e_nname;
-       struct berval pdn;
+       struct berval dn = e->e_name;
+       struct berval ndn = e->e_nname;
+       struct berval pdn, npdn;
        EntryInfo *ei = NULL;
        int rc;
 
-       rc = bdb_cache_find_ndn( op, tid, &dn, &ei );
+       if (ndn.bv_len == 0) return 0;
+
+       rc = bdb_cache_find_ndn( op, tid, &ndn, &ei );
        if ( ei ) bdb_cache_entryinfo_unlock( ei );
        if ( rc == DB_NOTFOUND ) {
-               if ( be_issuffix( op->o_bd, &dn ) ) {
-                       pdn = slap_empty_bv;
-               } else {
+               if ( !be_issuffix( op->o_bd, &ndn ) ) {
                        dnParent( &dn, &pdn );
-                       e->e_nname = pdn;
+                       dnParent( &ndn, &npdn );
+                       e->e_name = pdn;
+                       e->e_nname = npdn;
                        rc = bdb_tool_next_id( op, tid, e, text, 1 );
-                       e->e_nname = dn;
+                       e->e_name = dn;
+                       e->e_nname = ndn;
                        if ( rc ) {
                                return rc;
                        }
@@ -266,7 +263,7 @@ static int bdb_tool_next_id(
                                }
                                nhmax *= 2;
                        }
-                       ber_dupbv( &holes[nholes].dn, &dn );
+                       ber_dupbv( &holes[nholes].dn, &ndn );
                        holes[nholes++].id = e->e_id;
                }
        } else if ( !hole ) {