Test for return value from CreateDirectory("c:").
[wine/dcerpc.git] / dlls / wldap32 / add.c
blobb111c3842a7427ebde3eadcbc1bc206abd907110
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 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 static LDAPMod *nullattrs[] = { NULL };
35 #else
36 #define LDAP_NOT_SUPPORTED 0x5c
37 #endif
39 #include "winldap_private.h"
40 #include "wldap32.h"
42 WINE_DEFAULT_DEBUG_CHANNEL(wldap32);
44 ULONG ldap_addA( WLDAP32_LDAP *ld, PCHAR dn, LDAPModA *attrs[] )
46 ULONG ret = LDAP_NOT_SUPPORTED;
47 #ifdef HAVE_LDAP
48 WCHAR *dnW = NULL;
49 LDAPModW **attrsW = NULL;
51 ret = WLDAP32_LDAP_NO_MEMORY;
53 TRACE( "(%p, %s, %p)\n", ld, debugstr_a(dn), attrs );
55 if (!ld) return ~0UL;
57 if (dn) {
58 dnW = strAtoW( dn );
59 if (!dnW) goto exit;
61 if (attrs) {
62 attrsW = modarrayAtoW( attrs );
63 if (!attrsW) goto exit;
66 ret = ldap_addW( ld, dnW, attrsW );
68 exit:
69 strfreeW( dnW );
70 modarrayfreeW( attrsW );
72 #endif
73 return ret;
76 ULONG ldap_addW( WLDAP32_LDAP *ld, PWCHAR dn, LDAPModW *attrs[] )
78 ULONG ret = LDAP_NOT_SUPPORTED;
79 #ifdef HAVE_LDAP
80 char *dnU = NULL;
81 LDAPMod **attrsU = NULL;
83 ret = WLDAP32_LDAP_NO_MEMORY;
85 TRACE( "(%p, %s, %p)\n", ld, debugstr_w(dn), attrs );
87 if (!ld) return WLDAP32_LDAP_PARAM_ERROR;
89 if (dn) {
90 dnU = strWtoU( dn );
91 if (!dnU) goto exit;
93 if (attrs) {
94 attrsU = modarrayWtoU( attrs );
95 if (!attrsU) goto exit;
98 ret = ldap_add( ld, dn ? dnU : "", attrs ? attrsU : nullattrs );
100 exit:
101 strfreeU( dnU );
102 modarrayfreeU( attrsU );
104 #endif
105 return ret;
108 ULONG ldap_add_extA( WLDAP32_LDAP *ld, PCHAR dn, LDAPModA *attrs[],
109 PLDAPControlA *serverctrls, PLDAPControlA *clientctrls, ULONG *message )
111 ULONG ret = LDAP_NOT_SUPPORTED;
112 #ifdef HAVE_LDAP
113 WCHAR *dnW = NULL;
114 LDAPModW **attrsW = NULL;
115 LDAPControlW **serverctrlsW = NULL, **clientctrlsW = NULL;
117 ret = WLDAP32_LDAP_NO_MEMORY;
119 TRACE( "(%p, %s, %p, %p, %p, %p)\n", ld, debugstr_a(dn), attrs,
120 serverctrls, clientctrls, message );
122 if (!ld) return ~0UL;
124 if (dn) {
125 dnW = strAtoW( dn );
126 if (!dnW) goto exit;
128 if (attrs) {
129 attrsW = modarrayAtoW( attrs );
130 if (!attrsW) goto exit;
132 if (serverctrls) {
133 serverctrlsW = controlarrayAtoW( serverctrls );
134 if (!serverctrlsW) goto exit;
136 if (clientctrls) {
137 clientctrlsW = controlarrayAtoW( clientctrls );
138 if (!clientctrlsW) goto exit;
141 ret = ldap_add_extW( ld, dnW, attrsW, serverctrlsW, clientctrlsW, message );
143 exit:
144 strfreeW( dnW );
145 modarrayfreeW( attrsW );
146 controlarrayfreeW( serverctrlsW );
147 controlarrayfreeW( clientctrlsW );
149 #endif
150 return ret;
153 ULONG ldap_add_extW( WLDAP32_LDAP *ld, PWCHAR dn, LDAPModW *attrs[],
154 PLDAPControlW *serverctrls, PLDAPControlW *clientctrls, ULONG *message )
156 ULONG ret = LDAP_NOT_SUPPORTED;
157 #ifdef HAVE_LDAP
158 char *dnU = NULL;
159 LDAPMod **attrsU = NULL;
160 LDAPControl **serverctrlsU = NULL, **clientctrlsU = NULL;
161 int dummy;
163 ret = WLDAP32_LDAP_NO_MEMORY;
165 TRACE( "(%p, %s, %p, %p, %p, %p)\n", ld, debugstr_w(dn), attrs,
166 serverctrls, clientctrls, message );
168 if (!ld) return ~0UL;
169 if (!attrs) return LDAP_PROTOCOL_ERROR;
171 if (dn) {
172 dnU = strWtoU( dn );
173 if (!dnU) goto exit;
175 if (attrs) {
176 attrsU = modarrayWtoU( attrs );
177 if (!attrsU) goto exit;
179 if (serverctrls) {
180 serverctrlsU = controlarrayWtoU( serverctrls );
181 if (!serverctrlsU) goto exit;
183 if (clientctrls) {
184 clientctrlsU = controlarrayWtoU( clientctrls );
185 if (!clientctrlsU) goto exit;
188 ret = ldap_add_ext( ld, dn ? dnU : "", attrs? attrsU : nullattrs, serverctrlsU,
189 clientctrlsU, message ? (int *)message : &dummy );
191 exit:
192 strfreeU( dnU );
193 modarrayfreeU( attrsU );
194 controlarrayfreeU( serverctrlsU );
195 controlarrayfreeU( clientctrlsU );
197 #endif
198 return ret;
201 ULONG ldap_add_ext_sA( WLDAP32_LDAP *ld, PCHAR dn, LDAPModA *attrs[],
202 PLDAPControlA *serverctrls, PLDAPControlA *clientctrls )
204 ULONG ret = LDAP_NOT_SUPPORTED;
205 #ifdef HAVE_LDAP
206 WCHAR *dnW = NULL;
207 LDAPModW **attrsW = NULL;
208 LDAPControlW **serverctrlsW = NULL, **clientctrlsW = NULL;
210 ret = WLDAP32_LDAP_NO_MEMORY;
212 TRACE( "(%p, %s, %p, %p, %p)\n", ld, debugstr_a(dn), attrs,
213 serverctrls, clientctrls );
215 if (!ld) return WLDAP32_LDAP_PARAM_ERROR;
217 if (dn) {
218 dnW = strAtoW( dn );
219 if (!dnW) goto exit;
221 if (attrs) {
222 attrsW = modarrayAtoW( attrs );
223 if (!attrsW) goto exit;
225 if (serverctrls) {
226 serverctrlsW = controlarrayAtoW( serverctrls );
227 if (!serverctrlsW) goto exit;
229 if (clientctrls) {
230 clientctrlsW = controlarrayAtoW( clientctrls );
231 if (!clientctrlsW) goto exit;
234 ret = ldap_add_ext_sW( ld, dnW, attrsW, serverctrlsW, clientctrlsW );
236 exit:
237 strfreeW( dnW );
238 modarrayfreeW( attrsW );
239 controlarrayfreeW( serverctrlsW );
240 controlarrayfreeW( clientctrlsW );
242 #endif
243 return ret;
246 ULONG ldap_add_ext_sW( WLDAP32_LDAP *ld, PWCHAR dn, LDAPModW *attrs[],
247 PLDAPControlW *serverctrls, PLDAPControlW *clientctrls )
249 ULONG ret = LDAP_NOT_SUPPORTED;
250 #ifdef HAVE_LDAP
251 char *dnU = NULL;
252 LDAPMod **attrsU = NULL;
253 LDAPControl **serverctrlsU = NULL, **clientctrlsU = NULL;
255 ret = WLDAP32_LDAP_NO_MEMORY;
257 TRACE( "(%p, %s, %p, %p, %p)\n", ld, debugstr_w(dn), attrs,
258 serverctrls, clientctrls );
260 if (!ld) return WLDAP32_LDAP_PARAM_ERROR;
261 if (!attrs) return LDAP_PROTOCOL_ERROR;
263 if (dn) {
264 dnU = strWtoU( dn );
265 if (!dnU) goto exit;
267 if (attrs) {
268 attrsU = modarrayWtoU( attrs );
269 if (!attrsU) goto exit;
271 if (serverctrls) {
272 serverctrlsU = controlarrayWtoU( serverctrls );
273 if (!serverctrlsU) goto exit;
275 if (clientctrls) {
276 clientctrlsU = controlarrayWtoU( clientctrls );
277 if (!clientctrlsU) goto exit;
280 ret = ldap_add_ext_s( ld, dn ? dnU : "", attrs ? attrsU : nullattrs,
281 serverctrlsU, clientctrlsU );
283 exit:
284 strfreeU( dnU );
285 modarrayfreeU( attrsU );
286 controlarrayfreeU( serverctrlsU );
287 controlarrayfreeU( clientctrlsU );
289 #endif
290 return ret;
293 ULONG ldap_add_sA( WLDAP32_LDAP *ld, PCHAR dn, LDAPModA *attrs[] )
295 ULONG ret = LDAP_NOT_SUPPORTED;
296 #ifdef HAVE_LDAP
297 WCHAR *dnW = NULL;
298 LDAPModW **attrsW = NULL;
300 ret = WLDAP32_LDAP_NO_MEMORY;
302 TRACE( "(%p, %s, %p)\n", ld, debugstr_a(dn), attrs );
304 if (!ld) return WLDAP32_LDAP_PARAM_ERROR;
306 if (dn) {
307 dnW = strAtoW( dn );
308 if (!dnW) goto exit;
310 if (attrs) {
311 attrsW = modarrayAtoW( attrs );
312 if (!attrsW) goto exit;
315 ret = ldap_add_sW( ld, dnW, attrsW );
317 exit:
318 strfreeW( dnW );
319 modarrayfreeW( attrsW );
321 #endif
322 return ret;
325 ULONG ldap_add_sW( WLDAP32_LDAP *ld, PWCHAR dn, LDAPModW *attrs[] )
327 ULONG ret = LDAP_NOT_SUPPORTED;
328 #ifdef HAVE_LDAP
329 char *dnU = NULL;
330 LDAPMod **attrsU = NULL;
332 ret = WLDAP32_LDAP_NO_MEMORY;
334 TRACE( "(%p, %s, %p)\n", ld, debugstr_w(dn), attrs );
336 if (!ld) return WLDAP32_LDAP_PARAM_ERROR;
338 if (dn) {
339 dnU = strWtoU( dn );
340 if (!dnU) goto exit;
342 if (attrs) {
343 attrsU = modarrayWtoU( attrs );
344 if (!attrsU) goto exit;
347 ret = ldap_add_s( ld, dn ? dnU : "", attrs ? attrsU : nullattrs );
349 exit:
350 strfreeU( dnU );
351 modarrayfreeU( attrsU );
353 #endif
354 return ret;