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