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 "winldap_private.h"
23 /***********************************************************************
24 * ldap_control_freeA (WLDAP32.@)
26 * See ldap_control_freeW.
28 ULONG CDECL
ldap_control_freeA( LDAPControlA
*control
)
30 ULONG ret
= WLDAP32_LDAP_SUCCESS
;
33 TRACE( "(%p)\n", control
);
34 controlfreeA( control
);
40 /***********************************************************************
41 * ldap_control_freeW (WLDAP32.@)
43 * Free an LDAPControl structure.
46 * control [I] LDAPControl structure to free.
51 ULONG CDECL
ldap_control_freeW( LDAPControlW
*control
)
53 ULONG ret
= WLDAP32_LDAP_SUCCESS
;
56 TRACE( "(%p)\n", control
);
57 controlfreeW( control
);
63 /***********************************************************************
64 * ldap_controls_freeA (WLDAP32.@)
66 * See ldap_controls_freeW.
68 ULONG CDECL
ldap_controls_freeA( LDAPControlA
**controls
)
70 ULONG ret
= WLDAP32_LDAP_SUCCESS
;
73 TRACE( "(%p)\n", controls
);
74 controlarrayfreeA( controls
);
80 /***********************************************************************
81 * ldap_controls_freeW (WLDAP32.@)
83 * Free an array of LDAPControl structures.
86 * controls [I] Array of LDAPControl structures to free.
91 ULONG CDECL
ldap_controls_freeW( LDAPControlW
**controls
)
93 ULONG ret
= WLDAP32_LDAP_SUCCESS
;
96 TRACE( "(%p)\n", controls
);
97 controlarrayfreeW( controls
);
103 /***********************************************************************
104 * ldap_create_sort_controlA (WLDAP32.@)
106 * See ldap_create_sort_controlW.
108 ULONG CDECL
ldap_create_sort_controlA( WLDAP32_LDAP
*ld
, PLDAPSortKeyA
*sortkey
,
109 UCHAR critical
, PLDAPControlA
*control
)
111 ULONG ret
= WLDAP32_LDAP_NOT_SUPPORTED
;
113 LDAPSortKeyW
**sortkeyW
= NULL
;
114 LDAPControlW
*controlW
= NULL
;
116 TRACE( "(%p, %p, 0x%02x, %p)\n", ld
, sortkey
, critical
, control
);
118 if (!ld
|| !sortkey
|| !control
)
119 return WLDAP32_LDAP_PARAM_ERROR
;
121 sortkeyW
= sortkeyarrayAtoW( sortkey
);
122 if (!sortkeyW
) return WLDAP32_LDAP_NO_MEMORY
;
124 ret
= ldap_create_sort_controlW( ld
, sortkeyW
, critical
, &controlW
);
126 *control
= controlWtoA( controlW
);
127 if (!*control
) ret
= WLDAP32_LDAP_NO_MEMORY
;
129 ldap_control_freeW( controlW
);
130 sortkeyarrayfreeW( sortkeyW
);
136 /***********************************************************************
137 * ldap_create_sort_controlW (WLDAP32.@)
139 * Create a control for server sorted search results.
142 * ld [I] Pointer to an LDAP context.
143 * sortkey [I] Array of LDAPSortKey structures, each specifying an
144 * attribute to use as a sort key, a matching rule and
145 * the sort order (ascending or descending).
146 * critical [I] Tells the server this control is critical to the
148 * control [O] LDAPControl created.
151 * Success: LDAP_SUCCESS
152 * Failure: An LDAP error code.
155 * Pass the created control as a server control in subsequent calls
156 * to ldap_search_ext(_s) to obtain sorted search results.
158 ULONG CDECL
ldap_create_sort_controlW( WLDAP32_LDAP
*ld
, PLDAPSortKeyW
*sortkey
,
159 UCHAR critical
, PLDAPControlW
*control
)
161 ULONG ret
= WLDAP32_LDAP_NOT_SUPPORTED
;
163 LDAPSortKey
**sortkeyU
= NULL
;
164 LDAPControl
*controlU
= NULL
;
166 TRACE( "(%p, %p, 0x%02x, %p)\n", ld
, sortkey
, critical
, control
);
168 if (!ld
|| !sortkey
|| !control
)
169 return WLDAP32_LDAP_PARAM_ERROR
;
171 sortkeyU
= sortkeyarrayWtoU( sortkey
);
172 if (!sortkeyU
) return WLDAP32_LDAP_NO_MEMORY
;
174 ret
= map_error( ldap_create_sort_control( ld
, sortkeyU
, critical
, &controlU
));
176 *control
= controlUtoW( controlU
);
177 if (!*control
) ret
= WLDAP32_LDAP_NO_MEMORY
;
179 ldap_control_free( controlU
);
180 sortkeyarrayfreeU( sortkeyU
);
186 /***********************************************************************
187 * ldap_create_vlv_controlA (WLDAP32.@)
189 * See ldap_create_vlv_controlW.
191 INT CDECL
ldap_create_vlv_controlA( WLDAP32_LDAP
*ld
, WLDAP32_LDAPVLVInfo
*info
,
192 UCHAR critical
, LDAPControlA
**control
)
194 INT ret
= WLDAP32_LDAP_NOT_SUPPORTED
;
196 LDAPControlW
*controlW
= NULL
;
198 TRACE( "(%p, %p, 0x%02x, %p)\n", ld
, info
, critical
, control
);
200 if (!ld
|| !control
) return ~0u;
202 ret
= ldap_create_vlv_controlW( ld
, info
, critical
, &controlW
);
204 if (ret
== WLDAP32_LDAP_SUCCESS
)
206 *control
= controlWtoA( controlW
);
207 if (!*control
) ret
= WLDAP32_LDAP_NO_MEMORY
;
208 ldap_control_freeW( controlW
);
215 /***********************************************************************
216 * ldap_create_vlv_controlW (WLDAP32.@)
218 * Create a virtual list view control.
221 * ld [I] Pointer to an LDAP context.
222 * info [I] LDAPVLVInfo structure specifying a list view window.
223 * critical [I] Tells the server this control is critical to the
225 * control [O] LDAPControl created.
228 * Success: LDAP_SUCCESS
229 * Failure: An LDAP error code.
232 * Pass the created control in conjunction with a sort control as
233 * server controls in subsequent calls to ldap_search_ext(_s). The
234 * server will then return a sorted, contiguous subset of results
235 * that meets the criteria specified in the LDAPVLVInfo structure.
237 INT CDECL
ldap_create_vlv_controlW( WLDAP32_LDAP
*ld
, WLDAP32_LDAPVLVInfo
*info
,
238 UCHAR critical
, LDAPControlW
**control
)
240 INT ret
= WLDAP32_LDAP_NOT_SUPPORTED
;
242 LDAPControl
*controlU
= NULL
;
244 TRACE( "(%p, %p, 0x%02x, %p)\n", ld
, info
, critical
, control
);
246 if (!ld
|| !control
) return ~0u;
248 ret
= map_error( ldap_create_vlv_control( ld
, (LDAPVLVInfo
*)info
, &controlU
));
250 if (ret
== WLDAP32_LDAP_SUCCESS
)
252 *control
= controlUtoW( controlU
);
253 if (!*control
) ret
= WLDAP32_LDAP_NO_MEMORY
;
254 ldap_control_free( controlU
);
261 static inline void bv_val_dup( const struct WLDAP32_berval
*src
, struct WLDAP32_berval
*dst
)
263 dst
->bv_val
= HeapAlloc( GetProcessHeap(), 0, src
->bv_len
);
266 memcpy( dst
->bv_val
, src
->bv_val
, src
->bv_len
);
267 dst
->bv_len
= src
->bv_len
;
273 /***********************************************************************
274 * ldap_encode_sort_controlA (WLDAP32.@)
276 * See ldap_encode_sort_controlW.
278 ULONG CDECL
ldap_encode_sort_controlA( WLDAP32_LDAP
*ld
, PLDAPSortKeyA
*sortkeys
,
279 PLDAPControlA ret
, BOOLEAN critical
)
281 LDAPControlA
*control
= NULL
;
284 if ((result
= ldap_create_sort_controlA( ld
, sortkeys
, critical
, &control
)) == WLDAP32_LDAP_SUCCESS
)
286 ret
->ldctl_oid
= strdupU(control
->ldctl_oid
);
287 bv_val_dup( &control
->ldctl_value
, &ret
->ldctl_value
);
288 ret
->ldctl_iscritical
= control
->ldctl_iscritical
;
289 ldap_control_freeA( control
);
294 /***********************************************************************
295 * ldap_encode_sort_controlW (WLDAP32.@)
297 * Create a control for server sorted search results.
300 * ld [I] Pointer to an LDAP context.
301 * sortkey [I] Array of LDAPSortKey structures, each specifying an
302 * attribute to use as a sort key, a matching rule and
303 * the sort order (ascending or descending).
304 * critical [I] Tells the server this control is critical to the
306 * control [O] LDAPControl created.
309 * Success: LDAP_SUCCESS
310 * Failure: An LDAP error code.
313 * This function is obsolete. Use its equivalent
314 * ldap_create_sort_control instead.
316 ULONG CDECL
ldap_encode_sort_controlW( WLDAP32_LDAP
*ld
, PLDAPSortKeyW
*sortkeys
,
317 PLDAPControlW ret
, BOOLEAN critical
)
319 LDAPControlW
*control
= NULL
;
322 if ((result
= ldap_create_sort_controlW( ld
, sortkeys
, critical
, &control
)) == WLDAP32_LDAP_SUCCESS
)
324 ret
->ldctl_oid
= strdupW(control
->ldctl_oid
);
325 bv_val_dup( &control
->ldctl_value
, &ret
->ldctl_value
);
326 ret
->ldctl_iscritical
= control
->ldctl_iscritical
;
327 ldap_control_freeW( control
);
332 /***********************************************************************
333 * ldap_free_controlsA (WLDAP32.@)
335 * See ldap_free_controlsW.
337 ULONG CDECL
ldap_free_controlsA( LDAPControlA
**controls
)
339 return ldap_controls_freeA( controls
);
342 /***********************************************************************
343 * ldap_free_controlsW (WLDAP32.@)
345 * Free an array of LDAPControl structures.
348 * controls [I] Array of LDAPControl structures to free.
354 * Obsolete, use ldap_controls_freeW.
356 ULONG CDECL
ldap_free_controlsW( LDAPControlW
**controls
)
358 return ldap_controls_freeW( controls
);