1 /* delete.c - bdb2 backend delete routine */
11 #include "back-bdb2.h"
12 #include "proto-back-bdb2.h"
15 bdb2i_back_delete_internal(
22 struct ldbminfo *li = (struct ldbminfo *) be->be_private;
29 Debug(LDAP_DEBUG_ARGS, "==> bdb2i_back_delete: %s\n", dn, 0, 0);
31 /* get entry with writer lock */
32 if ( (e = bdb2i_dn2entry_w( be, dn, &matched )) == NULL ) {
33 Debug(LDAP_DEBUG_ARGS, "<=- bdb2i_back_delete: no such object %s\n",
35 send_ldap_result( conn, op, LDAP_NO_SUCH_OBJECT, matched, "" );
36 if ( matched != NULL ) {
42 /* check for deleted */
44 if ( bdb2i_has_children( be, e ) ) {
45 Debug(LDAP_DEBUG_ARGS, "<=- bdb2i_back_delete: non leaf %s\n",
47 send_ldap_result( conn, op, LDAP_NOT_ALLOWED_ON_NONLEAF, "",
52 #ifdef SLAPD_CHILD_MODIFICATION_WITH_ENTRY_ACL
53 if ( ! access_allowed( be, conn, op, e,
54 "entry", NULL, ACL_WRITE ) )
56 Debug(LDAP_DEBUG_ARGS,
57 "<=- bdb2i_back_delete: insufficient access %s\n",
59 send_ldap_result( conn, op, LDAP_INSUFFICIENT_ACCESS, "", "" );
64 /* delete from parent's id2children entry */
65 if( (pdn = dn_parent( be, dn )) != NULL ) {
66 if( (p = bdb2i_dn2entry_w( be, pdn, &matched )) == NULL) {
67 Debug( LDAP_DEBUG_TRACE,
68 "<=- bdb2i_back_delete: parent does not exist\n", 0, 0, 0);
69 send_ldap_result( conn, op, LDAP_OPERATIONS_ERROR,
74 #ifndef SLAPD_CHILD_MODIFICATION_WITH_ENTRY_ACL
75 /* check parent for "children" acl */
76 if ( ! access_allowed( be, conn, op, p,
77 "children", NULL, ACL_WRITE ) )
79 Debug( LDAP_DEBUG_TRACE,
80 "<=- bdb2i_back_delete: no access to parent\n", 0, 0, 0 );
81 send_ldap_result( conn, op, LDAP_INSUFFICIENT_ACCESS,
88 /* no parent, must be root to delete */
89 if( ! be_isroot( be, op->o_ndn ) ) {
90 Debug( LDAP_DEBUG_TRACE,
91 "<=- bdb2i_back_delete: no parent & not root\n", 0, 0, 0);
92 send_ldap_result( conn, op, LDAP_INSUFFICIENT_ACCESS,
97 ldap_pvt_thread_mutex_lock(&li->li_root_mutex);
101 if ( bdb2i_id2children_remove( be, p, e ) != 0 ) {
102 Debug(LDAP_DEBUG_ARGS,
103 "<=- bdb2i_back_delete: operations error %s\n",
105 send_ldap_result( conn, op, LDAP_OPERATIONS_ERROR, "","" );
109 /* delete from dn2id mapping */
110 if ( bdb2i_dn2id_delete( be, e->e_dn ) != 0 ) {
111 Debug(LDAP_DEBUG_ARGS,
112 "<=- bdb2i_back_delete: operations error %s\n",
114 send_ldap_result( conn, op, LDAP_OPERATIONS_ERROR, "", "" );
118 /* delete from disk and cache */
119 if ( bdb2i_id2entry_delete( be, e ) != 0 ) {
120 Debug(LDAP_DEBUG_ARGS,
121 "<=- bdb2i_back_delete: operations error %s\n",
123 send_ldap_result( conn, op, LDAP_OPERATIONS_ERROR, "", "" );
127 send_ldap_result( conn, op, LDAP_SUCCESS, "", "" );
131 if ( pdn != NULL ) free(pdn);
134 /* free parent and writer lock */
135 bdb2i_cache_return_entry_w( &li->li_cache, p );
140 /* release root lock */
141 ldap_pvt_thread_mutex_unlock(&li->li_root_mutex);
144 /* free entry and writer lock */
145 bdb2i_cache_return_entry_w( &li->li_cache, e );
147 if ( matched != NULL ) free(matched);
162 struct ldbminfo *li = (struct ldbminfo *) be->be_private;
163 struct timeval time1;
166 bdb2i_start_timing( be->be_private, &time1 );
168 if ( bdb2i_enter_backend_w( get_dbenv( be ), &lock ) != 0 ) {
170 send_ldap_result( conn, op, LDAP_OPERATIONS_ERROR, "", "" );
175 ret = bdb2i_back_delete_internal( be, conn, op, dn );
176 (void) bdb2i_leave_backend( get_dbenv( be ), lock );
177 bdb2i_stop_timing( be->be_private, time1, "DEL", conn, op );