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
22 #include "wine/port.h"
33 #include "winldap_private.h"
35 #include "wine/debug.h"
37 WINE_DEFAULT_DEBUG_CHANNEL(wldap32
);
39 /***********************************************************************
40 * ldap_control_freeA (WLDAP32.@)
42 * See ldap_control_freeW.
44 ULONG CDECL
ldap_control_freeA( LDAPControlA
*control
)
46 ULONG ret
= WLDAP32_LDAP_SUCCESS
;
49 TRACE( "(%p)\n", control
);
50 controlfreeA( control
);
56 /***********************************************************************
57 * ldap_control_freeW (WLDAP32.@)
59 * Free an LDAPControl structure.
62 * control [I] LDAPControl structure to free.
67 ULONG CDECL
ldap_control_freeW( LDAPControlW
*control
)
69 ULONG ret
= WLDAP32_LDAP_SUCCESS
;
72 TRACE( "(%p)\n", control
);
73 controlfreeW( control
);
79 /***********************************************************************
80 * ldap_controls_freeA (WLDAP32.@)
82 * See ldap_controls_freeW.
84 ULONG CDECL
ldap_controls_freeA( LDAPControlA
**controls
)
86 ULONG ret
= WLDAP32_LDAP_SUCCESS
;
89 TRACE( "(%p)\n", controls
);
90 controlarrayfreeA( controls
);
96 /***********************************************************************
97 * ldap_controls_freeW (WLDAP32.@)
99 * Free an array of LDAPControl structures.
102 * controls [I] Array of LDAPControl structures to free.
107 ULONG CDECL
ldap_controls_freeW( LDAPControlW
**controls
)
109 ULONG ret
= WLDAP32_LDAP_SUCCESS
;
112 TRACE( "(%p)\n", controls
);
113 controlarrayfreeW( controls
);
119 /***********************************************************************
120 * ldap_create_sort_controlA (WLDAP32.@)
122 * See ldap_create_sort_controlW.
124 ULONG CDECL
ldap_create_sort_controlA( WLDAP32_LDAP
*ld
, PLDAPSortKeyA
*sortkey
,
125 UCHAR critical
, PLDAPControlA
*control
)
127 ULONG ret
= WLDAP32_LDAP_NOT_SUPPORTED
;
129 LDAPSortKeyW
**sortkeyW
= NULL
;
130 LDAPControlW
*controlW
= NULL
;
132 TRACE( "(%p, %p, 0x%02x, %p)\n", ld
, sortkey
, critical
, control
);
134 if (!ld
|| !sortkey
|| !control
)
135 return WLDAP32_LDAP_PARAM_ERROR
;
137 sortkeyW
= sortkeyarrayAtoW( sortkey
);
138 if (!sortkeyW
) return WLDAP32_LDAP_NO_MEMORY
;
140 ret
= ldap_create_sort_controlW( ld
, sortkeyW
, critical
, &controlW
);
142 *control
= controlWtoA( controlW
);
143 if (!*control
) ret
= WLDAP32_LDAP_NO_MEMORY
;
145 ldap_control_freeW( controlW
);
146 sortkeyarrayfreeW( sortkeyW
);
152 /***********************************************************************
153 * ldap_create_sort_controlW (WLDAP32.@)
155 * Create a control for server sorted search results.
158 * ld [I] Pointer to an LDAP context.
159 * sortkey [I] Array of LDAPSortKey structures, each specifying an
160 * attribute to use as a sort key, a matching rule and
161 * the sort order (ascending or descending).
162 * critical [I] Tells the server this control is critical to the
164 * control [O] LDAPControl created.
167 * Success: LDAP_SUCCESS
168 * Failure: An LDAP error code.
171 * Pass the created control as a server control in subsequent calls
172 * to ldap_search_ext(_s) to obtain sorted search results.
174 ULONG CDECL
ldap_create_sort_controlW( WLDAP32_LDAP
*ld
, PLDAPSortKeyW
*sortkey
,
175 UCHAR critical
, PLDAPControlW
*control
)
177 ULONG ret
= WLDAP32_LDAP_NOT_SUPPORTED
;
179 LDAPSortKey
**sortkeyU
= NULL
;
180 LDAPControl
*controlU
= NULL
;
182 TRACE( "(%p, %p, 0x%02x, %p)\n", ld
, sortkey
, critical
, control
);
184 if (!ld
|| !sortkey
|| !control
)
185 return WLDAP32_LDAP_PARAM_ERROR
;
187 sortkeyU
= sortkeyarrayWtoU( sortkey
);
188 if (!sortkeyU
) return WLDAP32_LDAP_NO_MEMORY
;
190 ret
= map_error( ldap_create_sort_control( ld
, sortkeyU
, critical
, &controlU
));
192 *control
= controlUtoW( controlU
);
193 if (!*control
) ret
= WLDAP32_LDAP_NO_MEMORY
;
195 ldap_control_free( controlU
);
196 sortkeyarrayfreeU( sortkeyU
);
202 /***********************************************************************
203 * ldap_create_vlv_controlA (WLDAP32.@)
205 * See ldap_create_vlv_controlW.
207 INT CDECL
ldap_create_vlv_controlA( WLDAP32_LDAP
*ld
, WLDAP32_LDAPVLVInfo
*info
,
208 UCHAR critical
, LDAPControlA
**control
)
210 INT ret
= WLDAP32_LDAP_NOT_SUPPORTED
;
212 LDAPControlW
*controlW
= NULL
;
214 TRACE( "(%p, %p, 0x%02x, %p)\n", ld
, info
, critical
, control
);
216 if (!ld
|| !control
) return ~0u;
218 ret
= ldap_create_vlv_controlW( ld
, info
, critical
, &controlW
);
220 if (ret
== WLDAP32_LDAP_SUCCESS
)
222 *control
= controlWtoA( controlW
);
223 if (!*control
) ret
= WLDAP32_LDAP_NO_MEMORY
;
224 ldap_control_freeW( controlW
);
231 /***********************************************************************
232 * ldap_create_vlv_controlW (WLDAP32.@)
234 * Create a virtual list view control.
237 * ld [I] Pointer to an LDAP context.
238 * info [I] LDAPVLVInfo structure specifying a list view window.
239 * critical [I] Tells the server this control is critical to the
241 * control [O] LDAPControl created.
244 * Success: LDAP_SUCCESS
245 * Failure: An LDAP error code.
248 * Pass the created control in conjunction with a sort control as
249 * server controls in subsequent calls to ldap_search_ext(_s). The
250 * server will then return a sorted, contiguous subset of results
251 * that meets the criteria specified in the LDAPVLVInfo structure.
253 INT CDECL
ldap_create_vlv_controlW( WLDAP32_LDAP
*ld
, WLDAP32_LDAPVLVInfo
*info
,
254 UCHAR critical
, LDAPControlW
**control
)
256 INT ret
= WLDAP32_LDAP_NOT_SUPPORTED
;
258 LDAPControl
*controlU
= NULL
;
260 TRACE( "(%p, %p, 0x%02x, %p)\n", ld
, info
, critical
, control
);
262 if (!ld
|| !control
) return ~0u;
264 ret
= map_error( ldap_create_vlv_control( ld
, (LDAPVLVInfo
*)info
, &controlU
));
266 if (ret
== WLDAP32_LDAP_SUCCESS
)
268 *control
= controlUtoW( controlU
);
269 if (!*control
) ret
= WLDAP32_LDAP_NO_MEMORY
;
270 ldap_control_free( controlU
);
277 static inline void bv_val_dup( const struct WLDAP32_berval
*src
, struct WLDAP32_berval
*dst
)
279 dst
->bv_val
= HeapAlloc( GetProcessHeap(), 0, src
->bv_len
);
282 memcpy( dst
->bv_val
, src
->bv_val
, src
->bv_len
);
283 dst
->bv_len
= src
->bv_len
;
289 /***********************************************************************
290 * ldap_encode_sort_controlA (WLDAP32.@)
292 * See ldap_encode_sort_controlW.
294 ULONG CDECL
ldap_encode_sort_controlA( WLDAP32_LDAP
*ld
, PLDAPSortKeyA
*sortkeys
,
295 PLDAPControlA ret
, BOOLEAN critical
)
297 LDAPControlA
*control
;
300 if ((result
= ldap_create_sort_controlA( ld
, sortkeys
, critical
, &control
)) == WLDAP32_LDAP_SUCCESS
)
302 ret
->ldctl_oid
= strdupU(control
->ldctl_oid
);
303 bv_val_dup( &control
->ldctl_value
, &ret
->ldctl_value
);
304 ret
->ldctl_iscritical
= control
->ldctl_iscritical
;
305 ldap_control_freeA( control
);
310 /***********************************************************************
311 * ldap_encode_sort_controlW (WLDAP32.@)
313 * Create a control for server sorted search results.
316 * ld [I] Pointer to an LDAP context.
317 * sortkey [I] Array of LDAPSortKey structures, each specifying an
318 * attribute to use as a sort key, a matching rule and
319 * the sort order (ascending or descending).
320 * critical [I] Tells the server this control is critical to the
322 * control [O] LDAPControl created.
325 * Success: LDAP_SUCCESS
326 * Failure: An LDAP error code.
329 * This function is obsolete. Use its equivalent
330 * ldap_create_sort_control instead.
332 ULONG CDECL
ldap_encode_sort_controlW( WLDAP32_LDAP
*ld
, PLDAPSortKeyW
*sortkeys
,
333 PLDAPControlW ret
, BOOLEAN critical
)
335 LDAPControlW
*control
;
338 if ((result
= ldap_create_sort_controlW( ld
, sortkeys
, critical
, &control
)) == WLDAP32_LDAP_SUCCESS
)
340 ret
->ldctl_oid
= strdupW(control
->ldctl_oid
);
341 bv_val_dup( &control
->ldctl_value
, &ret
->ldctl_value
);
342 ret
->ldctl_iscritical
= control
->ldctl_iscritical
;
343 ldap_control_freeW( control
);
348 /***********************************************************************
349 * ldap_free_controlsA (WLDAP32.@)
351 * See ldap_free_controlsW.
353 ULONG CDECL
ldap_free_controlsA( LDAPControlA
**controls
)
355 return ldap_controls_freeA( controls
);
358 /***********************************************************************
359 * ldap_free_controlsW (WLDAP32.@)
361 * Free an array of LDAPControl structures.
364 * controls [I] Array of LDAPControl structures to free.
370 * Obsolete, use ldap_controls_freeW.
372 ULONG CDECL
ldap_free_controlsW( LDAPControlW
**controls
)
374 return ldap_controls_freeW( controls
);