]> git.sur5r.net Git - openldap/blob - servers/slapd/back-bdb2/delete.c
Some minor clean-up; checking bdb2 for sync with ldbm.
[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 #ifndef SLAPD_CHILD_MODIFICATION_WITH_ENTRY_ACL
74                 /* check parent for "children" acl */
75                 if ( ! access_allowed( be, conn, op, p,
76                         "children", NULL, ACL_WRITE ) )
77                 {
78                         Debug( LDAP_DEBUG_TRACE,
79                                 "<=- bdb2i_back_delete: no access to parent\n", 0, 0, 0 );
80                         send_ldap_result( conn, op, LDAP_INSUFFICIENT_ACCESS,
81                                 "", "" );
82                         goto return_results;
83                 }
84 #endif
85
86         } else {
87                 /* no parent, must be root to delete */
88                 if( ! be_isroot( be, op->o_ndn ) ) {
89                         Debug( LDAP_DEBUG_TRACE,
90                                 "<=- bdb2i_back_delete: no parent & not root\n", 0, 0, 0);
91                         send_ldap_result( conn, op, LDAP_INSUFFICIENT_ACCESS,
92                                 "", "");
93                         goto return_results;
94                 }
95         }
96
97         if ( bdb2i_id2children_remove( be, p, e ) != 0 ) {
98                 Debug(LDAP_DEBUG_ARGS,
99                         "<=- bdb2i_back_delete: operations error %s\n",
100                         dn, 0, 0);
101                 send_ldap_result( conn, op, LDAP_OPERATIONS_ERROR, "","" );
102                 goto return_results;
103         }
104
105         /* delete from dn2id mapping */
106         if ( bdb2i_dn2id_delete( be, e->e_ndn ) != 0 ) {
107                 Debug(LDAP_DEBUG_ARGS,
108                         "<=- bdb2i_back_delete: operations error %s\n",
109                         dn, 0, 0);
110                 send_ldap_result( conn, op, LDAP_OPERATIONS_ERROR, "", "" );
111                 goto return_results;
112         }
113
114         /* delete from disk and cache */
115         if ( bdb2i_id2entry_delete( be, e ) != 0 ) {
116                 Debug(LDAP_DEBUG_ARGS,
117                         "<=- bdb2i_back_delete: operations error %s\n",
118                         dn, 0, 0);
119                 send_ldap_result( conn, op, LDAP_OPERATIONS_ERROR, "", "" );
120                 goto return_results;
121         }
122
123         send_ldap_result( conn, op, LDAP_SUCCESS, "", "" );
124         rc = 0;
125
126 return_results:;
127         if ( pdn != NULL ) free(pdn);
128
129         if( p != NULL ) {
130                 /* free parent and writer lock */
131                 bdb2i_cache_return_entry_w( &li->li_cache, p );
132
133         }
134
135         /* free entry and writer lock */
136         bdb2i_cache_return_entry_w( &li->li_cache, e );
137
138         if ( matched != NULL ) free(matched);
139
140         return rc;
141 }
142
143
144 int
145 bdb2_back_delete(
146     BackendDB   *be,
147     Connection  *conn,
148     Operation   *op,
149     char        *dn
150 )
151 {
152         DB_LOCK         lock;
153         struct ldbminfo *li = (struct ldbminfo *) be->be_private;
154         struct timeval  time1;
155         int             ret;
156
157         bdb2i_start_timing( be->bd_info, &time1 );
158
159         if ( bdb2i_enter_backend_w( &lock ) != 0 ) {
160
161                 send_ldap_result( conn, op, LDAP_OPERATIONS_ERROR, "", "" );
162                 return( -1 );
163
164         }
165
166         ret = bdb2i_back_delete_internal( be, conn, op, dn );
167         (void) bdb2i_leave_backend_w( lock );
168         bdb2i_stop_timing( be->bd_info, time1, "DEL", conn, op );
169
170         return( ret );
171 }
172
173