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 )
21 /* initialize key and data thangs */
24 key.flags = DB_DBT_REALLOC;
25 data.flags = DB_DBT_REALLOC;
30 int bdb_tool_entry_close(
33 struct bdb_info *bdb = (struct bdb_info *) be->be_private;
47 cursor->c_close( cursor );
54 ID bdb_tool_entry_next(
59 struct bdb_info *bdb = (struct bdb_info *) be->be_private;
62 assert( slapMode & SLAP_TOOL_MODE );
63 assert( bdb != NULL );
66 rc = bdb->bi_id2entry->bdi_db->cursor(
67 bdb->bi_id2entry->bdi_db, NULL, &cursor,
74 rc = cursor->c_get( cursor, &key, &data, DB_NEXT );
80 if( data.data == NULL ) {
84 AC_MEMCPY( &id, key.data, key.size );
88 Entry* bdb_tool_entry_get( BackendDB *be, ID id )
95 assert( slapMode & SLAP_TOOL_MODE );
96 assert( data.data != NULL );
100 rc = entry_decode( &bv, &e );
102 if( rc == LDAP_SUCCESS ) {
109 ID bdb_tool_entry_put(
114 struct bdb_info *bdb = (struct bdb_info *) be->be_private;
117 assert( be != NULL );
118 assert( slapMode & SLAP_TOOL_MODE );
120 Debug( LDAP_DEBUG_TRACE, "=> bdb_tool_entry_put( %ld, \"%s\" )\n",
121 (long) e->e_id, e->e_dn, 0 );
124 rc = txn_begin( bdb->bi_dbenv, NULL, &tid,
125 bdb->bi_db_opflags );
127 Debug( LDAP_DEBUG_ANY,
128 "=> bdb_tool_entry_put: txn_begin failed: %s (%d)\n",
129 db_strerror(rc), rc, 0 );
134 rc = bdb_next_id( be, tid, &e->e_id );
136 Debug( LDAP_DEBUG_ANY,
137 "=> bdb_tool_entry_put: next_id failed: %s (%d)\n",
138 db_strerror(rc), rc, 0 );
142 /* add dn2id indices */
143 rc = bdb_dn2id_add( be, tid, e->e_ndn, e->e_id );
145 Debug( LDAP_DEBUG_ANY,
146 "=> bdb_tool_entry_put: dn2id_add failed: %s (%d)\n",
147 db_strerror(rc), rc, 0 );
152 rc = bdb_id2entry_add( be, tid, e );
154 Debug( LDAP_DEBUG_ANY,
155 "=> bdb_tool_entry_put: id2entry_add failed: %s (%d)\n",
156 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 );
181 Debug( LDAP_DEBUG_ANY,
182 "=> bdb_tool_entry_put: txn_aborted! %s (%d)\n",
183 db_strerror(rc), rc, 0 );
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",
203 e = bdb_tool_entry_get( be, id );
206 Debug( LDAP_DEBUG_ANY,
207 "bdb_tool_entry_reindex:: could not locate id=%ld\n",
213 rc = txn_begin( bi->bi_dbenv, NULL, &tid, bi->bi_db_opflags );
215 Debug( LDAP_DEBUG_ANY,
216 "=> bdb_tool_entry_reindex: txn_begin failed: %s (%d)\n",
217 db_strerror(rc), rc, 0 );
223 * just (re)add them for now
224 * assume that some other routine (not yet implemented)
225 * will zap index databases
229 Debug( LDAP_DEBUG_TRACE, "=> bdb_tool_entry_reindex( %ld, \"%s\" )\n",
230 (long) id, e->e_dn, 0 );
232 rc = bdb_index_entry_add( be, tid, e, e->e_attrs );
236 rc = txn_commit( tid, 0 );
238 Debug( LDAP_DEBUG_ANY,
239 "=> bdb_tool_entry_reindex: txn_commit failed: %s (%d)\n",
240 db_strerror(rc), rc, 0 );
246 Debug( LDAP_DEBUG_ANY,
247 "=> bdb_tool_entry_reindex: txn_aborted! %s (%d)\n",
248 db_strerror(rc), rc, 0 );