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;
59 Debug( LDAP_DEBUG_TRACE, "do_modrdn\n", 0, 0, 0 );
62 * Parse the modrdn request. It looks like this:
64 * ModifyRDNRequest := SEQUENCE {
65 * entry DistinguishedName,
66 * newrdn RelativeDistinguishedName
67 * deleteoldrdn BOOLEAN,
68 * newSuperior [0] LDAPDN OPTIONAL (v3 Only!)
72 if ( ber_scanf( op->o_ber, "{aab", &dn, &newrdn, &deloldrdn )
74 Debug( LDAP_DEBUG_ANY, "ber_scanf failed\n", 0, 0, 0 );
75 send_ldap_disconnect( conn, op,
76 LDAP_PROTOCOL_ERROR, "decoding error" );
77 return SLAPD_DISCONNECT;
80 /* Check for newSuperior parameter, if present scan it */
82 if ( ber_peek_tag( op->o_ber, &length ) == LDAP_TAG_NEWSUPERIOR ) {
83 if ( op->o_protocol < LDAP_VERSION3 ) {
84 /* Conection record indicates v2 but field
85 * newSuperior is present: report error.
87 Debug( LDAP_DEBUG_ANY,
88 "modrdn(v2): invalid field newSuperior!\n",
90 send_ldap_disconnect( conn, op,
91 LDAP_PROTOCOL_ERROR, "newSuperior requires LDAPv3" );
92 rc = SLAPD_DISCONNECT;
96 if ( ber_scanf( op->o_ber, "a", &newSuperior )
99 Debug( LDAP_DEBUG_ANY, "ber_scanf(\"a\") failed\n",
101 send_ldap_disconnect( conn, op,
102 LDAP_PROTOCOL_ERROR, "decoding error" );
103 rc = SLAPD_DISCONNECT;
107 nnewSuperior = ch_strdup( newSuperior );
109 if( dn_normalize( nnewSuperior ) == NULL ) {
110 Debug( LDAP_DEBUG_ANY, "do_modrdn: invalid new superior (%s)\n",
112 send_ldap_result( conn, op, rc = LDAP_INVALID_DN_SYNTAX, NULL,
113 "invalid new superior DN", NULL, NULL );
119 Debug( LDAP_DEBUG_ARGS,
120 "do_modrdn: dn (%s) newrdn (%s) newsuperior (%s)\n",
122 newSuperior != NULL ? newSuperior : "" );
124 if ( ber_scanf( op->o_ber, /*{*/ "}") == LBER_ERROR ) {
125 Debug( LDAP_DEBUG_ANY, "do_modrdn: ber_scanf failed\n", 0, 0, 0 );
126 send_ldap_disconnect( conn, op,
127 LDAP_PROTOCOL_ERROR, "decoding error" );
128 rc = SLAPD_DISCONNECT;
132 if( (rc = get_ctrls( conn, op, 1 )) != LDAP_SUCCESS ) {
133 Debug( LDAP_DEBUG_ANY, "do_modrdn: get_ctrls failed\n", 0, 0, 0 );
134 /* get_ctrls has sent results. Now clean up. */
138 ndn = ch_strdup( dn );
140 if( dn_normalize( ndn ) == NULL ) {
141 Debug( LDAP_DEBUG_ANY, "do_modrdn: invalid dn (%s)\n", dn, 0, 0 );
142 send_ldap_result( conn, op, rc = LDAP_INVALID_DN_SYNTAX, NULL,
143 "invalid DN", NULL, NULL );
147 if( !rdn_validate( newrdn ) ) {
148 Debug( LDAP_DEBUG_ANY, "do_modrdn: invalid rdn (%s)\n", newrdn, 0, 0 );
149 send_ldap_result( conn, op, rc = LDAP_INVALID_DN_SYNTAX, NULL,
150 "invalid RDN", NULL, NULL );
155 Debug( LDAP_DEBUG_ANY, "do_modrdn: root dse!\n", 0, 0, 0 );
156 send_ldap_result( conn, op, rc = LDAP_UNWILLING_TO_PERFORM,
157 NULL, "cannot rename the root DSE", NULL, NULL );
160 #ifdef SLAPD_SCHEMA_DN
161 } else if ( strcasecmp( ndn, SLAPD_SCHEMA_DN ) == 0 ) {
162 Debug( LDAP_DEBUG_ANY, "do_modrdn: subschema subentry!\n", 0, 0, 0 );
164 send_ldap_result( conn, op, rc = LDAP_UNWILLING_TO_PERFORM,
165 NULL, "cannot rename subschema subentry", NULL, NULL );
170 Statslog( LDAP_DEBUG_STATS, "conn=%ld op=%d MODRDN dn=\"%s\"\n",
171 op->o_connid, op->o_opid, dn, 0, 0 );
173 manageDSAit = get_manageDSAit( op );
176 * We could be serving multiple database backends. Select the
177 * appropriate one, or send a referral to our "referral server"
178 * if we don't hold it.
180 if ( (be = select_backend( ndn, manageDSAit )) == NULL ) {
181 send_ldap_result( conn, op, rc = LDAP_REFERRAL,
182 NULL, NULL, default_referral, NULL );
186 /* check restrictions */
187 rc = backend_check_restrictions( be, conn, op, NULL, &text ) ;
188 if( rc != LDAP_SUCCESS ) {
189 send_ldap_result( conn, op, rc,
190 NULL, text, NULL, NULL );
194 /* check for referrals */
195 rc = backend_check_referrals( be, conn, op, dn, ndn );
196 if ( rc != LDAP_SUCCESS ) {
200 /* Make sure that the entry being changed and the newSuperior are in
201 * the same backend, otherwise we return an error.
203 if( newSuperior != NULL ) {
204 newSuperior_be = select_backend( nnewSuperior, 0 );
206 if ( newSuperior_be != be ) {
207 /* newSuperior is in same backend */
208 rc = LDAP_AFFECTS_MULTIPLE_DSAS;
210 send_ldap_result( conn, op, rc,
211 NULL, "cannot rename between DSAa", NULL, NULL );
216 /* deref suffix alias if appropriate */
217 nnewSuperior = suffix_alias( be, nnewSuperior );
220 /* deref suffix alias if appropriate */
221 ndn = suffix_alias( be, ndn );
224 * do the add if 1 && (2 || 3)
225 * 1) there is an add function implemented in this backend;
226 * 2) this backend is master for what it holds;
227 * 3) it's a replica and the dn supplied is the update_ndn.
229 if ( be->be_modrdn ) {
230 /* do the update here */
231 #ifndef SLAPD_MULTIMASTER
232 if ( be->be_update_ndn == NULL ||
233 strcmp( be->be_update_ndn, op->o_ndn ) == 0 )
236 if ( (*be->be_modrdn)( be, conn, op, dn, ndn, newrdn,
237 deloldrdn, newSuperior ) == 0
238 #ifdef SLAPD_MULTIMASTER
239 && ( be->be_update_ndn == NULL ||
240 strcmp( be->be_update_ndn, op->o_ndn ) )
243 struct replog_moddn moddn;
244 moddn.newrdn = newrdn;
245 moddn.deloldrdn = deloldrdn;
246 moddn.newsup = newSuperior;
248 replog( be, op, dn, &moddn );
250 #ifndef SLAPD_MULTIMASTER
252 send_ldap_result( conn, op, rc = LDAP_REFERRAL, NULL, NULL,
253 be->be_update_refs ? be->be_update_refs : default_referral, NULL );
257 send_ldap_result( conn, op, rc = LDAP_UNWILLING_TO_PERFORM,
258 NULL, "operation not supported within namingContext", NULL, NULL );
263 if( ndn != NULL ) free( ndn );
265 if ( newSuperior != NULL )
267 if ( nnewSuperior != NULL )
268 free( nnewSuperior );