1 #pragma ident "%Z%%M% %I% %E% SMI"
4 * The contents of this file are subject to the Netscape Public
5 * License Version 1.1 (the "License"); you may not use this file
6 * except in compliance with the License. You may obtain a copy of
7 * the License at http://www.mozilla.org/NPL/
9 * Software distributed under the License is distributed on an "AS
10 * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
11 * implied. See the License for the specific language governing
12 * rights and limitations under the License.
14 * The Original Code is Mozilla Communicator client code, released
17 * The Initial Developer of the Original Code is Netscape
18 * Communications Corporation. Portions created by Netscape are
19 * Copyright (C) 1998-1999 Netscape Communications Corporation. All
25 * Copyright (c) 1990 Regents of the University of Michigan.
26 * All rights reserved.
34 static char copyright
[] = "@(#) Copyright (c) 1990 Regents of the University of Michigan.\nAll rights reserved.\n";
41 * ldap_rename - initiate an ldap modifyDN operation. Parameters:
44 * dn DN of the object to modify
45 * newrdn RDN that will form leftmost component of entry's new name
46 * newparent if present, this is the Distinguished Name of the entry
47 * which becomes the immediate parent of the existing entry
48 * deleteoldrdn nonzero means to delete old rdn values from the entry
49 * while zero means to retain them as attributes of the entry
50 * serverctrls list of LDAP server controls
51 * clientctrls list of client controls
52 * msgidp this result parameter will be set to the message id of the
53 * request if the ldap_rename() call succeeds
57 * rc = ldap_rename( ld, dn, newrdn, newparent, deleteoldrdn, serverctrls, clientctrls, &msgid );
65 const char *newparent
,
67 LDAPControl
**serverctrls
,
68 LDAPControl
**clientctrls
, /* not used for anything yet */
76 * A modify dn request looks like this:
77 * ModifyDNRequest ::= SEQUENCE {
79 * newrdn RelativeLDAPDN,
80 * newparent [0] LDAPDN OPTIONAL,
81 * deleteoldrdn BOOLEAN
85 LDAPDebug( LDAP_DEBUG_TRACE
, "ldap_rename\n", 0, 0, 0 );
87 if ( !NSLDAPI_VALID_LDAP_POINTER( ld
)) {
88 return( LDAP_PARAM_ERROR
);
90 if ( NULL
== newrdn
) {
91 LDAP_SET_LDERRNO( ld
, LDAP_PARAM_ERROR
, NULL
, NULL
);
92 return( LDAP_PARAM_ERROR
);
95 /* only ldapv3 or higher can do a proper rename
96 * (i.e. with non-NULL newparent and/or controls)
99 if (( NSLDAPI_LDAP_VERSION( ld
) < LDAP_VERSION3
)
100 && ((newparent
!= NULL
) || (serverctrls
!= NULL
)
101 || (clientctrls
!= NULL
))) {
102 LDAP_SET_LDERRNO( ld
, LDAP_NOT_SUPPORTED
, NULL
, NULL
);
103 return( LDAP_NOT_SUPPORTED
);
106 if ( msgidp
== NULL
) {
107 LDAP_SET_LDERRNO( ld
, LDAP_PARAM_ERROR
, NULL
, NULL
);
108 return( LDAP_PARAM_ERROR
);
111 LDAP_MUTEX_LOCK( ld
, LDAP_MSGID_LOCK
);
112 *msgidp
= ++ld
->ld_msgid
;
113 LDAP_MUTEX_UNLOCK( ld
, LDAP_MSGID_LOCK
);
115 /* see if modRDN or modDN is handled by the cache */
116 if ( ld
->ld_cache_on
) {
117 if ( newparent
== NULL
&& ld
->ld_cache_modrdn
!= NULL
) {
118 LDAP_MUTEX_LOCK( ld
, LDAP_CACHE_LOCK
);
119 if ( (rc
= (ld
->ld_cache_modrdn
)( ld
, *msgidp
,
120 LDAP_REQ_MODRDN
, dn
, newrdn
, deleteoldrdn
))
123 LDAP_MUTEX_UNLOCK( ld
, LDAP_CACHE_LOCK
);
124 return( LDAP_SUCCESS
);
126 LDAP_MUTEX_UNLOCK( ld
, LDAP_CACHE_LOCK
);
128 } else if ( ld
->ld_cache_rename
!= NULL
) {
129 LDAP_MUTEX_LOCK( ld
, LDAP_CACHE_LOCK
);
130 if ( (rc
= (ld
->ld_cache_rename
)( ld
, *msgidp
,
131 LDAP_REQ_MODDN
, dn
, newrdn
, newparent
,
132 deleteoldrdn
)) != 0 ) {
134 return( LDAP_SUCCESS
);
136 LDAP_MUTEX_UNLOCK( ld
, LDAP_CACHE_LOCK
);
141 /* create a message to send */
142 if (( err
= nsldapi_alloc_ber_with_options( ld
, &ber
))
148 if ( ber_printf( ber
, "{it{ssb", *msgidp
, LDAP_REQ_MODDN
, dn
,
149 newrdn
, deleteoldrdn
) == -1 ) {
150 LDAP_SET_LDERRNO( ld
, LDAP_ENCODING_ERROR
, NULL
, NULL
);
152 return( LDAP_ENCODING_ERROR
);
155 if ( newparent
== NULL
) {
156 if ( ber_printf( ber
, "}" ) == -1 ) {
157 LDAP_SET_LDERRNO( ld
, LDAP_ENCODING_ERROR
, NULL
, NULL
);
159 return( LDAP_ENCODING_ERROR
);
162 if ( ber_printf( ber
, "ts}", LDAP_TAG_NEWSUPERIOR
, newparent
)
164 LDAP_SET_LDERRNO( ld
, LDAP_ENCODING_ERROR
, NULL
, NULL
);
166 return( LDAP_ENCODING_ERROR
);
170 if (( rc
= nsldapi_put_controls( ld
, serverctrls
, 1, ber
))
176 /* send the message */
177 rc
= nsldapi_send_initial_request( ld
, *msgidp
, LDAP_REQ_MODDN
,
180 return( rc
< 0 ? LDAP_GET_LDERRNO( ld
, NULL
, NULL
) : LDAP_SUCCESS
);
185 ldap_modrdn2( LDAP
*ld
, const char *dn
, const char *newrdn
, int deleteoldrdn
)
189 if ( ldap_rename( ld
, dn
, newrdn
, NULL
, deleteoldrdn
, NULL
, NULL
, &msgid
) == LDAP_SUCCESS
) {
192 return( -1 ); /* error is in ld handle */
198 ldap_modrdn( LDAP
*ld
, const char *dn
, const char *newrdn
)
200 return( ldap_modrdn2( ld
, dn
, newrdn
, 1 ) );
209 const char *newparent
,
211 LDAPControl
**serverctrls
,
212 LDAPControl
**clientctrls
/* not used for anything yet */
218 if ( ldap_rename( ld
, dn
, newrdn
, newparent
, deleteoldrdn
, serverctrls
, clientctrls
, &msgid
) != LDAP_SUCCESS
) {
219 return( LDAP_GET_LDERRNO( ld
, NULL
, NULL
) );
223 return( LDAP_GET_LDERRNO( ld
, NULL
, NULL
) );
225 if ( ldap_result( ld
, msgid
, 1, (struct timeval
*) NULL
, &res
) == -1 )
226 return( LDAP_GET_LDERRNO( ld
, NULL
, NULL
) );
228 return( ldap_result2error( ld
, res
, 1 ) );
233 ldap_modrdn2_s( LDAP
*ld
, const char *dn
, const char *newrdn
, int deleteoldrdn
)
238 if ( (msgid
= ldap_modrdn2( ld
, dn
, newrdn
, deleteoldrdn
)) == -1 )
239 return( LDAP_GET_LDERRNO( ld
, NULL
, NULL
) );
241 if ( ldap_result( ld
, msgid
, 1, (struct timeval
*) NULL
, &res
) == -1 )
242 return( LDAP_GET_LDERRNO( ld
, NULL
, NULL
) );
244 return( ldap_result2error( ld
, res
, 1 ) );
249 ldap_modrdn_s( LDAP
*ld
, const char *dn
, const char *newrdn
)
251 return( ldap_modrdn2_s( ld
, dn
, newrdn
, 1 ) );