1N/A#pragma ident "%Z%%M% %I% %E% SMI"
1N/A
1N/A/*
1N/A * The contents of this file are subject to the Netscape Public
1N/A * License Version 1.1 (the "License"); you may not use this file
1N/A * except in compliance with the License. You may obtain a copy of
1N/A * the License at http://www.mozilla.org/NPL/
1N/A *
1N/A * Software distributed under the License is distributed on an "AS
1N/A * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
1N/A * implied. See the License for the specific language governing
1N/A * rights and limitations under the License.
1N/A *
1N/A * The Original Code is Mozilla Communicator client code, released
1N/A * March 31, 1998.
1N/A *
1N/A * The Initial Developer of the Original Code is Netscape
1N/A * Communications Corporation. Portions created by Netscape are
1N/A * Copyright (C) 1998-1999 Netscape Communications Corporation. All
1N/A * Rights Reserved.
1N/A *
1N/A * Contributor(s):
1N/A */
1N/A/*
1N/A * Copyright (c) 1990 Regents of the University of Michigan.
1N/A * All rights reserved.
1N/A */
1N/A/*
1N/A * rename.c
1N/A */
1N/A
1N/A#if 0
1N/A#ifndef lint
1N/Astatic char copyright[] = "@(#) Copyright (c) 1990 Regents of the University of Michigan.\nAll rights reserved.\n";
1N/A#endif
1N/A#endif
1N/A
1N/A#include "ldap-int.h"
1N/A
1N/A/*
1N/A * ldap_rename - initiate an ldap modifyDN operation. Parameters:
1N/A *
1N/A * ld LDAP descriptor
1N/A * dn DN of the object to modify
1N/A * newrdn RDN that will form leftmost component of entry's new name
1N/A * newparent if present, this is the Distinguished Name of the entry
1N/A * which becomes the immediate parent of the existing entry
1N/A * deleteoldrdn nonzero means to delete old rdn values from the entry
1N/A * while zero means to retain them as attributes of the entry
1N/A * serverctrls list of LDAP server controls
1N/A * clientctrls list of client controls
1N/A * msgidp this result parameter will be set to the message id of the
1N/A * request if the ldap_rename() call succeeds
1N/A *
1N/A * Example:
1N/A * int rc;
1N/A * rc = ldap_rename( ld, dn, newrdn, newparent, deleteoldrdn, serverctrls, clientctrls, &msgid );
1N/A */
1N/Aint
1N/ALDAP_CALL
1N/Aldap_rename(
1N/A LDAP *ld,
1N/A const char *dn,
1N/A const char *newrdn,
1N/A const char *newparent,
1N/A int deleteoldrdn,
1N/A LDAPControl **serverctrls,
1N/A LDAPControl **clientctrls, /* not used for anything yet */
1N/A int *msgidp
1N/A)
1N/A{
1N/A BerElement *ber;
1N/A int rc, err;
1N/A
1N/A /*
1N/A * A modify dn request looks like this:
1N/A * ModifyDNRequest ::= SEQUENCE {
1N/A * entry LDAPDN,
1N/A * newrdn RelativeLDAPDN,
1N/A * newparent [0] LDAPDN OPTIONAL,
1N/A * deleteoldrdn BOOLEAN
1N/A * }
1N/A */
1N/A
1N/A LDAPDebug( LDAP_DEBUG_TRACE, "ldap_rename\n", 0, 0, 0 );
1N/A
1N/A if ( !NSLDAPI_VALID_LDAP_POINTER( ld )) {
1N/A return( LDAP_PARAM_ERROR );
1N/A }
1N/A if ( NULL == newrdn) {
1N/A LDAP_SET_LDERRNO( ld, LDAP_PARAM_ERROR, NULL, NULL );
1N/A return( LDAP_PARAM_ERROR );
1N/A }
1N/A
1N/A /* only ldapv3 or higher can do a proper rename
1N/A * (i.e. with non-NULL newparent and/or controls)
1N/A */
1N/A
1N/A if (( NSLDAPI_LDAP_VERSION( ld ) < LDAP_VERSION3 )
1N/A && ((newparent != NULL) || (serverctrls != NULL)
1N/A || (clientctrls != NULL))) {
1N/A LDAP_SET_LDERRNO( ld, LDAP_NOT_SUPPORTED, NULL, NULL );
1N/A return( LDAP_NOT_SUPPORTED );
1N/A }
1N/A
1N/A if ( msgidp == NULL ) {
1N/A LDAP_SET_LDERRNO( ld, LDAP_PARAM_ERROR, NULL, NULL );
1N/A return( LDAP_PARAM_ERROR );
1N/A }
1N/A
1N/A LDAP_MUTEX_LOCK( ld, LDAP_MSGID_LOCK );
1N/A *msgidp = ++ld->ld_msgid;
1N/A LDAP_MUTEX_UNLOCK( ld, LDAP_MSGID_LOCK );
1N/A
1N/A /* see if modRDN or modDN is handled by the cache */
1N/A if ( ld->ld_cache_on ) {
1N/A if ( newparent == NULL && ld->ld_cache_modrdn != NULL ) {
1N/A LDAP_MUTEX_LOCK( ld, LDAP_CACHE_LOCK );
1N/A if ( (rc = (ld->ld_cache_modrdn)( ld, *msgidp,
1N/A LDAP_REQ_MODRDN, dn, newrdn, deleteoldrdn ))
1N/A != 0 ) {
1N/A *msgidp = rc;
1N/A LDAP_MUTEX_UNLOCK( ld, LDAP_CACHE_LOCK );
1N/A return( LDAP_SUCCESS );
1N/A }
1N/A LDAP_MUTEX_UNLOCK( ld, LDAP_CACHE_LOCK );
1N/A#if 0
1N/A } else if ( ld->ld_cache_rename != NULL ) {
1N/A LDAP_MUTEX_LOCK( ld, LDAP_CACHE_LOCK );
1N/A if ( (rc = (ld->ld_cache_rename)( ld, *msgidp,
1N/A LDAP_REQ_MODDN, dn, newrdn, newparent,
1N/A deleteoldrdn )) != 0 ) {
1N/A *msgidp = rc;
1N/A return( LDAP_SUCCESS );
1N/A }
1N/A LDAP_MUTEX_UNLOCK( ld, LDAP_CACHE_LOCK );
1N/A#endif
1N/A }
1N/A }
1N/A
1N/A /* create a message to send */
1N/A if (( err = nsldapi_alloc_ber_with_options( ld, &ber ))
1N/A != LDAP_SUCCESS ) {
1N/A return( err );
1N/A }
1N/A
1N/A /* fill it in */
1N/A if ( ber_printf( ber, "{it{ssb", *msgidp, LDAP_REQ_MODDN, dn,
1N/A newrdn, deleteoldrdn ) == -1 ) {
1N/A LDAP_SET_LDERRNO( ld, LDAP_ENCODING_ERROR, NULL, NULL );
1N/A ber_free( ber, 1 );
1N/A return( LDAP_ENCODING_ERROR );
1N/A }
1N/A
1N/A if ( newparent == NULL ) {
1N/A if ( ber_printf( ber, "}" ) == -1 ) {
1N/A LDAP_SET_LDERRNO( ld, LDAP_ENCODING_ERROR, NULL, NULL );
1N/A ber_free( ber, 1 );
1N/A return( LDAP_ENCODING_ERROR );
1N/A }
1N/A } else {
1N/A if ( ber_printf( ber, "ts}", LDAP_TAG_NEWSUPERIOR, newparent )
1N/A == -1 ) {
1N/A LDAP_SET_LDERRNO( ld, LDAP_ENCODING_ERROR, NULL, NULL );
1N/A ber_free( ber, 1 );
1N/A return( LDAP_ENCODING_ERROR );
1N/A }
1N/A }
1N/A
1N/A if (( rc = nsldapi_put_controls( ld, serverctrls, 1, ber ))
1N/A != LDAP_SUCCESS ) {
1N/A ber_free( ber, 1 );
1N/A return( rc );
1N/A }
1N/A
1N/A /* send the message */
1N/A rc = nsldapi_send_initial_request( ld, *msgidp, LDAP_REQ_MODDN,
1N/A (char *) dn, ber );
1N/A *msgidp = rc;
1N/A return( rc < 0 ? LDAP_GET_LDERRNO( ld, NULL, NULL ) : LDAP_SUCCESS );
1N/A}
1N/A
1N/Aint
1N/ALDAP_CALL
1N/Aldap_modrdn2( LDAP *ld, const char *dn, const char *newrdn, int deleteoldrdn )
1N/A{
1N/A int msgid;
1N/A
1N/A if ( ldap_rename( ld, dn, newrdn, NULL, deleteoldrdn, NULL, NULL, &msgid ) == LDAP_SUCCESS ) {
1N/A return( msgid );
1N/A } else {
1N/A return( -1 ); /* error is in ld handle */
1N/A }
1N/A}
1N/A
1N/Aint
1N/ALDAP_CALL
1N/Aldap_modrdn( LDAP *ld, const char *dn, const char *newrdn )
1N/A{
1N/A return( ldap_modrdn2( ld, dn, newrdn, 1 ) );
1N/A}
1N/A
1N/Aint
1N/ALDAP_CALL
1N/Aldap_rename_s(
1N/A LDAP *ld,
1N/A const char *dn,
1N/A const char *newrdn,
1N/A const char *newparent,
1N/A int deleteoldrdn,
1N/A LDAPControl **serverctrls,
1N/A LDAPControl **clientctrls /* not used for anything yet */
1N/A)
1N/A{
1N/A int msgid;
1N/A LDAPMessage *res;
1N/A
1N/A if ( ldap_rename( ld, dn, newrdn, newparent, deleteoldrdn, serverctrls, clientctrls, &msgid ) != LDAP_SUCCESS ) {
1N/A return( LDAP_GET_LDERRNO( ld, NULL, NULL ) );
1N/A }
1N/A
1N/A if ( msgid == -1 )
1N/A return( LDAP_GET_LDERRNO( ld, NULL, NULL ) );
1N/A
1N/A if ( ldap_result( ld, msgid, 1, (struct timeval *) NULL, &res ) == -1 )
1N/A return( LDAP_GET_LDERRNO( ld, NULL, NULL ) );
1N/A
1N/A return( ldap_result2error( ld, res, 1 ) );
1N/A}
1N/A
1N/Aint
1N/ALDAP_CALL
1N/Aldap_modrdn2_s( LDAP *ld, const char *dn, const char *newrdn, int deleteoldrdn )
1N/A{
1N/A int msgid;
1N/A LDAPMessage *res;
1N/A
1N/A if ( (msgid = ldap_modrdn2( ld, dn, newrdn, deleteoldrdn )) == -1 )
1N/A return( LDAP_GET_LDERRNO( ld, NULL, NULL ) );
1N/A
1N/A if ( ldap_result( ld, msgid, 1, (struct timeval *) NULL, &res ) == -1 )
1N/A return( LDAP_GET_LDERRNO( ld, NULL, NULL ) );
1N/A
1N/A return( ldap_result2error( ld, res, 1 ) );
1N/A}
1N/A
1N/Aint
1N/ALDAP_CALL
1N/Aldap_modrdn_s( LDAP *ld, const char *dn, const char *newrdn )
1N/A{
1N/A return( ldap_modrdn2_s( ld, dn, newrdn, 1 ) );
1N/A}