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"
35 #define LDAP_NOT_SUPPORTED 0x5c
38 #include "winldap_private.h"
41 WINE_DEFAULT_DEBUG_CHANNEL(wldap32
);
43 ULONG
ldap_compareA( WLDAP32_LDAP
*ld
, PCHAR dn
, PCHAR attr
, PCHAR value
)
45 ULONG ret
= LDAP_NOT_SUPPORTED
;
47 WCHAR
*dnW
= NULL
, *attrW
= NULL
, *valueW
= NULL
;
49 ret
= WLDAP32_LDAP_NO_MEMORY
;
51 TRACE( "(%p, %s, %s, %s)\n", ld
, debugstr_a(dn
), debugstr_a(attr
),
61 attrW
= strAtoW( attr
);
62 if (!attrW
) goto exit
;
65 valueW
= strAtoW( value
);
66 if (!valueW
) goto exit
;
69 ret
= ldap_compareW( ld
, dnW
, attrW
, valueW
);
80 ULONG
ldap_compareW( WLDAP32_LDAP
*ld
, PWCHAR dn
, PWCHAR attr
, PWCHAR value
)
82 ULONG ret
= LDAP_NOT_SUPPORTED
;
84 char *dnU
= NULL
, *attrU
= NULL
, *valueU
= NULL
;
86 ret
= WLDAP32_LDAP_NO_MEMORY
;
88 TRACE( "(%p, %s, %s, %s)\n", ld
, debugstr_w(dn
), debugstr_w(attr
),
91 if (!ld
) return WLDAP32_LDAP_PARAM_ERROR
;
92 if (!attr
) return ~0UL;
99 attrU
= strWtoU( attr
);
100 if (!attrU
) goto exit
;
103 valueU
= strWtoU( value
);
104 if (!valueU
) goto exit
;
107 ret
= ldap_compare( ld
, dn
? dnU
: "", attrU
, value
? valueU
: "" );
118 ULONG
ldap_compare_extA( WLDAP32_LDAP
*ld
, PCHAR dn
, PCHAR attr
, PCHAR value
,
119 struct WLDAP32_berval
*data
, PLDAPControlA
*serverctrls
, PLDAPControlA
*clientctrls
,
122 ULONG ret
= LDAP_NOT_SUPPORTED
;
124 WCHAR
*dnW
= NULL
, *attrW
= NULL
, *valueW
= NULL
;
125 LDAPControlW
**serverctrlsW
= NULL
, **clientctrlsW
= NULL
;
127 ret
= WLDAP32_LDAP_NO_MEMORY
;
129 TRACE( "(%p, %s, %s, %s, %p, %p, %p, %p)\n", ld
, debugstr_a(dn
),
130 debugstr_a(attr
), debugstr_a(value
), data
, serverctrls
,
131 clientctrls
, message
);
133 if (!ld
|| !message
) return WLDAP32_LDAP_PARAM_ERROR
;
140 attrW
= strAtoW( attr
);
141 if (!attrW
) goto exit
;
144 valueW
= strAtoW( value
);
145 if (!valueW
) goto exit
;
148 serverctrlsW
= controlarrayAtoW( serverctrls
);
149 if (!serverctrlsW
) goto exit
;
152 clientctrlsW
= controlarrayAtoW( clientctrls
);
153 if (!clientctrlsW
) goto exit
;
156 ret
= ldap_compare_extW( ld
, dnW
, attrW
, valueW
, data
,
157 serverctrlsW
, clientctrlsW
, message
);
163 controlarrayfreeW( serverctrlsW
);
164 controlarrayfreeW( clientctrlsW
);
170 ULONG
ldap_compare_extW( WLDAP32_LDAP
*ld
, PWCHAR dn
, PWCHAR attr
, PWCHAR value
,
171 struct WLDAP32_berval
*data
, PLDAPControlW
*serverctrls
, PLDAPControlW
*clientctrls
,
174 ULONG ret
= LDAP_NOT_SUPPORTED
;
176 char *dnU
= NULL
, *attrU
= NULL
, *valueU
= NULL
;
177 LDAPControl
**serverctrlsU
= NULL
, **clientctrlsU
= NULL
;
178 struct berval berval
;
180 ret
= WLDAP32_LDAP_NO_MEMORY
;
182 TRACE( "(%p, %s, %s, %s, %p, %p, %p, %p)\n", ld
, debugstr_w(dn
),
183 debugstr_w(attr
), debugstr_w(value
), data
, serverctrls
,
184 clientctrls
, message
);
186 if (!ld
|| !message
) return WLDAP32_LDAP_PARAM_ERROR
;
187 if (!attr
) return WLDAP32_LDAP_NO_MEMORY
;
194 attrU
= strWtoU( attr
);
195 if (!attrU
) goto exit
;
199 valueU
= strWtoU( value
);
200 if (!valueU
) goto exit
;
202 berval
.bv_len
= valueU
? strlen( valueU
) : 0;
203 berval
.bv_val
= valueU
;
206 serverctrlsU
= controlarrayWtoU( serverctrls
);
207 if (!serverctrlsU
) goto exit
;
210 clientctrlsU
= controlarrayWtoU( clientctrls
);
211 if (!clientctrlsU
) goto exit
;
214 ret
= ldap_compare_ext( ld
, dn
? dnU
: "", attrU
, data
? (struct berval
*)data
: &berval
,
215 serverctrlsU
, clientctrlsU
, (int *)message
);
221 controlarrayfreeU( serverctrlsU
);
222 controlarrayfreeU( clientctrlsU
);
228 ULONG
ldap_compare_ext_sA( WLDAP32_LDAP
*ld
, PCHAR dn
, PCHAR attr
, PCHAR value
,
229 struct WLDAP32_berval
*data
, PLDAPControlA
*serverctrls
, PLDAPControlA
*clientctrls
)
231 ULONG ret
= LDAP_NOT_SUPPORTED
;
233 WCHAR
*dnW
= NULL
, *attrW
= NULL
, *valueW
= NULL
;
234 LDAPControlW
**serverctrlsW
= NULL
, **clientctrlsW
= NULL
;
236 ret
= WLDAP32_LDAP_NO_MEMORY
;
238 TRACE( "(%p, %s, %s, %s, %p, %p, %p)\n", ld
, debugstr_a(dn
),
239 debugstr_a(attr
), debugstr_a(value
), data
, serverctrls
,
242 if (!ld
) return WLDAP32_LDAP_PARAM_ERROR
;
249 attrW
= strAtoW( attr
);
250 if (!attrW
) goto exit
;
253 valueW
= strAtoW( value
);
254 if (!valueW
) goto exit
;
257 serverctrlsW
= controlarrayAtoW( serverctrls
);
258 if (!serverctrlsW
) goto exit
;
261 clientctrlsW
= controlarrayAtoW( clientctrls
);
262 if (!clientctrlsW
) goto exit
;
265 ret
= ldap_compare_ext_sW( ld
, dnW
, attrW
, valueW
, data
, serverctrlsW
,
272 controlarrayfreeW( serverctrlsW
);
273 controlarrayfreeW( clientctrlsW
);
279 ULONG
ldap_compare_ext_sW( WLDAP32_LDAP
*ld
, PWCHAR dn
, PWCHAR attr
, PWCHAR value
,
280 struct WLDAP32_berval
*data
, PLDAPControlW
*serverctrls
, PLDAPControlW
*clientctrls
)
282 ULONG ret
= LDAP_NOT_SUPPORTED
;
284 struct berval berval
;
285 char *dnU
= NULL
, *attrU
= NULL
, *valueU
= NULL
;
286 LDAPControl
**serverctrlsU
= NULL
, **clientctrlsU
= NULL
;
288 ret
= WLDAP32_LDAP_NO_MEMORY
;
290 TRACE( "(%p, %s, %s, %s, %p, %p, %p)\n", ld
, debugstr_w(dn
),
291 debugstr_w(attr
), debugstr_w(value
), data
, serverctrls
,
294 if (!ld
) return WLDAP32_LDAP_PARAM_ERROR
;
301 attrU
= strWtoU( attr
);
302 if (!attrU
) goto exit
;
306 valueU
= strWtoU( value
);
307 if (!valueU
) goto exit
;
309 berval
.bv_len
= valueU
? strlen( valueU
) : 0;
310 berval
.bv_val
= valueU
;
313 serverctrlsU
= controlarrayWtoU( serverctrls
);
314 if (!serverctrlsU
) goto exit
;
317 clientctrlsU
= controlarrayWtoU( clientctrls
);
318 if (!clientctrlsU
) goto exit
;
321 ret
= ldap_compare_ext_s( ld
, dn
? dnU
: "", attr
? attrU
: "", data
? (struct berval
*)data
: &berval
,
322 serverctrlsU
, clientctrlsU
);
328 controlarrayfreeU( serverctrlsU
);
329 controlarrayfreeU( clientctrlsU
);
335 ULONG
ldap_compare_sA( WLDAP32_LDAP
*ld
, PCHAR dn
, PCHAR attr
, PCHAR value
)
337 ULONG ret
= LDAP_NOT_SUPPORTED
;
339 WCHAR
*dnW
= NULL
, *attrW
= NULL
, *valueW
= NULL
;
341 ret
= WLDAP32_LDAP_NO_MEMORY
;
343 TRACE( "(%p, %s, %s, %s)\n", ld
, debugstr_a(dn
), debugstr_a(attr
),
346 if (!ld
) return WLDAP32_LDAP_PARAM_ERROR
;
353 attrW
= strAtoW( attr
);
354 if (!attrW
) goto exit
;
357 valueW
= strAtoW( value
);
358 if (!valueW
) goto exit
;
361 ret
= ldap_compare_sW( ld
, dnW
, attrW
, valueW
);
372 ULONG
ldap_compare_sW( WLDAP32_LDAP
*ld
, PWCHAR dn
, PWCHAR attr
, PWCHAR value
)
374 ULONG ret
= LDAP_NOT_SUPPORTED
;
376 char *dnU
= NULL
, *attrU
= NULL
, *valueU
= NULL
;
378 ret
= WLDAP32_LDAP_NO_MEMORY
;
380 TRACE( "(%p, %s, %s, %s)\n", ld
, debugstr_w(dn
), debugstr_w(attr
),
383 if (!ld
) return WLDAP32_LDAP_PARAM_ERROR
;
390 attrU
= strWtoU( attr
);
391 if (!attrU
) goto exit
;
394 valueU
= strWtoU( value
);
395 if (!valueU
) goto exit
;
398 ret
= ldap_compare_s( ld
, dn
? dnU
: "", attr
? attrU
: "", value
? valueU
: "" );