modrdn.c revision 1.1 1 1.1 lukem /* $OpenLDAP: pkg/ldap/servers/slapd/back-sql/modrdn.c,v 1.39.2.5 2008/02/11 23:26:48 kurt Exp $ */
2 1.1 lukem /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
3 1.1 lukem *
4 1.1 lukem * Copyright 1999-2008 The OpenLDAP Foundation.
5 1.1 lukem * Portions Copyright 1999 Dmitry Kovalev.
6 1.1 lukem * Portions Copyright 2002 Pierangelo Masarati.
7 1.1 lukem * All rights reserved.
8 1.1 lukem *
9 1.1 lukem * Redistribution and use in source and binary forms, with or without
10 1.1 lukem * modification, are permitted only as authorized by the OpenLDAP
11 1.1 lukem * Public License.
12 1.1 lukem *
13 1.1 lukem * A copy of this license is available in the file LICENSE in the
14 1.1 lukem * top-level directory of the distribution or, alternatively, at
15 1.1 lukem * <http://www.OpenLDAP.org/license.html>.
16 1.1 lukem */
17 1.1 lukem /* ACKNOWLEDGEMENTS:
18 1.1 lukem * This work was initially developed by Dmitry Kovalev for inclusion
19 1.1 lukem * by OpenLDAP Software. Additional significant contributors include
20 1.1 lukem * Pierangelo Masarati.
21 1.1 lukem */
22 1.1 lukem
23 1.1 lukem #include "portable.h"
24 1.1 lukem
25 1.1 lukem #include <stdio.h>
26 1.1 lukem #include <sys/types.h>
27 1.1 lukem #include "ac/string.h"
28 1.1 lukem
29 1.1 lukem #include "slap.h"
30 1.1 lukem #include "proto-sql.h"
31 1.1 lukem
32 1.1 lukem int
33 1.1 lukem backsql_modrdn( Operation *op, SlapReply *rs )
34 1.1 lukem {
35 1.1 lukem backsql_info *bi = (backsql_info*)op->o_bd->be_private;
36 1.1 lukem SQLHDBC dbh = SQL_NULL_HDBC;
37 1.1 lukem SQLHSTMT sth = SQL_NULL_HSTMT;
38 1.1 lukem RETCODE rc;
39 1.1 lukem backsql_entryID e_id = BACKSQL_ENTRYID_INIT,
40 1.1 lukem n_id = BACKSQL_ENTRYID_INIT;
41 1.1 lukem backsql_srch_info bsi = { 0 };
42 1.1 lukem backsql_oc_map_rec *oc = NULL;
43 1.1 lukem struct berval pdn = BER_BVNULL, pndn = BER_BVNULL,
44 1.1 lukem *new_pdn = NULL, *new_npdn = NULL,
45 1.1 lukem new_dn = BER_BVNULL, new_ndn = BER_BVNULL,
46 1.1 lukem realnew_dn = BER_BVNULL;
47 1.1 lukem Entry r = { 0 },
48 1.1 lukem p = { 0 },
49 1.1 lukem n = { 0 },
50 1.1 lukem *e = NULL;
51 1.1 lukem int manageDSAit = get_manageDSAit( op );
52 1.1 lukem struct berval *newSuperior = op->oq_modrdn.rs_newSup;
53 1.1 lukem
54 1.1 lukem Debug( LDAP_DEBUG_TRACE, "==>backsql_modrdn() renaming entry \"%s\", "
55 1.1 lukem "newrdn=\"%s\", newSuperior=\"%s\"\n",
56 1.1 lukem op->o_req_dn.bv_val, op->oq_modrdn.rs_newrdn.bv_val,
57 1.1 lukem newSuperior ? newSuperior->bv_val : "(NULL)" );
58 1.1 lukem
59 1.1 lukem rs->sr_err = backsql_get_db_conn( op, &dbh );
60 1.1 lukem if ( rs->sr_err != LDAP_SUCCESS ) {
61 1.1 lukem Debug( LDAP_DEBUG_TRACE, " backsql_modrdn(): "
62 1.1 lukem "could not get connection handle - exiting\n",
63 1.1 lukem 0, 0, 0 );
64 1.1 lukem rs->sr_text = ( rs->sr_err == LDAP_OTHER )
65 1.1 lukem ? "SQL-backend error" : NULL;
66 1.1 lukem e = NULL;
67 1.1 lukem goto done;
68 1.1 lukem }
69 1.1 lukem
70 1.1 lukem bsi.bsi_e = &r;
71 1.1 lukem rs->sr_err = backsql_init_search( &bsi, &op->o_req_ndn,
72 1.1 lukem LDAP_SCOPE_BASE,
73 1.1 lukem (time_t)(-1), NULL, dbh, op, rs,
74 1.1 lukem slap_anlist_all_attributes,
75 1.1 lukem ( BACKSQL_ISF_MATCHED | BACKSQL_ISF_GET_ENTRY | BACKSQL_ISF_GET_OC ) );
76 1.1 lukem switch ( rs->sr_err ) {
77 1.1 lukem case LDAP_SUCCESS:
78 1.1 lukem break;
79 1.1 lukem
80 1.1 lukem case LDAP_REFERRAL:
81 1.1 lukem if ( manageDSAit && !BER_BVISNULL( &bsi.bsi_e->e_nname ) &&
82 1.1 lukem dn_match( &op->o_req_ndn, &bsi.bsi_e->e_nname ) )
83 1.1 lukem {
84 1.1 lukem rs->sr_err = LDAP_SUCCESS;
85 1.1 lukem rs->sr_text = NULL;
86 1.1 lukem rs->sr_matched = NULL;
87 1.1 lukem if ( rs->sr_ref ) {
88 1.1 lukem ber_bvarray_free( rs->sr_ref );
89 1.1 lukem rs->sr_ref = NULL;
90 1.1 lukem }
91 1.1 lukem break;
92 1.1 lukem }
93 1.1 lukem e = &r;
94 1.1 lukem /* fallthru */
95 1.1 lukem
96 1.1 lukem default:
97 1.1 lukem Debug( LDAP_DEBUG_TRACE, "backsql_modrdn(): "
98 1.1 lukem "could not retrieve modrdnDN ID - no such entry\n",
99 1.1 lukem 0, 0, 0 );
100 1.1 lukem if ( !BER_BVISNULL( &r.e_nname ) ) {
101 1.1 lukem /* FIXME: should always be true! */
102 1.1 lukem e = &r;
103 1.1 lukem
104 1.1 lukem } else {
105 1.1 lukem e = NULL;
106 1.1 lukem }
107 1.1 lukem goto done;
108 1.1 lukem }
109 1.1 lukem
110 1.1 lukem #ifdef BACKSQL_ARBITRARY_KEY
111 1.1 lukem Debug( LDAP_DEBUG_TRACE, " backsql_modrdn(): entry id=%s\n",
112 1.1 lukem e_id.eid_id.bv_val, 0, 0 );
113 1.1 lukem #else /* ! BACKSQL_ARBITRARY_KEY */
114 1.1 lukem Debug( LDAP_DEBUG_TRACE, " backsql_modrdn(): entry id=%ld\n",
115 1.1 lukem e_id.eid_id, 0, 0 );
116 1.1 lukem #endif /* ! BACKSQL_ARBITRARY_KEY */
117 1.1 lukem
118 1.1 lukem if ( get_assert( op ) &&
119 1.1 lukem ( test_filter( op, &r, get_assertion( op ) )
120 1.1 lukem != LDAP_COMPARE_TRUE ) )
121 1.1 lukem {
122 1.1 lukem rs->sr_err = LDAP_ASSERTION_FAILED;
123 1.1 lukem e = &r;
124 1.1 lukem goto done;
125 1.1 lukem }
126 1.1 lukem
127 1.1 lukem if ( backsql_has_children( op, dbh, &op->o_req_ndn ) == LDAP_COMPARE_TRUE ) {
128 1.1 lukem Debug( LDAP_DEBUG_TRACE, " backsql_modrdn(): "
129 1.1 lukem "entry \"%s\" has children\n",
130 1.1 lukem op->o_req_dn.bv_val, 0, 0 );
131 1.1 lukem rs->sr_err = LDAP_NOT_ALLOWED_ON_NONLEAF;
132 1.1 lukem rs->sr_text = "subtree rename not supported";
133 1.1 lukem e = &r;
134 1.1 lukem goto done;
135 1.1 lukem }
136 1.1 lukem
137 1.1 lukem /*
138 1.1 lukem * Check for entry access to target
139 1.1 lukem */
140 1.1 lukem if ( !access_allowed( op, &r, slap_schema.si_ad_entry,
141 1.1 lukem NULL, ACL_WRITE, NULL ) ) {
142 1.1 lukem Debug( LDAP_DEBUG_TRACE, " no access to entry\n", 0, 0, 0 );
143 1.1 lukem rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
144 1.1 lukem goto done;
145 1.1 lukem }
146 1.1 lukem
147 1.1 lukem dnParent( &op->o_req_dn, &pdn );
148 1.1 lukem dnParent( &op->o_req_ndn, &pndn );
149 1.1 lukem
150 1.1 lukem /*
151 1.1 lukem * namingContext "" is not supported
152 1.1 lukem */
153 1.1 lukem if ( BER_BVISEMPTY( &pdn ) ) {
154 1.1 lukem Debug( LDAP_DEBUG_TRACE, " backsql_modrdn(): "
155 1.1 lukem "parent is \"\" - aborting\n", 0, 0, 0 );
156 1.1 lukem rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
157 1.1 lukem rs->sr_text = "not allowed within namingContext";
158 1.1 lukem e = NULL;
159 1.1 lukem goto done;
160 1.1 lukem }
161 1.1 lukem
162 1.1 lukem /*
163 1.1 lukem * Check for children access to parent
164 1.1 lukem */
165 1.1 lukem bsi.bsi_e = &p;
166 1.1 lukem e_id = bsi.bsi_base_id;
167 1.1 lukem memset( &bsi.bsi_base_id, 0, sizeof( bsi.bsi_base_id ) );
168 1.1 lukem rs->sr_err = backsql_init_search( &bsi, &pndn,
169 1.1 lukem LDAP_SCOPE_BASE,
170 1.1 lukem (time_t)(-1), NULL, dbh, op, rs,
171 1.1 lukem slap_anlist_all_attributes,
172 1.1 lukem BACKSQL_ISF_GET_ENTRY );
173 1.1 lukem
174 1.1 lukem #ifdef BACKSQL_ARBITRARY_KEY
175 1.1 lukem Debug( LDAP_DEBUG_TRACE, " backsql_modrdn(): "
176 1.1 lukem "old parent entry id is %s\n",
177 1.1 lukem bsi.bsi_base_id.eid_id.bv_val, 0, 0 );
178 1.1 lukem #else /* ! BACKSQL_ARBITRARY_KEY */
179 1.1 lukem Debug( LDAP_DEBUG_TRACE, " backsql_modrdn(): "
180 1.1 lukem "old parent entry id is %ld\n",
181 1.1 lukem bsi.bsi_base_id.eid_id, 0, 0 );
182 1.1 lukem #endif /* ! BACKSQL_ARBITRARY_KEY */
183 1.1 lukem
184 1.1 lukem if ( rs->sr_err != LDAP_SUCCESS ) {
185 1.1 lukem Debug( LDAP_DEBUG_TRACE, "backsql_modrdn(): "
186 1.1 lukem "could not retrieve renameDN ID - no such entry\n",
187 1.1 lukem 0, 0, 0 );
188 1.1 lukem e = &p;
189 1.1 lukem goto done;
190 1.1 lukem }
191 1.1 lukem
192 1.1 lukem if ( !access_allowed( op, &p, slap_schema.si_ad_children, NULL,
193 1.1 lukem newSuperior ? ACL_WDEL : ACL_WRITE, NULL ) )
194 1.1 lukem {
195 1.1 lukem Debug( LDAP_DEBUG_TRACE, " no access to parent\n", 0, 0, 0 );
196 1.1 lukem rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
197 1.1 lukem goto done;
198 1.1 lukem }
199 1.1 lukem
200 1.1 lukem if ( newSuperior ) {
201 1.1 lukem (void)backsql_free_entryID( &bsi.bsi_base_id, 0, op->o_tmpmemctx );
202 1.1 lukem
203 1.1 lukem /*
204 1.1 lukem * namingContext "" is not supported
205 1.1 lukem */
206 1.1 lukem if ( BER_BVISEMPTY( newSuperior ) ) {
207 1.1 lukem Debug( LDAP_DEBUG_TRACE, " backsql_modrdn(): "
208 1.1 lukem "newSuperior is \"\" - aborting\n", 0, 0, 0 );
209 1.1 lukem rs->sr_err = LDAP_UNWILLING_TO_PERFORM;
210 1.1 lukem rs->sr_text = "not allowed within namingContext";
211 1.1 lukem e = NULL;
212 1.1 lukem goto done;
213 1.1 lukem }
214 1.1 lukem
215 1.1 lukem new_pdn = newSuperior;
216 1.1 lukem new_npdn = op->oq_modrdn.rs_nnewSup;
217 1.1 lukem
218 1.1 lukem /*
219 1.1 lukem * Check for children access to new parent
220 1.1 lukem */
221 1.1 lukem bsi.bsi_e = &n;
222 1.1 lukem rs->sr_err = backsql_init_search( &bsi, new_npdn,
223 1.1 lukem LDAP_SCOPE_BASE,
224 1.1 lukem (time_t)(-1), NULL, dbh, op, rs,
225 1.1 lukem slap_anlist_all_attributes,
226 1.1 lukem ( BACKSQL_ISF_MATCHED | BACKSQL_ISF_GET_ENTRY ) );
227 1.1 lukem if ( rs->sr_err != LDAP_SUCCESS ) {
228 1.1 lukem Debug( LDAP_DEBUG_TRACE, "backsql_modrdn(): "
229 1.1 lukem "could not retrieve renameDN ID - no such entry\n",
230 1.1 lukem 0, 0, 0 );
231 1.1 lukem e = &n;
232 1.1 lukem goto done;
233 1.1 lukem }
234 1.1 lukem
235 1.1 lukem n_id = bsi.bsi_base_id;
236 1.1 lukem
237 1.1 lukem #ifdef BACKSQL_ARBITRARY_KEY
238 1.1 lukem Debug( LDAP_DEBUG_TRACE, " backsql_modrdn(): "
239 1.1 lukem "new parent entry id=%s\n",
240 1.1 lukem n_id.eid_id.bv_val, 0, 0 );
241 1.1 lukem #else /* ! BACKSQL_ARBITRARY_KEY */
242 1.1 lukem Debug( LDAP_DEBUG_TRACE, " backsql_modrdn(): "
243 1.1 lukem "new parent entry id=%ld\n",
244 1.1 lukem n_id.eid_id, 0, 0 );
245 1.1 lukem #endif /* ! BACKSQL_ARBITRARY_KEY */
246 1.1 lukem
247 1.1 lukem if ( !access_allowed( op, &n, slap_schema.si_ad_children,
248 1.1 lukem NULL, ACL_WADD, NULL ) ) {
249 1.1 lukem Debug( LDAP_DEBUG_TRACE, " backsql_modrdn(): "
250 1.1 lukem "no access to new parent \"%s\"\n",
251 1.1 lukem new_pdn->bv_val, 0, 0 );
252 1.1 lukem rs->sr_err = LDAP_INSUFFICIENT_ACCESS;
253 1.1 lukem e = &n;
254 1.1 lukem goto done;
255 1.1 lukem }
256 1.1 lukem
257 1.1 lukem } else {
258 1.1 lukem n_id = bsi.bsi_base_id;
259 1.1 lukem new_pdn = &pdn;
260 1.1 lukem new_npdn = &pndn;
261 1.1 lukem }
262 1.1 lukem
263 1.1 lukem memset( &bsi.bsi_base_id, 0, sizeof( bsi.bsi_base_id ) );
264 1.1 lukem
265 1.1 lukem if ( newSuperior && dn_match( &pndn, new_npdn ) ) {
266 1.1 lukem Debug( LDAP_DEBUG_TRACE, " backsql_modrdn(): "
267 1.1 lukem "newSuperior is equal to old parent - ignored\n",
268 1.1 lukem 0, 0, 0 );
269 1.1 lukem newSuperior = NULL;
270 1.1 lukem }
271 1.1 lukem
272 1.1 lukem if ( newSuperior && dn_match( &op->o_req_ndn, new_npdn ) ) {
273 1.1 lukem Debug( LDAP_DEBUG_TRACE, " backsql_modrdn(): "
274 1.1 lukem "newSuperior is equal to entry being moved "
275 1.1 lukem "- aborting\n", 0, 0, 0 );
276 1.1 lukem rs->sr_err = LDAP_OTHER;
277 1.1 lukem rs->sr_text = "newSuperior is equal to old DN";
278 1.1 lukem e = &r;
279 1.1 lukem goto done;
280 1.1 lukem }
281 1.1 lukem
282 1.1 lukem build_new_dn( &new_dn, new_pdn, &op->oq_modrdn.rs_newrdn,
283 1.1 lukem op->o_tmpmemctx );
284 1.1 lukem build_new_dn( &new_ndn, new_npdn, &op->oq_modrdn.rs_nnewrdn,
285 1.1 lukem op->o_tmpmemctx );
286 1.1 lukem
287 1.1 lukem Debug( LDAP_DEBUG_TRACE, " backsql_modrdn(): new entry dn is \"%s\"\n",
288 1.1 lukem new_dn.bv_val, 0, 0 );
289 1.1 lukem
290 1.1 lukem realnew_dn = new_dn;
291 1.1 lukem if ( backsql_api_dn2odbc( op, rs, &realnew_dn ) ) {
292 1.1 lukem Debug( LDAP_DEBUG_TRACE, " backsql_modrdn(\"%s\"): "
293 1.1 lukem "backsql_api_dn2odbc(\"%s\") failed\n",
294 1.1 lukem op->o_req_dn.bv_val, realnew_dn.bv_val, 0 );
295 1.1 lukem SQLFreeStmt( sth, SQL_DROP );
296 1.1 lukem
297 1.1 lukem rs->sr_text = "SQL-backend error";
298 1.1 lukem rs->sr_err = LDAP_OTHER;
299 1.1 lukem e = NULL;
300 1.1 lukem goto done;
301 1.1 lukem }
302 1.1 lukem
303 1.1 lukem Debug( LDAP_DEBUG_TRACE, " backsql_modrdn(): "
304 1.1 lukem "executing renentry_stmt\n", 0, 0, 0 );
305 1.1 lukem
306 1.1 lukem rc = backsql_Prepare( dbh, &sth, bi->sql_renentry_stmt, 0 );
307 1.1 lukem if ( rc != SQL_SUCCESS ) {
308 1.1 lukem Debug( LDAP_DEBUG_TRACE,
309 1.1 lukem " backsql_modrdn(): "
310 1.1 lukem "error preparing renentry_stmt\n", 0, 0, 0 );
311 1.1 lukem backsql_PrintErrors( bi->sql_db_env, dbh,
312 1.1 lukem sth, rc );
313 1.1 lukem
314 1.1 lukem rs->sr_text = "SQL-backend error";
315 1.1 lukem rs->sr_err = LDAP_OTHER;
316 1.1 lukem e = NULL;
317 1.1 lukem goto done;
318 1.1 lukem }
319 1.1 lukem
320 1.1 lukem rc = backsql_BindParamBerVal( sth, 1, SQL_PARAM_INPUT, &realnew_dn );
321 1.1 lukem if ( rc != SQL_SUCCESS ) {
322 1.1 lukem Debug( LDAP_DEBUG_TRACE,
323 1.1 lukem " backsql_add_attr(): "
324 1.1 lukem "error binding DN parameter for objectClass %s\n",
325 1.1 lukem oc->bom_oc->soc_cname.bv_val, 0, 0 );
326 1.1 lukem backsql_PrintErrors( bi->sql_db_env, dbh,
327 1.1 lukem sth, rc );
328 1.1 lukem SQLFreeStmt( sth, SQL_DROP );
329 1.1 lukem
330 1.1 lukem rs->sr_text = "SQL-backend error";
331 1.1 lukem rs->sr_err = LDAP_OTHER;
332 1.1 lukem e = NULL;
333 1.1 lukem goto done;
334 1.1 lukem }
335 1.1 lukem
336 1.1 lukem rc = backsql_BindParamID( sth, 2, SQL_PARAM_INPUT, &n_id.eid_id );
337 1.1 lukem if ( rc != SQL_SUCCESS ) {
338 1.1 lukem Debug( LDAP_DEBUG_TRACE,
339 1.1 lukem " backsql_add_attr(): "
340 1.1 lukem "error binding parent ID parameter for objectClass %s\n",
341 1.1 lukem oc->bom_oc->soc_cname.bv_val, 0, 0 );
342 1.1 lukem backsql_PrintErrors( bi->sql_db_env, dbh,
343 1.1 lukem sth, rc );
344 1.1 lukem SQLFreeStmt( sth, SQL_DROP );
345 1.1 lukem
346 1.1 lukem rs->sr_text = "SQL-backend error";
347 1.1 lukem rs->sr_err = LDAP_OTHER;
348 1.1 lukem e = NULL;
349 1.1 lukem goto done;
350 1.1 lukem }
351 1.1 lukem
352 1.1 lukem rc = backsql_BindParamID( sth, 3, SQL_PARAM_INPUT, &e_id.eid_keyval );
353 1.1 lukem if ( rc != SQL_SUCCESS ) {
354 1.1 lukem Debug( LDAP_DEBUG_TRACE,
355 1.1 lukem " backsql_add_attr(): "
356 1.1 lukem "error binding entry ID parameter for objectClass %s\n",
357 1.1 lukem oc->bom_oc->soc_cname.bv_val, 0, 0 );
358 1.1 lukem backsql_PrintErrors( bi->sql_db_env, dbh,
359 1.1 lukem sth, rc );
360 1.1 lukem SQLFreeStmt( sth, SQL_DROP );
361 1.1 lukem
362 1.1 lukem rs->sr_text = "SQL-backend error";
363 1.1 lukem rs->sr_err = LDAP_OTHER;
364 1.1 lukem e = NULL;
365 1.1 lukem goto done;
366 1.1 lukem }
367 1.1 lukem
368 1.1 lukem rc = backsql_BindParamID( sth, 4, SQL_PARAM_INPUT, &e_id.eid_id );
369 1.1 lukem if ( rc != SQL_SUCCESS ) {
370 1.1 lukem Debug( LDAP_DEBUG_TRACE,
371 1.1 lukem " backsql_add_attr(): "
372 1.1 lukem "error binding ID parameter for objectClass %s\n",
373 1.1 lukem oc->bom_oc->soc_cname.bv_val, 0, 0 );
374 1.1 lukem backsql_PrintErrors( bi->sql_db_env, dbh,
375 1.1 lukem sth, rc );
376 1.1 lukem SQLFreeStmt( sth, SQL_DROP );
377 1.1 lukem
378 1.1 lukem rs->sr_text = "SQL-backend error";
379 1.1 lukem rs->sr_err = LDAP_OTHER;
380 1.1 lukem e = NULL;
381 1.1 lukem goto done;
382 1.1 lukem }
383 1.1 lukem
384 1.1 lukem rc = SQLExecute( sth );
385 1.1 lukem if ( rc != SQL_SUCCESS ) {
386 1.1 lukem Debug( LDAP_DEBUG_TRACE, " backsql_modrdn(): "
387 1.1 lukem "could not rename ldap_entries record\n", 0, 0, 0 );
388 1.1 lukem backsql_PrintErrors( bi->sql_db_env, dbh, sth, rc );
389 1.1 lukem SQLFreeStmt( sth, SQL_DROP );
390 1.1 lukem rs->sr_err = LDAP_OTHER;
391 1.1 lukem rs->sr_text = "SQL-backend error";
392 1.1 lukem e = NULL;
393 1.1 lukem goto done;
394 1.1 lukem }
395 1.1 lukem SQLFreeStmt( sth, SQL_DROP );
396 1.1 lukem
397 1.1 lukem assert( op->orr_modlist != NULL );
398 1.1 lukem
399 1.1 lukem slap_mods_opattrs( op, &op->orr_modlist, 1 );
400 1.1 lukem
401 1.1 lukem assert( e_id.eid_oc != NULL );
402 1.1 lukem oc = e_id.eid_oc;
403 1.1 lukem rs->sr_err = backsql_modify_internal( op, rs, dbh, oc, &e_id, op->orr_modlist );
404 1.1 lukem slap_graduate_commit_csn( op );
405 1.1 lukem if ( rs->sr_err != LDAP_SUCCESS ) {
406 1.1 lukem e = &r;
407 1.1 lukem goto done;
408 1.1 lukem }
409 1.1 lukem
410 1.1 lukem if ( BACKSQL_CHECK_SCHEMA( bi ) ) {
411 1.1 lukem char textbuf[ SLAP_TEXT_BUFLEN ] = { '\0' };
412 1.1 lukem
413 1.1 lukem backsql_entry_clean( op, &r );
414 1.1 lukem (void)backsql_free_entryID( &e_id, 0, op->o_tmpmemctx );
415 1.1 lukem
416 1.1 lukem bsi.bsi_e = &r;
417 1.1 lukem rs->sr_err = backsql_init_search( &bsi, &new_ndn,
418 1.1 lukem LDAP_SCOPE_BASE,
419 1.1 lukem (time_t)(-1), NULL, dbh, op, rs,
420 1.1 lukem slap_anlist_all_attributes,
421 1.1 lukem ( BACKSQL_ISF_MATCHED | BACKSQL_ISF_GET_ENTRY ) );
422 1.1 lukem switch ( rs->sr_err ) {
423 1.1 lukem case LDAP_SUCCESS:
424 1.1 lukem break;
425 1.1 lukem
426 1.1 lukem case LDAP_REFERRAL:
427 1.1 lukem if ( manageDSAit && !BER_BVISNULL( &bsi.bsi_e->e_nname ) &&
428 1.1 lukem dn_match( &new_ndn, &bsi.bsi_e->e_nname ) )
429 1.1 lukem {
430 1.1 lukem rs->sr_err = LDAP_SUCCESS;
431 1.1 lukem rs->sr_text = NULL;
432 1.1 lukem rs->sr_matched = NULL;
433 1.1 lukem if ( rs->sr_ref ) {
434 1.1 lukem ber_bvarray_free( rs->sr_ref );
435 1.1 lukem rs->sr_ref = NULL;
436 1.1 lukem }
437 1.1 lukem break;
438 1.1 lukem }
439 1.1 lukem e = &r;
440 1.1 lukem /* fallthru */
441 1.1 lukem
442 1.1 lukem default:
443 1.1 lukem Debug( LDAP_DEBUG_TRACE, "backsql_modrdn(): "
444 1.1 lukem "could not retrieve modrdnDN ID - no such entry\n",
445 1.1 lukem 0, 0, 0 );
446 1.1 lukem if ( !BER_BVISNULL( &r.e_nname ) ) {
447 1.1 lukem /* FIXME: should always be true! */
448 1.1 lukem e = &r;
449 1.1 lukem
450 1.1 lukem } else {
451 1.1 lukem e = NULL;
452 1.1 lukem }
453 1.1 lukem goto done;
454 1.1 lukem }
455 1.1 lukem
456 1.1 lukem e_id = bsi.bsi_base_id;
457 1.1 lukem
458 1.1 lukem rs->sr_err = entry_schema_check( op, &r, NULL, 0, 0,
459 1.1 lukem &rs->sr_text, textbuf, sizeof( textbuf ) );
460 1.1 lukem if ( rs->sr_err != LDAP_SUCCESS ) {
461 1.1 lukem Debug( LDAP_DEBUG_TRACE, " backsql_modrdn(\"%s\"): "
462 1.1 lukem "entry failed schema check -- aborting\n",
463 1.1 lukem r.e_name.bv_val, 0, 0 );
464 1.1 lukem e = NULL;
465 1.1 lukem goto done;
466 1.1 lukem }
467 1.1 lukem }
468 1.1 lukem
469 1.1 lukem done:;
470 1.1 lukem if ( e != NULL ) {
471 1.1 lukem if ( !access_allowed( op, e, slap_schema.si_ad_entry, NULL,
472 1.1 lukem ACL_DISCLOSE, NULL ) )
473 1.1 lukem {
474 1.1 lukem rs->sr_err = LDAP_NO_SUCH_OBJECT;
475 1.1 lukem rs->sr_text = NULL;
476 1.1 lukem rs->sr_matched = NULL;
477 1.1 lukem if ( rs->sr_ref ) {
478 1.1 lukem ber_bvarray_free( rs->sr_ref );
479 1.1 lukem rs->sr_ref = NULL;
480 1.1 lukem }
481 1.1 lukem }
482 1.1 lukem }
483 1.1 lukem
484 1.1 lukem /*
485 1.1 lukem * Commit only if all operations succeed
486 1.1 lukem */
487 1.1 lukem if ( sth != SQL_NULL_HSTMT ) {
488 1.1 lukem SQLUSMALLINT CompletionType = SQL_ROLLBACK;
489 1.1 lukem
490 1.1 lukem if ( rs->sr_err == LDAP_SUCCESS && !op->o_noop ) {
491 1.1 lukem CompletionType = SQL_COMMIT;
492 1.1 lukem }
493 1.1 lukem
494 1.1 lukem SQLTransact( SQL_NULL_HENV, dbh, CompletionType );
495 1.1 lukem }
496 1.1 lukem
497 1.1 lukem if ( op->o_noop && rs->sr_err == LDAP_SUCCESS ) {
498 1.1 lukem rs->sr_err = LDAP_X_NO_OPERATION;
499 1.1 lukem }
500 1.1 lukem
501 1.1 lukem send_ldap_result( op, rs );
502 1.1 lukem slap_graduate_commit_csn( op );
503 1.1 lukem
504 1.1 lukem if ( !BER_BVISNULL( &realnew_dn ) && realnew_dn.bv_val != new_dn.bv_val ) {
505 1.1 lukem ch_free( realnew_dn.bv_val );
506 1.1 lukem }
507 1.1 lukem
508 1.1 lukem if ( !BER_BVISNULL( &new_dn ) ) {
509 1.1 lukem slap_sl_free( new_dn.bv_val, op->o_tmpmemctx );
510 1.1 lukem }
511 1.1 lukem
512 1.1 lukem if ( !BER_BVISNULL( &new_ndn ) ) {
513 1.1 lukem slap_sl_free( new_ndn.bv_val, op->o_tmpmemctx );
514 1.1 lukem }
515 1.1 lukem
516 1.1 lukem if ( !BER_BVISNULL( &e_id.eid_ndn ) ) {
517 1.1 lukem (void)backsql_free_entryID( &e_id, 0, op->o_tmpmemctx );
518 1.1 lukem }
519 1.1 lukem
520 1.1 lukem if ( !BER_BVISNULL( &n_id.eid_ndn ) ) {
521 1.1 lukem (void)backsql_free_entryID( &n_id, 0, op->o_tmpmemctx );
522 1.1 lukem }
523 1.1 lukem
524 1.1 lukem if ( !BER_BVISNULL( &r.e_nname ) ) {
525 1.1 lukem backsql_entry_clean( op, &r );
526 1.1 lukem }
527 1.1 lukem
528 1.1 lukem if ( !BER_BVISNULL( &p.e_nname ) ) {
529 1.1 lukem backsql_entry_clean( op, &p );
530 1.1 lukem }
531 1.1 lukem
532 1.1 lukem if ( !BER_BVISNULL( &n.e_nname ) ) {
533 1.1 lukem backsql_entry_clean( op, &n );
534 1.1 lukem }
535 1.1 lukem
536 1.1 lukem if ( rs->sr_ref ) {
537 1.1 lukem ber_bvarray_free( rs->sr_ref );
538 1.1 lukem rs->sr_ref = NULL;
539 1.1 lukem }
540 1.1 lukem
541 1.1 lukem Debug( LDAP_DEBUG_TRACE, "<==backsql_modrdn()\n", 0, 0, 0 );
542 1.1 lukem
543 1.1 lukem return rs->sr_err;
544 1.1 lukem }
545 1.1 lukem
546