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.

436 lines
13 KiB

  1. //***************************************************************************
  2. // Copyright (c) Microsoft Corporation
  3. //
  4. // Module Name:
  5. // TRIGGERPROVIDER.H
  6. //
  7. // Abstract:
  8. // Contains CTriggerProvider definition.
  9. //
  10. // Author:
  11. // Vasundhara .G
  12. //
  13. // Revision History:
  14. // Vasundhara .G 9-oct-2k : Created It.
  15. //***************************************************************************
  16. #ifndef __TRIGGER_PROVIDER_H
  17. #define __TRIGGER_PROVIDER_H
  18. // typedefs
  19. typedef TCHAR STRINGVALUE[ MAX_STRING_LENGTH + 1 ];
  20. #define ERROR_TRIGNAME_ALREADY_EXIST 1
  21. #define ERROR_TRIGGER_NOT_DELETED 2
  22. #define ERROR_TRIGGER_NOT_FOUND 3
  23. #define WARNING_INVALID_USER 2
  24. #define ERROR_SCHDEULE_TASK_INVALID_USER 0x80041310
  25. #define ERROR_TASK_SCHDEULE_SERVICE_STOP 0x80041315
  26. #define EXE_STRING _T( ".exe" )
  27. #define CREATE_METHOD_NAME L"CreateETrigger"
  28. #define DELETE_METHOD_NAME L"DeleteETrigger"
  29. #define QUERY_METHOD_NAME L"QueryETrigger"
  30. #define IN_TRIGGER_ID L"TriggerID"
  31. #define IN_TRIGGER_NAME L"TriggerName"
  32. #define IN_TRIGGER_DESC L"TriggerDesc"
  33. #define IN_TRIGGER_ACTION L"TriggerAction"
  34. #define IN_TRIGGER_QUERY L"TriggerQuery"
  35. #define IN_TRIGGER_USER L"RunAsUser"
  36. #define IN_TRIGGER_PWD L"RunAsPwd"
  37. #define IN_TRIGGER_TSCHDULER L"ScheduledTaskName"
  38. #define RETURN_VALUE L"ReturnValue"
  39. #define OUT_RUNAS_USER L"RunAsUser"
  40. #define UNIQUE_TASK_NAME _T( "%s%d%d" )
  41. #define NAMESPACE L"root\\cimv2"
  42. #define CONSUMER_CLASS L"CmdTriggerConsumer"
  43. #define TRIGGER_ID L"TriggerID"
  44. #define TRIGGER_NAME L"TriggerName"
  45. #define TRIGGER_DESC L"TriggerDesc"
  46. #define TRIGGER_ACTION L"Action"
  47. #define TASK_SHEDULER L"ScheduledTaskName"
  48. #define FILTER_CLASS L"__EventFilter"
  49. #define FILTER_NAME L"Name"
  50. #define FILTER_QUERY_LANGUAGE L"QueryLanguage"
  51. #define QUERY_LANGUAGE L"WQL"
  52. #define FILTER_QUERY L"Query"
  53. #define BINDINGCLASS L"__FilterToConsumerBinding"
  54. #define CONSUMER_BIND L"Consumer"
  55. #define FILTER_BIND L"Filter"
  56. #define REL_PATH L"__RELPATH"
  57. #define BIND_CONSUMER_PATH _T( "CmdTriggerConsumer.TriggerID=%d" )
  58. #define TRIGGER_INSTANCE_NAME _T( "SELECT * FROM CmdTriggerConsumer WHERE TriggerName = \"%s\"" )
  59. #define BIND_FILTER_PATH _T( "__EventFilter.Name=\"" )
  60. #define BACK_SLASH L"\""
  61. #define DOUBLE_SLASH L"\\\"\""
  62. #define EQUAL _T( '=' )
  63. #define DOUBLE_QUOTE _T( '"' )
  64. #define END_OF_STRING _T( '\0' )
  65. #define FILTER_PROP _T( "__FilterToConsumerBinding.Consumer=\"%s\",Filter=\"__EventFilter.Name=\\\"" )
  66. #define FILTER_UNIQUE_NAME _T( "CmdTriggerConsumer.%d%d:%d:%d%d/%d/%d" )
  67. #define CONSUMER_QUERY _T("SELECT * FROM CmdTriggerConsumer WHERE TriggerName = \"%s\"")
  68. #define VALID_QUERY _T("__instancecreationevent where targetinstance isa \"win32_ntlogevent\"")
  69. #define EVENT_LOG _T("win32_ntlogevent")
  70. #define INSTANCE_EXISTS_QUERY L"select * from CmdTriggerConsumer"
  71. // provider class
  72. class CTriggerProvider : public IDispatch,
  73. public IWbemEventConsumerProvider,
  74. public IWbemServices, public IWbemProviderInit
  75. {
  76. private:
  77. DWORD m_dwCount; // holds the object reference count
  78. DWORD m_dwNextTriggerID; // holds the value of the next trigger id
  79. // WMI related stuff
  80. LPWSTR m_pwszLocale;
  81. IWbemContext* m_pContext;
  82. IWbemServices* m_pServices;
  83. // construction / destruction
  84. public:
  85. CTriggerProvider();
  86. ~CTriggerProvider();
  87. // methods
  88. private:
  89. HRESULT CreateTrigger( VARIANT varTName,
  90. VARIANT varTDesc,
  91. VARIANT varTAction,
  92. VARIANT varTQuery,
  93. VARIANT varRUser,
  94. VARIANT varRPwd,
  95. HRESULT *phRes = NULL );
  96. HRESULT DeleteTrigger( VARIANT varTName,
  97. DWORD *dwTrigId );
  98. HRESULT QueryTrigger( VARIANT varScheduledTaskName,
  99. CHString &szRunAsUser );
  100. HRESULT ValidateParams( VARIANT varTrigName,
  101. VARIANT varTrigAction,
  102. VARIANT varTrigQuery );
  103. HRESULT SetUserContext( VARIANT varRUser,
  104. VARIANT varRPwd,
  105. VARIANT varTAction,
  106. CHString &szscheduler );
  107. HRESULT DeleteTaskScheduler( CHString strTScheduler );
  108. ITaskScheduler* GetTaskScheduler();
  109. VOID CTriggerProvider::GetUniqueTScheduler( CHString& szScheduler,
  110. DWORD dwTrigID,
  111. VARIANT varTrigName );
  112. // [ implementation of ] interfaces members
  113. public:
  114. // ****
  115. // IUnknown members
  116. STDMETHODIMP_(ULONG) AddRef( void );
  117. STDMETHODIMP_(ULONG) Release( void );
  118. STDMETHODIMP QueryInterface( REFIID riid, LPVOID* ppv );
  119. // ****
  120. // IDispatch interface
  121. STDMETHOD( GetTypeInfoCount )( THIS_ UINT FAR* pctinfo )
  122. {
  123. // not implemented at this class level ... handled by base class ( WMI base class )
  124. return WBEM_E_NOT_SUPPORTED;
  125. };
  126. STDMETHOD( GetTypeInfo )(
  127. THIS_ UINT itinfo,
  128. LCID lcid,
  129. ITypeInfo FAR* FAR* pptinfo )
  130. {
  131. // not implemented at this class level ... handled by base class ( WMI base class )
  132. return WBEM_E_NOT_SUPPORTED;
  133. };
  134. STDMETHOD( GetIDsOfNames )(
  135. THIS_ REFIID riid,
  136. OLECHAR FAR* FAR* rgszNames,
  137. UINT cNames,
  138. LCID lcid,
  139. DISPID FAR* rgdispid )
  140. {
  141. // not implemented at this class level ... handled by base class ( WMI base class )
  142. return WBEM_E_NOT_SUPPORTED;
  143. };
  144. STDMETHOD( Invoke )(
  145. THIS_ DISPID dispidMember,
  146. REFIID riid,
  147. LCID lcid,
  148. WORD wFlags,
  149. DISPPARAMS FAR* pdispparams,
  150. VARIANT FAR* pvarResult,
  151. EXCEPINFO FAR* pexcepinfo,
  152. UINT FAR* puArgErr )
  153. {
  154. // not implemented at this class level ... handled by base class ( WMI base class )
  155. return WBEM_E_NOT_SUPPORTED;
  156. };
  157. // ****
  158. // IWbemProviderInit members
  159. HRESULT STDMETHODCALLTYPE Initialize(
  160. LPWSTR pszUser,
  161. LONG lFlags,
  162. LPWSTR pszNamespace,
  163. LPWSTR pszLocale,
  164. IWbemServices *pNamespace,
  165. IWbemContext *pCtx,
  166. IWbemProviderInitSink *pInitSink );
  167. // ****
  168. // IWbemServices members
  169. HRESULT STDMETHODCALLTYPE OpenNamespace(
  170. const BSTR Namespace,
  171. long lFlags,
  172. IWbemContext __RPC_FAR *pCtx,
  173. IWbemServices __RPC_FAR *__RPC_FAR *ppWorkingNamespace,
  174. IWbemCallResult __RPC_FAR *__RPC_FAR *ppResult )
  175. {
  176. // not implemented at this class level ... handled by base class ( WMI base class )
  177. return WBEM_E_NOT_SUPPORTED;
  178. };
  179. HRESULT STDMETHODCALLTYPE CancelAsyncCall( IWbemObjectSink __RPC_FAR *pSink )
  180. {
  181. // not implemented at this class level ... handled by base class ( WMI base class )
  182. return WBEM_E_NOT_SUPPORTED;
  183. };
  184. HRESULT STDMETHODCALLTYPE QueryObjectSink(
  185. long lFlags,
  186. IWbemObjectSink __RPC_FAR *__RPC_FAR *ppResponseHandler )
  187. {
  188. // not implemented at this class level ... handled by base class ( WMI base class )
  189. return WBEM_E_NOT_SUPPORTED;
  190. };
  191. HRESULT STDMETHODCALLTYPE GetObject(
  192. const BSTR ObjectPath,
  193. long lFlags,
  194. IWbemContext __RPC_FAR *pCtx,
  195. IWbemClassObject __RPC_FAR *__RPC_FAR *ppObject,
  196. IWbemCallResult __RPC_FAR *__RPC_FAR *ppCallResult )
  197. {
  198. // not implemented at this class level ... handled by base class ( WMI base class )
  199. return WBEM_E_NOT_SUPPORTED;
  200. };
  201. HRESULT STDMETHODCALLTYPE GetObjectAsync(
  202. const BSTR ObjectPath,
  203. long lFlags,
  204. IWbemContext __RPC_FAR *pCtx,
  205. IWbemObjectSink __RPC_FAR *pResponseHandler )
  206. {
  207. // not implemented at this class level ... handled by base class ( WMI base class )
  208. return WBEM_E_NOT_SUPPORTED;
  209. }
  210. HRESULT STDMETHODCALLTYPE PutClass(
  211. IWbemClassObject __RPC_FAR *pObject,
  212. long lFlags,
  213. IWbemContext __RPC_FAR *pCtx,
  214. IWbemCallResult __RPC_FAR *__RPC_FAR *ppCallResult )
  215. {
  216. // not implemented at this class level ... handled by base class ( WMI base class )
  217. return WBEM_E_NOT_SUPPORTED;
  218. };
  219. HRESULT STDMETHODCALLTYPE PutClassAsync(
  220. IWbemClassObject __RPC_FAR *pObject,
  221. long lFlags,
  222. IWbemContext __RPC_FAR *pCtx,
  223. IWbemObjectSink __RPC_FAR *pResponseHandler )
  224. {
  225. // not implemented at this class level ... handled by base class ( WMI base class )
  226. return WBEM_E_NOT_SUPPORTED;
  227. };
  228. HRESULT STDMETHODCALLTYPE DeleteClass(
  229. const BSTR Class,
  230. long lFlags,
  231. IWbemContext __RPC_FAR *pCtx,
  232. IWbemCallResult __RPC_FAR *__RPC_FAR *ppCallResult )
  233. {
  234. // not implemented at this class level ... handled by base class ( WMI base class )
  235. return WBEM_E_NOT_SUPPORTED;
  236. };
  237. HRESULT STDMETHODCALLTYPE DeleteClassAsync(
  238. const BSTR Class,
  239. long lFlags,
  240. IWbemContext __RPC_FAR *pCtx,
  241. IWbemObjectSink __RPC_FAR *pResponseHandler)
  242. {
  243. // not implemented at this class level ... handled by base class ( WMI base class )
  244. return WBEM_E_NOT_SUPPORTED;
  245. };
  246. HRESULT STDMETHODCALLTYPE CreateClassEnum(
  247. const BSTR Superclass,
  248. long lFlags,
  249. IWbemContext __RPC_FAR *pCtx,
  250. IEnumWbemClassObject __RPC_FAR *__RPC_FAR *ppEnum )
  251. {
  252. // not implemented at this class level ... handled by base class ( WMI base class )
  253. return WBEM_E_NOT_SUPPORTED;
  254. };
  255. HRESULT STDMETHODCALLTYPE CreateClassEnumAsync(
  256. const BSTR Superclass,
  257. long lFlags,
  258. IWbemContext __RPC_FAR *pCtx,
  259. IWbemObjectSink __RPC_FAR *pResponseHandler )
  260. {
  261. // not implemented at this class level ... handled by base class ( WMI base class )
  262. return WBEM_E_NOT_SUPPORTED;
  263. };
  264. HRESULT STDMETHODCALLTYPE PutInstance(
  265. IWbemClassObject __RPC_FAR *pInst,
  266. long lFlags,
  267. IWbemContext __RPC_FAR *pCtx,
  268. IWbemCallResult __RPC_FAR *__RPC_FAR *ppCallResult )
  269. {
  270. // not implemented at this class level ... handled by base class ( WMI base class )
  271. return WBEM_E_NOT_SUPPORTED;
  272. };
  273. HRESULT STDMETHODCALLTYPE PutInstanceAsync(
  274. IWbemClassObject __RPC_FAR *pInst,
  275. long lFlags,
  276. IWbemContext __RPC_FAR *pCtx,
  277. IWbemObjectSink __RPC_FAR *pResponseHandler )
  278. {
  279. // not implemented at this class level ... handled by base class ( WMI base class )
  280. return WBEM_E_NOT_SUPPORTED;
  281. };
  282. HRESULT STDMETHODCALLTYPE DeleteInstance(
  283. const BSTR ObjectPath,
  284. long lFlags,
  285. IWbemContext __RPC_FAR *pCtx,
  286. IWbemCallResult __RPC_FAR *__RPC_FAR *ppCallResult )
  287. {
  288. // not implemented at this class level ... handled by base class ( WMI base class )
  289. return WBEM_E_NOT_SUPPORTED;
  290. };
  291. HRESULT STDMETHODCALLTYPE DeleteInstanceAsync(
  292. const BSTR ObjectPath,
  293. long lFlags,
  294. IWbemContext __RPC_FAR *pCtx,
  295. IWbemObjectSink __RPC_FAR *pResponseHandler )
  296. {
  297. // not implemented at this class level ... handled by base class ( WMI base class )
  298. return WBEM_E_NOT_SUPPORTED;
  299. };
  300. HRESULT STDMETHODCALLTYPE CreateInstanceEnum(
  301. const BSTR Class,
  302. long lFlags,
  303. IWbemContext __RPC_FAR *pCtx,
  304. IEnumWbemClassObject __RPC_FAR *__RPC_FAR *ppEnum )
  305. {
  306. // not implemented at this class level ... handled by base class ( WMI base class )
  307. return WBEM_E_NOT_SUPPORTED;
  308. };
  309. HRESULT STDMETHODCALLTYPE CreateInstanceEnumAsync(
  310. const BSTR Class,
  311. long lFlags,
  312. IWbemContext __RPC_FAR *pCtx,
  313. IWbemObjectSink __RPC_FAR *pResponseHandler )
  314. {
  315. // not implemented at this class level ... handled by base class ( WMI base class )
  316. return WBEM_E_NOT_SUPPORTED;
  317. }
  318. HRESULT STDMETHODCALLTYPE ExecQuery(
  319. const BSTR QueryLanguage,
  320. const BSTR Query,
  321. long lFlags,
  322. IWbemContext __RPC_FAR *pCtx,
  323. IEnumWbemClassObject __RPC_FAR *__RPC_FAR *ppEnum )
  324. {
  325. // not implemented at this class level ... handled by base class ( WMI base class )
  326. return WBEM_E_NOT_SUPPORTED;
  327. };
  328. HRESULT STDMETHODCALLTYPE ExecQueryAsync(
  329. const BSTR QueryLanguage,
  330. const BSTR Query,
  331. long lFlags,
  332. IWbemContext __RPC_FAR *pCtx,
  333. IWbemObjectSink __RPC_FAR *pResponseHandler )
  334. {
  335. // not implemented at this class level ... handled by base class ( WMI base class )
  336. return WBEM_E_NOT_SUPPORTED;
  337. };
  338. HRESULT STDMETHODCALLTYPE ExecNotificationQuery(
  339. const BSTR QueryLanguage,
  340. const BSTR Query,
  341. long lFlags,
  342. IWbemContext __RPC_FAR *pCtx,
  343. IEnumWbemClassObject __RPC_FAR *__RPC_FAR *ppEnum )
  344. {
  345. // not implemented at this class level ... handled by base class ( WMI base class )
  346. return WBEM_E_NOT_SUPPORTED;
  347. };
  348. HRESULT STDMETHODCALLTYPE ExecNotificationQueryAsync(
  349. const BSTR QueryLanguage,
  350. const BSTR Query,
  351. long lFlags,
  352. IWbemContext __RPC_FAR *pCtx,
  353. IWbemObjectSink __RPC_FAR *pResponseHandler )
  354. {
  355. // not implemented at this class level ... handled by base class ( WMI base class )
  356. return WBEM_E_NOT_SUPPORTED;
  357. };
  358. HRESULT STDMETHODCALLTYPE ExecMethod(
  359. const BSTR strObjectPath,
  360. const BSTR strMethodName,
  361. long lFlags,
  362. IWbemContext* pCtx,
  363. IWbemClassObject* pInParams,
  364. IWbemClassObject** ppOutParams,
  365. IWbemCallResult** ppCallResult )
  366. {
  367. // not implemented at this class level ... handled by base class ( WMI base class )
  368. return WBEM_E_NOT_SUPPORTED;
  369. }
  370. // *** one of method implemented by this provider under IWbemServices interface ***
  371. HRESULT STDMETHODCALLTYPE ExecMethodAsync(
  372. const BSTR strObjectPath,
  373. const BSTR strMethodName,
  374. long lFlags,
  375. IWbemContext* pCtx,
  376. IWbemClassObject* pInParams,
  377. IWbemObjectSink* pResponseHandler );
  378. // ****
  379. // IWbemEventConsumerProvider members
  380. // ( this routine allows you to map the one physical consumer to potentially
  381. // multiple logical consumers. )
  382. STDMETHOD( FindConsumer )( IWbemClassObject* pLogicalConsumer,
  383. IWbemUnboundObjectSink** ppConsumer);
  384. };
  385. #endif // __TRIGGER_PROVIDER_H