Release 1.3.7.
[wine/gsoc-2012-control.git] / dlls / wldap32 / add.c
blobb15f5f9e41c491c8e1d16486389e6b341e47726f
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 #include "winldap_private.h"
37 #include "wldap32.h"
39 WINE_DEFAULT_DEBUG_CHANNEL(wldap32);
41 #ifdef HAVE_LDAP
42 static LDAPMod *nullattrs[] = { NULL };
43 #endif
45 /***********************************************************************
46 * ldap_addA (WLDAP32.@)
48 * See ldap_addW.
50 ULONG CDECL ldap_addA( WLDAP32_LDAP *ld, PCHAR dn, LDAPModA *attrs[] )
52 ULONG ret = WLDAP32_LDAP_NOT_SUPPORTED;
53 #ifdef HAVE_LDAP
54 WCHAR *dnW = NULL;
55 LDAPModW **attrsW = NULL;
57 ret = WLDAP32_LDAP_NO_MEMORY;
59 TRACE( "(%p, %s, %p)\n", ld, debugstr_a(dn), attrs );
61 if (!ld) return ~0u;
63 if (dn) {
64 dnW = strAtoW( dn );
65 if (!dnW) goto exit;
67 if (attrs) {
68 attrsW = modarrayAtoW( attrs );
69 if (!attrsW) goto exit;
72 ret = ldap_addW( ld, dnW, attrsW );
74 exit:
75 strfreeW( dnW );
76 modarrayfreeW( attrsW );
78 #endif
79 return ret;
82 /***********************************************************************
83 * ldap_addW (WLDAP32.@)
85 * Add an entry to a directory tree (asynchronous operation).
87 * PARAMS
88 * ld [I] Pointer to an LDAP context.
89 * dn [I] DN of the entry to add.
90 * attrs [I] Pointer to an array of LDAPModW structures, each
91 * specifying an attribute and its values to add.
93 * RETURNS
94 * Success: Message ID of the add operation.
95 * Failure: An LDAP error code.
97 * NOTES
98 * Call ldap_result with the message ID to get the result of
99 * the operation. Cancel the operation by calling ldap_abandon
100 * with the message ID.
102 ULONG CDECL ldap_addW( WLDAP32_LDAP *ld, PWCHAR dn, LDAPModW *attrs[] )
104 ULONG ret = WLDAP32_LDAP_NOT_SUPPORTED;
105 #ifdef HAVE_LDAP
106 char *dnU = NULL;
107 LDAPMod **attrsU = NULL;
108 int msg;
110 ret = WLDAP32_LDAP_NO_MEMORY;
112 TRACE( "(%p, %s, %p)\n", ld, debugstr_w(dn), attrs );
114 if (!ld) return WLDAP32_LDAP_PARAM_ERROR;
116 if (dn) {
117 dnU = strWtoU( dn );
118 if (!dnU) goto exit;
120 if (attrs) {
121 attrsU = modarrayWtoU( attrs );
122 if (!attrsU) goto exit;
125 ret = ldap_add_ext( ld, dn ? dnU : "", attrs ? attrsU : nullattrs, NULL, NULL, &msg );
127 if (ret == LDAP_SUCCESS)
128 ret = msg;
129 else
130 ret = ~0u;
132 exit:
133 strfreeU( dnU );
134 modarrayfreeU( attrsU );
136 #endif
137 return ret;
140 /***********************************************************************
141 * ldap_add_extA (WLDAP32.@)
143 * See ldap_add_extW.
145 ULONG CDECL ldap_add_extA( WLDAP32_LDAP *ld, PCHAR dn, LDAPModA *attrs[],
146 PLDAPControlA *serverctrls, PLDAPControlA *clientctrls, ULONG *message )
148 ULONG ret = WLDAP32_LDAP_NOT_SUPPORTED;
149 #ifdef HAVE_LDAP
150 WCHAR *dnW = NULL;
151 LDAPModW **attrsW = NULL;
152 LDAPControlW **serverctrlsW = NULL, **clientctrlsW = NULL;
154 ret = WLDAP32_LDAP_NO_MEMORY;
156 TRACE( "(%p, %s, %p, %p, %p, %p)\n", ld, debugstr_a(dn), attrs,
157 serverctrls, clientctrls, message );
159 if (!ld) return WLDAP32_LDAP_PARAM_ERROR;
161 if (dn) {
162 dnW = strAtoW( dn );
163 if (!dnW) goto exit;
165 if (attrs) {
166 attrsW = modarrayAtoW( attrs );
167 if (!attrsW) goto exit;
169 if (serverctrls) {
170 serverctrlsW = controlarrayAtoW( serverctrls );
171 if (!serverctrlsW) goto exit;
173 if (clientctrls) {
174 clientctrlsW = controlarrayAtoW( clientctrls );
175 if (!clientctrlsW) goto exit;
178 ret = ldap_add_extW( ld, dnW, attrsW, serverctrlsW, clientctrlsW, message );
180 exit:
181 strfreeW( dnW );
182 modarrayfreeW( attrsW );
183 controlarrayfreeW( serverctrlsW );
184 controlarrayfreeW( clientctrlsW );
186 #endif
187 return ret;
190 /***********************************************************************
191 * ldap_add_extW (WLDAP32.@)
193 * Add an entry to a directory tree (asynchronous operation).
195 * PARAMS
196 * ld [I] Pointer to an LDAP context.
197 * dn [I] DN of the entry to add.
198 * attrs [I] Pointer to an array of LDAPModW structures, each
199 * specifying an attribute and its values to add.
200 * serverctrls [I] Array of LDAP server controls.
201 * clientctrls [I] Array of LDAP client controls.
202 * message [O] Message ID of the add operation.
204 * RETURNS
205 * Success: LDAP_SUCCESS
206 * Failure: An LDAP error code.
208 * NOTES
209 * Call ldap_result with the message ID to get the result of
210 * the operation. The serverctrls and clientctrls parameters are
211 * optional and should be set to NULL if not used.
213 ULONG CDECL ldap_add_extW( WLDAP32_LDAP *ld, PWCHAR dn, LDAPModW *attrs[],
214 PLDAPControlW *serverctrls, PLDAPControlW *clientctrls, ULONG *message )
216 ULONG ret = WLDAP32_LDAP_NOT_SUPPORTED;
217 #ifdef HAVE_LDAP
218 char *dnU = NULL;
219 LDAPMod **attrsU = NULL;
220 LDAPControl **serverctrlsU = NULL, **clientctrlsU = NULL;
221 int dummy;
223 ret = WLDAP32_LDAP_NO_MEMORY;
225 TRACE( "(%p, %s, %p, %p, %p, %p)\n", ld, debugstr_w(dn), attrs,
226 serverctrls, clientctrls, message );
228 if (!ld) return WLDAP32_LDAP_PARAM_ERROR;
230 if (dn) {
231 dnU = strWtoU( dn );
232 if (!dnU) goto exit;
234 if (attrs) {
235 attrsU = modarrayWtoU( attrs );
236 if (!attrsU) goto exit;
238 if (serverctrls) {
239 serverctrlsU = controlarrayWtoU( serverctrls );
240 if (!serverctrlsU) goto exit;
242 if (clientctrls) {
243 clientctrlsU = controlarrayWtoU( clientctrls );
244 if (!clientctrlsU) goto exit;
247 ret = map_error( ldap_add_ext( ld, dn ? dnU : "", attrs ? attrsU : nullattrs, serverctrlsU,
248 clientctrlsU, message ? (int *)message : &dummy ));
250 exit:
251 strfreeU( dnU );
252 modarrayfreeU( attrsU );
253 controlarrayfreeU( serverctrlsU );
254 controlarrayfreeU( clientctrlsU );
256 #endif
257 return ret;
260 /***********************************************************************
261 * ldap_add_ext_sA (WLDAP32.@)
263 * See ldap_add_ext_sW.
265 ULONG CDECL ldap_add_ext_sA( WLDAP32_LDAP *ld, PCHAR dn, LDAPModA *attrs[],
266 PLDAPControlA *serverctrls, PLDAPControlA *clientctrls )
268 ULONG ret = WLDAP32_LDAP_NOT_SUPPORTED;
269 #ifdef HAVE_LDAP
270 WCHAR *dnW = NULL;
271 LDAPModW **attrsW = NULL;
272 LDAPControlW **serverctrlsW = NULL, **clientctrlsW = NULL;
274 ret = WLDAP32_LDAP_NO_MEMORY;
276 TRACE( "(%p, %s, %p, %p, %p)\n", ld, debugstr_a(dn), attrs,
277 serverctrls, clientctrls );
279 if (!ld) return WLDAP32_LDAP_PARAM_ERROR;
281 if (dn) {
282 dnW = strAtoW( dn );
283 if (!dnW) goto exit;
285 if (attrs) {
286 attrsW = modarrayAtoW( attrs );
287 if (!attrsW) goto exit;
289 if (serverctrls) {
290 serverctrlsW = controlarrayAtoW( serverctrls );
291 if (!serverctrlsW) goto exit;
293 if (clientctrls) {
294 clientctrlsW = controlarrayAtoW( clientctrls );
295 if (!clientctrlsW) goto exit;
298 ret = ldap_add_ext_sW( ld, dnW, attrsW, serverctrlsW, clientctrlsW );
300 exit:
301 strfreeW( dnW );
302 modarrayfreeW( attrsW );
303 controlarrayfreeW( serverctrlsW );
304 controlarrayfreeW( clientctrlsW );
306 #endif
307 return ret;
310 /***********************************************************************
311 * ldap_add_ext_sW (WLDAP32.@)
313 * Add an entry to a directory tree (synchronous operation).
315 * PARAMS
316 * ld [I] Pointer to an LDAP context.
317 * dn [I] DN of the entry to add.
318 * attrs [I] Pointer to an array of LDAPModW structures, each
319 * specifying an attribute and its values to add.
320 * serverctrls [I] Array of LDAP server controls.
321 * clientctrls [I] Array of LDAP client controls.
323 * RETURNS
324 * Success: LDAP_SUCCESS
325 * Failure: An LDAP error code.
327 * NOTES
328 * The serverctrls and clientctrls parameters are optional and
329 * should be set to NULL if not used.
331 ULONG CDECL ldap_add_ext_sW( WLDAP32_LDAP *ld, PWCHAR dn, LDAPModW *attrs[],
332 PLDAPControlW *serverctrls, PLDAPControlW *clientctrls )
334 ULONG ret = WLDAP32_LDAP_NOT_SUPPORTED;
335 #ifdef HAVE_LDAP
336 char *dnU = NULL;
337 LDAPMod **attrsU = NULL;
338 LDAPControl **serverctrlsU = NULL, **clientctrlsU = NULL;
340 ret = WLDAP32_LDAP_NO_MEMORY;
342 TRACE( "(%p, %s, %p, %p, %p)\n", ld, debugstr_w(dn), attrs,
343 serverctrls, clientctrls );
345 if (!ld) return WLDAP32_LDAP_PARAM_ERROR;
347 if (dn) {
348 dnU = strWtoU( dn );
349 if (!dnU) goto exit;
351 if (attrs) {
352 attrsU = modarrayWtoU( attrs );
353 if (!attrsU) goto exit;
355 if (serverctrls) {
356 serverctrlsU = controlarrayWtoU( serverctrls );
357 if (!serverctrlsU) goto exit;
359 if (clientctrls) {
360 clientctrlsU = controlarrayWtoU( clientctrls );
361 if (!clientctrlsU) goto exit;
364 ret = map_error( ldap_add_ext_s( ld, dn ? dnU : "", attrs ? attrsU : nullattrs,
365 serverctrlsU, clientctrlsU ));
367 exit:
368 strfreeU( dnU );
369 modarrayfreeU( attrsU );
370 controlarrayfreeU( serverctrlsU );
371 controlarrayfreeU( clientctrlsU );
373 #endif
374 return ret;
377 /***********************************************************************
378 * ldap_add_sA (WLDAP32.@)
380 * See ldap_add_sW.
382 ULONG CDECL ldap_add_sA( WLDAP32_LDAP *ld, PCHAR dn, LDAPModA *attrs[] )
384 ULONG ret = WLDAP32_LDAP_NOT_SUPPORTED;
385 #ifdef HAVE_LDAP
386 WCHAR *dnW = NULL;
387 LDAPModW **attrsW = NULL;
389 ret = WLDAP32_LDAP_NO_MEMORY;
391 TRACE( "(%p, %s, %p)\n", ld, debugstr_a(dn), attrs );
393 if (!ld) return WLDAP32_LDAP_PARAM_ERROR;
395 if (dn) {
396 dnW = strAtoW( dn );
397 if (!dnW) goto exit;
399 if (attrs) {
400 attrsW = modarrayAtoW( attrs );
401 if (!attrsW) goto exit;
404 ret = ldap_add_sW( ld, dnW, attrsW );
406 exit:
407 strfreeW( dnW );
408 modarrayfreeW( attrsW );
410 #endif
411 return ret;
414 /***********************************************************************
415 * ldap_add_sW (WLDAP32.@)
417 * Add an entry to a directory tree (synchronous operation).
419 * PARAMS
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.
425 * RETURNS
426 * Success: LDAP_SUCCESS
427 * Failure: An LDAP error code.
429 ULONG CDECL ldap_add_sW( WLDAP32_LDAP *ld, PWCHAR dn, LDAPModW *attrs[] )
431 ULONG ret = WLDAP32_LDAP_NOT_SUPPORTED;
432 #ifdef HAVE_LDAP
433 char *dnU = NULL;
434 LDAPMod **attrsU = NULL;
436 ret = WLDAP32_LDAP_NO_MEMORY;
438 TRACE( "(%p, %s, %p)\n", ld, debugstr_w(dn), attrs );
440 if (!ld) return WLDAP32_LDAP_PARAM_ERROR;
442 if (dn) {
443 dnU = strWtoU( dn );
444 if (!dnU) goto exit;
446 if (attrs) {
447 attrsU = modarrayWtoU( attrs );
448 if (!attrsU) goto exit;
451 ret = map_error( ldap_add_ext_s( ld, dn ? dnU : "", attrs ? attrsU : nullattrs, NULL, NULL ));
453 exit:
454 strfreeU( dnU );
455 modarrayfreeU( attrsU );
457 #endif
458 return ret;