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_SUCCESS 0x00
36 #define LDAP_NOT_SUPPORTED 0x5c
39 #include "winldap_private.h"
42 WINE_DEFAULT_DEBUG_CHANNEL(wldap32);
44 /***********************************************************************
45 * ldap_control_freeA (WLDAP32.@)
47 * See ldap_control_freeW.
49 ULONG CDECL ldap_control_freeA( LDAPControlA *control )
51 ULONG ret = LDAP_SUCCESS;
54 TRACE( "(%p)\n", control );
55 controlfreeA( control );
61 /***********************************************************************
62 * ldap_control_freeW (WLDAP32.@)
64 * Free an LDAPControl structure.
67 * control [I] LDAPControl structure to free.
72 ULONG CDECL ldap_control_freeW( LDAPControlW *control )
74 ULONG ret = LDAP_SUCCESS;
77 TRACE( "(%p)\n", control );
78 controlfreeW( control );
84 /***********************************************************************
85 * ldap_controls_freeA (WLDAP32.@)
87 * See ldap_controls_freeW.
89 ULONG CDECL ldap_controls_freeA( LDAPControlA **controls )
91 ULONG ret = LDAP_SUCCESS;
94 TRACE( "(%p)\n", controls );
95 controlarrayfreeA( controls );
101 /***********************************************************************
102 * ldap_controls_freeW (WLDAP32.@)
104 * Free an array of LDAPControl structures.
107 * controls [I] Array of LDAPControl structures to free.
112 ULONG CDECL ldap_controls_freeW( LDAPControlW **controls )
114 ULONG ret = LDAP_SUCCESS;
117 TRACE( "(%p)\n", controls );
118 controlarrayfreeW( controls );
124 /***********************************************************************
125 * ldap_create_sort_controlA (WLDAP32.@)
127 * See ldap_create_sort_controlW.
129 ULONG CDECL ldap_create_sort_controlA( WLDAP32_LDAP *ld, PLDAPSortKeyA *sortkey,
130 UCHAR critical, PLDAPControlA *control )
132 ULONG ret = LDAP_NOT_SUPPORTED;
134 LDAPSortKeyW **sortkeyW = NULL;
135 LDAPControlW *controlW = NULL;
137 TRACE( "(%p, %p, 0x%02x, %p)\n", ld, sortkey, critical, control );
139 if (!ld || !sortkey || !control)
140 return WLDAP32_LDAP_PARAM_ERROR;
142 sortkeyW = sortkeyarrayAtoW( sortkey );
143 if (!sortkeyW) return WLDAP32_LDAP_NO_MEMORY;
145 ret = ldap_create_sort_controlW( ld, sortkeyW, critical, &controlW );
147 *control = controlWtoA( controlW );
148 if (!*control) ret = WLDAP32_LDAP_NO_MEMORY;
150 ldap_control_freeW( controlW );
151 sortkeyarrayfreeW( sortkeyW );
157 /***********************************************************************
158 * ldap_create_sort_controlW (WLDAP32.@)
160 * Create a control for server sorted search results.
163 * ld [I] Pointer to an LDAP context.
164 * sortkey [I] Array of LDAPSortKey structures, each specifying an
165 * attribute to use as a sort key, a matching rule and
166 * the sort order (ascending or descending).
167 * critical [I] Tells the server this control is critical to the
169 * control [O] LDAPControl created.
172 * Success: LDAP_SUCCESS
173 * Failure: An LDAP error code.
176 * Pass the created control as a server control in subsequent calls
177 * to ldap_search_ext(_s) to obtain sorted search results.
179 ULONG CDECL ldap_create_sort_controlW( WLDAP32_LDAP *ld, PLDAPSortKeyW *sortkey,
180 UCHAR critical, PLDAPControlW *control )
182 ULONG ret = LDAP_NOT_SUPPORTED;
184 LDAPSortKey **sortkeyU = NULL;
185 LDAPControl *controlU = NULL;
187 TRACE( "(%p, %p, 0x%02x, %p)\n", ld, sortkey, critical, control );
189 if (!ld || !sortkey || !control)
190 return WLDAP32_LDAP_PARAM_ERROR;
192 sortkeyU = sortkeyarrayWtoU( sortkey );
193 if (!sortkeyU) return WLDAP32_LDAP_NO_MEMORY;
195 ret = ldap_create_sort_control( ld, sortkeyU, critical, &controlU );
197 *control = controlUtoW( controlU );
198 if (!*control) ret = WLDAP32_LDAP_NO_MEMORY;
200 ldap_control_free( controlU );
201 sortkeyarrayfreeU( sortkeyU );
207 /***********************************************************************
208 * ldap_create_vlv_controlA (WLDAP32.@)
210 * See ldap_create_vlv_controlW.
212 INT CDECL ldap_create_vlv_controlA( WLDAP32_LDAP *ld, WLDAP32_LDAPVLVInfo *info,
213 UCHAR critical, LDAPControlA **control )
215 INT ret = LDAP_NOT_SUPPORTED;
217 LDAPControlW *controlW = NULL;
219 TRACE( "(%p, %p, 0x%02x, %p)\n", ld, info, critical, control );
221 if (!ld || !control) return ~0UL;
223 ret = ldap_create_vlv_controlW( ld, info, critical, &controlW );
225 if (ret == LDAP_SUCCESS)
227 *control = controlWtoA( controlW );
228 if (!*control) ret = WLDAP32_LDAP_NO_MEMORY;
229 ldap_control_freeW( controlW );
236 /***********************************************************************
237 * ldap_create_vlv_controlW (WLDAP32.@)
239 * Create a virtual list view control.
242 * ld [I] Pointer to an LDAP context.
243 * info [I] LDAPVLVInfo structure specifying a list view window.
244 * critical [I] Tells the server this control is critical to the
246 * control [O] LDAPControl created.
249 * Success: LDAP_SUCCESS
250 * Failure: An LDAP error code.
253 * Pass the created control in conjuction with a sort control as
254 * server controls in subsequent calls to ldap_search_ext(_s). The
255 * server will then return a sorted, contiguous subset of results
256 * that meets the criteria specified in the LDAPVLVInfo structure.
258 INT CDECL ldap_create_vlv_controlW( WLDAP32_LDAP *ld, WLDAP32_LDAPVLVInfo *info,
259 UCHAR critical, LDAPControlW **control )
261 INT ret = LDAP_NOT_SUPPORTED;
263 LDAPControl *controlU = NULL;
265 TRACE( "(%p, %p, 0x%02x, %p)\n", ld, info, critical, control );
267 if (!ld || !control) return ~0UL;
269 ret = ldap_create_vlv_control( ld, (LDAPVLVInfo *)info, &controlU );
271 if (ret == LDAP_SUCCESS)
273 *control = controlUtoW( controlU );
274 if (!*control) ret = WLDAP32_LDAP_NO_MEMORY;
275 ldap_control_free( controlU );
282 /***********************************************************************
283 * ldap_encode_sort_controlA (WLDAP32.@)
285 * See ldap_encode_sort_controlW.
287 ULONG CDECL ldap_encode_sort_controlA( WLDAP32_LDAP *ld, PLDAPSortKeyA *sortkeys,
288 PLDAPControlA control, BOOLEAN critical )
290 return ldap_create_sort_controlA( ld, sortkeys, critical, &control );
293 /***********************************************************************
294 * ldap_encode_sort_controlW (WLDAP32.@)
296 * Create a control for server sorted search results.
299 * ld [I] Pointer to an LDAP context.
300 * sortkey [I] Array of LDAPSortKey structures, each specifying an
301 * attribute to use as a sort key, a matching rule and
302 * the sort order (ascending or descending).
303 * critical [I] Tells the server this control is critical to the
305 * control [O] LDAPControl created.
308 * Success: LDAP_SUCCESS
309 * Failure: An LDAP error code.
312 * This function is obsolete. Use its equivalent
313 * ldap_create_sort_control instead.
315 ULONG CDECL ldap_encode_sort_controlW( WLDAP32_LDAP *ld, PLDAPSortKeyW *sortkeys,
316 PLDAPControlW control, BOOLEAN critical )
318 return ldap_create_sort_controlW( ld, sortkeys, critical, &control );
321 /***********************************************************************
322 * ldap_free_controlsA (WLDAP32.@)
324 * See ldap_free_controlsW.
326 ULONG CDECL ldap_free_controlsA( LDAPControlA **controls )
328 return ldap_controls_freeA( controls );
331 /***********************************************************************
332 * ldap_free_controlsW (WLDAP32.@)
334 * Free an array of LDAPControl structures.
337 * controls [I] Array of LDAPControl structures to free.
343 * Obsolete, use ldap_controls_freeW.
345 ULONG CDECL ldap_free_controlsW( LDAPControlW **controls )
347 return ldap_controls_freeW( controls );