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
23 #include "wine/port.h"
24 #include "wine/debug.h"
34 static LDAPMod *nullattrs[] = { NULL };
36 #define LDAP_NOT_SUPPORTED 0x5c
39 #include "winldap_private.h"
42 WINE_DEFAULT_DEBUG_CHANNEL(wldap32);
44 ULONG ldap_addA( WLDAP32_LDAP *ld, PCHAR dn, LDAPModA *attrs[] )
46 ULONG ret = LDAP_NOT_SUPPORTED;
49 LDAPModW **attrsW = NULL;
51 ret = WLDAP32_LDAP_NO_MEMORY;
53 TRACE( "(%p, %s, %p)\n", ld, debugstr_a(dn), attrs );
62 attrsW = modarrayAtoW( attrs );
63 if (!attrsW) goto exit;
66 ret = ldap_addW( ld, dnW, attrsW );
70 modarrayfreeW( attrsW );
76 ULONG ldap_addW( WLDAP32_LDAP *ld, PWCHAR dn, LDAPModW *attrs[] )
78 ULONG ret = LDAP_NOT_SUPPORTED;
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;
94 attrsU = modarrayWtoU( attrs );
95 if (!attrsU) goto exit;
98 ret = ldap_add( ld, dn ? dnU : "", attrs ? attrsU : nullattrs );
102 modarrayfreeU( attrsU );
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;
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;
129 attrsW = modarrayAtoW( attrs );
130 if (!attrsW) goto exit;
133 serverctrlsW = controlarrayAtoW( serverctrls );
134 if (!serverctrlsW) goto exit;
137 clientctrlsW = controlarrayAtoW( clientctrls );
138 if (!clientctrlsW) goto exit;
141 ret = ldap_add_extW( ld, dnW, attrsW, serverctrlsW, clientctrlsW, message );
145 modarrayfreeW( attrsW );
146 controlarrayfreeW( serverctrlsW );
147 controlarrayfreeW( clientctrlsW );
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;
159 LDAPMod **attrsU = NULL;
160 LDAPControl **serverctrlsU = NULL, **clientctrlsU = NULL;
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;
176 attrsU = modarrayWtoU( attrs );
177 if (!attrsU) goto exit;
180 serverctrlsU = controlarrayWtoU( serverctrls );
181 if (!serverctrlsU) goto exit;
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 );
193 modarrayfreeU( attrsU );
194 controlarrayfreeU( serverctrlsU );
195 controlarrayfreeU( clientctrlsU );
201 ULONG ldap_add_ext_sA( WLDAP32_LDAP *ld, PCHAR dn, LDAPModA *attrs[],
202 PLDAPControlA *serverctrls, PLDAPControlA *clientctrls )
204 ULONG ret = LDAP_NOT_SUPPORTED;
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;
222 attrsW = modarrayAtoW( attrs );
223 if (!attrsW) goto exit;
226 serverctrlsW = controlarrayAtoW( serverctrls );
227 if (!serverctrlsW) goto exit;
230 clientctrlsW = controlarrayAtoW( clientctrls );
231 if (!clientctrlsW) goto exit;
234 ret = ldap_add_ext_sW( ld, dnW, attrsW, serverctrlsW, clientctrlsW );
238 modarrayfreeW( attrsW );
239 controlarrayfreeW( serverctrlsW );
240 controlarrayfreeW( clientctrlsW );
246 ULONG ldap_add_ext_sW( WLDAP32_LDAP *ld, PWCHAR dn, LDAPModW *attrs[],
247 PLDAPControlW *serverctrls, PLDAPControlW *clientctrls )
249 ULONG ret = LDAP_NOT_SUPPORTED;
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;
268 attrsU = modarrayWtoU( attrs );
269 if (!attrsU) goto exit;
272 serverctrlsU = controlarrayWtoU( serverctrls );
273 if (!serverctrlsU) goto exit;
276 clientctrlsU = controlarrayWtoU( clientctrls );
277 if (!clientctrlsU) goto exit;
280 ret = ldap_add_ext_s( ld, dn ? dnU : "", attrs ? attrsU : nullattrs,
281 serverctrlsU, clientctrlsU );
285 modarrayfreeU( attrsU );
286 controlarrayfreeU( serverctrlsU );
287 controlarrayfreeU( clientctrlsU );
293 ULONG ldap_add_sA( WLDAP32_LDAP *ld, PCHAR dn, LDAPModA *attrs[] )
295 ULONG ret = LDAP_NOT_SUPPORTED;
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;
311 attrsW = modarrayAtoW( attrs );
312 if (!attrsW) goto exit;
315 ret = ldap_add_sW( ld, dnW, attrsW );
319 modarrayfreeW( attrsW );
325 ULONG ldap_add_sW( WLDAP32_LDAP *ld, PWCHAR dn, LDAPModW *attrs[] )
327 ULONG ret = LDAP_NOT_SUPPORTED;
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;
343 attrsU = modarrayWtoU( attrs );
344 if (!attrsU) goto exit;
347 ret = ldap_add_s( ld, dn ? dnU : "", attrs ? attrsU : nullattrs );
351 modarrayfreeU( attrsU );