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"
33 struct ldbminfo *li = (struct ldbminfo *) op->o_bd->be_private;
38 int manageDSAit = get_manageDSAit( op );
39 AttributeDescription *children = slap_schema.si_ad_children;
40 AttributeDescription *entry = slap_schema.si_ad_entry;
42 Debug(LDAP_DEBUG_ARGS, "==> ldbm_back_delete: %s\n", op->o_req_dn.bv_val, 0, 0);
44 /* grab giant lock for writing */
45 ldap_pvt_thread_rdwr_wlock(&li->li_giant_rwlock);
48 if ( !SLAP_SHADOW( op->o_bd )) {
50 char csnbuf[LDAP_LUTIL_CSNSTR_BUFSIZE];
53 csn.bv_len = sizeof(csnbuf);
54 slap_get_csn( op, &csn, 1 );
57 /* get entry with writer lock */
58 e = dn2entry_w( op->o_bd, &op->o_req_ndn, &matched );
60 /* FIXME : dn2entry() should return non-glue entry */
61 if ( e == NULL || ( !manageDSAit && is_entry_glue( e ))) {
62 Debug(LDAP_DEBUG_ARGS, "<=- ldbm_back_delete: no such object %s\n",
63 op->o_req_dn.bv_val, 0, 0);
65 if ( matched != NULL ) {
66 rs->sr_matched = ch_strdup( matched->e_dn );
67 rs->sr_ref = is_entry_referral( matched )
68 ? get_entry_referrals( op, matched )
70 cache_return_entry_r( &li->li_cache, matched );
73 rs->sr_ref = referral_rewrite( default_referral, NULL,
74 &op->o_req_dn, LDAP_SCOPE_DEFAULT );
77 rs->sr_err = LDAP_REFERRAL;
78 rs->sr_flags |= REP_MATCHED_MUST_BE_FREED | REP_REF_MUSTBEFREED;
82 /* check entry for "entry" acl */
83 if ( ! access_allowed( op, e, entry, NULL, ACL_WDEL, NULL ) )
85 Debug( LDAP_DEBUG_TRACE,
86 "<=- ldbm_back_delete: no write access to entry\n", 0,
89 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
90 rs->sr_text = "no write access to entry";
94 if ( !manageDSAit && is_entry_referral( e ) ) {
95 /* parent is a referral, don't allow add */
96 /* parent is an alias, don't allow add */
97 rs->sr_ref = get_entry_referrals( op, e );
99 Debug( LDAP_DEBUG_TRACE, "entry is referral\n", 0,
102 rs->sr_err = LDAP_REFERRAL;
103 rs->sr_matched = ch_strdup( e->e_name.bv_val );
104 rs->sr_flags = REP_MATCHED_MUSTBEFREED | REP_REF_MUSTBEFREED;
108 if ( has_children( op->o_bd, e ) ) {
109 Debug(LDAP_DEBUG_ARGS, "<=- ldbm_back_delete: non leaf %s\n",
110 op->o_req_dn.bv_val, 0, 0);
112 rs->sr_err = LDAP_NOT_ALLOWED_ON_NONLEAF;
113 rs->sr_text = "subordinate objects must be deleted first";
117 /* delete from parent's id2children entry */
118 if( !be_issuffix( op->o_bd, &e->e_nname ) && (dnParent( &e->e_nname, &pdn ),
120 if( (p = dn2entry_w( op->o_bd, &pdn, NULL )) == NULL) {
121 Debug( LDAP_DEBUG_TRACE,
122 "<=- ldbm_back_delete: parent does not exist\n",
125 rs->sr_err = LDAP_OTHER;
126 rs->sr_text = "could not locate parent of entry";
130 /* check parent for "children" acl */
131 if ( ! access_allowed( op, p,
132 children, NULL, ACL_WDEL, NULL ) )
134 Debug( LDAP_DEBUG_TRACE,
135 "<=- ldbm_back_delete: no access to parent\n", 0,
138 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
139 rs->sr_text = "no write access to parent";
144 /* no parent, must be root to delete */
145 if( ! be_isroot( op ) ) {
146 if ( be_issuffix( op->o_bd, (struct berval *)&slap_empty_bv )
147 || be_shadow_update( op ) ) {
148 p = (Entry *)&slap_entry_root;
150 rc = access_allowed( op, p,
151 children, NULL, ACL_WDEL, NULL );
154 /* check parent for "children" acl */
156 Debug( LDAP_DEBUG_TRACE,
157 "<=- ldbm_back_delete: no "
158 "access to parent\n", 0, 0, 0 );
160 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
161 rs->sr_text = "no write access to parent";
166 Debug( LDAP_DEBUG_TRACE,
167 "<=- ldbm_back_delete: no parent & "
168 "not root\n", 0, 0, 0);
170 rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
176 /* delete from dn2id mapping */
177 if ( dn2id_delete( op->o_bd, &e->e_nname, e->e_id ) != 0 ) {
178 Debug(LDAP_DEBUG_ARGS,
179 "<=- ldbm_back_delete: operations error %s\n",
180 op->o_req_dn.bv_val, 0, 0);
182 rs->sr_err = LDAP_OTHER;
183 rs->sr_text = "DN index delete failed";
187 /* delete from disk and cache */
188 if ( id2entry_delete( op->o_bd, e ) != 0 ) {
189 Debug(LDAP_DEBUG_ARGS,
190 "<=- ldbm_back_delete: operations error %s\n",
191 op->o_req_dn.bv_val, 0, 0);
193 rs->sr_err = LDAP_OTHER;
194 rs->sr_text = "entry delete failed";
198 /* delete attribute indices */
199 (void) index_entry_del( op, e );
201 rs->sr_err = LDAP_SUCCESS;
207 /* free parent and writer lock */
208 cache_return_entry_w( &li->li_cache, p );
212 /* free entry and writer lock */
213 cache_return_entry_w( &li->li_cache, e );
216 ldap_pvt_thread_rdwr_wunlock(&li->li_giant_rwlock);
218 send_ldap_result( op, rs );
219 if ( !SLAP_SHADOW( op->o_bd ))
220 slap_graduate_commit_csn( op );