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 if( dn_normalize_case( ndn ) == NULL ) {
81 Debug( LDAP_DEBUG_ANY, "do_modrdn: invalid dn (%s)\n", ndn, 0, 0 );
82 send_ldap_result( conn, op, rc = LDAP_INVALID_DN_SYNTAX, NULL,
83 "invalid DN", NULL, NULL );
89 if( !rdn_validate( newrdn ) ) {
90 Debug( LDAP_DEBUG_ANY, "do_modrdn: invalid rdn (%s)\n", newrdn, 0, 0 );
91 send_ldap_result( conn, op, rc = LDAP_INVALID_DN_SYNTAX, NULL,
92 "invalid RDN", NULL, NULL );
98 /* Check for newSuperior parameter, if present scan it */
100 if ( ber_peek_tag( op->o_ber, &length ) == LDAP_TAG_NEWSUPERIOR ) {
102 if ( op->o_protocol == 0 ) {
106 ldap_pvt_thread_mutex_lock( &conn->c_mutex );
107 conn->c_protocol = LDAP_VERSION3;
108 ldap_pvt_thread_mutex_unlock( &conn->c_mutex );
109 op->o_protocol = LDAP_VERSION3;
111 } else if ( op->o_protocol < LDAP_VERSION3 ) {
112 /* Conection record indicates v2 but field
113 * newSuperior is present: report error.
115 Debug( LDAP_DEBUG_ANY,
116 "modrdn(v2): invalid field newSuperior!\n",
118 send_ldap_disconnect( conn, op,
119 LDAP_PROTOCOL_ERROR, "newSuperior requires LDAPv3" );
123 if ( ber_scanf( op->o_ber, "a", &newSuperior )
126 Debug( LDAP_DEBUG_ANY, "ber_scanf(\"a\"}) failed\n",
128 send_ldap_disconnect( conn, op,
129 LDAP_PROTOCOL_ERROR, "decoding error" );
133 nnewSuperior = ch_strdup( newSuperior );
135 if( dn_normalize_case( nnewSuperior ) == NULL ) {
136 Debug( LDAP_DEBUG_ANY, "do_modrdn: invalid new superior (%s)\n",
138 send_ldap_result( conn, op, rc = LDAP_INVALID_DN_SYNTAX, NULL,
139 "invalid (new superior) DN", NULL, NULL );
147 Debug( LDAP_DEBUG_ARGS,
148 "do_modrdn: dn (%s) newrdn (%s) newsuperior (%s)\n",
150 newSuperior != NULL ? newSuperior : "" );
152 if ( ber_scanf( op->o_ber, /*{*/ "}") == LBER_ERROR ) {
156 free( nnewSuperior );
157 Debug( LDAP_DEBUG_ANY, "do_modrdn: ber_scanf failed\n", 0, 0, 0 );
158 send_ldap_disconnect( conn, op,
159 LDAP_PROTOCOL_ERROR, "decoding error" );
163 if( (rc = get_ctrls( conn, op, 1 )) != LDAP_SUCCESS ) {
167 Debug( LDAP_DEBUG_ANY, "do_modrdn: get_ctrls failed\n", 0, 0, 0 );
171 Statslog( LDAP_DEBUG_STATS, "conn=%d op=%d MODRDN dn=\"%s\"\n",
172 op->o_connid, op->o_opid, ndn, 0, 0 );
175 * We could be serving multiple database backends. Select the
176 * appropriate one, or send a referral to our "referral server"
177 * if we don't hold it.
180 if ( (be = select_backend( ndn )) == NULL ) {
184 free( nnewSuperior );
185 send_ldap_result( conn, op, rc = LDAP_REFERRAL,
186 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.
194 if( newSuperior != NULL ) {
195 newSuperior_be = select_backend( nnewSuperior );
197 if ( newSuperior_be != be ) {
198 /* newSuperior is in same backend */
199 rc = LDAP_AFFECTS_MULTIPLE_DSAS;
201 send_ldap_result( conn, op, rc,
202 NULL, NULL, NULL, NULL );
207 free( nnewSuperior );
214 * do the add if 1 && (2 || 3)
215 * 1) there is an add function implemented in this backend;
216 * 2) this backend is master for what it holds;
217 * 3) it's a replica and the dn supplied is the update_ndn.
219 if ( be->be_modrdn ) {
220 /* do the update here */
221 if ( be->be_update_ndn == NULL ||
222 strcmp( be->be_update_ndn, op->o_ndn ) == 0 )
224 if ( (*be->be_modrdn)( be, conn, op, ndn, newrdn,
225 deloldrdn, newSuperior ) == 0 ) {
226 /* XXX: MAY NEED TO ADD newSuperior HERE */
227 replog( be, LDAP_REQ_MODRDN, ndn, newrdn,
231 send_ldap_result( conn, op, rc = LDAP_REFERRAL, NULL, NULL,
232 be->be_update_refs ? be->be_update_refs : default_referral, NULL );
235 send_ldap_result( conn, op, rc = LDAP_UNWILLING_TO_PERFORM,
236 NULL, "Function not implemented", NULL, NULL );
242 free( nnewSuperior );