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