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.

130 lines
4.3 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. BOOL LookupNames(PDS_SELECTION_LIST pDsSelList, LPCTSTR pszServer, PUSER_LIST *ppUserList, BOOL bStandalone);
  47. void GetDomainName(LPCTSTR pszServer, LPTSTR pszDomain, ULONG cchDomain);
  48. void GetDcName(LPCTSTR pszDomain, LPTSTR pszDC, ULONG cchDC);
  49. PSID_CACHE_ENTRY FindSid(PSID pSid);
  50. PSID_CACHE_ENTRY MakeEntry(PSID pSid,
  51. SID_NAME_USE SidType,
  52. LPCTSTR pszName,
  53. LPCTSTR pszLogonName = NULL);
  54. BOOL AddEntry(PSID_CACHE_ENTRY pEntry);
  55. BOOL BuildUserList(HDPA hEntryList,
  56. LPCTSTR pszServer,
  57. PUSER_LIST *ppUserList);
  58. private:
  59. int HashSid(PSID pSid);
  60. static int CALLBACK CompareSid(LPVOID p1, LPVOID p2, LPARAM lParam);
  61. void GetUserFriendlyName(LPCTSTR pszSamLogonName,
  62. LPCTSTR pszSamAccountName,
  63. LPCTSTR pszServer,
  64. BOOL bUseSamCompatibleInfo,
  65. BOOL bIsStandalone,
  66. BSTR *pstrLogonName,
  67. BSTR *pstrDisplayName);
  68. BSTR GetNT4DisplayName(LPCTSTR pszAccount,
  69. LPCTSTR pszName,
  70. LPCTSTR pszServer,
  71. BOOL bStandalone);
  72. BOOL InternalLookupSids(HDPA hSids,
  73. LPCTSTR pszServer,
  74. LPSECURITYINFO2 psi2,
  75. HDPA hEntryList,
  76. HWND hWndNotify = NULL,
  77. UINT uMsgNotify = 0);
  78. BOOL LookupSidsHelper(HDPA hSids,
  79. LPCTSTR pszServer,
  80. HDPA hEntryList,
  81. HWND hWndNotify = NULL,
  82. UINT uMsgNotify = 0,
  83. BOOL bSecondTry = FALSE,
  84. BOOL bWellKnown = FALSE);
  85. HRESULT LookupSidsFromObject(HDPA hSids, LPSECURITYINFO2 psi2, HDPA hEntryList);
  86. BOOL InternalLookupNames(PDS_SELECTION_LIST pDsSelList,
  87. LPCTSTR pszServer,
  88. HDPA hEntryList,
  89. BOOL bStandalone);
  90. static DWORD WINAPI InitThread(LPVOID pvThreadData);
  91. void Lock() { EnterCriticalSection(&m_csHashTableLock); }
  92. void Unlock() { LeaveCriticalSection(&m_csHashTableLock); }
  93. void LockDomain() { EnterCriticalSection(&m_csDomainNameLock); }
  94. void UnlockDomain() { LeaveCriticalSection(&m_csDomainNameLock); }
  95. void LockDc() { EnterCriticalSection(&m_csDcNameLock); }
  96. void UnlockDc() { LeaveCriticalSection(&m_csDcNameLock); }
  97. };
  98. typedef CSidCache *PSIDCACHE;
  99. //
  100. // Helper functions for creating/deleting the global SID Cache
  101. //
  102. PSIDCACHE GetSidCache();
  103. void FreeSidCache();
  104. #endif // _SIDCACHE_H_