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
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 /***********************************************************************
44 * ldap_parse_extended_resultA (WLDAP32.@)
46 * See ldap_parse_extended_resultW.
48 ULONG CDECL
ldap_parse_extended_resultA( WLDAP32_LDAP
*ld
, WLDAP32_LDAPMessage
*result
,
49 PCHAR
*oid
, struct WLDAP32_berval
**data
, BOOLEAN free
)
51 ULONG ret
= LDAP_NOT_SUPPORTED
;
55 TRACE( "(%p, %p, %p, %p, 0x%02x)\n", ld
, result
, oid
, data
, free
);
57 if (!ld
) return WLDAP32_LDAP_PARAM_ERROR
;
58 if (!result
) return WLDAP32_LDAP_NO_RESULTS_RETURNED
;
60 ret
= ldap_parse_extended_resultW( ld
, result
, &oidW
, data
, free
);
63 *oid
= strWtoA( oidW
);
64 if (!*oid
) ret
= WLDAP32_LDAP_NO_MEMORY
;
65 ldap_memfreeW( oidW
);
72 /***********************************************************************
73 * ldap_parse_extended_resultW (WLDAP32.@)
75 * Parse the result of an extended operation.
78 * ld [I] Pointer to an LDAP context.
79 * result [I] Result message from an extended operation.
80 * oid [O] OID of the extended operation.
81 * data [O] Result data.
82 * free [I] Free the result message?
85 * Success: LDAP_SUCCESS
86 * Failure: An LDAP error code.
89 * Free the OID and result data with ldap_memfree. Pass a nonzero
90 * value for 'free' or call ldap_msgfree to free the result message.
92 ULONG CDECL
ldap_parse_extended_resultW( WLDAP32_LDAP
*ld
, WLDAP32_LDAPMessage
*result
,
93 PWCHAR
*oid
, struct WLDAP32_berval
**data
, BOOLEAN free
)
95 ULONG ret
= LDAP_NOT_SUPPORTED
;
99 TRACE( "(%p, %p, %p, %p, 0x%02x)\n", ld
, result
, oid
, data
, free
);
101 if (!ld
) return WLDAP32_LDAP_PARAM_ERROR
;
102 if (!result
) return WLDAP32_LDAP_NO_RESULTS_RETURNED
;
104 ret
= ldap_parse_extended_result( ld
, result
, &oidU
, (struct berval
**)data
, free
);
107 *oid
= strUtoW( oidU
);
108 if (!*oid
) ret
= WLDAP32_LDAP_NO_MEMORY
;
109 ldap_memfree( oidU
);
116 /***********************************************************************
117 * ldap_parse_referenceA (WLDAP32.@)
119 * See ldap_parse_referenceW.
121 ULONG CDECL
ldap_parse_referenceA( WLDAP32_LDAP
*ld
, WLDAP32_LDAPMessage
*message
,
124 ULONG ret
= LDAP_NOT_SUPPORTED
;
126 WCHAR
**referralsW
= NULL
;
128 TRACE( "(%p, %p, %p)\n", ld
, message
, referrals
);
130 if (!ld
) return ~0UL;
132 ret
= ldap_parse_referenceW( ld
, message
, &referralsW
);
134 *referrals
= strarrayWtoA( referralsW
);
135 ldap_value_freeW( referralsW
);
141 /***********************************************************************
142 * ldap_parse_referenceW (WLDAP32.@)
144 * Return any referrals from a result message.
147 * ld [I] Pointer to an LDAP context.
148 * result [I] Result message.
149 * referrals [O] Array of referral URLs.
152 * Success: LDAP_SUCCESS
153 * Failure: An LDAP error code.
156 * Free the referrals with ldap_value_free.
158 ULONG CDECL
ldap_parse_referenceW( WLDAP32_LDAP
*ld
, WLDAP32_LDAPMessage
*message
,
161 ULONG ret
= LDAP_NOT_SUPPORTED
;
162 #ifdef HAVE_LDAP_PARSE_REFERENCE
163 char **referralsU
= NULL
;
165 TRACE( "(%p, %p, %p)\n", ld
, message
, referrals
);
167 if (!ld
) return ~0UL;
169 ret
= ldap_parse_reference( ld
, message
, &referralsU
, NULL
, 0 );
171 *referrals
= strarrayUtoW( referralsU
);
172 ldap_memfree( referralsU
);
178 /***********************************************************************
179 * ldap_parse_resultA (WLDAP32.@)
181 * See ldap_parse_resultW.
183 ULONG CDECL
ldap_parse_resultA( WLDAP32_LDAP
*ld
, WLDAP32_LDAPMessage
*result
,
184 ULONG
*retcode
, PCHAR
*matched
, PCHAR
*error
, PCHAR
**referrals
,
185 PLDAPControlA
**serverctrls
, BOOLEAN free
)
187 ULONG ret
= LDAP_NOT_SUPPORTED
;
189 WCHAR
**matchedW
= NULL
, **errorW
= NULL
, **referralsW
= NULL
;
190 LDAPControlW
**serverctrlsW
= NULL
;
192 TRACE( "(%p, %p, %p, %p, %p, %p, %p, 0x%02x)\n", ld
, result
, retcode
,
193 matched
, error
, referrals
, serverctrls
, free
);
195 if (!ld
) return ~0UL;
197 ret
= ldap_parse_resultW( ld
, result
, retcode
, matchedW
, errorW
,
198 &referralsW
, &serverctrlsW
, free
);
200 matched
= strarrayWtoA( matchedW
);
201 error
= strarrayWtoA( errorW
);
203 *referrals
= strarrayWtoA( referralsW
);
204 *serverctrls
= controlarrayWtoA( serverctrlsW
);
206 ldap_value_freeW( matchedW
);
207 ldap_value_freeW( errorW
);
208 ldap_value_freeW( referralsW
);
209 ldap_controls_freeW( serverctrlsW
);
215 /***********************************************************************
216 * ldap_parse_resultW (WLDAP32.@)
218 * Parse a result message.
221 * ld [I] Pointer to an LDAP context.
222 * result [I] Result message.
223 * retcode [O] Return code for the server operation.
224 * matched [O] DNs matched in the operation.
225 * error [O] Error message for the operation.
226 * referrals [O] Referrals found in the result message.
227 * serverctrls [O] Controls used in the operation.
228 * free [I] Free the result message?
231 * Success: LDAP_SUCCESS
232 * Failure: An LDAP error code.
235 * Free the DNs and error message with ldap_memfree. Free
236 * the referrals with ldap_value_free and the controls with
237 * ldap_controls_free. Pass a nonzero value for 'free' or call
238 * ldap_msgfree to free the result message.
240 ULONG CDECL
ldap_parse_resultW( WLDAP32_LDAP
*ld
, WLDAP32_LDAPMessage
*result
,
241 ULONG
*retcode
, PWCHAR
*matched
, PWCHAR
*error
, PWCHAR
**referrals
,
242 PLDAPControlW
**serverctrls
, BOOLEAN free
)
244 ULONG ret
= LDAP_NOT_SUPPORTED
;
246 char **matchedU
= NULL
, **errorU
= NULL
, **referralsU
= NULL
;
247 LDAPControl
**serverctrlsU
= NULL
;
249 TRACE( "(%p, %p, %p, %p, %p, %p, %p, 0x%02x)\n", ld
, result
, retcode
,
250 matched
, error
, referrals
, serverctrls
, free
);
252 if (!ld
) return ~0UL;
254 ret
= ldap_parse_result( ld
, result
, (int *)retcode
, matchedU
, errorU
,
255 &referralsU
, &serverctrlsU
, free
);
257 matched
= strarrayUtoW( matchedU
);
258 error
= strarrayUtoW( errorU
);
260 *referrals
= strarrayUtoW( referralsU
);
261 *serverctrls
= controlarrayUtoW( serverctrlsU
);
263 ldap_memfree( matchedU
);
264 ldap_memfree( errorU
);
265 ldap_memfree( referralsU
);
266 ldap_controls_free( serverctrlsU
);
272 /***********************************************************************
273 * ldap_parse_sort_controlA (WLDAP32.@)
275 * See ldap_parse_sort_controlW.
277 ULONG CDECL
ldap_parse_sort_controlA( WLDAP32_LDAP
*ld
, PLDAPControlA
*control
,
278 ULONG
*result
, PCHAR
*attr
)
280 ULONG ret
= LDAP_NOT_SUPPORTED
;
283 LDAPControlW
**controlW
= NULL
;
285 TRACE( "(%p, %p, %p, %p)\n", ld
, control
, result
, attr
);
287 if (!ld
) return ~0UL;
290 controlW
= controlarrayAtoW( control
);
291 if (!controlW
) return WLDAP32_LDAP_NO_MEMORY
;
294 ret
= ldap_parse_sort_controlW( ld
, controlW
, result
, &attrW
);
296 *attr
= strWtoA( attrW
);
297 controlarrayfreeW( controlW
);
303 /***********************************************************************
304 * ldap_parse_sort_controlW (WLDAP32.@)
306 * Parse a sort control.
309 * ld [I] Pointer to an LDAP context.
310 * control [I] Control obtained from a result message.
311 * result [O] Result code.
312 * attr [O] Failing attribute.
315 * Success: LDAP_SUCCESS
316 * Failure: An LDAP error code.
319 * If the function fails, free the failing attribute with ldap_memfree.
321 ULONG CDECL
ldap_parse_sort_controlW( WLDAP32_LDAP
*ld
, PLDAPControlW
*control
,
322 ULONG
*result
, PWCHAR
*attr
)
324 ULONG ret
= LDAP_NOT_SUPPORTED
;
327 LDAPControl
**controlU
= NULL
;
330 TRACE( "(%p, %p, %p, %p)\n", ld
, control
, result
, attr
);
332 if (!ld
) return ~0UL;
335 controlU
= controlarrayWtoU( control
);
336 if (!controlU
) return WLDAP32_LDAP_NO_MEMORY
;
339 ret
= ldap_parse_sort_control( ld
, controlU
, &res
, &attrU
);
342 *attr
= strUtoW( attrU
);
343 controlarrayfreeU( controlU
);
349 /***********************************************************************
350 * ldap_parse_vlv_controlA (WLDAP32.@)
352 * See ldap_parse_vlv_controlW.
354 INT CDECL
ldap_parse_vlv_controlA( WLDAP32_LDAP
*ld
, PLDAPControlA
*control
,
355 PULONG targetpos
, PULONG listcount
,
356 struct WLDAP32_berval
**context
, PINT errcode
)
358 int ret
= LDAP_NOT_SUPPORTED
;
360 LDAPControlW
**controlW
= NULL
;
362 TRACE( "(%p, %p, %p, %p, %p, %p)\n", ld
, control
, targetpos
,
363 listcount
, context
, errcode
);
365 if (!ld
) return ~0UL;
368 controlW
= controlarrayAtoW( control
);
369 if (!controlW
) return WLDAP32_LDAP_NO_MEMORY
;
372 ret
= ldap_parse_vlv_controlW( ld
, controlW
, targetpos
, listcount
,
375 controlarrayfreeW( controlW
);
381 /***********************************************************************
382 * ldap_parse_vlv_controlW (WLDAP32.@)
384 * Parse a virtual list view control.
387 * ld [I] Pointer to an LDAP context.
388 * control [I] Controls obtained from a result message.
389 * targetpos [O] Positition of the target in the result list.
390 * listcount [O] Estimate of the number of results in the list.
391 * context [O] Server side context.
392 * errcode [O] Error code from the listview operation.
395 * Success: LDAP_SUCCESS
396 * Failure: An LDAP error code.
399 * Free the server context with ber_bvfree.
401 INT CDECL
ldap_parse_vlv_controlW( WLDAP32_LDAP
*ld
, PLDAPControlW
*control
,
402 PULONG targetpos
, PULONG listcount
,
403 struct WLDAP32_berval
**context
, PINT errcode
)
405 int ret
= LDAP_NOT_SUPPORTED
;
407 LDAPControl
**controlU
= NULL
;
408 unsigned long pos
, count
;
410 TRACE( "(%p, %p, %p, %p, %p, %p)\n", ld
, control
, targetpos
,
411 listcount
, context
, errcode
);
413 if (!ld
) return ~0UL;
416 controlU
= controlarrayWtoU( control
);
417 if (!controlU
) return WLDAP32_LDAP_NO_MEMORY
;
420 ret
= ldap_parse_vlv_control( ld
, controlU
, &pos
, &count
,
421 (struct berval
**)context
, errcode
);
425 controlarrayfreeU( controlU
);