3 * Copyright 1998-2000 The OpenLDAP Foundation, All Rights Reserved.
4 * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
7 * Copyright (c) 1995 Regents of the University of Michigan.
10 * Redistribution and use in source and binary forms are permitted
11 * provided that this notice is preserved and that due credit is given
12 * to the University of Michigan at Ann Arbor. The name of the University
13 * may not be used to endorse or promote products derived from this
14 * software without specific prior written permission. This software
15 * is provided ``as is'' without express or implied warranty.
19 * LDAP v3 newSuperior support.
21 * Copyright 1999, Juan C. Gomez, All rights reserved.
22 * This software is not subject to any license of Silicon Graphics
23 * Inc. or Purdue University.
25 * Redistribution and use in source and binary forms are permitted
26 * without restriction or fee of any kind as long as this notice
35 #include <ac/socket.h>
36 #include <ac/string.h>
47 char *dn, *ndn = NULL, *newrdn;
50 /* Vars for LDAP v3 newSuperior support */
51 char *newSuperior = NULL;
52 char *nnewSuperior = NULL;
53 Backend *newSuperior_be = NULL;
60 LDAP_LOG(( "operation", LDAP_LEVEL_ENTRY,
61 "do_modrdn: begin\n" ));
63 Debug( LDAP_DEBUG_TRACE, "do_modrdn\n", 0, 0, 0 );
68 * Parse the modrdn request. It looks like this:
70 * ModifyRDNRequest := SEQUENCE {
71 * entry DistinguishedName,
72 * newrdn RelativeDistinguishedName
73 * deleteoldrdn BOOLEAN,
74 * newSuperior [0] LDAPDN OPTIONAL (v3 Only!)
78 if ( ber_scanf( op->o_ber, "{aab", &dn, &newrdn, &deloldrdn )
81 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
82 "do_modrdn: ber_scanf failed\n" ));
84 Debug( LDAP_DEBUG_ANY, "ber_scanf failed\n", 0, 0, 0 );
87 send_ldap_disconnect( conn, op,
88 LDAP_PROTOCOL_ERROR, "decoding error" );
89 return SLAPD_DISCONNECT;
92 /* Check for newSuperior parameter, if present scan it */
94 if ( ber_peek_tag( op->o_ber, &length ) == LDAP_TAG_NEWSUPERIOR ) {
95 if ( op->o_protocol < LDAP_VERSION3 ) {
96 /* Conection record indicates v2 but field
97 * newSuperior is present: report error.
100 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
101 "do_modrdn: (v2) invalid field newSuperior.\n" ));
103 Debug( LDAP_DEBUG_ANY,
104 "modrdn(v2): invalid field newSuperior!\n",
108 send_ldap_disconnect( conn, op,
109 LDAP_PROTOCOL_ERROR, "newSuperior requires LDAPv3" );
110 rc = SLAPD_DISCONNECT;
114 if ( ber_scanf( op->o_ber, "a", &newSuperior )
118 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
119 "do_modrdn: ber_scanf(\"a\") failed\n" ));
121 Debug( LDAP_DEBUG_ANY, "ber_scanf(\"a\") failed\n",
125 send_ldap_disconnect( conn, op,
126 LDAP_PROTOCOL_ERROR, "decoding error" );
127 rc = SLAPD_DISCONNECT;
131 nnewSuperior = ch_strdup( newSuperior );
133 if( dn_normalize( nnewSuperior ) == NULL ) {
135 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
136 "do_modrdn: invalid new superior (%s)\n", newSuperior ));
138 Debug( LDAP_DEBUG_ANY, "do_modrdn: invalid new superior (%s)\n",
142 send_ldap_result( conn, op, rc = LDAP_INVALID_DN_SYNTAX, NULL,
143 "invalid new superior DN", NULL, NULL );
150 LDAP_LOG(( "operation", LDAP_LEVEL_ARGS,
151 "do_modrdn: dn (%s) newrdn (%s) newsuperior(%s)\n",
152 dn, newrdn, newSuperior != NULL ? newSuperior : "" ));
154 Debug( LDAP_DEBUG_ARGS,
155 "do_modrdn: dn (%s) newrdn (%s) newsuperior (%s)\n",
157 newSuperior != NULL ? newSuperior : "" );
161 if ( ber_scanf( op->o_ber, /*{*/ "}") == LBER_ERROR ) {
163 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
164 "do_modrdn: ber_scanf failed\n" ));
166 Debug( LDAP_DEBUG_ANY, "do_modrdn: ber_scanf failed\n", 0, 0, 0 );
169 send_ldap_disconnect( conn, op,
170 LDAP_PROTOCOL_ERROR, "decoding error" );
171 rc = SLAPD_DISCONNECT;
175 if( (rc = get_ctrls( conn, op, 1 )) != LDAP_SUCCESS ) {
177 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
178 "do_modrdn: get_ctrls failed\n" ));
180 Debug( LDAP_DEBUG_ANY, "do_modrdn: get_ctrls failed\n", 0, 0, 0 );
183 /* get_ctrls has sent results. Now clean up. */
187 ndn = ch_strdup( dn );
189 if( dn_normalize( ndn ) == NULL ) {
191 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
192 "do_modrdn: invalid dn (%s)\n", dn ));
194 Debug( LDAP_DEBUG_ANY, "do_modrdn: invalid dn (%s)\n", dn, 0, 0 );
197 send_ldap_result( conn, op, rc = LDAP_INVALID_DN_SYNTAX, NULL,
198 "invalid DN", NULL, NULL );
202 if( !rdn_validate( newrdn ) ) {
204 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
205 "do_modrdn: invalid rdn (%s).\n", newrdn ));
207 Debug( LDAP_DEBUG_ANY, "do_modrdn: invalid rdn (%s)\n", newrdn, 0, 0 );
210 send_ldap_result( conn, op, rc = LDAP_INVALID_DN_SYNTAX, NULL,
211 "invalid RDN", NULL, NULL );
217 LDAP_LOG(( "operation", LDAP_LEVEL_ERR,
218 "do_modrdn: attempt to modify root DSE.\n" ));
220 Debug( LDAP_DEBUG_ANY, "do_modrdn: root dse!\n", 0, 0, 0 );
223 send_ldap_result( conn, op, rc = LDAP_UNWILLING_TO_PERFORM,
224 NULL, "cannot rename the root DSE", NULL, NULL );
228 Statslog( LDAP_DEBUG_STATS, "conn=%ld op=%d MODRDN dn=\"%s\"\n",
229 op->o_connid, op->o_opid, dn, 0, 0 );
231 manageDSAit = get_manageDSAit( op );
234 * We could be serving multiple database backends. Select the
235 * appropriate one, or send a referral to our "referral server"
236 * if we don't hold it.
238 if ( (be = select_backend( ndn, manageDSAit )) == NULL ) {
239 send_ldap_result( conn, op, rc = LDAP_REFERRAL,
240 NULL, NULL, default_referral, NULL );
244 /* check restrictions */
245 rc = backend_check_restrictions( be, conn, op, NULL, &text ) ;
246 if( rc != LDAP_SUCCESS ) {
247 send_ldap_result( conn, op, rc,
248 NULL, text, NULL, NULL );
252 /* check for referrals */
253 rc = backend_check_referrals( be, conn, op, dn, ndn );
254 if ( rc != LDAP_SUCCESS ) {
258 /* Make sure that the entry being changed and the newSuperior are in
259 * the same backend, otherwise we return an error.
261 if( newSuperior != NULL ) {
262 newSuperior_be = select_backend( nnewSuperior, 0 );
264 if ( newSuperior_be != be ) {
265 /* newSuperior is in same backend */
266 rc = LDAP_AFFECTS_MULTIPLE_DSAS;
268 send_ldap_result( conn, op, rc,
269 NULL, "cannot rename between DSAa", NULL, NULL );
274 /* deref suffix alias if appropriate */
275 nnewSuperior = suffix_alias( be, nnewSuperior );
278 /* deref suffix alias if appropriate */
279 ndn = suffix_alias( be, ndn );
282 * do the add if 1 && (2 || 3)
283 * 1) there is an add function implemented in this backend;
284 * 2) this backend is master for what it holds;
285 * 3) it's a replica and the dn supplied is the update_ndn.
287 if ( be->be_modrdn ) {
288 /* do the update here */
289 #ifndef SLAPD_MULTIMASTER
290 if ( be->be_update_ndn == NULL ||
291 strcmp( be->be_update_ndn, op->o_ndn ) == 0 )
294 if ( (*be->be_modrdn)( be, conn, op, dn, ndn, newrdn,
295 deloldrdn, newSuperior ) == 0
296 #ifdef SLAPD_MULTIMASTER
297 && ( be->be_update_ndn == NULL ||
298 strcmp( be->be_update_ndn, op->o_ndn ) )
301 struct replog_moddn moddn;
302 moddn.newrdn = newrdn;
303 moddn.deloldrdn = deloldrdn;
304 moddn.newsup = newSuperior;
306 replog( be, op, dn, &moddn );
308 #ifndef SLAPD_MULTIMASTER
310 send_ldap_result( conn, op, rc = LDAP_REFERRAL, NULL, NULL,
311 be->be_update_refs ? be->be_update_refs : default_referral, NULL );
315 send_ldap_result( conn, op, rc = LDAP_UNWILLING_TO_PERFORM,
316 NULL, "operation not supported within namingContext", NULL, NULL );
321 if( ndn != NULL ) free( ndn );
323 if ( newSuperior != NULL )
325 if ( nnewSuperior != NULL )
326 free( nnewSuperior );