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 #ifndef SLAPD_CHILD_MODIFICATION_WITH_ENTRY_ACL
76 /* check parent for "children" acl */
77 if ( ! access_allowed( be, conn, op, p,
78 "children", NULL, ACL_WRITE ) )
80 Debug( LDAP_DEBUG_TRACE,
81 "<=- ldbm_back_delete: no access to parent\n", 0,
83 send_ldap_result( conn, op, LDAP_INSUFFICIENT_ACCESS,
90 /* no parent, must be root to delete */
91 if( ! be_isroot( be, op->o_ndn ) ) {
92 Debug( LDAP_DEBUG_TRACE,
93 "<=- ldbm_back_delete: no parent & not root\n",
95 send_ldap_result( conn, op, LDAP_INSUFFICIENT_ACCESS,
100 ldap_pvt_thread_mutex_lock(&li->li_root_mutex);
104 if ( id2children_remove( be, p, e ) != 0 ) {
105 Debug(LDAP_DEBUG_ARGS,
106 "<=- ldbm_back_delete: operations error %s\n",
108 send_ldap_result( conn, op, LDAP_OPERATIONS_ERROR, "","" );
112 /* delete from dn2id mapping */
113 if ( dn2id_delete( be, e->e_ndn ) != 0 ) {
114 Debug(LDAP_DEBUG_ARGS,
115 "<=- ldbm_back_delete: operations error %s\n",
117 send_ldap_result( conn, op, LDAP_OPERATIONS_ERROR, "", "" );
121 /* delete from disk and cache */
122 if ( id2entry_delete( be, e ) != 0 ) {
123 Debug(LDAP_DEBUG_ARGS,
124 "<=- ldbm_back_delete: operations error %s\n",
126 send_ldap_result( conn, op, LDAP_OPERATIONS_ERROR, "", "" );
130 send_ldap_result( conn, op, LDAP_SUCCESS, "", "" );
134 if ( pdn != NULL ) free(pdn);
137 /* free parent and writer lock */
138 cache_return_entry_w( &li->li_cache, p );
142 /* release root lock */
143 ldap_pvt_thread_mutex_unlock(&li->li_root_mutex);
146 /* free entry and writer lock */
147 cache_return_entry_w( &li->li_cache, e );
149 if ( matched != NULL ) free(matched);