* Sync up to trunk head (r64921).
[reactos.git] / dll / win32 / wldap32 / modrdn.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 "winldap_private.h"
22
23 /***********************************************************************
24 * ldap_modrdnA (WLDAP32.@)
25 *
26 * See ldap_modrdnW.
27 */
28 ULONG CDECL ldap_modrdnA( WLDAP32_LDAP *ld, PCHAR dn, PCHAR newdn )
29 {
30 ULONG ret = WLDAP32_LDAP_NOT_SUPPORTED;
31 #ifdef HAVE_LDAP
32 WCHAR *dnW = NULL, *newdnW = NULL;
33
34 ret = WLDAP32_LDAP_NO_MEMORY;
35
36 TRACE( "(%p, %s, %s)\n", ld, debugstr_a(dn), debugstr_a(newdn) );
37
38 if (!ld || !newdn) return ~0u;
39
40 if (dn) {
41 dnW = strAtoW( dn );
42 if (!dnW) goto exit;
43 }
44
45 newdnW = strAtoW( newdn );
46 if (!newdnW) goto exit;
47
48 ret = ldap_modrdnW( ld, dnW, newdnW );
49
50 exit:
51 strfreeW( dnW );
52 strfreeW( newdnW );
53
54 #endif
55 return ret;
56 }
57
58 /***********************************************************************
59 * ldap_modrdnW (WLDAP32.@)
60 *
61 * Change the RDN of a directory entry (asynchronous operation).
62 *
63 * PARAMS
64 * ld [I] Pointer to an LDAP context.
65 * dn [I] DN of the entry to change.
66 * newdn [I] New DN for the entry.
67 *
68 * RETURNS
69 * Success: Message ID of the modrdn operation.
70 * Failure: An LDAP error code.
71 *
72 * NOTES
73 * Call ldap_result with the message ID to get the result of
74 * the operation. Cancel the operation by calling ldap_abandon
75 * with the message ID.
76 */
77 ULONG CDECL ldap_modrdnW( WLDAP32_LDAP *ld, PWCHAR dn, PWCHAR newdn )
78 {
79 ULONG ret = WLDAP32_LDAP_NOT_SUPPORTED;
80 #ifdef HAVE_LDAP
81 char *dnU = NULL, *newdnU = NULL;
82 int msg;
83
84 ret = WLDAP32_LDAP_NO_MEMORY;
85
86 TRACE( "(%p, %s, %s)\n", ld, debugstr_w(dn), debugstr_w(newdn) );
87
88 if (!ld || !newdn) return ~0u;
89
90 if (dn) {
91 dnU = strWtoU( dn );
92 if (!dnU) goto exit;
93 }
94
95 newdnU = strWtoU( newdn );
96 if (!newdnU) goto exit;
97
98 ret = ldap_rename( ld, dn ? dnU : "", newdnU, NULL, 1, NULL, NULL, &msg );
99
100 if (ret == LDAP_SUCCESS)
101 ret = msg;
102 else
103 ret = ~0u;
104
105 exit:
106 strfreeU( dnU );
107 strfreeU( newdnU );
108
109 #endif
110 return ret;
111 }
112
113 /***********************************************************************
114 * ldap_modrdn2A (WLDAP32.@)
115 *
116 * See ldap_modrdn2W.
117 */
118 ULONG CDECL ldap_modrdn2A( WLDAP32_LDAP *ld, PCHAR dn, PCHAR newdn, INT delete )
119 {
120 ULONG ret = WLDAP32_LDAP_NOT_SUPPORTED;
121 #ifdef HAVE_LDAP
122 WCHAR *dnW = NULL, *newdnW = NULL;
123
124 ret = WLDAP32_LDAP_NO_MEMORY;
125
126 TRACE( "(%p, %s, %p, 0x%02x)\n", ld, debugstr_a(dn), newdn, delete );
127
128 if (!ld || !newdn) return ~0u;
129
130 if (dn) {
131 dnW = strAtoW( dn );
132 if (!dnW) goto exit;
133 }
134
135 newdnW = strAtoW( newdn );
136 if (!newdnW) goto exit;
137
138 ret = ldap_modrdn2W( ld, dnW, newdnW, delete );
139
140 exit:
141 strfreeW( dnW );
142 strfreeW( newdnW );
143
144 #endif
145 return ret;
146 }
147
148 /***********************************************************************
149 * ldap_modrdn2W (WLDAP32.@)
150 *
151 * Change the RDN of a directory entry (asynchronous operation).
152 *
153 * PARAMS
154 * ld [I] Pointer to an LDAP context.
155 * dn [I] DN of the entry to change.
156 * newdn [I] New DN for the entry.
157 * delete [I] Delete old DN?
158 *
159 * RETURNS
160 * Success: Message ID of the modrdn operation.
161 * Failure: An LDAP error code.
162 *
163 * NOTES
164 * Call ldap_result with the message ID to get the result of
165 * the operation. Cancel the operation by calling ldap_abandon
166 * with the message ID.
167 */
168 ULONG CDECL ldap_modrdn2W( WLDAP32_LDAP *ld, PWCHAR dn, PWCHAR newdn, INT delete )
169 {
170 ULONG ret = WLDAP32_LDAP_NOT_SUPPORTED;
171 #ifdef HAVE_LDAP
172 char *dnU = NULL, *newdnU = NULL;
173 int msg;
174
175 ret = WLDAP32_LDAP_NO_MEMORY;
176
177 TRACE( "(%p, %s, %p, 0x%02x)\n", ld, debugstr_w(dn), newdn, delete );
178
179 if (!ld || !newdn) return ~0u;
180
181 if (dn) {
182 dnU = strWtoU( dn );
183 if (!dnU) goto exit;
184 }
185
186 newdnU = strWtoU( newdn );
187 if (!newdnU) goto exit;
188
189 ret = ldap_rename( ld, dn ? dnU : "", newdnU, NULL, delete, NULL, NULL, &msg );
190
191 if (ret == LDAP_SUCCESS)
192 ret = msg;
193 else
194 ret = ~0u;
195
196 exit:
197 strfreeU( dnU );
198 strfreeU( newdnU );
199
200 #endif
201 return ret;
202 }
203
204 /***********************************************************************
205 * ldap_modrdn2_sA (WLDAP32.@)
206 *
207 * See ldap_modrdn2_sW.
208 */
209 ULONG CDECL ldap_modrdn2_sA( WLDAP32_LDAP *ld, PCHAR dn, PCHAR newdn, INT delete )
210 {
211 ULONG ret = WLDAP32_LDAP_NOT_SUPPORTED;
212 #ifdef HAVE_LDAP
213 WCHAR *dnW = NULL, *newdnW = NULL;
214
215 ret = WLDAP32_LDAP_NO_MEMORY;
216
217 TRACE( "(%p, %s, %p, 0x%02x)\n", ld, debugstr_a(dn), newdn, delete );
218
219 if (!ld || !newdn) return WLDAP32_LDAP_PARAM_ERROR;
220
221 if (dn) {
222 dnW = strAtoW( dn );
223 if (!dnW) goto exit;
224 }
225
226 newdnW = strAtoW( newdn );
227 if (!newdnW) goto exit;
228
229 ret = ldap_modrdn2_sW( ld, dnW, newdnW, delete );
230
231 exit:
232 strfreeW( dnW );
233 strfreeW( newdnW );
234
235 #endif
236 return ret;
237 }
238
239 /***********************************************************************
240 * ldap_modrdn2_sW (WLDAP32.@)
241 *
242 * Change the RDN of a directory entry (synchronous operation).
243 *
244 * PARAMS
245 * ld [I] Pointer to an LDAP context.
246 * dn [I] DN of the entry to change.
247 * newdn [I] New DN for the entry.
248 * delete [I] Delete old DN?
249 *
250 * RETURNS
251 * Success: LDAP_SUCCESS
252 * Failure: An LDAP error code.
253 */
254 ULONG CDECL ldap_modrdn2_sW( WLDAP32_LDAP *ld, PWCHAR dn, PWCHAR newdn, INT delete )
255 {
256 ULONG ret = WLDAP32_LDAP_NOT_SUPPORTED;
257 #ifdef HAVE_LDAP
258 char *dnU = NULL, *newdnU = NULL;
259
260 ret = WLDAP32_LDAP_NO_MEMORY;
261
262 TRACE( "(%p, %s, %p, 0x%02x)\n", ld, debugstr_w(dn), newdn, delete );
263
264 if (!ld || !newdn) return WLDAP32_LDAP_PARAM_ERROR;
265
266 if (dn) {
267 dnU = strWtoU( dn );
268 if (!dnU) goto exit;
269 }
270
271 newdnU = strWtoU( newdn );
272 if (!newdnU) goto exit;
273
274 ret = map_error( ldap_rename_s( ld, dn ? dnU : "", newdnU, NULL, delete, NULL, NULL ));
275
276 exit:
277 strfreeU( dnU );
278 strfreeU( newdnU );
279
280 #endif
281 return ret;
282 }
283
284 /***********************************************************************
285 * ldap_modrdn_sA (WLDAP32.@)
286 *
287 * See ldap_modrdn_sW.
288 */
289 ULONG CDECL ldap_modrdn_sA( WLDAP32_LDAP *ld, PCHAR dn, PCHAR newdn )
290 {
291 ULONG ret = WLDAP32_LDAP_NOT_SUPPORTED;
292 #ifdef HAVE_LDAP
293 WCHAR *dnW = NULL, *newdnW = NULL;
294
295 ret = WLDAP32_LDAP_NO_MEMORY;
296
297 TRACE( "(%p, %s, %p)\n", ld, debugstr_a(dn), newdn );
298
299 if (!ld || !newdn) return WLDAP32_LDAP_PARAM_ERROR;
300
301 if (dn) {
302 dnW = strAtoW( dn );
303 if (!dnW) goto exit;
304 }
305
306 newdnW = strAtoW( newdn );
307 if (!newdnW) goto exit;
308
309 ret = ldap_modrdn_sW( ld, dnW, newdnW );
310
311 exit:
312 strfreeW( dnW );
313 strfreeW( newdnW );
314
315 #endif
316 return ret;
317 }
318
319 /***********************************************************************
320 * ldap_modrdn_sW (WLDAP32.@)
321 *
322 * Change the RDN of a directory entry (synchronous operation).
323 *
324 * PARAMS
325 * ld [I] Pointer to an LDAP context.
326 * dn [I] DN of the entry to change.
327 * newdn [I] New DN for the entry.
328 *
329 * RETURNS
330 * Success: LDAP_SUCCESS
331 * Failure: An LDAP error code.
332 */
333 ULONG CDECL ldap_modrdn_sW( WLDAP32_LDAP *ld, PWCHAR dn, PWCHAR newdn )
334 {
335 ULONG ret = WLDAP32_LDAP_NOT_SUPPORTED;
336 #ifdef HAVE_LDAP
337 char *dnU = NULL, *newdnU = NULL;
338
339 ret = WLDAP32_LDAP_NO_MEMORY;
340
341 TRACE( "(%p, %s, %p)\n", ld, debugstr_w(dn), newdn );
342
343 if (!ld || !newdn) return WLDAP32_LDAP_PARAM_ERROR;
344
345 if (dn) {
346 dnU = strWtoU( dn );
347 if (!dnU) goto exit;
348 }
349
350 newdnU = strWtoU( newdn );
351 if (!newdnU) goto exit;
352
353 ret = map_error( ldap_rename_s( ld, dn ? dnU : "", newdnU, NULL, 1, NULL, NULL ));
354
355 exit:
356 strfreeU( dnU );
357 strfreeU( newdnU );
358
359 #endif
360 return ret;
361 }