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 Debug (LDAP_DEBUG_TRACE,
43 "rdwr_Xchk: readers_reading: %d writer_writing: %d\n",
44 e->e_rdwr.readers_reading, e->e_rdwr.writer_writing, 0);
46 /* check for deleted */
48 if ( has_children( be, e ) ) {
49 Debug(LDAP_DEBUG_ARGS, "<=- ldbm_back_delete: non leaf %s\n",
51 send_ldap_result( conn, op, LDAP_NOT_ALLOWED_ON_NONLEAF, "",
56 #ifdef SLAPD_CHILD_MODIFICATION_WITH_ENTRY_ACL
57 if ( ! access_allowed( be, conn, op, e, "entry", NULL, op->o_dn,
59 Debug(LDAP_DEBUG_ARGS,
60 "<=- ldbm_back_delete: insufficient access %s\n",
62 send_ldap_result( conn, op, LDAP_INSUFFICIENT_ACCESS, "", "" );
67 Debug (LDAP_DEBUG_TRACE,
68 "rdwr_Xchk: readers_reading: %d writer_writing: %d\n",
69 e->e_rdwr.readers_reading, e->e_rdwr.writer_writing, 0);
71 /* delete from parent's id2children entry */
72 if( (pdn = dn_parent( be, dn )) != NULL ) {
73 if( (p = dn2entry_w( be, pdn, &matched )) == NULL) {
74 Debug( LDAP_DEBUG_TRACE, "parent does not exist\n",
76 send_ldap_result( conn, op, LDAP_OPERATIONS_ERROR,
81 #ifndef SLAPD_CHILD_MODIFICATION_WITH_ENTRY_ACL
82 /* check parent for "children" acl */
83 if ( ! access_allowed( be, conn, op, p, "children", NULL,
84 op->o_dn, ACL_WRITE ) )
86 Debug( LDAP_DEBUG_TRACE, "no access to parent\n", 0,
88 send_ldap_result( conn, op, LDAP_INSUFFICIENT_ACCESS,
95 /* no parent, must be root to delete */
96 if( ! be_isroot( be, op->o_dn ) ) {
97 Debug( LDAP_DEBUG_TRACE, "no parent & not root\n",
99 send_ldap_result( conn, op, LDAP_INSUFFICIENT_ACCESS,
104 pthread_mutex_lock(&li->li_root_mutex);
108 if ( id2children_remove( be, p, e ) != 0 ) {
109 Debug(LDAP_DEBUG_ARGS,
110 "<=- ldbm_back_delete: operations error %s\n",
112 send_ldap_result( conn, op, LDAP_OPERATIONS_ERROR, "","" );
116 /* delete from dn2id mapping */
117 if ( dn2id_delete( be, e->e_dn ) != 0 ) {
118 Debug(LDAP_DEBUG_ARGS,
119 "<=- ldbm_back_delete: operations error %s\n",
121 send_ldap_result( conn, op, LDAP_OPERATIONS_ERROR, "", "" );
125 /* delete from disk and cache */
126 if ( id2entry_delete( be, e ) != 0 ) {
127 Debug(LDAP_DEBUG_ARGS,
128 "<=- ldbm_back_delete: operations error %s\n",
130 send_ldap_result( conn, op, LDAP_OPERATIONS_ERROR, "", "" );
134 send_ldap_result( conn, op, LDAP_SUCCESS, "", "" );
138 if ( pdn != NULL ) free(pdn);
141 /* free parent and writer lock */
142 cache_return_entry_w( &li->li_cache, p );
144 } else if ( rootlock ) {
145 /* release root lock */
146 pthread_mutex_unlock(&li->li_root_mutex);
149 /* free entry and writer lock */
150 cache_return_entry_w( &li->li_cache, e );
152 if ( matched != NULL ) free(matched);