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