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.

354 lines
14 KiB

  1. /******************************************************************
  2. SrvScal.cpp -- WBEM provider class implementation
  3. MODULE:
  4. DhcpProv.dll
  5. DESCRIPTION:
  6. Contains: the definition of the DHCP_Server class,
  7. the static table of manageable objects.
  8. REVISION:
  9. 08/03/98 - created
  10. ******************************************************************/
  11. #include <stdafx.h>
  12. #include "SrvFn.h" // needed for the declarations of all the functions.
  13. #include "SrvScal.h" // own header
  14. // static table of CDHCP_Property objects containing the DHCP Server
  15. // scalar parameters (properties) which are WBEM manageable. Each object associates
  16. // the name of the property with their SET and GET functions.
  17. // *** NOTE ***
  18. // The name of each property has to be in sync with the ones specified in the DhcpSchema.mof.
  19. // The indices specified in SrvScal.h should also be in sync with the actual row from this table (they are used
  20. // in the property's action functions.
  21. static const CDHCP_Property DHCP_Server_Property[]=
  22. {
  23. CDHCP_Property(L"StartTime", fnSrvGetStartTime, NULL),
  24. CDHCP_Property(L"TotalNoOfAcks", fnSrvGetTotalNoOfAcks, NULL),
  25. CDHCP_Property(L"TotalNoOfDeclines", fnSrvGetTotalNoOfDeclines, NULL),
  26. CDHCP_Property(L"TotalNoOfDiscovers", fnSrvGetTotalNoOfDiscovers, NULL),
  27. CDHCP_Property(L"TotalNoOfNacks", fnSrvGetTotalNoOfNacks, NULL),
  28. CDHCP_Property(L"TotalNoOfOffers", fnSrvGetTotalNoOfOffers, NULL),
  29. CDHCP_Property(L"TotalNoOfReleases", fnSrvGetTotalNoOfReleases, NULL),
  30. CDHCP_Property(L"TotalNoOfRequests", fnSrvGetTotalNoOfRequests, NULL),
  31. CDHCP_Property(L"ServerVersion", fnSrvGetServerVersion, NULL),
  32. CDHCP_Property(L"APIProtocol", fnSrvGetAPIProtocol, fnSrvSetAPIProtocol),
  33. CDHCP_Property(L"DatabaseName", fnSrvGetDatabaseName, fnSrvSetDatabaseName),
  34. CDHCP_Property(L"DatabasePath", fnSrvGetDatabasePath, fnSrvSetDatabasePath),
  35. CDHCP_Property(L"BackupPath", fnSrvGetBackupPath, fnSrvSetBackupPath),
  36. CDHCP_Property(L"BackupInterval", fnSrvGetBackupInterval, fnSrvSetBackupInterval),
  37. CDHCP_Property(L"DatabaseLoggingFlag", fnSrvGetDatabaseLoggingFlag, fnSrvSetDatabaseLoggingFlag),
  38. CDHCP_Property(L"RestoreFlag", fnSrvGetRestoreFlag, fnSrvSetRestoreFlag),
  39. CDHCP_Property(L"DatabaseCleanupInterval", fnSrvGetDatabaseCleanupInterval, fnSrvSetDatabaseCleanupInterval),
  40. CDHCP_Property(L"DebugFlag", fnSrvGetDebugFlag, fnSrvSetDebugFlag),
  41. CDHCP_Property(L"PingRetries", fnSrvGetPingRetries, fnSrvSetPingRetries),
  42. CDHCP_Property(L"BootFileTable", fnSrvGetBootFileTable, fnSrvSetBootFileTable),
  43. CDHCP_Property(L"AuditLog", fnSrvGetAuditLog, fnSrvSetAuditLog)
  44. };
  45. // the name of the WBEM class
  46. #define PROVIDER_NAME_DHCP_SERVER "DHCP_Server"
  47. // main class instantiation.
  48. CDHCP_Server MyDHCP_Server_Scalars (PROVIDER_NAME_DHCP_SERVER, PROVIDER_NAMESPACE_DHCP) ;
  49. /*****************************************************************************
  50. *
  51. * FUNCTION : CDHCP_Server::CDHCP_Server
  52. *
  53. * DESCRIPTION : Constructor
  54. *
  55. * INPUTS : none
  56. *
  57. * RETURNS : nothing
  58. *
  59. * COMMENTS : Calls the Provider constructor.
  60. *
  61. *****************************************************************************/
  62. CDHCP_Server::CDHCP_Server (const CHString& strName, LPCSTR pszNameSpace ) :
  63. Provider(strName, pszNameSpace)
  64. {
  65. }
  66. /*****************************************************************************
  67. *
  68. * FUNCTION : CDHCP_Server::~CDHCP_Server
  69. *
  70. * DESCRIPTION : Destructor
  71. *
  72. * INPUTS : none
  73. *
  74. * RETURNS : nothing
  75. *
  76. * COMMENTS :
  77. *
  78. *****************************************************************************/
  79. CDHCP_Server::~CDHCP_Server ()
  80. {
  81. }
  82. /*****************************************************************************
  83. *
  84. * FUNCTION : CDHCP_Server::EnumerateInstances
  85. *
  86. * DESCRIPTION : Returns all the instances of this class.
  87. *
  88. * INPUTS : none
  89. *
  90. * RETURNS : WBEM_S_NO_ERROR if successful
  91. *
  92. * COMMENTS : Enumerates all this instances of this class. As there is only one
  93. * DHCP Server per system, there is only one instance for this class
  94. *
  95. *****************************************************************************/
  96. HRESULT CDHCP_Server::EnumerateInstances ( MethodContext* pMethodContext, long lFlags )
  97. {
  98. CInstance* pInstance;
  99. HRESULT hRes = WBEM_S_NO_ERROR;
  100. if ((pInstance = CreateNewInstance(pMethodContext)) != NULL &&
  101. LoadInstanceProperties(pInstance))
  102. {
  103. hRes = Commit(pInstance);
  104. }
  105. else
  106. {
  107. hRes = WBEM_E_OUT_OF_MEMORY;
  108. }
  109. return hRes ;
  110. }
  111. /*****************************************************************************
  112. *
  113. * FUNCTION : CDHCP_Server::GetObject
  114. *
  115. * DESCRIPTION : Find a single instance based on the key properties for the
  116. * class.
  117. *
  118. * INPUTS : A pointer to a CInstance object containing the key properties.
  119. *
  120. * RETURNS : WBEM_S_NO_ERROR if the instance can be found
  121. * WBEM_E_NOT_FOUND if the instance described by the key properties
  122. * could not be found
  123. * WBEM_E_FAILED if the instance could be found but another error
  124. * occurred.
  125. *
  126. * COMMENTS :
  127. *
  128. *****************************************************************************/
  129. HRESULT CDHCP_Server::GetObject ( CInstance* pInstance, long lFlags )
  130. {
  131. return LoadInstanceProperties(pInstance)? WBEM_S_NO_ERROR : WBEM_E_NOT_FOUND;
  132. }
  133. /*****************************************************************************
  134. *
  135. * FUNCTION : CDHCP_Server::ExecQuery
  136. *
  137. * DESCRIPTION : You are passed a method context to use in the creation of
  138. * instances that satisfy the query, and a CFrameworkQuery
  139. * which describes the query. Create and populate all
  140. * instances which satisfy the query. CIMOM will post -
  141. * filter the query for you, you may return more instances
  142. * or more properties than are requested and CIMOM
  143. * will filter out any that do not apply.
  144. *
  145. *
  146. * INPUTS :
  147. *
  148. * RETURNS : WBEM_E_PROVIDER_NOT_CAPABLE if not supported for this class
  149. * WBEM_E_FAILED if the query failed
  150. * WBEM_S_NO_ERROR if query was successful
  151. *
  152. * COMMENTS : TO DO: Most providers will not need to implement this method. If you don't, cimom
  153. * will call your enumerate function to get all the instances and perform the
  154. * filtering for you. Unless you expect SIGNIFICANT savings from implementing
  155. * queries, you should remove this entire method.
  156. *
  157. *****************************************************************************/
  158. HRESULT CDHCP_Server::ExecQuery (MethodContext *pMethodContext, CFrameworkQuery& Query, long lFlags)
  159. {
  160. return (WBEM_E_PROVIDER_NOT_CAPABLE);
  161. }
  162. /*****************************************************************************
  163. *
  164. * FUNCTION : CDHCP_Server::PutInstance
  165. *
  166. * DESCRIPTION : PutInstance should be used in provider classes that can write
  167. * instance information back to the hardware or software.
  168. * For example: Win32_Environment will allow a PutInstance of a new
  169. * environment variable, because environment variables are "software"
  170. * related. However, a class like Win32_MotherboardDevice will not
  171. * allow editing of the bus speed. Since by default PutInstance
  172. * returns WBEM_E_PROVIDER_NOT_CAPABLE, this function is placed here as a
  173. * skeleton, but can be removed if not used.
  174. *
  175. * INPUTS :
  176. *
  177. * RETURNS : WBEM_E_PROVIDER_NOT_CAPABLE if PutInstance is not available
  178. * WBEM_E_FAILED if there is an error delivering the instance
  179. * WBEM_E_INVALID_PARAMETER if any of the instance properties
  180. * are incorrect.
  181. * WBEM_S_NO_ERROR if instance is properly delivered
  182. *
  183. * COMMENTS : TO DO: If you don't intend to support writing to your provider, remove this method.
  184. *
  185. *****************************************************************************/
  186. HRESULT CDHCP_Server::PutInstance ( const CInstance &Instance, long lFlags)
  187. {
  188. int i;
  189. DWORD returnCode;
  190. // the object below is used as a "repository" for all the properties' values.
  191. // once it is filled up with data, it is commited explicitely to the DHCP Server.
  192. CDHCP_Server_Parameters ServerParameters;
  193. for (i = 0; i < NUM_SERVER_PROPERTIES; i++)
  194. {
  195. if (DHCP_Server_Property[i].m_pfnActionSet != NULL)
  196. {
  197. // execute the SET property action function
  198. // no data is written to DHCP Server at this moment, only ServerParameters object
  199. // is filled up with the values taken from the Instance.
  200. // don't care much here about the error codes. Failure means some properties will
  201. // not be written. At least we are giving a chance to all the writable properties.
  202. (*(DHCP_Server_Property[i].m_pfnActionSet))(&ServerParameters, (CInstance *)&Instance, NULL);
  203. }
  204. }
  205. // commit the values of all the writable properties to DHCP Server
  206. return ServerParameters.CommitSet(returnCode) ? WBEM_S_NO_ERROR : WBEM_E_FAILED;
  207. }
  208. /*****************************************************************************
  209. *
  210. * FUNCTION : CDHCP_Server::DeleteInstance
  211. *
  212. * DESCRIPTION : DeleteInstance, like PutInstance, actually writes information
  213. * to the software or hardware. For most hardware devices,
  214. * DeleteInstance should not be implemented, but for software
  215. * configuration, DeleteInstance implementation is plausible.
  216. * Like PutInstance, DeleteInstance returns WBEM_E_PROVIDER_NOT_CAPABLE from
  217. * inside Provider::DeleteInstance (defined in Provider.h). So, if
  218. * you choose not to implement DeleteInstance, remove this function
  219. * definition and the declaration from DHCP_Server_Scalars.h
  220. *
  221. * INPUTS :
  222. *
  223. * RETURNS : WBEM_E_PROVIDER_NOT_CAPABLE if DeleteInstance is not available.
  224. * WBEM_E_FAILED if there is an error deleting the instance.
  225. * WBEM_E_INVALID_PARAMETER if any of the instance properties
  226. * are incorrect.
  227. * WBEM_S_NO_ERROR if instance is properly deleted.
  228. *
  229. * COMMENTS : TO DO: If you don't intend to support deleting instances, remove this method.
  230. *
  231. *****************************************************************************/
  232. HRESULT CDHCP_Server::DeleteInstance ( const CInstance &Instance, long lFlags )
  233. {
  234. return (WBEM_E_PROVIDER_NOT_CAPABLE);
  235. }
  236. /*****************************************************************************
  237. *
  238. * FUNCTION : CDHCP_Server::ExecMethod
  239. *
  240. * DESCRIPTION : Override this function to provide support for methods.
  241. * A method is an entry point for the user of your provider
  242. * to request your class perform some function above and
  243. * beyond a change of state. (A change of state should be
  244. * handled by PutInstance() )
  245. *
  246. * INPUTS : A pointer to a CInstance containing the instance the method was executed against.
  247. * A string containing the method name
  248. * A pointer to the CInstance which contains the IN parameters.
  249. * A pointer to the CInstance to contain the OUT parameters.
  250. * A set of specialized method flags
  251. *
  252. * RETURNS : WBEM_E_PROVIDER_NOT_CAPABLE if not implemented for this class
  253. * WBEM_S_NO_ERROR if method executes successfully
  254. * WBEM_E_FAILED if error occurs executing method
  255. *
  256. * COMMENTS : TO DO: If you don't intend to support Methods, remove this method.
  257. *
  258. *****************************************************************************/
  259. HRESULT CDHCP_Server::ExecMethod ( const CInstance& Instance,
  260. const BSTR bstrMethodName,
  261. CInstance *pInParams,
  262. CInstance *pOutParams,
  263. long lFlags)
  264. {
  265. int nSetPrefixLen = wcslen(_SRV_SET_PREFIX);
  266. // is it a "SET" operation?
  267. if (!_wcsnicmp (bstrMethodName, _SRV_SET_PREFIX, nSetPrefixLen))
  268. {
  269. int i;
  270. WCHAR *wcsPropertyName = bstrMethodName + nSetPrefixLen; // pointer to the property name
  271. // scan the DHCP_Server_Property table looking for the property's row
  272. for (i = 0; i < NUM_SERVER_PROPERTIES; i++)
  273. {
  274. // if the property row is found
  275. if (!_wcsicmp(wcsPropertyName, DHCP_Server_Property[i].m_wsPropName))
  276. {
  277. // see if the property is writable
  278. if (DHCP_Server_Property[i].m_pfnActionSet != NULL)
  279. {
  280. // execute the SET property action function
  281. if ((*(DHCP_Server_Property[i].m_pfnActionSet))(NULL, pInParams, pOutParams))
  282. // everything worked fine.
  283. return WBEM_S_NO_ERROR;
  284. else
  285. // an error occured during "SET"
  286. return WBEM_E_FAILED;
  287. }
  288. else
  289. // no, the property cannot be written. (shouldn't really happen, as the methods from the
  290. // repository should match the writable properties only)
  291. return WBEM_E_READ_ONLY;
  292. }
  293. }
  294. }
  295. // if this point was reached, no method was found => provider not capable
  296. return WBEM_E_PROVIDER_NOT_CAPABLE;
  297. }
  298. /*****************************************************************************
  299. *
  300. * FUNCTION : CDHCP_Server::LoadInstanceProperties
  301. *
  302. * RETURNS : TRUE if the values for all the properties was loaded successfully,
  303. * FALSE otherwise.
  304. *
  305. * COMMENTS : It loops through the Server_Property table, calling the GET functions.
  306. *
  307. *****************************************************************************/
  308. BOOL CDHCP_Server::LoadInstanceProperties(CInstance* pInstance)
  309. {
  310. int i;
  311. // there should be used this object, in order to not call several times the DHCP Server API.
  312. CDHCP_Server_Parameters ServerParameters;
  313. for (i = 0; i < NUM_SERVER_PROPERTIES; i++)
  314. {
  315. // if there is an invisible property (does not support GET) just skip it.
  316. if (DHCP_Server_Property[i].m_pfnActionGet == NULL)
  317. continue;
  318. // call the appropriate GET function, fail if the call fails (there should be no reason for failure)
  319. if (!(*(DHCP_Server_Property[i].m_pfnActionGet))(&ServerParameters, NULL, pInstance))
  320. return FALSE;
  321. }
  322. return TRUE;
  323. }