wldap32: Fix unused variable warnings.
[wine/hacks.git] / dlls / wldap32 / add.c
blob99d7c818f8db3aa44d7e4d8ab153490a256389af
1 /*
2 * WLDAP32 - LDAP support for Wine
4 * Copyright 2005 Hans Leidekker
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.
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.
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
21 #include "config.h"
23 #include "wine/port.h"
24 #include "wine/debug.h"
26 #include <stdarg.h>
28 #include "windef.h"
29 #include "winbase.h"
30 #include "winnls.h"
32 #ifdef HAVE_LDAP_H
33 #include <ldap.h>
34 #endif
36 #ifndef LDAP_NOT_SUPPORTED
37 #define LDAP_NOT_SUPPORTED 0x5c
38 #endif
40 #include "winldap_private.h"
41 #include "wldap32.h"
43 WINE_DEFAULT_DEBUG_CHANNEL(wldap32);
45 #ifdef HAVE_LDAP
46 static LDAPMod *nullattrs[] = { NULL };
47 #endif
49 /***********************************************************************
50 * ldap_addA (WLDAP32.@)
52 * See ldap_addW.
54 ULONG ldap_addA( WLDAP32_LDAP *ld, PCHAR dn, LDAPModA *attrs[] )
56 ULONG ret = LDAP_NOT_SUPPORTED;
57 #ifdef HAVE_LDAP
58 WCHAR *dnW = NULL;
59 LDAPModW **attrsW = NULL;
61 ret = WLDAP32_LDAP_NO_MEMORY;
63 TRACE( "(%p, %s, %p)\n", ld, debugstr_a(dn), attrs );
65 if (!ld) return ~0UL;
67 if (dn) {
68 dnW = strAtoW( dn );
69 if (!dnW) goto exit;
71 if (attrs) {
72 attrsW = modarrayAtoW( attrs );
73 if (!attrsW) goto exit;
76 ret = ldap_addW( ld, dnW, attrsW );
78 exit:
79 strfreeW( dnW );
80 modarrayfreeW( attrsW );
82 #endif
83 return ret;
86 /***********************************************************************
87 * ldap_addW (WLDAP32.@)
89 * Add an entry to a directory tree (asynchronous operation).
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.
97 * RETURNS
98 * Success: Message ID of the add operation.
99 * Failure: An LDAP error code.
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.
106 ULONG ldap_addW( WLDAP32_LDAP *ld, PWCHAR dn, LDAPModW *attrs[] )
108 ULONG ret = LDAP_NOT_SUPPORTED;
109 #ifdef HAVE_LDAP
110 char *dnU = NULL;
111 LDAPMod **attrsU = NULL;
112 int msg;
114 ret = WLDAP32_LDAP_NO_MEMORY;
116 TRACE( "(%p, %s, %p)\n", ld, debugstr_w(dn), attrs );
118 if (!ld) return WLDAP32_LDAP_PARAM_ERROR;
120 if (dn) {
121 dnU = strWtoU( dn );
122 if (!dnU) goto exit;
124 if (attrs) {
125 attrsU = modarrayWtoU( attrs );
126 if (!attrsU) goto exit;
129 ret = ldap_add_ext( ld, dn ? dnU : "", attrs ? attrsU : nullattrs, NULL, NULL, &msg );
131 if (ret == LDAP_SUCCESS)
132 ret = msg;
133 else
134 ret = ~0UL;
136 exit:
137 strfreeU( dnU );
138 modarrayfreeU( attrsU );
140 #endif
141 return ret;
144 /***********************************************************************
145 * ldap_add_extA (WLDAP32.@)
147 * See ldap_add_extW.
149 ULONG ldap_add_extA( WLDAP32_LDAP *ld, PCHAR dn, LDAPModA *attrs[],
150 PLDAPControlA *serverctrls, PLDAPControlA *clientctrls, ULONG *message )
152 ULONG ret = LDAP_NOT_SUPPORTED;
153 #ifdef HAVE_LDAP
154 WCHAR *dnW = NULL;
155 LDAPModW **attrsW = NULL;
156 LDAPControlW **serverctrlsW = NULL, **clientctrlsW = NULL;
158 ret = WLDAP32_LDAP_NO_MEMORY;
160 TRACE( "(%p, %s, %p, %p, %p, %p)\n", ld, debugstr_a(dn), attrs,
161 serverctrls, clientctrls, message );
163 if (!ld) return WLDAP32_LDAP_PARAM_ERROR;
165 if (dn) {
166 dnW = strAtoW( dn );
167 if (!dnW) goto exit;
169 if (attrs) {
170 attrsW = modarrayAtoW( attrs );
171 if (!attrsW) goto exit;
173 if (serverctrls) {
174 serverctrlsW = controlarrayAtoW( serverctrls );
175 if (!serverctrlsW) goto exit;
177 if (clientctrls) {
178 clientctrlsW = controlarrayAtoW( clientctrls );
179 if (!clientctrlsW) goto exit;
182 ret = ldap_add_extW( ld, dnW, attrsW, serverctrlsW, clientctrlsW, message );
184 exit:
185 strfreeW( dnW );
186 modarrayfreeW( attrsW );
187 controlarrayfreeW( serverctrlsW );
188 controlarrayfreeW( clientctrlsW );
190 #endif
191 return ret;
194 /***********************************************************************
195 * ldap_add_extW (WLDAP32.@)
197 * Add an entry to a directory tree (asynchronous operation).
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.
208 * RETURNS
209 * Success: LDAP_SUCCESS
210 * Failure: An LDAP error code.
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.
217 ULONG ldap_add_extW( WLDAP32_LDAP *ld, PWCHAR dn, LDAPModW *attrs[],
218 PLDAPControlW *serverctrls, PLDAPControlW *clientctrls, ULONG *message )
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;
227 ret = WLDAP32_LDAP_NO_MEMORY;
229 TRACE( "(%p, %s, %p, %p, %p, %p)\n", ld, debugstr_w(dn), attrs,
230 serverctrls, clientctrls, message );
232 if (!ld) return WLDAP32_LDAP_PARAM_ERROR;
234 if (dn) {
235 dnU = strWtoU( dn );
236 if (!dnU) goto exit;
238 if (attrs) {
239 attrsU = modarrayWtoU( attrs );
240 if (!attrsU) goto exit;
242 if (serverctrls) {
243 serverctrlsU = controlarrayWtoU( serverctrls );
244 if (!serverctrlsU) goto exit;
246 if (clientctrls) {
247 clientctrlsU = controlarrayWtoU( clientctrls );
248 if (!clientctrlsU) goto exit;
251 ret = ldap_add_ext( ld, dn ? dnU : "", attrs ? attrsU : nullattrs, serverctrlsU,
252 clientctrlsU, message ? (int *)message : &dummy );
254 exit:
255 strfreeU( dnU );
256 modarrayfreeU( attrsU );
257 controlarrayfreeU( serverctrlsU );
258 controlarrayfreeU( clientctrlsU );
260 #endif
261 return ret;
264 /***********************************************************************
265 * ldap_add_ext_sA (WLDAP32.@)
267 * See ldap_add_ext_sW.
269 ULONG ldap_add_ext_sA( WLDAP32_LDAP *ld, PCHAR dn, LDAPModA *attrs[],
270 PLDAPControlA *serverctrls, PLDAPControlA *clientctrls )
272 ULONG ret = LDAP_NOT_SUPPORTED;
273 #ifdef HAVE_LDAP
274 WCHAR *dnW = NULL;
275 LDAPModW **attrsW = NULL;
276 LDAPControlW **serverctrlsW = NULL, **clientctrlsW = NULL;
278 ret = WLDAP32_LDAP_NO_MEMORY;
280 TRACE( "(%p, %s, %p, %p, %p)\n", ld, debugstr_a(dn), attrs,
281 serverctrls, clientctrls );
283 if (!ld) return WLDAP32_LDAP_PARAM_ERROR;
285 if (dn) {
286 dnW = strAtoW( dn );
287 if (!dnW) goto exit;
289 if (attrs) {
290 attrsW = modarrayAtoW( attrs );
291 if (!attrsW) goto exit;
293 if (serverctrls) {
294 serverctrlsW = controlarrayAtoW( serverctrls );
295 if (!serverctrlsW) goto exit;
297 if (clientctrls) {
298 clientctrlsW = controlarrayAtoW( clientctrls );
299 if (!clientctrlsW) goto exit;
302 ret = ldap_add_ext_sW( ld, dnW, attrsW, serverctrlsW, clientctrlsW );
304 exit:
305 strfreeW( dnW );
306 modarrayfreeW( attrsW );
307 controlarrayfreeW( serverctrlsW );
308 controlarrayfreeW( clientctrlsW );
310 #endif
311 return ret;
314 /***********************************************************************
315 * ldap_add_ext_sW (WLDAP32.@)
317 * Add an entry to a directory tree (synchronous operation).
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.
327 * RETURNS
328 * Success: LDAP_SUCCESS
329 * Failure: An LDAP error code.
331 * NOTES
332 * The serverctrls and clientctrls parameters are optional and
333 * should be set to NULL if not used.
335 ULONG ldap_add_ext_sW( WLDAP32_LDAP *ld, PWCHAR dn, LDAPModW *attrs[],
336 PLDAPControlW *serverctrls, PLDAPControlW *clientctrls )
338 ULONG ret = LDAP_NOT_SUPPORTED;
339 #ifdef HAVE_LDAP
340 char *dnU = NULL;
341 LDAPMod **attrsU = NULL;
342 LDAPControl **serverctrlsU = NULL, **clientctrlsU = NULL;
344 ret = WLDAP32_LDAP_NO_MEMORY;
346 TRACE( "(%p, %s, %p, %p, %p)\n", ld, debugstr_w(dn), attrs,
347 serverctrls, clientctrls );
349 if (!ld) return WLDAP32_LDAP_PARAM_ERROR;
351 if (dn) {
352 dnU = strWtoU( dn );
353 if (!dnU) goto exit;
355 if (attrs) {
356 attrsU = modarrayWtoU( attrs );
357 if (!attrsU) goto exit;
359 if (serverctrls) {
360 serverctrlsU = controlarrayWtoU( serverctrls );
361 if (!serverctrlsU) goto exit;
363 if (clientctrls) {
364 clientctrlsU = controlarrayWtoU( clientctrls );
365 if (!clientctrlsU) goto exit;
368 ret = ldap_add_ext_s( ld, dn ? dnU : "", attrs ? attrsU : nullattrs,
369 serverctrlsU, clientctrlsU );
371 exit:
372 strfreeU( dnU );
373 modarrayfreeU( attrsU );
374 controlarrayfreeU( serverctrlsU );
375 controlarrayfreeU( clientctrlsU );
377 #endif
378 return ret;
381 /***********************************************************************
382 * ldap_add_sA (WLDAP32.@)
384 * See ldap_add_sW.
386 ULONG ldap_add_sA( WLDAP32_LDAP *ld, PCHAR dn, LDAPModA *attrs[] )
388 ULONG ret = LDAP_NOT_SUPPORTED;
389 #ifdef HAVE_LDAP
390 WCHAR *dnW = NULL;
391 LDAPModW **attrsW = NULL;
393 ret = WLDAP32_LDAP_NO_MEMORY;
395 TRACE( "(%p, %s, %p)\n", ld, debugstr_a(dn), attrs );
397 if (!ld) return WLDAP32_LDAP_PARAM_ERROR;
399 if (dn) {
400 dnW = strAtoW( dn );
401 if (!dnW) goto exit;
403 if (attrs) {
404 attrsW = modarrayAtoW( attrs );
405 if (!attrsW) goto exit;
408 ret = ldap_add_sW( ld, dnW, attrsW );
410 exit:
411 strfreeW( dnW );
412 modarrayfreeW( attrsW );
414 #endif
415 return ret;
418 /***********************************************************************
419 * ldap_add_sW (WLDAP32.@)
421 * Add an entry to a directory tree (synchronous operation).
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.
429 * RETURNS
430 * Success: LDAP_SUCCESS
431 * Failure: An LDAP error code.
433 ULONG ldap_add_sW( WLDAP32_LDAP *ld, PWCHAR dn, LDAPModW *attrs[] )
435 ULONG ret = LDAP_NOT_SUPPORTED;
436 #ifdef HAVE_LDAP
437 char *dnU = NULL;
438 LDAPMod **attrsU = NULL;
440 ret = WLDAP32_LDAP_NO_MEMORY;
442 TRACE( "(%p, %s, %p)\n", ld, debugstr_w(dn), attrs );
444 if (!ld) return WLDAP32_LDAP_PARAM_ERROR;
446 if (dn) {
447 dnU = strWtoU( dn );
448 if (!dnU) goto exit;
450 if (attrs) {
451 attrsU = modarrayWtoU( attrs );
452 if (!attrsU) goto exit;
455 ret = ldap_add_ext_s( ld, dn ? dnU : "", attrs ? attrsU : nullattrs, NULL, NULL );
457 exit:
458 strfreeU( dnU );
459 modarrayfreeU( attrsU );
461 #endif
462 return ret;