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