2 * Copyright 1998-1999 The OpenLDAP Foundation, All Rights Reserved.
3 * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
6 * Copyright (c) 1990 Regents of the University of Michigan.
13 * Support for MODIFYDN REQUEST V3 (newSuperior) by:
15 * Copyright 1999, Juan C. Gomez, All rights reserved.
16 * This software is not subject to any license of Silicon Graphics
17 * Inc. or Purdue University.
19 * Redistribution and use in source and binary forms are permitted
20 * without restriction or fee of any kind as long as this notice
29 #include <ac/socket.h>
30 #include <ac/string.h>
36 * ldap_rename2 - initiate an ldap (and X.500) modifyDN operation. Parameters:
37 * (LDAP V3 MODIFYDN REQUEST)
39 * dn DN of the object to modify
40 * newrdn RDN to give the object
41 * deleteoldrdn nonzero means to delete old rdn values from the entry
42 * newSuperior DN of the new parent if applicable
46 ldap_rename2( LDAP *ld,
53 * A modify rdn request looks like this:
54 * ModifyRDNRequest ::= SEQUENCE {
55 * entry DistinguishedName,
56 * newrdn RelativeDistinguishedName,
57 * deleteoldrdn BOOLEAN
58 * newSuperior [0] DistinguishedName [v3 only]
62 Debug( LDAP_DEBUG_TRACE, "ldap_rename2\n", 0, 0, 0 );
64 if( newSuperior != NULL ) {
67 /* create a message to send */
68 if ( (ber = ldap_alloc_ber_with_options( ld )) == NULLBER ) {
72 if ( ber_printf( ber, "{it{ssbts}}",
82 ld->ld_errno = LDAP_ENCODING_ERROR;
88 /* send the message */
89 return ldap_send_initial_request( ld, LDAP_REQ_MODRDN, dn, ber );
93 /* If no newSuperior fall through to ldap_modrdn2() */
95 return ldap_modrdn2( ld, dn, newrdn, deleteoldrdn );
99 }/* int ldap_rename2() */
103 * ldap_modrdn2 - initiate an ldap (and X.500) modifyRDN operation. Parameters:
106 * dn DN of the object to modify
107 * newrdn RDN to give the object
108 * deleteoldrdn nonzero means to delete old rdn values from the entry
111 * msgid = ldap_modrdn( ld, dn, newrdn );
114 ldap_modrdn2( LDAP *ld, char *dn, char *newrdn, int deleteoldrdn )
119 * A modify rdn request looks like this:
120 * ModifyRDNRequest ::= SEQUENCE {
121 * entry DistinguishedName,
122 * newrdn RelativeDistinguishedName,
123 * deleteoldrdn BOOLEAN
127 Debug( LDAP_DEBUG_TRACE, "ldap_modrdn\n", 0, 0, 0 );
129 /* create a message to send */
130 if ( (ber = ldap_alloc_ber_with_options( ld )) == NULLBER ) {
134 if ( ber_printf( ber, "{it{ssb}}", ++ld->ld_msgid, LDAP_REQ_MODRDN, dn,
135 newrdn, deleteoldrdn ) == -1 ) {
136 ld->ld_errno = LDAP_ENCODING_ERROR;
141 /* send the message */
142 return ( ldap_send_initial_request( ld, LDAP_REQ_MODRDN, dn, ber ));
146 ldap_modrdn( LDAP *ld, char *dn, char *newrdn )
148 return( ldap_modrdn2( ld, dn, newrdn, 1 ) );
152 ldap_rename2_s( LDAP *ld, char *dn, char *newrdn, int deleteoldrdn,
159 if ( (msgid = ldap_rename2( ld,
165 return( ld->ld_errno );
167 if ( ldap_result( ld, msgid, 1, (struct timeval *) NULL, &res )
169 return( ld->ld_errno );
171 return( ldap_result2error( ld, res, 1 ) );
176 ldap_modrdn2_s( LDAP *ld, char *dn, char *newrdn, int deleteoldrdn )
181 if ( (msgid = ldap_modrdn2( ld, dn, newrdn, deleteoldrdn )) == -1 )
182 return( ld->ld_errno );
184 if ( ldap_result( ld, msgid, 1, (struct timeval *) NULL, &res ) == -1 )
185 return( ld->ld_errno );
187 return( ldap_result2error( ld, res, 1 ) );
191 ldap_modrdn_s( LDAP *ld, char *dn, char *newrdn )
193 return( ldap_modrdn2_s( ld, dn, newrdn, 1 ) );