2 * Copyright (c) 1995 Regents of the University of Michigan.
5 * Redistribution and use in source and binary forms are permitted
6 * provided that this notice is preserved and that due credit is given
7 * to the University of Michigan at Ann Arbor. The name of the University
8 * may not be used to endorse or promote products derived from this
9 * software without specific prior written permission. This software
10 * is provided ``as is'' without express or implied warranty.
14 * LDAP v3 newSuperior support.
16 * Copyright 1999, Juan C. Gomez, All rights reserved.
17 * This software is not subject to any license of Silicon Graphics
18 * Inc. or Purdue University.
20 * Redistribution and use in source and binary forms are permitted
21 * without restriction or fee of any kind as long as this notice
30 #include <ac/socket.h>
31 #include <ac/string.h>
44 /* Vars for LDAP v3 newSuperior support */
45 char *newSuperior = NULL;
46 char *nnewSuperior = NULL;
47 Backend *newSuperior_be = NULL;
51 Debug( LDAP_DEBUG_TRACE, "do_modrdn\n", 0, 0, 0 );
53 if( op->o_bind_in_progress ) {
54 Debug( LDAP_DEBUG_ANY, "do_modrdn: SASL bind in progress.\n",
56 send_ldap_result( conn, op, LDAP_SASL_BIND_IN_PROGRESS,
57 NULL, "SASL bind in progress", NULL, NULL );
58 return LDAP_SASL_BIND_IN_PROGRESS;
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", &ndn, &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" );
80 /* Check for newSuperior parameter, if present scan it */
82 if ( ber_peek_tag( op->o_ber, &length ) == LDAP_TAG_NEWSUPERIOR ) {
84 if ( op->o_protocol == 0 ) {
88 ldap_pvt_thread_mutex_lock( &conn->c_mutex );
89 conn->c_protocol = LDAP_VERSION3;
90 ldap_pvt_thread_mutex_unlock( &conn->c_mutex );
91 op->o_protocol = LDAP_VERSION3;
93 } else if ( op->o_protocol < LDAP_VERSION3 ) {
94 /* Conection record indicates v2 but field
95 * newSuperior is present: report error.
97 Debug( LDAP_DEBUG_ANY,
98 "modrdn(v2): invalid field newSuperior!\n",
100 send_ldap_disconnect( conn, op,
101 LDAP_PROTOCOL_ERROR, "newSuperior requires LDAPv3" );
105 if ( ber_scanf( op->o_ber, "a", &newSuperior )
108 Debug( LDAP_DEBUG_ANY, "ber_scanf(\"a\"}) failed\n",
110 send_ldap_disconnect( conn, op,
111 LDAP_PROTOCOL_ERROR, "decoding error" );
118 Debug( LDAP_DEBUG_ARGS,
119 "do_modrdn: dn (%s) newrdn (%s) newsuperior (%s)\n",
121 newSuperior != NULL ? newSuperior : "" );
123 if ( ber_scanf( op->o_ber, /*{*/ "}") == LBER_ERROR ) {
127 Debug( LDAP_DEBUG_ANY, "do_modrdn: ber_scanf failed\n", 0, 0, 0 );
128 send_ldap_disconnect( conn, op,
129 LDAP_PROTOCOL_ERROR, "decoding error" );
133 if( (rc = get_ctrls( conn, op, 1 )) != LDAP_SUCCESS ) {
137 Debug( LDAP_DEBUG_ANY, "do_modrdn: get_ctrls failed\n", 0, 0, 0 );
141 if( newSuperior != NULL ) {
142 /* GET BACKEND FOR NEW SUPERIOR */
144 nnewSuperior = strdup( newSuperior );
145 dn_normalize_case( nnewSuperior );
147 if ( (newSuperior_be = select_backend( nnewSuperior ))
150 /* We do not have a backend for newSuperior so we send
152 * XXX: We may need to do something else here, not sure
156 Debug( LDAP_DEBUG_ARGS,
157 "do_modrdn: cant find backend for=(%s)\n",
163 free( nnewSuperior );
164 send_ldap_result( conn, op, LDAP_REFERRAL,
165 NULL, NULL, default_referral, NULL );
170 dn_normalize_case( ndn );
172 Statslog( LDAP_DEBUG_STATS, "conn=%d op=%d MODRDN dn=\"%s\"\n",
173 op->o_connid, op->o_opid, ndn, 0, 0 );
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.
181 if ( (be = select_backend( ndn )) == NULL ) {
185 free( nnewSuperior );
186 send_ldap_result( conn, op, rc = LDAP_REFERRAL,
187 NULL, NULL, default_referral, NULL );
191 /* Make sure that the entry being changed and the newSuperior are in
192 * the same backend, otherwise we return an error.
195 if ( (newSuperior_be != NULL) && ( be != newSuperior_be) ) {
197 Debug( LDAP_DEBUG_ANY, "dn=(%s), newSuperior=(%s)\n", ndn,
203 free( nnewSuperior );
205 send_ldap_result( conn, op, rc = LDAP_AFFECTS_MULTIPLE_DSAS,
206 NULL, NULL, NULL, NULL );
213 * do the add if 1 && (2 || 3)
214 * 1) there is an add function implemented in this backend;
215 * 2) this backend is master for what it holds;
216 * 3) it's a replica and the dn supplied is the update_ndn.
218 if ( be->be_modrdn ) {
219 /* do the update here */
220 if ( be->be_update_ndn == NULL ||
221 strcmp( be->be_update_ndn, op->o_ndn ) == 0 )
223 if ( (*be->be_modrdn)( be, conn, op, ndn, newrdn,
224 deloldrdn, newSuperior ) == 0 ) {
225 /* XXX: MAY NEED TO ADD newSuperior HERE */
226 replog( be, LDAP_REQ_MODRDN, ndn, newrdn,
230 send_ldap_result( conn, op, rc = LDAP_REFERRAL, NULL, NULL,
231 be->be_update_refs ? be->be_update_refs : default_referral, NULL );
234 send_ldap_result( conn, op, rc = LDAP_UNWILLING_TO_PERFORM,
235 NULL, "Function not implemented", NULL, NULL );
241 free( nnewSuperior );