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