1 /* tools.c - tools for slap tools */
4 * Copyright 1998-2000 The OpenLDAP Foundation, All Rights Reserved.
5 * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
12 #include <ac/string.h>
13 #include <ac/socket.h>
17 static DBC *cursor = NULL;
20 int bdb_tool_entry_open(
21 BackendDB *be, int mode )
24 struct bdb_info *bdb = (struct bdb_info *) be->be_private;
26 rc = bdb->bi_entries->bdi_db->cursor(
27 bdb->bi_entries->bdi_db, NULL, &cursor, 0 );
32 /* initialize key and data thangs */
35 key.flags = DB_DBT_REALLOC;
36 data.flags = DB_DBT_REALLOC;
41 int bdb_tool_entry_close(
44 struct bdb_info *bdb = (struct bdb_info *) be->be_private;
56 cursor->c_close( cursor );
63 ID bdb_tool_entry_next(
69 assert( slapMode & SLAP_TOOL_MODE );
70 assert( cursor != NULL );
72 rc = cursor->c_get( cursor, &key, &data, DB_NEXT );
78 if( data.data == NULL ) {
82 AC_MEMCPY( &id, key.data, key.size );
86 Entry* bdb_tool_entry_get( BackendDB *be, ID id )
91 assert( slapMode & SLAP_TOOL_MODE );
92 assert( data.data != NULL );
96 rc = entry_decode( &bv, &e );
98 if( rc == LDAP_SUCCESS ) {
105 ID bdb_tool_entry_put(
110 struct bdb_info *bdb = (struct bdb_info *) be->be_private;
115 assert( slapMode & SLAP_TOOL_MODE );
118 key.data = (char *) &e->e_id;
119 key.size = sizeof(ID);
121 rc = entry_encode( e, &bv );
122 if( rc != LDAP_SUCCESS ) {
129 Debug( LDAP_DEBUG_TRACE, "=> bdb_tool_entry_put( %ld, \"%s\" )\n",
130 e->e_id, e->e_dn, 0 );
132 rc = txn_begin( bdb->bi_dbenv, NULL, &tid, 0 );
138 e->e_id = bdb_next_id( be, tid );
139 if( e->e_id == NOID ) {
143 /* store it -- don't override */
144 rc = bdb->bi_entries->bdi_db->put( bdb->bi_entries->bdi_db,
145 tid, &key, &data, DB_NOOVERWRITE );
152 rc = bdb_index_dn_add( be, tid, e->e_ndn, e->e_id );
159 rc = bdb_index_entry_add( be, tid, e, e->e_attrs );
167 if( e->e_id != NOID ) {
168 rc = txn_commit( tid, 0 );
182 int bdb_tool_entry_reindex(
186 struct bdb_dbinfo *bdi = (struct bdb_dbinfo *) be->be_private;
191 Debug( LDAP_DEBUG_ARGS, "=> bdb_tool_entry_reindex( %ld )\n",
194 rc = txn_begin( bdi->bdi_db_env, NULL, &tid, 0 );
196 e = bdb_tool_entry_get( be, tid, id );
199 Debug( LDAP_DEBUG_ANY,
200 "bdb_tool_entry_reindex:: could not locate id=%ld\n",
202 txn_abort( bdi->bdi_db_env );
207 * just (re)add them for now
208 * assume that some other routine (not yet implemented)
209 * will zap index databases
213 Debug( LDAP_DEBUG_TRACE, "=> bdb_tool_entry_reindex( %ld, \"%s\" )\n",
216 rc = index_entry_add( be, e, e->e_attrs );