Implement LDAP_OPT_API_FEATURE_INFO and LDAP_OPT_API_INFO.
[wine] / dlls / wldap32 / option.c
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
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
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>
34 #else
35 #define LDAP_NOT_SUPPORTED  0x5c
36 #endif
37
38 #include "winldap_private.h"
39 #include "wldap32.h"
40
41 WINE_DEFAULT_DEBUG_CHANNEL(wldap32);
42
43 ULONG ldap_get_optionA( WLDAP32_LDAP *ld, int option, void *value )
44 {
45     ULONG ret = LDAP_NOT_SUPPORTED;
46 #ifdef HAVE_LDAP
47
48     TRACE( "(%p, 0x%08x, %p)\n", ld, option, value );
49
50     if (!ld || !value) return WLDAP32_LDAP_PARAM_ERROR;
51
52     switch (option)
53     {
54     case LDAP_OPT_API_FEATURE_INFO:
55     {
56         LDAPAPIFeatureInfoW featureW;
57         LDAPAPIFeatureInfoA *featureA = value;
58
59         if (!featureA->ldapaif_name) return WLDAP32_LDAP_PARAM_ERROR;
60
61         featureW.ldapaif_info_version = featureA->ldapaif_info_version;
62         featureW.ldapaif_name = strAtoW( featureA->ldapaif_name );
63         featureW.ldapaif_version = 0;
64
65         if (!featureW.ldapaif_name) return WLDAP32_LDAP_NO_MEMORY;
66
67         ret = ldap_get_optionW( ld, option, &featureW );
68
69         featureA->ldapaif_version = featureW.ldapaif_version;
70         strfreeW( featureW.ldapaif_name );
71         return ret;
72     }
73     case LDAP_OPT_API_INFO:
74     {
75         LDAPAPIInfoW infoW;
76         LDAPAPIInfoA *infoA = value;
77
78         memset( &infoW, 0, sizeof(LDAPAPIInfoW) );
79         infoW.ldapai_info_version = infoA->ldapai_info_version;
80
81         ret = ldap_get_optionW( ld, option, &infoW );
82
83         infoA->ldapai_api_version = infoW.ldapai_api_version;
84         infoA->ldapai_protocol_version = infoW.ldapai_protocol_version;
85
86         if (infoW.ldapai_extensions)
87         {
88             infoA->ldapai_extensions = strarrayWtoA( infoW.ldapai_extensions );
89             if (!infoA->ldapai_extensions) return WLDAP32_LDAP_NO_MEMORY;
90         }
91         if (infoW.ldapai_vendor_name)
92         {
93             infoA->ldapai_vendor_name = strWtoA( infoW.ldapai_vendor_name );
94             if (!infoA->ldapai_vendor_name)
95             {
96                 ldap_value_freeW( infoW.ldapai_extensions );
97                 return WLDAP32_LDAP_NO_MEMORY;
98             }
99         }
100         infoA->ldapai_vendor_version = infoW.ldapai_vendor_version;
101
102         ldap_value_freeW( infoW.ldapai_extensions );
103         ldap_memfreeW( infoW.ldapai_vendor_name );
104         return ret;
105     }
106
107     case LDAP_OPT_DEREF:
108     case LDAP_OPT_DESC:
109     case LDAP_OPT_ERROR_NUMBER:
110     case LDAP_OPT_PROTOCOL_VERSION:
111     case LDAP_OPT_REFERRALS:
112     case LDAP_OPT_SIZELIMIT:
113     case LDAP_OPT_TIMELIMIT:
114         return ldap_get_optionW( ld, option, value );
115
116     case LDAP_OPT_CACHE_ENABLE:
117     case LDAP_OPT_CACHE_FN_PTRS:
118     case LDAP_OPT_CACHE_STRATEGY:
119     case LDAP_OPT_IO_FN_PTRS:
120     case LDAP_OPT_REBIND_ARG:
121     case LDAP_OPT_REBIND_FN:
122     case LDAP_OPT_RESTART:
123     case LDAP_OPT_THREAD_FN_PTRS:
124         return LDAP_LOCAL_ERROR;
125
126     case LDAP_OPT_AREC_EXCLUSIVE:
127     case LDAP_OPT_AUTO_RECONNECT:
128     case LDAP_OPT_CLIENT_CERTIFICATE:
129     case LDAP_OPT_DNSDOMAIN_NAME:
130     case LDAP_OPT_ENCRYPT:
131     case LDAP_OPT_ERROR_STRING:
132     case LDAP_OPT_FAST_CONCURRENT_BIND:
133     case LDAP_OPT_GETDSNAME_FLAGS:
134     case LDAP_OPT_HOST_NAME:
135     case LDAP_OPT_HOST_REACHABLE:
136     case LDAP_OPT_PING_KEEP_ALIVE:
137     case LDAP_OPT_PING_LIMIT:
138     case LDAP_OPT_PING_WAIT_TIME:
139     case LDAP_OPT_PROMPT_CREDENTIALS:
140     case LDAP_OPT_REF_DEREF_CONN_PER_MSG:
141     case LDAP_OPT_REFERRAL_CALLBACK:
142     case LDAP_OPT_REFERRAL_HOP_LIMIT:
143     case LDAP_OPT_ROOTDSE_CACHE:
144     case LDAP_OPT_SASL_METHOD:
145     case LDAP_OPT_SECURITY_CONTEXT:
146     case LDAP_OPT_SEND_TIMEOUT:
147     case LDAP_OPT_SERVER_CERTIFICATE:
148     case LDAP_OPT_SERVER_ERROR:
149     case LDAP_OPT_SERVER_EXT_ERROR:
150     case LDAP_OPT_SIGN:
151     case LDAP_OPT_SSL:
152     case LDAP_OPT_SSL_INFO:
153     case LDAP_OPT_SSPI_FLAGS:
154     case LDAP_OPT_TCP_KEEPALIVE:
155         FIXME( "Unsupported option: 0x%02x\n", option );
156         return LDAP_NOT_SUPPORTED;
157
158     default:
159         FIXME( "Unknown option: 0x%02x\n", option );
160         return LDAP_LOCAL_ERROR;
161     }
162
163 #endif
164     return ret;
165 }
166
167 ULONG ldap_get_optionW( WLDAP32_LDAP *ld, int option, void *value )
168 {
169     ULONG ret = LDAP_NOT_SUPPORTED;
170 #ifdef HAVE_LDAP
171
172     TRACE( "(%p, 0x%08x, %p)\n", ld, option, value );
173
174     if (!ld || !value) return WLDAP32_LDAP_PARAM_ERROR;
175
176     switch (option)
177     {
178     case LDAP_OPT_API_FEATURE_INFO:
179     {
180         LDAPAPIFeatureInfo featureU;
181         LDAPAPIFeatureInfoW *featureW = value;
182
183         if (!featureW->ldapaif_name) return WLDAP32_LDAP_PARAM_ERROR;
184
185         featureU.ldapaif_info_version = featureW->ldapaif_info_version;
186         featureU.ldapaif_name = strWtoU( featureW->ldapaif_name );
187         featureU.ldapaif_version = 0;
188
189         if (!featureU.ldapaif_name) return WLDAP32_LDAP_NO_MEMORY;
190
191         ret = ldap_get_option( ld, option, &featureU );
192
193         featureW->ldapaif_version = featureU.ldapaif_version;
194         strfreeU( featureU.ldapaif_name );
195         return ret;
196     }
197     case LDAP_OPT_API_INFO:
198     {
199         LDAPAPIInfo infoU;
200         LDAPAPIInfoW *infoW = value;
201
202         memset( &infoU, 0, sizeof(LDAPAPIInfo) );
203         infoU.ldapai_info_version = infoW->ldapai_info_version;
204
205         ret = ldap_get_option( ld, option, &infoU );
206
207         infoW->ldapai_api_version = infoU.ldapai_api_version;
208         infoW->ldapai_protocol_version = infoU.ldapai_protocol_version;
209
210         if (infoU.ldapai_extensions)
211         {
212             infoW->ldapai_extensions = strarrayUtoW( infoU.ldapai_extensions );
213             if (!infoW->ldapai_extensions) return WLDAP32_LDAP_NO_MEMORY;
214         }
215         if (infoU.ldapai_vendor_name)
216         {
217             infoW->ldapai_vendor_name = strUtoW( infoU.ldapai_vendor_name );
218             if (!infoW->ldapai_vendor_name)
219             {
220                 ldap_value_free( infoU.ldapai_extensions );
221                 return WLDAP32_LDAP_NO_MEMORY;
222             }
223         }
224         infoW->ldapai_vendor_version = infoU.ldapai_vendor_version;
225
226         ldap_value_free( infoU.ldapai_extensions );
227         ldap_memfree( infoU.ldapai_vendor_name );
228         return ret;
229     }
230
231     case LDAP_OPT_DEREF:
232     case LDAP_OPT_DESC:
233     case LDAP_OPT_ERROR_NUMBER:
234     case LDAP_OPT_PROTOCOL_VERSION:
235     case LDAP_OPT_REFERRALS:
236     case LDAP_OPT_SIZELIMIT:
237     case LDAP_OPT_TIMELIMIT:
238         return ldap_get_option( ld, option, value );
239
240     case LDAP_OPT_CACHE_ENABLE:
241     case LDAP_OPT_CACHE_FN_PTRS:
242     case LDAP_OPT_CACHE_STRATEGY:
243     case LDAP_OPT_IO_FN_PTRS:
244     case LDAP_OPT_REBIND_ARG:
245     case LDAP_OPT_REBIND_FN:
246     case LDAP_OPT_RESTART:
247     case LDAP_OPT_THREAD_FN_PTRS:
248         return LDAP_LOCAL_ERROR;
249
250     case LDAP_OPT_AREC_EXCLUSIVE:
251     case LDAP_OPT_AUTO_RECONNECT:
252     case LDAP_OPT_CLIENT_CERTIFICATE:
253     case LDAP_OPT_DNSDOMAIN_NAME:
254     case LDAP_OPT_ENCRYPT:
255     case LDAP_OPT_ERROR_STRING:
256     case LDAP_OPT_FAST_CONCURRENT_BIND:
257     case LDAP_OPT_GETDSNAME_FLAGS:
258     case LDAP_OPT_HOST_NAME:
259     case LDAP_OPT_HOST_REACHABLE:
260     case LDAP_OPT_PING_KEEP_ALIVE:
261     case LDAP_OPT_PING_LIMIT:
262     case LDAP_OPT_PING_WAIT_TIME:
263     case LDAP_OPT_PROMPT_CREDENTIALS:
264     case LDAP_OPT_REF_DEREF_CONN_PER_MSG:
265     case LDAP_OPT_REFERRAL_CALLBACK:
266     case LDAP_OPT_REFERRAL_HOP_LIMIT:
267     case LDAP_OPT_ROOTDSE_CACHE:
268     case LDAP_OPT_SASL_METHOD:
269     case LDAP_OPT_SECURITY_CONTEXT:
270     case LDAP_OPT_SEND_TIMEOUT:
271     case LDAP_OPT_SERVER_CERTIFICATE:
272     case LDAP_OPT_SERVER_ERROR:
273     case LDAP_OPT_SERVER_EXT_ERROR:
274     case LDAP_OPT_SIGN:
275     case LDAP_OPT_SSL:
276     case LDAP_OPT_SSL_INFO:
277     case LDAP_OPT_SSPI_FLAGS:
278     case LDAP_OPT_TCP_KEEPALIVE:
279         FIXME( "Unsupported option: 0x%02x\n", option );
280         return LDAP_NOT_SUPPORTED;
281
282     default:
283         FIXME( "Unknown option: 0x%02x\n", option );
284         return LDAP_LOCAL_ERROR;
285     }
286
287 #endif
288     return ret;
289 }
290
291 ULONG ldap_set_optionA( WLDAP32_LDAP *ld, int option, void *value )
292 {
293     ULONG ret = LDAP_NOT_SUPPORTED;
294 #ifdef HAVE_LDAP
295
296     TRACE( "(%p, 0x%08x, %p)\n", ld, option, value );
297
298     if (!ld || !value) return WLDAP32_LDAP_PARAM_ERROR;
299
300     switch (option)
301     {
302     case LDAP_OPT_DEREF:
303     case LDAP_OPT_DESC:
304     case LDAP_OPT_ERROR_NUMBER:
305     case LDAP_OPT_PROTOCOL_VERSION:
306     case LDAP_OPT_REFERRALS:
307     case LDAP_OPT_SIZELIMIT:
308     case LDAP_OPT_TIMELIMIT:
309         return ldap_set_optionW( ld, option, value );
310
311     case LDAP_OPT_CACHE_ENABLE:
312     case LDAP_OPT_CACHE_FN_PTRS:
313     case LDAP_OPT_CACHE_STRATEGY:
314     case LDAP_OPT_IO_FN_PTRS:
315     case LDAP_OPT_REBIND_ARG:
316     case LDAP_OPT_REBIND_FN:
317     case LDAP_OPT_RESTART:
318     case LDAP_OPT_THREAD_FN_PTRS:
319         return LDAP_LOCAL_ERROR;
320
321     case LDAP_OPT_API_FEATURE_INFO:
322     case LDAP_OPT_API_INFO:
323         return LDAP_UNWILLING_TO_PERFORM;
324
325     case LDAP_OPT_AREC_EXCLUSIVE:
326     case LDAP_OPT_AUTO_RECONNECT:
327     case LDAP_OPT_CLIENT_CERTIFICATE:
328     case LDAP_OPT_DNSDOMAIN_NAME:
329     case LDAP_OPT_ENCRYPT:
330     case LDAP_OPT_ERROR_STRING:
331     case LDAP_OPT_FAST_CONCURRENT_BIND:
332     case LDAP_OPT_GETDSNAME_FLAGS:
333     case LDAP_OPT_HOST_NAME:
334     case LDAP_OPT_HOST_REACHABLE:
335     case LDAP_OPT_PING_KEEP_ALIVE:
336     case LDAP_OPT_PING_LIMIT:
337     case LDAP_OPT_PING_WAIT_TIME:
338     case LDAP_OPT_PROMPT_CREDENTIALS:
339     case LDAP_OPT_REF_DEREF_CONN_PER_MSG:
340     case LDAP_OPT_REFERRAL_CALLBACK:
341     case LDAP_OPT_REFERRAL_HOP_LIMIT:
342     case LDAP_OPT_ROOTDSE_CACHE:
343     case LDAP_OPT_SASL_METHOD:
344     case LDAP_OPT_SECURITY_CONTEXT:
345     case LDAP_OPT_SEND_TIMEOUT:
346     case LDAP_OPT_SERVER_CERTIFICATE:
347     case LDAP_OPT_SERVER_ERROR:
348     case LDAP_OPT_SERVER_EXT_ERROR:
349     case LDAP_OPT_SIGN:
350     case LDAP_OPT_SSL:
351     case LDAP_OPT_SSL_INFO:
352     case LDAP_OPT_SSPI_FLAGS:
353     case LDAP_OPT_TCP_KEEPALIVE:
354         FIXME( "Unsupported option: 0x%02x\n", option );
355         return LDAP_NOT_SUPPORTED;
356
357     default:
358         FIXME( "Unknown option: 0x%02x\n", option );
359         return LDAP_LOCAL_ERROR;
360     }
361
362 #endif
363     return ret;
364 }
365
366 ULONG ldap_set_optionW( WLDAP32_LDAP *ld, int option, void *value )
367 {
368     ULONG ret = LDAP_NOT_SUPPORTED;
369 #ifdef HAVE_LDAP
370
371     TRACE( "(%p, 0x%08x, %p)\n", ld, option, value );
372
373     if (!ld || !value) return WLDAP32_LDAP_PARAM_ERROR;
374
375     switch (option)
376     {
377     case LDAP_OPT_DEREF:
378     case LDAP_OPT_DESC:
379     case LDAP_OPT_ERROR_NUMBER:
380     case LDAP_OPT_PROTOCOL_VERSION:
381     case LDAP_OPT_REFERRALS:
382     case LDAP_OPT_SIZELIMIT:
383     case LDAP_OPT_TIMELIMIT:
384         return ldap_set_option( ld, option, value );
385
386     case LDAP_OPT_CACHE_ENABLE:
387     case LDAP_OPT_CACHE_FN_PTRS:
388     case LDAP_OPT_CACHE_STRATEGY:
389     case LDAP_OPT_IO_FN_PTRS:
390     case LDAP_OPT_REBIND_ARG:
391     case LDAP_OPT_REBIND_FN:
392     case LDAP_OPT_RESTART:
393     case LDAP_OPT_THREAD_FN_PTRS:
394         return LDAP_LOCAL_ERROR;
395
396     case LDAP_OPT_API_FEATURE_INFO:
397     case LDAP_OPT_API_INFO:
398         return LDAP_UNWILLING_TO_PERFORM;
399
400     case LDAP_OPT_AREC_EXCLUSIVE:
401     case LDAP_OPT_AUTO_RECONNECT:
402     case LDAP_OPT_CLIENT_CERTIFICATE:
403     case LDAP_OPT_DNSDOMAIN_NAME:
404     case LDAP_OPT_ENCRYPT:
405     case LDAP_OPT_ERROR_STRING:
406     case LDAP_OPT_FAST_CONCURRENT_BIND:
407     case LDAP_OPT_GETDSNAME_FLAGS:
408     case LDAP_OPT_HOST_NAME:
409     case LDAP_OPT_HOST_REACHABLE:
410     case LDAP_OPT_PING_KEEP_ALIVE:
411     case LDAP_OPT_PING_LIMIT:
412     case LDAP_OPT_PING_WAIT_TIME:
413     case LDAP_OPT_PROMPT_CREDENTIALS:
414     case LDAP_OPT_REF_DEREF_CONN_PER_MSG:
415     case LDAP_OPT_REFERRAL_CALLBACK:
416     case LDAP_OPT_REFERRAL_HOP_LIMIT:
417     case LDAP_OPT_ROOTDSE_CACHE:
418     case LDAP_OPT_SASL_METHOD:
419     case LDAP_OPT_SECURITY_CONTEXT:
420     case LDAP_OPT_SEND_TIMEOUT:
421     case LDAP_OPT_SERVER_CERTIFICATE:
422     case LDAP_OPT_SERVER_ERROR:
423     case LDAP_OPT_SERVER_EXT_ERROR:
424     case LDAP_OPT_SIGN:
425     case LDAP_OPT_SSL:
426     case LDAP_OPT_SSL_INFO:
427     case LDAP_OPT_SSPI_FLAGS:
428     case LDAP_OPT_TCP_KEEPALIVE:
429         FIXME( "Unsupported option: 0x%02x\n", option );
430         return LDAP_NOT_SUPPORTED;
431
432     default:
433         FIXME( "Unknown option: 0x%02x\n", option );
434         return LDAP_LOCAL_ERROR;
435     }
436
437 #endif
438     return ret;
439 }