]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/back-bdb/tools.c
normalize authcDN (ITS#3246); don't touch databases when running slapadd in dryryn...
[openldap] / servers / slapd / back-bdb / tools.c
index 06e2454d1ed2103b7059a1f8d85fb28accc806ad..6484e4db9e285d61ef2add639e2525312771b916 100644 (file)
@@ -1,8 +1,17 @@
 /* tools.c - tools for slap tools */
 /* $OpenLDAP$ */
-/*
- * Copyright 1998-2003 The OpenLDAP Foundation, All Rights Reserved.
- * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
+/* This work is part of OpenLDAP Software <http://www.openldap.org/>.
+ *
+ * Copyright 2000-2004 The OpenLDAP Foundation.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted only as authorized by the OpenLDAP
+ * Public License.
+ *
+ * A copy of this license is available in the file LICENSE in the
+ * top-level directory of the distribution or, alternatively, at
+ * <http://www.OpenLDAP.org/license.html>.
  */
 
 #include "portable.h"
@@ -109,7 +118,7 @@ ID bdb_tool_dn2id_get(
        struct berval *dn
 )
 {
-       struct bdb_info *bdb = (struct bdb_nifo *) be->be_private;
+       struct bdb_info *bdb = (struct bdb_info *) be->be_private;
        DB *db = bdb->bi_dn2id->bdi_db;
        int rc;
        DBT     key, data;
@@ -192,24 +201,28 @@ static int bdb_tool_next_id(
        DB_TXN *tid,
        Entry *e,
        struct berval *text,
-       int hole,
-       u_int32_t locker )
+       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, locker );
+       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;
-                       rc = bdb_tool_next_id( op, tid, e, text, 1, locker );
+                       dnParent( &ndn, &npdn );
+                       e->e_name = pdn;
+                       e->e_nname = npdn;
+                       rc = bdb_tool_next_id( op, tid, e, text, 1 );
+                       e->e_name = dn;
+                       e->e_nname = ndn;
                        if ( rc ) {
                                return rc;
                        }
@@ -228,7 +241,6 @@ static int bdb_tool_next_id(
 #endif
                        return rc;
                }
-               e->e_nname = dn;
                rc = bdb_dn2id_add( op, tid, ei, e );
                if ( rc ) {
                        snprintf( text->bv_val, text->bv_len, 
@@ -244,19 +256,21 @@ static int bdb_tool_next_id(
                } else if ( hole ) {
                        if ( nholes == nhmax - 1 ) {
                                if ( holes == hbuf ) {
-                                       holes = ch_malloc( nhmax * sizeof(ID) * 2 );
+                                       holes = ch_malloc( nhmax * sizeof(dn_id) * 2 );
                                        AC_MEMCPY( holes, hbuf, sizeof(hbuf) );
                                } else {
-                                       holes = ch_realloc( holes, nhmax * sizeof(ID) * 2 );
+                                       holes = ch_realloc( holes, nhmax * sizeof(dn_id) * 2 );
                                }
                                nhmax *= 2;
                        }
-                       ber_dupbv( &holes[nholes].dn, &dn );
+                       ber_dupbv( &holes[nholes].dn, &ndn );
                        holes[nholes++].id = e->e_id;
                }
        } else if ( !hole ) {
                unsigned i;
 
+               e->e_id = ei->bei_id;
+
                for ( i=0; i<nholes; i++) {
                        if ( holes[i].id == e->e_id ) {
                                int j;
@@ -282,7 +296,6 @@ ID bdb_tool_entry_put(
        struct bdb_info *bdb = (struct bdb_info *) be->be_private;
        DB_TXN *tid = NULL;
        Operation op = {0};
-       u_int32_t locker;
 
        assert( be != NULL );
        assert( slapMode & SLAP_TOOL_MODE );
@@ -319,9 +332,8 @@ ID bdb_tool_entry_put(
        op.o_tmpmemctx = NULL;
        op.o_tmpmfuncs = &ch_mfuncs;
 
-       locker = TXN_ID( tid );
        /* add dn2id indices */
-       rc = bdb_tool_next_id( &op, tid, e, text, 0, locker );
+       rc = bdb_tool_next_id( &op, tid, e, text, 0 );
        if( rc != 0 ) {
                goto done;
        }