3 * Copyright 1998-1999 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>
46 char *dn, *ndn, *newrdn;
49 /* Vars for LDAP v3 newSuperior support */
50 char *newSuperior = NULL;
51 char *nnewSuperior = NULL;
52 Backend *newSuperior_be = NULL;
56 Debug( LDAP_DEBUG_TRACE, "do_modrdn\n", 0, 0, 0 );
58 if( op->o_bind_in_progress ) {
59 Debug( LDAP_DEBUG_ANY, "do_modrdn: SASL bind in progress.\n",
61 send_ldap_result( conn, op, LDAP_SASL_BIND_IN_PROGRESS,
62 NULL, "SASL bind in progress", NULL, NULL );
63 return LDAP_SASL_BIND_IN_PROGRESS;
67 * Parse the modrdn request. It looks like this:
69 * ModifyRDNRequest := SEQUENCE {
70 * entry DistinguishedName,
71 * newrdn RelativeDistinguishedName
72 * deleteoldrdn BOOLEAN,
73 * newSuperior [0] LDAPDN OPTIONAL (v3 Only!)
77 if ( ber_scanf( op->o_ber, "{aab", &dn, &newrdn, &deloldrdn )
79 Debug( LDAP_DEBUG_ANY, "ber_scanf failed\n", 0, 0, 0 );
80 send_ldap_disconnect( conn, op,
81 LDAP_PROTOCOL_ERROR, "decoding error" );
85 ndn = ch_strdup( dn );
87 if( dn_normalize( ndn ) == NULL ) {
88 Debug( LDAP_DEBUG_ANY, "do_modrdn: invalid dn (%s)\n", dn, 0, 0 );
89 send_ldap_result( conn, op, rc = LDAP_INVALID_DN_SYNTAX, NULL,
90 "invalid DN", NULL, NULL );
94 if( !rdn_validate( newrdn ) ) {
95 Debug( LDAP_DEBUG_ANY, "do_modrdn: invalid rdn (%s)\n", newrdn, 0, 0 );
96 send_ldap_result( conn, op, rc = LDAP_INVALID_DN_SYNTAX, NULL,
97 "invalid RDN", NULL, NULL );
101 /* Check for newSuperior parameter, if present scan it */
103 if ( ber_peek_tag( op->o_ber, &length ) == LDAP_TAG_NEWSUPERIOR ) {
104 if ( op->o_protocol < LDAP_VERSION3 ) {
105 /* Conection record indicates v2 but field
106 * newSuperior is present: report error.
108 Debug( LDAP_DEBUG_ANY,
109 "modrdn(v2): invalid field newSuperior!\n",
111 send_ldap_disconnect( conn, op,
112 LDAP_PROTOCOL_ERROR, "newSuperior requires LDAPv3" );
117 if ( ber_scanf( op->o_ber, "a", &newSuperior )
120 Debug( LDAP_DEBUG_ANY, "ber_scanf(\"a\") failed\n",
122 send_ldap_disconnect( conn, op,
123 LDAP_PROTOCOL_ERROR, "decoding error" );
128 nnewSuperior = ch_strdup( newSuperior );
130 if( dn_normalize( nnewSuperior ) == NULL ) {
131 Debug( LDAP_DEBUG_ANY, "do_modrdn: invalid new superior (%s)\n",
133 send_ldap_result( conn, op, rc = LDAP_INVALID_DN_SYNTAX, NULL,
134 "invalid (new superior) DN", NULL, NULL );
140 Debug( LDAP_DEBUG_ARGS,
141 "do_modrdn: dn (%s) newrdn (%s) newsuperior (%s)\n",
143 newSuperior != NULL ? newSuperior : "" );
145 if ( ber_scanf( op->o_ber, /*{*/ "}") == LBER_ERROR ) {
146 Debug( LDAP_DEBUG_ANY, "do_modrdn: ber_scanf failed\n", 0, 0, 0 );
147 send_ldap_disconnect( conn, op,
148 LDAP_PROTOCOL_ERROR, "decoding error" );
153 if( (rc = get_ctrls( conn, op, 1 )) != LDAP_SUCCESS ) {
154 Debug( LDAP_DEBUG_ANY, "do_modrdn: get_ctrls failed\n", 0, 0, 0 );
155 /* get_ctrls has sent results. Now clean up. */
159 Statslog( LDAP_DEBUG_STATS, "conn=%ld op=%d MODRDN dn=\"%s\"\n",
160 op->o_connid, op->o_opid, dn, 0, 0 );
163 * We could be serving multiple database backends. Select the
164 * appropriate one, or send a referral to our "referral server"
165 * if we don't hold it.
168 if ( (be = select_backend( ndn )) == NULL ) {
169 send_ldap_result( conn, op, rc = LDAP_REFERRAL,
170 NULL, NULL, default_referral, NULL );
174 if ( global_readonly || be->be_readonly ) {
175 Debug( LDAP_DEBUG_ANY, "do_modrdn: database is read-only\n",
177 send_ldap_result( conn, op, rc = LDAP_UNWILLING_TO_PERFORM,
178 NULL, "database is read-only", NULL, NULL );
182 /* Make sure that the entry being changed and the newSuperior are in
183 * the same backend, otherwise we return an error.
185 if( newSuperior != NULL ) {
186 newSuperior_be = select_backend( nnewSuperior );
188 if ( newSuperior_be != be ) {
189 /* newSuperior is in same backend */
190 rc = LDAP_AFFECTS_MULTIPLE_DSAS;
192 send_ldap_result( conn, op, rc,
193 NULL, NULL, NULL, NULL );
198 /* deref suffix alias if appropriate */
199 nnewSuperior = suffix_alias( be, nnewSuperior );
202 /* deref suffix alias if appropriate */
203 ndn = suffix_alias( be, ndn );
206 * do the add if 1 && (2 || 3)
207 * 1) there is an add function implemented in this backend;
208 * 2) this backend is master for what it holds;
209 * 3) it's a replica and the dn supplied is the update_ndn.
211 if ( be->be_modrdn ) {
212 /* do the update here */
213 #ifndef SLAPD_MULTIMASTER
214 if ( be->be_update_ndn == NULL ||
215 strcmp( be->be_update_ndn, op->o_ndn ) == 0 )
218 if ( (*be->be_modrdn)( be, conn, op, dn, ndn, newrdn,
219 deloldrdn, newSuperior ) == 0
220 #ifdef SLAPD_MULTIMASTER
221 && ( be->be_update_ndn == NULL ||
222 strcmp( be->be_update_ndn, op->o_ndn ) )
225 struct replog_moddn moddn;
226 moddn.newrdn = newrdn;
227 moddn.deloldrdn = deloldrdn;
228 moddn.newsup = newSuperior;
230 replog( be, op, dn, &moddn );
232 #ifndef SLAPD_MULTIMASTER
234 send_ldap_result( conn, op, rc = LDAP_REFERRAL, NULL, NULL,
235 be->be_update_refs ? be->be_update_refs : default_referral, NULL );
239 send_ldap_result( conn, op, rc = LDAP_UNWILLING_TO_PERFORM,
240 NULL, "Function not implemented", NULL, NULL );
247 if ( newSuperior != NULL )
249 if ( nnewSuperior != NULL )
250 free( nnewSuperior );