1 /* delete.c - ldbm backend delete routine */
11 #include "back-ldbm.h"
12 #include "proto-back-ldbm.h"
22 struct ldbminfo *li = (struct ldbminfo *) be->be_private;
29 Debug(LDAP_DEBUG_ARGS, "==> ldbm_back_delete: %s\n", dn, 0, 0);
31 /* get entry with writer lock */
32 if ( (e = dn2entry_w( be, dn, &matched )) == NULL ) {
33 Debug(LDAP_DEBUG_ARGS, "<=- ldbm_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 ( has_children( be, e ) ) {
45 Debug(LDAP_DEBUG_ARGS, "<=- ldbm_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 "<=- ldbm_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, e->e_ndn )) != NULL ) {
66 if( (p = dn2entry_w( be, pdn, &matched )) == NULL) {
67 Debug( LDAP_DEBUG_TRACE,
68 "<=- ldbm_back_delete: parent does not exist\n",
70 send_ldap_result( conn, op, LDAP_OPERATIONS_ERROR,
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 "<=- ldbm_back_delete: no access to parent\n", 0,
82 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 "<=- ldbm_back_delete: no parent & not root\n",
93 send_ldap_result( conn, op, LDAP_INSUFFICIENT_ACCESS,
98 ldap_pvt_thread_mutex_lock(&li->li_root_mutex);
102 if ( id2children_remove( be, p, e ) != 0 ) {
103 Debug(LDAP_DEBUG_ARGS,
104 "<=- ldbm_back_delete: operations error %s\n",
106 send_ldap_result( conn, op, LDAP_OPERATIONS_ERROR, "","" );
110 /* delete from dn2id mapping */
111 if ( dn2id_delete( be, e->e_ndn ) != 0 ) {
112 Debug(LDAP_DEBUG_ARGS,
113 "<=- ldbm_back_delete: operations error %s\n",
115 send_ldap_result( conn, op, LDAP_OPERATIONS_ERROR, "", "" );
119 /* delete from disk and cache */
120 if ( id2entry_delete( be, e ) != 0 ) {
121 Debug(LDAP_DEBUG_ARGS,
122 "<=- ldbm_back_delete: operations error %s\n",
124 send_ldap_result( conn, op, LDAP_OPERATIONS_ERROR, "", "" );
128 send_ldap_result( conn, op, LDAP_SUCCESS, "", "" );
132 if ( pdn != NULL ) free(pdn);
135 /* free parent and writer lock */
136 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 cache_return_entry_w( &li->li_cache, e );
147 if ( matched != NULL ) free(matched);