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;
24 rc = bdb->bi_id2entry->bdi_db->cursor(
25 bdb->bi_id2entry->bdi_db, NULL, &cursor, 0 );
30 /* initialize key and data thangs */
33 key.flags = DB_DBT_REALLOC;
34 data.flags = DB_DBT_REALLOC;
39 int bdb_tool_entry_close(
42 struct bdb_info *bdb = (struct bdb_info *) be->be_private;
54 cursor->c_close( cursor );
61 ID bdb_tool_entry_next(
67 assert( slapMode & SLAP_TOOL_MODE );
68 assert( cursor != NULL );
70 rc = cursor->c_get( cursor, &key, &data, DB_NEXT );
76 if( data.data == NULL ) {
80 AC_MEMCPY( &id, key.data, key.size );
84 Entry* bdb_tool_entry_get( BackendDB *be, ID id )
89 assert( slapMode & SLAP_TOOL_MODE );
90 assert( data.data != NULL );
94 rc = entry_decode( &bv, &e );
96 if( rc == LDAP_SUCCESS ) {
103 ID bdb_tool_entry_put(
108 struct bdb_info *bdb = (struct bdb_info *) be->be_private;
111 assert( slapMode & SLAP_TOOL_MODE );
113 Debug( LDAP_DEBUG_TRACE, "=> bdb_tool_entry_put( %ld, \"%s\" )\n",
114 e->e_id, e->e_dn, 0 );
116 rc = txn_begin( bdb->bi_dbenv, NULL, &tid, 0 );
121 rc = bdb_next_id( be, tid, &e->e_id );
126 /* add dn2id indices */
127 rc = bdb_dn2id_add( be, tid, e->e_ndn, e->e_id );
133 rc = bdb_id2entry_add( be, tid, e );
139 rc = bdb_index_entry_add( be, tid, e, e->e_attrs );
147 rc = txn_commit( tid, 0 );
161 int bdb_tool_entry_reindex(
165 struct bdb_dbinfo *bdi = (struct bdb_dbinfo *) be->be_private;
170 Debug( LDAP_DEBUG_ARGS, "=> bdb_tool_entry_reindex( %ld )\n",
173 rc = txn_begin( bdi->bdi_db_env, NULL, &tid, 0 );
175 e = bdb_tool_entry_get( be, tid, id );
178 Debug( LDAP_DEBUG_ANY,
179 "bdb_tool_entry_reindex:: could not locate id=%ld\n",
186 * just (re)add them for now
187 * assume that some other routine (not yet implemented)
188 * will zap index databases
192 Debug( LDAP_DEBUG_TRACE, "=> bdb_tool_entry_reindex( %ld, \"%s\" )\n",
195 rc = index_entry_add( be, e, e->e_attrs );