]> git.sur5r.net Git - openldap/blob - libraries/libldap/modrdn.c
More files that didn't get merged properly.
[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 #include <ac/time.h>
19
20 #include "lber.h"
21 #include "ldap.h"
22 #include "ldap-int.h"
23
24 /*
25  * ldap_modrdn2 - initiate an ldap (and X.500) modifyRDN operation. Parameters:
26  *
27  *      ld              LDAP descriptor
28  *      dn              DN of the object to modify
29  *      newrdn          RDN to give the object
30  *      deleteoldrdn    nonzero means to delete old rdn values from the entry
31  *
32  * Example:
33  *      msgid = ldap_modrdn( ld, dn, newrdn );
34  */
35 int
36 ldap_modrdn2( LDAP *ld, char *dn, char *newrdn, int deleteoldrdn )
37 {
38         BerElement      *ber;
39
40         /*
41          * A modify rdn request looks like this:
42          *      ModifyRDNRequest ::= SEQUENCE {
43          *              entry           DistinguishedName,
44          *              newrdn          RelativeDistinguishedName,
45          *              deleteoldrdn    BOOLEAN
46          *      }
47          */
48
49         Debug( LDAP_DEBUG_TRACE, "ldap_modrdn\n", 0, 0, 0 );
50
51         /* create a message to send */
52         if ( (ber = ldap_alloc_ber_with_options( ld )) == NULLBER ) {
53                 return( -1 );
54         }
55
56         if ( ber_printf( ber, "{it{ssb}}", ++ld->ld_msgid, LDAP_REQ_MODRDN, dn,
57             newrdn, deleteoldrdn ) == -1 ) {
58                 ld->ld_errno = LDAP_ENCODING_ERROR;
59                 ber_free( ber, 1 );
60                 return( -1 );
61         }
62
63         /* send the message */
64         return ( ldap_send_initial_request( ld, LDAP_REQ_MODRDN, dn, ber ));
65 }
66
67 int
68 ldap_modrdn( LDAP *ld, char *dn, char *newrdn )
69 {
70         return( ldap_modrdn2( ld, dn, newrdn, 1 ) );
71 }
72
73 int
74 ldap_modrdn2_s( LDAP *ld, char *dn, char *newrdn, int deleteoldrdn )
75 {
76         int             msgid;
77         LDAPMessage     *res;
78
79         if ( (msgid = ldap_modrdn2( ld, dn, newrdn, deleteoldrdn )) == -1 )
80                 return( ld->ld_errno );
81
82         if ( ldap_result( ld, msgid, 1, (struct timeval *) NULL, &res ) == -1 )
83                 return( ld->ld_errno );
84
85         return( ldap_result2error( ld, res, 1 ) );
86 }
87
88 int
89 ldap_modrdn_s( LDAP *ld, char *dn, char *newrdn )
90 {
91         return( ldap_modrdn2_s( ld, dn, newrdn, 1 ) );
92 }