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 pdn = dn_parent( be, e->e_ndn );
57 if( pdn != NULL && *pdn != '\0' && !be_issuffix(be, "") ) {
60 assert( *pdn != '\0' );
62 /* get parent with writer lock */
63 if ( (p = bdb2i_dn2entry_w( be, pdn, &matched )) == NULL ) {
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 ) {
80 if ( matched != NULL ) {
84 if ( ! access_allowed( be, conn, op, p,
85 "children", NULL, ACL_WRITE ) )
87 Debug( LDAP_DEBUG_TRACE, "no access to parent\n", 0,
89 send_ldap_result( conn, op, LDAP_INSUFFICIENT_ACCESS,
92 /* free parent and writer lock */
93 bdb2i_cache_return_entry_w( &li->li_cache, p );
101 assert( *pdn == '\0' );
105 /* no parent, must be adding entry to root */
106 if ( ! be_isroot( be, op->o_ndn ) ) {
107 Debug( LDAP_DEBUG_TRACE, "%s add denied\n",
108 pdn == NULL ? "suffix" : "entry at root",
111 send_ldap_result( conn, op, LDAP_INSUFFICIENT_ACCESS,
119 e->e_id = bdb2i_next_id( be );
122 * Try to add the entry to the cache, assign it a new dnid.
124 bdb2i_start_timing( be->bd_info, &time1 );
126 rc = bdb2i_cache_add_entry_rw( &li->li_cache, e, CACHE_WRITE_LOCK );
128 bdb2i_stop_timing( be->bd_info, time1, "ADD-CACHE", conn, op );
132 /* free parent and writer lock */
133 bdb2i_cache_return_entry_w( &li->li_cache, p );
136 Debug( LDAP_DEBUG_ANY, "cache_add_entry_lock failed\n", 0, 0,
140 bdb2i_next_id_return( be, e->e_id );
146 send_ldap_result( conn, op, LDAP_ALREADY_EXISTS, "", "" );
148 send_ldap_result( conn, op, LDAP_OPERATIONS_ERROR, "", "" );
157 * add it to the id2children index for the parent
160 bdb2i_start_timing( be->bd_info, &time1 );
162 if ( bdb2i_id2children_add( be, p, e ) != 0 ) {
163 Debug( LDAP_DEBUG_TRACE, "bdb2i_id2children_add failed\n", 0,
165 send_ldap_result( conn, op, LDAP_OPERATIONS_ERROR, "", "" );
167 bdb2i_stop_timing( be->bd_info, time1, "ADD-ID2CHILDREN", conn, op );
172 bdb2i_stop_timing( be->bd_info, time1, "ADD-ID2CHILDREN", conn, op );
175 * Add the entry to the attribute indexes, then add it to
176 * the id2children index, dn2id index, and the id2entry index.
179 bdb2i_start_timing( be->bd_info, &time1 );
181 /* attribute indexes */
182 if ( bdb2i_index_add_entry( be, e ) != 0 ) {
183 Debug( LDAP_DEBUG_TRACE, "bdb2i_index_add_entry failed\n", 0,
185 send_ldap_result( conn, op, LDAP_OPERATIONS_ERROR, "", "" );
187 bdb2i_stop_timing( be->bd_info, time1, "ADD-INDEX", conn, op );
192 bdb2i_stop_timing( be->bd_info, time1, "ADD-INDEX", conn, op );
194 bdb2i_start_timing( be->bd_info, &time1 );
197 if ( bdb2i_dn2id_add( be, e->e_ndn, e->e_id ) != 0 ) {
198 Debug( LDAP_DEBUG_TRACE, "bdb2i_dn2id_add failed\n", 0,
200 send_ldap_result( conn, op, LDAP_OPERATIONS_ERROR, "", "" );
202 bdb2i_stop_timing( be->bd_info, time1, "ADD-DN2ID", conn, op );
207 bdb2i_stop_timing( be->bd_info, time1, "ADD-DN2ID", conn, op );
209 bdb2i_start_timing( be->bd_info, &time1 );
212 if ( bdb2i_id2entry_add( be, e ) != 0 ) {
213 Debug( LDAP_DEBUG_TRACE, "bdb2i_id2entry_add failed\n", 0,
215 (void) bdb2i_dn2id_delete( be, e->e_ndn );
216 send_ldap_result( conn, op, LDAP_OPERATIONS_ERROR, "", "" );
218 bdb2i_stop_timing( be->bd_info, time1, "ADD-ID2ENTRY", conn, op );
223 bdb2i_stop_timing( be->bd_info, time1, "ADD-ID2ENTRY", conn, op );
225 send_ldap_result( conn, op, LDAP_SUCCESS, "", "" );
230 /* free parent and writer lock */
231 bdb2i_cache_return_entry_w( &li->li_cache, p );
235 /* free entry and writer lock */
236 bdb2i_cache_return_entry_w( &li->li_cache, e );
251 struct ldbminfo *li = (struct ldbminfo *) be->be_private;
252 struct timeval time1;
255 bdb2i_start_timing( be->bd_info, &time1 );
257 if ( bdb2i_enter_backend_w( &lock ) != 0 ) {
259 send_ldap_result( conn, op, LDAP_OPERATIONS_ERROR, "", "" );
264 /* check, if a new default attribute index will be created,
265 in which case we have to open the index file BEFORE TP */
266 switch ( slapMode ) {
267 case SLAP_SERVER_MODE:
268 case SLAP_TIMEDSERVER_MODE:
270 case SLAP_TOOLID_MODE:
271 bdb2i_check_default_attr_index_add( li, e );
275 ret = bdb2i_back_add_internal( be, conn, op, e );
277 /* if the operation was successful, we will delay the unlock */
279 (void) bdb2i_leave_backend_w( lock );
281 bdb2i_stop_timing( be->bd_info, time1, "ADD", conn, op );
288 bdb2i_release_add_lock( void )
290 (void) bdb2i_leave_backend_w( lock );