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.

150 lines
6.4 KiB

  1. /*---------------------------------------------------------------------------
  2. File: Exchange.hpp
  3. Comments: Mailbox security translation functions.
  4. (c) Copyright 1995-1998, Mission Critical Software, Inc., All Rights Reserved
  5. Proprietary and confidential to Mission Critical Software, Inc.
  6. REVISION LOG ENTRY
  7. Revision By: ...
  8. Revised on 2/8/98 6:32:13 PM
  9. ---------------------------------------------------------------------------
  10. */
  11. #ifndef __EXCHANGE_HPP__
  12. #define __EXCHANGE_HPP__
  13. #define INITGUID
  14. #define USES_IID_IMAPIContainer
  15. #define USES_IID_IABContainer
  16. #define USES_IID_IMAPITable
  17. #define USES_IID_IDistList
  18. #define USES_IID_IMAPIProp
  19. #include <winbase.h>
  20. #include <objbase.h>
  21. #include <mapiguid.h>
  22. #include <mapiutil.h>
  23. #include <emsabtag.h>
  24. #include "edk2.hpp"
  25. #include "stargs.hpp"
  26. #include "sidcache.hpp"
  27. #include "Ustring.hpp"
  28. #include "sdstat.hpp"
  29. #include <dapi.h>
  30. #include "exldap.h"
  31. // Maximum numbers of entries to put through MAPI calls:
  32. #define MAX_COPY_ENTRIES 1024L
  33. #define MAX_DELETE_ENTRIES 1024L
  34. // Macro causes many retries on operations that may fail at first and succeed after a retry.
  35. #define RETRIES 100
  36. #ifdef _DEBUG
  37. #define MAKE_MAPI_CALL(hr, c) \
  38. { \
  39. int iMapiRetriesOnMapiCallFailed = 0; \
  40. do { \
  41. hr = c; \
  42. } while( (hr == MAPI_E_CALL_FAILED) && (++iMapiRetriesOnMapiCallFailed < RETRIES) ); \
  43. if (iMapiRetriesOnMapiCallFailed && SUCCEEDED(hr)) { \
  44. printf("%s succeeded after %d retries.\n", #c, iMapiRetriesOnMapiCallFailed); \
  45. } \
  46. }
  47. #else
  48. #define MAKE_MAPI_CALL(hr, c) \
  49. { \
  50. int iMapiRetriesOnMapiCallFailed = 0; \
  51. do { \
  52. hr = c; \
  53. } while( (hr == MAPI_E_CALL_FAILED) && (++iMapiRetriesOnMapiCallFailed < RETRIES) ); \
  54. }
  55. #endif
  56. class TGlobalDirectory
  57. {
  58. protected:
  59. BOOL m_bUseDefaultMapiProfile; // Whether to use MAPI profile listed in Registry.
  60. BOOL m_bPromptForMapiProfile; // Whether to prompt for MAPI profile.
  61. LPTSTR m_pszMapiProfile; // MAPI profile to use.
  62. TSDResolveStats * m_stat;
  63. // DAPI
  64. DAPI_HANDLE m_dSession;
  65. DAPI_PARMS m_dParms;
  66. public:
  67. TGlobalDirectory::TGlobalDirectory();
  68. TGlobalDirectory::~TGlobalDirectory();
  69. protected:
  70. // MAPI
  71. BOOL m_bMapiInitialized; // TRUE if initialization was successful.
  72. LPMAPISESSION m_pMapiSession; // MAPI session handle.
  73. LPADRBOOK m_pAdrBook; // The master AB.
  74. LPABCONT m_pGlobalList;
  75. LPABCONT m_pContainer;
  76. LPMAPITABLE m_pGlobalTable;
  77. LPSPropTagArray m_pGlobalPropertyTags;
  78. LPSRowSet m_pGlobalRows;
  79. LPSRowSet m_pRootRows;
  80. LPMAPITABLE m_pContainerTable;
  81. WCHAR * m_name; // container name used in error messages
  82. void LogMapiError(int iSeverity, LPCTSTR pszEntryPoint, HRESULT hr);
  83. void LogDapiError(int iSeverity, LPCTSTR pszUserMessage, DAPI_EVENT * pResult);
  84. BOOL m_bLoggedFailedClose; // Already logged a failure to close.
  85. LPTSTR GetMapiProfile() const; // The MAPI profile to use; may be default.
  86. BOOL DoUseDefaultMapiProfile() const; // Whether to use MAPI profile listed in Registry.
  87. BOOL DoPromptForMapiProfile() const; // Whether to prompt for MAPI profile.
  88. public:
  89. void SetStats(TSDResolveStats * s ) { m_stat = s; }
  90. BOOL StartMapiSession(); // Use MAPI profile switch to start a session.
  91. void EndMapiSession(); // Close the MAPI session.
  92. BOOL MapiIsOpen() { return (m_pMapiSession != 0 ) ; }
  93. BOOL OpenGlobalList(); // Open the address book and the Global List.
  94. void CloseGlobalList(); // Release the address book and Global List.
  95. void PromptForMapiProfile() { m_bPromptForMapiProfile = TRUE; m_bUseDefaultMapiProfile = FALSE;}
  96. void UseDefaultMapiProfile() { m_bUseDefaultMapiProfile = TRUE; m_bPromptForMapiProfile = FALSE; }
  97. void SetMapiProfile(LPCTSTR profile) { m_pszMapiProfile = new TCHAR [ UStrLen(profile) + 1 ];
  98. UStrCpy(m_pszMapiProfile,profile);
  99. m_bPromptForMapiProfile = FALSE; m_bUseDefaultMapiProfile = FALSE;}
  100. BOOL Scan(SecurityTranslatorArgs * args,WCHAR const * container); // uses MAPI to update mailboxes
  101. BOOL DoDAPITranslation(WCHAR * server,SecurityTranslatorArgs * args); // uses DAPI to update sites, containers, orgs.
  102. BOOL DoLdapTranslation(WCHAR * server,WCHAR * creds, WCHAR * password,SecurityTranslatorArgs * args,WCHAR * basepoint,WCHAR * query = NULL );
  103. DWORD GetLDAPPort(WCHAR * server);
  104. void GetSiteNameForServer(WCHAR const * server,CLdapEnum * e,WCHAR * siteName);
  105. protected:
  106. // MAPI work routines
  107. BOOL UpdateEntry( LPMAPIPROP pUserEntry, ULONG ulType, SecurityTranslatorArgs * args);
  108. BOOL ScanHierarchy( LPABCONT pContainerTable, SecurityTranslatorArgs * args,WCHAR const * container);
  109. BOOL ScanContents(LPMAPITABLE pContainerTable,SecurityTranslatorArgs * args);
  110. // DAPI work routines
  111. BOOL DAPITranslate(WCHAR * dn,SecurityTranslatorArgs * args);
  112. BOOL DAPIOpen(WCHAR * server);
  113. BOOL DAPIClose();
  114. // not used
  115. BOOL OpenContainerByRow(long row);
  116. BOOL OpenContainerByName(WCHAR * name, TAccountCache * cache, BOOL nochange);
  117. //BOOL ListContainers(CTreeCtrl * tree);
  118. //BOOL DoDAPIThing(CTreeCtrl * tree, CString dn);
  119. };
  120. BOOL LoadDAPI();
  121. void ReleaseDAPI();
  122. #endif //__EXCHANGE_HPP__