]> git.sur5r.net Git - openldap/blob - libraries/libldap/modrdn.c
Cast char* argument to hh_to_c() to Byte*
[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         BerElement      *ber;
53
54         /*
55          * A modify rdn request looks like this:
56          *      ModifyRDNRequest ::= SEQUENCE {
57          *              entry           DistinguishedName,
58          *              newrdn          RelativeDistinguishedName,
59          *              deleteoldrdn    BOOLEAN
60          *              newSuperior     [0] DistinguishedName   [v3 only]
61          *      }
62          */
63
64         Debug( LDAP_DEBUG_TRACE, "ldap_rename2\n", 0, 0, 0 );
65
66         /* create a message to send */
67         if ( (ber = ldap_alloc_ber_with_options( ld )) == NULLBER ) {
68                 return( -1 );
69         }
70
71         if( newSuperior != NULL ) {
72
73             if ( ber_printf( ber, "{it{ssbts}}",\
74                              ++ld->ld_msgid,\
75                              LDAP_REQ_MODRDN,\
76                              dn,\
77                              newrdn,\
78                              deleteoldrdn,\
79                              LDAP_TAG_NEWSUPERIOR,\
80                              newSuperior )\
81                  == -1 ) {
82
83                 ld->ld_errno = LDAP_ENCODING_ERROR;
84                 ber_free( ber, 1 );
85                 return( -1 );
86
87             }
88
89             /* send the message */
90             return ldap_send_initial_request( ld, LDAP_REQ_MODRDN, dn, ber );
91             
92         } else {
93
94             /* If no newSuperior fall through to ldap_modrdn2() */
95
96             return ldap_modrdn2( ld, dn, newrdn, deleteoldrdn );
97
98         }
99
100 }/* int ldap_rename2() */
101
102
103 /*
104  * ldap_modrdn2 - initiate an ldap (and X.500) modifyRDN operation. Parameters:
105  *
106  *      ld              LDAP descriptor
107  *      dn              DN of the object to modify
108  *      newrdn          RDN to give the object
109  *      deleteoldrdn    nonzero means to delete old rdn values from the entry
110  *
111  * Example:
112  *      msgid = ldap_modrdn( ld, dn, newrdn );
113  */
114 int
115 ldap_modrdn2( LDAP *ld, char *dn, char *newrdn, int deleteoldrdn )
116 {
117         BerElement      *ber;
118
119         /*
120          * A modify rdn request looks like this:
121          *      ModifyRDNRequest ::= SEQUENCE {
122          *              entry           DistinguishedName,
123          *              newrdn          RelativeDistinguishedName,
124          *              deleteoldrdn    BOOLEAN
125          *      }
126          */
127
128         Debug( LDAP_DEBUG_TRACE, "ldap_modrdn\n", 0, 0, 0 );
129
130         /* create a message to send */
131         if ( (ber = ldap_alloc_ber_with_options( ld )) == NULLBER ) {
132                 return( -1 );
133         }
134
135         if ( ber_printf( ber, "{it{ssb}}", ++ld->ld_msgid, LDAP_REQ_MODRDN, dn,
136             newrdn, deleteoldrdn ) == -1 ) {
137                 ld->ld_errno = LDAP_ENCODING_ERROR;
138                 ber_free( ber, 1 );
139                 return( -1 );
140         }
141
142         /* send the message */
143         return ( ldap_send_initial_request( ld, LDAP_REQ_MODRDN, dn, ber ));
144 }
145
146 int
147 ldap_modrdn( LDAP *ld, char *dn, char *newrdn )
148 {
149         return( ldap_modrdn2( ld, dn, newrdn, 1 ) );
150 }
151
152 int
153 ldap_rename2_s( LDAP *ld, char *dn, char *newrdn, int deleteoldrdn,\
154                 char *newSuperior )
155 {
156         int             msgid;
157         LDAPMessage     *res;
158
159
160         if ( (msgid = ldap_rename2( ld,\
161                                     dn,\
162                                     newrdn,\
163                                     deleteoldrdn,\
164                                     newSuperior ))\
165              == -1 )
166                 return( ld->ld_errno );
167
168         if ( ldap_result( ld, msgid, 1, (struct timeval *) NULL, &res )\
169              == -1 )
170                 return( ld->ld_errno );
171
172         return( ldap_result2error( ld, res, 1 ) );
173
174 }
175
176 int
177 ldap_modrdn2_s( LDAP *ld, char *dn, char *newrdn, int deleteoldrdn )
178 {
179         int             msgid;
180         LDAPMessage     *res;
181
182         if ( (msgid = ldap_modrdn2( ld, dn, newrdn, deleteoldrdn )) == -1 )
183                 return( ld->ld_errno );
184
185         if ( ldap_result( ld, msgid, 1, (struct timeval *) NULL, &res ) == -1 )
186                 return( ld->ld_errno );
187
188         return( ldap_result2error( ld, res, 1 ) );
189 }
190
191 int
192 ldap_modrdn_s( LDAP *ld, char *dn, char *newrdn )
193 {
194         return( ldap_modrdn2_s( ld, dn, newrdn, 1 ) );
195 }
196