2 * Copyright 1998-1999 The OpenLDAP Foundation, All Rights Reserved.
3 * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
6 * Copyright (c) 1995 Regents of the University of Michigan.
9 * Redistribution and use in source and binary forms are permitted
10 * provided that this notice is preserved and that due credit is given
11 * to the University of Michigan at Ann Arbor. The name of the University
12 * may not be used to endorse or promote products derived from this
13 * software without specific prior written permission. This software
14 * is provided ``as is'' without express or implied warranty.
18 * LDAP v3 newSuperior support.
20 * Copyright 1999, Juan C. Gomez, All rights reserved.
21 * This software is not subject to any license of Silicon Graphics
22 * Inc. or Purdue University.
24 * Redistribution and use in source and binary forms are permitted
25 * without restriction or fee of any kind as long as this notice
34 #include <ac/socket.h>
35 #include <ac/string.h>
48 /* Vars for LDAP v3 newSuperior support */
49 char *newSuperior = NULL;
50 char *nnewSuperior = NULL;
51 Backend *newSuperior_be = NULL;
55 Debug( LDAP_DEBUG_TRACE, "do_modrdn\n", 0, 0, 0 );
57 if( op->o_bind_in_progress ) {
58 Debug( LDAP_DEBUG_ANY, "do_modrdn: SASL bind in progress.\n",
60 send_ldap_result( conn, op, LDAP_SASL_BIND_IN_PROGRESS,
61 NULL, "SASL bind in progress", NULL, NULL );
62 return LDAP_SASL_BIND_IN_PROGRESS;
66 * Parse the modrdn request. It looks like this:
68 * ModifyRDNRequest := SEQUENCE {
69 * entry DistinguishedName,
70 * newrdn RelativeDistinguishedName
71 * deleteoldrdn BOOLEAN,
72 * newSuperior [0] LDAPDN OPTIONAL (v3 Only!)
76 if ( ber_scanf( op->o_ber, "{aab", &ndn, &newrdn, &deloldrdn )
78 Debug( LDAP_DEBUG_ANY, "ber_scanf failed\n", 0, 0, 0 );
79 send_ldap_disconnect( conn, op,
80 LDAP_PROTOCOL_ERROR, "decoding error" );
84 if( dn_normalize_case( ndn ) == NULL ) {
85 Debug( LDAP_DEBUG_ANY, "do_modrdn: invalid dn (%s)\n", ndn, 0, 0 );
86 send_ldap_result( conn, op, rc = LDAP_INVALID_DN_SYNTAX, NULL,
87 "invalid DN", NULL, NULL );
93 if( !rdn_validate( newrdn ) ) {
94 Debug( LDAP_DEBUG_ANY, "do_modrdn: invalid rdn (%s)\n", newrdn, 0, 0 );
95 send_ldap_result( conn, op, rc = LDAP_INVALID_DN_SYNTAX, NULL,
96 "invalid RDN", NULL, NULL );
102 /* Check for newSuperior parameter, if present scan it */
104 if ( ber_peek_tag( op->o_ber, &length ) == LDAP_TAG_NEWSUPERIOR ) {
105 if ( op->o_protocol < LDAP_VERSION3 ) {
106 /* Conection record indicates v2 but field
107 * newSuperior is present: report error.
109 Debug( LDAP_DEBUG_ANY,
110 "modrdn(v2): invalid field newSuperior!\n",
112 send_ldap_disconnect( conn, op,
113 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" );
127 nnewSuperior = ch_strdup( newSuperior );
129 if( dn_normalize_case( nnewSuperior ) == NULL ) {
130 Debug( LDAP_DEBUG_ANY, "do_modrdn: invalid new superior (%s)\n",
132 send_ldap_result( conn, op, rc = LDAP_INVALID_DN_SYNTAX, NULL,
133 "invalid (new superior) DN", NULL, NULL );
141 Debug( LDAP_DEBUG_ARGS,
142 "do_modrdn: dn (%s) newrdn (%s) newsuperior (%s)\n",
144 newSuperior != NULL ? newSuperior : "" );
146 if ( ber_scanf( op->o_ber, /*{*/ "}") == LBER_ERROR ) {
150 free( nnewSuperior );
151 Debug( LDAP_DEBUG_ANY, "do_modrdn: ber_scanf failed\n", 0, 0, 0 );
152 send_ldap_disconnect( conn, op,
153 LDAP_PROTOCOL_ERROR, "decoding error" );
157 if( (rc = get_ctrls( conn, op, 1 )) != LDAP_SUCCESS ) {
161 Debug( LDAP_DEBUG_ANY, "do_modrdn: get_ctrls failed\n", 0, 0, 0 );
165 Statslog( LDAP_DEBUG_STATS, "conn=%ld op=%d MODRDN dn=\"%s\"\n",
166 op->o_connid, op->o_opid, ndn, 0, 0 );
169 * We could be serving multiple database backends. Select the
170 * appropriate one, or send a referral to our "referral server"
171 * if we don't hold it.
174 if ( (be = select_backend( ndn )) == NULL ) {
178 free( nnewSuperior );
179 send_ldap_result( conn, op, rc = LDAP_REFERRAL,
180 NULL, NULL, default_referral, NULL );
184 if ( global_readonly || be->be_readonly ) {
185 Debug( LDAP_DEBUG_ANY, "do_modrdn: database is read-only\n",
187 send_ldap_result( conn, op, rc = LDAP_UNWILLING_TO_PERFORM,
188 NULL, "database is read-only", NULL, NULL );
192 /* Make sure that the entry being changed and the newSuperior are in
193 * the same backend, otherwise we return an error.
195 if( newSuperior != NULL ) {
196 newSuperior_be = select_backend( nnewSuperior );
198 if ( newSuperior_be != be ) {
199 /* newSuperior is in same backend */
200 rc = LDAP_AFFECTS_MULTIPLE_DSAS;
202 send_ldap_result( conn, op, rc,
203 NULL, NULL, NULL, NULL );
208 free( nnewSuperior );
213 /* deref suffix alias if appropriate */
214 nnewSuperior = suffix_alias( be, nnewSuperior );
217 /* deref suffix alias if appropriate */
218 ndn = suffix_alias( be, ndn );
221 * do the add if 1 && (2 || 3)
222 * 1) there is an add function implemented in this backend;
223 * 2) this backend is master for what it holds;
224 * 3) it's a replica and the dn supplied is the update_ndn.
226 if ( be->be_modrdn ) {
227 /* do the update here */
228 #ifndef SLAPD_MULTIMASTER
229 if ( be->be_update_ndn == NULL ||
230 strcmp( be->be_update_ndn, op->o_ndn ) == 0 )
233 if ( (*be->be_modrdn)( be, conn, op, ndn, newrdn,
234 deloldrdn, newSuperior ) == 0
235 #ifdef SLAPD_MULTIMASTER
236 && ( be->be_update_ndn == NULL ||
237 strcmp( be->be_update_ndn, op->o_ndn ) )
240 struct replog_moddn moddn;
241 moddn.newrdn = newrdn;
242 moddn.deloldrdn = deloldrdn;
243 moddn.newsup = newSuperior;
245 replog( be, op, ndn, &moddn );
247 #ifndef SLAPD_MULTIMASTER
249 send_ldap_result( conn, op, rc = LDAP_REFERRAL, NULL, NULL,
250 be->be_update_refs ? be->be_update_refs : default_referral, NULL );
254 send_ldap_result( conn, op, rc = LDAP_UNWILLING_TO_PERFORM,
255 NULL, "Function not implemented", NULL, NULL );
262 free( nnewSuperior );