10Sstevel@tonic-gate /*
2*3857Sstevel * Portions Copyright 1998 Sun Microsystems, Inc. All rights reserved.
3*3857Sstevel * Use is subject to license terms.
40Sstevel@tonic-gate */
50Sstevel@tonic-gate
60Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI"
70Sstevel@tonic-gate
80Sstevel@tonic-gate /*
90Sstevel@tonic-gate * Copyright (c) 1990 Regents of the University of Michigan.
100Sstevel@tonic-gate * All rights reserved.
110Sstevel@tonic-gate *
120Sstevel@tonic-gate * modrdn.c
130Sstevel@tonic-gate */
140Sstevel@tonic-gate
150Sstevel@tonic-gate #ifndef lint
160Sstevel@tonic-gate static char copyright[] = "@(#) Copyright (c) 1990 Regents of the University of Michigan.\nAll rights reserved.\n";
170Sstevel@tonic-gate #endif
180Sstevel@tonic-gate
190Sstevel@tonic-gate #include <stdio.h>
200Sstevel@tonic-gate #include <string.h>
210Sstevel@tonic-gate
220Sstevel@tonic-gate #ifdef MACOS
230Sstevel@tonic-gate #include "macos.h"
240Sstevel@tonic-gate #endif /* MACOS */
250Sstevel@tonic-gate
260Sstevel@tonic-gate #if !defined( MACOS ) && !defined( DOS )
270Sstevel@tonic-gate #include <sys/types.h>
280Sstevel@tonic-gate #include <sys/socket.h>
290Sstevel@tonic-gate #endif
300Sstevel@tonic-gate
310Sstevel@tonic-gate #include "lber.h"
320Sstevel@tonic-gate #include "ldap.h"
330Sstevel@tonic-gate #include "ldap-private.h"
340Sstevel@tonic-gate #include "ldap-int.h"
350Sstevel@tonic-gate
360Sstevel@tonic-gate /*
370Sstevel@tonic-gate * ldap_modrdn - initiate an ldap (and X.500) modifyRDN operation. Parameters:
380Sstevel@tonic-gate *
390Sstevel@tonic-gate * ld LDAP descriptor
400Sstevel@tonic-gate * dn DN of the object to modify
410Sstevel@tonic-gate * newrdn RDN to give the object
420Sstevel@tonic-gate * deleteoldrdn nonzero means to delete old rdn values from the entry
430Sstevel@tonic-gate *
440Sstevel@tonic-gate * Example:
450Sstevel@tonic-gate * msgid = ldap_modrdn( ld, dn, newrdn );
460Sstevel@tonic-gate */
470Sstevel@tonic-gate int
ldap_modrdn(LDAP * ld,char * dn,char * newrdn,int deleteoldrdn)480Sstevel@tonic-gate ldap_modrdn( LDAP *ld, char *dn, char *newrdn, int deleteoldrdn )
490Sstevel@tonic-gate {
500Sstevel@tonic-gate BerElement *ber;
510Sstevel@tonic-gate int rv;
520Sstevel@tonic-gate
530Sstevel@tonic-gate /*
540Sstevel@tonic-gate * A modify rdn request looks like this:
550Sstevel@tonic-gate * ModifyRDNRequest ::= SEQUENCE {
560Sstevel@tonic-gate * entry DistinguishedName,
570Sstevel@tonic-gate * newrdn RelativeDistinguishedName,
580Sstevel@tonic-gate * deleteoldrdn BOOLEAN
590Sstevel@tonic-gate * }
600Sstevel@tonic-gate */
610Sstevel@tonic-gate
620Sstevel@tonic-gate #ifdef _REENTRANT
630Sstevel@tonic-gate LOCK_LDAP(ld);
640Sstevel@tonic-gate #endif
650Sstevel@tonic-gate Debug( LDAP_DEBUG_TRACE, catgets(slapdcat, 1, 193, "ldap_modrdn\n"), 0, 0, 0 );
660Sstevel@tonic-gate
670Sstevel@tonic-gate /* create a message to send */
680Sstevel@tonic-gate if ( (ber = alloc_ber_with_options( ld )) == NULLBER ) {
690Sstevel@tonic-gate #ifdef _REENTRANT
700Sstevel@tonic-gate UNLOCK_LDAP(ld);
710Sstevel@tonic-gate #endif
720Sstevel@tonic-gate return( -1 );
730Sstevel@tonic-gate }
740Sstevel@tonic-gate
750Sstevel@tonic-gate if ( ber_printf( ber, "{it{ssb}}", ++ld->ld_msgid, LDAP_REQ_MODRDN, dn,
760Sstevel@tonic-gate newrdn, deleteoldrdn ) == -1 ) {
770Sstevel@tonic-gate ld->ld_errno = LDAP_ENCODING_ERROR;
780Sstevel@tonic-gate ber_free( ber, 1 );
790Sstevel@tonic-gate #ifdef _REENTRANT
800Sstevel@tonic-gate UNLOCK_LDAP(ld);
810Sstevel@tonic-gate #endif
820Sstevel@tonic-gate return( -1 );
830Sstevel@tonic-gate }
840Sstevel@tonic-gate
850Sstevel@tonic-gate /* send the message */
860Sstevel@tonic-gate rv = send_initial_request( ld, LDAP_REQ_MODRDN, dn, ber );
870Sstevel@tonic-gate #ifdef _REENTRANT
880Sstevel@tonic-gate UNLOCK_LDAP(ld);
890Sstevel@tonic-gate #endif
900Sstevel@tonic-gate return ( rv );
910Sstevel@tonic-gate }
920Sstevel@tonic-gate
930Sstevel@tonic-gate int
ldap_modrdn0(LDAP * ld,char * dn,char * newrdn)940Sstevel@tonic-gate ldap_modrdn0( LDAP *ld, char *dn, char *newrdn )
950Sstevel@tonic-gate {
960Sstevel@tonic-gate return( ldap_modrdn( ld, dn, newrdn, 1 ) );
970Sstevel@tonic-gate }
980Sstevel@tonic-gate
990Sstevel@tonic-gate int
ldap_modrdn_s(LDAP * ld,char * dn,char * newrdn,int deleteoldrdn)1000Sstevel@tonic-gate ldap_modrdn_s( LDAP *ld, char *dn, char *newrdn, int deleteoldrdn )
1010Sstevel@tonic-gate {
1020Sstevel@tonic-gate int msgid;
1030Sstevel@tonic-gate LDAPMessage *res;
1040Sstevel@tonic-gate
1050Sstevel@tonic-gate if ( (msgid = ldap_modrdn( ld, dn, newrdn, deleteoldrdn )) == -1 )
1060Sstevel@tonic-gate return( ld->ld_errno );
1070Sstevel@tonic-gate
1080Sstevel@tonic-gate if ( ldap_result( ld, msgid, 1, (struct timeval *) NULL, &res ) == -1 )
1090Sstevel@tonic-gate return( ld->ld_errno );
1100Sstevel@tonic-gate
1110Sstevel@tonic-gate return( ldap_result2error( ld, res, 1 ) );
1120Sstevel@tonic-gate }
1130Sstevel@tonic-gate
1140Sstevel@tonic-gate int
ldap_modrdn0_s(LDAP * ld,char * dn,char * newrdn)1150Sstevel@tonic-gate ldap_modrdn0_s( LDAP *ld, char *dn, char *newrdn )
1160Sstevel@tonic-gate {
1170Sstevel@tonic-gate return( ldap_modrdn_s( ld, dn, newrdn, 1 ) );
1180Sstevel@tonic-gate }
119