1 /* tools.c - tools for slap tools */
4 * Copyright 1998-2000 The OpenLDAP Foundation, All Rights Reserved.
5 * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
11 #include <ac/string.h>
15 static DBC *cursor = NULL;
18 int bdb_tool_entry_open(
19 BackendDB *be, int mode )
22 struct bdb_info *bdb = (struct bdb_info *) be->be_private;
25 assert( bdb != NULL );
27 rc = bdb->bi_id2entry->bdi_db->cursor(
28 bdb->bi_id2entry->bdi_db, NULL, &cursor, 0 );
33 /* initialize key and data thangs */
36 key.flags = DB_DBT_REALLOC;
37 data.flags = DB_DBT_REALLOC;
42 int bdb_tool_entry_close(
45 struct bdb_info *bdb = (struct bdb_info *) be->be_private;
59 cursor->c_close( cursor );
66 ID bdb_tool_entry_next(
73 assert( slapMode & SLAP_TOOL_MODE );
74 assert( cursor != NULL );
76 rc = cursor->c_get( cursor, &key, &data, DB_NEXT );
82 if( data.data == NULL ) {
86 AC_MEMCPY( &id, key.data, key.size );
90 Entry* bdb_tool_entry_get( BackendDB *be, ID id )
97 assert( slapMode & SLAP_TOOL_MODE );
98 assert( data.data != NULL );
100 DBT2bv( &data, &bv );
102 rc = entry_decode( &bv, &e );
104 if( rc == LDAP_SUCCESS ) {
111 ID bdb_tool_entry_put(
116 struct bdb_info *bdb = (struct bdb_info *) be->be_private;
119 assert( be != NULL );
120 assert( slapMode & SLAP_TOOL_MODE );
122 Debug( LDAP_DEBUG_TRACE, "=> bdb_tool_entry_put( %ld, \"%s\" )\n",
123 e->e_id, e->e_dn, 0 );
125 rc = txn_begin( bdb->bi_dbenv, NULL, &tid, 0 );
127 Debug( LDAP_DEBUG_ANY,
128 "=> bdb_tool_entry_put: txn_begin failed: %s (%d)\n",
129 db_strerror(rc), rc, 0 );
133 rc = bdb_next_id( be, tid, &e->e_id );
135 Debug( LDAP_DEBUG_ANY,
136 "=> bdb_tool_entry_put: next_id failed: %s (%d)\n",
137 db_strerror(rc), rc, 0 );
141 /* add dn2id indices */
142 rc = bdb_dn2id_add( be, tid, e->e_ndn, e->e_id );
144 Debug( LDAP_DEBUG_ANY,
145 "=> bdb_tool_entry_put: dn2id_add failed: %s (%d)\n",
146 db_strerror(rc), rc, 0 );
151 rc = bdb_id2entry_add( be, tid, e );
153 Debug( LDAP_DEBUG_ANY,
154 "=> bdb_tool_entry_put: id2entry_add failed: %s (%d)\n",
155 db_strerror(rc), rc, 0 );
160 rc = bdb_index_entry_add( be, tid, e, e->e_attrs );
162 Debug( LDAP_DEBUG_ANY,
163 "=> bdb_tool_entry_put: index_entry_add failed: %s (%d)\n",
164 db_strerror(rc), rc, 0 );
171 rc = txn_commit( tid, 0 );
173 Debug( LDAP_DEBUG_ANY,
174 "=> bdb_tool_entry_put: txn_commit failed: %s (%d)\n",
175 db_strerror(rc), rc, 0 );
180 Debug( LDAP_DEBUG_ANY,
181 "=> bdb_tool_entry_put: txn_aborted!\n",
191 int bdb_tool_entry_reindex(
195 struct bdb_info *bi = (struct bdb_info *) be->be_private;
200 Debug( LDAP_DEBUG_ARGS, "=> bdb_tool_entry_reindex( %ld )\n",
204 rc = txn_begin( bi->bi_dbenv, NULL, &tid, 0 );
207 e = bdb_tool_entry_get( be, id );
210 Debug( LDAP_DEBUG_ANY,
211 "bdb_tool_entry_reindex:: could not locate id=%ld\n",
220 * just (re)add them for now
221 * assume that some other routine (not yet implemented)
222 * will zap index databases
226 Debug( LDAP_DEBUG_TRACE, "=> bdb_tool_entry_reindex( %ld, \"%s\" )\n",
229 rc = bdb_index_entry_add( be, tid, e, e->e_attrs );