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.

368 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_SuperScope class,
  7. the static table of manageable objects.
  8. REVISION:
  9. 08/03/98 - created
  10. ******************************************************************/
  11. #include <stdafx.h>
  12. #include "SScoFn.h" // needed for the declarations of all the functions.
  13. #include "SScoScal.h" // own header
  14. #include "AScoScal.h" // own header
  15. // properties names
  16. #define PROP_SScopeSubnets_SuperScope L"SuperScope"
  17. #define PROP_SScopeSubnets_Subnet L"Subnet"
  18. // the name of the WBEM class
  19. #define PROVIDER_NAME_DHCP_SUPERSCOPESUBNETS "DHCP_SuperScopeSubnets"
  20. // main class instantiation.
  21. CDHCP_SuperScopeToSubnet MyDHCP_SuperScopeSubnet_Scalars (PROVIDER_NAME_DHCP_SUPERSCOPESUBNETS, PROVIDER_NAMESPACE_DHCP) ;
  22. /*****************************************************************************
  23. *
  24. * FUNCTION : CDHCP_SuperScopeToSubnet::CDHCP_SuperScopeToSubnet
  25. *
  26. * DESCRIPTION : Constructor
  27. *
  28. * INPUTS : none
  29. *
  30. * RETURNS : nothing
  31. *
  32. * COMMENTS : Calls the Provider constructor.
  33. *
  34. *****************************************************************************/
  35. CDHCP_SuperScopeToSubnet::CDHCP_SuperScopeToSubnet (const CHString& strName, LPCSTR pszNameSpace ) :
  36. Provider(strName, pszNameSpace)
  37. {
  38. }
  39. /*****************************************************************************
  40. *
  41. * FUNCTION : CDHCP_SuperScopeToSubnet::~CDHCP_SuperScopeToSubnet
  42. *
  43. * DESCRIPTION : Destructor
  44. *
  45. * INPUTS : none
  46. *
  47. * RETURNS : nothing
  48. *
  49. * COMMENTS :
  50. *
  51. *****************************************************************************/
  52. CDHCP_SuperScopeToSubnet::~CDHCP_SuperScopeToSubnet ()
  53. {
  54. }
  55. /*****************************************************************************
  56. *
  57. * FUNCTION : CDHCP_SuperScopeToSubnet::EnumerateInstances
  58. *
  59. * DESCRIPTION : Returns all the instances of this class.
  60. *
  61. * INPUTS : none
  62. *
  63. * RETURNS : WBEM_S_NO_ERROR if successful
  64. *
  65. * COMMENTS : Enumerates all this instances of this class. As there is only one
  66. * DHCP Server per system, there is only one instance for this class
  67. *
  68. *****************************************************************************/
  69. HRESULT CDHCP_SuperScopeToSubnet::EnumerateInstances ( MethodContext* pMethodContext, long lFlags )
  70. {
  71. CDHCP_SuperScope_Parameters SuperScopeParams(NULL); // don't know here the scope
  72. HRESULT hRes = WBEM_E_FAILED;
  73. LPDHCP_SUPER_SCOPE_TABLE pScopesTable;
  74. LPDHCP_SUPER_SCOPE_TABLE_ENTRY *pSortedEntries = NULL ;
  75. DWORD dwNumEntries;
  76. if (SuperScopeParams.GetSuperScopes(pScopesTable, TRUE) &&
  77. SuperScopeParams.GetSortedScopes(ENTRIES_SORTED_ON_SUBNET, pSortedEntries, dwNumEntries))
  78. {
  79. for (int i = 0; i<dwNumEntries; i++)
  80. {
  81. if(pSortedEntries[i]->SuperScopeName != NULL)
  82. {
  83. CInstance *pInstance = CreateNewInstance(pMethodContext); // create now the instance;
  84. if (pInstance != NULL)
  85. {
  86. WCHAR wcsBuffer[256];
  87. // set the superscope part of the association
  88. swprintf(wcsBuffer, L"DHCP_SuperScope.Name=\"%s\"",
  89. pSortedEntries[i]->SuperScopeName ) ;
  90. pInstance->SetCHString(PROP_SScopeSubnets_SuperScope, wcsBuffer);
  91. // set the subnet part of the association
  92. swprintf(wcsBuffer, L"DHCP_Subnet.Address=\"%u.%u.%u.%u\"",
  93. (pSortedEntries[i]->SubnetAddress & 0xff000000) >> 24,
  94. (pSortedEntries[i]->SubnetAddress & 0x00ff0000) >> 16,
  95. (pSortedEntries[i]->SubnetAddress & 0x0000ff00) >> 8,
  96. (pSortedEntries[i]->SubnetAddress & 0x000000ff));
  97. pInstance->SetCHString(PROP_SScopeSubnets_Subnet, wcsBuffer);
  98. hRes = Commit(pInstance);
  99. if (hRes != WBEM_S_NO_ERROR)
  100. break;
  101. }
  102. }
  103. }
  104. }
  105. return hRes;
  106. }
  107. /*****************************************************************************
  108. *
  109. * FUNCTION : CDHCP_SuperScopeToSubnet::GetObject
  110. *
  111. * DESCRIPTION : Find a single instance based on the key properties for the
  112. * class.
  113. *
  114. * INPUTS : A pointer to a CInstance object containing the key properties.
  115. *
  116. * RETURNS : WBEM_S_NO_ERROR if the instance can be found
  117. * WBEM_E_NOT_FOUND if the instance described by the key properties
  118. * could not be found
  119. * WBEM_E_FAILED if the instance could be found but another error
  120. * occurred.
  121. *
  122. * COMMENTS :
  123. *
  124. *****************************************************************************/
  125. HRESULT CDHCP_SuperScopeToSubnet::GetObject ( CInstance* pInstance, long lFlags )
  126. {
  127. CHString superScope;
  128. CHString subnet;
  129. DHCP_IP_ADDRESS subnetAddress;
  130. // at this point, the key information should be provided by the pInstance
  131. if (!pInstance->GetCHString(PROP_SScopeSubnets_SuperScope, superScope) ||
  132. !pInstance->GetCHString(PROP_SScopeSubnets_Subnet, subnet) ||
  133. !inet_wstodw(subnet, subnetAddress))
  134. return (WBEM_E_FAILED);
  135. int idx;
  136. idx = superScope.Find(_T('"'));
  137. if (idx == -1)
  138. return WBEM_E_FAILED;
  139. superScope = superScope.Mid(idx + 1);
  140. idx = superScope.Find(_T('"'));
  141. if (idx == -1)
  142. return WBEM_E_FAILED;
  143. superScope = superScope.Mid(0, idx);
  144. CDHCP_SuperScope_Parameters SuperScopeParams(superScope);
  145. LPDHCP_SUPER_SCOPE_TABLE pTable;
  146. LPDHCP_SUPER_SCOPE_TABLE_ENTRY *pSortedEntries;
  147. DWORD dwNumEntries;
  148. if (SuperScopeParams.GetSuperScopes(pTable, TRUE) &&
  149. SuperScopeParams.GetSortedScopes(ENTRIES_SORTED_ON_SUBNET, pSortedEntries, dwNumEntries))
  150. {
  151. for (int i = 0; pSortedEntries[i]->SubnetAddress <= subnetAddress && i < dwNumEntries; i++)
  152. {
  153. if (pSortedEntries[i]->SubnetAddress == subnetAddress)
  154. {
  155. return wcscmp(pSortedEntries[i]->SuperScopeName, SuperScopeParams.m_wcsSuperScopeName) == 0 ?
  156. WBEM_S_NO_ERROR : WBEM_E_NOT_FOUND;
  157. }
  158. }
  159. }
  160. return WBEM_E_NOT_FOUND;
  161. }
  162. /*****************************************************************************
  163. *
  164. * FUNCTION : CDHCP_SuperScopeToSubnet::ExecQuery
  165. *
  166. * DESCRIPTION : You are passed a method context to use in the creation of
  167. * instances that satisfy the query, and a CFrameworkQuery
  168. * which describes the query. Create and populate all
  169. * instances which satisfy the query. CIMOM will post -
  170. * filter the query for you, you may return more instances
  171. * or more properties than are requested and CIMOM
  172. * will filter out any that do not apply.
  173. *
  174. *
  175. * INPUTS :
  176. *
  177. * RETURNS : WBEM_E_PROVIDER_NOT_CAPABLE if not supported for this class
  178. * WBEM_E_FAILED if the query failed
  179. * WBEM_S_NO_ERROR if query was successful
  180. *
  181. * COMMENTS : TO DO: Most providers will not need to implement this method. If you don't, cimom
  182. * will call your enumerate function to get all the instances and perform the
  183. * filtering for you. Unless you expect SIGNIFICANT savings from implementing
  184. * queries, you should remove this entire method.
  185. *
  186. *****************************************************************************/
  187. HRESULT CDHCP_SuperScopeToSubnet::ExecQuery (MethodContext *pMethodContext, CFrameworkQuery& Query, long lFlags)
  188. {
  189. return WBEM_E_PROVIDER_NOT_CAPABLE;
  190. }
  191. /*****************************************************************************
  192. *
  193. * FUNCTION : CDHCP_SuperScopeToSubnet::PutInstance
  194. *
  195. * DESCRIPTION : PutInstance should be used in provider classes that can write
  196. * instance information back to the hardware or software.
  197. * For example: Win32_Environment will allow a PutInstance of a new
  198. * environment variable, because environment variables are "software"
  199. * related. However, a class like Win32_MotherboardDevice will not
  200. * allow editing of the bus speed. Since by default PutInstance
  201. * returns WBEM_E_PROVIDER_NOT_CAPABLE, this function is placed here as a
  202. * skeleton, but can be removed if not used.
  203. *
  204. * INPUTS :
  205. *
  206. * RETURNS : WBEM_E_PROVIDER_NOT_CAPABLE if PutInstance is not available
  207. * WBEM_E_FAILED if there is an error delivering the instance
  208. * WBEM_E_INVALID_PARAMETER if any of the instance properties
  209. * are incorrect.
  210. * WBEM_S_NO_ERROR if instance is properly delivered
  211. *
  212. * COMMENTS : TO DO: If you don't intend to support writing to your provider, remove this method.
  213. *
  214. *****************************************************************************/
  215. HRESULT CDHCP_SuperScopeToSubnet::PutInstance ( const CInstance &Instance, long lFlags)
  216. {
  217. CHString superScope;
  218. CHString subnet;
  219. DHCP_IP_ADDRESS subnetAddress;
  220. // at this point, the key information should be provided by the pInstance
  221. if (!Instance.GetCHString(PROP_SScopeSubnets_SuperScope, superScope) ||
  222. !Instance.GetCHString(PROP_SScopeSubnets_Subnet, subnet) ||
  223. !inet_wstodw(subnet, subnetAddress))
  224. return (WBEM_E_FAILED);
  225. int idx;
  226. idx = superScope.Find(_T('"'));
  227. if (idx == -1)
  228. return WBEM_E_FAILED;
  229. superScope = superScope.Mid(idx + 1);
  230. idx = superScope.Find(_T('"'));
  231. if (idx == -1)
  232. return WBEM_E_FAILED;
  233. superScope = superScope.Mid(0, idx);
  234. CDHCP_SuperScope_Parameters SuperScopeParams(superScope);
  235. LPDHCP_SUPER_SCOPE_TABLE pTable;
  236. LPDHCP_SUPER_SCOPE_TABLE_ENTRY *pSortedEntries;
  237. DWORD dwNumEntries;
  238. if (SuperScopeParams.GetSuperScopes(pTable, TRUE) &&
  239. SuperScopeParams.GetSortedScopes(ENTRIES_SORTED_ON_SUBNET, pSortedEntries, dwNumEntries))
  240. {
  241. for (int i = 0; pSortedEntries[i]->SubnetAddress <= subnetAddress && i < dwNumEntries; i++)
  242. {
  243. if (pSortedEntries[i]->SubnetAddress == subnetAddress &&
  244. SuperScopeParams.AlterSubnetSet(subnetAddress))
  245. return WBEM_S_NO_ERROR;
  246. }
  247. }
  248. return WBEM_E_FAILED;
  249. }
  250. /*****************************************************************************
  251. *
  252. * FUNCTION : CDHCP_SuperScopeToSubnet::DeleteInstance
  253. *
  254. * DESCRIPTION : DeleteInstance, like PutInstance, actually writes information
  255. * to the software or hardware. For most hardware devices,
  256. * DeleteInstance should not be implemented, but for software
  257. * configuration, DeleteInstance implementation is plausible.
  258. * Like PutInstance, DeleteInstance returns WBEM_E_PROVIDER_NOT_CAPABLE from
  259. * inside Provider::DeleteInstance (defined in Provider.h). So, if
  260. * you choose not to implement DeleteInstance, remove this function
  261. * definition and the declaration from DHCP_Server_Scalars.h
  262. *
  263. * INPUTS :
  264. *
  265. * RETURNS : WBEM_E_PROVIDER_NOT_CAPABLE if DeleteInstance is not available.
  266. * WBEM_E_FAILED if there is an error deleting the instance.
  267. * WBEM_E_INVALID_PARAMETER if any of the instance properties
  268. * are incorrect.
  269. * WBEM_S_NO_ERROR if instance is properly deleted.
  270. *
  271. * COMMENTS : TO DO: If you don't intend to support deleting instances, remove this method.
  272. *
  273. *****************************************************************************/
  274. HRESULT CDHCP_SuperScopeToSubnet::DeleteInstance ( const CInstance &Instance, long lFlags )
  275. {
  276. CHString superScope;
  277. CHString subnet;
  278. DHCP_IP_ADDRESS subnetAddress;
  279. // at this point, the key information should be provided by the pInstance
  280. if (!Instance.GetCHString(PROP_SScopeSubnets_SuperScope, superScope) ||
  281. !Instance.GetCHString(PROP_SScopeSubnets_Subnet, subnet) ||
  282. !inet_wstodw(subnet, subnetAddress))
  283. return (WBEM_E_FAILED);
  284. CDHCP_SuperScope_Parameters SuperScopeParams;
  285. LPDHCP_SUPER_SCOPE_TABLE pTable;
  286. LPDHCP_SUPER_SCOPE_TABLE_ENTRY *pSortedEntries;
  287. DWORD dwNumEntries;
  288. if (SuperScopeParams.GetSuperScopes(pTable, TRUE) &&
  289. SuperScopeParams.GetSortedScopes(ENTRIES_SORTED_ON_SUBNET, pSortedEntries, dwNumEntries))
  290. {
  291. for (int i = 0; pSortedEntries[i]->SubnetAddress <= subnetAddress && i < dwNumEntries; i++)
  292. {
  293. if (pSortedEntries[i]->SubnetAddress == subnetAddress &&
  294. SuperScopeParams.AlterSubnetSet(subnetAddress))
  295. return WBEM_S_NO_ERROR;
  296. }
  297. }
  298. return WBEM_E_PROVIDER_NOT_CAPABLE;
  299. }
  300. /*****************************************************************************
  301. *
  302. * FUNCTION : CDHCP_SuperScopeToSubnet::ExecMethod
  303. *
  304. * DESCRIPTION : Override this function to provide support for methods.
  305. * A method is an entry point for the user of your provider
  306. * to request your class perform some function above and
  307. * beyond a change of state. (A change of state should be
  308. * handled by PutInstance() )
  309. *
  310. * INPUTS : A pointer to a CInstance containing the instance the method was executed against.
  311. * A string containing the method name
  312. * A pointer to the CInstance which contains the IN parameters.
  313. * A pointer to the CInstance to contain the OUT parameters.
  314. * A set of specialized method flags
  315. *
  316. * RETURNS : WBEM_E_PROVIDER_NOT_CAPABLE if not implemented for this class
  317. * WBEM_S_NO_ERROR if method executes successfully
  318. * WBEM_E_FAILED if error occurs executing method
  319. *
  320. * COMMENTS : TO DO: If you don't intend to support Methods, remove this method.
  321. *
  322. *****************************************************************************/
  323. HRESULT CDHCP_SuperScopeToSubnet::ExecMethod ( const CInstance& Instance,
  324. const BSTR bstrMethodName,
  325. CInstance *pInParams,
  326. CInstance *pOutParams,
  327. long lFlags)
  328. {
  329. return WBEM_E_PROVIDER_NOT_CAPABLE;
  330. }