1 /* add.c - ldap bdb2 back-end add routine */
11 #include "back-bdb2.h"
12 #include "proto-back-bdb2.h"
15 bdb2i_back_add_internal(
22 struct ldbminfo *li = (struct ldbminfo *) be->be_private;
27 Debug(LDAP_DEBUG_ARGS, "==> bdb2i_back_add: %s\n", e->e_dn, 0, 0);
29 if ( ( bdb2i_dn2id( be, e->e_ndn ) ) != NOID ) {
31 send_ldap_result( conn, op, LDAP_ALREADY_EXISTS, "", "" );
35 if ( global_schemacheck && oc_schema_check( e ) != 0 ) {
36 Debug( LDAP_DEBUG_TRACE, "entry failed schema check\n",
40 send_ldap_result( conn, op, LDAP_OBJECT_CLASS_VIOLATION, "",
46 * Get the parent dn and see if the corresponding entry exists.
47 * If the parent does not exist, only allow the "root" user to
51 if ( (pdn = dn_parent( be, e->e_ndn )) != NULL ) {
54 /* get parent with writer lock */
55 if ( (p = bdb2i_dn2entry_w( be, pdn, &matched )) == NULL ) {
56 Debug( LDAP_DEBUG_TRACE, "parent does not exist\n", 0,
58 send_ldap_result( conn, op, LDAP_NO_SUCH_OBJECT,
61 if ( matched != NULL ) {
72 if ( matched != NULL ) {
76 if ( ! access_allowed( be, conn, op, p,
77 "children", NULL, ACL_WRITE ) )
79 Debug( LDAP_DEBUG_TRACE, "no access to parent\n", 0,
81 send_ldap_result( conn, op, LDAP_INSUFFICIENT_ACCESS,
84 /* free parent and writer lock */
85 bdb2i_cache_return_entry_w( &li->li_cache, p );
92 /* no parent, must be adding entry to root */
93 if ( ! be_isroot( be, op->o_ndn ) ) {
94 Debug( LDAP_DEBUG_TRACE, "no parent & not root\n", 0,
96 send_ldap_result( conn, op, LDAP_INSUFFICIENT_ACCESS,
104 e->e_id = bdb2i_next_id( be );
107 * Try to add the entry to the cache, assign it a new dnid.
109 rc = bdb2i_cache_add_entry_rw( &li->li_cache, e, CACHE_WRITE_LOCK );
113 /* free parent and writer lock */
114 bdb2i_cache_return_entry_w( &li->li_cache, p );
117 Debug( LDAP_DEBUG_ANY, "cache_add_entry_lock failed\n", 0, 0,
121 bdb2i_next_id_return( be, e->e_id );
127 send_ldap_result( conn, op, LDAP_ALREADY_EXISTS, "", "" );
129 send_ldap_result( conn, op, LDAP_OPERATIONS_ERROR, "", "" );
138 * add it to the id2children index for the parent
141 if ( bdb2i_id2children_add( be, p, e ) != 0 ) {
142 Debug( LDAP_DEBUG_TRACE, "bdb2i_id2children_add failed\n", 0,
144 send_ldap_result( conn, op, LDAP_OPERATIONS_ERROR, "", "" );
150 * Add the entry to the attribute indexes, then add it to
151 * the id2children index, dn2id index, and the id2entry index.
154 /* attribute indexes */
155 if ( bdb2i_index_add_entry( be, e ) != 0 ) {
156 Debug( LDAP_DEBUG_TRACE, "bdb2i_index_add_entry failed\n", 0,
158 send_ldap_result( conn, op, LDAP_OPERATIONS_ERROR, "", "" );
164 if ( bdb2i_dn2id_add( be, e->e_ndn, e->e_id ) != 0 ) {
165 Debug( LDAP_DEBUG_TRACE, "bdb2i_dn2id_add failed\n", 0,
167 send_ldap_result( conn, op, LDAP_OPERATIONS_ERROR, "", "" );
173 if ( bdb2i_id2entry_add( be, e ) != 0 ) {
174 Debug( LDAP_DEBUG_TRACE, "bdb2i_id2entry_add failed\n", 0,
176 (void) bdb2i_dn2id_delete( be, e->e_ndn );
177 send_ldap_result( conn, op, LDAP_OPERATIONS_ERROR, "", "" );
182 send_ldap_result( conn, op, LDAP_SUCCESS, "", "" );
187 /* free parent and writer lock */
188 bdb2i_cache_return_entry_w( &li->li_cache, p );
192 /* free entry and writer lock */
193 bdb2i_cache_return_entry_w( &li->li_cache, e );
208 struct ldbminfo *li = (struct ldbminfo *) be->be_private;
209 struct timeval time1;
212 bdb2i_start_timing( be->bd_info, &time1 );
214 if ( bdb2i_enter_backend_w( get_dbenv( be ), &lock ) != 0 ) {
216 send_ldap_result( conn, op, LDAP_OPERATIONS_ERROR, "", "" );
221 /* check, if a new default attribute index will be created,
222 in which case we have to open the index file BEFORE TP */
223 switch ( slapMode ) {
224 case SLAP_SERVER_MODE:
225 case SLAP_TIMEDSERVER_MODE:
227 bdb2i_check_default_attr_index_add( li, e );
231 ret = bdb2i_back_add_internal( be, conn, op, e );
232 (void) bdb2i_leave_backend( get_dbenv( be ), lock );
233 bdb2i_stop_timing( be->bd_info, time1, "ADD", conn, op );