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;
50 Debug( LDAP_DEBUG_TRACE, "do_modrdn\n", 0, 0, 0 );
53 * Parse the modrdn request. It looks like this:
55 * ModifyRDNRequest := SEQUENCE {
56 * entry DistinguishedName,
57 * newrdn RelativeDistinguishedName
58 * deleteoldrdn BOOLEAN,
59 * newSuperior [0] LDAPDN OPTIONAL (v3 Only!)
63 if ( ber_scanf( op->o_ber, "{aab", &ndn, &newrdn, &deloldrdn )
65 Debug( LDAP_DEBUG_ANY, "ber_scanf failed\n", 0, 0, 0 );
66 send_ldap_result( conn, op, LDAP_PROTOCOL_ERROR, NULL, "" );
70 /* Check for newSuperior parameter, if present scan it */
72 if ( ber_peek_tag( op->o_ber, &length ) == LDAP_TAG_NEWSUPERIOR ) {
74 if ( op->o_protocol == 0 ) {
78 ldap_pvt_thread_mutex_lock( &conn->c_mutex );
79 conn->c_protocol = LDAP_VERSION3;
80 ldap_pvt_thread_mutex_unlock( &conn->c_mutex );
81 op->o_protocol = LDAP_VERSION3;
83 } else 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_result( conn, op, LDAP_PROTOCOL_ERROR,
95 if ( ber_scanf( op->o_ber, "a", &newSuperior )
98 Debug( LDAP_DEBUG_ANY, "ber_scanf(\"a\"}) failed\n",
100 send_ldap_result( conn, op, LDAP_PROTOCOL_ERROR, NULL,
108 Debug( LDAP_DEBUG_ARGS,
109 "do_modrdn: dn (%s) newrdn (%s) newsuperior (%s)\n",
111 newSuperior != NULL ? newSuperior : "" );
113 if ( ber_scanf( op->o_ber, /*{*/ "}") == LBER_ERROR ) {
117 Debug( LDAP_DEBUG_ANY, "do_modrdn: ber_scanf failed\n", 0, 0, 0 );
118 send_ldap_result( conn, op, LDAP_PROTOCOL_ERROR, NULL,
124 if( get_ctrls( conn, op, 1 ) == -1 ) {
128 Debug( LDAP_DEBUG_ANY, "do_modrdn: get_ctrls failed\n", 0, 0, 0 );
133 if( newSuperior != NULL ) {
134 /* GET BACKEND FOR NEW SUPERIOR */
136 nnewSuperior = strdup( newSuperior );
137 dn_normalize_case( nnewSuperior );
139 if ( (newSuperior_be = select_backend( nnewSuperior ))
142 /* We do not have a backend for newSuperior so we send
144 * XXX: We may need to do something else here, not sure
148 Debug( LDAP_DEBUG_ARGS,
149 "do_modrdn: cant find backend for=(%s)\n",
155 free( nnewSuperior );
156 send_ldap_result( conn, op, LDAP_PARTIAL_RESULTS, NULL,
162 dn_normalize_case( ndn );
164 Statslog( LDAP_DEBUG_STATS, "conn=%d op=%d MODRDN dn=\"%s\"\n",
165 conn->c_connid, op->o_opid, ndn, 0, 0 );
168 * We could be serving multiple database backends. Select the
169 * appropriate one, or send a referral to our "referral server"
170 * if we don't hold it.
173 if ( (be = select_backend( ndn )) == NULL ) {
177 free( nnewSuperior );
178 send_ldap_result( conn, op, LDAP_PARTIAL_RESULTS, NULL,
183 /* Make sure that the entry being changed and the newSuperior are in
184 * the same backend, otherwise we return an error.
187 if ( (newSuperior_be != NULL) && ( be != newSuperior_be) ) {
189 Debug( LDAP_DEBUG_ANY, "dn=(%s), newSuperior=(%s)\n", ndn,
195 free( nnewSuperior );
197 send_ldap_result( conn, op, LDAP_AFFECTS_MULTIPLE_DSAS,
205 /* alias suffix if approp */
206 ndn = suffixAlias( ndn, op, be );
209 * do the add if 1 && (2 || 3)
210 * 1) there is an add function implemented in this backend;
211 * 2) this backend is master for what it holds;
212 * 3) it's a replica and the dn supplied is the update_ndn.
214 if ( be->be_modrdn ) {
215 /* do the update here */
216 if ( be->be_update_ndn == NULL ||
217 strcmp( be->be_update_ndn, op->o_ndn ) == 0 )
219 if ( (*be->be_modrdn)( be, conn, op, ndn, newrdn,
220 deloldrdn, newSuperior ) == 0 ) {
221 /* XXX: MAY NEEED TO ADD newSuperior HERE */
222 replog( be, LDAP_REQ_MODRDN, ndn, newrdn,
226 send_ldap_result( conn, op, LDAP_PARTIAL_RESULTS, NULL,
230 send_ldap_result( conn, op, LDAP_UNWILLING_TO_PERFORM, NULL,
231 "Function not implemented" );
237 free( nnewSuperior );