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.

352 lines
10 KiB

  1. // ipsecparser.h: path and query parser provided by IPSec provider
  2. // Copyright (c)1997-2001 Microsoft Corporation
  3. //
  4. //////////////////////////////////////////////////////////////////////
  5. #if _MSC_VER >= 1000
  6. #pragma once
  7. #endif // _MSC_VER >= 1000
  8. #include "globals.h"
  9. //
  10. // trivial wrapper just to ease the memory management and initialization
  11. //
  12. class CPropValuePair
  13. {
  14. public:
  15. CPropValuePair::CPropValuePair() : pszKey(NULL)
  16. {
  17. ::VariantInit(&varVal);
  18. }
  19. CPropValuePair::~CPropValuePair()
  20. {
  21. delete [] pszKey;
  22. ::VariantClear(&varVal);
  23. }
  24. LPWSTR pszKey;
  25. VARIANT varVal;
  26. };
  27. /*
  28. Class description
  29. Naming:
  30. CIPSecPathParser stands for SCE Path Parser.
  31. Base class:
  32. CComObjectRootEx for threading model and IUnknown.
  33. CComCoClass for class factory support.
  34. IIPSecPathParser and IIPSecKeyChain for custom interfaces.
  35. Purpose of class:
  36. (1) We wish to simplify path parsing. This is our effort of creation IPSec path parser
  37. that can be externally CoCreateInstance'd.
  38. (2) To support a more friendly and uniform interface, both IPSec path parser and IPSec query
  39. let client use the service via IIPSecKeyChain.
  40. Design:
  41. (1) See IIPSecPathParser and IIPSecKeyChain. Almost everything is captured by these two interfaces.
  42. (2) This is not a directly instantiatable class. See Use section for creation steps.
  43. (3) Since paths only contains class name and key properties, we opt to use a less fancier data
  44. structure - vector to store the properties' (name,value) pair. The nature of key properties
  45. being normally limited in number should offer you comfort in using this data structure.
  46. (4) Class name and namespace are cached in separate string members.
  47. Use:
  48. (1) For external users:
  49. (a) CoCreateInstance of our class (CLSID_IPSecPathParser) and request for IID_IIPSecPathParser.
  50. (b) Call ParsePath to parse the path string.
  51. (c) QI IIPSecKeyChain and use the key chain to access the results.
  52. (2) For internal users:
  53. (a) CComObject<CIPSecPathParser>::CreateInstance(&pPathParser);
  54. (b) QI for IIPSecPathParser.
  55. (c) ParsePath
  56. (d) QI IIPSecKeyChain and use the key chain to access the results.
  57. See CRequestObject's use for sample.
  58. Notes:
  59. (1) This class is not intended to be further derived. It is a final class. It's
  60. destructor is thus not virtual!
  61. (2) Refer to MSDN and ATL COM programming for the use of ATL.
  62. (3) The caller can't cache the interface pointer (IIPSecKeyChain) and do another parsing (which
  63. is allowed) and expect the previous IIPSecKeyChain interface to work for the previous parsing.
  64. */
  65. class ATL_NO_VTABLE CIPSecPathParser
  66. : public CComObjectRootEx<CComMultiThreadModel>,
  67. public CComCoClass<CIPSecPathParser, &CLSID_IPSecPathParser>,
  68. public IIPSecPathParser,
  69. public IIPSecKeyChain
  70. {
  71. public:
  72. BEGIN_COM_MAP(CIPSecPathParser)
  73. COM_INTERFACE_ENTRY(IIPSecPathParser)
  74. COM_INTERFACE_ENTRY(IIPSecKeyChain)
  75. END_COM_MAP()
  76. DECLARE_NOT_AGGREGATABLE( CIPSecPathParser )
  77. DECLARE_REGISTRY_RESOURCEID(IDR_NETSECPROV)
  78. protected:
  79. CIPSecPathParser();
  80. ~CIPSecPathParser();
  81. public:
  82. //
  83. // IIPSecPathParser
  84. //
  85. STDMETHOD(ParsePath) (
  86. IN LPCWSTR strObjectPath
  87. );
  88. //
  89. // IIPSecKeyChain
  90. //
  91. STDMETHOD(GetKeyPropertyCount) (
  92. OUT DWORD *pCount
  93. );
  94. STDMETHOD(GetNamespace) (
  95. OUT BSTR *pbstrNamespace
  96. );
  97. STDMETHOD(GetClassName) (
  98. OUT BSTR *pbstrClassName
  99. );
  100. STDMETHOD(GetKeyPropertyValue) (
  101. IN LPCWSTR pszKeyPropName,
  102. OUT VARIANT *pvarValue
  103. );
  104. STDMETHOD(GetKeyPropertyValueByIndex) (
  105. IN DWORD dwIndex,
  106. OUT BSTR* pbstrKeyPropName,
  107. OUT VARIANT *pvarValue
  108. );
  109. private:
  110. void Cleanup();
  111. std::vector<CPropValuePair*> m_vecKeyValueList;
  112. LPWSTR m_pszClassName;
  113. LPWSTR m_pszNamespace;
  114. };
  115. /*
  116. Class description
  117. Naming:
  118. CIPSecQueryParser stands for IPSec Query Parser.
  119. Base class:
  120. (1) CComObjectRootEx for threading model and IUnknown.
  121. (2) CComCoClass for class factory support.
  122. (3) IIPSecQueryParser and IIPSecKeyChain for custom interfaces.
  123. Purpose of class:
  124. (1) We wish to simplify query parsing. This is our effort of creation IPSec query parser
  125. that can be externally CoCreateInstance'd.
  126. (2) To support a more friendly and uniform interface, both IPSec path parser and IPSec query
  127. let client use the service via IIPSecKeyChain.
  128. Design:
  129. (1) See IIPSecQueryParser and IIPSecKeyChain. Almost everything is captured by these two interfaces.
  130. (2) This is not a directly instantiatable class. See Use section for creation steps.
  131. (3) Parsing a query is a very complicated matter. WMI support of complicated queries are limited
  132. too. We are very pragmatic about it: we only cares about the class names (actually, WMI limits
  133. its queries to unary - one class name only) and one important property - let's call it the querying
  134. property (m_bstrQueryingPropName). For IPSec use, that querying property is almost always
  135. the store path.
  136. (4) Class names are cached in string list member m_vecClassList.
  137. (5) The query property values (in string) will be cached in a string list member - m_vecQueryingPropValueList.
  138. Use:
  139. (1) For external users:
  140. (a) CoCreateInstance of our class (CLSID_IPSecQueryParser) and request for IID_IIPSecQueryParser.
  141. (b) Call ParseQuery to parse the query.
  142. (c) QI IIPSecKeyChain and use the key chain to access the results.
  143. (2) For internal users:
  144. (a) CComObject<CIPSecPathParser>::CreateInstance(&pPathParser);
  145. (b) QI for IIPSecQueryParser.
  146. (c) Call ParseQuery to parse the query.
  147. (d) QI IIPSecKeyChain and use the key chain to access the results.
  148. See CRequestObject's use for sample.
  149. Notes:
  150. (1) This class is not intended to be further derived. It is a final class. It's
  151. destructor is thus not virtual!
  152. (2) Refer to MSDN and ATL COM programming for the use of ATL.
  153. */
  154. class ATL_NO_VTABLE CIPSecQueryParser
  155. : public CComObjectRootEx<CComMultiThreadModel>,
  156. public CComCoClass<CIPSecQueryParser, &CLSID_IPSecQueryParser>,
  157. public IIPSecQueryParser,
  158. public IIPSecKeyChain
  159. {
  160. public:
  161. BEGIN_COM_MAP(CIPSecQueryParser)
  162. COM_INTERFACE_ENTRY(IIPSecQueryParser)
  163. COM_INTERFACE_ENTRY(IIPSecKeyChain)
  164. END_COM_MAP()
  165. DECLARE_NOT_AGGREGATABLE( CIPSecQueryParser )
  166. DECLARE_REGISTRY_RESOURCEID(IDR_NETSECPROV)
  167. protected:
  168. CIPSecQueryParser();
  169. ~CIPSecQueryParser();
  170. public:
  171. //
  172. // IIPSecQueryParser
  173. //
  174. STDMETHOD(ParseQuery) (
  175. IN LPCWSTR strQuery,
  176. IN LPCWSTR strQueryPropName
  177. );
  178. STDMETHOD(GetClassCount) (
  179. OUT DWORD* pdwCount
  180. )
  181. {
  182. if (pdwCount == NULL)
  183. {
  184. return E_INVALIDARG;
  185. }
  186. *pdwCount = m_vecClassList.size();
  187. return S_OK;
  188. }
  189. STDMETHOD(GetClassName) (
  190. IN int iIndex,
  191. OUT BSTR * pbstrClassName
  192. );
  193. STDMETHOD(GetQueryingPropertyValueCount) (
  194. OUT DWORD* pdwCount
  195. )
  196. {
  197. if (pdwCount == NULL)
  198. {
  199. return E_INVALIDARG;
  200. }
  201. *pdwCount = m_vecQueryingPropValueList.size();
  202. return S_OK;
  203. }
  204. STDMETHOD(GetQueryingPropertyValue) (
  205. IN int iIndex,
  206. OUT BSTR * pbstrQPValue
  207. );
  208. //
  209. // IIPSecKeyChain
  210. //
  211. STDMETHOD(GetKeyPropertyCount) (
  212. OUT DWORD *pCount
  213. )
  214. {
  215. if (pCount == NULL)
  216. {
  217. return E_INVALIDARG;
  218. }
  219. *pCount = m_vecQueryingPropValueList.size() > 0 ? 1 : 0;
  220. return S_OK;
  221. }
  222. STDMETHOD(GetNamespace) (
  223. OUT BSTR *pbstrNamespace
  224. )
  225. {
  226. *pbstrNamespace = NULL;
  227. return WBEM_E_NOT_SUPPORTED;
  228. }
  229. STDMETHOD(GetClassName) (
  230. OUT BSTR *pbstrClassName
  231. )
  232. {
  233. //
  234. // since we only support single class query, this must be it
  235. //
  236. return GetClassName(0, pbstrClassName);
  237. }
  238. STDMETHOD(GetKeyPropertyValue) (
  239. IN LPCWSTR pszKeyPropName,
  240. OUT VARIANT * pvarValue
  241. );
  242. STDMETHOD(GetKeyPropertyValueByIndex) (
  243. IN DWORD dwIndex,
  244. OUT BSTR * pbstrKeyPropName,
  245. OUT VARIANT * pvarValue
  246. )
  247. {
  248. if (pbstrKeyPropName == NULL || pvarValue == NULL)
  249. {
  250. return E_INVALIDARG;
  251. }
  252. *pbstrKeyPropName = NULL;
  253. ::VariantInit(pvarValue);
  254. return WBEM_E_NOT_SUPPORTED;
  255. }
  256. private:
  257. void Cleanup();
  258. HRESULT ExtractClassNames (
  259. SWbemRpnEncodedQuery *pRpn
  260. );
  261. HRESULT ExtractQueryingProperties (
  262. SWbemRpnEncodedQuery *pRpn,
  263. LPCWSTR strQueryPropName
  264. );
  265. HRESULT GetQueryPropFromToken (
  266. SWbemRpnQueryToken *pRpnQueryToken,
  267. LPCWSTR strQueryPropName
  268. );
  269. std::vector<LPWSTR> m_vecClassList;
  270. std::vector<LPWSTR> m_vecQueryingPropValueList;
  271. CComBSTR m_bstrQueryingPropName;
  272. };