]> git.sur5r.net Git - openldap/blob - servers/slapd/back-bdb2/delete.c
expose oc_check_operational from schema.c
[openldap] / servers / slapd / back-bdb2 / delete.c
1 /* delete.c - bdb2 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-bdb2.h"
12 #include "proto-back-bdb2.h"
13
14 static int
15 bdb2i_back_delete_internal(
16     BackendDB   *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     rc = -1;
27
28         Debug(LDAP_DEBUG_ARGS, "==> bdb2i_back_delete: %s\n", dn, 0, 0);
29
30         /* get entry with writer lock */
31         if ( (e = bdb2i_dn2entry_w( be, dn, &matched )) == NULL ) {
32                 Debug(LDAP_DEBUG_ARGS, "<=- bdb2i_back_delete: no such object %s\n",
33                         dn, 0, 0);
34                 send_ldap_result( conn, op, LDAP_NO_SUCH_OBJECT, matched, "" );
35                 if ( matched != NULL ) {
36                         free( matched );
37                 }
38                 return( -1 );
39         }
40
41         /* check for deleted */
42
43         if ( bdb2i_has_children( be, e ) ) {
44                 Debug(LDAP_DEBUG_ARGS, "<=- bdb2i_back_delete: non leaf %s\n",
45                         dn, 0, 0);
46                 send_ldap_result( conn, op, LDAP_NOT_ALLOWED_ON_NONLEAF, "",
47                     "" );
48                 goto return_results;
49         }
50
51 #ifdef SLAPD_CHILD_MODIFICATION_WITH_ENTRY_ACL
52         if ( ! access_allowed( be, conn, op, e,
53                 "entry", NULL, ACL_WRITE ) )
54         {
55                 Debug(LDAP_DEBUG_ARGS,
56                         "<=- bdb2i_back_delete: insufficient access %s\n",
57                         dn, 0, 0);
58                 send_ldap_result( conn, op, LDAP_INSUFFICIENT_ACCESS, "", "" );
59                 goto return_results;
60         }
61 #endif
62
63         /* delete from parent's id2children entry */
64         if( (pdn = dn_parent( be, e->e_ndn )) != NULL ) {
65                 if( (p = bdb2i_dn2entry_w( be, pdn, &matched )) == NULL) {
66                         Debug( LDAP_DEBUG_TRACE,
67                                 "<=- bdb2i_back_delete: parent does not exist\n", 0, 0, 0);
68                         send_ldap_result( conn, op, LDAP_OPERATIONS_ERROR,
69                                 "", "");
70                         goto return_results;
71                 }
72
73                 /* check parent for "children" acl */
74                 if ( ! access_allowed( be, conn, op, p,
75                         "children", NULL, ACL_WRITE ) )
76                 {
77                         Debug( LDAP_DEBUG_TRACE,
78                                 "<=- bdb2i_back_delete: no access to parent\n", 0, 0, 0 );
79                         send_ldap_result( conn, op, LDAP_INSUFFICIENT_ACCESS,
80                                 "", "" );
81                         goto return_results;
82                 }
83
84         } else {
85                 /* no parent, must be root to delete */
86                 if( ! be_isroot( be, op->o_ndn ) ) {
87                         Debug( LDAP_DEBUG_TRACE,
88                                 "<=- bdb2i_back_delete: no parent & not root\n", 0, 0, 0);
89                         send_ldap_result( conn, op, LDAP_INSUFFICIENT_ACCESS,
90                                 "", "");
91                         goto return_results;
92                 }
93         }
94
95         if ( bdb2i_id2children_remove( be, p, e ) != 0 ) {
96                 Debug(LDAP_DEBUG_ARGS,
97                         "<=- bdb2i_back_delete: operations error %s\n",
98                         dn, 0, 0);
99                 send_ldap_result( conn, op, LDAP_OPERATIONS_ERROR, "","" );
100                 goto return_results;
101         }
102
103         /* delete from dn2id mapping */
104         if ( bdb2i_dn2id_delete( be, e->e_ndn ) != 0 ) {
105                 Debug(LDAP_DEBUG_ARGS,
106                         "<=- bdb2i_back_delete: operations error %s\n",
107                         dn, 0, 0);
108                 send_ldap_result( conn, op, LDAP_OPERATIONS_ERROR, "", "" );
109                 goto return_results;
110         }
111
112         /* delete from disk and cache */
113         if ( bdb2i_id2entry_delete( be, e ) != 0 ) {
114                 Debug(LDAP_DEBUG_ARGS,
115                         "<=- bdb2i_back_delete: operations error %s\n",
116                         dn, 0, 0);
117                 send_ldap_result( conn, op, LDAP_OPERATIONS_ERROR, "", "" );
118                 goto return_results;
119         }
120
121         send_ldap_result( conn, op, LDAP_SUCCESS, "", "" );
122         rc = 0;
123
124 return_results:;
125         if ( pdn != NULL ) free(pdn);
126
127         if( p != NULL ) {
128                 /* free parent and writer lock */
129                 bdb2i_cache_return_entry_w( &li->li_cache, p );
130
131         }
132
133         /* free entry and writer lock */
134         bdb2i_cache_return_entry_w( &li->li_cache, e );
135
136         if ( matched != NULL ) free(matched);
137
138         return rc;
139 }
140
141
142 int
143 bdb2_back_delete(
144     BackendDB   *be,
145     Connection  *conn,
146     Operation   *op,
147     char        *dn
148 )
149 {
150         DB_LOCK         lock;
151         struct ldbminfo *li = (struct ldbminfo *) be->be_private;
152         struct timeval  time1;
153         int             ret;
154
155         bdb2i_start_timing( be->bd_info, &time1 );
156
157         if ( bdb2i_enter_backend_w( &lock ) != 0 ) {
158
159                 send_ldap_result( conn, op, LDAP_OPERATIONS_ERROR, "", "" );
160                 return( -1 );
161
162         }
163
164         ret = bdb2i_back_delete_internal( be, conn, op, dn );
165         (void) bdb2i_leave_backend_w( lock );
166         bdb2i_stop_timing( be->bd_info, time1, "DEL", conn, op );
167
168         return( ret );
169 }
170
171