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.

353 lines
11 KiB

  1. //+----------------------------------------------------------------------------
  2. //
  3. // Windows NT Active Directory Service domain trust verification WMI provider
  4. //
  5. // Microsoft Windows
  6. // Copyright (C) Microsoft Corporation, 1992 - 1999
  7. //
  8. // File: TrustPrv.h
  9. //
  10. // Contents: WMI provider class definition
  11. //
  12. // Classes:
  13. //
  14. // History: 22-Mar-00 EricB created
  15. //
  16. //-----------------------------------------------------------------------------
  17. #if !defined(_TRUSTPRV_H_INCLUDED_)
  18. #define _TRUSTPRV_H_INCLUDED_
  19. #if _MSC_VER > 1000
  20. #pragma once
  21. #endif // _MSC_VER > 1000
  22. #include "resource.h" // resource defines
  23. #include "msg.h"
  24. #define TM_PROV_NAME L"TrustMonitor"
  25. extern PCWSTR CLASSNAME_STRING_PROVIDER;
  26. extern PCWSTR CLASSNAME_STRING_TRUST;
  27. extern PCWSTR CLASSNAME_STRING_LOCAL;
  28. enum TrustMonClass {NO_CLASS, CLASS_PROVIDER, CLASS_TRUST, CLASS_LOCAL};
  29. enum TrustCheckLevel {DONT_VERIFY = 0, SC_QUERY, PW_VERIFY, SC_RESET};
  30. const DWORD MaxCheckLevel = (DWORD)SC_RESET; // update this if new check levels added
  31. EXTERN_C const CLSID CLSID_TrustMonProvider;
  32. const unsigned long TRUSTMON_FILETIMES_PER_MILLISECOND = 10000;
  33. const DWORD TRUSTMON_FILETIMES_PER_SECOND = 1000 * TRUSTMON_FILETIMES_PER_MILLISECOND;
  34. const __int64 TRUSTMON_FILETIMES_PER_MINUTE = 60 * (__int64)TRUSTMON_FILETIMES_PER_SECOND;
  35. const __int64 TRUSTMON_FILETIMES_PER_HOUR = 60 * (__int64)TRUSTMON_FILETIMES_PER_MINUTE;
  36. const __int64 TRUSTMON_DEFAULT_ENUM_AGE = 20 * TRUSTMON_FILETIMES_PER_MINUTE;
  37. const __int64 TRUSTMON_DEFAULT_VERIFY_AGE = 3 * TRUSTMON_FILETIMES_PER_MINUTE;
  38. const TrustCheckLevel DEFAULT_TRUST_CHECK_LEVEL = PW_VERIFY;
  39. class CAsyncCallWorker; // forward declaration
  40. //+----------------------------------------------------------------------------
  41. //
  42. // Class: CTrustPrv
  43. //
  44. //-----------------------------------------------------------------------------
  45. class CTrustPrv :
  46. public IWbemServices,
  47. public IWbemProviderInit,
  48. public IWbemObjectSink,
  49. public CComObjectRoot,
  50. public CComCoClass<CTrustPrv, &CLSID_TrustMonProvider>
  51. {
  52. public:
  53. CTrustPrv(void);
  54. ~CTrustPrv(void);
  55. BEGIN_COM_MAP(CTrustPrv)
  56. COM_INTERFACE_ENTRY(IWbemServices)
  57. COM_INTERFACE_ENTRY(IWbemProviderInit)
  58. COM_INTERFACE_ENTRY(IWbemObjectSink)
  59. END_COM_MAP()
  60. //DECLARE_NOT_AGGREGATABLE(CTrustPrv)
  61. // Remove the comment from the line above if you don't want your object to
  62. // support aggregation.
  63. DECLARE_REGISTRY_RESOURCEID(IDR_TrustPrv)
  64. //
  65. // IWbemProviderInit
  66. //
  67. STDMETHOD(Initialize)(
  68. IN LPWSTR pszUser,
  69. IN LONG lFlags,
  70. IN LPWSTR pszNamespace,
  71. IN LPWSTR pszLocale,
  72. IN IWbemServices *pNamespace,
  73. IN IWbemContext *pCtx,
  74. IN IWbemProviderInitSink *pInitSink);
  75. //
  76. // IWbemServices
  77. //
  78. // +++ Implemented +++
  79. STDMETHOD(GetObjectAsync)(
  80. IN const BSTR strObjectPath,
  81. IN long lFlags,
  82. IN IWbemContext *pCtx,
  83. IN IWbemObjectSink *pResponseHandler);
  84. STDMETHOD(CreateInstanceEnumAsync)(
  85. IN const BSTR strClass,
  86. IN long lFlags,
  87. IN IWbemContext *pCtx,
  88. IN IWbemObjectSink *pResponseHandler);
  89. // --- NOT Implemented ---
  90. STDMETHOD(OpenNamespace)(
  91. IN const BSTR strNamespace,
  92. IN long lFlags,
  93. IN IWbemContext *pCtx,
  94. IN OUT IWbemServices **ppWorkingNamespace,
  95. IN OUT IWbemCallResult **ppResult)
  96. { return WBEM_E_NOT_SUPPORTED; };
  97. STDMETHOD(CancelAsyncCall)(
  98. IN IWbemObjectSink *pSink)
  99. { return WBEM_E_NOT_SUPPORTED; };
  100. STDMETHOD(QueryObjectSink)(
  101. IN long lFlags,
  102. OUT IWbemObjectSink **ppResponseHandler)
  103. { return WBEM_E_NOT_SUPPORTED; };
  104. STDMETHOD(GetObject)(
  105. IN const BSTR strObjectPath,
  106. IN long lFlags,
  107. IN IWbemContext *pCtx,
  108. IN OUT IWbemClassObject **ppObject,
  109. IN OUT IWbemCallResult **ppCallResult)
  110. { return WBEM_E_NOT_SUPPORTED; };
  111. STDMETHOD(PutClass)(
  112. IN IWbemClassObject *pObject,
  113. IN long lFlags,
  114. IN IWbemContext *pCtx,
  115. IN OUT IWbemCallResult **ppCallResult)
  116. { return WBEM_E_NOT_SUPPORTED; };
  117. STDMETHOD(PutClassAsync)(
  118. IN IWbemClassObject *pObject,
  119. IN long lFlags,
  120. IN IWbemContext *pCtx,
  121. IN IWbemObjectSink *pResponseHandler)
  122. { return WBEM_E_NOT_SUPPORTED; };
  123. STDMETHOD(DeleteClass)(
  124. IN const BSTR strClass,
  125. IN long lFlags,
  126. IN IWbemContext *pCtx,
  127. IN OUT IWbemCallResult **ppCallResult)
  128. { return WBEM_E_NOT_SUPPORTED; };
  129. STDMETHOD(DeleteClassAsync)(
  130. IN const BSTR strClass,
  131. IN long lFlags,
  132. IN IWbemContext *pCtx,
  133. IN IWbemObjectSink *pResponseHandler)
  134. { return WBEM_E_NOT_SUPPORTED; };
  135. STDMETHOD(CreateClassEnum)(
  136. IN const BSTR strSuperclass,
  137. IN long lFlags,
  138. IN IWbemContext *pCtx,
  139. OUT IEnumWbemClassObject **ppEnum)
  140. { return WBEM_E_NOT_SUPPORTED; };
  141. STDMETHOD(CreateClassEnumAsync)(
  142. IN const BSTR strSuperclass,
  143. IN long lFlags,
  144. IN IWbemContext *pCtx,
  145. IN IWbemObjectSink *pResponseHandler)
  146. { return WBEM_E_NOT_SUPPORTED; };
  147. STDMETHOD(PutInstance)(
  148. IN IWbemClassObject *pInst,
  149. IN long lFlags,
  150. IN IWbemContext *pCtx,
  151. IN OUT IWbemCallResult **ppCallResult)
  152. { return WBEM_E_NOT_SUPPORTED; };
  153. STDMETHOD(PutInstanceAsync)(
  154. IN IWbemClassObject *pInst,
  155. IN long lFlags,
  156. IN IWbemContext *pCtx,
  157. IN IWbemObjectSink *pResponseHandler)
  158. { return WBEM_E_NOT_SUPPORTED; };
  159. STDMETHOD(DeleteInstance)(
  160. IN const BSTR strObjectPath,
  161. IN long lFlags,
  162. IN IWbemContext *pCtx,
  163. IN OUT IWbemCallResult **ppCallResult)
  164. { return WBEM_E_NOT_SUPPORTED; };
  165. STDMETHOD(DeleteInstanceAsync)(
  166. IN const BSTR strObjectPath,
  167. IN long lFlags,
  168. IN IWbemContext *pCtx,
  169. IN IWbemObjectSink *pResponseHandler)
  170. { return WBEM_E_NOT_SUPPORTED; };
  171. STDMETHOD(CreateInstanceEnum)(
  172. IN const BSTR strClass,
  173. IN long lFlags,
  174. IN IWbemContext *pCtx,
  175. OUT IEnumWbemClassObject **ppEnum)
  176. { return WBEM_E_NOT_SUPPORTED; };
  177. STDMETHOD(ExecQuery)(
  178. IN const BSTR strQueryLanguage,
  179. IN const BSTR strQuery,
  180. IN long lFlags,
  181. IN IWbemContext *pCtx,
  182. OUT IEnumWbemClassObject **ppEnum)
  183. { return WBEM_E_NOT_SUPPORTED; };
  184. STDMETHOD(ExecQueryAsync)(
  185. IN const BSTR strQueryLanguage,
  186. IN const BSTR strQuery,
  187. IN long lFlags,
  188. IN IWbemContext *pCtx,
  189. IN IWbemObjectSink *pResponseHandler)
  190. { return WBEM_E_NOT_SUPPORTED; };
  191. STDMETHOD(ExecNotificationQuery)(
  192. IN const BSTR strQueryLanguage,
  193. IN const BSTR strQuery,
  194. IN long lFlags,
  195. IN IWbemContext *pCtx,
  196. OUT IEnumWbemClassObject **ppEnum)
  197. { return WBEM_E_NOT_SUPPORTED; };
  198. STDMETHOD(ExecNotificationQueryAsync)(
  199. IN const BSTR strQueryLanguage,
  200. IN const BSTR strQuery,
  201. IN long lFlags,
  202. IN IWbemContext *pCtx,
  203. IN IWbemObjectSink *pResponseHandler)
  204. { return WBEM_E_NOT_SUPPORTED; };
  205. STDMETHOD(ExecMethod)(
  206. IN const BSTR strObjectPath,
  207. IN const BSTR strMethodName,
  208. IN long lFlags,
  209. IN IWbemContext *pCtx,
  210. IN IWbemClassObject *pInParams,
  211. IN OUT IWbemClassObject **ppOutParams,
  212. IN OUT IWbemCallResult **ppCallResult)
  213. { return WBEM_E_NOT_SUPPORTED; };
  214. STDMETHOD(ExecMethodAsync)(
  215. IN const BSTR strObjectPath,
  216. IN const BSTR strMethodName,
  217. IN long lFlags,
  218. IN IWbemContext *pCtx,
  219. IN IWbemClassObject *pInParams,
  220. IN IWbemObjectSink *pResponseHandler)
  221. {return WBEM_E_NOT_SUPPORTED;};
  222. //
  223. // IWbemObjectSink
  224. //
  225. STDMETHOD(Indicate)(
  226. IN LONG lObjectCount,
  227. IN IWbemClassObject ** rgpObjArray);
  228. STDMETHOD(SetStatus)(
  229. IN LONG lFlags,
  230. IN HRESULT hr,
  231. IN BSTR strParam,
  232. IN IWbemClassObject * pObj)
  233. {TRACE(L"CTrustPrv::SetStatus\n");
  234. return WBEM_NO_ERROR;};
  235. void SetTrustListLifetime(DWORD dwMins) {m_liTrustEnumMaxAge.QuadPart = dwMins * TRUSTMON_FILETIMES_PER_MINUTE;}
  236. DWORD GetTrustListLifetime(void) {return (DWORD)(m_liTrustEnumMaxAge.QuadPart / TRUSTMON_FILETIMES_PER_MINUTE);}
  237. void SetTrustStatusLifetime(DWORD dwMins) {m_liVerifyMaxAge.QuadPart = dwMins * TRUSTMON_FILETIMES_PER_MINUTE;}
  238. DWORD GetTrustStatusLifetime(void) {return (DWORD)(m_liVerifyMaxAge.QuadPart / TRUSTMON_FILETIMES_PER_MINUTE);}
  239. void SetTrustCheckLevel(DWORD dwLevel) {if (dwLevel > MaxCheckLevel) dwLevel = MaxCheckLevel; m_TrustCheckLevel = (TrustCheckLevel)dwLevel;}
  240. TrustCheckLevel GetTrustCheckLevel(void) {return m_TrustCheckLevel;}
  241. void SetReturnAll(BOOL fReturnAll) {m_fReturnAllTrusts = fReturnAll;}
  242. BOOL GetReturnAll(void) {return m_fReturnAllTrusts;}
  243. HRESULT SetProviderProps(IWbemClassObject * pClass);
  244. protected:
  245. CComPtr<IWbemServices> m_sipNamespace;
  246. CComPtr<IWbemClassObject> m_sipClassDefTrustProvider;
  247. CComPtr<IWbemClassObject> m_sipClassDefTrustStatus;
  248. friend class CAsyncCallWorker;
  249. private:
  250. HRESULT CreateAndSendProv(IWbemObjectSink * pResponseHandler);
  251. CDomainInfo m_DomainInfo;
  252. HANDLE m_hMutex;
  253. LARGE_INTEGER m_liTrustEnumMaxAge;
  254. LARGE_INTEGER m_liVerifyMaxAge;
  255. TrustCheckLevel m_TrustCheckLevel;
  256. BOOL m_fReturnAllTrusts;
  257. BOOL m_fRegisteredForChanges;
  258. };
  259. //+----------------------------------------------------------------------------
  260. //
  261. // class CAsyncCallWorker
  262. //
  263. //-----------------------------------------------------------------------------
  264. class CAsyncCallWorker
  265. {
  266. public:
  267. CAsyncCallWorker(CTrustPrv * pTrustsImpl,
  268. long lFlags,
  269. IWbemClassObject * pClassDef,
  270. IWbemObjectSink * pResponseHandler,
  271. LPWSTR pwzInstanceName = NULL);
  272. ~CAsyncCallWorker();
  273. static VOID __cdecl CreateInstEnum(PVOID pParam);
  274. static VOID __cdecl GetObj(PVOID pParam);
  275. private:
  276. CComPtr<CTrustPrv> m_sipTrustPrv;
  277. CComPtr<IWbemObjectSink> m_sipResponseHandler;
  278. CComPtr<IWbemClassObject> m_sipClassDef;
  279. LPWSTR m_pwzInstanceName;
  280. long m_lFlags;
  281. };
  282. HRESULT CreateAndSendTrustInst(CTrustInfo & Trust,
  283. IWbemClassObject * pClassDef,
  284. IWbemObjectSink * pResponseHandler);
  285. #define CHECK_HRESULT(hr, x) \
  286. if (FAILED(hr)) { \
  287. TRACE(L"***ERROR 0x%08x at %S line: %d\n", hr, __FILE__, __LINE__); \
  288. x; }
  289. VOID WINAPI DoMofComp(HWND hWndParent,
  290. HINSTANCE hModule,
  291. PCTSTR ptzCommandLine,
  292. INT nShowCmd);
  293. #endif // !defined(_TRUSTPRV_H_INCLUDED_)