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 );
54 * Parse the modrdn request. It looks like this:
56 * ModifyRDNRequest := SEQUENCE {
57 * entry DistinguishedName,
58 * newrdn RelativeDistinguishedName
59 * deleteoldrdn BOOLEAN,
60 * newSuperior [0] LDAPDN OPTIONAL (v3 Only!)
64 if ( ber_scanf( op->o_ber, "{aab", &ndn, &newrdn, &deloldrdn )
66 Debug( LDAP_DEBUG_ANY, "ber_scanf failed\n", 0, 0, 0 );
67 send_ldap_result( conn, op, rc = LDAP_PROTOCOL_ERROR, NULL, "" );
71 /* Check for newSuperior parameter, if present scan it */
73 if ( ber_peek_tag( op->o_ber, &length ) == LDAP_TAG_NEWSUPERIOR ) {
75 if ( op->o_protocol == 0 ) {
79 ldap_pvt_thread_mutex_lock( &conn->c_mutex );
80 conn->c_protocol = LDAP_VERSION3;
81 ldap_pvt_thread_mutex_unlock( &conn->c_mutex );
82 op->o_protocol = LDAP_VERSION3;
84 } else if ( op->o_protocol < LDAP_VERSION3 ) {
85 /* Conection record indicates v2 but field
86 * newSuperior is present: report error.
88 Debug( LDAP_DEBUG_ANY,
89 "modrdn(v2): invalid field newSuperior!\n",
91 send_ldap_result( conn, op, rc = LDAP_PROTOCOL_ERROR,
96 if ( ber_scanf( op->o_ber, "a", &newSuperior )
99 Debug( LDAP_DEBUG_ANY, "ber_scanf(\"a\"}) failed\n",
101 send_ldap_result( conn, op, rc = LDAP_PROTOCOL_ERROR, NULL,
109 Debug( LDAP_DEBUG_ARGS,
110 "do_modrdn: dn (%s) newrdn (%s) newsuperior (%s)\n",
112 newSuperior != NULL ? newSuperior : "" );
114 if ( ber_scanf( op->o_ber, /*{*/ "}") == LBER_ERROR ) {
118 Debug( LDAP_DEBUG_ANY, "do_modrdn: ber_scanf failed\n", 0, 0, 0 );
119 send_ldap_result( conn, op, rc = LDAP_PROTOCOL_ERROR, NULL,
125 if( (rc = get_ctrls( conn, op, 1 )) != LDAP_SUCCESS ) {
129 Debug( LDAP_DEBUG_ANY, "do_modrdn: get_ctrls failed\n", 0, 0, 0 );
134 if( newSuperior != NULL ) {
135 /* GET BACKEND FOR NEW SUPERIOR */
137 nnewSuperior = strdup( newSuperior );
138 dn_normalize_case( nnewSuperior );
140 if ( (newSuperior_be = select_backend( nnewSuperior ))
143 /* We do not have a backend for newSuperior so we send
145 * XXX: We may need to do something else here, not sure
149 Debug( LDAP_DEBUG_ARGS,
150 "do_modrdn: cant find backend for=(%s)\n",
156 free( nnewSuperior );
157 send_ldap_result( conn, op, LDAP_PARTIAL_RESULTS, NULL,
163 dn_normalize_case( ndn );
165 Statslog( LDAP_DEBUG_STATS, "conn=%d op=%d MODRDN dn=\"%s\"\n",
166 conn->c_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_PARTIAL_RESULTS, NULL,
184 /* Make sure that the entry being changed and the newSuperior are in
185 * the same backend, otherwise we return an error.
188 if ( (newSuperior_be != NULL) && ( be != newSuperior_be) ) {
190 Debug( LDAP_DEBUG_ANY, "dn=(%s), newSuperior=(%s)\n", ndn,
196 free( nnewSuperior );
198 send_ldap_result( conn, op, rc = LDAP_AFFECTS_MULTIPLE_DSAS,
206 /* alias suffix if approp */
207 ndn = suffixAlias( ndn, op, be );
210 * do the add if 1 && (2 || 3)
211 * 1) there is an add function implemented in this backend;
212 * 2) this backend is master for what it holds;
213 * 3) it's a replica and the dn supplied is the update_ndn.
215 if ( be->be_modrdn ) {
216 /* do the update here */
217 if ( be->be_update_ndn == NULL ||
218 strcmp( be->be_update_ndn, op->o_ndn ) == 0 )
220 if ( (*be->be_modrdn)( be, conn, op, ndn, newrdn,
221 deloldrdn, newSuperior ) == 0 ) {
222 /* XXX: MAY NEED TO ADD newSuperior HERE */
223 replog( be, LDAP_REQ_MODRDN, ndn, newrdn,
227 send_ldap_result( conn, op, rc = LDAP_PARTIAL_RESULTS, NULL,
231 send_ldap_result( conn, op, rc = LDAP_UNWILLING_TO_PERFORM, NULL,
232 "Function not implemented" );
238 free( nnewSuperior );