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.

129 lines
4.2 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. //
  5. // Copyright (C) Microsoft Corporation, 1997 - 1999
  6. //
  7. // File: sidcache.h
  8. //
  9. // This file contains definitions and prototypes for SID/Name cache.
  10. //
  11. //--------------------------------------------------------------------------
  12. #ifndef _SIDCACHE_H_
  13. #define _SIDCACHE_H_
  14. #include <comctrlp.h> // DPA
  15. DWORD WaitOnThread(HANDLE *phThread);
  16. #define BUCKET_COUNT 31
  17. typedef struct _sid_cache_entry
  18. {
  19. DWORD dwLastAccessTime;
  20. SID_NAME_USE SidType;
  21. PSID pSid;
  22. LPCTSTR pszName;
  23. LPCTSTR pszLogonName;
  24. } SID_CACHE_ENTRY, *PSID_CACHE_ENTRY;
  25. class CSidCache
  26. {
  27. private:
  28. HDPA m_dpaSidHashTable[BUCKET_COUNT];
  29. CRITICAL_SECTION m_csHashTableLock;
  30. CRITICAL_SECTION m_csDomainNameLock;
  31. CRITICAL_SECTION m_csDcNameLock;
  32. LPTSTR m_pszCachedServer;
  33. LPTSTR m_pszCachedDomain;
  34. HANDLE m_hInitThread;
  35. LPTSTR m_pszLastDc;
  36. LPTSTR m_pszLastDomain;
  37. LONG m_cRef;
  38. public:
  39. CSidCache();
  40. ~CSidCache();
  41. // used to control lifetime of the object
  42. ULONG AddRef();
  43. ULONG Release();
  44. BOOL LookupSids(HDPA hSids, LPCTSTR pszServer, LPSECURITYINFO2 psi2, PUSER_LIST *ppUserList);
  45. BOOL LookupSidsAsync(HDPA hSids, LPCTSTR pszServer, LPSECURITYINFO2 psi2, HWND hWndNotify, UINT uMsgNotify);
  46. #if(_WIN32_WINNT >= 0x0500)
  47. BOOL LookupNames(PDS_SELECTION_LIST pDsSelList, LPCTSTR pszServer, PUSER_LIST *ppUserList, BOOL bStandalone);
  48. #endif
  49. void GetDomainName(LPCTSTR pszServer, LPTSTR pszDomain, ULONG cchDomain);
  50. void GetDcName(LPCTSTR pszDomain, LPTSTR pszDC, ULONG cchDC);
  51. PSID_CACHE_ENTRY FindSid(PSID pSid);
  52. PSID_CACHE_ENTRY MakeEntry(PSID pSid,
  53. SID_NAME_USE SidType,
  54. LPCTSTR pszName,
  55. LPCTSTR pszLogonName = NULL);
  56. BOOL AddEntry(PSID_CACHE_ENTRY pEntry);
  57. BOOL BuildUserList(HDPA hEntryList,
  58. LPCTSTR pszServer,
  59. PUSER_LIST *ppUserList);
  60. private:
  61. int HashSid(PSID pSid);
  62. static int CALLBACK CompareSid(LPVOID p1, LPVOID p2, LPARAM lParam);
  63. void GetUserFriendlyName(LPCTSTR pszSamLogonName,
  64. LPCTSTR pszSamAccountName,
  65. LPCTSTR pszServer,
  66. BOOL bUseSamCompatibleInfo,
  67. BOOL bIsStandalone,
  68. BSTR *pstrLogonName,
  69. BSTR *pstrDisplayName);
  70. BSTR GetNT4DisplayName(LPCTSTR pszAccount,
  71. LPCTSTR pszName,
  72. LPCTSTR pszServer,
  73. BOOL bStandalone);
  74. BOOL InternalLookupSids(HDPA hSids,
  75. LPCTSTR pszServer,
  76. LPSECURITYINFO2 psi2,
  77. HDPA hEntryList,
  78. HWND hWndNotify = NULL,
  79. UINT uMsgNotify = 0);
  80. BOOL LookupSidsHelper(HDPA hSids,
  81. LPCTSTR pszServer,
  82. HDPA hEntryList,
  83. HWND hWndNotify = NULL,
  84. UINT uMsgNotify = 0,
  85. BOOL bSecondTry = FALSE);
  86. HRESULT LookupSidsFromObject(HDPA hSids, LPSECURITYINFO2 psi2, HDPA hEntryList);
  87. #if(_WIN32_WINNT >= 0x0500)
  88. BOOL InternalLookupNames(PDS_SELECTION_LIST pDsSelList,
  89. LPCTSTR pszServer,
  90. HDPA hEntryList,
  91. BOOL bStandalone);
  92. #endif
  93. static DWORD WINAPI InitThread(LPVOID pvThreadData);
  94. void Lock() { EnterCriticalSection(&m_csHashTableLock); }
  95. void Unlock() { LeaveCriticalSection(&m_csHashTableLock); }
  96. void LockDomain() { EnterCriticalSection(&m_csDomainNameLock); }
  97. void UnlockDomain() { LeaveCriticalSection(&m_csDomainNameLock); }
  98. void LockDc() { EnterCriticalSection(&m_csDcNameLock); }
  99. void UnlockDc() { LeaveCriticalSection(&m_csDcNameLock); }
  100. };
  101. typedef CSidCache *PSIDCACHE;
  102. //
  103. // Helper functions for creating/deleting the global SID Cache
  104. //
  105. PSIDCACHE GetSidCache();
  106. void FreeSidCache();
  107. #endif // _SIDCACHE_H_