Commit | Line | Data |
---|---|---|
907be53b HL |
1 | /* |
2 | * WLDAP32 - LDAP support for Wine | |
3 | * | |
4 | * Copyright 2005 Hans Leidekker | |
5 | * | |
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. | |
10 | * | |
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. | |
15 | * | |
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 | |
360a3f91 | 18 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA |
907be53b HL |
19 | */ |
20 | ||
21 | #include "config.h" | |
22 | ||
23 | #include "wine/port.h" | |
24 | #include "wine/debug.h" | |
25 | ||
26 | #include <stdarg.h> | |
27 | ||
28 | #include "windef.h" | |
29 | #include "winbase.h" | |
30 | #include "winnls.h" | |
31 | ||
32 | #ifdef HAVE_LDAP_H | |
33 | #include <ldap.h> | |
907be53b HL |
34 | #endif |
35 | ||
36 | #include "winldap_private.h" | |
37 | #include "wldap32.h" | |
38 | ||
39 | WINE_DEFAULT_DEBUG_CHANNEL(wldap32); | |
40 | ||
7849ea59 HL |
41 | /*********************************************************************** |
42 | * ldap_control_freeA (WLDAP32.@) | |
43 | * | |
44 | * See ldap_control_freeW. | |
45 | */ | |
91e45c62 | 46 | ULONG CDECL ldap_control_freeA( LDAPControlA *control ) |
907be53b | 47 | { |
46906871 | 48 | ULONG ret = WLDAP32_LDAP_SUCCESS; |
907be53b HL |
49 | #ifdef HAVE_LDAP |
50 | ||
51 | TRACE( "(%p)\n", control ); | |
52 | controlfreeA( control ); | |
53 | ||
54 | #endif | |
55 | return ret; | |
56 | } | |
57 | ||
7849ea59 HL |
58 | /*********************************************************************** |
59 | * ldap_control_freeW (WLDAP32.@) | |
60 | * | |
61 | * Free an LDAPControl structure. | |
62 | * | |
548d0888 | 63 | * PARAMS |
7849ea59 HL |
64 | * control [I] LDAPControl structure to free. |
65 | * | |
66 | * RETURNS | |
67 | * LDAP_SUCCESS | |
68 | */ | |
91e45c62 | 69 | ULONG CDECL ldap_control_freeW( LDAPControlW *control ) |
907be53b | 70 | { |
46906871 | 71 | ULONG ret = WLDAP32_LDAP_SUCCESS; |
907be53b HL |
72 | #ifdef HAVE_LDAP |
73 | ||
74 | TRACE( "(%p)\n", control ); | |
75 | controlfreeW( control ); | |
76 | ||
77 | #endif | |
78 | return ret; | |
79 | } | |
80 | ||
7849ea59 HL |
81 | /*********************************************************************** |
82 | * ldap_controls_freeA (WLDAP32.@) | |
83 | * | |
84 | * See ldap_controls_freeW. | |
85 | */ | |
91e45c62 | 86 | ULONG CDECL ldap_controls_freeA( LDAPControlA **controls ) |
907be53b | 87 | { |
46906871 | 88 | ULONG ret = WLDAP32_LDAP_SUCCESS; |
907be53b HL |
89 | #ifdef HAVE_LDAP |
90 | ||
91 | TRACE( "(%p)\n", controls ); | |
92 | controlarrayfreeA( controls ); | |
93 | ||
94 | #endif | |
95 | return ret; | |
96 | } | |
97 | ||
7849ea59 HL |
98 | /*********************************************************************** |
99 | * ldap_controls_freeW (WLDAP32.@) | |
100 | * | |
101 | * Free an array of LDAPControl structures. | |
102 | * | |
548d0888 | 103 | * PARAMS |
7849ea59 HL |
104 | * controls [I] Array of LDAPControl structures to free. |
105 | * | |
106 | * RETURNS | |
107 | * LDAP_SUCCESS | |
108 | */ | |
91e45c62 | 109 | ULONG CDECL ldap_controls_freeW( LDAPControlW **controls ) |
907be53b | 110 | { |
46906871 | 111 | ULONG ret = WLDAP32_LDAP_SUCCESS; |
907be53b HL |
112 | #ifdef HAVE_LDAP |
113 | ||
114 | TRACE( "(%p)\n", controls ); | |
115 | controlarrayfreeW( controls ); | |
116 | ||
117 | #endif | |
118 | return ret; | |
119 | } | |
120 | ||
7849ea59 HL |
121 | /*********************************************************************** |
122 | * ldap_create_sort_controlA (WLDAP32.@) | |
123 | * | |
124 | * See ldap_create_sort_controlW. | |
125 | */ | |
91e45c62 | 126 | ULONG CDECL ldap_create_sort_controlA( WLDAP32_LDAP *ld, PLDAPSortKeyA *sortkey, |
8be6ee36 HL |
127 | UCHAR critical, PLDAPControlA *control ) |
128 | { | |
46906871 | 129 | ULONG ret = WLDAP32_LDAP_NOT_SUPPORTED; |
8be6ee36 HL |
130 | #ifdef HAVE_LDAP |
131 | LDAPSortKeyW **sortkeyW = NULL; | |
132 | LDAPControlW *controlW = NULL; | |
133 | ||
134 | TRACE( "(%p, %p, 0x%02x, %p)\n", ld, sortkey, critical, control ); | |
135 | ||
136 | if (!ld || !sortkey || !control) | |
137 | return WLDAP32_LDAP_PARAM_ERROR; | |
138 | ||
139 | sortkeyW = sortkeyarrayAtoW( sortkey ); | |
140 | if (!sortkeyW) return WLDAP32_LDAP_NO_MEMORY; | |
141 | ||
142 | ret = ldap_create_sort_controlW( ld, sortkeyW, critical, &controlW ); | |
143 | ||
144 | *control = controlWtoA( controlW ); | |
145 | if (!*control) ret = WLDAP32_LDAP_NO_MEMORY; | |
146 | ||
147 | ldap_control_freeW( controlW ); | |
148 | sortkeyarrayfreeW( sortkeyW ); | |
149 | ||
150 | #endif | |
151 | return ret; | |
152 | } | |
153 | ||
7849ea59 HL |
154 | /*********************************************************************** |
155 | * ldap_create_sort_controlW (WLDAP32.@) | |
156 | * | |
157 | * Create a control for server sorted search results. | |
158 | * | |
548d0888 | 159 | * PARAMS |
7849ea59 HL |
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 | |
165 | * search operation. | |
166 | * control [O] LDAPControl created. | |
167 | * | |
168 | * RETURNS | |
169 | * Success: LDAP_SUCCESS | |
170 | * Failure: An LDAP error code. | |
171 | * | |
172 | * NOTES | |
173 | * Pass the created control as a server control in subsequent calls | |
174 | * to ldap_search_ext(_s) to obtain sorted search results. | |
175 | */ | |
91e45c62 | 176 | ULONG CDECL ldap_create_sort_controlW( WLDAP32_LDAP *ld, PLDAPSortKeyW *sortkey, |
8be6ee36 HL |
177 | UCHAR critical, PLDAPControlW *control ) |
178 | { | |
46906871 | 179 | ULONG ret = WLDAP32_LDAP_NOT_SUPPORTED; |
8be6ee36 HL |
180 | #ifdef HAVE_LDAP |
181 | LDAPSortKey **sortkeyU = NULL; | |
182 | LDAPControl *controlU = NULL; | |
183 | ||
184 | TRACE( "(%p, %p, 0x%02x, %p)\n", ld, sortkey, critical, control ); | |
185 | ||
186 | if (!ld || !sortkey || !control) | |
187 | return WLDAP32_LDAP_PARAM_ERROR; | |
188 | ||
189 | sortkeyU = sortkeyarrayWtoU( sortkey ); | |
190 | if (!sortkeyU) return WLDAP32_LDAP_NO_MEMORY; | |
191 | ||
192 | ret = ldap_create_sort_control( ld, sortkeyU, critical, &controlU ); | |
193 | ||
194 | *control = controlUtoW( controlU ); | |
195 | if (!*control) ret = WLDAP32_LDAP_NO_MEMORY; | |
196 | ||
197 | ldap_control_free( controlU ); | |
198 | sortkeyarrayfreeU( sortkeyU ); | |
199 | ||
200 | #endif | |
201 | return ret; | |
202 | } | |
203 | ||
7849ea59 HL |
204 | /*********************************************************************** |
205 | * ldap_create_vlv_controlA (WLDAP32.@) | |
206 | * | |
207 | * See ldap_create_vlv_controlW. | |
208 | */ | |
91e45c62 | 209 | INT CDECL ldap_create_vlv_controlA( WLDAP32_LDAP *ld, WLDAP32_LDAPVLVInfo *info, |
f667584a | 210 | UCHAR critical, LDAPControlA **control ) |
abb5d46d | 211 | { |
46906871 | 212 | INT ret = WLDAP32_LDAP_NOT_SUPPORTED; |
abb5d46d | 213 | #ifdef HAVE_LDAP |
1bf5e2da | 214 | LDAPControlW *controlW = NULL; |
abb5d46d HL |
215 | |
216 | TRACE( "(%p, %p, 0x%02x, %p)\n", ld, info, critical, control ); | |
217 | ||
1bf5e2da | 218 | if (!ld || !control) return ~0UL; |
abb5d46d | 219 | |
1bf5e2da | 220 | ret = ldap_create_vlv_controlW( ld, info, critical, &controlW ); |
abb5d46d | 221 | |
46906871 | 222 | if (ret == WLDAP32_LDAP_SUCCESS) |
1bf5e2da HL |
223 | { |
224 | *control = controlWtoA( controlW ); | |
225 | if (!*control) ret = WLDAP32_LDAP_NO_MEMORY; | |
226 | ldap_control_freeW( controlW ); | |
227 | } | |
abb5d46d HL |
228 | |
229 | #endif | |
230 | return ret; | |
231 | } | |
232 | ||
7849ea59 HL |
233 | /*********************************************************************** |
234 | * ldap_create_vlv_controlW (WLDAP32.@) | |
235 | * | |
236 | * Create a virtual list view control. | |
237 | * | |
548d0888 | 238 | * PARAMS |
7849ea59 HL |
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 | |
242 | * search operation. | |
243 | * control [O] LDAPControl created. | |
244 | * | |
245 | * RETURNS | |
246 | * Success: LDAP_SUCCESS | |
247 | * Failure: An LDAP error code. | |
248 | * | |
249 | * NOTES | |
79c0bc28 | 250 | * Pass the created control in conjunction with a sort control as |
7849ea59 HL |
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. | |
254 | */ | |
91e45c62 | 255 | INT CDECL ldap_create_vlv_controlW( WLDAP32_LDAP *ld, WLDAP32_LDAPVLVInfo *info, |
f667584a | 256 | UCHAR critical, LDAPControlW **control ) |
abb5d46d | 257 | { |
46906871 | 258 | INT ret = WLDAP32_LDAP_NOT_SUPPORTED; |
abb5d46d | 259 | #ifdef HAVE_LDAP |
1bf5e2da | 260 | LDAPControl *controlU = NULL; |
abb5d46d HL |
261 | |
262 | TRACE( "(%p, %p, 0x%02x, %p)\n", ld, info, critical, control ); | |
263 | ||
1bf5e2da | 264 | if (!ld || !control) return ~0UL; |
abb5d46d | 265 | |
1bf5e2da | 266 | ret = ldap_create_vlv_control( ld, (LDAPVLVInfo *)info, &controlU ); |
abb5d46d | 267 | |
1bf5e2da HL |
268 | if (ret == LDAP_SUCCESS) |
269 | { | |
270 | *control = controlUtoW( controlU ); | |
271 | if (!*control) ret = WLDAP32_LDAP_NO_MEMORY; | |
272 | ldap_control_free( controlU ); | |
273 | } | |
abb5d46d HL |
274 | |
275 | #endif | |
276 | return ret; | |
277 | } | |
278 | ||
7849ea59 HL |
279 | /*********************************************************************** |
280 | * ldap_encode_sort_controlA (WLDAP32.@) | |
281 | * | |
282 | * See ldap_encode_sort_controlW. | |
283 | */ | |
91e45c62 | 284 | ULONG CDECL ldap_encode_sort_controlA( WLDAP32_LDAP *ld, PLDAPSortKeyA *sortkeys, |
abb5d46d HL |
285 | PLDAPControlA control, BOOLEAN critical ) |
286 | { | |
287 | return ldap_create_sort_controlA( ld, sortkeys, critical, &control ); | |
288 | } | |
289 | ||
7849ea59 HL |
290 | /*********************************************************************** |
291 | * ldap_encode_sort_controlW (WLDAP32.@) | |
292 | * | |
293 | * Create a control for server sorted search results. | |
294 | * | |
548d0888 | 295 | * PARAMS |
7849ea59 HL |
296 | * ld [I] Pointer to an LDAP context. |
297 | * sortkey [I] Array of LDAPSortKey structures, each specifying an | |
298 | * attribute to use as a sort key, a matching rule and | |
299 | * the sort order (ascending or descending). | |
300 | * critical [I] Tells the server this control is critical to the | |
301 | * search operation. | |
302 | * control [O] LDAPControl created. | |
303 | * | |
304 | * RETURNS | |
305 | * Success: LDAP_SUCCESS | |
306 | * Failure: An LDAP error code. | |
307 | * | |
308 | * NOTES | |
309 | * This function is obsolete. Use its equivalent | |
310 | * ldap_create_sort_control instead. | |
311 | */ | |
91e45c62 | 312 | ULONG CDECL ldap_encode_sort_controlW( WLDAP32_LDAP *ld, PLDAPSortKeyW *sortkeys, |
abb5d46d HL |
313 | PLDAPControlW control, BOOLEAN critical ) |
314 | { | |
315 | return ldap_create_sort_controlW( ld, sortkeys, critical, &control ); | |
316 | } | |
317 | ||
7849ea59 HL |
318 | /*********************************************************************** |
319 | * ldap_free_controlsA (WLDAP32.@) | |
320 | * | |
321 | * See ldap_free_controlsW. | |
322 | */ | |
91e45c62 | 323 | ULONG CDECL ldap_free_controlsA( LDAPControlA **controls ) |
907be53b HL |
324 | { |
325 | return ldap_controls_freeA( controls ); | |
326 | } | |
327 | ||
7849ea59 HL |
328 | /*********************************************************************** |
329 | * ldap_free_controlsW (WLDAP32.@) | |
330 | * | |
331 | * Free an array of LDAPControl structures. | |
332 | * | |
548d0888 | 333 | * PARAMS |
7849ea59 HL |
334 | * controls [I] Array of LDAPControl structures to free. |
335 | * | |
336 | * RETURNS | |
337 | * LDAP_SUCCESS | |
338 | * | |
339 | * NOTES | |
340 | * Obsolete, use ldap_controls_freeW. | |
341 | */ | |
91e45c62 | 342 | ULONG CDECL ldap_free_controlsW( LDAPControlW **controls ) |
907be53b HL |
343 | { |
344 | return ldap_controls_freeW( controls ); | |
345 | } |