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.

370 lines
6.4 KiB

  1. // ActiveSocket.cpp: implementation for the WMI class SCW_ActiveSocket
  2. //
  3. // Copyright (c)1997-2001 Microsoft Corporation
  4. //
  5. //////////////////////////////////////////////////////////////////////
  6. #include "precomp.h"
  7. #include "ActiveSocket.h"
  8. #include "NetSecProv.h"
  9. //#include "IPUtil.h"
  10. /*
  11. Routine Description:
  12. Name:
  13. CActiveSocket::QueryInstance
  14. Functionality:
  15. Given the query, it returns to WMI (using pSink) all the instances that satisfy the query.
  16. Actually, what we give back to WMI may contain extra instances. WMI will do the final filtering.
  17. Virtual:
  18. Yes (part of IIPSecObjectImpl)
  19. Arguments:
  20. None.
  21. Return Value:
  22. Success:
  23. Failure:
  24. Notes:
  25. */
  26. STDMETHODIMP
  27. CActiveSocket::QueryInstance (
  28. IN LPCWSTR pszQuery,
  29. IN IWbemContext * pCtx,
  30. IN IWbemObjectSink * pSink
  31. )
  32. {
  33. //
  34. // Make sure that WinSocket is initialized
  35. //
  36. //ULONG uResult = ::WSAStartup( 0x0101, &WsaData );
  37. //if ( Result == SOCKET_ERROR )
  38. //{
  39. //
  40. // $consider: we need to supply our custom error info
  41. //
  42. // return WBEM_E_FAILED;
  43. //}
  44. //
  45. // get the filter name from the query
  46. // this key chain is not good because it doesn't have any info as what to look for
  47. // in the where clause
  48. //
  49. m_srpKeyChain.Release();
  50. HRESULT hr = CNetSecProv::GetKeyChainFromQuery(pszQuery, g_pszProtocol, &m_srpKeyChain);
  51. if (FAILED(hr))
  52. {
  53. return hr;
  54. }
  55. CComVariant varProtocol;
  56. CComVariant varPort;
  57. //
  58. // we will tolerate those queries that have not filter name in the where clause,
  59. // so ignore the return result
  60. //
  61. hr = m_srpKeyChain->GetKeyPropertyValue(g_pszProtocol, &varProtocol);
  62. if (SUCCEEDED(hr))
  63. {
  64. hr = m_srpKeyChain->GetKeyPropertyValue(g_pszPort, &varPort);
  65. }
  66. //
  67. //
  68. //
  69. //
  70. // since we are querying, it's ok to return not found
  71. //
  72. if (WBEM_E_NOT_FOUND == hr)
  73. {
  74. hr = WBEM_S_NO_MORE_DATA;
  75. }
  76. else if (SUCCEEDED(hr))
  77. {
  78. hr = WBEM_NO_ERROR;
  79. }
  80. return hr;
  81. }
  82. /*
  83. Routine Description:
  84. Name:
  85. CActiveSocket::DeleteInstance
  86. Functionality:
  87. Not supported. SCW_ActiveSocket is a read only class.
  88. Virtual:
  89. Yes (part of IIPSecObjectImpl)
  90. Arguments:
  91. pCtx - COM interface pointer supplied by WMI that we need to
  92. pass around for various WMI API's.
  93. pSink - COM interface pointer supplied by WMI that we use to
  94. notify WMI with our result.
  95. Return Value:
  96. WBEM_E_NOT_SUPPORTED
  97. Notes:
  98. */
  99. STDMETHODIMP
  100. CActiveSocket::DeleteInstance (
  101. IN IWbemContext * pCtx,
  102. IN IWbemObjectSink * pSink
  103. )
  104. {
  105. return WBEM_E_NOT_SUPPORTED;
  106. }
  107. /*
  108. Routine Description:
  109. Name:
  110. CActiveSocket::PutInstance
  111. Functionality:
  112. Not supported. SCW_ActiveSocket is a read only class.
  113. Virtual:
  114. Yes (part of IIPSecObjectImpl)
  115. Arguments:
  116. pInst - The object.
  117. pCtx - COM interface pointer supplied by WMI that we need to
  118. pass around for various WMI API's.
  119. pSink - COM interface pointer supplied by WMI that we use to
  120. notify WMI with our result.
  121. Return Value:
  122. WBEM_E_NOT_SUPPORTED
  123. Notes:
  124. */
  125. STDMETHODIMP
  126. CActiveSocket::PutInstance (
  127. IN IWbemClassObject * pInst,
  128. IN IWbemContext * pCtx,
  129. IN IWbemObjectSink * pSink
  130. )
  131. {
  132. return WBEM_E_NOT_SUPPORTED;
  133. }
  134. /*
  135. Routine Description:
  136. Name:
  137. CActiveSocket::PutInstance
  138. Functionality:
  139. This is a single instance Get. The key chain must already have the key.
  140. Virtual:
  141. Yes (part of IIPSecObjectImpl)
  142. Arguments:
  143. pCtx - COM interface pointer supplied by WMI that we need to
  144. pass around for various WMI API's.
  145. pSink - COM interface pointer supplied by WMI that we use to
  146. notify WMI with our result.
  147. Return Value:
  148. Success:
  149. WBEM_NO_ERROR
  150. Failure:
  151. Various error codes.
  152. Notes:
  153. */
  154. STDMETHODIMP
  155. CActiveSocket::GetInstance (
  156. IWbemContext * pCtx, // [in]
  157. IWbemObjectSink * pSink // [in]
  158. )
  159. {
  160. //
  161. // Make sure that WinSocket is initialized
  162. //
  163. //ULONG uResult = ::WSAStartup( 0x0101, &WsaData );
  164. //if ( Result == SOCKET_ERROR )
  165. //{
  166. //
  167. // $consider: we need to supply our custom error info
  168. //
  169. // return WBEM_E_FAILED;
  170. //}
  171. CComVariant varProtocol;
  172. CComVariant varPort;
  173. //
  174. // we will tolerate those queries that have not filter name in the where clause,
  175. // so ignore the return result
  176. //
  177. HRESULT hr = m_srpKeyChain->GetKeyPropertyValue(g_pszProtocol, &varProtocol);
  178. if (hr == WBEM_S_FALSE)
  179. {
  180. hr = WBEM_E_NOT_FOUND;
  181. }
  182. if (SUCCEEDED(hr))
  183. {
  184. hr = m_srpKeyChain->GetKeyPropertyValue(g_pszPort, &varPort);
  185. }
  186. if (hr == WBEM_S_FALSE)
  187. {
  188. hr = WBEM_E_NOT_FOUND;
  189. }
  190. if (SUCCEEDED(hr))
  191. {
  192. CComPtr<IWbemClassObject> srpObj;
  193. hr = CreateWbemObjFromSocket((SCW_Protocol)(varProtocol.lVal), varPort.lVal, &srpObj);
  194. if (SUCCEEDED(hr))
  195. {
  196. hr = pSink->Indicate(1, &srpObj);
  197. }
  198. }
  199. //
  200. // since we try to find the single instance, it's an error not to find it.
  201. //
  202. return SUCCEEDED(hr) ? WBEM_NO_ERROR : hr;
  203. }
  204. /*
  205. Routine Description:
  206. Name:
  207. CActiveSocket::CreateWbemObjFromSocket
  208. Functionality:
  209. Private helper.
  210. Given socket information, we will create an SCW_ActiveSocket instance representing the socket.
  211. Virtual:
  212. No.
  213. Arguments:
  214. Proto - the protocol (one of the two key properties)
  215. Port - the port number (the other key property)
  216. ppObj - Receives the object interface pointer.
  217. Return Value:
  218. Success:
  219. WBEM_NO_ERROR
  220. Failure:
  221. Various error codes.
  222. Notes:
  223. */
  224. HRESULT
  225. CActiveSocket::CreateWbemObjFromSocket (
  226. IN SCW_Protocol Proto,
  227. IN DWORD Port,
  228. OUT IWbemClassObject ** ppObj
  229. )
  230. {
  231. if (ppObj == NULL)
  232. {
  233. return WBEM_E_INVALID_PARAMETER;
  234. }
  235. *ppObj = NULL;
  236. return WBEM_E_NOT_SUPPORTED;
  237. }