]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/back-ldbm/tools.c
don't send error with back-meta
[openldap] / servers / slapd / back-ldbm / tools.c
index 68d2a289698eb4987336029b36794ee41185dfe4..db2b31e91bcd5cd59238ab8b380915d5d5aae4f8 100644 (file)
@@ -1,8 +1,17 @@
 /* tools.c - tools for slap tools */
 /* $OpenLDAP$ */
-/*
- * Copyright 1998-2000 The OpenLDAP Foundation, All Rights Reserved.
- * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
+/* This work is part of OpenLDAP Software <http://www.openldap.org/>.
+ *
+ * Copyright 1998-2006 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"
@@ -48,6 +57,7 @@ int ldbm_tool_entry_open(
            == NULL ) {
                Debug( LDAP_DEBUG_ANY, "Could not open/create id2entry" LDBM_SUFFIX "\n",
                    0, 0, 0 );
+
                return( -1 );
        }
 
@@ -85,6 +95,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 );
 
@@ -110,6 +123,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 );
 
@@ -120,12 +136,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 );
@@ -134,7 +158,7 @@ Entry* ldbm_tool_entry_get( BackendDB *be, ID id )
                return NULL;
        }
 
-       e = str2entry( data.dptr );
+       e = str2entry2( data.dptr, 0 );
        ldbm_datum_free( id2entry->dbc_db, data );
 
        if( e != NULL ) {
@@ -146,16 +170,25 @@ Entry* ldbm_tool_entry_get( BackendDB *be, ID id )
 
 ID ldbm_tool_entry_put(
        BackendDB *be,
-       Entry *e )
+       Entry *e,
+       struct berval *text )
 {
        struct ldbminfo *li = (struct ldbminfo *) be->be_private;
        Datum key, data;
        int rc, len;
+       ID id;
+       Operation op = {0};
+       Opheader ohdr = {0};
 
        assert( slapMode & SLAP_TOOL_MODE );
        assert( id2entry != NULL );
 
-       if( next_id_get( be ) == NOID ) {
+       assert( text != NULL );
+       assert( text->bv_val != NULL );
+       assert( text->bv_val[0] == '\0' );      /* overconservative? */
+
+       if ( next_id_get( be, &id ) || id == NOID ) {
+               strncpy( text->bv_val, "unable to get nextid", text->bv_len );
                return NOID;
        }
 
@@ -164,22 +197,46 @@ ID ldbm_tool_entry_put(
        Debug( LDAP_DEBUG_TRACE, "=> ldbm_tool_entry_put( %ld, \"%s\" )\n",
                e->e_id, e->e_dn, 0 );
 
-       rc = index_entry_add( be, e, e->e_attrs );
+       if ( dn2id( be, &e->e_nname, &id ) ) {
+               /* something bad happened to ldbm cache */
+               strncpy( text->bv_val, "ldbm cache corrupted", text->bv_len );
+               return NOID;
+       }
 
-       if( rc != 0 ) {
+       if( id != NOID ) {
+               Debug( LDAP_DEBUG_TRACE,
+                       "<= ldbm_tool_entry_put: \"%s\" already exists (id=%ld)\n",
+                       e->e_ndn, id, 0 );
+               strncpy( text->bv_val, "already exists", text->bv_len );
                return NOID;
        }
 
-       rc = dn2id_add( be, e->e_ndn, e->e_id );
+       op.o_hdr = &ohdr;
+       op.o_bd = be;
+       op.o_tmpmemctx = NULL;
+       op.o_tmpmfuncs = &ch_mfuncs;
 
+       rc = index_entry_add( &op, e );
        if( rc != 0 ) {
+               strncpy( text->bv_val, "index add failed", text->bv_len );
+               return NOID;
+       }
+
+       rc = dn2id_add( be, &e->e_nname, e->e_id );
+       if( rc != 0 ) {
+               strncpy( text->bv_val, "dn2id add failed", text->bv_len );
                return NOID;
        }
 
        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 );
@@ -189,7 +246,8 @@ ID ldbm_tool_entry_put(
        rc = ldbm_cache_store( id2entry, key, data, LDBM_REPLACE );
 
        if( rc != 0 ) {
-               (void) dn2id_delete( be, e->e_ndn, e->e_id );
+               (void) dn2id_delete( be, &e->e_nname, e->e_id );
+               strncpy( text->bv_val, "cache store failed", text->bv_len );
                return NOID;
        }
 
@@ -202,16 +260,20 @@ int ldbm_tool_entry_reindex(
 {
        int rc;
        Entry *e;
+       Operation op = {0};
+       Opheader ohdr = {0};
 
        Debug( LDAP_DEBUG_ARGS, "=> ldbm_tool_entry_reindex( %ld )\n",
                (long) id, 0, 0 );
 
+
        e = ldbm_tool_entry_get( be, id );
 
        if( e == NULL ) {
                Debug( LDAP_DEBUG_ANY,
                        "ldbm_tool_entry_reindex:: could not locate id=%ld\n",
                        (long) id, 0, 0 );
+
                return -1;
        }
 
@@ -225,7 +287,13 @@ int ldbm_tool_entry_reindex(
        Debug( LDAP_DEBUG_TRACE, "=> ldbm_tool_entry_reindex( %ld, \"%s\" )\n",
                id, e->e_dn, 0 );
 
-       rc = index_entry_add( be, e, e->e_attrs );
+       dn2id_add( be, &e->e_nname, e->e_id );
+
+       op.o_hdr = &ohdr;
+       op.o_bd = be;
+       op.o_tmpmemctx = NULL;
+       op.o_tmpmfuncs = &ch_mfuncs;
+       rc = index_entry_add( &op, e );
 
        entry_free( e );
 
@@ -239,7 +307,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;