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.

328 lines
14 KiB

  1. /******************************************************************
  2. SNetScal.cpp -- WBEM provider class implementation
  3. MODULE:
  4. DhcpProv.dll
  5. DESCRIPTION:
  6. Contains: the definition of the DHCP_Subnet class,
  7. the static table of manageable objects.
  8. REVISION:
  9. 08/03/98 - created
  10. ******************************************************************/
  11. #include <stdafx.h>
  12. #include "props.h"
  13. #include "snetfn.h"
  14. #include "rngfn.h"
  15. #include "srvfn.h"
  16. #include "anetrng.h"
  17. // the name of the WBEM class
  18. #define PROVIDER_NAME_DHCP_ASSOC_SUBNETINCLRANGE "DHCP_SubnetIncludedRange"
  19. #define PROVIDER_NAME_DHCP_ASSOC_SUBNETEXCLRANGE "DHCP_SubnetExcludedRange"
  20. // Create here the two associations: Subnet<->IncludedRegion and Subnet<->ExcludedRegions
  21. CDHCP_AssociationSubnetToRange MyDHCP_Assoc_SubnetInclRange(PROVIDER_NAME_DHCP_ASSOC_SUBNETINCLRANGE, PROVIDER_NAMESPACE_DHCP, DhcpIpRanges);
  22. CDHCP_AssociationSubnetToRange MyDHCP_Assoc_SubnetExclRange(PROVIDER_NAME_DHCP_ASSOC_SUBNETEXCLRANGE, PROVIDER_NAMESPACE_DHCP, DhcpExcludedIpRanges);
  23. /*****************************************************************************
  24. *
  25. * FUNCTION : CDHCP_AssociationSubnetToRange::CDHCP_AssociationSubnetToRange
  26. *
  27. * DESCRIPTION : Constructor
  28. *
  29. * INPUTS : none
  30. *
  31. * RETURNS : nothing
  32. *
  33. * COMMENTS : Calls the Provider constructor.
  34. *
  35. *****************************************************************************/
  36. CDHCP_AssociationSubnetToRange::CDHCP_AssociationSubnetToRange (const CHString& strName, LPCSTR pszNameSpace, DWORD dwRangeType ) :
  37. Provider(strName, pszNameSpace)
  38. {
  39. m_dwRangeType = dwRangeType;
  40. }
  41. /*****************************************************************************
  42. *
  43. * FUNCTION : CDHCP_AssociationSubnetToRange::~CDHCP_AssociationSubnetToRange
  44. *
  45. * DESCRIPTION : Destructor
  46. *
  47. * INPUTS : none
  48. *
  49. * RETURNS : nothing
  50. *
  51. * COMMENTS :
  52. *
  53. *****************************************************************************/
  54. CDHCP_AssociationSubnetToRange::~CDHCP_AssociationSubnetToRange ()
  55. {
  56. }
  57. /*****************************************************************************
  58. *
  59. * FUNCTION : CDHCP_AssociationSubnetToRange::EnumerateInstances
  60. *
  61. * DESCRIPTION : Returns all the instances of this class.
  62. *
  63. * INPUTS : none
  64. *
  65. * RETURNS : WBEM_S_NO_ERROR if successful
  66. *
  67. * COMMENTS : Enumerates all this instances of this class. As there is only one
  68. * DHCP Server per system, there is only one instance for this class
  69. *
  70. *****************************************************************************/
  71. HRESULT CDHCP_AssociationSubnetToRange::EnumerateInstances ( MethodContext* pMethodContext, long lFlags )
  72. {
  73. CDHCP_Server_Parameters srvParams;
  74. LPDHCP_MIB_INFO pSrvMibInfo;
  75. HRESULT hRes = WBEM_S_NO_ERROR;
  76. if (!srvParams.GetMibInfo(pSrvMibInfo, TRUE))
  77. return WBEM_E_FAILED;
  78. // loop through all the subnets configured on the local server
  79. for (int i = 0; hRes == WBEM_S_NO_ERROR && i < pSrvMibInfo->Scopes; i++)
  80. {
  81. DWORD dwSubnet;
  82. DHCP_RESUME_HANDLE ResumeHandle;
  83. WCHAR wcsSubnetQuery[64]; // should be enough for holding 'xxx.yyy.zzz.uuu\0'
  84. dwSubnet = pSrvMibInfo->ScopeInfo[i].Subnet;
  85. CDHCP_Range_Parameters rngParams(dwSubnet);
  86. // build the str representation of the Subnet address
  87. swprintf(wcsSubnetQuery, L"DHCP_Subnet.Address=\"%u.%u.%u.%u\"",
  88. (dwSubnet & 0xff000000) >> 24,
  89. (dwSubnet & 0x00ff0000) >> 16,
  90. (dwSubnet & 0x0000ff00) >> 8,
  91. (dwSubnet & 0x000000ff));
  92. ResumeHandle = 0;
  93. do
  94. {
  95. DWORD errCode;
  96. // load the next buffer
  97. errCode = rngParams.NextSubnetRange(ResumeHandle, (DHCP_SUBNET_ELEMENT_TYPE)m_dwRangeType);
  98. // if ERROR_NO_MORE_ITEMS than no information was filled into m_pRangeInfoArray (which is null)
  99. if (errCode == ERROR_NO_MORE_ITEMS)
  100. break;
  101. // two alternatives here: ERROR_MORE_DATA (ResumeHandle != 0) and ERROR_SUCCESS (which case
  102. // the API is setting ResumeHandle to NULL (hope so :o). In both cases, just go on.
  103. if (errCode != ERROR_MORE_DATA && errCode != ERROR_SUCCESS)
  104. return WBEM_E_FAILED;
  105. // for the current buffer, loop through all the ranges
  106. for (int j = 0; hRes == WBEM_S_NO_ERROR && j < rngParams.m_pRangeInfoArray->NumElements; j++)
  107. {
  108. // this is finally the info of the current range
  109. LPDHCP_IP_RANGE pRange = (m_dwRangeType == DhcpIpRanges)?
  110. (LPDHCP_IP_RANGE)(rngParams.m_pRangeInfoArray->Elements[j].Element.IpRange) :
  111. (LPDHCP_IP_RANGE)(rngParams.m_pRangeInfoArray->Elements[j].Element.ExcludeIpRange);
  112. WCHAR wcsRegionQuery[128]; // should be enough for holding the whole query
  113. DWORD dwQueryIndex = 0;
  114. // we finally have everything we need for creating one more instance
  115. CInstance* pInstance = CreateNewInstance(pMethodContext);
  116. //------------------add 'Subnet' reference to the instance--------------------
  117. if (pInstance == NULL ||
  118. !pInstance->SetCHString(PROP_ANetRange_Subnet, wcsSubnetQuery))
  119. return WBEM_E_FAILED;
  120. //..................copy 'EndAddress' to the Range reference..................
  121. // build the str representation of the EndAddress
  122. dwQueryIndex += swprintf(wcsRegionQuery + dwQueryIndex, L"DHCP_Range.EndAddress=\"%u.%u.%u.%u\"",
  123. (pRange->EndAddress & 0xff000000) >> 24,
  124. (pRange->EndAddress & 0x00ff0000) >> 16,
  125. (pRange->EndAddress & 0x0000ff00) >> 8,
  126. (pRange->EndAddress & 0x000000ff));
  127. //..................copy 'RangeType' to the Range reference...................
  128. dwQueryIndex += swprintf(wcsRegionQuery + dwQueryIndex, L",RangeType=%u", m_dwRangeType);
  129. //..................copy 'StartAddress' to the Range reference................
  130. // build the str representation of the StartAddress
  131. dwQueryIndex += swprintf(wcsRegionQuery + dwQueryIndex ,L",StartAddress=\"%u.%u.%u.%u\"",
  132. (pRange->StartAddress & 0xff000000) >> 24,
  133. (pRange->StartAddress & 0x00ff0000) >> 16,
  134. (pRange->StartAddress & 0x0000ff00) >> 8,
  135. (pRange->StartAddress & 0x000000ff));
  136. //..................copy 'Subnet' to the Range reference......................
  137. // build the str representation of the StartAddress
  138. dwQueryIndex += swprintf(wcsRegionQuery + dwQueryIndex ,L",Subnet=\"%u.%u.%u.%u\"",
  139. (dwSubnet & 0xff000000) >> 24,
  140. (dwSubnet & 0x00ff0000) >> 16,
  141. (dwSubnet & 0x0000ff00) >> 8,
  142. (dwSubnet & 0x000000ff));
  143. //------------------add the 'Range' reference to the instance------------------
  144. if (!pInstance->SetCHString(PROP_ANetRange_Range, wcsRegionQuery))
  145. return WBEM_E_FAILED;
  146. //~~~~~~~~~~~~~~~~~ Commit the instance ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  147. hRes = Commit(pInstance);
  148. }
  149. } while (ResumeHandle != 0); // bail if ResumeHandle got back to 0 (the end was reached)
  150. }
  151. return WBEM_S_NO_ERROR;
  152. }
  153. /*****************************************************************************
  154. *
  155. * FUNCTION : CDHCP_AssociationSubnetToRange::GetObject
  156. *
  157. * DESCRIPTION : Find a single instance based on the key properties for the
  158. * class.
  159. *
  160. * INPUTS : A pointer to a CInstance object containing the key properties.
  161. *
  162. * RETURNS : WBEM_S_NO_ERROR if the instance can be found
  163. * WBEM_E_NOT_FOUND if the instance described by the key properties
  164. * could not be found
  165. * WBEM_E_FAILED if the instance could be found but another error
  166. * occurred.
  167. *
  168. * COMMENTS :
  169. *
  170. *****************************************************************************/
  171. HRESULT CDHCP_AssociationSubnetToRange::GetObject ( CInstance* pInstance, long lFlags )
  172. {
  173. return WBEM_S_NO_ERROR;
  174. }
  175. /*****************************************************************************
  176. *
  177. * FUNCTION : CDHCP_AssociationSubnetToRange::ExecQuery
  178. *
  179. * DESCRIPTION : You are passed a method context to use in the creation of
  180. * instances that satisfy the query, and a CFrameworkQuery
  181. * which describes the query. Create and populate all
  182. * instances which satisfy the query. CIMOM will post -
  183. * filter the query for you, you may return more instances
  184. * or more properties than are requested and CIMOM
  185. * will filter out any that do not apply.
  186. *
  187. *
  188. * INPUTS :
  189. *
  190. * RETURNS : WBEM_E_PROVIDER_NOT_CAPABLE if not supported for this class
  191. * WBEM_E_FAILED if the query failed
  192. * WBEM_S_NO_ERROR if query was successful
  193. *
  194. * COMMENTS : TO DO: Most providers will not need to implement this method. If you don't, cimom
  195. * will call your enumerate function to get all the instances and perform the
  196. * filtering for you. Unless you expect SIGNIFICANT savings from implementing
  197. * queries, you should remove this entire method.
  198. *
  199. *****************************************************************************/
  200. HRESULT CDHCP_AssociationSubnetToRange::ExecQuery (MethodContext *pMethodContext, CFrameworkQuery& Query, long lFlags)
  201. {
  202. return WBEM_E_PROVIDER_NOT_CAPABLE;
  203. }
  204. /*****************************************************************************
  205. *
  206. * FUNCTION : CDHCP_AssociationSubnetToRange::PutInstance
  207. *
  208. * DESCRIPTION : PutInstance should be used in provider classes that can write
  209. * instance information back to the hardware or software.
  210. * For example: Win32_Environment will allow a PutInstance of a new
  211. * environment variable, because environment variables are "software"
  212. * related. However, a class like Win32_MotherboardDevice will not
  213. * allow editing of the bus speed. Since by default PutInstance
  214. * returns WBEM_E_PROVIDER_NOT_CAPABLE, this function is placed here as a
  215. * skeleton, but can be removed if not used.
  216. *
  217. * INPUTS :
  218. *
  219. * RETURNS : WBEM_E_PROVIDER_NOT_CAPABLE if PutInstance is not available
  220. * WBEM_E_FAILED if there is an error delivering the instance
  221. * WBEM_E_INVALID_PARAMETER if any of the instance properties
  222. * are incorrect.
  223. * WBEM_S_NO_ERROR if instance is properly delivered
  224. *
  225. * COMMENTS : TO DO: If you don't intend to support writing to your provider, remove this method.
  226. *
  227. *****************************************************************************/
  228. HRESULT CDHCP_AssociationSubnetToRange::PutInstance ( const CInstance &Instance, long lFlags)
  229. {
  230. return WBEM_E_PROVIDER_NOT_CAPABLE;
  231. }
  232. /*****************************************************************************
  233. *
  234. * FUNCTION : CDHCP_AssociationSubnetToRange::DeleteInstance
  235. *
  236. * DESCRIPTION : DeleteInstance, like PutInstance, actually writes information
  237. * to the software or hardware. For most hardware devices,
  238. * DeleteInstance should not be implemented, but for software
  239. * configuration, DeleteInstance implementation is plausible.
  240. * Like PutInstance, DeleteInstance returns WBEM_E_PROVIDER_NOT_CAPABLE from
  241. * inside Provider::DeleteInstance (defined in Provider.h). So, if
  242. * you choose not to implement DeleteInstance, remove this function
  243. * definition and the declaration from DHCP_Server_Scalars.h
  244. *
  245. * INPUTS :
  246. *
  247. * RETURNS : WBEM_E_PROVIDER_NOT_CAPABLE if DeleteInstance is not available.
  248. * WBEM_E_FAILED if there is an error deleting the instance.
  249. * WBEM_E_INVALID_PARAMETER if any of the instance properties
  250. * are incorrect.
  251. * WBEM_S_NO_ERROR if instance is properly deleted.
  252. *
  253. * COMMENTS : TO DO: If you don't intend to support deleting instances, remove this method.
  254. *
  255. *****************************************************************************/
  256. HRESULT CDHCP_AssociationSubnetToRange::DeleteInstance ( const CInstance &Instance, long lFlags )
  257. {
  258. return WBEM_E_PROVIDER_NOT_CAPABLE;
  259. }
  260. /*****************************************************************************
  261. *
  262. * FUNCTION : CDHCP_AssociationSubnetToRange::ExecMethod
  263. *
  264. * DESCRIPTION : Override this function to provide support for methods.
  265. * A method is an entry point for the user of your provider
  266. * to request your class perform some function above and
  267. * beyond a change of state. (A change of state should be
  268. * handled by PutInstance() )
  269. *
  270. * INPUTS : A pointer to a CInstance containing the instance the method was executed against.
  271. * A string containing the method name
  272. * A pointer to the CInstance which contains the IN parameters.
  273. * A pointer to the CInstance to contain the OUT parameters.
  274. * A set of specialized method flags
  275. *
  276. * RETURNS : WBEM_E_PROVIDER_NOT_CAPABLE if not implemented for this class
  277. * WBEM_S_NO_ERROR if method executes successfully
  278. * WBEM_E_FAILED if error occurs executing method
  279. *
  280. * COMMENTS : TO DO: If you don't intend to support Methods, remove this method.
  281. *
  282. *****************************************************************************/
  283. HRESULT CDHCP_AssociationSubnetToRange::ExecMethod ( const CInstance& Instance,
  284. const BSTR bstrMethodName,
  285. CInstance *pInParams,
  286. CInstance *pOutParams,
  287. long lFlags)
  288. {
  289. return WBEM_E_PROVIDER_NOT_CAPABLE;
  290. }