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, e->e_ndn )) != 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 /* check parent for "children" acl */
74 if ( ! access_allowed( be, conn, op, p,
75 "children", NULL, ACL_WRITE ) )
77 Debug( LDAP_DEBUG_TRACE,
78 "<=- bdb2i_back_delete: no access to parent\n", 0, 0, 0 );
79 send_ldap_result( conn, op, LDAP_INSUFFICIENT_ACCESS,
85 /* no parent, must be root to delete */
86 if( ! be_isroot( be, op->o_ndn ) ) {
87 Debug( LDAP_DEBUG_TRACE,
88 "<=- bdb2i_back_delete: no parent & not root\n", 0, 0, 0);
89 send_ldap_result( conn, op, LDAP_INSUFFICIENT_ACCESS,
95 if ( bdb2i_id2children_remove( be, p, e ) != 0 ) {
96 Debug(LDAP_DEBUG_ARGS,
97 "<=- bdb2i_back_delete: operations error %s\n",
99 send_ldap_result( conn, op, LDAP_OPERATIONS_ERROR, "","" );
103 /* delete from dn2id mapping */
104 if ( bdb2i_dn2id_delete( be, e->e_ndn ) != 0 ) {
105 Debug(LDAP_DEBUG_ARGS,
106 "<=- bdb2i_back_delete: operations error %s\n",
108 send_ldap_result( conn, op, LDAP_OPERATIONS_ERROR, "", "" );
112 /* delete from disk and cache */
113 if ( bdb2i_id2entry_delete( be, e ) != 0 ) {
114 Debug(LDAP_DEBUG_ARGS,
115 "<=- bdb2i_back_delete: operations error %s\n",
117 send_ldap_result( conn, op, LDAP_OPERATIONS_ERROR, "", "" );
121 send_ldap_result( conn, op, LDAP_SUCCESS, "", "" );
125 if ( pdn != NULL ) free(pdn);
128 /* free parent and writer lock */
129 bdb2i_cache_return_entry_w( &li->li_cache, p );
133 /* free entry and writer lock */
134 bdb2i_cache_return_entry_w( &li->li_cache, e );
136 if ( matched != NULL ) free(matched);
151 struct ldbminfo *li = (struct ldbminfo *) be->be_private;
152 struct timeval time1;
155 bdb2i_start_timing( be->bd_info, &time1 );
157 if ( bdb2i_enter_backend_w( &lock ) != 0 ) {
159 send_ldap_result( conn, op, LDAP_OPERATIONS_ERROR, "", "" );
164 ret = bdb2i_back_delete_internal( be, conn, op, dn );
165 (void) bdb2i_leave_backend_w( lock );
166 bdb2i_stop_timing( be->bd_info, time1, "DEL", conn, op );