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;
28 Debug(LDAP_DEBUG_ARGS, "==> bdb2i_back_delete: %s\n", dn, 0, 0);
30 /* get entry with writer lock */
31 if ( (e = bdb2i_dn2entry_w( be, dn, &matched )) == NULL ) {
32 Debug(LDAP_DEBUG_ARGS, "<=- bdb2i_back_delete: no such object %s\n",
34 send_ldap_result( conn, op, LDAP_NO_SUCH_OBJECT, matched, "" );
35 if ( matched != NULL ) {
41 /* check for deleted */
43 if ( bdb2i_has_children( be, e ) ) {
44 Debug(LDAP_DEBUG_ARGS, "<=- bdb2i_back_delete: non leaf %s\n",
46 send_ldap_result( conn, op, LDAP_NOT_ALLOWED_ON_NONLEAF, "",
51 #ifdef SLAPD_CHILD_MODIFICATION_WITH_ENTRY_ACL
52 if ( ! access_allowed( be, conn, op, e,
53 "entry", NULL, ACL_WRITE ) )
55 Debug(LDAP_DEBUG_ARGS,
56 "<=- bdb2i_back_delete: insufficient access %s\n",
58 send_ldap_result( conn, op, LDAP_INSUFFICIENT_ACCESS, "", "" );
63 /* delete from parent's id2children entry */
64 if( (pdn = dn_parent( be, dn )) != NULL ) {
65 if( (p = bdb2i_dn2entry_w( be, pdn, &matched )) == NULL) {
66 Debug( LDAP_DEBUG_TRACE,
67 "<=- bdb2i_back_delete: parent does not exist\n", 0, 0, 0);
68 send_ldap_result( conn, op, LDAP_OPERATIONS_ERROR,
73 #ifndef SLAPD_CHILD_MODIFICATION_WITH_ENTRY_ACL
74 /* check parent for "children" acl */
75 if ( ! access_allowed( be, conn, op, p,
76 "children", NULL, ACL_WRITE ) )
78 Debug( LDAP_DEBUG_TRACE,
79 "<=- bdb2i_back_delete: no access to parent\n", 0, 0, 0 );
80 send_ldap_result( conn, op, LDAP_INSUFFICIENT_ACCESS,
87 /* no parent, must be root to delete */
88 if( ! be_isroot( be, op->o_ndn ) ) {
89 Debug( LDAP_DEBUG_TRACE,
90 "<=- bdb2i_back_delete: no parent & not root\n", 0, 0, 0);
91 send_ldap_result( conn, op, LDAP_INSUFFICIENT_ACCESS,
97 if ( bdb2i_id2children_remove( be, p, e ) != 0 ) {
98 Debug(LDAP_DEBUG_ARGS,
99 "<=- bdb2i_back_delete: operations error %s\n",
101 send_ldap_result( conn, op, LDAP_OPERATIONS_ERROR, "","" );
105 /* delete from dn2id mapping */
106 if ( bdb2i_dn2id_delete( be, e->e_dn ) != 0 ) {
107 Debug(LDAP_DEBUG_ARGS,
108 "<=- bdb2i_back_delete: operations error %s\n",
110 send_ldap_result( conn, op, LDAP_OPERATIONS_ERROR, "", "" );
114 /* delete from disk and cache */
115 if ( bdb2i_id2entry_delete( be, e ) != 0 ) {
116 Debug(LDAP_DEBUG_ARGS,
117 "<=- bdb2i_back_delete: operations error %s\n",
119 send_ldap_result( conn, op, LDAP_OPERATIONS_ERROR, "", "" );
123 send_ldap_result( conn, op, LDAP_SUCCESS, "", "" );
127 if ( pdn != NULL ) free(pdn);
130 /* free parent and writer lock */
131 bdb2i_cache_return_entry_w( &li->li_cache, p );
135 /* free entry and writer lock */
136 bdb2i_cache_return_entry_w( &li->li_cache, e );
138 if ( matched != NULL ) free(matched);
153 struct ldbminfo *li = (struct ldbminfo *) be->be_private;
154 struct timeval time1;
157 bdb2i_start_timing( be->bd_info, &time1 );
159 if ( bdb2i_enter_backend_w( get_dbenv( be ), &lock ) != 0 ) {
161 send_ldap_result( conn, op, LDAP_OPERATIONS_ERROR, "", "" );
166 ret = bdb2i_back_delete_internal( be, conn, op, dn );
167 (void) bdb2i_leave_backend( get_dbenv( be ), lock );
168 bdb2i_stop_timing( be->bd_info, time1, "DEL", conn, op );