push b79aff4f9e064e6702329573e5ebb8548e254b61
[wine/hacks.git] / dlls / wldap32 / parse.c
blobe47adf2e84943a4e6945992f8bb7eb5cfc712019
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 #else
35 #define LDAP_NOT_SUPPORTED 0x5c
36 #endif
38 #include "winldap_private.h"
39 #include "wldap32.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;
52 #ifdef HAVE_LDAP
53 WCHAR *oidW = NULL;
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 );
62 if (oid) {
63 *oid = strWtoA( oidW );
64 if (!*oid) ret = WLDAP32_LDAP_NO_MEMORY;
65 ldap_memfreeW( oidW );
68 #endif
69 return ret;
72 /***********************************************************************
73 * ldap_parse_extended_resultW (WLDAP32.@)
75 * Parse the result of an extended operation.
77 * PARAMS
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?
84 * RETURNS
85 * Success: LDAP_SUCCESS
86 * Failure: An LDAP error code.
88 * NOTES
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;
96 #ifdef HAVE_LDAP
97 char *oidU = NULL;
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 );
106 if (oid) {
107 *oid = strUtoW( oidU );
108 if (!*oid) ret = WLDAP32_LDAP_NO_MEMORY;
109 ldap_memfree( oidU );
112 #endif
113 return ret;
116 /***********************************************************************
117 * ldap_parse_referenceA (WLDAP32.@)
119 * See ldap_parse_referenceW.
121 ULONG CDECL ldap_parse_referenceA( WLDAP32_LDAP *ld, WLDAP32_LDAPMessage *message,
122 PCHAR **referrals )
124 ULONG ret = LDAP_NOT_SUPPORTED;
125 #ifdef HAVE_LDAP
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 );
137 #endif
138 return ret;
141 /***********************************************************************
142 * ldap_parse_referenceW (WLDAP32.@)
144 * Return any referrals from a result message.
146 * PARAMS
147 * ld [I] Pointer to an LDAP context.
148 * result [I] Result message.
149 * referrals [O] Array of referral URLs.
151 * RETURNS
152 * Success: LDAP_SUCCESS
153 * Failure: An LDAP error code.
155 * NOTES
156 * Free the referrals with ldap_value_free.
158 ULONG CDECL ldap_parse_referenceW( WLDAP32_LDAP *ld, WLDAP32_LDAPMessage *message,
159 PWCHAR **referrals )
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 );
174 #endif
175 return ret;
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;
188 #ifdef HAVE_LDAP
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 );
211 #endif
212 return ret;
215 /***********************************************************************
216 * ldap_parse_resultW (WLDAP32.@)
218 * Parse a result message.
220 * PARAMS
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?
230 * RETURNS
231 * Success: LDAP_SUCCESS
232 * Failure: An LDAP error code.
234 * NOTES
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;
245 #ifdef HAVE_LDAP
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 );
268 #endif
269 return ret;
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;
281 #ifdef HAVE_LDAP
282 WCHAR *attrW = NULL;
283 LDAPControlW **controlW = NULL;
285 TRACE( "(%p, %p, %p, %p)\n", ld, control, result, attr );
287 if (!ld) return ~0UL;
289 if (control) {
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 );
299 #endif
300 return ret;
303 /***********************************************************************
304 * ldap_parse_sort_controlW (WLDAP32.@)
306 * Parse a sort control.
308 * PARAMS
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.
314 * RETURNS
315 * Success: LDAP_SUCCESS
316 * Failure: An LDAP error code.
318 * NOTES
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;
325 #ifdef HAVE_LDAP
326 char *attrU = NULL;
327 LDAPControl **controlU = NULL;
328 unsigned long res;
330 TRACE( "(%p, %p, %p, %p)\n", ld, control, result, attr );
332 if (!ld) return ~0UL;
334 if (control) {
335 controlU = controlarrayWtoU( control );
336 if (!controlU) return WLDAP32_LDAP_NO_MEMORY;
339 ret = ldap_parse_sort_control( ld, controlU, &res, &attrU );
341 *result = res;
342 *attr = strUtoW( attrU );
343 controlarrayfreeU( controlU );
345 #endif
346 return ret;
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;
359 #ifdef HAVE_LDAP
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;
367 if (control) {
368 controlW = controlarrayAtoW( control );
369 if (!controlW) return WLDAP32_LDAP_NO_MEMORY;
372 ret = ldap_parse_vlv_controlW( ld, controlW, targetpos, listcount,
373 context, errcode );
375 controlarrayfreeW( controlW );
377 #endif
378 return ret;
381 /***********************************************************************
382 * ldap_parse_vlv_controlW (WLDAP32.@)
384 * Parse a virtual list view control.
386 * PARAMS
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.
394 * RETURNS
395 * Success: LDAP_SUCCESS
396 * Failure: An LDAP error code.
398 * NOTES
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;
406 #ifdef HAVE_LDAP
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;
415 if (control) {
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 );
423 *targetpos = pos;
424 *listcount = count;
425 controlarrayfreeU( controlU );
427 #endif
428 return ret;