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;
28 Debug(LDAP_DEBUG_ARGS, "==> bdb2i_back_add: %s\n", e->e_dn, 0, 0);
30 /* nobody else can add until we lock our parent */
31 /* DDD ldap_pvt_thread_mutex_lock(&li->li_add_mutex); */
33 if ( ( bdb2i_dn2id( be, e->e_ndn ) ) != NOID ) {
34 /* DDD ldap_pvt_thread_mutex_unlock(&li->li_add_mutex); */
36 send_ldap_result( conn, op, LDAP_ALREADY_EXISTS, "", "" );
40 if ( global_schemacheck && oc_schema_check( e ) != 0 ) {
41 /* DDD ldap_pvt_thread_mutex_unlock(&li->li_add_mutex); */
43 Debug( LDAP_DEBUG_TRACE, "entry failed schema check\n",
47 send_ldap_result( conn, op, LDAP_OBJECT_CLASS_VIOLATION, "",
53 * Get the parent dn and see if the corresponding entry exists.
54 * If the parent does not exist, only allow the "root" user to
58 if ( (pdn = dn_parent( be, e->e_ndn )) != NULL ) {
61 /* get parent with writer lock */
62 if ( (p = bdb2i_dn2entry_w( be, pdn, &matched )) == NULL ) {
63 /* DDD ldap_pvt_thread_mutex_unlock(&li->li_add_mutex); */
64 Debug( LDAP_DEBUG_TRACE, "parent does not exist\n", 0,
66 send_ldap_result( conn, op, LDAP_NO_SUCH_OBJECT,
69 if ( matched != NULL ) {
78 /* don't need the add lock anymore */
79 /* DDD ldap_pvt_thread_mutex_unlock(&li->li_add_mutex); */
83 if ( matched != NULL ) {
87 if ( ! access_allowed( be, conn, op, p,
88 "children", NULL, ACL_WRITE ) )
90 Debug( LDAP_DEBUG_TRACE, "no access to parent\n", 0,
92 send_ldap_result( conn, op, LDAP_INSUFFICIENT_ACCESS,
95 /* free parent and writer lock */
96 bdb2i_cache_return_entry_w( &li->li_cache, p );
103 /* no parent, must be adding entry to root */
104 if ( ! be_isroot( be, op->o_ndn ) ) {
105 /* DDD ldap_pvt_thread_mutex_unlock(&li->li_add_mutex); */
106 Debug( LDAP_DEBUG_TRACE, "no parent & not root\n", 0,
108 send_ldap_result( conn, op, LDAP_INSUFFICIENT_ACCESS,
116 * no parent, acquire the root write lock
117 * and release the add lock.
119 /* DDD ldap_pvt_thread_mutex_lock(&li->li_root_mutex); */
121 /* DDD ldap_pvt_thread_mutex_unlock(&li->li_add_mutex); */
124 e->e_id = bdb2i_next_id( be );
127 * Try to add the entry to the cache, assign it a new dnid.
129 rc = bdb2i_cache_add_entry_rw( &li->li_cache, e, CACHE_WRITE_LOCK );
133 /* free parent and writer lock */
134 bdb2i_cache_return_entry_w( &li->li_cache, p );
138 /* release root lock */
139 /* DDD ldap_pvt_thread_mutex_unlock(&li->li_root_mutex); */
142 Debug( LDAP_DEBUG_ANY, "cache_add_entry_lock failed\n", 0, 0,
146 bdb2i_next_id_return( be, e->e_id );
152 send_ldap_result( conn, op, LDAP_ALREADY_EXISTS, "", "" );
154 send_ldap_result( conn, op, LDAP_OPERATIONS_ERROR, "", "" );
163 * add it to the id2children index for the parent
166 if ( bdb2i_id2children_add( be, p, e ) != 0 ) {
167 Debug( LDAP_DEBUG_TRACE, "bdb2i_id2children_add failed\n", 0,
169 send_ldap_result( conn, op, LDAP_OPERATIONS_ERROR, "", "" );
175 * Add the entry to the attribute indexes, then add it to
176 * the id2children index, dn2id index, and the id2entry index.
179 /* attribute indexes */
180 if ( bdb2i_index_add_entry( be, e ) != 0 ) {
181 Debug( LDAP_DEBUG_TRACE, "bdb2i_index_add_entry failed\n", 0,
183 send_ldap_result( conn, op, LDAP_OPERATIONS_ERROR, "", "" );
189 if ( bdb2i_dn2id_add( be, e->e_ndn, e->e_id ) != 0 ) {
190 Debug( LDAP_DEBUG_TRACE, "bdb2i_dn2id_add failed\n", 0,
192 send_ldap_result( conn, op, LDAP_OPERATIONS_ERROR, "", "" );
198 if ( bdb2i_id2entry_add( be, e ) != 0 ) {
199 Debug( LDAP_DEBUG_TRACE, "bdb2i_id2entry_add failed\n", 0,
201 (void) bdb2i_dn2id_delete( be, e->e_ndn );
202 send_ldap_result( conn, op, LDAP_OPERATIONS_ERROR, "", "" );
207 send_ldap_result( conn, op, LDAP_SUCCESS, "", "" );
212 /* free parent and writer lock */
213 bdb2i_cache_return_entry_w( &li->li_cache, p );
218 /* release root lock */
219 /* DDD ldap_pvt_thread_mutex_unlock(&li->li_root_mutex); */
222 /* free entry and writer lock */
223 bdb2i_cache_return_entry_w( &li->li_cache, e );
238 struct ldbminfo *li = (struct ldbminfo *) be->be_private;
239 struct timeval time1;
242 bdb2i_start_timing( be->bd_info, &time1 );
244 if ( bdb2i_enter_backend_w( get_dbenv( be ), &lock ) != 0 ) {
246 send_ldap_result( conn, op, LDAP_OPERATIONS_ERROR, "", "" );
251 /* check, if a new default attribute index will be created,
252 in which case we have to open the index file BEFORE TP */
253 switch ( slapMode ) {
254 case SLAP_SERVER_MODE:
255 case SLAP_TIMEDSERVER_MODE:
257 bdb2i_check_default_attr_index_add( li, e );
261 ret = bdb2i_back_add_internal( be, conn, op, e );
262 (void) bdb2i_leave_backend( get_dbenv( be ), lock );
263 bdb2i_stop_timing( be->bd_info, time1, "ADD", conn, op );