]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/back-ldbm/tools.c
Remove abandon cruft
[openldap] / servers / slapd / back-ldbm / tools.c
index 4bae7a4c9ca07ef58749472b961664b98bc10e4f..a497be625b458a5a304fe634325026af956881af 100644 (file)
@@ -91,6 +91,9 @@ ID ldbm_tool_entry_first(
        }
 
        AC_MEMCPY( &id, key.dptr, key.dsize );
+#ifndef WORDS_BIGENDIAN
+       id = ntohl( id );
+#endif
 
        ldbm_datum_free( id2entry->dbc_db, key );
 
@@ -116,6 +119,9 @@ ID ldbm_tool_entry_next(
        }
 
        AC_MEMCPY( &id, key.dptr, key.dsize );
+#ifndef WORDS_BIGENDIAN
+       id = ntohl( id );
+#endif
 
        ldbm_datum_free( id2entry->dbc_db, key );
 
@@ -126,12 +132,20 @@ Entry* ldbm_tool_entry_get( BackendDB *be, ID id )
 {
        Entry *e;
        Datum key, data;
+#ifndef WORDS_BIGENDIAN
+       ID id2;
+#endif
        assert( slapMode & SLAP_TOOL_MODE );
        assert( id2entry != NULL );
 
        ldbm_datum_init( key );
 
+#ifndef WORDS_BIGENDIAN
+       id2 = htonl( id );
+       key.dptr = (char *) &id2;
+#else
        key.dptr = (char *) &id;
+#endif
        key.dsize = sizeof(ID);
 
        data = ldbm_cache_fetch( id2entry, key );
@@ -157,11 +171,12 @@ ID ldbm_tool_entry_put(
        struct ldbminfo *li = (struct ldbminfo *) be->be_private;
        Datum key, data;
        int rc, len;
+       ID id;
 
        assert( slapMode & SLAP_TOOL_MODE );
        assert( id2entry != NULL );
 
-       if( next_id_get( be ) == NOID ) {
+       if ( next_id_get( be, &id ) || id == NOID ) {
                return NOID;
        }
 
@@ -169,21 +184,36 @@ ID ldbm_tool_entry_put(
 
 #ifdef NEW_LOGGING
        LDAP_LOG(( "backend", LDAP_LEVEL_ENTRY,
-                  "ldbm_tool_entry_put: (%s)%ld\n", e->e_dn, e->e_id ));
+               "ldbm_tool_entry_put: (%s)%ld\n", e->e_dn, e->e_id ));
 #else
        Debug( LDAP_DEBUG_TRACE, "=> ldbm_tool_entry_put( %ld, \"%s\" )\n",
                e->e_id, e->e_dn, 0 );
 #endif
 
+       if ( dn2id( be, e->e_ndn, &id ) ) {
+               /* something bad happened to ldbm cache */
+               return NOID;
+       }
 
-       rc = index_entry_add( be, e, e->e_attrs );
+       if( id != NOID ) {
+#ifdef NEW_LOGGING
+               LDAP_LOG(( "backend", LDAP_LEVEL_ENTRY,
+                       "ldbm_tool_entry_put: \"%s\" already exists (id=%ld)\n",
+                       e->e_dn, id ));
+#else
+               Debug( LDAP_DEBUG_TRACE,
+                       "<= ldbm_tool_entry_put: \"%s\" already exists (id=%ld)\n",
+                       e->e_ndn, id, 0 );
+#endif
+               return NOID;
+       }
 
+       rc = index_entry_add( be, e, e->e_attrs );
        if( rc != 0 ) {
                return NOID;
        }
 
        rc = dn2id_add( be, e->e_ndn, e->e_id );
-
        if( rc != 0 ) {
                return NOID;
        }
@@ -191,7 +221,12 @@ ID ldbm_tool_entry_put(
        ldbm_datum_init( key );
        ldbm_datum_init( data );
 
+#ifndef WORDS_BIGENDIAN
+       id = htonl( e->e_id );
+       key.dptr = (char *) &id;
+#else
        key.dptr = (char *) &e->e_id;
+#endif
        key.dsize = sizeof(ID);
 
        data.dptr = entry2str( e, &len );
@@ -255,7 +290,7 @@ int ldbm_tool_entry_reindex(
                id, e->e_dn, 0 );
 #endif
 
-
+       dn2id_add( be, e->e_ndn, e->e_id );
        rc = index_entry_add( be, e, e->e_attrs );
 
        entry_free( e );
@@ -270,7 +305,9 @@ int ldbm_tool_sync( BackendDB *be )
        assert( slapMode & SLAP_TOOL_MODE );
 
        if ( li->li_nextid != NOID ) {
-               next_id_write( be, li->li_nextid );
+               if ( next_id_write( be, li->li_nextid ) ) {
+                       return( -1 );
+               }
        }
 
        return 0;