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.

302 lines
7.5 KiB

  1. //***************************************************************************
  2. //
  3. // Copyright (c) 1998-1999 Microsoft Corporation
  4. //
  5. // PRIVILEGE.H
  6. //
  7. // alanbos 30-Sep-98 Created.
  8. //
  9. // Define Privilege classes.
  10. //
  11. //***************************************************************************
  12. #ifndef _PRIVILEGE_H_
  13. #define _PRIVILEGE_H_
  14. using namespace std;
  15. class CEnumPrivilegeSet;
  16. //***************************************************************************
  17. //
  18. // CLASS NAME:
  19. //
  20. // CSWbemPrivilege
  21. //
  22. // DESCRIPTION:
  23. //
  24. // Implements the ISWbemPrivilege interface.
  25. //
  26. //***************************************************************************
  27. class CSWbemPrivilege : public ISWbemPrivilege,
  28. public ISupportErrorInfo,
  29. public IProvideClassInfo
  30. {
  31. private:
  32. CDispatchHelp m_Dispatch;
  33. LUID m_Luid;
  34. bool m_bIsEnabled;
  35. WbemPrivilegeEnum m_privilege;
  36. protected:
  37. long m_cRef; //Object reference count
  38. public:
  39. CSWbemPrivilege (WbemPrivilegeEnum privilege, LUID &luid, bool bIsEnabled);
  40. virtual ~CSWbemPrivilege (void);
  41. //Non-delegating object IUnknown
  42. STDMETHODIMP QueryInterface(REFIID, LPVOID*);
  43. STDMETHODIMP_(ULONG) AddRef(void);
  44. STDMETHODIMP_(ULONG) Release(void);
  45. // IDispatch
  46. STDMETHODIMP GetTypeInfoCount(UINT* pctinfo)
  47. {return m_Dispatch.GetTypeInfoCount(pctinfo);}
  48. STDMETHODIMP GetTypeInfo(UINT itinfo, LCID lcid, ITypeInfo** pptinfo)
  49. {return m_Dispatch.GetTypeInfo(itinfo, lcid, pptinfo);}
  50. STDMETHODIMP GetIDsOfNames(REFIID riid, OLECHAR** rgszNames,
  51. UINT cNames, LCID lcid, DISPID* rgdispid)
  52. {return m_Dispatch.GetIDsOfNames(riid, rgszNames, cNames,
  53. lcid,
  54. rgdispid);}
  55. STDMETHODIMP Invoke(DISPID dispidMember, REFIID riid, LCID lcid,
  56. WORD wFlags, DISPPARAMS* pdispparams, VARIANT* pvarResult,
  57. EXCEPINFO* pexcepinfo, UINT* puArgErr)
  58. {return m_Dispatch.Invoke(dispidMember, riid, lcid, wFlags,
  59. pdispparams, pvarResult, pexcepinfo, puArgErr);}
  60. // ISWbemPrivilege methods
  61. HRESULT STDMETHODCALLTYPE get_IsEnabled
  62. (
  63. /* [out] */ VARIANT_BOOL *bIsEnabled
  64. );
  65. HRESULT STDMETHODCALLTYPE put_IsEnabled
  66. (
  67. /* [in] */ VARIANT_BOOL bIsEnabled
  68. );
  69. HRESULT STDMETHODCALLTYPE get_Name
  70. (
  71. /* [out] */ BSTR *bsName
  72. );
  73. HRESULT STDMETHODCALLTYPE get_DisplayName
  74. (
  75. /* [out] */ BSTR *bsDisplayName
  76. );
  77. HRESULT STDMETHODCALLTYPE get_Identifier
  78. (
  79. /* [out] */ WbemPrivilegeEnum *iPrivilege
  80. );
  81. // ISupportErrorInfo methods
  82. HRESULT STDMETHODCALLTYPE InterfaceSupportsErrorInfo
  83. (
  84. /* [in] */ REFIID riid
  85. );
  86. // IProvideClassInfo methods
  87. HRESULT STDMETHODCALLTYPE GetClassInfo
  88. (
  89. /* [in,out] */ ITypeInfo **ppTI
  90. )
  91. {
  92. return m_Dispatch.GetClassInfo (ppTI);
  93. };
  94. // CSWbemPrivilege methods
  95. void GetLUID (PLUID pLuid);
  96. static TCHAR *GetNameFromId (WbemPrivilegeEnum iPrivilege);
  97. static OLECHAR *GetMonikerNameFromId (WbemPrivilegeEnum iPrivilege);
  98. static bool GetIdFromMonikerName (OLECHAR *name, WbemPrivilegeEnum &iPrivilege);
  99. static bool GetIdFromName (BSTR bsName, WbemPrivilegeEnum &iPrivilege);
  100. };
  101. typedef map< WbemPrivilegeEnum,CSWbemPrivilege*,less<int>, CWbemAllocator<CSWbemPrivilege*> > PrivilegeMap;
  102. //***************************************************************************
  103. //
  104. // CLASS NAME:
  105. //
  106. // CSWbemPrivilegeSet
  107. //
  108. // DESCRIPTION:
  109. //
  110. // Implements the ISWbemPrivilegeSet interface.
  111. //
  112. //***************************************************************************
  113. class CSWbemPrivilegeSet : public ISWbemPrivilegeSet,
  114. public ISupportErrorInfo,
  115. public IProvideClassInfo
  116. {
  117. friend CEnumPrivilegeSet;
  118. friend CSWbemSecurity;
  119. private:
  120. bool m_bMutable;
  121. CDispatchHelp m_Dispatch;
  122. PrivilegeMap m_PrivilegeMap;
  123. protected:
  124. long m_cRef; //Object reference count
  125. public:
  126. CSWbemPrivilegeSet ();
  127. CSWbemPrivilegeSet (const CSWbemPrivilegeSet &privSet,
  128. bool bMutable = true);
  129. CSWbemPrivilegeSet (ISWbemPrivilegeSet *pISWbemPrivilegeSet);
  130. virtual ~CSWbemPrivilegeSet (void);
  131. //Non-delegating object IUnknown
  132. STDMETHODIMP QueryInterface(REFIID, LPVOID*);
  133. STDMETHODIMP_(ULONG) AddRef(void);
  134. STDMETHODIMP_(ULONG) Release(void);
  135. // IDispatch
  136. STDMETHODIMP GetTypeInfoCount(UINT* pctinfo)
  137. {return m_Dispatch.GetTypeInfoCount(pctinfo);}
  138. STDMETHODIMP GetTypeInfo(UINT itinfo, LCID lcid, ITypeInfo** pptinfo)
  139. {return m_Dispatch.GetTypeInfo(itinfo, lcid, pptinfo);}
  140. STDMETHODIMP GetIDsOfNames(REFIID riid, OLECHAR** rgszNames,
  141. UINT cNames, LCID lcid, DISPID* rgdispid)
  142. {return m_Dispatch.GetIDsOfNames(riid, rgszNames, cNames,
  143. lcid,
  144. rgdispid);}
  145. STDMETHODIMP Invoke(DISPID dispidMember, REFIID riid, LCID lcid,
  146. WORD wFlags, DISPPARAMS* pdispparams, VARIANT* pvarResult,
  147. EXCEPINFO* pexcepinfo, UINT* puArgErr)
  148. {return m_Dispatch.Invoke(dispidMember, riid, lcid, wFlags,
  149. pdispparams, pvarResult, pexcepinfo, puArgErr);}
  150. // Collection methods
  151. HRESULT STDMETHODCALLTYPE get__NewEnum
  152. (
  153. /*[out]*/ IUnknown **ppUnk
  154. );
  155. HRESULT STDMETHODCALLTYPE Item
  156. (
  157. /*[in]*/ WbemPrivilegeEnum privilege,
  158. /*[out]*/ ISWbemPrivilege **ppPrivilege
  159. );
  160. HRESULT STDMETHODCALLTYPE get_Count
  161. (
  162. /*[in]*/ long *plCount
  163. );
  164. HRESULT STDMETHODCALLTYPE Add
  165. (
  166. /*[in]*/ WbemPrivilegeEnum privilege,
  167. /*[in]*/ VARIANT_BOOL bIsEnabled,
  168. /*[out]*/ ISWbemPrivilege **ppPrivilege
  169. );
  170. HRESULT STDMETHODCALLTYPE Remove
  171. (
  172. /*[in]*/ WbemPrivilegeEnum privilege
  173. );
  174. // CSWbemPrivilegeSet methods
  175. HRESULT STDMETHODCALLTYPE DeleteAll
  176. (
  177. );
  178. HRESULT STDMETHODCALLTYPE AddAsString
  179. (
  180. /*[in]*/ BSTR strPrivilege,
  181. /*[in]*/ VARIANT_BOOL bIsEnabled,
  182. /*[out]*/ ISWbemPrivilege **ppPrivilege
  183. );
  184. // ISupportErrorInfo methods
  185. HRESULT STDMETHODCALLTYPE InterfaceSupportsErrorInfo
  186. (
  187. /* [in] */ REFIID riid
  188. );
  189. // IProvideClassInfo methods
  190. HRESULT STDMETHODCALLTYPE GetClassInfo
  191. (
  192. /* [in,out] */ ITypeInfo **ppTI
  193. )
  194. {
  195. return m_Dispatch.GetClassInfo (ppTI);
  196. };
  197. // Other methods
  198. ULONG GetNumberOfDisabledElements ();
  199. PrivilegeMap &GetPrivilegeMap ()
  200. {
  201. return m_PrivilegeMap;
  202. }
  203. void Reset (CSWbemPrivilegeSet &privSet);
  204. };
  205. //***************************************************************************
  206. //
  207. // CLASS NAME:
  208. //
  209. // CEnumPrivilegeSet
  210. //
  211. // DESCRIPTION:
  212. //
  213. // Implements the IEnumVARIANT interface for Privilege collections.
  214. //
  215. //***************************************************************************
  216. class CEnumPrivilegeSet : public IEnumVARIANT
  217. {
  218. private:
  219. long m_cRef;
  220. CSWbemPrivilegeSet *m_pPrivilegeSet;
  221. PrivilegeMap::iterator m_Iterator;
  222. public:
  223. CEnumPrivilegeSet (CSWbemPrivilegeSet *pPrivilegeSet);
  224. CEnumPrivilegeSet (CSWbemPrivilegeSet *pPrivilegeSet,
  225. PrivilegeMap::iterator iterator);
  226. virtual ~CEnumPrivilegeSet (void);
  227. // Non-delegating object IUnknown
  228. STDMETHODIMP QueryInterface(REFIID, LPVOID*);
  229. STDMETHODIMP_(ULONG) AddRef(void);
  230. STDMETHODIMP_(ULONG) Release(void);
  231. // IEnumVARIANT
  232. STDMETHODIMP Next(
  233. unsigned long celt,
  234. VARIANT FAR* rgvar,
  235. unsigned long FAR* pceltFetched
  236. );
  237. STDMETHODIMP Skip(
  238. unsigned long celt
  239. );
  240. STDMETHODIMP Reset();
  241. STDMETHODIMP Clone(
  242. IEnumVARIANT **ppenum
  243. );
  244. };
  245. #endif