1 /**
2  * Windows API header module
3  *
4  * Translated from MinGW Windows headers
5  *
6  * Authors: Stewart Gordon
7  * License: $(LINK2 http://www.boost.org/LICENSE_1_0.txt, Boost License 1.0)
8  * Source: $(DRUNTIMESRC core/sys/windows/_winldap.d)
9  */
10 module core.sys.windows.winldap;
11 version (Windows):
12 
13 version (ANSI) {} else version = Unicode;
14 
15 /* Comment from MinGW
16   winldap.h - Header file for the Windows LDAP API
17 
18   Written by Filip Navara <xnavara@volny.cz>
19 
20   References:
21     The C LDAP Application Program Interface
22     http://www.watersprings.org/pub/id/draft-ietf-ldapext-ldap-c-api-05.txt
23 
24     Lightweight Directory Access Protocol Reference
25     http://msdn.microsoft.com/library/en-us/netdir/ldap/ldap_reference.asp
26 
27   This library is distributed in the hope that it will be useful,
28   but WITHOUT ANY WARRANTY; without even the implied warranty of
29   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
30 */
31 
32 import core.sys.windows.schannel, core.sys.windows.winber;
33 import core.sys.windows.wincrypt, core.sys.windows.windef;
34 
35 //align(4):
36 
37 enum {
38     LDAP_VERSION1    = 1,
39     LDAP_VERSION2    = 2,
40     LDAP_VERSION3    = 3,
41     LDAP_VERSION     = LDAP_VERSION2,
42     LDAP_VERSION_MIN = LDAP_VERSION2,
43     LDAP_VERSION_MAX = LDAP_VERSION3
44 }
45 
46 /*  MinGW defines ANSI and Unicode versions as LDAP_VENDOR_NAME and
47  *  LDAP_VENDOR_NAME_W respectively; similarly with other string constants
48  *  defined in this module.
49  */
50 const TCHAR[] LDAP_VENDOR_NAME = "Microsoft Corporation.";
51 
52 enum LDAP_API_VERSION          = 2004;
53 enum LDAP_VENDOR_VERSION       =  510;
54 enum LDAP_API_INFO_VERSION     =    1;
55 enum LDAP_FEATURE_INFO_VERSION =    1;
56 
57 enum {
58     LDAP_SUCCESS                    = 0x00,
59     LDAP_OPT_SUCCESS                = LDAP_SUCCESS,
60     LDAP_OPERATIONS_ERROR,
61     LDAP_PROTOCOL_ERROR,
62     LDAP_TIMELIMIT_EXCEEDED,
63     LDAP_SIZELIMIT_EXCEEDED,
64     LDAP_COMPARE_FALSE,
65     LDAP_COMPARE_TRUE,
66     LDAP_STRONG_AUTH_NOT_SUPPORTED,
67     LDAP_AUTH_METHOD_NOT_SUPPORTED  = LDAP_STRONG_AUTH_NOT_SUPPORTED,
68     LDAP_STRONG_AUTH_REQUIRED,
69     LDAP_REFERRAL_V2,
70     LDAP_PARTIAL_RESULTS            = LDAP_REFERRAL_V2,
71     LDAP_REFERRAL,
72     LDAP_ADMIN_LIMIT_EXCEEDED,
73     LDAP_UNAVAILABLE_CRIT_EXTENSION,
74     LDAP_CONFIDENTIALITY_REQUIRED,
75     LDAP_SASL_BIND_IN_PROGRESS,  // = 0x0e
76     LDAP_NO_SUCH_ATTRIBUTE          = 0x10,
77     LDAP_UNDEFINED_TYPE,
78     LDAP_INAPPROPRIATE_MATCHING,
79     LDAP_CONSTRAINT_VIOLATION,
80     LDAP_TYPE_OR_VALUE_EXISTS,
81     LDAP_ATTRIBUTE_OR_VALUE_EXISTS  = LDAP_TYPE_OR_VALUE_EXISTS,
82     LDAP_INVALID_SYNTAX,         // = 0x15
83     LDAP_NO_SUCH_OBJECT             = 0x20,
84     LDAP_ALIAS_PROBLEM,
85     LDAP_INVALID_DN_SYNTAX,
86     LDAP_IS_LEAF,
87     LDAP_ALIAS_DEREF_PROBLEM,    // = 0x24
88     LDAP_INAPPROPRIATE_AUTH         = 0x30,
89     LDAP_INVALID_CREDENTIALS,
90     LDAP_INSUFFICIENT_ACCESS,
91     LDAP_INSUFFICIENT_RIGHTS        = LDAP_INSUFFICIENT_ACCESS,
92     LDAP_BUSY,
93     LDAP_UNAVAILABLE,
94     LDAP_UNWILLING_TO_PERFORM,
95     LDAP_LOOP_DETECT,            // = 0x36
96     LDAP_NAMING_VIOLATION           = 0x40,
97     LDAP_OBJECT_CLASS_VIOLATION,
98     LDAP_NOT_ALLOWED_ON_NONLEAF,
99     LDAP_NOT_ALLOWED_ON_RDN,
100     LDAP_ALREADY_EXISTS,
101     LDAP_NO_OBJECT_CLASS_MODS,
102     LDAP_RESULTS_TOO_LARGE,
103     LDAP_AFFECTS_MULTIPLE_DSAS,  // = 0x47
104     LDAP_OTHER                      = 0x50,
105     LDAP_SERVER_DOWN,
106     LDAP_LOCAL_ERROR,
107     LDAP_ENCODING_ERROR,
108     LDAP_DECODING_ERROR,
109     LDAP_TIMEOUT,
110     LDAP_AUTH_UNKNOWN,
111     LDAP_FILTER_ERROR,
112     LDAP_USER_CANCELLED,
113     LDAP_PARAM_ERROR,
114     LDAP_NO_MEMORY,
115     LDAP_CONNECT_ERROR,
116     LDAP_NOT_SUPPORTED,
117     LDAP_CONTROL_NOT_FOUND,
118     LDAP_NO_RESULTS_RETURNED,
119     LDAP_MORE_RESULTS_TO_RETURN,
120     LDAP_CLIENT_LOOP,
121     LDAP_REFERRAL_LIMIT_EXCEEDED // = 0x61
122 }
123 
124 enum {
125     LDAP_PORT        =  389,
126     LDAP_SSL_PORT    =  636,
127     LDAP_GC_PORT     = 3268,
128     LDAP_SSL_GC_PORT = 3269
129 }
130 
131 enum void*
132     LDAP_OPT_OFF = null,
133     LDAP_OPT_ON = cast(void*) 1;
134 
135 enum {
136     LDAP_OPT_API_INFO               = 0x00,
137     LDAP_OPT_DESC,
138     LDAP_OPT_DEREF,
139     LDAP_OPT_SIZELIMIT,
140     LDAP_OPT_TIMELIMIT,
141     LDAP_OPT_THREAD_FN_PTRS,
142     LDAP_OPT_REBIND_FN,
143     LDAP_OPT_REBIND_ARG,
144     LDAP_OPT_REFERRALS,
145     LDAP_OPT_RESTART,
146     LDAP_OPT_SSL,
147     LDAP_OPT_TLS                    = LDAP_OPT_SSL,
148     LDAP_OPT_IO_FN_PTRS,         // = 0x0b
149     LDAP_OPT_CACHE_FN_PTRS          = 0x0d,
150     LDAP_OPT_CACHE_STRATEGY,
151     LDAP_OPT_CACHE_ENABLE,
152     LDAP_OPT_REFERRAL_HOP_LIMIT,
153     LDAP_OPT_PROTOCOL_VERSION,
154     LDAP_OPT_VERSION                = LDAP_OPT_PROTOCOL_VERSION,
155     LDAP_OPT_SERVER_CONTROLS,
156     LDAP_OPT_CLIENT_CONTROLS,    // = 0x13
157     LDAP_OPT_API_FEATURE_INFO       = 0x15,
158     LDAP_OPT_HOST_NAME              = 0x30,
159     LDAP_OPT_ERROR_NUMBER,
160     LDAP_OPT_ERROR_STRING,
161     LDAP_OPT_SERVER_ERROR,
162     LDAP_OPT_SERVER_EXT_ERROR,   // = 0x34
163     LDAP_OPT_PING_KEEP_ALIVE        = 0x36,
164     LDAP_OPT_PING_WAIT_TIME,
165     LDAP_OPT_PING_LIMIT,         // = 0x38
166     LDAP_OPT_DNSDOMAIN_NAME         = 0x3b,
167     LDAP_OPT_GETDSNAME_FLAGS        = 0x3d,
168     LDAP_OPT_HOST_REACHABLE,
169     LDAP_OPT_PROMPT_CREDENTIALS,
170     LDAP_OPT_TCP_KEEPALIVE,      // = 0x40
171     LDAP_OPT_REFERRAL_CALLBACK      = 0x70,
172     LDAP_OPT_CLIENT_CERTIFICATE     = 0x80,
173     LDAP_OPT_SERVER_CERTIFICATE, // = 0x81
174     LDAP_OPT_AUTO_RECONNECT         = 0x91,
175     LDAP_OPT_SSPI_FLAGS,
176     LDAP_OPT_SSL_INFO,
177     LDAP_OPT_TLS_INFO               = LDAP_OPT_SSL_INFO,
178     LDAP_OPT_REF_DEREF_CONN_PER_MSG,
179     LDAP_OPT_SIGN,
180     LDAP_OPT_ENCRYPT,
181     LDAP_OPT_SASL_METHOD,
182     LDAP_OPT_AREC_EXCLUSIVE,
183     LDAP_OPT_SECURITY_CONTEXT,
184     LDAP_OPT_ROOTDSE_CACHE       // = 0x9a
185 }
186 
187 enum {
188     LDAP_DEREF_NEVER,
189     LDAP_DEREF_SEARCHING,
190     LDAP_DEREF_FINDING,
191     LDAP_DEREF_ALWAYS
192 }
193 
194 enum LDAP_NO_LIMIT = 0;
195 
196 const TCHAR[] LDAP_CONTROL_REFERRALS = "1.2.840.113556.1.4.616";
197 
198 // FIXME: check type (declared with U suffix in MinGW)
199 enum : uint {
200     LDAP_CHASE_SUBORDINATE_REFERRALS = 0x20,
201     LDAP_CHASE_EXTERNAL_REFERRALS    = 0x40
202 }
203 
204 enum {
205     LDAP_SCOPE_DEFAULT = -1,
206     LDAP_SCOPE_BASE,
207     LDAP_SCOPE_ONELEVEL,
208     LDAP_SCOPE_SUBTREE
209 }
210 
211 enum {
212     LDAP_MOD_ADD,
213     LDAP_MOD_DELETE,
214     LDAP_MOD_REPLACE,
215     LDAP_MOD_BVALUES = 0x80
216 }
217 
218 enum : int {
219     LDAP_RES_BIND             = 0x61,
220     LDAP_RES_SEARCH_ENTRY     = 0x64,
221     LDAP_RES_SEARCH_RESULT    = 0x65,
222     LDAP_RES_MODIFY           = 0x67,
223     LDAP_RES_ADD              = 0x69,
224     LDAP_RES_DELETE           = 0x6b,
225     LDAP_RES_MODRDN           = 0x6d,
226     LDAP_RES_COMPARE          = 0x6f,
227     LDAP_RES_SEARCH_REFERENCE = 0x73,
228     LDAP_RES_EXTENDED         = 0x78,
229     LDAP_RES_ANY              = -1
230 }
231 
232 enum {
233     LDAP_MSG_ONE,
234     LDAP_MSG_ALL,
235     LDAP_MSG_RECEIVED
236 }
237 
238 const TCHAR[]
239     LDAP_SERVER_SORT_OID         = "1.2.840.113556.1.4.473",
240     LDAP_SERVER_RESP_SORT_OID    = "1.2.840.113556.1.4.474",
241     LDAP_PAGED_RESULT_OID_STRING = "1.2.840.113556.1.4.319",
242     LDAP_CONTROL_VLVREQUEST      = "2.16.840.1.113730.3.4.9",
243     LDAP_CONTROL_VLVRESPONSE     = "2.16.840.1.113730.3.4.10",
244     LDAP_START_TLS_OID           = "1.3.6.1.4.1.1466.20037",
245     LDAP_TTL_EXTENDED_OP_OID     = "1.3.6.1.4.1.1466.101.119.1";
246 
247 enum {
248     LDAP_AUTH_NONE      = 0x00U,
249     LDAP_AUTH_SIMPLE    = 0x80U,
250     LDAP_AUTH_SASL      = 0x83U,
251     LDAP_AUTH_OTHERKIND = 0x86U,
252     LDAP_AUTH_EXTERNAL  = LDAP_AUTH_OTHERKIND | 0x0020U,
253     LDAP_AUTH_SICILY    = LDAP_AUTH_OTHERKIND | 0x0200U,
254     LDAP_AUTH_NEGOTIATE = LDAP_AUTH_OTHERKIND | 0x0400U,
255     LDAP_AUTH_MSN       = LDAP_AUTH_OTHERKIND | 0x0800U,
256     LDAP_AUTH_NTLM      = LDAP_AUTH_OTHERKIND | 0x1000U,
257     LDAP_AUTH_DIGEST    = LDAP_AUTH_OTHERKIND | 0x4000U,
258     LDAP_AUTH_DPA       = LDAP_AUTH_OTHERKIND | 0x2000U,
259     LDAP_AUTH_SSPI      = LDAP_AUTH_NEGOTIATE
260 }
261 
262 enum {
263     LDAP_FILTER_AND        = 0xa0,
264     LDAP_FILTER_OR,
265     LDAP_FILTER_NOT,
266     LDAP_FILTER_EQUALITY,
267     LDAP_FILTER_SUBSTRINGS,
268     LDAP_FILTER_GE,
269     LDAP_FILTER_LE,     // = 0xa6
270     LDAP_FILTER_APPROX     = 0xa8,
271     LDAP_FILTER_EXTENSIBLE,
272     LDAP_FILTER_PRESENT    = 0x87
273 }
274 
275 enum {
276     LDAP_SUBSTRING_INITIAL = 0x80,
277     LDAP_SUBSTRING_ANY,
278     LDAP_SUBSTRING_FINAL
279 }
280 
281 // should be opaque structure
282 struct LDAP {
283     struct _ld_sp {
284         UINT_PTR sb_sd;
285         UCHAR[(10*ULONG.sizeof)+1] Reserved1;
286         ULONG_PTR sb_naddr;
287         UCHAR[(6*ULONG.sizeof)] Reserved2;
288     }
289     _ld_sp   ld_sp;
290     PCHAR    ld_host;
291     ULONG    ld_version;
292     UCHAR    ld_lberoptions;
293     int      ld_deref;
294     int      ld_timelimit;
295     int      ld_sizelimit;
296     int      ld_errno;
297     PCHAR    ld_matched;
298     PCHAR    ld_error;
299 }
300 alias LDAP* PLDAP;
301 
302 // should be opaque structure
303 struct LDAPMessage {
304     ULONG        lm_msgid;
305     ULONG        lm_msgtype;
306     BerElement*  lm_ber;
307     LDAPMessage* lm_chain;
308     LDAPMessage* lm_next;
309     ULONG        lm_time;
310 }
311 alias LDAPMessage* PLDAPMessage;
312 
313 struct LDAP_TIMEVAL {
314     LONG tv_sec;
315     LONG tv_usec;
316 }
317 alias LDAP_TIMEVAL* PLDAP_TIMEVAL;
318 
319 struct LDAPAPIInfoA {
320     int    ldapai_info_version;
321     int    ldapai_api_version;
322     int    ldapai_protocol_version;
323     char** ldapai_extensions;
324     char*  ldapai_vendor_name;
325     int    ldapai_vendor_version;
326 }
327 alias LDAPAPIInfoA* PLDAPAPIInfoA;
328 
329 struct LDAPAPIInfoW {
330     int     ldapai_info_version;
331     int     ldapai_api_version;
332     int     ldapai_protocol_version;
333     PWCHAR* ldapai_extensions;
334     PWCHAR  ldapai_vendor_name;
335     int     ldapai_vendor_version;
336 }
337 alias LDAPAPIInfoW* PLDAPAPIInfoW;
338 
339 struct LDAPAPIFeatureInfoA {
340     int   ldapaif_info_version;
341     char* ldapaif_name;
342     int   ldapaif_version;
343 }
344 alias LDAPAPIFeatureInfoA* PLDAPAPIFeatureInfoA;
345 
346 struct LDAPAPIFeatureInfoW {
347     int    ldapaif_info_version;
348     PWCHAR ldapaif_name;
349     int    ldapaif_version;
350 }
351 alias LDAPAPIFeatureInfoW* PLDAPAPIFeatureInfoW;
352 
353 struct LDAPControlA {
354     PCHAR    ldctl_oid;
355     BerValue ldctl_value;
356     BOOLEAN  ldctl_iscritical;
357 }
358 alias LDAPControlA* PLDAPControlA;
359 
360 struct LDAPControlW {
361     PWCHAR   ldctl_oid;
362     BerValue ldctl_value;
363     BOOLEAN  ldctl_iscritical;
364 }
365 alias LDAPControlW* PLDAPControlW;
366 
367 /*  Do we really need these?  In MinGW, LDAPModA/W have only mod_op, mod_type
368  *  and mod_vals, and macros are used to simulate anonymous unions in those
369  *  structures.
370  */
371 union mod_vals_u_tA {
372     PCHAR*     modv_strvals;
373     BerValue** modv_bvals;
374 }
375 
376 union mod_vals_u_tW {
377     PWCHAR*    modv_strvals;
378     BerValue** modv_bvals;
379 }
380 
381 struct LDAPModA {
382     ULONG         mod_op;
383     PCHAR         mod_type;
384 
385     union {
386         mod_vals_u_tA mod_vals;
387         // The following members are defined as macros in MinGW.
388         PCHAR*        mod_values;
389         BerValue**    mod_bvalues;
390     }
391 }
392 alias LDAPModA* PLDAPModA;
393 
394 struct LDAPModW {
395     ULONG         mod_op;
396     PWCHAR        mod_type;
397 
398     union {
399         mod_vals_u_tW mod_vals;
400         // The following members are defined as macros in MinGW.
401         PWCHAR*       mod_values;
402         BerValue**    mod_bvalues;
403     }
404 }
405 alias LDAPModW* PLDAPModW;
406 
407 /* Opaque structure
408  *  http://msdn.microsoft.com/library/en-us/ldap/ldap/ldapsearch.asp
409  */
410 struct LDAPSearch;
411 alias LDAPSearch* PLDAPSearch;
412 
413 struct LDAPSortKeyA {
414     PCHAR   sk_attrtype;
415     PCHAR   sk_matchruleoid;
416     BOOLEAN sk_reverseorder;
417 }
418 alias LDAPSortKeyA* PLDAPSortKeyA;
419 
420 struct LDAPSortKeyW {
421     PWCHAR  sk_attrtype;
422     PWCHAR  sk_matchruleoid;
423     BOOLEAN sk_reverseorder;
424 }
425 alias LDAPSortKeyW* PLDAPSortKeyW;
426 
427 /*  MinGW defines these as immediate function typedefs, which don't translate
428  *  well into D.
429  */
430 extern (C) {
431     alias ULONG function(PLDAP, PLDAP, PWCHAR, PCHAR, ULONG, PVOID, PVOID,
432       PLDAP*) QUERYFORCONNECTION;
433     alias BOOLEAN function(PLDAP, PLDAP, PWCHAR, PCHAR, PLDAP, ULONG, PVOID,
434       PVOID, ULONG) NOTIFYOFNEWCONNECTION;
435     alias ULONG function(PLDAP, PLDAP) DEREFERENCECONNECTION;
436     alias BOOLEAN function(PLDAP, PSecPkgContext_IssuerListInfoEx,
437       PCCERT_CONTEXT*) QUERYCLIENTCERT;
438 }
439 
440 struct LDAP_REFERRAL_CALLBACK {
441     ULONG                  SizeOfCallbacks;
442     QUERYFORCONNECTION*    QueryForConnection;
443     NOTIFYOFNEWCONNECTION* NotifyRoutine;
444     DEREFERENCECONNECTION* DereferenceRoutine;
445 }
446 alias LDAP_REFERRAL_CALLBACK* PLDAP_REFERRAL_CALLBACK;
447 
448 struct LDAPVLVInfo {
449     int       ldvlv_version;
450     uint      ldvlv_before_count;
451     uint      ldvlv_after_count;
452     uint      ldvlv_offset;
453     uint      ldvlv_count;
454     BerValue* ldvlv_attrvalue;
455     BerValue* ldvlv_context;
456     void*     ldvlv_extradata;
457 }
458 
459 /*
460  * Under Microsoft WinLDAP the function ldap_error is only stub.
461  * This macro uses LDAP structure to get error string and pass it to the user.
462  */
463 private extern (C) int printf(const scope char* format, ...);
464 int ldap_perror(LDAP* handle, char* message) {
465     return printf("%s: %s\n", message, handle.ld_error);
466 }
467 
468 /*  FIXME: In MinGW, these are WINLDAPAPI == DECLSPEC_IMPORT.  Linkage
469  *  attribute?
470  */
471 extern (C) {
472     PLDAP ldap_initA(PCHAR, ULONG);
473     PLDAP ldap_initW(PWCHAR, ULONG);
474     PLDAP ldap_openA(PCHAR, ULONG);
475     PLDAP ldap_openW(PWCHAR, ULONG);
476     PLDAP cldap_openA(PCHAR, ULONG);
477     PLDAP cldap_openW(PWCHAR, ULONG);
478     ULONG ldap_connect(LDAP*, LDAP_TIMEVAL*);
479     PLDAP ldap_sslinitA(PCHAR, ULONG, int);
480     PLDAP ldap_sslinitW(PWCHAR, ULONG, int);
481     ULONG ldap_start_tls_sA(LDAP*, PLDAPControlA*, PLDAPControlA*);
482     ULONG ldap_start_tls_sW(LDAP*, PLDAPControlW*, PLDAPControlW*);
483     BOOLEAN ldap_stop_tls_s(LDAP*);
484     ULONG ldap_get_optionA(LDAP*, int, void*);
485     ULONG ldap_get_optionW(LDAP*, int, void*);
486     ULONG ldap_set_optionA(LDAP*, int, void*);
487     ULONG ldap_set_optionW(LDAP*, int, void*);
488     ULONG ldap_control_freeA(LDAPControlA*);
489     ULONG ldap_control_freeW(LDAPControlW*);
490     ULONG ldap_controls_freeA(LDAPControlA**);
491     ULONG ldap_controls_freeW(LDAPControlW**);
492     ULONG ldap_free_controlsA(LDAPControlA**);
493     ULONG ldap_free_controlsW(LDAPControlW**);
494     ULONG ldap_sasl_bindA(LDAP*, PCSTR, PCSTR, BERVAL*, PLDAPControlA*,
495       PLDAPControlA*, int*);
496     ULONG ldap_sasl_bindW(LDAP*, PCWSTR, PCWSTR, BERVAL*, PLDAPControlW*,
497       PLDAPControlW*, int*);
498     ULONG ldap_sasl_bind_sA(LDAP*, PCSTR, PCSTR, BERVAL*, PLDAPControlA*,
499       PLDAPControlA*, PBERVAL*);
500     ULONG ldap_sasl_bind_sW(LDAP*, PCWSTR, PCWSTR, BERVAL*, PLDAPControlW*,
501       PLDAPControlW*, PBERVAL*);
502     ULONG ldap_simple_bindA(LDAP*, PSTR, PSTR);
503     ULONG ldap_simple_bindW(LDAP*, PWSTR, PWSTR);
504     ULONG ldap_simple_bind_sA(LDAP*, PSTR, PSTR);
505     ULONG ldap_simple_bind_sW(LDAP*, PWSTR, PWSTR);
506     ULONG ldap_unbind(LDAP*);
507     ULONG ldap_unbind_s(LDAP*);
508     ULONG ldap_search_extA(LDAP*, PCSTR, ULONG, PCSTR, PZPSTR, ULONG,
509       PLDAPControlA*, PLDAPControlA*, ULONG, ULONG, ULONG*);
510     ULONG ldap_search_extW(LDAP*, PCWSTR, ULONG, PCWSTR, PZPWSTR, ULONG,
511       PLDAPControlW*, PLDAPControlW*, ULONG, ULONG, ULONG*);
512     ULONG ldap_search_ext_sA(LDAP*, PCSTR, ULONG, PCSTR, PZPSTR, ULONG,
513       PLDAPControlA*, PLDAPControlA*, LDAP_TIMEVAL*, ULONG, PLDAPMessage*);
514     ULONG ldap_search_ext_sW(LDAP*, PCWSTR, ULONG, PCWSTR, PZPWSTR, ULONG,
515       PLDAPControlW*, PLDAPControlW*, LDAP_TIMEVAL*, ULONG, PLDAPMessage*);
516     ULONG ldap_searchA(LDAP*, PCSTR, ULONG, PCSTR, PZPSTR, ULONG);
517     ULONG ldap_searchW(LDAP*, PCWSTR, ULONG, PCWSTR, PZPWSTR, ULONG);
518     ULONG ldap_search_sA(LDAP*, PCSTR, ULONG, PCSTR, PZPSTR, ULONG,
519       PLDAPMessage*);
520     ULONG ldap_search_sW(LDAP*, PCWSTR, ULONG, PCWSTR, PZPWSTR, ULONG,
521       PLDAPMessage*);
522     ULONG ldap_search_stA(LDAP*, PCSTR, ULONG, PCSTR, PZPSTR, ULONG,
523       LDAP_TIMEVAL*, PLDAPMessage*);
524     ULONG ldap_search_stW(LDAP*, PCWSTR, ULONG, PCWSTR, PZPWSTR, ULONG,
525       LDAP_TIMEVAL*, PLDAPMessage*);
526     ULONG ldap_compare_extA(LDAP*, PCSTR, PCSTR, PCSTR, BerValue*,
527       PLDAPControlA*, PLDAPControlA*, ULONG*);
528     ULONG ldap_compare_extW(LDAP*, PCWSTR, PCWSTR, PCWSTR, BerValue*,
529       PLDAPControlW*, PLDAPControlW*, ULONG*);
530     ULONG ldap_compare_ext_sA(LDAP*, PCSTR, PCSTR, PCSTR, BerValue*,
531       PLDAPControlA*, PLDAPControlA*);
532     ULONG ldap_compare_ext_sW(LDAP*, PCWSTR, PCWSTR, PCWSTR, BerValue*,
533       PLDAPControlW*, PLDAPControlW*);
534     ULONG ldap_compareA(LDAP*, PCSTR, PCSTR, PCSTR);
535     ULONG ldap_compareW(LDAP*, PCWSTR, PCWSTR, PCWSTR);
536     ULONG ldap_compare_sA(LDAP*, PCSTR, PCSTR, PCSTR);
537     ULONG ldap_compare_sW(LDAP*, PCWSTR, PCWSTR, PCWSTR);
538     ULONG ldap_modify_extA(LDAP*, PCSTR, LDAPModA**, PLDAPControlA*,
539       PLDAPControlA*, ULONG*);
540     ULONG ldap_modify_extW(LDAP*, PCWSTR, LDAPModW**, PLDAPControlW*,
541       PLDAPControlW*, ULONG*);
542     ULONG ldap_modify_ext_sA(LDAP*, PCSTR, LDAPModA**, PLDAPControlA*,
543       PLDAPControlA*);
544     ULONG ldap_modify_ext_sW(LDAP*, PCWSTR, LDAPModW**, PLDAPControlW*,
545       PLDAPControlW*);
546     ULONG ldap_modifyA(LDAP*, PSTR, LDAPModA**);
547     ULONG ldap_modifyW(LDAP*, PWSTR, LDAPModW**);
548     ULONG ldap_modify_sA(LDAP*, PSTR, LDAPModA**);
549     ULONG ldap_modify_sW(LDAP*, PWSTR, LDAPModW**);
550     ULONG ldap_rename_extA(LDAP*, PCSTR, PCSTR, PCSTR, INT, PLDAPControlA*,
551       PLDAPControlA*, ULONG*);
552     ULONG ldap_rename_extW(LDAP*, PCWSTR, PCWSTR, PCWSTR, INT, PLDAPControlW*,
553       PLDAPControlW*, ULONG*);
554     ULONG ldap_rename_ext_sA(LDAP*, PCSTR, PCSTR, PCSTR, INT,
555       PLDAPControlA*, PLDAPControlA*);
556     ULONG ldap_rename_ext_sW(LDAP*, PCWSTR, PCWSTR, PCWSTR, INT,
557       PLDAPControlW*, PLDAPControlW*);
558     ULONG ldap_add_extA(LDAP*, PCSTR, LDAPModA**, PLDAPControlA*,
559       PLDAPControlA*, ULONG*);
560     ULONG ldap_add_extW(LDAP*, PCWSTR, LDAPModW**, PLDAPControlW*,
561       PLDAPControlW*, ULONG*);
562     ULONG ldap_add_ext_sA(LDAP*, PCSTR, LDAPModA**, PLDAPControlA*,
563       PLDAPControlA*);
564     ULONG ldap_add_ext_sW(LDAP*, PCWSTR, LDAPModW**, PLDAPControlW*,
565       PLDAPControlW*);
566     ULONG ldap_addA(LDAP*, PSTR, LDAPModA**);
567     ULONG ldap_addW(LDAP*, PWSTR, LDAPModW**);
568     ULONG ldap_add_sA(LDAP*, PSTR, LDAPModA**);
569     ULONG ldap_add_sW(LDAP*, PWSTR, LDAPModW**);
570     ULONG ldap_delete_extA(LDAP*, PCSTR, PLDAPControlA*, PLDAPControlA*,
571       ULONG*);
572     ULONG ldap_delete_extW(LDAP*, PCWSTR, PLDAPControlW*, PLDAPControlW*,
573       ULONG*);
574     ULONG ldap_delete_ext_sA(LDAP*, PCSTR, PLDAPControlA*, PLDAPControlA*);
575     ULONG ldap_delete_ext_sW(LDAP*, PCWSTR, PLDAPControlW*, PLDAPControlW*);
576     ULONG ldap_deleteA(LDAP*, PCSTR);
577     ULONG ldap_deleteW(LDAP*, PCWSTR);
578     ULONG ldap_delete_sA(LDAP*, PCSTR);
579     ULONG ldap_delete_sW(LDAP*, PCWSTR);
580     ULONG ldap_extended_operationA(LDAP*, PCSTR, BerValue*, PLDAPControlA*,
581       PLDAPControlA*, ULONG*);
582     ULONG ldap_extended_operationW(LDAP*, PCWSTR, BerValue*, PLDAPControlW*,
583       PLDAPControlW*, ULONG*);
584     ULONG ldap_extended_operation_sA(LDAP*, PSTR, BerValue*, PLDAPControlA*,
585       PLDAPControlA*, PCHAR*, BerValue**);
586     ULONG ldap_extended_operation_sW(LDAP*, PWSTR, BerValue*, PLDAPControlW*,
587       PLDAPControlW*, PWCHAR*, BerValue**);
588     ULONG ldap_close_extended_op(LDAP*, ULONG);
589     ULONG ldap_abandon(LDAP*, ULONG);
590     ULONG ldap_result(LDAP*, ULONG, ULONG, LDAP_TIMEVAL*, LDAPMessage**);
591     ULONG ldap_msgfree(LDAPMessage*);
592     ULONG ldap_parse_resultA(LDAP*, LDAPMessage*, ULONG*, PSTR*, PSTR*,
593       PZPSTR*, PLDAPControlA**, BOOLEAN);
594     ULONG ldap_parse_resultW(LDAP*, LDAPMessage*, ULONG*, PWSTR*, PWSTR*,
595       PZPWSTR*, PLDAPControlW**, BOOLEAN);
596     ULONG ldap_parse_extended_resultA(LDAP, LDAPMessage*, PSTR*, BerValue**,
597       BOOLEAN);
598     ULONG ldap_parse_extended_resultW(LDAP, LDAPMessage*, PWSTR*, BerValue**,
599       BOOLEAN);
600     PCHAR ldap_err2stringA(ULONG);
601     PWCHAR ldap_err2stringW(ULONG);
602     ULONG LdapGetLastError();
603     ULONG LdapMapErrorToWin32(ULONG);
604     ULONG ldap_result2error(LDAP*, LDAPMessage*, ULONG);
605     PLDAPMessage ldap_first_entry(LDAP*, LDAPMessage*);
606     PLDAPMessage ldap_next_entry(LDAP*, LDAPMessage*);
607     PLDAPMessage ldap_first_reference(LDAP*, LDAPMessage*);
608     PLDAPMessage ldap_next_reference(LDAP*, LDAPMessage*);
609     ULONG ldap_count_entries(LDAP*, LDAPMessage*);
610     ULONG ldap_count_references(LDAP*, LDAPMessage*);
611     PCHAR ldap_first_attributeA(LDAP*, LDAPMessage*, BerElement**);
612     PWCHAR ldap_first_attributeW(LDAP*, LDAPMessage*, BerElement**);
613     PCHAR ldap_next_attributeA(LDAP*, LDAPMessage*, BerElement*);
614     PWCHAR ldap_next_attributeW(LDAP*, LDAPMessage*, BerElement*);
615     VOID ldap_memfreeA(PCHAR);
616     VOID ldap_memfreeW(PWCHAR);
617     PCHAR* ldap_get_valuesA(LDAP*, LDAPMessage*, PCSTR);
618     PWCHAR* ldap_get_valuesW(LDAP*, LDAPMessage*, PCWSTR);
619     BerValue** ldap_get_values_lenA(LDAP*, LDAPMessage*, PCSTR);
620     BerValue** ldap_get_values_lenW(LDAP*, LDAPMessage*, PCWSTR);
621     ULONG ldap_count_valuesA(PCHAR*);
622     ULONG ldap_count_valuesW(PWCHAR*);
623     ULONG ldap_count_values_len(BerValue**);
624     ULONG ldap_value_freeA(PCHAR*);
625     ULONG ldap_value_freeW(PWCHAR*);
626     ULONG ldap_value_free_len(BerValue**);
627     PCHAR ldap_get_dnA(LDAP*, LDAPMessage*);
628     PWCHAR ldap_get_dnW(LDAP*, LDAPMessage*);
629     PCHAR ldap_explode_dnA(PCSTR, ULONG);
630     PWCHAR ldap_explode_dnW(PCWSTR, ULONG);
631     PCHAR ldap_dn2ufnA(PCSTR);
632     PWCHAR ldap_dn2ufnW(PCWSTR);
633     ULONG ldap_ufn2dnA(PCSTR, PSTR*);
634     ULONG ldap_ufn2dnW(PCWSTR, PWSTR*);
635     ULONG ldap_parse_referenceA(LDAP*, LDAPMessage*, PCHAR**);
636     ULONG ldap_parse_referenceW(LDAP*, LDAPMessage*, PWCHAR**);
637     ULONG ldap_check_filterA(LDAP*, PSTR);
638     ULONG ldap_check_filterW(LDAP*, PWSTR);
639     ULONG ldap_create_page_controlA(PLDAP, ULONG, BerValue*, UCHAR,
640       PLDAPControlA*);
641     ULONG ldap_create_page_controlW(PLDAP, ULONG, BerValue*, UCHAR,
642       PLDAPControlW*);
643     ULONG ldap_create_sort_controlA(PLDAP, PLDAPSortKeyA*, UCHAR,
644       PLDAPControlA*);
645     ULONG ldap_create_sort_controlW(PLDAP, PLDAPSortKeyW*, UCHAR,
646     PLDAPControlW*);
647     INT ldap_create_vlv_controlA(LDAP*, LDAPVLVInfo*, UCHAR, PLDAPControlA*);
648     INT ldap_create_vlv_controlW(LDAP*, LDAPVLVInfo*, UCHAR, PLDAPControlW*);
649     ULONG ldap_encode_sort_controlA(PLDAP, PLDAPSortKeyA*, PLDAPControlA,
650       BOOLEAN);
651     ULONG ldap_encode_sort_controlW(PLDAP, PLDAPSortKeyW*, PLDAPControlW,
652       BOOLEAN);
653     ULONG ldap_escape_filter_elementA(PCHAR, ULONG, PCHAR, ULONG);
654     ULONG ldap_escape_filter_elementW(PWCHAR, ULONG, PWCHAR, ULONG);
655     ULONG ldap_get_next_page(PLDAP, PLDAPSearch, ULONG, ULONG*);
656     ULONG ldap_get_next_page_s(PLDAP, PLDAPSearch, LDAP_TIMEVAL*, ULONG,
657       ULONG*, LDAPMessage**);
658     ULONG ldap_get_paged_count(PLDAP, PLDAPSearch, ULONG*, PLDAPMessage);
659     ULONG ldap_parse_page_controlA(PLDAP, PLDAPControlA*, ULONG*, BerValue**);
660     ULONG ldap_parse_page_controlW(PLDAP, PLDAPControlW*, ULONG*, BerValue**);
661     ULONG ldap_parse_sort_controlA(PLDAP, PLDAPControlA*, ULONG*, PCHAR*);
662     ULONG ldap_parse_sort_controlW(PLDAP, PLDAPControlW*, ULONG*, PWCHAR*);
663     INT ldap_parse_vlv_controlA(PLDAP, PLDAPControlA*, PULONG, PULONG,
664       BerValue**, PINT);
665     INT ldap_parse_vlv_controlW(PLDAP, PLDAPControlW*, PULONG, PULONG,
666       BerValue**, PINT);
667     PLDAPSearch ldap_search_init_pageA(PLDAP, PCSTR, ULONG, PCSTR, PZPSTR,
668       ULONG, PLDAPControlA*, PLDAPControlA*, ULONG, ULONG, PLDAPSortKeyA*);
669     PLDAPSearch ldap_search_init_pageW(PLDAP, PCWSTR, ULONG, PCWSTR, PZPWSTR,
670       ULONG, PLDAPControlW*, PLDAPControlW*, ULONG, ULONG, PLDAPSortKeyW*);
671     ULONG ldap_search_abandon_page(PLDAP, PLDAPSearch);
672     LDAP ldap_conn_from_msg(LDAP*, LDAPMessage*);
673     INT LdapUnicodeToUTF8(LPCWSTR, int, LPSTR, int);
674     INT LdapUTF8ToUnicode(LPCSTR, int, LPWSTR, int);
675     ULONG ldap_bindA(LDAP*, PSTR, PCHAR, ULONG);
676     ULONG ldap_bindW(LDAP*, PWSTR, PWCHAR, ULONG);
677     ULONG ldap_bind_sA(LDAP*, PSTR, PCHAR, ULONG);
678     ULONG ldap_bind_sW(LDAP*, PWSTR, PWCHAR, ULONG);
679     deprecated ("For LDAP 3 or later, use the ldap_rename_ext or ldap_rename_ext_s functions") {
680         ULONG ldap_modrdnA(LDAP*, PCSTR, PCSTR);
681         ULONG ldap_modrdnW(LDAP*, PCWSTR, PCWSTR);
682         ULONG ldap_modrdn_sA(LDAP*, PCSTR, PCSTR);
683         ULONG ldap_modrdn_sW(LDAP*, PCWSTR, PCWSTR);
684         ULONG ldap_modrdn2A(LDAP*, PCSTR, PCSTR, INT);
685         ULONG ldap_modrdn2W(LDAP*, PCWSTR, PCWSTR, INT);
686         ULONG ldap_modrdn2_sA(LDAP*, PCSTR, PCSTR, INT);
687         ULONG ldap_modrdn2_sW(LDAP*, PCWSTR, PCWSTR, INT);
688     }
689 }
690 
691 version (Unicode) {
692     alias LDAPControlW LDAPControl;
693     alias PLDAPControlW PLDAPControl;
694     alias LDAPModW LDAPMod;
695     alias LDAPModW PLDAPMod;
696     alias LDAPSortKeyW LDAPSortKey;
697     alias PLDAPSortKeyW PLDAPSortKey;
698     alias LDAPAPIInfoW LDAPAPIInfo;
699     alias PLDAPAPIInfoW PLDAPAPIInfo;
700     alias LDAPAPIFeatureInfoW LDAPAPIFeatureInfo;
701     alias PLDAPAPIFeatureInfoW PLDAPAPIFeatureInfo;
702     alias cldap_openW cldap_open;
703     alias ldap_openW ldap_open;
704     alias ldap_simple_bindW ldap_simple_bind;
705     alias ldap_simple_bind_sW ldap_simple_bind_s;
706     alias ldap_sasl_bindW ldap_sasl_bind;
707     alias ldap_sasl_bind_sW ldap_sasl_bind_s;
708     alias ldap_initW ldap_init;
709     alias ldap_sslinitW ldap_sslinit;
710     alias ldap_get_optionW ldap_get_option;
711     alias ldap_set_optionW ldap_set_option;
712     alias ldap_start_tls_sW ldap_start_tls_s;
713     alias ldap_addW ldap_add;
714     alias ldap_add_extW ldap_add_ext;
715     alias ldap_add_sW ldap_add_s;
716     alias ldap_add_ext_sW ldap_add_ext_s;
717     alias ldap_compareW ldap_compare;
718     alias ldap_compare_extW ldap_compare_ext;
719     alias ldap_compare_sW ldap_compare_s;
720     alias ldap_compare_ext_sW ldap_compare_ext_s;
721     alias ldap_deleteW ldap_delete;
722     alias ldap_delete_extW ldap_delete_ext;
723     alias ldap_delete_sW ldap_delete_s;
724     alias ldap_delete_ext_sW ldap_delete_ext_s;
725     alias ldap_extended_operation_sW ldap_extended_operation_s;
726     alias ldap_extended_operationW ldap_extended_operation;
727     alias ldap_modifyW ldap_modify;
728     alias ldap_modify_extW ldap_modify_ext;
729     alias ldap_modify_sW ldap_modify_s;
730     alias ldap_modify_ext_sW ldap_modify_ext_s;
731     alias ldap_check_filterW ldap_check_filter;
732     alias ldap_count_valuesW ldap_count_values;
733     alias ldap_create_page_controlW ldap_create_page_control;
734     alias ldap_create_sort_controlW ldap_create_sort_control;
735     alias ldap_create_vlv_controlW ldap_create_vlv_control;
736     alias ldap_encode_sort_controlW ldap_encode_sort_control;
737     alias ldap_escape_filter_elementW ldap_escape_filter_element;
738     alias ldap_first_attributeW ldap_first_attribute;
739     alias ldap_next_attributeW ldap_next_attribute;
740     alias ldap_get_valuesW ldap_get_values;
741     alias ldap_get_values_lenW ldap_get_values_len;
742     alias ldap_parse_extended_resultW ldap_parse_extended_result;
743     alias ldap_parse_page_controlW ldap_parse_page_control;
744     alias ldap_parse_referenceW ldap_parse_reference;
745     alias ldap_parse_resultW ldap_parse_result;
746     alias ldap_parse_sort_controlW ldap_parse_sort_control;
747     alias ldap_parse_vlv_controlW ldap_parse_vlv_control;
748     alias ldap_searchW ldap_search;
749     alias ldap_search_sW ldap_search_s;
750     alias ldap_search_stW ldap_search_st;
751     alias ldap_search_extW ldap_search_ext;
752     alias ldap_search_ext_sW ldap_search_ext_s;
753     alias ldap_search_init_pageW ldap_search_init_page;
754     alias ldap_err2stringW ldap_err2string;
755     alias ldap_control_freeW ldap_control_free;
756     alias ldap_controls_freeW ldap_controls_free;
757     alias ldap_free_controlsW ldap_free_controls;
758     alias ldap_memfreeW ldap_memfree;
759     alias ldap_value_freeW ldap_value_free;
760     alias ldap_dn2ufnW ldap_dn2ufn;
761     alias ldap_ufn2dnW ldap_ufn2dn;
762     alias ldap_explode_dnW ldap_explode_dn;
763     alias ldap_get_dnW ldap_get_dn;
764     alias ldap_rename_extW ldap_rename;
765     alias ldap_rename_ext_sW ldap_rename_s;
766     alias ldap_rename_extW ldap_rename_ext;
767     alias ldap_rename_ext_sW ldap_rename_ext_s;
768     deprecated {
769         alias ldap_bindW ldap_bind;
770         alias ldap_bind_sW ldap_bind_s;
771         alias ldap_modrdnW ldap_modrdn;
772         alias ldap_modrdn_sW ldap_modrdn_s;
773         alias ldap_modrdn2W ldap_modrdn2;
774         alias ldap_modrdn2_sW ldap_modrdn2_s;
775     }
776 } else {
777     alias LDAPControlA LDAPControl;
778     alias PLDAPControlA PLDAPControl;
779     alias LDAPModA LDAPMod;
780     alias LDAPModA PLDAPMod;
781     alias LDAPSortKeyA LDAPSortKey;
782     alias PLDAPSortKeyA PLDAPSortKey;
783     alias LDAPAPIInfoA LDAPAPIInfo;
784     alias PLDAPAPIInfoA PLDAPAPIInfo;
785     alias LDAPAPIFeatureInfoA LDAPAPIFeatureInfo;
786     alias PLDAPAPIFeatureInfoA PLDAPAPIFeatureInfo;
787     alias cldap_openA cldap_open;
788     alias ldap_openA ldap_open;
789     alias ldap_simple_bindA ldap_simple_bind;
790     alias ldap_simple_bind_sA ldap_simple_bind_s;
791     alias ldap_sasl_bindA ldap_sasl_bind;
792     alias ldap_sasl_bind_sA ldap_sasl_bind_s;
793     alias ldap_initA ldap_init;
794     alias ldap_sslinitA ldap_sslinit;
795     alias ldap_get_optionA ldap_get_option;
796     alias ldap_set_optionA ldap_set_option;
797     alias ldap_start_tls_sA ldap_start_tls_s;
798     alias ldap_addA ldap_add;
799     alias ldap_add_extA ldap_add_ext;
800     alias ldap_add_sA ldap_add_s;
801     alias ldap_add_ext_sA ldap_add_ext_s;
802     alias ldap_compareA ldap_compare;
803     alias ldap_compare_extA ldap_compare_ext;
804     alias ldap_compare_sA ldap_compare_s;
805     alias ldap_compare_ext_sA ldap_compare_ext_s;
806     alias ldap_deleteA ldap_delete;
807     alias ldap_delete_extA ldap_delete_ext;
808     alias ldap_delete_sA ldap_delete_s;
809     alias ldap_delete_ext_sA ldap_delete_ext_s;
810     alias ldap_extended_operation_sA ldap_extended_operation_s;
811     alias ldap_extended_operationA ldap_extended_operation;
812     alias ldap_modifyA ldap_modify;
813     alias ldap_modify_extA ldap_modify_ext;
814     alias ldap_modify_sA ldap_modify_s;
815     alias ldap_modify_ext_sA ldap_modify_ext_s;
816     alias ldap_check_filterA ldap_check_filter;
817     alias ldap_count_valuesA ldap_count_values;
818     alias ldap_create_page_controlA ldap_create_page_control;
819     alias ldap_create_sort_controlA ldap_create_sort_control;
820     alias ldap_create_vlv_controlA ldap_create_vlv_control;
821     alias ldap_encode_sort_controlA ldap_encode_sort_control;
822     alias ldap_escape_filter_elementA ldap_escape_filter_element;
823     alias ldap_first_attributeA ldap_first_attribute;
824     alias ldap_next_attributeA ldap_next_attribute;
825     alias ldap_get_valuesA ldap_get_values;
826     alias ldap_get_values_lenA ldap_get_values_len;
827     alias ldap_parse_extended_resultA ldap_parse_extended_result;
828     alias ldap_parse_page_controlA ldap_parse_page_control;
829     alias ldap_parse_referenceA ldap_parse_reference;
830     alias ldap_parse_resultA ldap_parse_result;
831     alias ldap_parse_sort_controlA ldap_parse_sort_control;
832     alias ldap_parse_vlv_controlA ldap_parse_vlv_control;
833     alias ldap_searchA ldap_search;
834     alias ldap_search_sA ldap_search_s;
835     alias ldap_search_stA ldap_search_st;
836     alias ldap_search_extA ldap_search_ext;
837     alias ldap_search_ext_sA ldap_search_ext_s;
838     alias ldap_search_init_pageA ldap_search_init_page;
839     alias ldap_err2stringA ldap_err2string;
840     alias ldap_control_freeA ldap_control_free;
841     alias ldap_controls_freeA ldap_controls_free;
842     alias ldap_free_controlsA ldap_free_controls;
843     alias ldap_memfreeA ldap_memfree;
844     alias ldap_value_freeA ldap_value_free;
845     alias ldap_dn2ufnA ldap_dn2ufn;
846     alias ldap_ufn2dnA ldap_ufn2dn;
847     alias ldap_explode_dnA ldap_explode_dn;
848     alias ldap_get_dnA ldap_get_dn;
849     alias ldap_rename_extA ldap_rename;
850     alias ldap_rename_ext_sA ldap_rename_s;
851     alias ldap_rename_extA ldap_rename_ext;
852     alias ldap_rename_ext_sA ldap_rename_ext_s;
853     deprecated {
854         alias ldap_bindA ldap_bind;
855         alias ldap_bind_sA ldap_bind_s;
856         alias ldap_modrdnA ldap_modrdn;
857         alias ldap_modrdn_sA ldap_modrdn_s;
858         alias ldap_modrdn2A ldap_modrdn2;
859         alias ldap_modrdn2_sA ldap_modrdn2_s;
860     }
861 }