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.

556 lines
14 KiB

  1. //////////////////////////////////////////////////////////////////////
  2. // NetSecProv.h : Declaration of the CNetSecProv
  3. // Copyright (c)1997-2001 Microsoft Corporation
  4. //
  5. // this is the Network Security WMI provider for SCE
  6. // Original Create Date: 2/19/2001
  7. // Original Author: shawnwu
  8. //////////////////////////////////////////////////////////////////////
  9. #pragma once
  10. #include "globals.h"
  11. using namespace std;
  12. typedef LPVOID * PPVOID;
  13. //
  14. // forward declaration to use these two interface inside function declaration
  15. //
  16. interface ISceKeyChain;
  17. interface IIPSecObjectImpl;
  18. /*
  19. Class CCriticalSection
  20. Naming:
  21. CCriticalSection stands for Critical Section.
  22. Base class:
  23. None.
  24. Purpose of class:
  25. Wrapper of Critical section object. This trivial helper at least do two
  26. things:
  27. (1) Critical section initialization and deletion will be automatic.
  28. (2) Helps to easily create a unique global stack variable of a critical
  29. section. Don't need to worry about creation time any more.
  30. Design:
  31. Trivial. Just the initialization inside constructor and deletion inside
  32. destructor, plus a pair of Enter and Leave functions.
  33. Use:
  34. (1) Create an instance if you need to do so. Otherwise, just reference the
  35. already created one.
  36. (2) Call Enter just as you would do with EnterCriticalSection when you need
  37. protected access to global objects.
  38. (3) Call Leave just as you would do with LeaveCriticalSection when you are
  39. done with the protected global objects.
  40. Notes:
  41. class CCriticalSection
  42. {
  43. public:
  44. CCriticalSection()
  45. {
  46. ::InitializeCriticalSection(&m_cs);
  47. }
  48. ~CCriticalSection()
  49. {
  50. ::DeleteCriticalSection(&m_cs);
  51. }
  52. void Enter()
  53. {
  54. ::EnterCriticalSection(&m_cs);
  55. }
  56. void Leave()
  57. {
  58. ::LeaveCriticalSection(&m_cs);
  59. }
  60. private:
  61. CRITICAL_SECTION m_cs;
  62. };
  63. */
  64. //
  65. // Two helper functions
  66. //
  67. //
  68. // $undone:shawnwu, need work on refining this pulling implementation.
  69. // We should do a pushing to enhance performance of the globals
  70. //
  71. // void UpdateGlobals(IWbemServices* pNamespace, IWbemContext* pCtx);
  72. //
  73. // To support testing. Since IPSec's operations may render the system
  74. // totally unusable, during development, we will be so much better off
  75. // if we can do (thus test) everything except the last step, which is
  76. // to put/delete object to/from SPD.
  77. //
  78. /*
  79. Class CDefWbemService
  80. Naming:
  81. CDefWbemService stands for Default Wbem Service.
  82. Base class:
  83. (1) CComObjectRootEx: for threading model and IUnknown.
  84. (2) IWbemServices: the purpose of the class. We don't want to
  85. the real provider to have so many dummy functions to confuse
  86. ourselves. We thus implement all of those that we don't want
  87. to implement in our final provider class.
  88. Purpose of class:
  89. Implements all functions (to not supported) so that the its derived class
  90. is no longer crowded by all these functions. This cleans up our real
  91. provider's implmentation.
  92. Design:
  93. (1) return WBEM_E_NOT_SUPPORTED for all the functions of IWbemServices.
  94. (2) Inherit from CComObjectRootEx to get the threading model and IUnknown.
  95. Use:
  96. (1) This is only for our provider class to inherit. You will never use it
  97. directly other than deriving from it.
  98. Notes:
  99. */
  100. class ATL_NO_VTABLE CDefWbemService
  101. :
  102. public CComObjectRootEx<CComMultiThreadModel>,
  103. public IWbemServices
  104. {
  105. public:
  106. DECLARE_NOT_AGGREGATABLE(CDefWbemService)
  107. DECLARE_PROTECT_FINAL_CONSTRUCT()
  108. BEGIN_COM_MAP(CDefWbemService)
  109. COM_INTERFACE_ENTRY(IWbemServices)
  110. END_COM_MAP()
  111. public:
  112. STDMETHOD(OpenNamespace)(
  113. IN const BSTR Namespace,
  114. IN long lFlags,
  115. IN IWbemContext * pCtx,
  116. IN OUT IWbemServices ** ppWorkingNamespace,
  117. IN OUT IWbemCallResult ** ppResult
  118. )
  119. {
  120. return WBEM_E_NOT_SUPPORTED;
  121. }
  122. STDMETHOD(CancelAsyncCall) (
  123. IN IWbemObjectSink * pSink
  124. )
  125. {
  126. return WBEM_E_NOT_SUPPORTED;
  127. }
  128. STDMETHOD(QueryObjectSink) (
  129. IN long lFlags,
  130. IN OUT IWbemObjectSink ** pSink
  131. )
  132. {
  133. return WBEM_E_NOT_SUPPORTED;
  134. }
  135. STDMETHOD(GetObject) (
  136. IN const BSTR ObjectPath,
  137. IN long lFlags,
  138. IN IWbemContext * pCtx,
  139. IN OUT IWbemClassObject ** ppObject,
  140. IN OUT IWbemCallResult ** ppCallResult
  141. )
  142. {
  143. return WBEM_E_NOT_SUPPORTED;
  144. }
  145. STDMETHOD(GetObjectAsync) (
  146. IN const BSTR ObjectPath,
  147. IN long lFlags,
  148. IN IWbemContext * pCtx,
  149. IN IWbemObjectSink * pSink
  150. )
  151. {
  152. return WBEM_E_NOT_SUPPORTED;
  153. }
  154. STDMETHOD(PutClass) (
  155. IN IWbemClassObject * pObject,
  156. IN long lFlags,
  157. IN IWbemContext * pCtx,
  158. IN OUT IWbemCallResult ** ppCallResult
  159. )
  160. {
  161. return WBEM_E_NOT_SUPPORTED;
  162. }
  163. STDMETHOD(PutClassAsync) (
  164. IN IWbemClassObject * pObject,
  165. IN long lFlags,
  166. IN IWbemContext * pCtx,
  167. IN IWbemObjectSink * pSink
  168. )
  169. {
  170. return WBEM_E_NOT_SUPPORTED;
  171. }
  172. STDMETHOD(DeleteClass) (
  173. IN const BSTR Class,
  174. IN long lFlags,
  175. IN IWbemContext * pCtx,
  176. IN OUT IWbemCallResult ** ppCallResult
  177. )
  178. {
  179. return WBEM_E_NOT_SUPPORTED;
  180. }
  181. STDMETHOD(DeleteClassAsync)(
  182. IN const BSTR Class,
  183. IN long lFlags,
  184. IN IWbemContext * pCtx,
  185. IN IWbemObjectSink * pSink
  186. )
  187. {
  188. return WBEM_E_NOT_SUPPORTED;
  189. }
  190. STDMETHOD(CreateClassEnum) (
  191. IN const BSTR Superclass,
  192. IN long lFlags,
  193. IN IWbemContext * pCtx,
  194. OUT IEnumWbemClassObject ** ppEnum
  195. )
  196. {
  197. return WBEM_E_NOT_SUPPORTED;
  198. }
  199. STDMETHOD(CreateClassEnumAsync) (
  200. IN const BSTR Superclass,
  201. IN long lFlags,
  202. IN IWbemContext * pCtx,
  203. IN IWbemObjectSink * pResponseHandler
  204. )
  205. {
  206. return WBEM_E_NOT_SUPPORTED;
  207. }
  208. STDMETHOD(PutInstance)(
  209. IN IWbemClassObject * pInst,
  210. IN long lFlags,
  211. IN IWbemContext * pCtx,
  212. OUT IWbemCallResult ** ppCallResult
  213. )
  214. {
  215. return WBEM_E_NOT_SUPPORTED;
  216. }
  217. STDMETHOD(PutInstanceAsync) (
  218. IN IWbemClassObject * pInst,
  219. IN long lFlags,
  220. IN IWbemContext * pCtx,
  221. IN IWbemObjectSink * pSink
  222. )
  223. {
  224. return WBEM_E_NOT_SUPPORTED;
  225. }
  226. STDMETHOD(DeleteInstanceAsync) (
  227. IN const BSTR ObjectPath,
  228. IN long lFlags,
  229. IN IWbemContext * pCtx,
  230. IN IWbemObjectSink * pSink
  231. )
  232. {
  233. return WBEM_E_NOT_SUPPORTED;
  234. }
  235. STDMETHOD(DeleteInstance) (
  236. IN const BSTR ObjectPath,
  237. IN long lFlags,
  238. IN IWbemContext * pCtx,
  239. OUT IWbemCallResult ** ppCallResult
  240. )
  241. {
  242. return WBEM_E_NOT_SUPPORTED;
  243. }
  244. STDMETHOD(CreateInstanceEnum)(
  245. IN const BSTR Class,
  246. IN long lFlags,
  247. IN IWbemContext * pCtx,
  248. OUT IEnumWbemClassObject ** ppEnum
  249. )
  250. {
  251. return WBEM_E_NOT_SUPPORTED;
  252. }
  253. STDMETHOD(CreateInstanceEnumAsync) (
  254. IN const BSTR Class,
  255. IN long lFlags,
  256. IN IWbemContext * pCtx,
  257. IN IWbemObjectSink * pSink
  258. )
  259. {
  260. return WBEM_E_NOT_SUPPORTED;
  261. }
  262. STDMETHOD(ExecQuery) (
  263. IN const BSTR QueryLanguage,
  264. IN const BSTR Query,
  265. IN long lFlags,
  266. IN IWbemContext * pCtx,
  267. OUT IEnumWbemClassObject ** ppEnum
  268. )
  269. {
  270. return WBEM_E_NOT_SUPPORTED;
  271. }
  272. STDMETHOD(ExecQueryAsync) (
  273. IN const BSTR QueryLanguage,
  274. IN const BSTR Query,
  275. IN long lFlags,
  276. IN IWbemContext * pCtx,
  277. IN IWbemObjectSink * pSink
  278. )
  279. {
  280. return WBEM_E_NOT_SUPPORTED;
  281. }
  282. STDMETHOD(ExecNotificationQuery) (
  283. IN const BSTR QueryLanguage,
  284. IN const BSTR Query,
  285. IN long lFlags,
  286. IN IWbemContext * pCtx,
  287. OUT IEnumWbemClassObject ** ppEnum
  288. )
  289. {
  290. return WBEM_E_NOT_SUPPORTED;
  291. }
  292. STDMETHOD(ExecNotificationQueryAsync) (
  293. IN const BSTR QueryLanguage,
  294. IN const BSTR Query,
  295. IN long lFlags,
  296. IN IWbemContext * pCtx,
  297. IN IWbemObjectSink * pSink
  298. )
  299. {
  300. return WBEM_E_NOT_SUPPORTED;
  301. }
  302. STDMETHOD(ExecMethod) (
  303. IN const BSTR,
  304. IN const BSTR,
  305. IN long,
  306. IN IWbemContext*,
  307. IN IWbemClassObject*,
  308. IN IWbemClassObject**,
  309. IN IWbemCallResult**
  310. )
  311. {
  312. return WBEM_E_NOT_SUPPORTED;
  313. }
  314. STDMETHOD(ExecMethodAsync) (
  315. IN const BSTR,
  316. IN const BSTR,
  317. IN long,
  318. IN IWbemContext*,
  319. IN IWbemClassObject*,
  320. IN IWbemObjectSink*
  321. )
  322. {
  323. return WBEM_E_NOT_SUPPORTED;
  324. }
  325. };
  326. /*
  327. Class CNetSecProv
  328. Naming:
  329. CNetSecProv stands for Network Security Provider.
  330. Base class:
  331. (1) CDefWbemService: for threading model and IUnknown, and those functions that we
  332. are not interested at all.
  333. (2) CComCoClass: for class factory support. This is necessary to be
  334. a provider because we need to be an externally createable class.
  335. (3) IWbemProviderInit: Allow initialization. Necessary as a provider.
  336. (4) IWbemServices: indirectly from CDefWbemService.
  337. Purpose of class:
  338. This is the provider that WMI sees.
  339. Design:
  340. (1) Implements those functions of IWbemServices that we are interested in,
  341. plus two static helpers functions for key chain creation. Extremely simple design.
  342. Use:
  343. (1) You will never create an instance directly yourself. It's created by WMI.
  344. (2) Call the static functions as you need them.
  345. Notes:
  346. */
  347. class ATL_NO_VTABLE CNetSecProv :
  348. public CDefWbemService,
  349. public CComCoClass<CNetSecProv, &CLSID_NetSecProv>,
  350. public IWbemProviderInit
  351. {
  352. public:
  353. CNetSecProv()
  354. {
  355. }
  356. ~CNetSecProv()
  357. {
  358. }
  359. DECLARE_REGISTRY_RESOURCEID(IDR_NETSECPROV)
  360. DECLARE_NOT_AGGREGATABLE(CNetSecProv)
  361. DECLARE_PROTECT_FINAL_CONSTRUCT()
  362. BEGIN_COM_MAP(CNetSecProv)
  363. COM_INTERFACE_ENTRY(IWbemProviderInit)
  364. COM_INTERFACE_ENTRY_CHAIN(CDefWbemService)
  365. END_COM_MAP()
  366. public:
  367. STDMETHOD(Initialize) (
  368. IN LPWSTR pszUser,
  369. IN LONG lFlags,
  370. IN LPWSTR pszNamespace,
  371. IN LPWSTR pszLocale,
  372. IN IWbemServices * pNamespace,
  373. IN IWbemContext * pCtx,
  374. IN IWbemProviderInitSink * pInitSink
  375. );
  376. //IWbemServices
  377. STDMETHOD(GetObjectAsync) (
  378. IN const BSTR ObjectPath,
  379. IN long lFlags,
  380. IN IWbemContext * pCtx,
  381. IN IWbemObjectSink * pSink
  382. );
  383. STDMETHOD(PutInstanceAsync) (
  384. IN IWbemClassObject * pInst,
  385. IN long lFlags,
  386. IN IWbemContext * pCtx,
  387. IN IWbemObjectSink * pSink
  388. );
  389. STDMETHOD(DeleteInstanceAsync) (
  390. IN const BSTR ObjectPath,
  391. IN long lFlags,
  392. IN IWbemContext * pCtx,
  393. IN IWbemObjectSink * pSink
  394. );
  395. STDMETHOD(CreateInstanceEnumAsync) (
  396. IN const BSTR Class,
  397. IN long lFlags,
  398. IN IWbemContext * pCtx,
  399. IN IWbemObjectSink * pSink
  400. );
  401. STDMETHOD(ExecQueryAsync) (
  402. IN const BSTR QueryLanguage,
  403. IN const BSTR Query,
  404. IN long lFlags,
  405. IN IWbemContext * pCtx,
  406. IN IWbemObjectSink * pSink
  407. );
  408. STDMETHOD(ExecMethodAsync)(
  409. IN const BSTR bstrPath,
  410. IN const BSTR bstrMethod,
  411. IN long Flag,
  412. IN IWbemContext * pCtx,
  413. IN IWbemClassObject * pObj,
  414. IN IWbemObjectSink * pSink
  415. );
  416. static HRESULT GetKeyChainByPath (
  417. IN LPCWSTR pszPath,
  418. OUT IIPSecKeyChain ** ppKeyChain
  419. );
  420. static HRESULT GetKeyChainFromQuery (
  421. IN LPCWSTR pszQuery,
  422. IN LPCWSTR pszWhereProperty,
  423. OUT IIPSecKeyChain ** ppKeyChain
  424. );
  425. private:
  426. CComPtr<IWbemServices> m_srpNamespace;
  427. };