]> git.sur5r.net Git - openldap/blob - libraries/libldap/modrdn.c
Remove superfluous \ at end of lines outside macros; DEC cc doesn't like them.
[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 /*
13  * Support for MODIFYDN REQUEST V3 (newSuperior) by:
14  *
15  * Copyright 1999, Juan C. Gomez, All rights reserved.
16  * This software is not subject to any license of Silicon Graphics 
17  * Inc. or Purdue University.
18  *
19  * Redistribution and use in source and binary forms are permitted
20  * without restriction or fee of any kind as long as this notice
21  * is preserved.
22  *
23  */
24
25 #include "portable.h"
26
27 #include <stdio.h>
28
29 #include <ac/socket.h>
30 #include <ac/string.h>
31 #include <ac/time.h>
32
33 #include "ldap-int.h"
34
35 /*
36  * ldap_rename2 - initiate an ldap (and X.500) modifyDN operation. Parameters:
37  *      (LDAP V3 MODIFYDN REQUEST)
38  *      ld              LDAP descriptor
39  *      dn              DN of the object to modify
40  *      newrdn          RDN to give the object
41  *      deleteoldrdn    nonzero means to delete old rdn values from the entry
42  *      newSuperior     DN of the new parent if applicable
43  */
44
45 int
46 ldap_rename2( LDAP *ld,
47               char *dn,
48               char *newrdn,
49               int deleteoldrdn,
50               char *newSuperior )
51 {
52         /*
53          * A modify rdn request looks like this:
54          *      ModifyRDNRequest ::= SEQUENCE {
55          *              entry           DistinguishedName,
56          *              newrdn          RelativeDistinguishedName,
57          *              deleteoldrdn    BOOLEAN
58          *              newSuperior     [0] DistinguishedName   [v3 only]
59          *      }
60          */
61
62         Debug( LDAP_DEBUG_TRACE, "ldap_rename2\n", 0, 0, 0 );
63
64         if( newSuperior != NULL ) {
65             BerElement  *ber;
66
67             /* create a message to send */
68             if ( (ber = ldap_alloc_ber_with_options( ld )) == NULLBER ) {
69                 return( -1 );
70             }
71
72             if ( ber_printf( ber, "{it{ssbts}}",
73                              ++ld->ld_msgid,
74                              LDAP_REQ_MODRDN,
75                              dn,
76                              newrdn,
77                              deleteoldrdn,
78                              LDAP_TAG_NEWSUPERIOR,
79                              newSuperior )
80                  == -1 ) {
81
82                 ld->ld_errno = LDAP_ENCODING_ERROR;
83                 ber_free( ber, 1 );
84                 return( -1 );
85
86             }
87
88             /* send the message */
89             return ldap_send_initial_request( ld, LDAP_REQ_MODRDN, dn, ber );
90             
91         } else {
92
93             /* If no newSuperior fall through to ldap_modrdn2() */
94
95             return ldap_modrdn2( ld, dn, newrdn, deleteoldrdn );
96
97         }
98
99 }/* int ldap_rename2() */
100
101
102 /*
103  * ldap_modrdn2 - initiate an ldap (and X.500) modifyRDN operation. Parameters:
104  *
105  *      ld              LDAP descriptor
106  *      dn              DN of the object to modify
107  *      newrdn          RDN to give the object
108  *      deleteoldrdn    nonzero means to delete old rdn values from the entry
109  *
110  * Example:
111  *      msgid = ldap_modrdn( ld, dn, newrdn );
112  */
113 int
114 ldap_modrdn2( LDAP *ld, char *dn, char *newrdn, int deleteoldrdn )
115 {
116         BerElement      *ber;
117
118         /*
119          * A modify rdn request looks like this:
120          *      ModifyRDNRequest ::= SEQUENCE {
121          *              entry           DistinguishedName,
122          *              newrdn          RelativeDistinguishedName,
123          *              deleteoldrdn    BOOLEAN
124          *      }
125          */
126
127         Debug( LDAP_DEBUG_TRACE, "ldap_modrdn\n", 0, 0, 0 );
128
129         /* create a message to send */
130         if ( (ber = ldap_alloc_ber_with_options( ld )) == NULLBER ) {
131                 return( -1 );
132         }
133
134         if ( ber_printf( ber, "{it{ssb}}", ++ld->ld_msgid, LDAP_REQ_MODRDN, dn,
135             newrdn, deleteoldrdn ) == -1 ) {
136                 ld->ld_errno = LDAP_ENCODING_ERROR;
137                 ber_free( ber, 1 );
138                 return( -1 );
139         }
140
141         /* send the message */
142         return ( ldap_send_initial_request( ld, LDAP_REQ_MODRDN, dn, ber ));
143 }
144
145 int
146 ldap_modrdn( LDAP *ld, char *dn, char *newrdn )
147 {
148         return( ldap_modrdn2( ld, dn, newrdn, 1 ) );
149 }
150
151 int
152 ldap_rename2_s( LDAP *ld, char *dn, char *newrdn, int deleteoldrdn,
153                 char *newSuperior )
154 {
155         int             msgid;
156         LDAPMessage     *res;
157
158
159         if ( (msgid = ldap_rename2( ld,
160                                     dn,
161                                     newrdn,
162                                     deleteoldrdn,
163                                     newSuperior ))
164              == -1 )
165                 return( ld->ld_errno );
166
167         if ( ldap_result( ld, msgid, 1, (struct timeval *) NULL, &res )
168              == -1 )
169                 return( ld->ld_errno );
170
171         return( ldap_result2error( ld, res, 1 ) );
172
173 }
174
175 int
176 ldap_modrdn2_s( LDAP *ld, char *dn, char *newrdn, int deleteoldrdn )
177 {
178         int             msgid;
179         LDAPMessage     *res;
180
181         if ( (msgid = ldap_modrdn2( ld, dn, newrdn, deleteoldrdn )) == -1 )
182                 return( ld->ld_errno );
183
184         if ( ldap_result( ld, msgid, 1, (struct timeval *) NULL, &res ) == -1 )
185                 return( ld->ld_errno );
186
187         return( ldap_result2error( ld, res, 1 ) );
188 }
189
190 int
191 ldap_modrdn_s( LDAP *ld, char *dn, char *newrdn )
192 {
193         return( ldap_modrdn2_s( ld, dn, newrdn, 1 ) );
194 }
195