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
27 #include "wine/debug.h"
28 #include "winldap_private.h"
30 WINE_DEFAULT_DEBUG_CHANNEL(wldap32
);
32 /***********************************************************************
33 * ldap_parse_extended_resultA (WLDAP32.@)
35 * See ldap_parse_extended_resultW.
37 ULONG CDECL
ldap_parse_extended_resultA( LDAP
*ld
, LDAPMessage
*result
, char **oid
, struct berval
**data
,
43 TRACE( "(%p, %p, %p, %p, 0x%02x)\n", ld
, result
, oid
, data
, free
);
45 if (!ld
) return LDAP_PARAM_ERROR
;
46 if (!result
) return LDAP_NO_RESULTS_RETURNED
;
48 ret
= ldap_parse_extended_resultW( ld
, result
, &oidW
, data
, free
);
52 if ((str
= strWtoA( oidW
))) *oid
= str
;
53 else ret
= LDAP_NO_MEMORY
;
54 ldap_memfreeW( oidW
);
59 /***********************************************************************
60 * ldap_parse_extended_resultW (WLDAP32.@)
62 * Parse the result of an extended operation.
65 * ld [I] Pointer to an LDAP context.
66 * result [I] Result message from an extended operation.
67 * oid [O] OID of the extended operation.
68 * data [O] Result data.
69 * free [I] Free the result message?
72 * Success: LDAP_SUCCESS
73 * Failure: An LDAP error code.
76 * Free the OID and result data with ldap_memfree. Pass a nonzero
77 * value for 'free' or call ldap_msgfree to free the result message.
79 ULONG CDECL
ldap_parse_extended_resultW( LDAP
*ld
, LDAPMessage
*result
, WCHAR
**oid
, struct berval
**data
,
84 struct bervalU
*dataU
= NULL
;
86 TRACE( "(%p, %p, %p, %p, 0x%02x)\n", ld
, result
, oid
, data
, free
);
88 if (!ld
) return LDAP_PARAM_ERROR
;
89 if (!result
) return LDAP_NO_RESULTS_RETURNED
;
92 struct ldap_parse_extended_result_params params
= { CTX(ld
), result
, &oidU
, &dataU
, free
};
93 ret
= map_error( LDAP_CALL( ldap_parse_extended_result
, ¶ms
));
98 if ((str
= strUtoW( oidU
))) *oid
= str
;
99 else ret
= LDAP_NO_MEMORY
;
100 LDAP_CALL( ldap_memfree
, oidU
);
105 if ((bv
= bervalUtoW( dataU
))) *data
= bv
;
106 else ret
= LDAP_NO_MEMORY
;
107 LDAP_CALL( ber_bvfree
, dataU
);
113 /***********************************************************************
114 * ldap_parse_referenceA (WLDAP32.@)
116 * See ldap_parse_referenceW.
118 ULONG CDECL
ldap_parse_referenceA( LDAP
*ld
, LDAPMessage
*message
, char ***referrals
)
121 WCHAR
**referralsW
= NULL
;
123 TRACE( "(%p, %p, %p)\n", ld
, message
, referrals
);
127 ret
= ldap_parse_referenceW( ld
, message
, &referralsW
);
131 if ((ref
= strarrayWtoA( referralsW
))) *referrals
= ref
;
132 else ret
= LDAP_NO_MEMORY
;
133 ldap_value_freeW( referralsW
);
138 /***********************************************************************
139 * ldap_parse_referenceW (WLDAP32.@)
141 * Return any referrals from a result message.
144 * ld [I] Pointer to an LDAP context.
145 * result [I] Result message.
146 * referrals [O] Array of referral URLs.
149 * Success: LDAP_SUCCESS
150 * Failure: An LDAP error code.
153 * Free the referrals with ldap_value_free.
155 ULONG CDECL
ldap_parse_referenceW( LDAP
*ld
, LDAPMessage
*message
, WCHAR
***referrals
)
158 char **referralsU
= NULL
;
160 TRACE( "(%p, %p, %p)\n", ld
, message
, referrals
);
164 struct ldap_parse_reference_params params
= { CTX(ld
), message
, &referralsU
, NULL
, 0 };
165 ret
= map_error( LDAP_CALL( ldap_parse_reference
, ¶ms
));
170 if ((ref
= strarrayUtoW( referralsU
))) *referrals
= ref
;
171 else ret
= LDAP_NO_MEMORY
;
172 LDAP_CALL( ldap_memfree
, referralsU
);
177 /***********************************************************************
178 * ldap_parse_resultA (WLDAP32.@)
180 * See ldap_parse_resultW.
182 ULONG CDECL
ldap_parse_resultA( LDAP
*ld
, LDAPMessage
*result
, ULONG
*retcode
, char **matched
, char **error
,
183 char ***referrals
, LDAPControlA
***serverctrls
, BOOLEAN free
)
186 WCHAR
*matchedW
= NULL
, *errorW
= NULL
, **referralsW
= NULL
;
187 LDAPControlW
**serverctrlsW
= NULL
;
189 TRACE( "(%p, %p, %p, %p, %p, %p, %p, 0x%02x)\n", ld
, result
, retcode
, matched
, error
, referrals
, serverctrls
,
192 if (!ld
) return LDAP_PARAM_ERROR
;
194 ret
= ldap_parse_resultW( ld
, result
, retcode
, &matchedW
, &errorW
, &referralsW
, &serverctrlsW
, free
);
196 if (matched
) *matched
= strWtoA( matchedW
);
197 if (error
) *error
= strWtoA( errorW
);
198 if (referrals
) *referrals
= strarrayWtoA( referralsW
);
199 if (serverctrls
) *serverctrls
= controlarrayWtoA( serverctrlsW
);
201 ldap_memfreeW( matchedW
);
202 ldap_memfreeW( errorW
);
203 ldap_value_freeW( referralsW
);
204 ldap_controls_freeW( serverctrlsW
);
208 /***********************************************************************
209 * ldap_parse_resultW (WLDAP32.@)
211 * Parse a result message.
214 * ld [I] Pointer to an LDAP context.
215 * result [I] Result message.
216 * retcode [O] Return code for the server operation.
217 * matched [O] DNs matched in the operation.
218 * error [O] Error message for the operation.
219 * referrals [O] Referrals found in the result message.
220 * serverctrls [O] Controls used in the operation.
221 * free [I] Free the result message?
224 * Success: LDAP_SUCCESS
225 * Failure: An LDAP error code.
228 * Free the DNs and error message with ldap_memfree. Free
229 * the referrals with ldap_value_free and the controls with
230 * ldap_controls_free. Pass a nonzero value for 'free' or call
231 * ldap_msgfree to free the result message.
233 ULONG CDECL
ldap_parse_resultW( LDAP
*ld
, LDAPMessage
*result
, ULONG
*retcode
, WCHAR
**matched
, WCHAR
**error
,
234 WCHAR
***referrals
, LDAPControlW
***serverctrls
, BOOLEAN free
)
237 char *matchedU
= NULL
, *errorU
= NULL
, **referralsU
= NULL
;
238 LDAPControlU
**serverctrlsU
= NULL
;
240 TRACE( "(%p, %p, %p, %p, %p, %p, %p, 0x%02x)\n", ld
, result
, retcode
, matched
, error
, referrals
, serverctrls
,
245 struct ldap_parse_result_params params
= { CTX(ld
), MSG(result
), (int *)retcode
, &matchedU
,
246 &errorU
, &referralsU
, &serverctrlsU
, free
};
247 ret
= map_error( LDAP_CALL( ldap_parse_result
, ¶ms
));
249 else return LDAP_PARAM_ERROR
;
251 if (matched
) *matched
= strUtoW( matchedU
);
252 if (error
) *error
= strUtoW( errorU
);
253 if (referrals
) *referrals
= strarrayUtoW( referralsU
);
254 if (serverctrls
) *serverctrls
= controlarrayUtoW( serverctrlsU
);
256 LDAP_CALL( ldap_memfree
, matchedU
);
257 LDAP_CALL( ldap_memfree
, errorU
);
258 LDAP_CALL( ldap_memvfree
, referralsU
);
259 LDAP_CALL( ldap_controls_free
, serverctrlsU
);
263 /***********************************************************************
264 * ldap_parse_sort_controlA (WLDAP32.@)
266 * See ldap_parse_sort_controlW.
268 ULONG CDECL
ldap_parse_sort_controlA( LDAP
*ld
, LDAPControlA
**control
, ULONG
*result
, char **attr
)
272 LDAPControlW
**controlW
= NULL
;
274 TRACE( "(%p, %p, %p, %p)\n", ld
, control
, result
, attr
);
276 if (!ld
) return LDAP_PARAM_ERROR
;
277 if (!control
) return LDAP_CONTROL_NOT_FOUND
;
278 if (!(controlW
= controlarrayAtoW( control
))) return LDAP_NO_MEMORY
;
280 ret
= ldap_parse_sort_controlW( ld
, controlW
, result
, &attrW
);
282 *attr
= strWtoA( attrW
);
283 controlarrayfreeW( controlW
);
287 /***********************************************************************
288 * ldap_parse_sort_controlW (WLDAP32.@)
290 * Parse a sort control.
293 * ld [I] Pointer to an LDAP context.
294 * control [I] Control obtained from a result message.
295 * result [O] Result code.
296 * attr [O] Failing attribute.
299 * Success: LDAP_SUCCESS
300 * Failure: An LDAP error code.
303 * If the function fails, free the failing attribute with ldap_memfree.
305 ULONG CDECL
ldap_parse_sort_controlW( LDAP
*ld
, LDAPControlW
**control
, ULONG
*result
, WCHAR
**attr
)
309 LDAPControlU
**controlU
, *sortcontrol
= NULL
;
313 TRACE( "(%p, %p, %p, %p)\n", ld
, control
, result
, attr
);
315 if (!ld
) return LDAP_PARAM_ERROR
;
316 if (!control
) return LDAP_CONTROL_NOT_FOUND
;
317 if (!(controlU
= controlarrayWtoU( control
))) return LDAP_NO_MEMORY
;
319 for (i
= 0; controlU
[i
]; i
++)
321 if (!strcmp( LDAP_SERVER_RESP_SORT_OID
, controlU
[i
]->ldctl_oid
))
322 sortcontrol
= controlU
[i
];
326 controlarrayfreeU( controlU
);
327 return LDAP_CONTROL_NOT_FOUND
;
331 struct ldap_parse_sortresponse_control_params params
= { CTX(ld
), sortcontrol
, &res
, &attrU
};
332 ret
= map_error( LDAP_CALL( ldap_parse_sortresponse_control
, ¶ms
));
334 if (ret
== LDAP_SUCCESS
)
337 if ((str
= strUtoW( attrU
)))
342 else ret
= LDAP_NO_MEMORY
;
343 LDAP_CALL( ldap_memfree
, attrU
);
346 controlarrayfreeU( controlU
);
350 /***********************************************************************
351 * ldap_parse_vlv_controlA (WLDAP32.@)
353 * See ldap_parse_vlv_controlW.
355 int CDECL
ldap_parse_vlv_controlA( LDAP
*ld
, LDAPControlA
**control
, ULONG
*targetpos
, ULONG
*listcount
,
356 struct berval
**context
, int *errcode
)
359 LDAPControlW
**controlW
= NULL
;
361 TRACE( "(%p, %p, %p, %p, %p, %p)\n", ld
, control
, targetpos
, listcount
, context
, errcode
);
365 if (control
&& !(controlW
= controlarrayAtoW( control
))) return LDAP_NO_MEMORY
;
366 ret
= ldap_parse_vlv_controlW( ld
, controlW
, targetpos
, listcount
, context
, errcode
);
367 controlarrayfreeW( controlW
);
371 /***********************************************************************
372 * ldap_parse_vlv_controlW (WLDAP32.@)
374 * Parse a virtual list view control.
377 * ld [I] Pointer to an LDAP context.
378 * control [I] Controls obtained from a result message.
379 * targetpos [O] Position of the target in the result list.
380 * listcount [O] Estimate of the number of results in the list.
381 * context [O] Server side context.
382 * errcode [O] Error code from the listview operation.
385 * Success: LDAP_SUCCESS
386 * Failure: An LDAP error code.
389 * Free the server context with ber_bvfree.
391 int CDECL
ldap_parse_vlv_controlW( LDAP
*ld
, LDAPControlW
**control
, ULONG
*targetpos
, ULONG
*listcount
,
392 struct berval
**context
, int *errcode
)
395 LDAPControlU
**controlU
, *vlvcontrolU
= NULL
;
396 struct bervalU
*ctxU
;
399 TRACE( "(%p, %p, %p, %p, %p, %p)\n", ld
, control
, targetpos
, listcount
, context
, errcode
);
401 if (!ld
|| !control
) return ~0u;
403 if (!(controlU
= controlarrayWtoU( control
))) return LDAP_NO_MEMORY
;
405 for (i
= 0; controlU
[i
]; i
++)
407 if (!strcmp( LDAP_CONTROL_VLVRESPONSE
, controlU
[i
]->ldctl_oid
))
408 vlvcontrolU
= controlU
[i
];
412 controlarrayfreeU( controlU
);
413 return LDAP_CONTROL_NOT_FOUND
;
417 struct ldap_parse_vlvresponse_control_params params
= { CTX(ld
), vlvcontrolU
, &pos
, &count
, &ctxU
, errcode
};
418 ret
= map_error( LDAP_CALL( ldap_parse_vlvresponse_control
, ¶ms
));
420 if (ret
== LDAP_SUCCESS
)
423 if ((bv
= bervalUtoW( ctxU
)))
429 else ret
= LDAP_NO_MEMORY
;
430 LDAP_CALL( ber_bvfree
, ctxU
);
433 controlarrayfreeU( controlU
);