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 if ( ( bdb2i_dn2id( be, e->e_ndn ) ) != NOID ) {
32 send_ldap_result( conn, op, LDAP_ALREADY_EXISTS, "", "" );
36 if ( global_schemacheck && oc_schema_check( e ) != 0 ) {
37 Debug( LDAP_DEBUG_TRACE, "entry failed schema check\n",
41 send_ldap_result( conn, op, LDAP_OBJECT_CLASS_VIOLATION, "",
47 * Get the parent dn and see if the corresponding entry exists.
48 * If the parent does not exist, only allow the "root" user to
52 if ( (pdn = dn_parent( be, e->e_ndn )) != NULL ) {
55 /* get parent with writer lock */
56 if ( (p = bdb2i_dn2entry_w( be, pdn, &matched )) == NULL ) {
57 Debug( LDAP_DEBUG_TRACE, "parent does not exist\n", 0,
59 send_ldap_result( conn, op, LDAP_NO_SUCH_OBJECT,
62 if ( matched != NULL ) {
73 if ( matched != NULL ) {
77 if ( ! access_allowed( be, conn, op, p,
78 "children", NULL, ACL_WRITE ) )
80 Debug( LDAP_DEBUG_TRACE, "no access to parent\n", 0,
82 send_ldap_result( conn, op, LDAP_INSUFFICIENT_ACCESS,
85 /* free parent and writer lock */
86 bdb2i_cache_return_entry_w( &li->li_cache, p );
93 /* no parent, must be adding entry to root */
94 if ( ! be_isroot( be, op->o_ndn ) ) {
95 Debug( LDAP_DEBUG_TRACE, "no parent & not root\n", 0,
97 send_ldap_result( conn, op, LDAP_INSUFFICIENT_ACCESS,
105 e->e_id = bdb2i_next_id( be );
108 * Try to add the entry to the cache, assign it a new dnid.
110 bdb2i_start_timing( be->bd_info, &time1 );
112 rc = bdb2i_cache_add_entry_rw( &li->li_cache, e, CACHE_WRITE_LOCK );
114 bdb2i_stop_timing( be->bd_info, time1, "ADD-CACHE", conn, op );
118 /* free parent and writer lock */
119 bdb2i_cache_return_entry_w( &li->li_cache, p );
122 Debug( LDAP_DEBUG_ANY, "cache_add_entry_lock failed\n", 0, 0,
126 bdb2i_next_id_return( be, e->e_id );
132 send_ldap_result( conn, op, LDAP_ALREADY_EXISTS, "", "" );
134 send_ldap_result( conn, op, LDAP_OPERATIONS_ERROR, "", "" );
143 * add it to the id2children index for the parent
146 bdb2i_start_timing( be->bd_info, &time1 );
148 if ( bdb2i_id2children_add( be, p, e ) != 0 ) {
149 Debug( LDAP_DEBUG_TRACE, "bdb2i_id2children_add failed\n", 0,
151 send_ldap_result( conn, op, LDAP_OPERATIONS_ERROR, "", "" );
153 bdb2i_stop_timing( be->bd_info, time1, "ADD-ID2CHILDREN", conn, op );
158 bdb2i_stop_timing( be->bd_info, time1, "ADD-ID2CHILDREN", conn, op );
161 * Add the entry to the attribute indexes, then add it to
162 * the id2children index, dn2id index, and the id2entry index.
165 bdb2i_start_timing( be->bd_info, &time1 );
167 /* attribute indexes */
168 if ( bdb2i_index_add_entry( be, e ) != 0 ) {
169 Debug( LDAP_DEBUG_TRACE, "bdb2i_index_add_entry failed\n", 0,
171 send_ldap_result( conn, op, LDAP_OPERATIONS_ERROR, "", "" );
173 bdb2i_stop_timing( be->bd_info, time1, "ADD-INDEX", conn, op );
178 bdb2i_stop_timing( be->bd_info, time1, "ADD-INDEX", conn, op );
180 bdb2i_start_timing( be->bd_info, &time1 );
183 if ( bdb2i_dn2id_add( be, e->e_ndn, e->e_id ) != 0 ) {
184 Debug( LDAP_DEBUG_TRACE, "bdb2i_dn2id_add failed\n", 0,
186 send_ldap_result( conn, op, LDAP_OPERATIONS_ERROR, "", "" );
188 bdb2i_stop_timing( be->bd_info, time1, "ADD-DN2ID", conn, op );
193 bdb2i_stop_timing( be->bd_info, time1, "ADD-DN2ID", conn, op );
195 bdb2i_start_timing( be->bd_info, &time1 );
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, "", "" );
204 bdb2i_stop_timing( be->bd_info, time1, "ADD-ID2ENTRY", conn, op );
209 bdb2i_stop_timing( be->bd_info, time1, "ADD-ID2ENTRY", conn, op );
211 send_ldap_result( conn, op, LDAP_SUCCESS, "", "" );
216 /* free parent and writer lock */
217 bdb2i_cache_return_entry_w( &li->li_cache, p );
221 /* free entry and writer lock */
222 bdb2i_cache_return_entry_w( &li->li_cache, e );
238 struct ldbminfo *li = (struct ldbminfo *) be->be_private;
239 struct timeval time1, time2;
242 bdb2i_start_timing( be->bd_info, &time1 );
244 if ( bdb2i_enter_backend_w( &lock ) != 0 ) {
246 send_ldap_result( conn, op, LDAP_OPERATIONS_ERROR, "", "" );
251 bdb2i_start_timing( be->bd_info, &time2 );
253 /* check, if a new default attribute index will be created,
254 in which case we have to open the index file BEFORE TP */
255 switch ( slapMode ) {
256 case SLAP_SERVER_MODE:
257 case SLAP_TIMEDSERVER_MODE:
259 case SLAP_TOOLID_MODE:
260 bdb2i_check_default_attr_index_add( li, e );
264 ret = bdb2i_back_add_internal( be, conn, op, e );
265 bdb2i_stop_timing( be->bd_info, time2, "ADD-INTERN", conn, op );
266 (void) bdb2i_leave_backend_w( lock );
267 bdb2i_stop_timing( be->bd_info, time1, "ADD", conn, op );