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