2 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
4 * Copyright 1998-2005 The OpenLDAP Foundation.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted only as authorized by the OpenLDAP
11 * A copy of this license is available in the file LICENSE in the
12 * top-level directory of the distribution or, alternatively, at
13 * <http://www.OpenLDAP.org/license.html>.
15 /* Portions Copyright (c) 1990 Regents of the University of Michigan.
16 * All rights reserved.
18 /* Copyright 1999, Juan C. Gomez, All rights reserved.
19 * This software is not subject to any license of Silicon Graphics
20 * Inc. or Purdue University.
22 * Redistribution and use in source and binary forms are permitted
23 * without restriction or fee of any kind as long as this notice
26 /* Portions Copyright (C) The Internet Society (1997)
27 * ASN.1 fragments are from RFC 2251; see RFC 2251 for full legal notices.
35 * A modify rdn request looks like this:
36 * ModifyRDNRequest ::= SEQUENCE {
37 * entry DistinguishedName,
38 * newrdn RelativeDistinguishedName,
39 * deleteoldrdn BOOLEAN
40 * newSuperior [0] DistinguishedName [v3 only]
48 #include <ac/socket.h>
49 #include <ac/string.h>
55 * ldap_rename - initiate an ldap extended modifyDN operation.
59 * dn DN of the object to modify
60 * newrdn RDN to give the object
61 * deleteoldrdn nonzero means to delete old rdn values from the entry
62 * newSuperior DN of the new parent if applicable
64 * Returns the LDAP error code.
71 LDAP_CONST char *newrdn,
72 LDAP_CONST char *newSuperior,
82 Debug( LDAP_DEBUG_TRACE, "ldap_rename\n", 0, 0, 0 );
84 /* check client controls */
85 rc = ldap_int_client_controls( ld, cctrls );
86 if( rc != LDAP_SUCCESS ) return rc;
88 /* create a message to send */
89 if ( (ber = ldap_alloc_ber_with_options( ld )) == NULL ) {
90 return( LDAP_NO_MEMORY );
93 LDAP_NEXT_MSGID( ld, id );
94 if( newSuperior != NULL ) {
95 /* must be version 3 (or greater) */
96 if ( ld->ld_version < LDAP_VERSION3 ) {
97 ld->ld_errno = LDAP_NOT_SUPPORTED;
99 return( ld->ld_errno );
101 rc = ber_printf( ber, "{it{ssbtsN}", /* '}' */
103 dn, newrdn, (ber_int_t) deleteoldrdn,
104 LDAP_TAG_NEWSUPERIOR, newSuperior );
107 rc = ber_printf( ber, "{it{ssbN}", /* '}' */
109 dn, newrdn, (ber_int_t) deleteoldrdn );
113 ld->ld_errno = LDAP_ENCODING_ERROR;
115 return( ld->ld_errno );
118 /* Put Server Controls */
119 if( ldap_int_put_controls( ld, sctrls, ber ) != LDAP_SUCCESS ) {
124 rc = ber_printf( ber, /*{*/ "N}" );
126 ld->ld_errno = LDAP_ENCODING_ERROR;
128 return( ld->ld_errno );
131 /* send the message */
132 *msgidp = ldap_send_initial_request( ld, LDAP_REQ_MODRDN, dn, ber, id );
135 return( ld->ld_errno );
143 * ldap_rename2 - initiate an ldap (and X.500) modifyDN operation. Parameters:
144 * (LDAP V3 MODIFYDN REQUEST)
146 * dn DN of the object to modify
147 * newrdn RDN to give the object
148 * deleteoldrdn nonzero means to delete old rdn values from the entry
149 * newSuperior DN of the new parent if applicable
151 * ldap_rename2 uses a U-Mich Style API. It returns the msgid.
158 LDAP_CONST char *newrdn,
159 LDAP_CONST char *newSuperior,
165 Debug( LDAP_DEBUG_TRACE, "ldap_rename2\n", 0, 0, 0 );
167 rc = ldap_rename( ld, dn, newrdn, newSuperior,
168 deleteoldrdn, NULL, NULL, &msgid );
170 return rc == LDAP_SUCCESS ? msgid : -1;
175 * ldap_modrdn2 - initiate an ldap modifyRDN operation. Parameters:
178 * dn DN of the object to modify
179 * newrdn RDN to give the object
180 * deleteoldrdn nonzero means to delete old rdn values from the entry
183 * msgid = ldap_modrdn( ld, dn, newrdn );
186 ldap_modrdn2( LDAP *ld,
188 LDAP_CONST char *newrdn,
191 return ldap_rename2( ld, dn, newrdn, NULL, deleteoldrdn );
195 ldap_modrdn( LDAP *ld, LDAP_CONST char *dn, LDAP_CONST char *newrdn )
197 return( ldap_rename2( ld, dn, newrdn, NULL, 1 ) );
205 LDAP_CONST char *newrdn,
206 LDAP_CONST char *newSuperior,
208 LDAPControl **sctrls,
209 LDAPControl **cctrls )
215 rc = ldap_rename( ld, dn, newrdn, newSuperior,
216 deleteoldrdn, sctrls, cctrls, &msgid );
218 if( rc != LDAP_SUCCESS ) {
222 rc = ldap_result( ld, msgid, LDAP_MSG_ALL, NULL, &res );
228 return ldap_result2error( ld, res, 1 );
235 LDAP_CONST char *newrdn,
236 LDAP_CONST char *newSuperior,
239 return ldap_rename_s( ld, dn, newrdn, newSuperior,
240 deleteoldrdn, NULL, NULL );
244 ldap_modrdn2_s( LDAP *ld, LDAP_CONST char *dn, LDAP_CONST char *newrdn, int deleteoldrdn )
246 return ldap_rename_s( ld, dn, newrdn, NULL, deleteoldrdn, NULL, NULL );
250 ldap_modrdn_s( LDAP *ld, LDAP_CONST char *dn, LDAP_CONST char *newrdn )
252 return ldap_rename_s( ld, dn, newrdn, NULL, 1, NULL, NULL );