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