1 /* id2entry.c - routines to deal with the id2entry database */
4 * Copyright 1998-2000 The OpenLDAP Foundation, All Rights Reserved.
5 * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
11 #include <ac/string.h>
21 struct bdb_info *bdb = (struct bdb_info *) be->be_private;
22 DB *db = bdb->bi_id2entry->bdi_db;
29 /* We only store rdns, and they go in the id2parent database. */
31 odn = e->e_dn; ondn = e->e_ndn;
33 e->e_dn = ""; e->e_ndn = "";
36 key.data = (char *) &e->e_id;
37 key.size = sizeof(ID);
39 rc = entry_encode( e, &bv );
41 e->e_dn = odn; e->e_ndn = ondn;
43 if( rc != LDAP_SUCCESS ) {
50 rc = db->put( db, tid, &key, &data, flag );
61 return bdb_id2entry_put(be, tid, e, DB_NOOVERWRITE);
64 int bdb_id2entry_update(
69 return bdb_id2entry_put(be, tid, e, 0);
78 struct bdb_info *bdb = (struct bdb_info *) be->be_private;
79 DB *db = bdb->bi_id2entry->bdi_db;
87 key.data = (char *) &id;
88 key.size = sizeof(ID);
91 data.flags = DB_DBT_MALLOC;
94 rc = db->get( db, tid, &key, &data, bdb->bi_db_opflags );
100 DBT2bv( &data, &bv );
102 rc = entry_decode( &bv, e );
107 /* only free on error. On success, the entry was
110 ch_free( data.data );
113 bdb_fix_dn(be, id, *e);
118 int bdb_id2entry_delete(
123 struct bdb_info *bdb = (struct bdb_info *) be->be_private;
124 DB *db = bdb->bi_id2entry->bdi_db;
129 key.data = (char *) &id;
130 key.size = sizeof(ID);
132 rc = db->del( db, tid, &key, 0 );
137 int bdb_entry_return(
141 /* Our entries are allocated in two blocks; the data comes from
142 * the db itself and the Entry structure and associated pointers
143 * are allocated in entry_decode. The db data pointer is saved
144 * in e_private. Since the Entry structure is allocated as a single
145 * block, e_attrs is always a fixed offset from e. The exception
146 * is when an entry has been modified, in which case we also need
149 if( (void *) e->e_attrs != (void *) (e+1)) {
150 attrs_free( e->e_attrs );
153 /* We had to construct the dn and ndn as well, in a single block */
156 /* In tool mode the e_private buffer is realloc'd, leave it alone */
157 if( e->e_private && !(slapMode & SLAP_TOOL_MODE) ) {
158 free( e->e_private );
166 int bdb_entry_release(
173 if (o && o->o_tag == LDAP_REQ_ADD)
176 return bdb_entry_return( be, e );