modrdn.c revision 1.2 1 1.2 christos /* $NetBSD: modrdn.c,v 1.2 2020/08/11 13:15:39 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.2 christos * Copyright 1998-2020 The OpenLDAP Foundation.
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 /* Portions Copyright 1999, Juan C. Gomez, All rights reserved.
18 1.1 lukem * This software is not subject to any license of Silicon Graphics
19 1.1 lukem * Inc. or Purdue University.
20 1.1 lukem *
21 1.1 lukem * Redistribution and use in source and binary forms are permitted
22 1.1 lukem * without restriction or fee of any kind as long as this notice
23 1.1 lukem * is preserved.
24 1.1 lukem */
25 1.1 lukem /* Portions Copyright (c) 1995 Regents of the University of Michigan.
26 1.1 lukem * All rights reserved.
27 1.1 lukem *
28 1.1 lukem * Redistribution and use in source and binary forms are permitted
29 1.1 lukem * provided that this notice is preserved and that due credit is given
30 1.1 lukem * to the University of Michigan at Ann Arbor. The name of the University
31 1.1 lukem * may not be used to endorse or promote products derived from this
32 1.1 lukem * software without specific prior written permission. This software
33 1.1 lukem * is provided ``as is'' without express or implied warranty.
34 1.1 lukem */
35 1.1 lukem
36 1.2 christos #include <sys/cdefs.h>
37 1.2 christos __RCSID("$NetBSD: modrdn.c,v 1.2 2020/08/11 13:15:39 christos Exp $");
38 1.2 christos
39 1.1 lukem #include "portable.h"
40 1.1 lukem
41 1.1 lukem #include <stdio.h>
42 1.1 lukem
43 1.1 lukem #include <ac/socket.h>
44 1.1 lukem #include <ac/string.h>
45 1.1 lukem
46 1.1 lukem #include "slap.h"
47 1.1 lukem
48 1.1 lukem int
49 1.1 lukem do_modrdn(
50 1.1 lukem Operation *op,
51 1.1 lukem SlapReply *rs
52 1.1 lukem )
53 1.1 lukem {
54 1.1 lukem struct berval dn = BER_BVNULL;
55 1.1 lukem struct berval newrdn = BER_BVNULL;
56 1.1 lukem struct berval newSuperior = BER_BVNULL;
57 1.1 lukem ber_int_t deloldrdn;
58 1.1 lukem
59 1.1 lukem struct berval pnewSuperior = BER_BVNULL;
60 1.1 lukem
61 1.1 lukem struct berval nnewSuperior = BER_BVNULL;
62 1.1 lukem
63 1.1 lukem ber_len_t length;
64 1.1 lukem
65 1.1 lukem Debug( LDAP_DEBUG_TRACE, "%s do_modrdn\n",
66 1.1 lukem op->o_log_prefix, 0, 0 );
67 1.1 lukem /*
68 1.1 lukem * Parse the modrdn request. It looks like this:
69 1.1 lukem *
70 1.1 lukem * ModifyRDNRequest := SEQUENCE {
71 1.1 lukem * entry DistinguishedName,
72 1.1 lukem * newrdn RelativeDistinguishedName
73 1.1 lukem * deleteoldrdn BOOLEAN,
74 1.1 lukem * newSuperior [0] LDAPDN OPTIONAL (v3 Only!)
75 1.1 lukem * }
76 1.1 lukem */
77 1.1 lukem
78 1.1 lukem if ( ber_scanf( op->o_ber, "{mmb", &dn, &newrdn, &deloldrdn )
79 1.1 lukem == LBER_ERROR )
80 1.1 lukem {
81 1.1 lukem Debug( LDAP_DEBUG_ANY, "%s do_modrdn: ber_scanf failed\n",
82 1.1 lukem op->o_log_prefix, 0, 0 );
83 1.1 lukem send_ldap_discon( op, rs, LDAP_PROTOCOL_ERROR, "decoding error" );
84 1.1 lukem return SLAPD_DISCONNECT;
85 1.1 lukem }
86 1.1 lukem
87 1.1 lukem /* Check for newSuperior parameter, if present scan it */
88 1.1 lukem
89 1.1 lukem if ( ber_peek_tag( op->o_ber, &length ) == LDAP_TAG_NEWSUPERIOR ) {
90 1.1 lukem if ( op->o_protocol < LDAP_VERSION3 ) {
91 1.1 lukem /* Connection record indicates v2 but field
92 1.1 lukem * newSuperior is present: report error.
93 1.1 lukem */
94 1.1 lukem Debug( LDAP_DEBUG_ANY,
95 1.1 lukem "%s do_modrdn: newSuperior requires LDAPv3\n",
96 1.1 lukem op->o_log_prefix, 0, 0 );
97 1.1 lukem
98 1.1 lukem send_ldap_discon( op, rs,
99 1.1 lukem LDAP_PROTOCOL_ERROR, "newSuperior requires LDAPv3" );
100 1.1 lukem rs->sr_err = SLAPD_DISCONNECT;
101 1.1 lukem goto cleanup;
102 1.1 lukem }
103 1.1 lukem
104 1.1 lukem if ( ber_scanf( op->o_ber, "m", &newSuperior )
105 1.1 lukem == LBER_ERROR ) {
106 1.1 lukem
107 1.1 lukem Debug( LDAP_DEBUG_ANY, "%s do_modrdn: ber_scanf(\"m\") failed\n",
108 1.1 lukem op->o_log_prefix, 0, 0 );
109 1.1 lukem
110 1.1 lukem send_ldap_discon( op, rs,
111 1.1 lukem LDAP_PROTOCOL_ERROR, "decoding error" );
112 1.1 lukem rs->sr_err = SLAPD_DISCONNECT;
113 1.1 lukem goto cleanup;
114 1.1 lukem }
115 1.1 lukem op->orr_newSup = &pnewSuperior;
116 1.1 lukem op->orr_nnewSup = &nnewSuperior;
117 1.1 lukem }
118 1.1 lukem
119 1.1 lukem Debug( LDAP_DEBUG_ARGS,
120 1.1 lukem "do_modrdn: dn (%s) newrdn (%s) newsuperior (%s)\n",
121 1.1 lukem dn.bv_val, newrdn.bv_val,
122 1.1 lukem newSuperior.bv_len ? newSuperior.bv_val : "" );
123 1.1 lukem
124 1.1 lukem if ( ber_scanf( op->o_ber, /*{*/ "}") == LBER_ERROR ) {
125 1.1 lukem Debug( LDAP_DEBUG_ANY, "%s do_modrdn: ber_scanf failed\n",
126 1.1 lukem op->o_log_prefix, 0, 0 );
127 1.1 lukem send_ldap_discon( op, rs,
128 1.1 lukem LDAP_PROTOCOL_ERROR, "decoding error" );
129 1.1 lukem rs->sr_err = SLAPD_DISCONNECT;
130 1.1 lukem goto cleanup;
131 1.1 lukem }
132 1.1 lukem
133 1.1 lukem if( get_ctrls( op, rs, 1 ) != LDAP_SUCCESS ) {
134 1.1 lukem Debug( LDAP_DEBUG_ANY, "%s do_modrdn: get_ctrls failed\n",
135 1.1 lukem op->o_log_prefix, 0, 0 );
136 1.1 lukem /* get_ctrls has sent results. Now clean up. */
137 1.1 lukem goto cleanup;
138 1.1 lukem }
139 1.1 lukem
140 1.1 lukem rs->sr_err = dnPrettyNormal( NULL, &dn, &op->o_req_dn, &op->o_req_ndn, op->o_tmpmemctx );
141 1.1 lukem if( rs->sr_err != LDAP_SUCCESS ) {
142 1.1 lukem Debug( LDAP_DEBUG_ANY, "%s do_modrdn: invalid dn (%s)\n",
143 1.1 lukem op->o_log_prefix, dn.bv_val, 0 );
144 1.1 lukem send_ldap_error( op, rs, LDAP_INVALID_DN_SYNTAX, "invalid DN" );
145 1.1 lukem goto cleanup;
146 1.1 lukem }
147 1.1 lukem
148 1.1 lukem /* FIXME: should have/use rdnPretty / rdnNormalize routines */
149 1.1 lukem
150 1.1 lukem rs->sr_err = dnPrettyNormal( NULL, &newrdn, &op->orr_newrdn, &op->orr_nnewrdn, op->o_tmpmemctx );
151 1.1 lukem if( rs->sr_err != LDAP_SUCCESS ) {
152 1.1 lukem Debug( LDAP_DEBUG_ANY, "%s do_modrdn: invalid newrdn (%s)\n",
153 1.1 lukem op->o_log_prefix, newrdn.bv_val, 0 );
154 1.1 lukem send_ldap_error( op, rs, LDAP_INVALID_DN_SYNTAX, "invalid new RDN" );
155 1.1 lukem goto cleanup;
156 1.1 lukem }
157 1.1 lukem
158 1.1 lukem if( rdn_validate( &op->orr_newrdn ) != LDAP_SUCCESS ) {
159 1.1 lukem Debug( LDAP_DEBUG_ANY, "%s do_modrdn: invalid rdn (%s)\n",
160 1.1 lukem op->o_log_prefix, op->orr_newrdn.bv_val, 0 );
161 1.1 lukem send_ldap_error( op, rs, LDAP_INVALID_DN_SYNTAX, "invalid new RDN" );
162 1.1 lukem goto cleanup;
163 1.1 lukem }
164 1.1 lukem
165 1.1 lukem if( op->orr_newSup ) {
166 1.1 lukem rs->sr_err = dnPrettyNormal( NULL, &newSuperior, &pnewSuperior,
167 1.1 lukem &nnewSuperior, op->o_tmpmemctx );
168 1.1 lukem if( rs->sr_err != LDAP_SUCCESS ) {
169 1.1 lukem Debug( LDAP_DEBUG_ANY,
170 1.1 lukem "%s do_modrdn: invalid newSuperior (%s)\n",
171 1.1 lukem op->o_log_prefix, newSuperior.bv_val, 0 );
172 1.1 lukem send_ldap_error( op, rs, LDAP_INVALID_DN_SYNTAX, "invalid newSuperior" );
173 1.1 lukem goto cleanup;
174 1.1 lukem }
175 1.1 lukem }
176 1.1 lukem
177 1.1 lukem Statslog( LDAP_DEBUG_STATS, "%s MODRDN dn=\"%s\"\n",
178 1.1 lukem op->o_log_prefix, op->o_req_dn.bv_val, 0, 0, 0 );
179 1.1 lukem
180 1.1 lukem op->orr_deleteoldrdn = deloldrdn;
181 1.1 lukem op->orr_modlist = NULL;
182 1.1 lukem
183 1.1 lukem /* prepare modlist of modifications from old/new RDN */
184 1.1 lukem rs->sr_err = slap_modrdn2mods( op, rs );
185 1.1 lukem if ( rs->sr_err != LDAP_SUCCESS ) {
186 1.1 lukem send_ldap_result( op, rs );
187 1.1 lukem goto cleanup;
188 1.1 lukem }
189 1.1 lukem
190 1.1 lukem op->o_bd = frontendDB;
191 1.1 lukem rs->sr_err = frontendDB->be_modrdn( op, rs );
192 1.1 lukem
193 1.1 lukem #ifdef LDAP_X_TXN
194 1.1 lukem if( rs->sr_err == LDAP_X_TXN_SPECIFY_OKAY ) {
195 1.1 lukem /* skip cleanup */
196 1.1 lukem }
197 1.1 lukem #endif
198 1.1 lukem
199 1.1 lukem cleanup:
200 1.1 lukem op->o_tmpfree( op->o_req_dn.bv_val, op->o_tmpmemctx );
201 1.1 lukem op->o_tmpfree( op->o_req_ndn.bv_val, op->o_tmpmemctx );
202 1.1 lukem
203 1.1 lukem op->o_tmpfree( op->orr_newrdn.bv_val, op->o_tmpmemctx );
204 1.1 lukem op->o_tmpfree( op->orr_nnewrdn.bv_val, op->o_tmpmemctx );
205 1.1 lukem
206 1.1 lukem if ( op->orr_modlist != NULL )
207 1.1 lukem slap_mods_free( op->orr_modlist, 1 );
208 1.1 lukem
209 1.1 lukem if ( !BER_BVISNULL( &pnewSuperior ) ) {
210 1.1 lukem op->o_tmpfree( pnewSuperior.bv_val, op->o_tmpmemctx );
211 1.1 lukem }
212 1.1 lukem if ( !BER_BVISNULL( &nnewSuperior ) ) {
213 1.1 lukem op->o_tmpfree( nnewSuperior.bv_val, op->o_tmpmemctx );
214 1.1 lukem }
215 1.1 lukem
216 1.1 lukem return rs->sr_err;
217 1.1 lukem }
218 1.1 lukem
219 1.1 lukem int
220 1.1 lukem fe_op_modrdn( Operation *op, SlapReply *rs )
221 1.1 lukem {
222 1.1 lukem struct berval dest_ndn = BER_BVNULL, dest_pndn, pdn = BER_BVNULL;
223 1.1 lukem BackendDB *op_be, *bd = op->o_bd;
224 1.1 lukem ber_slen_t diff;
225 1.1 lukem
226 1.1 lukem if( op->o_req_ndn.bv_len == 0 ) {
227 1.1 lukem Debug( LDAP_DEBUG_ANY, "%s do_modrdn: root dse!\n",
228 1.1 lukem op->o_log_prefix, 0, 0 );
229 1.1 lukem send_ldap_error( op, rs, LDAP_UNWILLING_TO_PERFORM,
230 1.1 lukem "cannot rename the root DSE" );
231 1.1 lukem goto cleanup;
232 1.1 lukem
233 1.1 lukem } else if ( bvmatch( &op->o_req_ndn, &frontendDB->be_schemandn ) ) {
234 1.1 lukem Debug( LDAP_DEBUG_ANY, "%s do_modrdn: subschema subentry: %s (%ld)\n",
235 1.1 lukem op->o_log_prefix, frontendDB->be_schemandn.bv_val, (long)frontendDB->be_schemandn.bv_len );
236 1.1 lukem
237 1.1 lukem send_ldap_error( op, rs, LDAP_UNWILLING_TO_PERFORM,
238 1.1 lukem "cannot rename subschema subentry" );
239 1.1 lukem goto cleanup;
240 1.1 lukem }
241 1.1 lukem
242 1.1 lukem if( op->orr_nnewSup ) {
243 1.1 lukem dest_pndn = *op->orr_nnewSup;
244 1.1 lukem } else {
245 1.1 lukem dnParent( &op->o_req_ndn, &dest_pndn );
246 1.1 lukem }
247 1.1 lukem build_new_dn( &dest_ndn, &dest_pndn, &op->orr_nnewrdn, op->o_tmpmemctx );
248 1.1 lukem
249 1.1 lukem diff = (ber_slen_t) dest_ndn.bv_len - (ber_slen_t) op->o_req_ndn.bv_len;
250 1.1 lukem if ( diff > 0 ? dnIsSuffix( &dest_ndn, &op->o_req_ndn )
251 1.1 lukem : diff < 0 && dnIsSuffix( &op->o_req_ndn, &dest_ndn ) )
252 1.1 lukem {
253 1.1 lukem send_ldap_error( op, rs, LDAP_UNWILLING_TO_PERFORM,
254 1.1 lukem diff > 0 ? "cannot place an entry below itself"
255 1.1 lukem : "cannot place an entry above itself" );
256 1.1 lukem goto cleanup;
257 1.1 lukem }
258 1.1 lukem
259 1.1 lukem /*
260 1.1 lukem * We could be serving multiple database backends. Select the
261 1.1 lukem * appropriate one, or send a referral to our "referral server"
262 1.1 lukem * if we don't hold it.
263 1.1 lukem */
264 1.1 lukem op->o_bd = select_backend( &op->o_req_ndn, 1 );
265 1.1 lukem if ( op->o_bd == NULL ) {
266 1.1 lukem op->o_bd = bd;
267 1.1 lukem rs->sr_ref = referral_rewrite( default_referral,
268 1.1 lukem NULL, &op->o_req_dn, LDAP_SCOPE_DEFAULT );
269 1.1 lukem if (!rs->sr_ref) rs->sr_ref = default_referral;
270 1.1 lukem
271 1.1 lukem if ( rs->sr_ref != NULL ) {
272 1.1 lukem rs->sr_err = LDAP_REFERRAL;
273 1.1 lukem send_ldap_result( op, rs );
274 1.1 lukem
275 1.1 lukem if (rs->sr_ref != default_referral) ber_bvarray_free( rs->sr_ref );
276 1.1 lukem } else {
277 1.1 lukem send_ldap_error( op, rs, LDAP_UNWILLING_TO_PERFORM,
278 1.1 lukem "no global superior knowledge" );
279 1.1 lukem }
280 1.1 lukem goto cleanup;
281 1.1 lukem }
282 1.1 lukem
283 1.1 lukem /* If we've got a glued backend, check the real backend */
284 1.1 lukem op_be = op->o_bd;
285 1.1 lukem if ( SLAP_GLUE_INSTANCE( op->o_bd )) {
286 1.1 lukem op->o_bd = select_backend( &op->o_req_ndn, 0 );
287 1.1 lukem }
288 1.1 lukem
289 1.1 lukem /* check restrictions */
290 1.1 lukem if( backend_check_restrictions( op, rs, NULL ) != LDAP_SUCCESS ) {
291 1.1 lukem send_ldap_result( op, rs );
292 1.1 lukem goto cleanup;
293 1.1 lukem }
294 1.1 lukem
295 1.1 lukem /* check for referrals */
296 1.1 lukem if ( backend_check_referrals( op, rs ) != LDAP_SUCCESS ) {
297 1.1 lukem goto cleanup;
298 1.1 lukem }
299 1.1 lukem
300 1.1 lukem /* check that destination DN is in the same backend as source DN */
301 1.1 lukem if ( select_backend( &dest_ndn, 0 ) != op->o_bd ) {
302 1.1 lukem send_ldap_error( op, rs, LDAP_AFFECTS_MULTIPLE_DSAS,
303 1.1 lukem "cannot rename between DSAs" );
304 1.1 lukem goto cleanup;
305 1.1 lukem }
306 1.1 lukem
307 1.1 lukem /*
308 1.1 lukem * do the modrdn if 1 && (2 || 3)
309 1.1 lukem * 1) there is a modrdn function implemented in this backend;
310 1.1 lukem * 2) this backend is master for what it holds;
311 1.1 lukem * 3) it's a replica and the dn supplied is the update_ndn.
312 1.1 lukem */
313 1.1 lukem if ( op->o_bd->be_modrdn ) {
314 1.1 lukem /* do the update here */
315 1.1 lukem int repl_user = be_isupdate( op );
316 1.1 lukem if ( !SLAP_SINGLE_SHADOW(op->o_bd) || repl_user )
317 1.1 lukem {
318 1.1 lukem op->o_bd = op_be;
319 1.1 lukem op->o_bd->be_modrdn( op, rs );
320 1.1 lukem
321 1.1 lukem if ( op->o_bd->be_delete ) {
322 1.1 lukem struct berval org_req_dn = BER_BVNULL;
323 1.1 lukem struct berval org_req_ndn = BER_BVNULL;
324 1.1 lukem struct berval org_dn = BER_BVNULL;
325 1.1 lukem struct berval org_ndn = BER_BVNULL;
326 1.1 lukem int org_managedsait;
327 1.1 lukem
328 1.1 lukem org_req_dn = op->o_req_dn;
329 1.1 lukem org_req_ndn = op->o_req_ndn;
330 1.1 lukem org_dn = op->o_dn;
331 1.1 lukem org_ndn = op->o_ndn;
332 1.1 lukem org_managedsait = get_manageDSAit( op );
333 1.1 lukem op->o_dn = op->o_bd->be_rootdn;
334 1.1 lukem op->o_ndn = op->o_bd->be_rootndn;
335 1.1 lukem op->o_managedsait = SLAP_CONTROL_NONCRITICAL;
336 1.1 lukem
337 1.1 lukem while ( rs->sr_err == LDAP_SUCCESS &&
338 1.1 lukem op->o_delete_glue_parent ) {
339 1.1 lukem op->o_delete_glue_parent = 0;
340 1.1 lukem if ( !be_issuffix( op->o_bd, &op->o_req_ndn )) {
341 1.1 lukem slap_callback cb = { NULL };
342 1.1 lukem cb.sc_response = slap_null_cb;
343 1.1 lukem dnParent( &op->o_req_ndn, &pdn );
344 1.1 lukem op->o_req_dn = pdn;
345 1.1 lukem op->o_req_ndn = pdn;
346 1.1 lukem op->o_callback = &cb;
347 1.1 lukem op->o_bd->be_delete( op, rs );
348 1.1 lukem } else {
349 1.1 lukem break;
350 1.1 lukem }
351 1.1 lukem }
352 1.1 lukem op->o_managedsait = org_managedsait;
353 1.1 lukem op->o_dn = org_dn;
354 1.1 lukem op->o_ndn = org_ndn;
355 1.1 lukem op->o_req_dn = org_req_dn;
356 1.1 lukem op->o_req_ndn = org_req_ndn;
357 1.1 lukem op->o_delete_glue_parent = 0;
358 1.1 lukem }
359 1.1 lukem
360 1.1 lukem } else {
361 1.1 lukem BerVarray defref = op->o_bd->be_update_refs
362 1.1 lukem ? op->o_bd->be_update_refs : default_referral;
363 1.1 lukem
364 1.1 lukem if ( defref != NULL ) {
365 1.1 lukem rs->sr_ref = referral_rewrite( defref,
366 1.1 lukem NULL, &op->o_req_dn, LDAP_SCOPE_DEFAULT );
367 1.1 lukem if (!rs->sr_ref) rs->sr_ref = defref;
368 1.1 lukem
369 1.1 lukem rs->sr_err = LDAP_REFERRAL;
370 1.1 lukem send_ldap_result( op, rs );
371 1.1 lukem
372 1.1 lukem if (rs->sr_ref != defref) ber_bvarray_free( rs->sr_ref );
373 1.1 lukem } else {
374 1.1 lukem send_ldap_error( op, rs, LDAP_UNWILLING_TO_PERFORM,
375 1.1 lukem "shadow context; no update referral" );
376 1.1 lukem }
377 1.1 lukem }
378 1.1 lukem } else {
379 1.1 lukem send_ldap_error( op, rs, LDAP_UNWILLING_TO_PERFORM,
380 1.1 lukem "operation not supported within namingContext" );
381 1.1 lukem }
382 1.1 lukem
383 1.1 lukem cleanup:;
384 1.1 lukem if ( dest_ndn.bv_val != NULL )
385 1.1 lukem ber_memfree_x( dest_ndn.bv_val, op->o_tmpmemctx );
386 1.1 lukem op->o_bd = bd;
387 1.1 lukem return rs->sr_err;
388 1.1 lukem }
389 1.1 lukem
390 1.1 lukem int
391 1.1 lukem slap_modrdn2mods(
392 1.1 lukem Operation *op,
393 1.1 lukem SlapReply *rs )
394 1.1 lukem {
395 1.1 lukem int a_cnt, d_cnt;
396 1.1 lukem LDAPRDN old_rdn = NULL;
397 1.1 lukem LDAPRDN new_rdn = NULL;
398 1.1 lukem
399 1.1 lukem assert( !BER_BVISEMPTY( &op->oq_modrdn.rs_newrdn ) );
400 1.2 christos
401 1.2 christos /* if requestDN is empty, silently reset deleteOldRDN */
402 1.2 christos if ( BER_BVISEMPTY( &op->o_req_dn ) ) op->orr_deleteoldrdn = 0;
403 1.1 lukem
404 1.1 lukem if ( ldap_bv2rdn_x( &op->oq_modrdn.rs_newrdn, &new_rdn,
405 1.1 lukem (char **)&rs->sr_text, LDAP_DN_FORMAT_LDAP, op->o_tmpmemctx ) ) {
406 1.1 lukem Debug( LDAP_DEBUG_TRACE,
407 1.1 lukem "%s slap_modrdn2mods: can't figure out "
408 1.1 lukem "type(s)/value(s) of newrdn\n",
409 1.1 lukem op->o_log_prefix, 0, 0 );
410 1.1 lukem rs->sr_err = LDAP_INVALID_DN_SYNTAX;
411 1.2 christos rs->sr_text = "unknown type(s)/value(s) used in RDN";
412 1.1 lukem goto done;
413 1.1 lukem }
414 1.1 lukem
415 1.1 lukem if ( op->oq_modrdn.rs_deleteoldrdn ) {
416 1.1 lukem if ( ldap_bv2rdn_x( &op->o_req_dn, &old_rdn,
417 1.1 lukem (char **)&rs->sr_text, LDAP_DN_FORMAT_LDAP, op->o_tmpmemctx ) ) {
418 1.1 lukem Debug( LDAP_DEBUG_TRACE,
419 1.1 lukem "%s slap_modrdn2mods: can't figure out "
420 1.1 lukem "type(s)/value(s) of oldrdn\n",
421 1.1 lukem op->o_log_prefix, 0, 0 );
422 1.1 lukem rs->sr_err = LDAP_OTHER;
423 1.1 lukem rs->sr_text = "cannot parse RDN from old DN";
424 1.1 lukem goto done;
425 1.1 lukem }
426 1.1 lukem }
427 1.1 lukem rs->sr_text = NULL;
428 1.1 lukem
429 1.1 lukem /* Add new attribute values to the entry */
430 1.1 lukem for ( a_cnt = 0; new_rdn[a_cnt]; a_cnt++ ) {
431 1.1 lukem AttributeDescription *desc = NULL;
432 1.1 lukem Modifications *mod_tmp;
433 1.1 lukem
434 1.1 lukem rs->sr_err = slap_bv2ad( &new_rdn[a_cnt]->la_attr, &desc, &rs->sr_text );
435 1.1 lukem
436 1.1 lukem if ( rs->sr_err != LDAP_SUCCESS ) {
437 1.1 lukem Debug( LDAP_DEBUG_TRACE,
438 1.1 lukem "%s slap_modrdn2mods: %s: %s (new)\n",
439 1.1 lukem op->o_log_prefix,
440 1.2 christos rs->sr_text,
441 1.1 lukem new_rdn[ a_cnt ]->la_attr.bv_val );
442 1.1 lukem goto done;
443 1.1 lukem }
444 1.1 lukem
445 1.2 christos if ( !desc->ad_type->sat_equality ) {
446 1.2 christos Debug( LDAP_DEBUG_TRACE,
447 1.2 christos "%s slap_modrdn2mods: %s: %s (new)\n",
448 1.2 christos op->o_log_prefix,
449 1.2 christos rs->sr_text,
450 1.2 christos new_rdn[ a_cnt ]->la_attr.bv_val );
451 1.2 christos rs->sr_text = "naming attribute has no equality matching rule";
452 1.2 christos rs->sr_err = LDAP_NAMING_VIOLATION;
453 1.2 christos goto done;
454 1.2 christos }
455 1.2 christos
456 1.1 lukem /* Apply modification */
457 1.1 lukem mod_tmp = ( Modifications * )ch_malloc( sizeof( Modifications ) );
458 1.1 lukem mod_tmp->sml_desc = desc;
459 1.1 lukem BER_BVZERO( &mod_tmp->sml_type );
460 1.1 lukem mod_tmp->sml_numvals = 1;
461 1.1 lukem mod_tmp->sml_values = ( BerVarray )ch_malloc( 2 * sizeof( struct berval ) );
462 1.1 lukem ber_dupbv( &mod_tmp->sml_values[0], &new_rdn[a_cnt]->la_value );
463 1.1 lukem mod_tmp->sml_values[1].bv_val = NULL;
464 1.1 lukem if( desc->ad_type->sat_equality->smr_normalize) {
465 1.1 lukem mod_tmp->sml_nvalues = ( BerVarray )ch_malloc( 2 * sizeof( struct berval ) );
466 1.2 christos rs->sr_err = desc->ad_type->sat_equality->smr_normalize(
467 1.1 lukem SLAP_MR_EQUALITY|SLAP_MR_VALUE_OF_ASSERTION_SYNTAX,
468 1.1 lukem desc->ad_type->sat_syntax,
469 1.1 lukem desc->ad_type->sat_equality,
470 1.1 lukem &mod_tmp->sml_values[0],
471 1.1 lukem &mod_tmp->sml_nvalues[0], NULL );
472 1.2 christos if (rs->sr_err != LDAP_SUCCESS) {
473 1.2 christos ch_free(mod_tmp->sml_nvalues);
474 1.2 christos ch_free(mod_tmp->sml_values[0].bv_val);
475 1.2 christos ch_free(mod_tmp->sml_values);
476 1.2 christos ch_free(mod_tmp);
477 1.2 christos goto done;
478 1.2 christos }
479 1.1 lukem mod_tmp->sml_nvalues[1].bv_val = NULL;
480 1.1 lukem } else {
481 1.1 lukem mod_tmp->sml_nvalues = NULL;
482 1.1 lukem }
483 1.1 lukem mod_tmp->sml_op = SLAP_MOD_SOFTADD;
484 1.1 lukem mod_tmp->sml_flags = 0;
485 1.1 lukem mod_tmp->sml_next = op->orr_modlist;
486 1.1 lukem op->orr_modlist = mod_tmp;
487 1.1 lukem }
488 1.1 lukem
489 1.1 lukem /* Remove old rdn value if required */
490 1.1 lukem if ( op->orr_deleteoldrdn ) {
491 1.1 lukem for ( d_cnt = 0; old_rdn[d_cnt]; d_cnt++ ) {
492 1.1 lukem AttributeDescription *desc = NULL;
493 1.1 lukem Modifications *mod_tmp;
494 1.1 lukem
495 1.1 lukem rs->sr_err = slap_bv2ad( &old_rdn[d_cnt]->la_attr, &desc, &rs->sr_text );
496 1.1 lukem if ( rs->sr_err != LDAP_SUCCESS ) {
497 1.1 lukem Debug( LDAP_DEBUG_TRACE,
498 1.1 lukem "%s slap_modrdn2mods: %s: %s (old)\n",
499 1.1 lukem op->o_log_prefix,
500 1.1 lukem rs->sr_text,
501 1.1 lukem old_rdn[d_cnt]->la_attr.bv_val );
502 1.1 lukem goto done;
503 1.1 lukem }
504 1.1 lukem
505 1.1 lukem /* Apply modification */
506 1.1 lukem mod_tmp = ( Modifications * )ch_malloc( sizeof( Modifications ) );
507 1.1 lukem mod_tmp->sml_desc = desc;
508 1.1 lukem BER_BVZERO( &mod_tmp->sml_type );
509 1.1 lukem mod_tmp->sml_numvals = 1;
510 1.1 lukem mod_tmp->sml_values = ( BerVarray )ch_malloc( 2 * sizeof( struct berval ) );
511 1.1 lukem ber_dupbv( &mod_tmp->sml_values[0], &old_rdn[d_cnt]->la_value );
512 1.1 lukem mod_tmp->sml_values[1].bv_val = NULL;
513 1.1 lukem if( desc->ad_type->sat_equality->smr_normalize) {
514 1.1 lukem mod_tmp->sml_nvalues = ( BerVarray )ch_malloc( 2 * sizeof( struct berval ) );
515 1.1 lukem (void) (*desc->ad_type->sat_equality->smr_normalize)(
516 1.1 lukem SLAP_MR_EQUALITY|SLAP_MR_VALUE_OF_ASSERTION_SYNTAX,
517 1.1 lukem desc->ad_type->sat_syntax,
518 1.1 lukem desc->ad_type->sat_equality,
519 1.1 lukem &mod_tmp->sml_values[0],
520 1.1 lukem &mod_tmp->sml_nvalues[0], NULL );
521 1.1 lukem mod_tmp->sml_nvalues[1].bv_val = NULL;
522 1.1 lukem } else {
523 1.1 lukem mod_tmp->sml_nvalues = NULL;
524 1.1 lukem }
525 1.1 lukem mod_tmp->sml_op = LDAP_MOD_DELETE;
526 1.1 lukem mod_tmp->sml_flags = 0;
527 1.1 lukem mod_tmp->sml_next = op->orr_modlist;
528 1.1 lukem op->orr_modlist = mod_tmp;
529 1.1 lukem }
530 1.1 lukem }
531 1.1 lukem
532 1.1 lukem done:
533 1.1 lukem
534 1.1 lukem /* LDAP v2 supporting correct attribute handling. */
535 1.1 lukem if ( rs->sr_err != LDAP_SUCCESS && op->orr_modlist != NULL ) {
536 1.1 lukem Modifications *tmp;
537 1.1 lukem
538 1.1 lukem for ( ; op->orr_modlist != NULL; op->orr_modlist = tmp ) {
539 1.1 lukem tmp = op->orr_modlist->sml_next;
540 1.1 lukem ch_free( op->orr_modlist );
541 1.1 lukem }
542 1.1 lukem }
543 1.1 lukem
544 1.1 lukem if ( new_rdn != NULL ) {
545 1.1 lukem ldap_rdnfree_x( new_rdn, op->o_tmpmemctx );
546 1.1 lukem }
547 1.1 lukem if ( old_rdn != NULL ) {
548 1.1 lukem ldap_rdnfree_x( old_rdn, op->o_tmpmemctx );
549 1.1 lukem }
550 1.1 lukem
551 1.1 lukem return rs->sr_err;
552 1.1 lukem }
553 1.1 lukem
554