]> git.sur5r.net Git - openldap/blob - servers/slapd/back-ldbm/delete.c
Import slapd.conf mode change (with typo correction) from -devel.
[openldap] / servers / slapd / back-ldbm / delete.c
1 /* delete.c - ldbm backend delete routine */
2
3 #include "portable.h"
4
5 #include <stdio.h>
6
7 #include <ac/string.h>
8 #include <ac/socket.h>
9
10 #include "slap.h"
11 #include "back-ldbm.h"
12 #include "proto-back-ldbm.h"
13
14 int
15 ldbm_back_delete(
16     Backend     *be,
17     Connection  *conn,
18     Operation   *op,
19     char        *dn
20 )
21 {
22         struct ldbminfo *li = (struct ldbminfo *) be->be_private;
23         char    *matched = NULL;
24         char    *pdn = NULL;
25         Entry   *e, *p = NULL;
26         int rootlock = 0;
27         int     rc = -1;
28
29         Debug(LDAP_DEBUG_ARGS, "==> ldbm_back_delete: %s\n", dn, 0, 0);
30
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",
34                         dn, 0, 0);
35                 send_ldap_result( conn, op, LDAP_NO_SUCH_OBJECT, matched, "" );
36                 if ( matched != NULL ) {
37                         free( matched );
38                 }
39                 return( -1 );
40         }
41
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);
45
46         /* check for deleted */
47
48         if ( has_children( be, e ) ) {
49                 Debug(LDAP_DEBUG_ARGS, "<=- ldbm_back_delete: non leaf %s\n",
50                         dn, 0, 0);
51                 send_ldap_result( conn, op, LDAP_NOT_ALLOWED_ON_NONLEAF, "",
52                     "" );
53                 goto return_results;
54         }
55
56 #ifdef SLAPD_CHILD_MODIFICATION_WITH_ENTRY_ACL
57         if ( ! access_allowed( be, conn, op, e, "entry", NULL, op->o_dn,
58             ACL_WRITE ) ) {
59                 Debug(LDAP_DEBUG_ARGS,
60                         "<=- ldbm_back_delete: insufficient access %s\n",
61                         dn, 0, 0);
62                 send_ldap_result( conn, op, LDAP_INSUFFICIENT_ACCESS, "", "" );
63                 goto return_results;
64         }
65 #endif
66
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);
70
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",
75                                 0, 0, 0);
76                         send_ldap_result( conn, op, LDAP_OPERATIONS_ERROR,
77                                 "", "");
78                         goto return_results;
79                 }
80
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 ) )
85                 {
86                         Debug( LDAP_DEBUG_TRACE, "no access to parent\n", 0,
87                                 0, 0 );
88                         send_ldap_result( conn, op, LDAP_INSUFFICIENT_ACCESS,
89                                 "", "" );
90                         goto return_results;
91                 }
92 #endif
93
94         } else {
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",
98                                 0, 0, 0);
99                         send_ldap_result( conn, op, LDAP_INSUFFICIENT_ACCESS,
100                                 "", "");
101                         goto return_results;
102                 }
103
104                 pthread_mutex_lock(&li->li_root_mutex);
105                 rootlock = 1;
106         }
107
108         if ( id2children_remove( be, p, e ) != 0 ) {
109                 Debug(LDAP_DEBUG_ARGS,
110                         "<=- ldbm_back_delete: operations error %s\n",
111                         dn, 0, 0);
112                 send_ldap_result( conn, op, LDAP_OPERATIONS_ERROR, "","" );
113                 goto return_results;
114         }
115
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",
120                         dn, 0, 0);
121                 send_ldap_result( conn, op, LDAP_OPERATIONS_ERROR, "", "" );
122                 goto return_results;
123         }
124
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",
129                         dn, 0, 0);
130                 send_ldap_result( conn, op, LDAP_OPERATIONS_ERROR, "", "" );
131                 goto return_results;
132         }
133
134         send_ldap_result( conn, op, LDAP_SUCCESS, "", "" );
135         rc = 0;
136
137 return_results:;
138         if ( pdn != NULL ) free(pdn);
139
140         if( p != NULL ) {
141                 /* free parent and writer lock */
142                 cache_return_entry_w( &li->li_cache, p );
143
144         } else if ( rootlock ) {
145                 /* release root lock */
146                 pthread_mutex_unlock(&li->li_root_mutex);
147         }
148
149         /* free entry and writer lock */
150         cache_return_entry_w( &li->li_cache, e );
151
152         if ( matched != NULL ) free(matched);
153
154         return rc;
155 }