]> git.sur5r.net Git - openldap/blobdiff - libraries/libldap/modrdn.c
Merge remote branch 'origin/mdb.master' into OPENLDAP_REL_ENG_2_4
[openldap] / libraries / libldap / modrdn.c
index 29108a3f38d12ae98343a644aec956d95fe09f53..23b251a568273c8852f6620143832aa722c4dcdf 100644 (file)
@@ -1,18 +1,21 @@
 /* $OpenLDAP$ */
-/*
- * Copyright 1998-2000 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.
+/* This work is part of OpenLDAP Software <http://www.openldap.org/>.
  *
- *  modrdn.c
- */
-/*
- * Support for MODIFYDN REQUEST V3 (newSuperior) by:
+ * Copyright 1998-2012 The OpenLDAP Foundation.
+ * All rights reserved.
  *
- * Copyright 1999, Juan C. Gomez, 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.
+ *
+ * A copy of this license is available in the file LICENSE in the
+ * top-level directory of the distribution or, alternatively, at
+ * <http://www.OpenLDAP.org/license.html>.
+ */
+/* 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.
  *
  * 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"
 
 #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.
  *
@@ -67,14 +75,20 @@ ldap_rename(
 {
        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 )) == 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 ) {
@@ -82,15 +96,14 @@ ldap_rename(
                        ber_free( ber, 1 );
                        return( ld->ld_errno );
                }
-
-               rc = ber_printf( ber, "{it{ssbts}", /* '}' */ 
-                       ++ld->ld_msgid, LDAP_REQ_MODDN,
+               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}", /* '}' */ 
-                       ++ld->ld_msgid, LDAP_REQ_MODDN,
+               rc = ber_printf( ber, "{it{ssbN}", /* '}' */ 
+                       id, LDAP_REQ_MODDN,
                        dn, newrdn, (ber_int_t) deleteoldrdn );
        }
 
@@ -106,7 +119,7 @@ ldap_rename(
                return ld->ld_errno;
        }
 
-       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 );
@@ -204,9 +217,9 @@ ldap_rename_s(
                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;
        }