1 /* add.c - ldap bdb2 back-end add routine */
11 #include "back-bdb2.h"
12 #include "proto-back-bdb2.h"
18 bdb2i_back_add_internal(
25 struct ldbminfo *li = (struct ldbminfo *) be->be_private;
31 Debug(LDAP_DEBUG_ARGS, "==> bdb2i_back_add: %s\n", e->e_dn, 0, 0);
33 if ( ( bdb2i_dn2id( be, e->e_ndn ) ) != NOID ) {
35 send_ldap_result( conn, op, LDAP_ALREADY_EXISTS, "", "" );
39 if ( global_schemacheck && oc_schema_check( e ) != 0 ) {
40 Debug( LDAP_DEBUG_TRACE, "entry failed schema check\n",
44 send_ldap_result( conn, op, LDAP_OBJECT_CLASS_VIOLATION, "",
50 * Get the parent dn and see if the corresponding entry exists.
51 * If the parent does not exist, only allow the "root" user to
55 if ( (pdn = dn_parent( be, e->e_ndn )) != NULL ) {
58 /* get parent with writer lock */
59 if ( (p = bdb2i_dn2entry_w( be, pdn, &matched )) == NULL ) {
60 Debug( LDAP_DEBUG_TRACE, "parent does not exist\n", 0,
62 send_ldap_result( conn, op, LDAP_NO_SUCH_OBJECT,
65 if ( matched != NULL ) {
76 if ( matched != NULL ) {
80 if ( ! access_allowed( be, conn, op, p,
81 "children", NULL, ACL_WRITE ) )
83 Debug( LDAP_DEBUG_TRACE, "no access to parent\n", 0,
85 send_ldap_result( conn, op, LDAP_INSUFFICIENT_ACCESS,
88 /* free parent and writer lock */
89 bdb2i_cache_return_entry_w( &li->li_cache, p );
96 /* no parent, must be adding entry to root */
97 if ( ! be_isroot( be, op->o_ndn ) ) {
98 Debug( LDAP_DEBUG_TRACE, "no parent & not root\n", 0,
100 send_ldap_result( conn, op, LDAP_INSUFFICIENT_ACCESS,
108 e->e_id = bdb2i_next_id( be );
111 * Try to add the entry to the cache, assign it a new dnid.
113 bdb2i_start_timing( be->bd_info, &time1 );
115 rc = bdb2i_cache_add_entry_rw( &li->li_cache, e, CACHE_WRITE_LOCK );
117 bdb2i_stop_timing( be->bd_info, time1, "ADD-CACHE", conn, op );
121 /* free parent and writer lock */
122 bdb2i_cache_return_entry_w( &li->li_cache, p );
125 Debug( LDAP_DEBUG_ANY, "cache_add_entry_lock failed\n", 0, 0,
129 bdb2i_next_id_return( be, e->e_id );
135 send_ldap_result( conn, op, LDAP_ALREADY_EXISTS, "", "" );
137 send_ldap_result( conn, op, LDAP_OPERATIONS_ERROR, "", "" );
146 * add it to the id2children index for the parent
149 bdb2i_start_timing( be->bd_info, &time1 );
151 if ( bdb2i_id2children_add( be, p, e ) != 0 ) {
152 Debug( LDAP_DEBUG_TRACE, "bdb2i_id2children_add failed\n", 0,
154 send_ldap_result( conn, op, LDAP_OPERATIONS_ERROR, "", "" );
156 bdb2i_stop_timing( be->bd_info, time1, "ADD-ID2CHILDREN", conn, op );
161 bdb2i_stop_timing( be->bd_info, time1, "ADD-ID2CHILDREN", conn, op );
164 * Add the entry to the attribute indexes, then add it to
165 * the id2children index, dn2id index, and the id2entry index.
168 bdb2i_start_timing( be->bd_info, &time1 );
170 /* attribute indexes */
171 if ( bdb2i_index_add_entry( be, e ) != 0 ) {
172 Debug( LDAP_DEBUG_TRACE, "bdb2i_index_add_entry failed\n", 0,
174 send_ldap_result( conn, op, LDAP_OPERATIONS_ERROR, "", "" );
176 bdb2i_stop_timing( be->bd_info, time1, "ADD-INDEX", conn, op );
181 bdb2i_stop_timing( be->bd_info, time1, "ADD-INDEX", conn, op );
183 bdb2i_start_timing( be->bd_info, &time1 );
186 if ( bdb2i_dn2id_add( be, e->e_ndn, e->e_id ) != 0 ) {
187 Debug( LDAP_DEBUG_TRACE, "bdb2i_dn2id_add failed\n", 0,
189 send_ldap_result( conn, op, LDAP_OPERATIONS_ERROR, "", "" );
191 bdb2i_stop_timing( be->bd_info, time1, "ADD-DN2ID", conn, op );
196 bdb2i_stop_timing( be->bd_info, time1, "ADD-DN2ID", conn, op );
198 bdb2i_start_timing( be->bd_info, &time1 );
201 if ( bdb2i_id2entry_add( be, e ) != 0 ) {
202 Debug( LDAP_DEBUG_TRACE, "bdb2i_id2entry_add failed\n", 0,
204 (void) bdb2i_dn2id_delete( be, e->e_ndn );
205 send_ldap_result( conn, op, LDAP_OPERATIONS_ERROR, "", "" );
207 bdb2i_stop_timing( be->bd_info, time1, "ADD-ID2ENTRY", conn, op );
212 bdb2i_stop_timing( be->bd_info, time1, "ADD-ID2ENTRY", conn, op );
214 send_ldap_result( conn, op, LDAP_SUCCESS, "", "" );
219 /* free parent and writer lock */
220 bdb2i_cache_return_entry_w( &li->li_cache, p );
224 /* free entry and writer lock */
225 bdb2i_cache_return_entry_w( &li->li_cache, e );
240 struct ldbminfo *li = (struct ldbminfo *) be->be_private;
241 struct timeval time1;
244 bdb2i_start_timing( be->bd_info, &time1 );
246 if ( bdb2i_enter_backend_w( &lock ) != 0 ) {
248 send_ldap_result( conn, op, LDAP_OPERATIONS_ERROR, "", "" );
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 );
266 /* if the operation was successful, we will delay the unlock */
268 (void) bdb2i_leave_backend_w( lock );
270 bdb2i_stop_timing( be->bd_info, time1, "ADD", conn, op );
277 bdb2i_release_add_lock( void )
279 (void) bdb2i_leave_backend_w( lock );