.gitignore: Added wildcards to ignore generated resource files.
[wine] / dlls / wldap32 / modify.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 #ifndef LDAP_NOT_SUPPORTED
37 #define LDAP_NOT_SUPPORTED  0x5c
38 #endif
39
40 #include "winldap_private.h"
41 #include "wldap32.h"
42
43 WINE_DEFAULT_DEBUG_CHANNEL(wldap32);
44
45 #ifdef HAVE_LDAP
46 static LDAPMod *nullmods[] = { NULL };
47 #endif
48
49 /***********************************************************************
50  *      ldap_modifyA     (WLDAP32.@)
51  *
52  * See ldap_modifyW.
53  */
54 ULONG CDECL ldap_modifyA( WLDAP32_LDAP *ld, PCHAR dn, LDAPModA *mods[] )
55 {
56     ULONG ret = LDAP_NOT_SUPPORTED;
57 #ifdef HAVE_LDAP
58     WCHAR *dnW = NULL;
59     LDAPModW **modsW = NULL;
60     
61     ret = WLDAP32_LDAP_NO_MEMORY;
62
63     TRACE( "(%p, %s, %p)\n", ld, debugstr_a(dn), mods );
64
65     if (!ld) return ~0UL;
66
67     if (dn) {
68         dnW = strAtoW( dn );
69         if (!dnW) goto exit;
70     }
71     if (mods) {
72         modsW = modarrayAtoW( mods );
73         if (!modsW) goto exit;
74     }
75
76     ret = ldap_modifyW( ld, dnW, modsW );
77
78 exit:
79     strfreeW( dnW );
80     modarrayfreeW( modsW );
81
82 #endif
83     return ret;
84 }
85
86 /***********************************************************************
87  *      ldap_modifyW     (WLDAP32.@)
88  *
89  * Change an entry in a directory tree (asynchronous operation).
90  *
91  * PARAMS
92  *  ld     [I] Pointer to an LDAP context.
93  *  dn     [I] DN of the entry to change.
94  *  mods   [I] Pointer to an array of LDAPModW structures, each
95  *             specifying an attribute and its values to change.
96  *
97  * RETURNS
98  *  Success: Message ID of the modify operation.
99  *  Failure: An LDAP error code.
100  *
101  * NOTES
102  *  Call ldap_result with the message ID to get the result of
103  *  the operation. Cancel the operation by calling ldap_abandon
104  *  with the message ID.
105  */
106 ULONG CDECL ldap_modifyW( WLDAP32_LDAP *ld, PWCHAR dn, LDAPModW *mods[] )
107 {
108     ULONG ret = LDAP_NOT_SUPPORTED;
109 #ifdef HAVE_LDAP
110     char *dnU = NULL;
111     LDAPMod **modsU = NULL;
112     int msg;
113
114     ret = WLDAP32_LDAP_NO_MEMORY;
115
116     TRACE( "(%p, %s, %p)\n", ld, debugstr_w(dn), mods );
117
118     if (!ld) return WLDAP32_LDAP_PARAM_ERROR;
119
120     if (dn) {
121         dnU = strWtoU( dn );
122         if (!dnU) goto exit;
123     }
124     if (mods) {
125         modsU = modarrayWtoU( mods );
126         if (!modsU) goto exit;
127     }
128
129     ret = ldap_modify_ext( ld, dn ? dnU : "", mods ? modsU : nullmods,
130                            NULL, NULL, &msg );
131
132     if (ret == LDAP_SUCCESS)
133         ret = msg;
134     else
135         ret = ~0UL;
136
137 exit:
138     strfreeU( dnU );
139     modarrayfreeU( modsU );
140
141 #endif
142     return ret;
143 }
144
145 /***********************************************************************
146  *      ldap_modify_extA     (WLDAP32.@)
147  *
148  * See ldap_modify_extW.
149  */
150 ULONG CDECL ldap_modify_extA( WLDAP32_LDAP *ld, PCHAR dn, LDAPModA *mods[],
151     PLDAPControlA *serverctrls, PLDAPControlA *clientctrls, ULONG *message )
152 {
153     ULONG ret = LDAP_NOT_SUPPORTED;
154 #ifdef HAVE_LDAP
155     WCHAR *dnW = NULL;
156     LDAPModW **modsW = NULL;
157     LDAPControlW **serverctrlsW = NULL, **clientctrlsW = NULL;
158
159     ret = WLDAP32_LDAP_NO_MEMORY;
160
161     TRACE( "(%p, %s, %p, %p, %p, %p)\n", ld, debugstr_a(dn), mods,
162            serverctrls, clientctrls, message );
163
164     if (!ld) return ~0UL;
165
166     if (dn) {
167         dnW = strAtoW( dn );
168         if (!dnW) goto exit;
169     }
170     if (mods) {
171         modsW = modarrayAtoW( mods );
172         if (!modsW) goto exit;
173     }
174     if (serverctrls) {
175         serverctrlsW = controlarrayAtoW( serverctrls );
176         if (!serverctrlsW) goto exit;
177     }
178     if (clientctrls) {
179         clientctrlsW = controlarrayAtoW( clientctrls );
180         if (!clientctrlsW) goto exit;
181     }
182
183     ret = ldap_modify_extW( ld, dnW, modsW, serverctrlsW, clientctrlsW, message );
184
185 exit:
186     strfreeW( dnW );
187     modarrayfreeW( modsW );
188     controlarrayfreeW( serverctrlsW );
189     controlarrayfreeW( clientctrlsW );
190
191 #endif
192     return ret;
193 }
194
195 /***********************************************************************
196  *      ldap_modify_extW     (WLDAP32.@)
197  *
198  * Change an entry in a directory tree (asynchronous operation).
199  *
200  * PARAMS
201  *  ld          [I] Pointer to an LDAP context.
202  *  dn          [I] DN of the entry to change.
203  *  mods        [I] Pointer to an array of LDAPModW structures, each
204  *                  specifying an attribute and its values to change.
205  *  serverctrls [I] Array of LDAP server controls.
206  *  clientctrls [I] Array of LDAP client controls.
207  *  message     [O] Message ID of the modify operation.
208  *
209  * RETURNS
210  *  Success: LDAP_SUCCESS
211  *  Failure: An LDAP error code.
212  *
213  * NOTES
214  *  Call ldap_result with the message ID to get the result of
215  *  the operation. The serverctrls and clientctrls parameters are
216  *  optional and should be set to NULL if not used.
217  */
218 ULONG CDECL ldap_modify_extW( WLDAP32_LDAP *ld, PWCHAR dn, LDAPModW *mods[],
219     PLDAPControlW *serverctrls, PLDAPControlW *clientctrls, ULONG *message )
220 {
221     ULONG ret = LDAP_NOT_SUPPORTED;
222 #ifdef HAVE_LDAP
223     char *dnU = NULL;
224     LDAPMod **modsU = NULL;
225     LDAPControl **serverctrlsU = NULL, **clientctrlsU = NULL;
226     int dummy;
227
228     ret = WLDAP32_LDAP_NO_MEMORY;
229
230     TRACE( "(%p, %s, %p, %p, %p, %p)\n", ld, debugstr_w(dn), mods,
231            serverctrls, clientctrls, message );
232
233     if (!ld) return ~0UL;
234
235     if (dn) {
236         dnU = strWtoU( dn );
237         if (!dnU) goto exit;
238     }
239     if (mods) {
240         modsU = modarrayWtoU( mods );
241         if (!modsU) goto exit;
242     }
243     if (serverctrls) {
244         serverctrlsU = controlarrayWtoU( serverctrls );
245         if (!serverctrlsU) goto exit;
246     }
247     if (clientctrls) {
248         clientctrlsU = controlarrayWtoU( clientctrls );
249         if (!clientctrlsU) goto exit;
250     }
251
252     ret = ldap_modify_ext( ld, dn ? dnU : "", mods ? modsU : nullmods, serverctrlsU,
253                            clientctrlsU, message ? (int *)message : &dummy );
254
255 exit:
256     strfreeU( dnU );
257     modarrayfreeU( modsU );
258     controlarrayfreeU( serverctrlsU );
259     controlarrayfreeU( clientctrlsU );
260
261 #endif
262     return ret;
263 }
264
265 /***********************************************************************
266  *      ldap_modify_ext_sA     (WLDAP32.@)
267  *
268  * See ldap_modify_ext_sW.
269  */
270 ULONG CDECL ldap_modify_ext_sA( WLDAP32_LDAP *ld, PCHAR dn, LDAPModA *mods[],
271     PLDAPControlA *serverctrls, PLDAPControlA *clientctrls )
272 {
273     ULONG ret = LDAP_NOT_SUPPORTED;
274 #ifdef HAVE_LDAP
275     WCHAR *dnW = NULL;
276     LDAPModW **modsW = NULL;
277     LDAPControlW **serverctrlsW = NULL, **clientctrlsW = NULL;
278
279     ret = WLDAP32_LDAP_NO_MEMORY;
280
281     TRACE( "(%p, %s, %p, %p, %p)\n", ld, debugstr_a(dn), mods,
282            serverctrls, clientctrls );
283
284     if (!ld) return WLDAP32_LDAP_PARAM_ERROR;
285
286     if (dn) {
287         dnW = strAtoW( dn );
288         if (!dnW) goto exit;
289     }
290     if (mods) {
291         modsW = modarrayAtoW( mods );
292         if (!modsW) goto exit;
293     }
294     if (serverctrls) {
295         serverctrlsW = controlarrayAtoW( serverctrls );
296         if (!serverctrlsW) goto exit;
297     }
298     if (clientctrls) {
299         clientctrlsW = controlarrayAtoW( clientctrls );
300         if (!clientctrlsW) goto exit;
301     }
302
303     ret = ldap_modify_ext_sW( ld, dnW, modsW, serverctrlsW, clientctrlsW );
304
305 exit:
306     strfreeW( dnW );
307     modarrayfreeW( modsW );
308     controlarrayfreeW( serverctrlsW );
309     controlarrayfreeW( clientctrlsW );
310
311 #endif
312     return ret;
313 }
314
315 /***********************************************************************
316  *      ldap_modify_ext_sW     (WLDAP32.@)
317  *
318  * Change an entry in a directory tree (synchronous operation).
319  *
320  * PARAMS
321  *  ld          [I] Pointer to an LDAP context.
322  *  dn          [I] DN of the entry to change.
323  *  mods        [I] Pointer to an array of LDAPModW structures, each
324  *                  specifying an attribute and its values to change.
325  *  serverctrls [I] Array of LDAP server controls.
326  *  clientctrls [I] Array of LDAP client controls.
327  *
328  * RETURNS
329  *  Success: LDAP_SUCCESS
330  *  Failure: An LDAP error code.
331  *
332  * NOTES
333  *  The serverctrls and clientctrls parameters are optional and
334  *  should be set to NULL if not used.
335  */
336 ULONG CDECL ldap_modify_ext_sW( WLDAP32_LDAP *ld, PWCHAR dn, LDAPModW *mods[],
337     PLDAPControlW *serverctrls, PLDAPControlW *clientctrls )
338 {
339     ULONG ret = LDAP_NOT_SUPPORTED;
340 #ifdef HAVE_LDAP
341     char *dnU = NULL;
342     LDAPMod **modsU = NULL;
343     LDAPControl **serverctrlsU = NULL, **clientctrlsU = NULL;
344
345     ret = WLDAP32_LDAP_NO_MEMORY;
346
347     TRACE( "(%p, %s, %p, %p, %p)\n", ld, debugstr_w(dn), mods,
348            serverctrls, clientctrls );
349
350     if (!ld) return WLDAP32_LDAP_PARAM_ERROR;
351
352     if (dn) {
353         dnU = strWtoU( dn );
354         if (!dnU) goto exit;
355     }
356     if (mods) {
357         modsU = modarrayWtoU( mods );
358         if (!modsU) goto exit;
359     }
360     if (serverctrls) {
361         serverctrlsU = controlarrayWtoU( serverctrls );
362         if (!serverctrlsU) goto exit;
363     }
364     if (clientctrls) {
365         clientctrlsU = controlarrayWtoU( clientctrls );
366         if (!clientctrlsU) goto exit;
367     }
368
369     ret = ldap_modify_ext_s( ld, dn ? dnU : "", mods ? modsU : nullmods,
370                              serverctrlsU, clientctrlsU );
371
372 exit:
373     strfreeU( dnU );
374     modarrayfreeU( modsU );
375     controlarrayfreeU( serverctrlsU );
376     controlarrayfreeU( clientctrlsU );
377
378 #endif
379     return ret;
380 }
381
382 /***********************************************************************
383  *      ldap_modify_sA     (WLDAP32.@)
384  *
385  * See ldap_modify_sW.
386  */
387 ULONG CDECL ldap_modify_sA( WLDAP32_LDAP *ld, PCHAR dn, LDAPModA *mods[] )
388 {
389     ULONG ret = LDAP_NOT_SUPPORTED;
390 #ifdef HAVE_LDAP
391     WCHAR *dnW = NULL;
392     LDAPModW **modsW = NULL;
393
394     ret = WLDAP32_LDAP_NO_MEMORY;
395
396     TRACE( "(%p, %s, %p)\n", ld, debugstr_a(dn), mods );
397
398     if (!ld) return WLDAP32_LDAP_PARAM_ERROR;
399
400     if (dn) {
401         dnW = strAtoW( dn );
402         if (!dnW) goto exit;
403     }
404     if (mods) {
405         modsW = modarrayAtoW( mods );
406         if (!modsW) goto exit;
407     }
408
409     ret = ldap_modify_sW( ld, dnW, modsW );
410
411 exit:
412     strfreeW( dnW );
413     modarrayfreeW( modsW );
414
415 #endif
416     return ret;
417 }
418
419 /***********************************************************************
420  *      ldap_modify_sW     (WLDAP32.@)
421  *
422  * Change an entry in a directory tree (synchronous operation).
423  *
424  * PARAMS
425  *  ld      [I] Pointer to an LDAP context.
426  *  dn      [I] DN of the entry to change.
427  *  attrs   [I] Pointer to an array of LDAPModW structures, each
428  *              specifying an attribute and its values to change.
429  *
430  * RETURNS
431  *  Success: LDAP_SUCCESS
432  *  Failure: An LDAP error code.
433  */
434 ULONG CDECL ldap_modify_sW( WLDAP32_LDAP *ld, PWCHAR dn, LDAPModW *mods[] )
435 {
436     ULONG ret = LDAP_NOT_SUPPORTED;
437 #ifdef HAVE_LDAP
438     char *dnU = NULL;
439     LDAPMod **modsU = NULL;
440
441     ret = WLDAP32_LDAP_NO_MEMORY;
442
443     TRACE( "(%p, %s, %p)\n", ld, debugstr_w(dn), mods );
444
445     if (!ld) return WLDAP32_LDAP_PARAM_ERROR;
446
447     if (dn) {
448         dnU = strWtoU( dn );
449         if (!dnU) goto exit;
450     }
451     if (mods) {
452         modsU = modarrayWtoU( mods );
453         if (!modsU) goto exit;
454     }
455
456     ret = ldap_modify_ext_s( ld, dn ? dnU : "", mods ? modsU : nullmods, NULL, NULL );
457
458 exit:
459     strfreeU( dnU );
460     modarrayfreeU( modsU );
461
462 #endif
463     return ret;
464 }