Sync with trunk (r48545)
[reactos.git] / dll / win32 / wldap32 / rename.c
1 /*
2 * WLDAP32 - LDAP support for Wine
3 *
4 * Copyright 2005 Hans Leidekker
5 *
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
10 *
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
15 *
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19 */
20
21 #include "config.h"
22
23 #include "wine/port.h"
24 #include "wine/debug.h"
25
26 #include <stdarg.h>
27
28 #include "windef.h"
29 #include "winbase.h"
30 #include "winnls.h"
31
32 #ifdef HAVE_LDAP_H
33 #include <ldap.h>
34 #endif
35
36 #include "winldap_private.h"
37 #include "wldap32.h"
38
39 WINE_DEFAULT_DEBUG_CHANNEL(wldap32);
40
41 /***********************************************************************
42 * ldap_rename_extA (WLDAP32.@)
43 *
44 * See ldap_rename_extW.
45 */
46 ULONG CDECL ldap_rename_extA( WLDAP32_LDAP *ld, PCHAR dn, PCHAR newrdn,
47 PCHAR newparent, INT delete, PLDAPControlA *serverctrls,
48 PLDAPControlA *clientctrls, ULONG *message )
49 {
50 ULONG ret = WLDAP32_LDAP_NOT_SUPPORTED;
51 #ifdef HAVE_LDAP
52 WCHAR *dnW = NULL, *newrdnW = NULL, *newparentW = NULL;
53 LDAPControlW **serverctrlsW = NULL, **clientctrlsW = NULL;
54
55 ret = WLDAP32_LDAP_NO_MEMORY;
56
57 TRACE( "(%p, %s, %s, %s, 0x%02x, %p, %p, %p)\n", ld, debugstr_a(dn),
58 debugstr_a(newrdn), debugstr_a(newparent), delete,
59 serverctrls, clientctrls, message );
60
61 if (!ld || !message) return WLDAP32_LDAP_PARAM_ERROR;
62
63 if (dn) {
64 dnW = strAtoW( dn );
65 if (!dnW) goto exit;
66 }
67 if (newrdn) {
68 newrdnW = strAtoW( newrdn );
69 if (!newrdnW) goto exit;
70 }
71 if (newparent) {
72 newparentW = strAtoW( newparent );
73 if (!newparentW) goto exit;
74 }
75 if (serverctrls) {
76 serverctrlsW = controlarrayAtoW( serverctrls );
77 if (!serverctrlsW) goto exit;
78 }
79 if (clientctrls) {
80 clientctrlsW = controlarrayAtoW( clientctrls );
81 if (!clientctrlsW) goto exit;
82 }
83
84 ret = ldap_rename_extW( ld, dnW, newrdnW, newparentW, delete,
85 serverctrlsW, clientctrlsW, message );
86
87 exit:
88 strfreeW( dnW );
89 strfreeW( newrdnW );
90 strfreeW( newparentW );
91 controlarrayfreeW( serverctrlsW );
92 controlarrayfreeW( clientctrlsW );
93
94 #endif
95 return ret;
96 }
97
98 /***********************************************************************
99 * ldap_rename_extW (WLDAP32.@)
100 *
101 * Change the DN of a directory entry (asynchronous operation).
102 *
103 * PARAMS
104 * ld [I] Pointer to an LDAP context.
105 * dn [I] DN of the entry to change.
106 * newrdn [I] New RDN for the entry.
107 * newparent [I] New parent for the entry.
108 * delete [I] Delete old RDN?
109 * serverctrls [I] Array of LDAP server controls.
110 * clientctrls [I] Array of LDAP client controls.
111 * message [O] Message ID of the operation.
112 *
113 * RETURNS
114 * Success: LDAP_SUCCESS
115 * Failure: An LDAP error code.
116 *
117 * NOTES
118 * Call ldap_result with the message ID to get the result of
119 * the operation. Cancel the operation by calling ldap_abandon
120 * with the message ID.
121 */
122 ULONG CDECL ldap_rename_extW( WLDAP32_LDAP *ld, PWCHAR dn, PWCHAR newrdn,
123 PWCHAR newparent, INT delete, PLDAPControlW *serverctrls,
124 PLDAPControlW *clientctrls, ULONG *message )
125 {
126 ULONG ret = WLDAP32_LDAP_NOT_SUPPORTED;
127 #ifdef HAVE_LDAP
128 char *dnU = NULL, *newrdnU = NULL, *newparentU = NULL;
129 LDAPControl **serverctrlsU = NULL, **clientctrlsU = NULL;
130
131 ret = WLDAP32_LDAP_NO_MEMORY;
132
133 TRACE( "(%p, %s, %s, %s, 0x%02x, %p, %p, %p)\n", ld, debugstr_w(dn),
134 debugstr_w(newrdn), debugstr_w(newparent), delete,
135 serverctrls, clientctrls, message );
136
137 if (!ld || !message) return WLDAP32_LDAP_PARAM_ERROR;
138
139 if (dn) {
140 dnU = strWtoU( dn );
141 if (!dnU) goto exit;
142 }
143 if (newrdn) {
144 newrdnU = strWtoU( newrdn );
145 if (!newrdnU) goto exit;
146 }
147 if (newparent) {
148 newparentU = strWtoU( newparent );
149 if (!newparentU) goto exit;
150 }
151 if (serverctrls) {
152 serverctrlsU = controlarrayWtoU( serverctrls );
153 if (!serverctrlsU) goto exit;
154 }
155 if (clientctrls) {
156 clientctrlsU = controlarrayWtoU( clientctrls );
157 if (!clientctrlsU) goto exit;
158 }
159
160 ret = map_error( ldap_rename( ld, dn ? dnU : "", newrdn ? newrdnU : "", newparentU,
161 delete, serverctrlsU, clientctrlsU, (int *)message ));
162
163 exit:
164 strfreeU( dnU );
165 strfreeU( newrdnU );
166 strfreeU( newparentU );
167 controlarrayfreeU( serverctrlsU );
168 controlarrayfreeU( clientctrlsU );
169
170 #endif
171 return ret;
172 }
173
174 /***********************************************************************
175 * ldap_rename_ext_sA (WLDAP32.@)
176 *
177 * See ldap_rename_ext_sW.
178 */
179 ULONG CDECL ldap_rename_ext_sA( WLDAP32_LDAP *ld, PCHAR dn, PCHAR newrdn,
180 PCHAR newparent, INT delete, PLDAPControlA *serverctrls,
181 PLDAPControlA *clientctrls )
182 {
183 ULONG ret = WLDAP32_LDAP_NOT_SUPPORTED;
184 #ifdef HAVE_LDAP
185 WCHAR *dnW = NULL, *newrdnW = NULL, *newparentW = NULL;
186 LDAPControlW **serverctrlsW = NULL, **clientctrlsW = NULL;
187
188 ret = WLDAP32_LDAP_NO_MEMORY;
189
190 TRACE( "(%p, %s, %s, %s, 0x%02x, %p, %p)\n", ld, debugstr_a(dn),
191 debugstr_a(newrdn), debugstr_a(newparent), delete,
192 serverctrls, clientctrls );
193
194 if (!ld) return WLDAP32_LDAP_PARAM_ERROR;
195
196 if (dn) {
197 dnW = strAtoW( dn );
198 if (!dnW) goto exit;
199 }
200 if (newrdn) {
201 newrdnW = strAtoW( newrdn );
202 if (!newrdnW) goto exit;
203 }
204 if (newparent) {
205 newparentW = strAtoW( newparent );
206 if (!newparentW) goto exit;
207 }
208 if (serverctrls) {
209 serverctrlsW = controlarrayAtoW( serverctrls );
210 if (!serverctrlsW) goto exit;
211 }
212 if (clientctrls) {
213 clientctrlsW = controlarrayAtoW( clientctrls );
214 if (!clientctrlsW) goto exit;
215 }
216
217 ret = ldap_rename_ext_sW( ld, dnW, newrdnW, newparentW, delete,
218 serverctrlsW, clientctrlsW );
219
220 exit:
221 strfreeW( dnW );
222 strfreeW( newrdnW );
223 strfreeW( newparentW );
224 controlarrayfreeW( serverctrlsW );
225 controlarrayfreeW( clientctrlsW );
226
227 #endif
228 return ret;
229 }
230 /***********************************************************************
231 * ldap_rename_ext_sW (WLDAP32.@)
232 *
233 * Change the DN of a directory entry (synchronous operation).
234 *
235 * PARAMS
236 * ld [I] Pointer to an LDAP context.
237 * dn [I] DN of the entry to change.
238 * newrdn [I] New RDN for the entry.
239 * newparent [I] New parent for the entry.
240 * delete [I] Delete old RDN?
241 * serverctrls [I] Array of LDAP server controls.
242 * clientctrls [I] Array of LDAP client controls.
243 *
244 * RETURNS
245 * Success: LDAP_SUCCESS
246 * Failure: An LDAP error code.
247 */
248 ULONG CDECL ldap_rename_ext_sW( WLDAP32_LDAP *ld, PWCHAR dn, PWCHAR newrdn,
249 PWCHAR newparent, INT delete, PLDAPControlW *serverctrls,
250 PLDAPControlW *clientctrls )
251 {
252 ULONG ret = WLDAP32_LDAP_NOT_SUPPORTED;
253 #ifdef HAVE_LDAP
254 char *dnU = NULL, *newrdnU = NULL, *newparentU = NULL;
255 LDAPControl **serverctrlsU = NULL, **clientctrlsU = NULL;
256
257 ret = WLDAP32_LDAP_NO_MEMORY;
258
259 TRACE( "(%p, %s, %s, %s, 0x%02x, %p, %p)\n", ld, debugstr_w(dn),
260 debugstr_w(newrdn), debugstr_w(newparent), delete,
261 serverctrls, clientctrls );
262
263 if (!ld) return WLDAP32_LDAP_PARAM_ERROR;
264
265 if (dn) {
266 dnU = strWtoU( dn );
267 if (!dnU) goto exit;
268 }
269 if (newrdn) {
270 newrdnU = strWtoU( newrdn );
271 if (!newrdnU) goto exit;
272 }
273 if (newparent) {
274 newparentU = strWtoU( newparent );
275 if (!newparentU) goto exit;
276 }
277 if (serverctrls) {
278 serverctrlsU = controlarrayWtoU( serverctrls );
279 if (!serverctrlsU) goto exit;
280 }
281 if (clientctrls) {
282 clientctrlsU = controlarrayWtoU( clientctrls );
283 if (!clientctrlsU) goto exit;
284 }
285
286 ret = map_error( ldap_rename_s( ld, dn ? dnU : "", newrdn ? newrdnU : "", newparentU,
287 delete, serverctrlsU, clientctrlsU ));
288
289 exit:
290 strfreeU( dnU );
291 strfreeU( newrdnU );
292 strfreeU( newparentU );
293 controlarrayfreeU( serverctrlsU );
294 controlarrayfreeU( clientctrlsU );
295
296 #endif
297 return ret;
298 }