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.

366 lines
9.8 KiB

  1. #ifndef _INC_DSKQUOTA_USER_H
  2. #define _INC_DSKQUOTA_USER_H
  3. ///////////////////////////////////////////////////////////////////////////////
  4. /* File: user.h
  5. Description: Contains declarations for class DiskQuotaUser. The
  6. DiskQuotaUser object represents a user's quota information on a
  7. particular volume. Per-user quota information is managed through
  8. the IDiskQuotaUser interface.
  9. Revision History:
  10. Date Description Programmer
  11. -------- --------------------------------------------------- ----------
  12. 05/22/96 Initial creation. BrianAu
  13. 08/20/96 Added m_dwID member to DiskQuotaUser. BrianAu
  14. 09/05/96 Added domain name string and cache. BrianAu
  15. 08/25/97 Added OLE automation support. BrianAu
  16. 03/18/98 Replaced "domain", "name" and "full name" with BrianAu
  17. "container", "logon name" and "display name" to
  18. better match the actual contents. This was in
  19. reponse to making the quota UI DS-aware. The
  20. "logon name" is now a unique key as it contains
  21. both account name and domain-like information.
  22. i.e. "REDMOND\brianau" or "[email protected]".
  23. */
  24. ///////////////////////////////////////////////////////////////////////////////
  25. #ifndef _INC_DSKQUOTA_H
  26. # include "dskquota.h"
  27. #endif
  28. #ifndef _INC_DSKQUOTA_FSOBJECT_H
  29. # include "fsobject.h"
  30. #endif
  31. #ifndef _INC_DSKQUOTA_DISPATCH_H
  32. # include "dispatch.h" // MIDL-generated header (automation).
  33. #endif
  34. #ifndef _INC_DSKQUOTA_OADISP_H
  35. # include "oadisp.h" // OleAutoDispatch class (automation).
  36. #endif
  37. class DiskQuotaUser : public IDiskQuotaUser {
  38. private:
  39. LONGLONG m_llQuotaUsed;
  40. LONGLONG m_llQuotaThreshold;
  41. LONGLONG m_llQuotaLimit;
  42. LONG m_cRef; // Ref counter.
  43. ULONG m_ulUniqueId; // Unique object ID.
  44. PSID m_pSid; // Ptr to user's SID structure.
  45. LPTSTR m_pszLogonName; // "[email protected]"
  46. LPTSTR m_pszDisplayName; // "Brian Aust"
  47. FSObject *m_pFSObject; // Ptr to file sys object.
  48. BOOL m_bNeedCacheUpdate; // T = Cached data is invalid.
  49. INT m_iContainerName; // Index into acct container name cache.
  50. DWORD m_dwAccountStatus; // Status of user account.
  51. static HANDLE m_hMutex; // For serializing access to users.
  52. static DWORD m_dwMutexWaitTimeout; // How long to wait for mutex.
  53. static LONG m_cUsersAlive; // Count of users currently alive.
  54. static ULONG m_ulNextUniqueId; // Unique ID generator.
  55. static CArray<CString> m_ContainerNameCache; // Cache container names as they
  56. // are found. Don't need to dup
  57. // names in each user object.
  58. VOID Destroy(VOID);
  59. VOID DestroyContainerNameCache(VOID);
  60. BOOL Lock(VOID);
  61. VOID ReleaseLock(VOID);
  62. //
  63. // Prevent copy construction.
  64. //
  65. DiskQuotaUser(const DiskQuotaUser& user);
  66. void operator = (const DiskQuotaUser& user);
  67. HRESULT
  68. GetLargeIntegerQuotaItem(
  69. PLONGLONG pllItem,
  70. PLONGLONG pllValueOut);
  71. HRESULT
  72. SetLargeIntegerQuotaItem(
  73. PLONGLONG pllItem,
  74. LONGLONG llValue,
  75. BOOL bWriteThrough = TRUE);
  76. HRESULT
  77. RefreshCachedInfo(
  78. VOID);
  79. HRESULT
  80. WriteCachedInfo(
  81. VOID);
  82. HRESULT
  83. GetCachedContainerName(
  84. INT iCacheIndex,
  85. LPTSTR pszContainer,
  86. UINT cchContainer);
  87. HRESULT
  88. CacheContainerName(
  89. LPCTSTR pszContainer,
  90. INT *pCacheIndex);
  91. public:
  92. DiskQuotaUser(FSObject *pFSObject);
  93. ~DiskQuotaUser(VOID);
  94. HRESULT
  95. Initialize(
  96. PFILE_QUOTA_INFORMATION pfqi = NULL);
  97. VOID
  98. SetAccountStatus(
  99. DWORD dwStatus);
  100. STDMETHODIMP
  101. SetName(
  102. LPCWSTR pszContainer,
  103. LPCWSTR pszLogonName,
  104. LPCWSTR pszDisplayName);
  105. //
  106. // IUnknown interface.
  107. //
  108. STDMETHODIMP
  109. QueryInterface(
  110. REFIID,
  111. LPVOID *);
  112. STDMETHODIMP_(ULONG)
  113. AddRef(
  114. VOID);
  115. STDMETHODIMP_(ULONG)
  116. Release(
  117. VOID);
  118. //
  119. // IDiskQuotaUser methods.
  120. //
  121. STDMETHODIMP
  122. GetID(
  123. ULONG *pulID);
  124. STDMETHODIMP
  125. GetName(
  126. LPWSTR pszContainerBuffer,
  127. DWORD cchContainerBuffer,
  128. LPWSTR pszLogonNameBuffer,
  129. DWORD cchLogonNameBuffer,
  130. LPWSTR pszDisplayNameBuffer,
  131. DWORD cchDisplayNameBuffer);
  132. STDMETHODIMP
  133. GetSidLength(
  134. LPDWORD pcbSid);
  135. STDMETHODIMP
  136. GetSid(
  137. PBYTE pSid,
  138. DWORD cbSidBuf);
  139. STDMETHODIMP
  140. GetQuotaThreshold(
  141. PLONGLONG pllThreshold)
  142. {
  143. return GetLargeIntegerQuotaItem(&m_llQuotaThreshold,
  144. pllThreshold);
  145. }
  146. STDMETHODIMP
  147. GetQuotaThresholdText(
  148. LPWSTR pszText,
  149. DWORD cchText);
  150. STDMETHODIMP
  151. GetQuotaLimit(
  152. PLONGLONG pllLimit)
  153. {
  154. return GetLargeIntegerQuotaItem(&m_llQuotaLimit,
  155. pllLimit);
  156. }
  157. STDMETHODIMP
  158. GetQuotaLimitText(
  159. LPWSTR pszText,
  160. DWORD cchText);
  161. STDMETHODIMP
  162. GetQuotaUsed(
  163. PLONGLONG pllUsed)
  164. {
  165. return GetLargeIntegerQuotaItem(&m_llQuotaUsed,
  166. pllUsed);
  167. }
  168. STDMETHODIMP
  169. GetQuotaUsedText(
  170. LPWSTR pszText,
  171. DWORD cchText);
  172. STDMETHODIMP
  173. GetQuotaInformation(
  174. LPVOID pbInfo,
  175. DWORD cbInfo);
  176. STDMETHODIMP
  177. SetQuotaThreshold(
  178. LONGLONG llThreshold,
  179. BOOL bWriteThrough = TRUE);
  180. STDMETHODIMP
  181. SetQuotaLimit(
  182. LONGLONG llLimit,
  183. BOOL bWriteThrough = TRUE);
  184. STDMETHODIMP
  185. Invalidate(
  186. VOID) { m_bNeedCacheUpdate = TRUE;
  187. return NO_ERROR; }
  188. STDMETHODIMP
  189. GetAccountStatus(
  190. LPDWORD pdwAccountStatus);
  191. };
  192. //
  193. // Proxy class to handle all automation interface duties.
  194. // It implements IDispatch and DIDiskQuotaUser passing any actions
  195. // for real disk quota activity onto a referenced DiskQuotaUser object.
  196. // Instances are created in DiskQuotaUser::QueryInterface in response
  197. // to requests for IDispatch and DIDiskQuotaUser.
  198. //
  199. class DiskQuotaUserDisp : public DIDiskQuotaUser
  200. {
  201. public:
  202. explicit DiskQuotaUserDisp(PDISKQUOTA_USER pUser);
  203. ~DiskQuotaUserDisp(VOID);
  204. //
  205. // IUnknown interface.
  206. //
  207. STDMETHODIMP
  208. QueryInterface(
  209. REFIID,
  210. LPVOID *);
  211. STDMETHODIMP_(ULONG)
  212. AddRef(
  213. VOID);
  214. STDMETHODIMP_(ULONG)
  215. Release(
  216. VOID);
  217. //
  218. // IDispatch methods.
  219. //
  220. STDMETHODIMP
  221. GetIDsOfNames(
  222. REFIID riid,
  223. OLECHAR ** rgszNames,
  224. UINT cNames,
  225. LCID lcid,
  226. DISPID *rgDispId);
  227. STDMETHODIMP
  228. GetTypeInfo(
  229. UINT iTInfo,
  230. LCID lcid,
  231. ITypeInfo **ppTInfo);
  232. STDMETHODIMP
  233. GetTypeInfoCount(
  234. UINT *pctinfo);
  235. STDMETHODIMP
  236. Invoke(
  237. DISPID dispIdMember,
  238. REFIID riid,
  239. LCID lcid,
  240. WORD wFlags,
  241. DISPPARAMS *pDispParams,
  242. VARIANT *pVarResult,
  243. EXCEPINFO *pExcepInfo,
  244. UINT *puArgErr);
  245. STDMETHODIMP
  246. get_ID(
  247. long *pID);
  248. STDMETHODIMP
  249. get_AccountContainerName(
  250. BSTR *pContainerName);
  251. STDMETHODIMP
  252. get_DisplayName(
  253. BSTR *pDisplayName);
  254. STDMETHODIMP
  255. get_LogonName(
  256. BSTR *pLogonName);
  257. STDMETHODIMP
  258. get_QuotaThreshold(
  259. double *pThreshold);
  260. STDMETHODIMP
  261. put_QuotaThreshold(
  262. double Threshold);
  263. STDMETHODIMP
  264. get_QuotaThresholdText(
  265. BSTR *pThresholdText);
  266. STDMETHODIMP
  267. get_QuotaLimit(
  268. double *pLimit);
  269. STDMETHODIMP
  270. put_QuotaLimit(
  271. double Limit);
  272. STDMETHODIMP
  273. get_QuotaLimitText(
  274. BSTR *pLimitText);
  275. STDMETHODIMP
  276. get_QuotaUsed(
  277. double *pUsed);
  278. STDMETHODIMP
  279. get_AccountStatus(
  280. AccountStatusConstants *pStatus);
  281. STDMETHODIMP
  282. get_QuotaUsedText(
  283. BSTR *pUsedText);
  284. //
  285. // Methods.
  286. //
  287. STDMETHODIMP
  288. Invalidate(void);
  289. private:
  290. LONG m_cRef;
  291. PDISKQUOTA_USER m_pUser; // For delegation
  292. OleAutoDispatch m_Dispatch; // Automation dispatch object.
  293. //
  294. // Prevent copy.
  295. //
  296. DiskQuotaUserDisp(const DiskQuotaUserDisp& rhs);
  297. DiskQuotaUserDisp& operator = (const DiskQuotaUserDisp& rhs);
  298. };
  299. #endif // _INC_DISKQUOTA_USER_H