1 /* delete.c - ldbm backend delete routine */
3 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
5 * Copyright 1998-2005 The OpenLDAP Foundation.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted only as authorized by the OpenLDAP
12 * A copy of this license is available in the file LICENSE in the
13 * top-level directory of the distribution or, alternatively, at
14 * <http://www.OpenLDAP.org/license.html>.
21 #include <ac/string.h>
22 #include <ac/socket.h>
25 #include "back-ldbm.h"
26 #include "proto-back-ldbm.h"
34 struct ldbminfo *li = (struct ldbminfo *) op->o_bd->be_private;
39 int manageDSAit = get_manageDSAit( op );
40 AttributeDescription *children = slap_schema.si_ad_children;
41 AttributeDescription *entry = slap_schema.si_ad_entry;
43 Debug(LDAP_DEBUG_ARGS, "==> ldbm_back_delete: %s\n", op->o_req_dn.bv_val, 0, 0);
45 /* grab giant lock for writing */
46 ldap_pvt_thread_rdwr_wlock(&li->li_giant_rwlock);
49 if ( !SLAP_SHADOW( op->o_bd )) {
51 char csnbuf[LDAP_LUTIL_CSNSTR_BUFSIZE];
54 csn.bv_len = sizeof(csnbuf);
55 slap_get_csn( op, &csn, 1 );
58 /* get entry with writer lock */
59 e = dn2entry_w( op->o_bd, &op->o_req_ndn, &matched );
61 /* FIXME : dn2entry() should return non-glue entry */
62 if ( e == NULL || ( !manageDSAit && is_entry_glue( e ))) {
63 Debug(LDAP_DEBUG_ARGS, "<=- ldbm_back_delete: no such object %s\n",
64 op->o_req_dn.bv_val, 0, 0);
66 if ( matched != NULL ) {
67 rs->sr_matched = ch_strdup( matched->e_dn );
68 rs->sr_ref = is_entry_referral( matched )
69 ? get_entry_referrals( op, matched )
71 cache_return_entry_r( &li->li_cache, matched );
74 rs->sr_ref = referral_rewrite( default_referral, NULL,
75 &op->o_req_dn, LDAP_SCOPE_DEFAULT );
78 rs->sr_err = LDAP_REFERRAL;
79 rs->sr_flags |= REP_MATCHED_MUSTBEFREED | REP_REF_MUSTBEFREED;
83 /* check entry for "entry" acl */
84 if ( ! access_allowed( op, e, entry, NULL, ACL_WDEL, NULL ) )
86 Debug( LDAP_DEBUG_TRACE,
87 "<=- ldbm_back_delete: no write access to entry\n", 0,
90 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
91 rs->sr_text = "no write access to entry";
95 if ( !manageDSAit && is_entry_referral( e ) ) {
96 /* parent is a referral, don't allow add */
97 /* parent is an alias, don't allow add */
98 rs->sr_ref = get_entry_referrals( op, e );
100 Debug( LDAP_DEBUG_TRACE, "entry is referral\n", 0,
103 rs->sr_err = LDAP_REFERRAL;
104 rs->sr_matched = ch_strdup( e->e_name.bv_val );
105 rs->sr_flags = REP_MATCHED_MUSTBEFREED | REP_REF_MUSTBEFREED;
109 if ( has_children( op->o_bd, e ) ) {
110 Debug(LDAP_DEBUG_ARGS, "<=- ldbm_back_delete: non leaf %s\n",
111 op->o_req_dn.bv_val, 0, 0);
113 rs->sr_err = LDAP_NOT_ALLOWED_ON_NONLEAF;
114 rs->sr_text = "subordinate objects must be deleted first";
118 /* delete from parent's id2children entry */
119 if( !be_issuffix( op->o_bd, &e->e_nname ) && (dnParent( &e->e_nname, &pdn ),
121 if( (p = dn2entry_w( op->o_bd, &pdn, NULL )) == NULL) {
122 Debug( LDAP_DEBUG_TRACE,
123 "<=- ldbm_back_delete: parent does not exist\n",
126 rs->sr_err = LDAP_OTHER;
127 rs->sr_text = "could not locate parent of entry";
131 /* check parent for "children" acl */
132 if ( ! access_allowed( op, p,
133 children, NULL, ACL_WDEL, NULL ) )
135 Debug( LDAP_DEBUG_TRACE,
136 "<=- ldbm_back_delete: no access to parent\n", 0,
139 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
140 rs->sr_text = "no write access to parent";
145 /* no parent, must be root to delete */
146 if( ! be_isroot( op ) ) {
147 if ( be_issuffix( op->o_bd, (struct berval *)&slap_empty_bv )
148 || be_shadow_update( op ) ) {
149 p = (Entry *)&slap_entry_root;
151 rc = access_allowed( op, p,
152 children, NULL, ACL_WDEL, NULL );
155 /* check parent for "children" acl */
157 Debug( LDAP_DEBUG_TRACE,
158 "<=- ldbm_back_delete: no "
159 "access to parent\n", 0, 0, 0 );
161 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
162 rs->sr_text = "no write access to parent";
167 Debug( LDAP_DEBUG_TRACE,
168 "<=- ldbm_back_delete: no parent & "
169 "not root\n", 0, 0, 0);
171 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
177 /* delete from dn2id mapping */
178 if ( dn2id_delete( op->o_bd, &e->e_nname, e->e_id ) != 0 ) {
179 Debug(LDAP_DEBUG_ARGS,
180 "<=- ldbm_back_delete: operations error %s\n",
181 op->o_req_dn.bv_val, 0, 0);
183 rs->sr_err = LDAP_OTHER;
184 rs->sr_text = "DN index delete failed";
188 /* delete from disk and cache */
189 if ( id2entry_delete( op->o_bd, e ) != 0 ) {
190 Debug(LDAP_DEBUG_ARGS,
191 "<=- ldbm_back_delete: operations error %s\n",
192 op->o_req_dn.bv_val, 0, 0);
194 rs->sr_err = LDAP_OTHER;
195 rs->sr_text = "entry delete failed";
199 /* delete attribute indices */
200 (void) index_entry_del( op, e );
202 rs->sr_err = LDAP_SUCCESS;
208 /* free parent and writer lock */
209 cache_return_entry_w( &li->li_cache, p );
213 /* free entry and writer lock */
214 cache_return_entry_w( &li->li_cache, e );
217 ldap_pvt_thread_rdwr_wunlock(&li->li_giant_rwlock);
219 send_ldap_result( op, rs );
220 if ( !SLAP_SHADOW( op->o_bd ))
221 slap_graduate_commit_csn( op );