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.

405 lines
9.0 KiB

  1. // IPSecBase.cpp: implementation of the base class for various Network
  2. // security WMI provider for IPSec
  3. //
  4. // Copyright (c)1997-2001 Microsoft Corporation
  5. //
  6. //////////////////////////////////////////////////////////////////////
  7. #include "precomp.h"
  8. #include "NetSecProv.h"
  9. #include "IPSecBase.h"
  10. #include "NspTCP.h"
  11. #include "Config.h"
  12. #include "Filter.h"
  13. #include "FilterTr.h"
  14. #include "FilterTun.h"
  15. #include "FilterMM.h"
  16. #include "PolicyQM.h"
  17. #include "PolicyMM.h"
  18. #include "AuthMM.h"
  19. #include "ExceptionPort.h"
  20. #include "ActiveSocket.h"
  21. const DWORD IP_ADDR_LENGTH = 16;
  22. const DWORD GUID_STRING_LENGTH = 39;
  23. //---------------------------------------------------------------------------
  24. // CIPSecBase is an abstract class. But it does implement some common
  25. // functionality for all our classes for WMI classes we provide
  26. //---------------------------------------------------------------------------
  27. /*
  28. Routine Description:
  29. Name:
  30. CIPSecBase::InitMembers
  31. Functionality:
  32. Initializing the members. Just cache some interface pointers.
  33. Virtual:
  34. No.
  35. Arguments:
  36. pCtx - COM interface pointer given by WMI. We need to pass this around for various WMI API's.
  37. pNamespace - COM interface pointer representing our namespace.
  38. pKeyChain - COM interface pointer representing the key chain created by ourselves.
  39. pszWmiClassName - The name of the WMI class this class is created to represent.
  40. Return Value:
  41. WBEM_NO_ERROR
  42. Notes:
  43. This is really an internal function. We don't bother to check validity of the parameters.
  44. */
  45. HRESULT
  46. CIPSecBase::InitMembers (
  47. IN IWbemContext * pCtx,
  48. IN IWbemServices * pNamespace,
  49. IN IIPSecKeyChain * pKeyChain,
  50. IN LPCWSTR pszWmiClassName
  51. )
  52. {
  53. if (pCtx != NULL)
  54. {
  55. m_srpCtx = pCtx;
  56. }
  57. m_srpNamespace = pNamespace;
  58. m_srpKeyChain.Release();
  59. m_srpKeyChain = pKeyChain;
  60. //
  61. // This Empty call is not really necessary unless the caller has mistakenly called it more than once
  62. //
  63. m_bstrWMIClassName.Empty();
  64. m_bstrWMIClassName = pszWmiClassName;
  65. return WBEM_NO_ERROR;
  66. }
  67. /*
  68. Routine Description:
  69. Name:
  70. CIPSecBase::CreateObject
  71. Functionality:
  72. Will create various C++ classes and return the IIPSecObjectImpl interface to the caller.
  73. IIPSecObjectImpl is our common interface for all C++ classes representing WMI classes.
  74. Virtual:
  75. No.
  76. Arguments:
  77. pNamespace - COM interface pointer representing our namespace.
  78. pCtx - COM interface pointer given by WMI. We need to pass this around for various WMI API's.
  79. pKeyChain - COM interface pointer representing the key chain created by ourselves.
  80. ppObjImp - COM interface pointer representing our object.
  81. Return Value:
  82. Success:
  83. WBEM_NO_ERROR
  84. Failure:
  85. Various error codes.
  86. Notes:
  87. */
  88. HRESULT
  89. CIPSecBase::CreateObject (
  90. IN IWbemServices * pNamespace,
  91. IN IIPSecKeyChain * pKeyChain,
  92. IN IWbemContext * pCtx,
  93. OUT IIPSecObjectImpl ** ppObjImp
  94. )
  95. {
  96. //
  97. // We can't take a blank class name. Since the caller is asking
  98. // for a class, the out parameter can't be NULL either.
  99. //
  100. if (ppObjImp == NULL || pKeyChain == NULL)
  101. {
  102. return WBEM_E_INVALID_PARAMETER;
  103. }
  104. CComBSTR bstrClsName;
  105. HRESULT hr = pKeyChain->GetClassName(&bstrClsName);
  106. if (FAILED(hr))
  107. {
  108. return hr;
  109. }
  110. *ppObjImp = NULL;
  111. hr = WBEM_E_NOT_SUPPORTED;
  112. CIPSecBase* pObj = NULL;
  113. //
  114. // based on the class name, we will call the same static (template) function
  115. // CreateIPSecObject for all the classes that implement our WMI classes.
  116. // This CreateIPSecObject function will create the appropriate C++ class
  117. // and return back its IIPSecObjectImpl interface.
  118. // The first parameter is simply a template parameter, not used otherwise.
  119. //
  120. if (_wcsicmp(bstrClsName, pszNspTcp) == 0)
  121. {
  122. CNspTCP * pNotUsed = NULL;
  123. hr = CreateIPSecObject(pNotUsed, pNamespace, pKeyChain, bstrClsName, pCtx, ppObjImp);
  124. }
  125. else if (_wcsicmp(bstrClsName, pszNspIPConfigure) == 0)
  126. {
  127. CIPSecConfig * pNotUsed = NULL;
  128. hr = CreateIPSecObject(pNotUsed, pNamespace, pKeyChain, bstrClsName, pCtx, ppObjImp);
  129. }
  130. else if (_wcsicmp(bstrClsName, pszNspTransportFilter) == 0)
  131. {
  132. CTransportFilter * pNotUsed = NULL;
  133. hr = CreateIPSecObject(pNotUsed, pNamespace, pKeyChain, bstrClsName, pCtx, ppObjImp);
  134. }
  135. else if (_wcsicmp(bstrClsName, pszNspTunnelFilter) == 0)
  136. {
  137. CTunnelFilter * pNotUsed = NULL;
  138. hr = CreateIPSecObject(pNotUsed, pNamespace, pKeyChain, bstrClsName, pCtx, ppObjImp);
  139. }
  140. else if (_wcsicmp(bstrClsName, pszNspMMFilter) == 0)
  141. {
  142. CMMFilter * pNotUsed = NULL;
  143. hr = CreateIPSecObject(pNotUsed, pNamespace, pKeyChain, bstrClsName, pCtx, ppObjImp);
  144. }
  145. else if (_wcsicmp(bstrClsName, pszNspQMPolicy) == 0)
  146. {
  147. CQMPolicy * pNotUsed = NULL;
  148. hr = CreateIPSecObject(pNotUsed, pNamespace, pKeyChain, bstrClsName, pCtx, ppObjImp);
  149. }
  150. else if (_wcsicmp(bstrClsName, pszNspMMPolicy) == 0)
  151. {
  152. CMMPolicy * pNotUsed = NULL;
  153. hr = CreateIPSecObject(pNotUsed, pNamespace, pKeyChain, bstrClsName, pCtx, ppObjImp);
  154. }
  155. else if (_wcsicmp(bstrClsName, pszNspMMAuth) == 0)
  156. {
  157. CAuthMM * pNotUsed = NULL;
  158. hr = CreateIPSecObject(pNotUsed, pNamespace, pKeyChain, bstrClsName, pCtx, ppObjImp);
  159. }
  160. else if (_wcsicmp(bstrClsName, pszNspExceptionPorts) == 0)
  161. {
  162. CExceptionPort * pNotUsed = NULL;
  163. hr = CreateIPSecObject(pNotUsed, pNamespace, pKeyChain, bstrClsName, pCtx, ppObjImp);
  164. }
  165. else if (_wcsicmp(bstrClsName, pszScwActiveSocket) == 0)
  166. {
  167. CActiveSocket * pNotUsed = NULL;
  168. hr = CreateIPSecObject(pNotUsed, pNamespace, pKeyChain, bstrClsName, pCtx, ppObjImp);
  169. }
  170. //else if (_wcsicmp(bstrClsName, pszNspRollbackFilter) == 0)
  171. //{
  172. //}
  173. //else if (_wcsicmp(bstrClsName, pszNspRollbackPolicy) == 0)
  174. //{
  175. //}
  176. if (SUCCEEDED(hr))
  177. {
  178. hr = WBEM_NO_ERROR;
  179. }
  180. return hr;
  181. }
  182. /*
  183. Routine Description:
  184. Name:
  185. CIPSecBase::SpawnObjectInstance
  186. Functionality:
  187. Will create a WMI class object (representing this class) that can be used to fill in properties.
  188. Virtual:
  189. No.
  190. Arguments:
  191. ppObj - Out parameter that receives the successfully spawned object.
  192. Return Value:
  193. Success:
  194. WBEM_NO_ERROR
  195. Failure:
  196. Various error codes.
  197. Notes:
  198. */
  199. HRESULT
  200. CIPSecBase::SpawnObjectInstance (
  201. OUT IWbemClassObject ** ppObj
  202. )
  203. {
  204. if (ppObj == NULL)
  205. {
  206. return WBEM_E_INVALID_PARAMETER;
  207. }
  208. *ppObj = NULL;
  209. HRESULT hr = WBEM_NO_ERROR;
  210. //
  211. // m_srpClassForSpawning is class definition, which can be used to spawn such instances
  212. // that can be used to fill in properties.
  213. //
  214. if (m_srpClassDefinition == NULL)
  215. {
  216. //
  217. // GetObject needs a bstr!
  218. //
  219. hr = m_srpNamespace->GetObject(m_bstrWMIClassName, 0, m_srpCtx, &m_srpClassDefinition, NULL);
  220. }
  221. if (SUCCEEDED(hr))
  222. {
  223. hr = m_srpClassDefinition->SpawnInstance(0, ppObj);
  224. }
  225. //
  226. // We trust SpawnInstance's return value. If it is successful, it must give us a valid object pointer.
  227. //
  228. if (SUCCEEDED(hr))
  229. {
  230. hr = WBEM_NO_ERROR;
  231. }
  232. return hr;
  233. }
  234. /*
  235. Routine Description:
  236. Name:
  237. CIPSecBase::SpawnRollbackInstance
  238. Functionality:
  239. Will create a WMI class object that can be used to fill in properties. This class object
  240. represents a rollback object of the given name. This is just a helper.
  241. Virtual:
  242. No.
  243. Arguments:
  244. pszClassName - The rollback instance's class name. It is not true that the rollback class's name
  245. and the class's name are in a 1 - 1 correspondence.
  246. ppObj - Out parameter that receives the successfully spawned object.
  247. Return Value:
  248. Success:
  249. WBEM_NO_ERROR
  250. Failure:
  251. Various error codes.
  252. Notes:
  253. */
  254. HRESULT
  255. CIPSecBase::SpawnRollbackInstance (
  256. IN LPCWSTR pszClassName,
  257. OUT IWbemClassObject ** ppObj
  258. )
  259. {
  260. if (ppObj == NULL)
  261. {
  262. return WBEM_E_INVALID_PARAMETER;
  263. }
  264. *ppObj = NULL;
  265. HRESULT hr = WBEM_NO_ERROR;
  266. CComPtr<IWbemClassObject> srpSpawnObj;
  267. CComBSTR bstrClsName(pszClassName);
  268. //
  269. // get the definition of the requested class, this definition object
  270. // will be able to spawn an instance.
  271. //
  272. hr = m_srpNamespace->GetObject(bstrClsName, 0, m_srpCtx, &srpSpawnObj, NULL);
  273. if (SUCCEEDED(hr))
  274. {
  275. hr = srpSpawnObj->SpawnInstance(0, ppObj);
  276. }
  277. return hr;
  278. }