X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;ds=sidebyside;f=libraries%2Flibldap%2Fmodrdn.c;h=5e4c45f9971825cf9b55ba9b61f72dc464989234;hb=b898f1271db5021e1873e38e1498a99d9450b646;hp=d2885bd63e95e3d7f3d5e79393dcff7e44f8f239;hpb=8c772985c7b7300665a30932d71d45c8af24af21;p=openldap
diff --git a/libraries/libldap/modrdn.c b/libraries/libldap/modrdn.c
index d2885bd63e..5e4c45f997 100644
--- a/libraries/libldap/modrdn.c
+++ b/libraries/libldap/modrdn.c
@@ -1,17 +1,21 @@
-/*
- * Copyright 1998-1999 The OpenLDAP Foundation, All Rights Reserved.
- * COPYING RESTRICTIONS APPLY, see COPYRIGHT file
- */
-/* Portions
- * Copyright (c) 1990 Regents of the University of Michigan.
- * All rights reserved.
+/* $OpenLDAP$ */
+/* This work is part of OpenLDAP Software .
*
- * modrdn.c
- */
-/*
- * Support for MODIFYDN REQUEST V3 (newSuperior) by:
+ * Copyright 1998-2010 The OpenLDAP Foundation.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted only as authorized by the OpenLDAP
+ * Public License.
*
- * Copyright 1999, Juan C. Gomez, All rights reserved.
+ * A copy of this license is available in the file LICENSE in the
+ * top-level directory of the distribution or, alternatively, at
+ * .
+ */
+/* Portions Copyright (c) 1990 Regents of the University of Michigan.
+ * All rights reserved.
+ */
+/* Copyright 1999, Juan C. Gomez, All rights reserved.
* This software is not subject to any license of Silicon Graphics
* Inc. or Purdue University.
*
@@ -20,14 +24,8 @@
* is preserved.
*/
-/*
- * A modify rdn request looks like this:
- * ModifyRDNRequest ::= SEQUENCE {
- * entry DistinguishedName,
- * newrdn RelativeDistinguishedName,
- * deleteoldrdn BOOLEAN
- * newSuperior [0] DistinguishedName [v3 only]
- * }
+/* ACKNOWLEDGEMENTS:
+ * Juan C. Gomez
*/
#include "portable.h"
@@ -40,6 +38,17 @@
#include "ldap-int.h"
+/*
+ * A modify rdn request looks like this:
+ * ModifyRDNRequest ::= SEQUENCE {
+ * entry DistinguishedName,
+ * newrdn RelativeDistinguishedName,
+ * deleteoldrdn BOOLEAN
+ * newSuperior [0] DistinguishedName [v3 only]
+ * }
+ */
+
+
/*
* ldap_rename - initiate an ldap extended modifyDN operation.
*
@@ -58,22 +67,28 @@ ldap_rename(
LDAP *ld,
LDAP_CONST char *dn,
LDAP_CONST char *newrdn,
- int deleteoldrdn,
LDAP_CONST char *newSuperior,
+ int deleteoldrdn,
LDAPControl **sctrls,
LDAPControl **cctrls,
int *msgidp )
{
BerElement *ber;
int rc;
+ ber_int_t id;
Debug( LDAP_DEBUG_TRACE, "ldap_rename\n", 0, 0, 0 );
+ /* check client controls */
+ rc = ldap_int_client_controls( ld, cctrls );
+ if( rc != LDAP_SUCCESS ) return rc;
+
/* create a message to send */
- if ( (ber = ldap_alloc_ber_with_options( ld )) == NULLBER ) {
+ if ( (ber = ldap_alloc_ber_with_options( ld )) == NULL ) {
return( LDAP_NO_MEMORY );
}
+ LDAP_NEXT_MSGID( ld, id );
if( newSuperior != NULL ) {
/* must be version 3 (or greater) */
if ( ld->ld_version < LDAP_VERSION3 ) {
@@ -81,16 +96,15 @@ ldap_rename(
ber_free( ber, 1 );
return( ld->ld_errno );
}
-
- rc = ber_printf( ber, "{it{ssbts}", /* leave '}' for later */
- ++ld->ld_msgid, LDAP_REQ_MODDN,
- dn, newrdn, deleteoldrdn,
+ rc = ber_printf( ber, "{it{ssbtsN}", /* '}' */
+ id, LDAP_REQ_MODDN,
+ dn, newrdn, (ber_int_t) deleteoldrdn,
LDAP_TAG_NEWSUPERIOR, newSuperior );
} else {
- rc = ber_printf( ber, "{it{ssb}", /* leave '}' for later */
- ++ld->ld_msgid, LDAP_REQ_MODDN,
- dn, newrdn, deleteoldrdn );
+ rc = ber_printf( ber, "{it{ssbN}", /* '}' */
+ id, LDAP_REQ_MODDN,
+ dn, newrdn, (ber_int_t) deleteoldrdn );
}
if ( rc < 0 ) {
@@ -105,8 +119,7 @@ ldap_rename(
return ld->ld_errno;
}
- /* close the '{' */
- rc = ber_printf( ber, "}" );
+ rc = ber_printf( ber, /*{*/ "N}" );
if ( rc < 0 ) {
ld->ld_errno = LDAP_ENCODING_ERROR;
ber_free( ber, 1 );
@@ -114,7 +127,7 @@ ldap_rename(
}
/* send the message */
- *msgidp = ldap_send_initial_request( ld, LDAP_REQ_MODRDN, dn, ber );
+ *msgidp = ldap_send_initial_request( ld, LDAP_REQ_MODRDN, dn, ber, id );
if( *msgidp < 0 ) {
return( ld->ld_errno );
@@ -141,16 +154,16 @@ ldap_rename2(
LDAP *ld,
LDAP_CONST char *dn,
LDAP_CONST char *newrdn,
- int deleteoldrdn,
- LDAP_CONST char *newSuperior )
+ LDAP_CONST char *newSuperior,
+ int deleteoldrdn )
{
int msgid;
int rc;
Debug( LDAP_DEBUG_TRACE, "ldap_rename2\n", 0, 0, 0 );
- rc = ldap_rename( ld, dn, newrdn, deleteoldrdn, newSuperior,
- NULL, NULL, &msgid );
+ rc = ldap_rename( ld, dn, newrdn, newSuperior,
+ deleteoldrdn, NULL, NULL, &msgid );
return rc == LDAP_SUCCESS ? msgid : -1;
}
@@ -173,13 +186,13 @@ ldap_modrdn2( LDAP *ld,
LDAP_CONST char *newrdn,
int deleteoldrdn )
{
- return ldap_rename2( ld, dn, newrdn, deleteoldrdn, NULL );
+ return ldap_rename2( ld, dn, newrdn, NULL, deleteoldrdn );
}
int
ldap_modrdn( LDAP *ld, LDAP_CONST char *dn, LDAP_CONST char *newrdn )
{
- return( ldap_rename2( ld, dn, newrdn, 1, NULL ) );
+ return( ldap_rename2( ld, dn, newrdn, NULL, 1 ) );
}
@@ -188,8 +201,8 @@ ldap_rename_s(
LDAP *ld,
LDAP_CONST char *dn,
LDAP_CONST char *newrdn,
- int deleteoldrdn,
LDAP_CONST char *newSuperior,
+ int deleteoldrdn,
LDAPControl **sctrls,
LDAPControl **cctrls )
{
@@ -197,16 +210,16 @@ ldap_rename_s(
int msgid;
LDAPMessage *res;
- rc = ldap_rename( ld, dn, newrdn, deleteoldrdn,
- newSuperior, sctrls, cctrls, &msgid );
+ rc = ldap_rename( ld, dn, newrdn, newSuperior,
+ deleteoldrdn, sctrls, cctrls, &msgid );
if( rc != LDAP_SUCCESS ) {
return rc;
}
- rc = ldap_result( ld, msgid, 1, NULL, &res );
+ rc = ldap_result( ld, msgid, LDAP_MSG_ALL, NULL, &res );
- if( rc == -1 ) {
+ if( rc == -1 || !res ) {
return ld->ld_errno;
}
@@ -218,21 +231,22 @@ ldap_rename2_s(
LDAP *ld,
LDAP_CONST char *dn,
LDAP_CONST char *newrdn,
- int deleteoldrdn,
- LDAP_CONST char *newSuperior )
+ LDAP_CONST char *newSuperior,
+ int deleteoldrdn )
{
- return ldap_rename_s( ld, dn, newrdn, deleteoldrdn, newSuperior, NULL, NULL );
+ return ldap_rename_s( ld, dn, newrdn, newSuperior,
+ deleteoldrdn, NULL, NULL );
}
int
ldap_modrdn2_s( LDAP *ld, LDAP_CONST char *dn, LDAP_CONST char *newrdn, int deleteoldrdn )
{
- return ldap_rename_s( ld, dn, newrdn, deleteoldrdn, NULL, NULL, NULL );
+ return ldap_rename_s( ld, dn, newrdn, NULL, deleteoldrdn, NULL, NULL );
}
int
ldap_modrdn_s( LDAP *ld, LDAP_CONST char *dn, LDAP_CONST char *newrdn )
{
- return ldap_rename_s( ld, dn, newrdn, 1, NULL, NULL, NULL );
+ return ldap_rename_s( ld, dn, newrdn, NULL, 1, NULL, NULL );
}