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