Source code of Windows XP (NT5)
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.

162 lines
6.0 KiB

  1. #ifndef EXLDAP_H
  2. #define EXLDAP_H
  3. #include <winldap.h>
  4. #include "EaLen.hpp"
  5. #include "Common.hpp"
  6. #include "UString.hpp"
  7. typedef WINLDAPAPI LDAP * LDAPAPI LDAP_OPEN( PWCHAR HostName, ULONG PortNumber );
  8. typedef WINLDAPAPI ULONG LDAPAPI LDAPMAPERRORTOWIN32( ULONG LdapError );
  9. typedef WINLDAPAPI ULONG LDAPAPI LDAP_UNBIND( LDAP *ld );
  10. typedef WINLDAPAPI ULONG LDAPAPI LDAP_BIND( LDAP *ld, PWCHAR dn, PWCHAR cred, ULONG method );
  11. typedef WINLDAPAPI ULONG LDAPAPI LDAPGETLASTERROR( VOID );
  12. typedef WINLDAPAPI ULONG LDAPAPI LDAP_MODIFY_S( LDAP *ld, PWCHAR dn, LDAPModW *mods[] );
  13. typedef WINLDAPAPI ULONG LDAPAPI LDAP_MSGFREE( LDAPMessage *res );
  14. typedef WINLDAPAPI ULONG LDAPAPI LDAP_COUNT_ENTRIES( LDAP *ld, LDAPMessage *res );
  15. typedef WINLDAPAPI ULONG LDAPAPI LDAP_SEARCH_EXT_S(
  16. LDAP *ld,
  17. PWCHAR base,
  18. ULONG scope,
  19. PWCHAR filter,
  20. PWCHAR attrs[],
  21. ULONG attrsonly,
  22. PLDAPControlW *ServerControls,
  23. PLDAPControlW *ClientControls,
  24. struct l_timeval *timeout,
  25. ULONG SizeLimit,
  26. LDAPMessage **res
  27. );
  28. typedef WINLDAPAPI ULONG LDAPAPI LDAP_CREATE_PAGE_CONTROL(
  29. PLDAP ExternalHandle,
  30. ULONG PageSize,
  31. struct berval *Cookie,
  32. UCHAR IsCritical,
  33. PLDAPControlW *Control
  34. );
  35. typedef WINLDAPAPI ULONG LDAPAPI LDAP_PARSE_PAGE_CONTROL (
  36. PLDAP ExternalHandle,
  37. PLDAPControlW *ServerControls,
  38. ULONG *TotalCount,
  39. struct berval **Cookie // Use ber_bvfree to free
  40. );
  41. typedef WINLDAPAPI PWCHAR *LDAPAPI LDAP_GET_VALUES(
  42. LDAP *ld,
  43. LDAPMessage *entry,
  44. PWCHAR attr
  45. );
  46. typedef WINLDAPAPI ULONG LDAPAPI LDAP_VALUE_FREE( PWCHAR *vals );
  47. typedef WINLDAPAPI LDAPMessage *LDAPAPI LDAP_NEXT_ENTRY( LDAP *ld, LDAPMessage *entry );
  48. typedef WINLDAPAPI LDAPMessage *LDAPAPI LDAP_FIRST_ENTRY( LDAP *ld, LDAPMessage *res );
  49. typedef WINLDAPAPI VOID LDAPAPI BER_BVFREE( struct berval *bv );
  50. typedef WINLDAPAPI ULONG LDAPAPI LDAP_CONTROLS_FREE (
  51. LDAPControlW **Control
  52. );
  53. typedef WINLDAPAPI ULONG LDAPAPI LDAP_PARSE_RESULT (
  54. LDAP *Connection,
  55. LDAPMessage *ResultMessage,
  56. ULONG *ReturnCode OPTIONAL, // returned by server
  57. PWCHAR *MatchedDNs OPTIONAL, // free with ldap_memfree
  58. PWCHAR *ErrorMessage OPTIONAL, // free with ldap_memfree
  59. PWCHAR **Referrals OPTIONAL, // free with ldap_value_freeW
  60. PLDAPControlW **ServerControls OPTIONAL, // free with ldap_free_controlsW
  61. BOOLEAN Freeit
  62. );
  63. typedef WINLDAPAPI ULONG LDAPAPI LDAP_GET_OPTION( LDAP *ld, int option, void *outvalue );
  64. typedef WINLDAPAPI ULONG LDAPAPI LDAP_SET_OPTION( LDAP *ld, int option, void *invalue );
  65. class CLdapConnection
  66. {
  67. WCHAR m_exchServer[LEN_Computer];
  68. LDAP * m_LD;
  69. ULONG m_port;
  70. HMODULE m_hDll;
  71. BOOL m_bUseSSL;
  72. WCHAR m_credentials[300];
  73. WCHAR m_password[100];
  74. public:
  75. LDAP_PARSE_RESULT * ldap_parse_result;
  76. LDAP_PARSE_PAGE_CONTROL * ldap_parse_page_control;
  77. LDAP_CONTROLS_FREE * ldap_controls_free;
  78. BER_BVFREE * ber_bvfree;
  79. LDAP_FIRST_ENTRY * ldap_first_entry;
  80. LDAP_NEXT_ENTRY * ldap_next_entry;
  81. LDAP_VALUE_FREE * ldap_value_free;
  82. LDAP_GET_VALUES * ldap_get_values;
  83. LDAP_CREATE_PAGE_CONTROL * ldap_create_page_control;
  84. LDAP_SEARCH_EXT_S * ldap_search_ext_s;
  85. LDAP_COUNT_ENTRIES * ldap_count_entries;
  86. LDAP_MSGFREE * ldap_msgfree;
  87. LDAP_MODIFY_S * ldap_modify_s;
  88. LDAPGETLASTERROR * LdapGetLastError;
  89. LDAP_BIND * ldap_bind_sW;
  90. LDAP_UNBIND * ldap_unbind;
  91. LDAPMAPERRORTOWIN32 * LdapMapErrorToWin32;
  92. LDAP_OPEN * ldap_open;
  93. LDAP_GET_OPTION * ldap_get_option;
  94. LDAP_SET_OPTION * ldap_set_option;
  95. public:
  96. CLdapConnection();
  97. ~CLdapConnection();
  98. void SetCredentials(WCHAR const * cred,WCHAR const * pwd) { safecopy(m_credentials,cred); safecopy(m_password,pwd); }
  99. LDAP * GetHandle() { return m_LD; }
  100. DWORD Connect(WCHAR const * server,ULONG port);
  101. DWORD UpdateSimpleStringValue(WCHAR const * dn, WCHAR const * property, WCHAR const * value);
  102. void Close();
  103. BOOL StringToBytes(WCHAR const * pString,BYTE * pBytes);
  104. BOOL BytesToString(BYTE * pBytes,WCHAR * sidString,DWORD numBytes);
  105. protected:
  106. // helper functions
  107. BYTE HexValue(WCHAR value);
  108. void AddByteToString(WCHAR ** string,BYTE value);
  109. };
  110. class CLdapEnum
  111. {
  112. BOOL m_bOpen;
  113. ULONG m_nReturned;
  114. ULONG m_nCurrent;
  115. ULONG m_totalCount;
  116. LDAPMessage * m_message;
  117. LDAPMessage * m_currMsg;
  118. WCHAR m_query[1000];
  119. WCHAR m_basepoint[LEN_DistName];
  120. int m_scope;
  121. long m_pageSize;
  122. int m_nAttributes;
  123. WCHAR ** m_AttrNames;
  124. public:
  125. CLdapConnection m_connection;
  126. public:
  127. CLdapEnum() { m_bOpen = FALSE; m_nReturned = 0; m_nCurrent = 0; m_totalCount = 0; m_message = NULL;
  128. m_query[0] = 0; m_basepoint[0] = 0; m_scope = 2; m_pageSize = 100; m_currMsg = NULL;
  129. m_nAttributes = 0; m_AttrNames =NULL;}
  130. ~CLdapEnum();
  131. DWORD InitConnection(WCHAR const * server,ULONG port) { return m_connection.Connect(server,port); }
  132. DWORD Open(WCHAR const * query,WCHAR const * basePoint,short scope, long pageSize,int numAttributes,
  133. WCHAR ** attrs);
  134. DWORD Next(PWCHAR ** ppAttrs);
  135. void FreeData(PWCHAR* pValues);
  136. protected:
  137. DWORD GetNextEntry(PWCHAR ** ppAttrs);
  138. DWORD GetNextPage();
  139. };
  140. #endif // EXLDAP_H