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.

372 lines
14 KiB

  1. //////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright (c) 1999-2000 Microsoft Corporation
  4. //
  5. // Module Name:
  6. // Util.cpp
  7. //
  8. // Description:
  9. // Implementation of utility class and functions
  10. //
  11. // Author:
  12. // Henry Wang (HenryWa) 24-AUG-1999
  13. //
  14. //////////////////////////////////////////////////////////////////////////////
  15. #include "Pch.h"
  16. #include "Cluster.h"
  17. #include "ClusterResource.h"
  18. #include "ClusterNode.h"
  19. #include "ClusterGroup.h"
  20. #include "ClusterNodeRes.h"
  21. #include "ClusterResourceType.h"
  22. //////////////////////////////////////////////////////////////////////////////
  23. // Global Data
  24. //////////////////////////////////////////////////////////////////////////////
  25. // CLUSTER
  26. const WCHAR * const PVD_CLASS_CLUSTER = L"MSCluster_Cluster";
  27. const WCHAR * const PVD_CLASS_CLUSTERTONETWORKS = L"MSCluster_ClusterToNetworks";
  28. const WCHAR * const PVD_CLASS_CLUSTERTONETINTERFACE = L"MSCluster_ClusterToNetworkInterface";
  29. const WCHAR * const PVD_CLASS_CLUSTERTONODE = L"MSCluster_ClusterToNode";
  30. const WCHAR * const PVD_CLASS_CLUSTERTOQUORUMRES = L"MSCluster_ClusterToQuorumResource";
  31. const WCHAR * const PVD_CLASS_CLUSTERTORES = L"MSCluster_ClusterToResource";
  32. const WCHAR * const PVD_CLASS_CLUSTERTORESTYPE = L"MSCluster_ClusterToResourceType";
  33. const WCHAR * const PVD_CLASS_CLUSTERTOGROUP = L"MSCluster_ClusterToGroup";
  34. const WCHAR * const PVD_PROP_CLUSTER_NAME = L"Name";
  35. const WCHAR * const PVD_PROP_CLUSTER_SECURITY = L"Security";
  36. const WCHAR * const PVD_PROP_CLUSTER_SECURITYDESCRIPTOR = L"Security_Descriptor";
  37. const WCHAR * const PVD_PROP_CLUSTER_GROUPADMIN = L"GroupAdminExtensions";
  38. const WCHAR * const PVD_PROP_CLUSTER_NODEADMIN = L"NodeAdminExtensions";
  39. const WCHAR * const PVD_PROP_CLUSTER_RESADMIN = L"ResourceAdminExtensions";
  40. const WCHAR * const PVD_PROP_CLUSTER_RESTYPEADMIN = L"ResourceTypeAdminExtensions";
  41. const WCHAR * const PVD_PROP_CLUSTER_NETWORKADMIN = L"NetworkAdminExtensions";
  42. const WCHAR * const PVD_PROP_CLUSTER_NETINTFACEADMIN = L"NetworkInterfaceAdminExtensions";
  43. const WCHAR * const PVD_PROP_CLUSTER_FILE = L"MaintenanceFile";
  44. const WCHAR * const PVD_PROP_CLUSTER_LOGSIZE = L"QuorumLogFileSize";
  45. const WCHAR * const PVD_PROP_CLUSTER_NETWORK = L"NetworkPriorities";
  46. const WCHAR * const CLUS_CLUS_GROUPADMIN = L"Groups\\AdminExtensions";
  47. const WCHAR * const CLUS_CLUS_NETWORKADMIN = L"Networks\\AdminExtensions";
  48. const WCHAR * const CLUS_CLUS_NETINTERFACEADMIN = L"NetworkInterfaces\\AdminExtensions";
  49. const WCHAR * const CLUS_CLUS_NODEADMIN = L"Nodes\\AdminExtensions";
  50. const WCHAR * const CLUS_CLUS_RESADMIN = L"Resources\\AdminExtensions";
  51. const WCHAR * const CLUS_CLUS_RESTYPEADMIN = L"ResourceTypes\\AdminExtensions";
  52. const WCHAR * const PVD_MTH_CLUSTER_RENAME = L"Rename";
  53. const WCHAR * const PVD_MTH_CLUSTER_SETQUORUM = L"SetQuorumResource";
  54. const WCHAR * const PVD_MTH_CLUSTER_PARM_NEWNAME = L"NewName";
  55. const WCHAR * const PVD_MTH_CLUSTER_PARM_RESOURCE = L"Resource";
  56. // NODE
  57. const WCHAR * const PVD_CLASS_NODE = L"MSCluster_Node";
  58. const WCHAR * const PVD_CLASS_NODEACTIVEGROUP = L"MSCluster_NodeActiveGroup";
  59. const WCHAR * const PVD_CLASS_NODETONETINTERFACE = L"MSCluster_NodeToNetworkInterface";
  60. const WCHAR * const PVD_CLASS_NODEACTIVERES = L"MSCluster_NodeActiveResource";
  61. const WCHAR * const PVD_PROP_NODE_NAME = L"Name";
  62. // RESOURCE
  63. const WCHAR * const PVD_CLASS_RESOURCE = L"MSCluster_Resource";
  64. const WCHAR * const PVD_CLASS_RESDEPRES = L"MSCluster_ResourceDepResource";
  65. const WCHAR * const PVD_CLASS_RESRESOURCETYPE = L"MSCluster_ResourceResourceType";
  66. const WCHAR * const PVD_PROP_RES_NAME = L"Name";
  67. const WCHAR * const PVD_PROP_RES_STATE = L"State";
  68. const WCHAR * const PVD_PROP_RES_PRIVATE = L"PrivateProperties";
  69. const WCHAR * const PVD_PROP_RES_CHECKPOINTS = L"RegistryCheckpoints";
  70. const WCHAR * const PVD_PROP_RES_CRYPTO_CHECKPOINTS = L"CryptoCheckpoints";
  71. const WCHAR * const PVD_PROP_RES_CORE_RESOURCE = L"CoreResource";
  72. const WCHAR * const PVD_MTH_RES_ONLINE = L"BringOnline";
  73. const WCHAR * const PVD_MTH_RES_OFFLINE = L"TakeOffline";
  74. const WCHAR * const PVD_MTH_RES_ADD_DEPENDENCY = L"AddDependency";
  75. const WCHAR * const PVD_MTH_RES_CHANGE_GROUP = L"MoveToNewGroup";
  76. const WCHAR * const PVD_MTH_RES_CREATE_RESOURCE = L"CreateResource";
  77. const WCHAR * const PVD_MTH_RES_FAIL_RESOURCE = L"FailResource";
  78. const WCHAR * const PVD_MTH_RES_REMOVE_DEPENDENCY = L"RemoveDependency";
  79. const WCHAR * const PVD_MTH_RES_RENAME = L"Rename";
  80. const WCHAR * const PVD_MTH_RES_DELETE = L"Delete";
  81. const WCHAR * const PVD_MTH_RES_ADD_REG_CHECKPOINT = L"AddRegistryCheckpoint";
  82. const WCHAR * const PVD_MTH_RES_DEL_REG_CHECKPOINT = L"RemoveRegistryCheckpoint";
  83. const WCHAR * const PVD_MTH_RES_ADD_CRYPTO_CHECKPOINT = L"AddCryptoCheckpoint";
  84. const WCHAR * const PVD_MTH_RES_DEL_CRYPTO_CHECKPOINT = L"RemoveCryptoCheckpoint";
  85. const WCHAR * const PVD_MTH_PARM_RESOURCE = L"Resource";
  86. const WCHAR * const PVD_MTH_PARM_GROUP = L"Group";
  87. const WCHAR * const PVD_MTH_PARM_NEWNAME = L"NewName";
  88. const WCHAR * const PVD_MTH_PARM_RES_NAME = L"ResourceName";
  89. const WCHAR * const PVD_MTH_PARM_RES_TYPE = L"ResourceType";
  90. const WCHAR * const PVD_MTH_PARM_SEP_MONITOR = L"SeparateMonitor";
  91. const WCHAR * const PVD_MTH_PARM_RES_CHECKPOINT_NAME = L"CheckpointName";
  92. // Resource Type
  93. const WCHAR * const PVD_CLASS_RESOURCETYPE = L"MSCluster_ResourceType";
  94. const WCHAR * const PVD_PROP_RESTYPE_NAME = L"Name";
  95. const WCHAR * const PVD_PROP_RESTYPE_QUORUM_CAPABLE = L"QuorumCapable";
  96. const WCHAR * const PVD_PROP_RESTYPE_LOCALQUORUM_CAPABLE = L"LocalQuorumCapable";
  97. const WCHAR * const PVD_PROP_RESTYPE_DELETE_REQUIRES_ALL_NODES = L"DeleteRequiresAllNodes";
  98. // GROUP
  99. const WCHAR * const PVD_CLASS_GROUP = L"MSCluster_ResourceGroup";
  100. const WCHAR * const PVD_CLASS_GROUPTORES = L"MSCluster_ResourceGroupToResource";
  101. const WCHAR * const PVD_PROP_GROUP_NAME = L"Name";
  102. const WCHAR * const PVD_PROP_NODELIST = L"PreferredNodeList";
  103. const WCHAR * const PVD_MTH_GROUP_CREATEGROUP = L"CreateGroup";
  104. const WCHAR * const PVD_MTH_GROUP_TAKEOFFLINE = L"TakeOffLine";
  105. const WCHAR * const PVD_MTH_GROUP_BRINGONLINE = L"BringOnLine";
  106. const WCHAR * const PVD_MTH_GROUP_MOVETONEWNODE = L"MoveToNewNode";
  107. const WCHAR * const PVD_MTH_GROUP_DELETE = L"Delete";
  108. const WCHAR * const PVD_MTH_GROUP_RENAME = L"Rename";
  109. const WCHAR * const PVD_MTH_GROUP_PARM_GROUPNAME = L"GroupName";
  110. const WCHAR * const PVD_MTH_GROUP_PARM_NODENAME = L"NodeName";
  111. const WCHAR * const PVD_MTH_GROUP_PARM_NEWNAME = L"NewName";
  112. // NetworkInterface
  113. const WCHAR * const PVD_CLASS_NETWORKSINTERFACE = L"MSCluster_NetworkInterface";
  114. const WCHAR * const PVD_PROP_NETINTERFACE_DEVICEID = L"DeviceId";
  115. const WCHAR * const PVD_PROP_NETINTERFACE_SYSTEMNAME = L"SystemName";
  116. const WCHAR * const PVD_PROP_NETINTERFACE_STATE = L"State";
  117. // networks
  118. const WCHAR * const PVD_CLASS_NETWORKS = L"MSCluster_Networks";
  119. const WCHAR * const PVD_CLASS_NETTONETINTERFACE = L"MSCluster_NetworkToNetworksInterface";
  120. const WCHAR * const PVD_PROP_NETWORK_STATE = L"State";
  121. const WCHAR * const PVD_MTH_NETWORK_RENAME = L"Rename";
  122. const WCHAR * const PVD_MTH_NETWORK_PARM_NEWNAME = L"NewName";
  123. // service
  124. const WCHAR * const PVD_CLASS_SERVICES = L"MSCluster_Service";
  125. const WCHAR * const PVD_CLASS_HOSTEDSERVICES = L"MSCluster_HostedService";
  126. const WCHAR * const PVD_PROP_SERVICE_NAME = L"Name";
  127. const WCHAR * const PVD_PROP_SERVICE_SYSTEMNAME = L"SystemName";
  128. const WCHAR * const PVD_MTH_SERVICE_PAUSE = L"Pause";
  129. const WCHAR * const PVD_MTH_SERVICE_RESUME = L"Resume";
  130. // event
  131. const WCHAR * const PVD_CLASS_EVENT = L"MSCluster_Event";
  132. const WCHAR * const PVD_PROP_EVENT_NAME = L"EventObjectName";
  133. const WCHAR * const PVD_PROP_EVENT_PATH = L"EventObjectPath";
  134. const WCHAR * const PVD_PROP_EVENT_TYPE = L"EventObjectType";
  135. const WCHAR * const PVD_PROP_EVENT_TYPEMAJOR = L"EventTypeMajor";
  136. const WCHAR * const PVD_PROP_EVENT_TYPEMINOR = L"EventTypeMinor";
  137. const WCHAR * const PVD_PROP_EVENT_NEWSTATE = L"EventNewState";
  138. const WCHAR * const PVD_PROP_EVENT_NODE = L"EventNode";
  139. const WCHAR * const PVD_PROP_EVENT_GROUP = L"EventGroup";
  140. const WCHAR * const PVD_CLASS_EVENT_ADD = L"MSCluster_EventObjectAdd";
  141. const WCHAR * const PVD_CLASS_EVENT_REMOVE = L"MSCluster_EventObjectRemove";
  142. const WCHAR * const PVD_CLASS_EVENT_STATECHANGE = L"MSCluster_EventStateChange";
  143. const WCHAR * const PVD_CLASS_EVENT_GROUPSTATECHANGE = L"MSCluster_EventGroupStateChange";
  144. const WCHAR * const PVD_CLASS_EVENT_RESOURCESTATECHANGE = L"MSCluster_EventResourceStateChange";
  145. const WCHAR * const PVD_CLASS_EVENT_PROP = L"MSCluster_EventPropertyChange";
  146. const WCHAR * const PVD_CLASS_PROPERTY = L"MSCluster_Property";
  147. const WCHAR * const PVD_PROP_NAME = L"Name";
  148. const WCHAR * const PVD_PROP_STATE = L"State";
  149. const WCHAR * const PVD_PROP_GROUPCOMPONENT = L"GroupComponent";
  150. const WCHAR * const PVD_PROP_PARTCOMPONENT = L"PartComponent";
  151. const WCHAR * const PVD_PROP_CHARACTERISTIC = L"characteristics";
  152. const WCHAR * const PVD_PROP_FLAGS = L"Flags";
  153. //
  154. // wbem
  155. //
  156. const WCHAR * const PVD_WBEM_EXTENDEDSTATUS = L"__ExtendedStatus";
  157. const WCHAR * const PVD_WBEM_DESCRIPTION = L"Description";
  158. const WCHAR * const PVD_WBEM_STATUSCODE = L"StatusCode";
  159. const WCHAR * const PVD_WBEM_STATUS = L"Status";
  160. const WCHAR * const PVD_WBEM_CLASS = L"__CLASS";
  161. const WCHAR * const PVD_WBEM_RELPATH = L"__Relpath";
  162. const WCHAR * const PVD_WBEM_PROP_ANTECEDENT = L"Antecedent";
  163. const WCHAR * const PVD_WBEM_PROP_DEPENDENT = L"Dependent";
  164. const WCHAR * const PVD_WBEM_PROP_DEVICEID = L"DeviceId";
  165. const WCHAR * const PVD_WBEM_QUA_DYNAMIC = L"Dynamic";
  166. const WCHAR * const PVD_WBEM_QUA_CIMTYPE = L"CIMTYPE";
  167. const WCHAR * const PVD_WBEM_QUA_PROV_VALUE = L"MS_CLUSTER_PROVIDER";
  168. const WCHAR * const PVD_WBEM_QUA_PROV_NAME = L"Provider";
  169. //////////////////////////////////////////////////////////////////////////////
  170. //++
  171. //
  172. // void
  173. // CreateClass(
  174. // const WCHAR * pwszClassNameIn,
  175. // CWbemServices * pNamespaceIn,
  176. // auto_ptr< CProvBase > & rNewClassInout
  177. // )
  178. //
  179. // Description:
  180. // Create the specified class
  181. //
  182. // Arguments:
  183. // pwszClassNameIn -- Name of the class to create.
  184. // pNamespaceIn -- WMI namespace
  185. // rNewClassInout -- Receives the new class.
  186. //
  187. // Return Values:
  188. // reference to the array of property maping table
  189. //
  190. //--
  191. //////////////////////////////////////////////////////////////////////////////
  192. void
  193. CreateClass(
  194. const WCHAR * pwszClassNameIn,
  195. CWbemServices * pNamespaceIn,
  196. auto_ptr< CProvBase > & rNewClassInout
  197. )
  198. {
  199. CClassCreator & rcc = g_ClassMap[ pwszClassNameIn ];
  200. if ( rcc.m_pfnConstructor != NULL )
  201. {
  202. auto_ptr< CProvBase > pBase(
  203. rcc.m_pfnConstructor(
  204. rcc.m_pbstrClassName,
  205. pNamespaceIn,
  206. rcc.m_dwEnumType
  207. )
  208. );
  209. rNewClassInout = pBase;
  210. }
  211. else
  212. {
  213. throw CProvException( static_cast< HRESULT >( WBEM_E_INVALID_PARAMETER ) );
  214. }
  215. return;
  216. } //*** void CreateClass()
  217. //****************************************************************************
  218. //
  219. // PropMapEntryArray
  220. //
  221. //****************************************************************************
  222. //////////////////////////////////////////////////////////////////////////////
  223. //++
  224. //
  225. // LPCWSTR
  226. // SPropMapEntryArray::PwszLookup(
  227. // LPCWSTR pwszIn
  228. // ) const
  229. //
  230. // Description:
  231. // Lookup an entry in the array.
  232. //
  233. // Arguments:
  234. // pwszIn -- Name of entry to lookup.
  235. //
  236. // Return Values:
  237. // Pointer to string entry in the array.
  238. //
  239. //--
  240. //////////////////////////////////////////////////////////////////////////////
  241. LPCWSTR
  242. SPropMapEntryArray::PwszLookup(
  243. LPCWSTR pwszIn
  244. ) const
  245. {
  246. UINT idx;
  247. for ( idx = 0; idx < m_dwSize; idx ++ )
  248. {
  249. if ( _wcsicmp( pwszIn, m_pArray[ idx ].clstName ) == 0 )
  250. {
  251. //
  252. // mofName is NULL for clstname not supported
  253. //
  254. return m_pArray[ idx ].mofName;
  255. }
  256. }
  257. //
  258. // mofname is the same as clstname if not found in the table
  259. //
  260. return pwszIn;
  261. } //*** SPropMapEntry::PwszLookup()
  262. //////////////////////////////////////////////////////////////////////////////
  263. //++
  264. //
  265. // LPCWSTR
  266. // PwszSpaceReplace(
  267. // LPWSTR pwszTrgInout,
  268. // LPCWSTR pwszSrcIn,
  269. // WCHAR wchArgIn
  270. // )
  271. //
  272. // Description:
  273. // Replace spaces in a string with another character.
  274. // Ignores leading spaces.
  275. //
  276. // Arguments:
  277. // pwszTrgInout -- Target string.
  278. // pwszSrcIn -- Source string.
  279. // wchArgIn -- Character to replace spaces with.
  280. //
  281. // Return Values:
  282. // Pointer to the target string.
  283. //
  284. //--
  285. //////////////////////////////////////////////////////////////////////////////
  286. LPWSTR
  287. PwszSpaceReplace(
  288. LPWSTR pwszTrgInout,
  289. LPCWSTR pwszSrcIn,
  290. WCHAR wchArgIn
  291. )
  292. {
  293. LPCWSTR pwsz = NULL;
  294. LPWSTR pwszTrg = NULL;
  295. if ( ( pwszTrgInout == NULL ) || ( pwszSrcIn == NULL ) )
  296. {
  297. return NULL;
  298. }
  299. //
  300. // ignore leading space
  301. //
  302. for ( pwsz = pwszSrcIn ; *pwsz == L' '; pwsz++ )
  303. {
  304. // empty loop
  305. }
  306. pwszTrg = pwszTrgInout;
  307. for ( ; *pwsz != L'\0' ; pwsz++ )
  308. {
  309. if ( *pwsz == L' ' )
  310. {
  311. *pwszTrg++ = wchArgIn;
  312. for ( ; *pwsz == L' '; pwsz++ )
  313. {
  314. // empty loop
  315. }
  316. pwsz--;
  317. }
  318. else
  319. {
  320. *pwszTrg++ = *pwsz;
  321. }
  322. } // for: each character in the source string
  323. *pwszTrg = L'\0';
  324. return pwszTrgInout;
  325. } //*** PwszSpaceReplace()