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