]> git.sur5r.net Git - openldap/blob - servers/slapd/back-ldbm/delete.c
Y2k copyright update
[openldap] / servers / slapd / back-ldbm / delete.c
1 /* delete.c - ldbm backend delete routine */
2 /* $OpenLDAP$ */
3 /*
4  * Copyright 1998-2000 The OpenLDAP Foundation, All Rights Reserved.
5  * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
6  */
7
8 #include "portable.h"
9
10 #include <stdio.h>
11
12 #include <ac/string.h>
13 #include <ac/socket.h>
14
15 #include "slap.h"
16 #include "back-ldbm.h"
17 #include "proto-back-ldbm.h"
18
19 int
20 ldbm_back_delete(
21     Backend     *be,
22     Connection  *conn,
23     Operation   *op,
24     char        *dn,
25     char        *ndn
26 )
27 {
28         struct ldbminfo *li = (struct ldbminfo *) be->be_private;
29         Entry   *matched;
30         char    *pdn = NULL;
31         Entry   *e, *p = NULL;
32         int rootlock = 0;
33         int     rc = -1;
34         int             manageDSAit = get_manageDSAit( op );
35 #ifdef SLAPD_SCHEMA_NOT_COMPAT
36         static AttributeDescription *children = NULL;
37 #else
38         static const char *children = "children";
39 #endif
40
41         Debug(LDAP_DEBUG_ARGS, "==> ldbm_back_delete: %s\n", dn, 0, 0);
42
43         /* get entry with writer lock */
44         if ( (e = dn2entry_w( be, ndn, &matched )) == NULL ) {
45                 char *matched_dn = NULL;
46                 struct berval **refs = NULL;
47
48                 Debug(LDAP_DEBUG_ARGS, "<=- ldbm_back_delete: no such object %s\n",
49                         dn, 0, 0);
50
51                 if ( matched != NULL ) {
52                         matched_dn = ch_strdup( matched->e_dn );
53                         refs = is_entry_referral( matched )
54                                 ? get_entry_referrals( be, conn, op, matched )
55                                 : NULL;
56                         cache_return_entry_r( &li->li_cache, matched );
57                 } else {
58                         refs = default_referral;
59                 }
60
61                 send_ldap_result( conn, op, LDAP_REFERRAL,
62                         matched_dn, NULL, refs, NULL );
63
64                 if ( matched != NULL ) {
65                         ber_bvecfree( refs );
66                         free( matched_dn );
67                 }
68
69                 return( -1 );
70         }
71
72 #ifdef SLAPD_CHILD_MODIFICATION_WITH_ENTRY_ACL
73         if ( ! access_allowed( be, conn, op, e,
74                 "entry", NULL, ACL_WRITE ) )
75         {
76                 Debug(LDAP_DEBUG_ARGS,
77                         "<=- ldbm_back_delete: insufficient access %s\n",
78                         dn, 0, 0);
79                 send_ldap_result( conn, op, LDAP_INSUFFICIENT_ACCESS,
80                         NULL, NULL, NULL, NULL );
81                 goto return_results;
82         }
83 #endif
84
85     if ( !manageDSAit && is_entry_referral( e ) ) {
86                 /* parent is a referral, don't allow add */
87                 /* parent is an alias, don't allow add */
88                 struct berval **refs = get_entry_referrals( be,
89                         conn, op, e );
90
91                 Debug( LDAP_DEBUG_TRACE, "entry is referral\n", 0,
92                     0, 0 );
93
94                 send_ldap_result( conn, op, LDAP_REFERRAL,
95                     e->e_dn, NULL, refs, NULL );
96
97                 ber_bvecfree( refs );
98
99                 rc = 1;
100                 goto return_results;
101         }
102
103
104         if ( has_children( be, e ) ) {
105                 Debug(LDAP_DEBUG_ARGS, "<=- ldbm_back_delete: non leaf %s\n",
106                         dn, 0, 0);
107                 send_ldap_result( conn, op, LDAP_NOT_ALLOWED_ON_NONLEAF,
108                         NULL, "subtree delete not supported", NULL, NULL );
109                 goto return_results;
110         }
111
112         /* delete from parent's id2children entry */
113         if( (pdn = dn_parent( be, e->e_ndn )) != NULL ) {
114                 if( (p = dn2entry_w( be, pdn, NULL )) == NULL) {
115                         Debug( LDAP_DEBUG_TRACE,
116                                 "<=- ldbm_back_delete: parent does not exist\n",
117                                 0, 0, 0);
118                         send_ldap_result( conn, op, LDAP_OTHER,
119                                 NULL, "could not locate parent of entry", NULL, NULL );
120                         goto return_results;
121                 }
122
123                 /* check parent for "children" acl */
124                 if ( ! access_allowed( be, conn, op, p,
125                         children, NULL, ACL_WRITE ) )
126                 {
127                         Debug( LDAP_DEBUG_TRACE,
128                                 "<=- ldbm_back_delete: no access to parent\n", 0,
129                                 0, 0 );
130                         send_ldap_result( conn, op, LDAP_INSUFFICIENT_ACCESS,
131                                 NULL, NULL, NULL, NULL );
132                         goto return_results;
133                 }
134
135         } else {
136                 /* no parent, must be root to delete */
137                 if( ! be_isroot( be, op->o_ndn ) ) {
138                         Debug( LDAP_DEBUG_TRACE,
139                                 "<=- ldbm_back_delete: no parent & not root\n",
140                                 0, 0, 0);
141                         send_ldap_result( conn, op, LDAP_INSUFFICIENT_ACCESS,
142                                 NULL, NULL, NULL, NULL );
143                         goto return_results;
144                 }
145
146                 ldap_pvt_thread_mutex_lock(&li->li_root_mutex);
147                 rootlock = 1;
148         }
149
150         /* delete from dn2id mapping */
151         if ( dn2id_delete( be, e->e_ndn, e->e_id ) != 0 ) {
152                 Debug(LDAP_DEBUG_ARGS,
153                         "<=- ldbm_back_delete: operations error %s\n",
154                         dn, 0, 0);
155                 send_ldap_result( conn, op, LDAP_OTHER,
156                         NULL, "DN index delete failed", NULL, NULL );
157                 goto return_results;
158         }
159
160         /* delete from disk and cache */
161         if ( id2entry_delete( be, e ) != 0 ) {
162                 Debug(LDAP_DEBUG_ARGS,
163                         "<=- ldbm_back_delete: operations error %s\n",
164                         dn, 0, 0);
165                 send_ldap_result( conn, op, LDAP_OTHER,
166                         NULL, "entry delete failed", NULL, NULL );
167                 goto return_results;
168         }
169
170         send_ldap_result( conn, op, LDAP_SUCCESS,
171                 NULL, NULL, NULL, NULL );
172         rc = 0;
173
174 return_results:;
175         if ( pdn != NULL ) free(pdn);
176
177         if( p != NULL ) {
178                 /* free parent and writer lock */
179                 cache_return_entry_w( &li->li_cache, p );
180         }
181
182         if ( rootlock ) {
183                 /* release root lock */
184                 ldap_pvt_thread_mutex_unlock(&li->li_root_mutex);
185         }
186
187         /* free entry and writer lock */
188         cache_return_entry_w( &li->li_cache, e );
189
190         return rc;
191 }