/* tools.c - tools for slap tools */
/* $OpenLDAP$ */
/*
- * Copyright 1998-2000 The OpenLDAP Foundation, All Rights Reserved.
+ * Copyright 1998-2002 The OpenLDAP Foundation, All Rights Reserved.
* COPYING RESTRICTIONS APPLY, see COPYRIGHT file
*/
}
AC_MEMCPY( &id, key.dptr, key.dsize );
+#ifndef WORDS_BIGENDIAN
+ id = ntohl( id );
+#endif
ldbm_datum_free( id2entry->dbc_db, key );
}
AC_MEMCPY( &id, key.dptr, key.dsize );
+#ifndef WORDS_BIGENDIAN
+ id = ntohl( id );
+#endif
ldbm_datum_free( id2entry->dbc_db, key );
{
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 );
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, rc_id;
+ int rc, len;
ID id;
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' );
+
+ if ( next_id_get( be, &id ) || id == NOID ) {
+ strncpy( text->bv_val, "unable to get nextid", text->bv_len );
return NOID;
}
e->e_id, e->e_dn, 0 );
#endif
- id = dn2id( be, e->e_ndn, &rc_id );
+ 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( id != NOID ) {
#ifdef NEW_LOGGING
LDAP_LOG(( "backend", LDAP_LEVEL_ENTRY,
"<= ldbm_tool_entry_put: \"%s\" already exists (id=%ld)\n",
e->e_ndn, id, 0 );
#endif
- return NOID;
- } else if ( rc_id ) {
- /* something bad happened to ldbm cache */
+ strncpy( text->bv_val, "already exists", text->bv_len );
return NOID;
}
rc = index_entry_add( be, e, e->e_attrs );
if( rc != 0 ) {
+ strncpy( text->bv_val, "index add failed", text->bv_len );
return NOID;
}
- rc = dn2id_add( be, e->e_ndn, e->e_id );
+ 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 );
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;
}
id, e->e_dn, 0 );
#endif
-
+ dn2id_add( be, &e->e_nname, e->e_id );
rc = index_entry_add( be, e, e->e_attrs );
entry_free( e );
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;