]> git.sur5r.net Git - openldap/blob - servers/slapd/back-ldbm/delete.c
Initial implementation of Kerberos password verification for
[openldap] / servers / slapd / back-ldbm / delete.c
1 /* delete.c - ldbm backend delete routine */
2 /* $OpenLDAP$ */
3 /*
4  * Copyright 1998-1999 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
36         Debug(LDAP_DEBUG_ARGS, "==> ldbm_back_delete: %s\n", dn, 0, 0);
37
38         /* get entry with writer lock */
39         if ( (e = dn2entry_w( be, ndn, &matched )) == NULL ) {
40                 char *matched_dn = NULL;
41                 struct berval **refs = NULL;
42
43                 Debug(LDAP_DEBUG_ARGS, "<=- ldbm_back_delete: no such object %s\n",
44                         dn, 0, 0);
45
46                 if ( matched != NULL ) {
47                         matched_dn = ch_strdup( matched->e_dn );
48                         refs = is_entry_referral( matched )
49                                 ? get_entry_referrals( be, conn, op, matched )
50                                 : NULL;
51                         cache_return_entry_r( &li->li_cache, matched );
52                 } else {
53                         refs = default_referral;
54                 }
55
56                 send_ldap_result( conn, op, LDAP_REFERRAL,
57                         matched_dn, NULL, refs, NULL );
58
59                 if ( matched != NULL ) {
60                         ber_bvecfree( refs );
61                         free( matched_dn );
62                 }
63
64                 return( -1 );
65         }
66
67 #ifdef SLAPD_CHILD_MODIFICATION_WITH_ENTRY_ACL
68         if ( ! access_allowed( be, conn, op, e,
69                 "entry", NULL, ACL_WRITE ) )
70         {
71                 Debug(LDAP_DEBUG_ARGS,
72                         "<=- ldbm_back_delete: insufficient access %s\n",
73                         dn, 0, 0);
74                 send_ldap_result( conn, op, LDAP_INSUFFICIENT_ACCESS,
75                         NULL, NULL, NULL, NULL );
76                 goto return_results;
77         }
78 #endif
79
80     if ( !manageDSAit && is_entry_referral( e ) ) {
81                 /* parent is a referral, don't allow add */
82                 /* parent is an alias, don't allow add */
83                 struct berval **refs = get_entry_referrals( be,
84                         conn, op, e );
85
86                 Debug( LDAP_DEBUG_TRACE, "entry is referral\n", 0,
87                     0, 0 );
88
89                 send_ldap_result( conn, op, LDAP_REFERRAL,
90                     e->e_dn, NULL, refs, NULL );
91
92                 ber_bvecfree( refs );
93
94                 rc = 1;
95                 goto return_results;
96         }
97
98
99         if ( has_children( be, e ) ) {
100                 Debug(LDAP_DEBUG_ARGS, "<=- ldbm_back_delete: non leaf %s\n",
101                         dn, 0, 0);
102                 send_ldap_result( conn, op, LDAP_NOT_ALLOWED_ON_NONLEAF,
103                         NULL, NULL, NULL, NULL );
104                 goto return_results;
105         }
106
107         /* delete from parent's id2children entry */
108         if( (pdn = dn_parent( be, e->e_ndn )) != NULL ) {
109                 if( (p = dn2entry_w( be, pdn, NULL )) == NULL) {
110                         Debug( LDAP_DEBUG_TRACE,
111                                 "<=- ldbm_back_delete: parent does not exist\n",
112                                 0, 0, 0);
113                         send_ldap_result( conn, op, LDAP_OPERATIONS_ERROR,
114                                 NULL, NULL, NULL, NULL );
115                         goto return_results;
116                 }
117
118                 /* check parent for "children" acl */
119                 if ( ! access_allowed( be, conn, op, p,
120                         "children", NULL, ACL_WRITE ) )
121                 {
122                         Debug( LDAP_DEBUG_TRACE,
123                                 "<=- ldbm_back_delete: no access to parent\n", 0,
124                                 0, 0 );
125                         send_ldap_result( conn, op, LDAP_INSUFFICIENT_ACCESS,
126                                 NULL, NULL, NULL, NULL );
127                         goto return_results;
128                 }
129
130         } else {
131                 /* no parent, must be root to delete */
132                 if( ! be_isroot( be, op->o_ndn ) ) {
133                         Debug( LDAP_DEBUG_TRACE,
134                                 "<=- ldbm_back_delete: no parent & not root\n",
135                                 0, 0, 0);
136                         send_ldap_result( conn, op, LDAP_INSUFFICIENT_ACCESS,
137                                 NULL, NULL, NULL, NULL );
138                         goto return_results;
139                 }
140
141                 ldap_pvt_thread_mutex_lock(&li->li_root_mutex);
142                 rootlock = 1;
143         }
144
145         /* delete from dn2id mapping */
146         if ( dn2id_delete( be, e->e_ndn, e->e_id ) != 0 ) {
147                 Debug(LDAP_DEBUG_ARGS,
148                         "<=- ldbm_back_delete: operations error %s\n",
149                         dn, 0, 0);
150                 send_ldap_result( conn, op, LDAP_OPERATIONS_ERROR,
151                         NULL, NULL, NULL, NULL );
152                 goto return_results;
153         }
154
155         /* delete from disk and cache */
156         if ( id2entry_delete( be, e ) != 0 ) {
157                 Debug(LDAP_DEBUG_ARGS,
158                         "<=- ldbm_back_delete: operations error %s\n",
159                         dn, 0, 0);
160                 send_ldap_result( conn, op, LDAP_OPERATIONS_ERROR,
161                         NULL, NULL, NULL, NULL );
162                 goto return_results;
163         }
164
165         send_ldap_result( conn, op, LDAP_SUCCESS,
166                 NULL, NULL, NULL, NULL );
167         rc = 0;
168
169 return_results:;
170         if ( pdn != NULL ) free(pdn);
171
172         if( p != NULL ) {
173                 /* free parent and writer lock */
174                 cache_return_entry_w( &li->li_cache, p );
175         }
176
177         if ( rootlock ) {
178                 /* release root lock */
179                 ldap_pvt_thread_mutex_unlock(&li->li_root_mutex);
180         }
181
182         /* free entry and writer lock */
183         cache_return_entry_w( &li->li_cache, e );
184
185         return rc;
186 }