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"
38 WINE_DEFAULT_DEBUG_CHANNEL(wldap32
);
41 /***********************************************************************
42 * ldap_control_freeA (WLDAP32.@)
44 * See ldap_control_freeW.
46 ULONG CDECL
ldap_control_freeA( LDAPControlA
*control
)
48 ULONG ret
= WLDAP32_LDAP_SUCCESS
;
51 TRACE( "(%p)\n", control
);
52 controlfreeA( control
);
58 /***********************************************************************
59 * ldap_control_freeW (WLDAP32.@)
61 * Free an LDAPControl structure.
64 * control [I] LDAPControl structure to free.
69 ULONG CDECL
ldap_control_freeW( LDAPControlW
*control
)
71 ULONG ret
= WLDAP32_LDAP_SUCCESS
;
74 TRACE( "(%p)\n", control
);
75 controlfreeW( control
);
81 /***********************************************************************
82 * ldap_controls_freeA (WLDAP32.@)
84 * See ldap_controls_freeW.
86 ULONG CDECL
ldap_controls_freeA( LDAPControlA
**controls
)
88 ULONG ret
= WLDAP32_LDAP_SUCCESS
;
91 TRACE( "(%p)\n", controls
);
92 controlarrayfreeA( controls
);
98 /***********************************************************************
99 * ldap_controls_freeW (WLDAP32.@)
101 * Free an array of LDAPControl structures.
104 * controls [I] Array of LDAPControl structures to free.
109 ULONG CDECL
ldap_controls_freeW( LDAPControlW
**controls
)
111 ULONG ret
= WLDAP32_LDAP_SUCCESS
;
114 TRACE( "(%p)\n", controls
);
115 controlarrayfreeW( controls
);
121 /***********************************************************************
122 * ldap_create_sort_controlA (WLDAP32.@)
124 * See ldap_create_sort_controlW.
126 ULONG CDECL
ldap_create_sort_controlA( WLDAP32_LDAP
*ld
, PLDAPSortKeyA
*sortkey
,
127 UCHAR critical
, PLDAPControlA
*control
)
129 ULONG ret
= WLDAP32_LDAP_NOT_SUPPORTED
;
131 LDAPSortKeyW
**sortkeyW
= NULL
;
132 LDAPControlW
*controlW
= NULL
;
134 TRACE( "(%p, %p, 0x%02x, %p)\n", ld
, sortkey
, critical
, control
);
136 if (!ld
|| !sortkey
|| !control
)
137 return WLDAP32_LDAP_PARAM_ERROR
;
139 sortkeyW
= sortkeyarrayAtoW( sortkey
);
140 if (!sortkeyW
) return WLDAP32_LDAP_NO_MEMORY
;
142 ret
= ldap_create_sort_controlW( ld
, sortkeyW
, critical
, &controlW
);
144 *control
= controlWtoA( controlW
);
145 if (!*control
) ret
= WLDAP32_LDAP_NO_MEMORY
;
147 ldap_control_freeW( controlW
);
148 sortkeyarrayfreeW( sortkeyW
);
154 /***********************************************************************
155 * ldap_create_sort_controlW (WLDAP32.@)
157 * Create a control for server sorted search results.
160 * ld [I] Pointer to an LDAP context.
161 * sortkey [I] Array of LDAPSortKey structures, each specifying an
162 * attribute to use as a sort key, a matching rule and
163 * the sort order (ascending or descending).
164 * critical [I] Tells the server this control is critical to the
166 * control [O] LDAPControl created.
169 * Success: LDAP_SUCCESS
170 * Failure: An LDAP error code.
173 * Pass the created control as a server control in subsequent calls
174 * to ldap_search_ext(_s) to obtain sorted search results.
176 ULONG CDECL
ldap_create_sort_controlW( WLDAP32_LDAP
*ld
, PLDAPSortKeyW
*sortkey
,
177 UCHAR critical
, PLDAPControlW
*control
)
179 ULONG ret
= WLDAP32_LDAP_NOT_SUPPORTED
;
181 LDAPSortKey
**sortkeyU
= NULL
;
182 LDAPControl
*controlU
= NULL
;
184 TRACE( "(%p, %p, 0x%02x, %p)\n", ld
, sortkey
, critical
, control
);
186 if (!ld
|| !sortkey
|| !control
)
187 return WLDAP32_LDAP_PARAM_ERROR
;
189 sortkeyU
= sortkeyarrayWtoU( sortkey
);
190 if (!sortkeyU
) return WLDAP32_LDAP_NO_MEMORY
;
192 ret
= map_error( ldap_create_sort_control( ld
->ld
, sortkeyU
, critical
, &controlU
));
194 *control
= controlUtoW( controlU
);
195 if (!*control
) ret
= WLDAP32_LDAP_NO_MEMORY
;
197 ldap_control_free( controlU
);
198 sortkeyarrayfreeU( sortkeyU
);
204 /***********************************************************************
205 * ldap_create_vlv_controlA (WLDAP32.@)
207 * See ldap_create_vlv_controlW.
209 INT CDECL
ldap_create_vlv_controlA( WLDAP32_LDAP
*ld
, WLDAP32_LDAPVLVInfo
*info
,
210 UCHAR critical
, LDAPControlA
**control
)
212 INT ret
= WLDAP32_LDAP_NOT_SUPPORTED
;
214 LDAPControlW
*controlW
= NULL
;
216 TRACE( "(%p, %p, 0x%02x, %p)\n", ld
, info
, critical
, control
);
218 if (!ld
|| !control
) return ~0u;
220 ret
= ldap_create_vlv_controlW( ld
, info
, critical
, &controlW
);
222 if (ret
== WLDAP32_LDAP_SUCCESS
)
224 *control
= controlWtoA( controlW
);
225 if (!*control
) ret
= WLDAP32_LDAP_NO_MEMORY
;
226 ldap_control_freeW( controlW
);
233 /***********************************************************************
234 * ldap_create_vlv_controlW (WLDAP32.@)
236 * Create a virtual list view control.
239 * ld [I] Pointer to an LDAP context.
240 * info [I] LDAPVLVInfo structure specifying a list view window.
241 * critical [I] Tells the server this control is critical to the
243 * control [O] LDAPControl created.
246 * Success: LDAP_SUCCESS
247 * Failure: An LDAP error code.
250 * Pass the created control in conjunction with a sort control as
251 * server controls in subsequent calls to ldap_search_ext(_s). The
252 * server will then return a sorted, contiguous subset of results
253 * that meets the criteria specified in the LDAPVLVInfo structure.
255 INT CDECL
ldap_create_vlv_controlW( WLDAP32_LDAP
*ld
, WLDAP32_LDAPVLVInfo
*info
,
256 UCHAR critical
, LDAPControlW
**control
)
258 INT ret
= WLDAP32_LDAP_NOT_SUPPORTED
;
260 LDAPControl
*controlU
= NULL
;
262 TRACE( "(%p, %p, 0x%02x, %p)\n", ld
, info
, critical
, control
);
264 if (!ld
|| !control
) return ~0u;
266 ret
= map_error( ldap_create_vlv_control( ld
->ld
, (LDAPVLVInfo
*)info
, &controlU
));
268 if (ret
== WLDAP32_LDAP_SUCCESS
)
270 *control
= controlUtoW( controlU
);
271 if (!*control
) ret
= WLDAP32_LDAP_NO_MEMORY
;
272 ldap_control_free( controlU
);
279 static inline void bv_val_dup( const struct WLDAP32_berval
*src
, struct WLDAP32_berval
*dst
)
281 if ((dst
->bv_val
= heap_alloc( src
->bv_len
)))
283 memcpy( dst
->bv_val
, src
->bv_val
, src
->bv_len
);
284 dst
->bv_len
= src
->bv_len
;
290 /***********************************************************************
291 * ldap_encode_sort_controlA (WLDAP32.@)
293 * See ldap_encode_sort_controlW.
295 ULONG CDECL
ldap_encode_sort_controlA( WLDAP32_LDAP
*ld
, PLDAPSortKeyA
*sortkeys
,
296 PLDAPControlA ret
, BOOLEAN critical
)
298 LDAPControlA
*control
;
301 if ((result
= ldap_create_sort_controlA( ld
, sortkeys
, critical
, &control
)) == WLDAP32_LDAP_SUCCESS
)
303 ret
->ldctl_oid
= strdupU(control
->ldctl_oid
);
304 bv_val_dup( &control
->ldctl_value
, &ret
->ldctl_value
);
305 ret
->ldctl_iscritical
= control
->ldctl_iscritical
;
306 ldap_control_freeA( control
);
311 /***********************************************************************
312 * ldap_encode_sort_controlW (WLDAP32.@)
314 * Create a control for server sorted search results.
317 * ld [I] Pointer to an LDAP context.
318 * sortkey [I] Array of LDAPSortKey structures, each specifying an
319 * attribute to use as a sort key, a matching rule and
320 * the sort order (ascending or descending).
321 * critical [I] Tells the server this control is critical to the
323 * control [O] LDAPControl created.
326 * Success: LDAP_SUCCESS
327 * Failure: An LDAP error code.
330 * This function is obsolete. Use its equivalent
331 * ldap_create_sort_control instead.
333 ULONG CDECL
ldap_encode_sort_controlW( WLDAP32_LDAP
*ld
, PLDAPSortKeyW
*sortkeys
,
334 PLDAPControlW ret
, BOOLEAN critical
)
336 LDAPControlW
*control
;
339 if ((result
= ldap_create_sort_controlW( ld
, sortkeys
, critical
, &control
)) == WLDAP32_LDAP_SUCCESS
)
341 ret
->ldctl_oid
= strdupW(control
->ldctl_oid
);
342 bv_val_dup( &control
->ldctl_value
, &ret
->ldctl_value
);
343 ret
->ldctl_iscritical
= control
->ldctl_iscritical
;
344 ldap_control_freeW( control
);
349 /***********************************************************************
350 * ldap_free_controlsA (WLDAP32.@)
352 * See ldap_free_controlsW.
354 ULONG CDECL
ldap_free_controlsA( LDAPControlA
**controls
)
356 return ldap_controls_freeA( controls
);
359 /***********************************************************************
360 * ldap_free_controlsW (WLDAP32.@)
362 * Free an array of LDAPControl structures.
365 * controls [I] Array of LDAPControl structures to free.
371 * Obsolete, use ldap_controls_freeW.
373 ULONG CDECL
ldap_free_controlsW( LDAPControlW
**controls
)
375 return ldap_controls_freeW( controls
);