]> git.sur5r.net Git - openldap/blob - libraries/libldap/modrdn.c
491fc97addf7c8a8e0c39daf6ae4f8e245c0b2e7
[openldap] / libraries / libldap / modrdn.c
1 /*
2  *  Copyright (c) 1990 Regents of the University of Michigan.
3  *  All rights reserved.
4  *
5  *  modrdn.c
6  */
7
8 #include "portable.h"
9
10 #ifndef lint 
11 static char copyright[] = "@(#) Copyright (c) 1990 Regents of the University of Michigan.\nAll rights reserved.\n";
12 #endif
13
14 #include <stdio.h>
15
16 #include <ac/socket.h>
17 #include <ac/string.h>
18
19 #include "lber.h"
20 #include "ldap.h"
21 #include "ldap-int.h"
22
23 /*
24  * ldap_modrdn2 - initiate an ldap (and X.500) modifyRDN operation. Parameters:
25  *
26  *      ld              LDAP descriptor
27  *      dn              DN of the object to modify
28  *      newrdn          RDN to give the object
29  *      deleteoldrdn    nonzero means to delete old rdn values from the entry
30  *
31  * Example:
32  *      msgid = ldap_modrdn( ld, dn, newrdn );
33  */
34 int
35 ldap_modrdn2( LDAP *ld, char *dn, char *newrdn, int deleteoldrdn )
36 {
37         BerElement      *ber;
38
39         /*
40          * A modify rdn request looks like this:
41          *      ModifyRDNRequest ::= SEQUENCE {
42          *              entry           DistinguishedName,
43          *              newrdn          RelativeDistinguishedName,
44          *              deleteoldrdn    BOOLEAN
45          *      }
46          */
47
48         Debug( LDAP_DEBUG_TRACE, "ldap_modrdn\n", 0, 0, 0 );
49
50         /* create a message to send */
51         if ( (ber = ldap_alloc_ber_with_options( ld )) == NULLBER ) {
52                 return( -1 );
53         }
54
55         if ( ber_printf( ber, "{it{ssb}}", ++ld->ld_msgid, LDAP_REQ_MODRDN, dn,
56             newrdn, deleteoldrdn ) == -1 ) {
57                 ld->ld_errno = LDAP_ENCODING_ERROR;
58                 ber_free( ber, 1 );
59                 return( -1 );
60         }
61
62         /* send the message */
63         return ( ldap_send_initial_request( ld, LDAP_REQ_MODRDN, dn, ber ));
64 }
65
66 int
67 ldap_modrdn( LDAP *ld, char *dn, char *newrdn )
68 {
69         return( ldap_modrdn2( ld, dn, newrdn, 1 ) );
70 }
71
72 int
73 ldap_modrdn2_s( LDAP *ld, char *dn, char *newrdn, int deleteoldrdn )
74 {
75         int             msgid;
76         LDAPMessage     *res;
77
78         if ( (msgid = ldap_modrdn2( ld, dn, newrdn, deleteoldrdn )) == -1 )
79                 return( ld->ld_errno );
80
81         if ( ldap_result( ld, msgid, 1, (struct timeval *) NULL, &res ) == -1 )
82                 return( ld->ld_errno );
83
84         return( ldap_result2error( ld, res, 1 ) );
85 }
86
87 int
88 ldap_modrdn_s( LDAP *ld, char *dn, char *newrdn )
89 {
90         return( ldap_modrdn2_s( ld, dn, newrdn, 1 ) );
91 }