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.

389 lines
16 KiB

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