Leaked source code of windows server 2003
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

298 lines
9.6 KiB

  1. //--------------------------------------------------------------------------------------------
  2. //
  3. // Copyright (c) Microsoft Corporation, 1996
  4. //
  5. // Description:
  6. //
  7. // Microsoft LDAP Client.
  8. //
  9. // All Interfaces that are exposed to a CLIENT.
  10. //
  11. // History
  12. //
  13. // davidsan 04-24-96 Created.
  14. //
  15. //--------------------------------------------------------------------------------------------
  16. // OVERVIEW:
  17. // The LDAP Client DLL defines an interface, ILdapClient, and a set of structure types
  18. // listed below. The ILdapClient interface provides a set of methods for communicating
  19. // with an LDAP-based directory service. The general approach taken is that calling an
  20. // ILdapClient method such as HrSearch() will return a transaction ID, or XID. This XID
  21. // can then be used in subsequent calls to wait for and retrieve the server's response;
  22. // an example would be the HrGetSearchResponse() method, which takes an XID and returns
  23. // the server's response to that search transaction. The HrGet*Response() functions can
  24. // also be used to check if the response is present by providing a timeout value of 0, which
  25. // will return immediately with LDAP_E_TIMEOUT if the data is not yet present.
  26. #ifndef _LDAPCLI_H
  27. #define _LDAPCLI_H
  28. //--------------------------------------------------------------------------------------------
  29. //
  30. // INCLUDES.
  31. //
  32. //--------------------------------------------------------------------------------------------
  33. #include <windows.h>
  34. #include <objbase.h>
  35. #include <ldaperr.h>
  36. #include <ldap.h>
  37. //--------------------------------------------------------------------------------------------
  38. //
  39. // DECLARATIONS.
  40. //
  41. //--------------------------------------------------------------------------------------------
  42. #define LDAP_VER_CURRENT 2
  43. #define INTERFACE_VER_CURRENT 1
  44. //--------------------------------------------------------------------------------------------
  45. //
  46. // TYPE DEFINITIONS.
  47. //
  48. //--------------------------------------------------------------------------------------------
  49. // NOTE! Make the 'Next' pointer be the first thing in all these linked-list structures!
  50. // Attribute value.
  51. typedef struct _attrval
  52. {
  53. struct _attrval *pvalNext;
  54. char *szVal;
  55. } VAL, *PVAL;
  56. // Attribute. Contains an attribute name (also called attribute type) followed by a set
  57. // of attribute values.
  58. typedef struct _attribute
  59. {
  60. struct _attribute *pattrNext;
  61. char *szAttrib;
  62. PVAL pvalFirst;
  63. } ATTR, *PATTR;
  64. // Database Object. Consists of a DN which identifies the object, followed by a set of
  65. // attributes.
  66. typedef struct _object
  67. {
  68. struct _object *pobjNext;
  69. char *szDN;
  70. PATTR pattrFirst;
  71. } OBJ, *POBJ;
  72. // attribute value assertion
  73. typedef struct _ava
  74. {
  75. char *szAttrib;
  76. char *szValue;
  77. } AVA, *PAVA;
  78. // substrings filter. this is less general than the ldap spec. cope.
  79. typedef struct _substrings
  80. {
  81. char *szAttrib;
  82. char *szInitial;
  83. char *szAny;
  84. char *szFinal;
  85. } SUB, *PSUB;
  86. // search filter
  87. typedef struct _filter
  88. {
  89. struct _filter *pfilterNext; // for chaining in sets
  90. DWORD type;
  91. union
  92. {
  93. struct _filter *pfilterSub;
  94. AVA ava;
  95. SUB sub;
  96. char *szAttrib;
  97. };
  98. } FILTER, *PFILTER;
  99. // search params
  100. typedef struct _searchparms
  101. {
  102. char *szDNBase;
  103. DWORD scope;
  104. DWORD deref;
  105. int cRecordsMax;
  106. int cSecondsMax;
  107. BOOL fAttrsOnly;
  108. PFILTER pfilter;
  109. int cAttrib;
  110. char **rgszAttrib;
  111. } SP, *PSP;
  112. // modify params
  113. typedef struct _modparms
  114. {
  115. struct _modparms *pmodNext;
  116. int modop;
  117. PATTR pattrFirst;
  118. } MOD, *PMOD;
  119. typedef DWORD XID, *PXID; // transaction ID
  120. interface ILdapClient;
  121. typedef interface ILdapClient LCLI, *PLCLI;
  122. interface ICLdapClient;
  123. typedef interface ICLdapClient CLCLI, *PCLCLI;
  124. //--------------------------------------------------------------------------------------------
  125. //
  126. // FUNCTIONS.
  127. //
  128. //--------------------------------------------------------------------------------------------
  129. //
  130. // To get an LDAP client interface call this.
  131. //
  132. #ifdef __cplusplus
  133. extern "C" {
  134. #endif
  135. __declspec(dllexport) HRESULT __cdecl HrCreateLdapClient(int iVerLdap, int iVerInterface, PLCLI *pplcli);
  136. __declspec(dllexport) HRESULT __cdecl HrCreateCLdapClient(int iVerLdap, int iVerInterface, PCLCLI *ppclcli);
  137. __declspec(dllexport) HRESULT __cdecl HrFreePobjList(POBJ pobj);
  138. #ifdef __cplusplus
  139. }
  140. #endif
  141. //--------------------------------------------------------------------------------------------
  142. //
  143. // INTERFACES: Definitions.
  144. //
  145. //--------------------------------------------------------------------------------------------
  146. #undef INTERFACE
  147. #define INTERFACE ILdapClient
  148. DECLARE_INTERFACE_(ILdapClient, IUnknown)
  149. {
  150. // IUnknown:
  151. STDMETHOD(QueryInterface) (THIS_ REFIID riid, LPVOID FAR *ppvObj) PURE;
  152. STDMETHOD_(ULONG, AddRef) (THIS) PURE;
  153. STDMETHOD_(ULONG, Release) (THIS) PURE;
  154. // ILdapClient
  155. STDMETHOD(HrConnect) (THIS_ CHAR *szServer, USHORT usPort) PURE;
  156. STDMETHOD(HrDisconnect) (THIS) PURE;
  157. STDMETHOD(HrIsConnected) (THIS) PURE;
  158. STDMETHOD(HrBindSimple) (THIS_ char *szDN, char *szPass, PXID pxid) PURE;
  159. STDMETHOD(HrGetBindResponse) (THIS_ XID xid, DWORD timeout) PURE;
  160. STDMETHOD(HrUnbind) (THIS) PURE; // this doesn't return an XID because there's no response
  161. // this function is a synchronous wrapper around the SSPI bind gunk
  162. //$ TODO: Pass in SSPI Package name (or support NTLM some other way)
  163. STDMETHOD(HrBindSSPI) (THIS_ char *szDN, char *szUser, char *szPass, BOOL fPrompt, DWORD timeout) PURE;
  164. STDMETHOD(HrSendSSPINegotiate) (THIS_ char *szDN, char *szUser, char *szPass, BOOL fPrompt, PXID pxid) PURE;
  165. STDMETHOD(HrGetSSPIChallenge) (THIS_ XID xid, BYTE *pbBuf, int cbBuf, int *pcbChallenge, DWORD timeout) PURE;
  166. STDMETHOD(HrSendSSPIResponse) (THIS_ BYTE *pbChallenge, int cbChallenge, PXID pxid) PURE;
  167. STDMETHOD(HrSearch) (THIS_ PSP psp, PXID pxid) PURE;
  168. STDMETHOD(HrGetSearchResponse) (THIS_ XID xid, DWORD timeout, POBJ *ppobj) PURE;
  169. STDMETHOD(HrModify) (THIS_ char *szDN, PMOD pmod, PXID pxid) PURE;
  170. STDMETHOD(HrGetModifyResponse) (THIS_ XID xid, DWORD timeout) PURE;
  171. STDMETHOD(HrAdd) (THIS_ char *szDN, PATTR pattr, PXID pxid) PURE;
  172. STDMETHOD(HrGetAddResponse) (THIS_ XID xid, DWORD timeout) PURE;
  173. STDMETHOD(HrDelete) (THIS_ char *szDN, PXID pxid) PURE;
  174. STDMETHOD(HrGetDeleteResponse) (THIS_ XID xid, DWORD timeout) PURE;
  175. STDMETHOD(HrModifyRDN) (THIS_ char *szDN, char *szNewRDN, BOOL fDeleteOldRDN, PXID pxid) PURE;
  176. STDMETHOD(HrGetModifyRDNResponse) (THIS_ XID xid, DWORD timeout) PURE;
  177. STDMETHOD(HrCompare) (THIS_ char *szDN, char *szAttrib, char *szValue, PXID pxid) PURE;
  178. STDMETHOD(HrGetCompareResponse) (THIS_ XID xid, DWORD timeout) PURE;
  179. STDMETHOD(HrCancelXid) (THIS_ XID xid) PURE;
  180. };
  181. #undef INTERFACE
  182. #define INTERFACE ICLdapClient
  183. DECLARE_INTERFACE_(ICLdapClient, IUnknown)
  184. {
  185. // IUnknown:
  186. STDMETHOD(QueryInterface) (THIS_ REFIID riid, LPVOID FAR *ppvObj) PURE;
  187. STDMETHOD_(ULONG, AddRef) (THIS) PURE;
  188. STDMETHOD_(ULONG, Release) (THIS) PURE;
  189. STDMETHOD(HrSetServerName) (THIS_ char *szServer, USHORT usPort) PURE;
  190. STDMETHOD(HrSetServerIPAddr) (THIS_ SOCKADDR_IN *psin) PURE;
  191. STDMETHOD(HrSearch) (THIS_ PSP psp, PXID pxid) PURE;
  192. STDMETHOD(HrGetSearchResponse) (THIS_ XID xid, DWORD timeout, POBJ *ppobj) PURE;
  193. STDMETHOD(HrCancelXid) (THIS_ XID xid) PURE;
  194. };
  195. // RFC1823 stuff
  196. typedef struct ldap
  197. {
  198. // these are publically accessible fields. this is how you control the parameters
  199. // of your search calls.
  200. int ld_deref;
  201. int ld_timelimit;
  202. int ld_sizelimit;
  203. int ld_errno;
  204. // these are not publically accessible fields. pretend you didn't see them.
  205. ILdapClient *plcli;
  206. } LDAP;
  207. typedef struct berval
  208. {
  209. unsigned long bv_len;
  210. char *bv_val;
  211. } BERVAL;
  212. #define LDAP_AUTH_NONE 0
  213. #define LDAP_AUTH_SIMPLE 1
  214. #define LDAP_AUTH_KRBV41 2
  215. #define LDAP_AUTH_KRBV42 3
  216. typedef OBJ LDAPMessage;
  217. #define DLLEXPORT __declspec(dllexport)
  218. #ifdef __cplusplus
  219. extern "C" {
  220. #endif
  221. DLLEXPORT LDAP * __cdecl ldap_open(char *hostname, int portno);
  222. DLLEXPORT int __cdecl ldap_bind_s(LDAP *ld, char *dn, char *cred, int method);
  223. DLLEXPORT int __cdecl ldap_unbind(LDAP *ld);
  224. DLLEXPORT int __cdecl ldap_search_s(LDAP *ld, char *base, int scope, char *filter, char *attrs[], int attrsonly, LDAPMessage **res);
  225. DLLEXPORT int __cdecl ldap_search_st(LDAP *ld, char *base, int scope, char *filter, char *attrs[], int attrsonly, struct timeval *timeout, LDAPMessage **res);
  226. DLLEXPORT int __cdecl ldap_msgfree(LDAPMessage *res);
  227. // result parsing stuff
  228. DLLEXPORT LDAPMessage * __cdecl ldap_first_entry(LDAP *ld, LDAPMessage *res);
  229. DLLEXPORT LDAPMessage * __cdecl ldap_next_entry(LDAP *ld, LDAPMessage *entry);
  230. DLLEXPORT int __cdecl ldap_count_entries(LDAP *ld, LDAPMessage *res);
  231. DLLEXPORT char * __cdecl ldap_first_attribute(LDAP *ld, LDAPMessage *entry, void **ptr);
  232. DLLEXPORT char * __cdecl ldap_next_attribute(LDAP *ld, LDAPMessage *entry, void **ptr);
  233. DLLEXPORT char ** __cdecl ldap_get_values(LDAP *ld, LDAPMessage *entry, char *attr);
  234. DLLEXPORT struct berval ** __cdecl ldap_get_values_len(LDAP *ld, LDAPMessage *entry, char *attr);
  235. DLLEXPORT int __cdecl ldap_count_values(char **vals);
  236. DLLEXPORT int __cdecl ldap_count_values_len(struct berval **vals);
  237. DLLEXPORT int __cdecl ldap_value_free(char **vals);
  238. DLLEXPORT int __cdecl ldap_value_free_len(struct berval **vals);
  239. DLLEXPORT char * __cdecl ldap_get_dn(LDAP *ld, LDAPMessage *entry);
  240. DLLEXPORT void __cdecl ldap_free_dn(char *dn);
  241. #ifdef __cplusplus
  242. }
  243. #endif
  244. #endif // _LDAPCLI_H