X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=servers%2Fslapd%2Fback-ldbm%2Ftools.c;h=f3510b859f15161802d226989162d13781e89f69;hb=b0b3eff457f0e431c4fd094d3d9cfeb6383df91d;hp=11d18f15fdd7195ab559b41dd45372b8cb02727c;hpb=b01f6de09896b612d9a1b7ae7a512ca331d9e99d;p=openldap
diff --git a/servers/slapd/back-ldbm/tools.c b/servers/slapd/back-ldbm/tools.c
index 11d18f15fd..f3510b859f 100644
--- a/servers/slapd/back-ldbm/tools.c
+++ b/servers/slapd/back-ldbm/tools.c
@@ -1,13 +1,24 @@
/* tools.c - tools for slap tools */
-/*
- * Copyright 1998-1999 The OpenLDAP Foundation, All Rights Reserved.
- * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
+/* $OpenLDAP$ */
+/* This work is part of OpenLDAP Software .
+ *
+ * Copyright 1998-2003 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
+ * .
*/
#include "portable.h"
#include
+#include
#include
#include "slap.h"
@@ -40,12 +51,18 @@ int ldbm_tool_entry_open(
flags = LDBM_READER;
}
- li->li_dbcachewsync = 0;
+ li->li_dbwritesync = 0;
if ( (id2entry = ldbm_cache_open( be, "id2entry", LDBM_SUFFIX, flags ))
== NULL ) {
+#ifdef NEW_LOGGING
+ LDAP_LOG( BACK_LDBM, CRIT,
+ "Could not open/create id2entry%s\n", LDBM_SUFFIX, 0, 0 );
+#else
Debug( LDAP_DEBUG_ANY, "Could not open/create id2entry" LDBM_SUFFIX "\n",
0, 0, 0 );
+#endif
+
return( -1 );
}
@@ -61,7 +78,7 @@ int ldbm_tool_entry_close(
assert( id2entry != NULL );
ldbm_cache_close( be, id2entry );
- li->li_dbcachewsync = 1;
+ li->li_dbwritesync = 1;
id2entry = NULL;
return 0;
@@ -82,7 +99,10 @@ ID ldbm_tool_entry_first(
return NOID;
}
- memcpy( &id, key.dptr, key.dsize );
+ AC_MEMCPY( &id, key.dptr, key.dsize );
+#ifndef WORDS_BIGENDIAN
+ id = ntohl( id );
+#endif
ldbm_datum_free( id2entry->dbc_db, key );
@@ -107,7 +127,10 @@ ID ldbm_tool_entry_next(
return NOID;
}
- memcpy( &id, key.dptr, key.dsize );
+ AC_MEMCPY( &id, key.dptr, key.dsize );
+#ifndef WORDS_BIGENDIAN
+ id = ntohl( id );
+#endif
ldbm_datum_free( id2entry->dbc_db, key );
@@ -118,12 +141,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 );
@@ -135,45 +166,91 @@ Entry* ldbm_tool_entry_get( BackendDB *be, ID id )
e = str2entry( data.dptr );
ldbm_datum_free( id2entry->dbc_db, data );
+ if( e != NULL ) {
+ e->e_id = id;
+ }
+
return e;
}
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};
assert( slapMode & SLAP_TOOL_MODE );
assert( id2entry != NULL );
- if( next_id_get( be ) == NOID ) {
+ assert( text );
+ assert( text->bv_val );
+ 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;
}
e->e_id = li->li_nextid++;
+#ifdef NEW_LOGGING
+ LDAP_LOG( BACK_LDBM, ENTRY,
+ "ldbm_tool_entry_put: (%s)%ld\n", e->e_dn, e->e_id ,0 );
+#else
Debug( LDAP_DEBUG_TRACE, "=> ldbm_tool_entry_put( %ld, \"%s\" )\n",
e->e_id, e->e_dn, 0 );
+#endif
- rc = index_add_entry( be, e );
+ 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 ) {
+#ifdef NEW_LOGGING
+ LDAP_LOG( BACK_LDBM, ENTRY,
+ "ldbm_tool_entry_put: \"%s\" already exists (id=%ld)\n",
+ e->e_dn, id, 0 );
+#else
+ Debug( LDAP_DEBUG_TRACE,
+ "<= ldbm_tool_entry_put: \"%s\" already exists (id=%ld)\n",
+ e->e_ndn, id, 0 );
+#endif
+ strncpy( text->bv_val, "already exists", text->bv_len );
return NOID;
}
- rc = dn2id_add( be, e->e_ndn, e->e_id );
+ 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 );
@@ -183,54 +260,72 @@ ID ldbm_tool_entry_put(
rc = ldbm_cache_store( id2entry, key, data, LDBM_REPLACE );
if( rc != 0 ) {
- (void) dn2id_delete( be, e->e_ndn );
+ (void) dn2id_delete( be, &e->e_nname, e->e_id );
+ strncpy( text->bv_val, "cache store failed", text->bv_len );
return NOID;
}
return e->e_id;
}
-int ldbm_tool_index_attr(
+int ldbm_tool_entry_reindex(
BackendDB *be,
- char* type )
+ ID id )
{
- static DBCache *db = NULL;
- int indexmask, syntaxmask;
- char * at_cn;
+ int rc;
+ Entry *e;
+ Operation op = {0};
- assert( slapMode & SLAP_TOOL_MODE );
+#ifdef NEW_LOGGING
+ LDAP_LOG( BACK_LDBM, ENTRY, "ldbm_tool_entry_reindex: ID=%ld\n",
+ (long)id, 0, 0 );
+#else
+ Debug( LDAP_DEBUG_ARGS, "=> ldbm_tool_entry_reindex( %ld )\n",
+ (long) id, 0, 0 );
+#endif
- attr_masks( be->be_private, type, &indexmask, &syntaxmask );
- attr_normalize( type );
- at_cn = at_canonical_name( type );
+ e = ldbm_tool_entry_get( be, id );
- if ( (db = ldbm_cache_open( be, at_cn, LDBM_SUFFIX, LDBM_NEWDB ))
- == NULL ) {
+ if( e == NULL ) {
+#ifdef NEW_LOGGING
+ LDAP_LOG( BACK_LDBM, INFO,
+ "ldbm_tool_entry_reindex: could not locate id %ld\n",
+ (long)id, 0, 0 );
+#else
Debug( LDAP_DEBUG_ANY,
- "<= index_read NULL (could not open %s%s)\n", at_cn,
- LDBM_SUFFIX, 0 );
- return 0;
+ "ldbm_tool_entry_reindex:: could not locate id=%ld\n",
+ (long) id, 0, 0 );
+#endif
+
+ return -1;
}
- ldbm_cache_close( be, db );
+ /*
+ * just (re)add them for now
+ * assume that some other routine (not yet implemented)
+ * will zap index databases
+ *
+ */
- return indexmask != 0;
-}
+#ifdef NEW_LOGGING
+ LDAP_LOG( BACK_LDBM, ENTRY,
+ "ldbm_tool_entry_reindex: (%s) %ld\n", e->e_dn, id, 0 );
+#else
+ Debug( LDAP_DEBUG_TRACE, "=> ldbm_tool_entry_reindex( %ld, \"%s\" )\n",
+ id, e->e_dn, 0 );
+#endif
-int ldbm_tool_index_change(
- BackendDB *be,
- char* type,
- struct berval **bv,
- ID id,
- int op )
-{
- assert( slapMode & SLAP_TOOL_MODE );
+ dn2id_add( be, &e->e_nname, e->e_id );
- index_change_values( be,
- type, bv, id, op );
+ op.o_bd = be;
+ op.o_tmpmemctx = NULL;
+ op.o_tmpmfuncs = &ch_mfuncs;
+ rc = index_entry_add( &op, e );
- return 0;
+ entry_free( e );
+
+ return rc;
}
int ldbm_tool_sync( BackendDB *be )
@@ -240,7 +335,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;