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