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.

1271 lines
38 KiB

  1. #include "WLBS_Provider.h"
  2. #include "WLBS_NodeSetting.h"
  3. #include "ClusterWrapper.h"
  4. #include "ControlWrapper.h"
  5. #include "utils.h"
  6. #include "wlbsutil.h"
  7. #include <winsock.h>
  8. #include "WLBS_NodeSetting.tmh"
  9. ////////////////////////////////////////////////////////////////////////////////
  10. //
  11. // CWLBS_NodeSetting::CWLBS_NodeSetting
  12. //
  13. // Purpose: Constructor
  14. //
  15. ////////////////////////////////////////////////////////////////////////////////
  16. CWLBS_NodeSetting::CWLBS_NodeSetting
  17. (
  18. CWbemServices* a_pNameSpace,
  19. IWbemObjectSink* a_pResponseHandler
  20. )
  21. : CWlbs_Root( a_pNameSpace, a_pResponseHandler )
  22. {
  23. }
  24. ////////////////////////////////////////////////////////////////////////////////
  25. //
  26. // CWLBS_NodeSetting::Create
  27. //
  28. // Purpose: This instantiates this class and is invoked from an array of
  29. // function pointers.
  30. //
  31. ////////////////////////////////////////////////////////////////////////////////
  32. CWlbs_Root* CWLBS_NodeSetting::Create
  33. (
  34. CWbemServices* a_pNameSpace,
  35. IWbemObjectSink* a_pResponseHandler
  36. )
  37. {
  38. CWlbs_Root* pRoot = new CWLBS_NodeSetting( a_pNameSpace, a_pResponseHandler );
  39. if( !pRoot )
  40. throw _com_error( WBEM_E_OUT_OF_MEMORY );
  41. return pRoot;
  42. }
  43. ////////////////////////////////////////////////////////////////////////////////
  44. //
  45. // CWLBS_NodeSetting::GetInstance
  46. //
  47. // Purpose: This function retrieves an instance of a MOF NodeSetting
  48. // class. The node does not have to be a member of a cluster. However,
  49. // WLBS must be installed for this function to succeed.
  50. //
  51. ////////////////////////////////////////////////////////////////////////////////
  52. HRESULT CWLBS_NodeSetting::GetInstance
  53. (
  54. const ParsedObjectPath* a_pParsedPath,
  55. long /* a_lFlags */,
  56. IWbemContext* /* a_pIContex */
  57. )
  58. {
  59. IWbemClassObject* pWlbsInstance = NULL;
  60. HRESULT hRes = 0;
  61. TRACE_CRIT("->%!FUNC!");
  62. try {
  63. //get the name key property and convert to wstring
  64. const wchar_t* wstrHostName = (*a_pParsedPath->m_paKeys)->m_vValue.bstrVal;
  65. CWlbsClusterWrapper* pCluster = GetClusterFromHostName(g_pWlbsControl, wstrHostName);
  66. DWORD dwHostID = ExtractHostID( wstrHostName );
  67. if (pCluster == NULL || (DWORD)-1 == dwHostID || pCluster->GetHostID() != dwHostID)
  68. {
  69. TRACE_CRIT("%!FUNC! (GetClusterFromHostName (Host Name : %ls) or ExtractHostID (Host Id : %d)) failed or Host Id does NOT match, Throwing com_error WBEM_E_NOT_FOUND exception",wstrHostName, dwHostID);
  70. throw _com_error( WBEM_E_NOT_FOUND );
  71. }
  72. //get the Wbem class instance
  73. SpawnInstance( MOF_NODESETTING::szName, &pWlbsInstance );
  74. //Convert status to string description
  75. FillWbemInstance(pCluster, pWlbsInstance );
  76. //send the results back to WinMgMt
  77. m_pResponseHandler->Indicate( 1, &pWlbsInstance );
  78. if( pWlbsInstance ) {
  79. pWlbsInstance->Release();
  80. pWlbsInstance = NULL;
  81. }
  82. m_pResponseHandler->SetStatus( 0, WBEM_S_NO_ERROR, NULL, NULL );
  83. hRes = WBEM_S_NO_ERROR;
  84. }
  85. catch(CErrorWlbsControl Err) {
  86. IWbemClassObject* pWbemExtStat = NULL;
  87. TRACE_CRIT("%!FUNC! Caught a Wlbs exception : 0x%x", Err.Error());
  88. CreateExtendedStatus( m_pNameSpace,
  89. &pWbemExtStat,
  90. Err.Error(),
  91. (PWCHAR)(Err.Description()) );
  92. m_pResponseHandler->SetStatus(0, WBEM_E_FAILED, NULL, pWbemExtStat);
  93. //if( pWbemExtStat )
  94. //pWbemExtStat->Release();
  95. if( pWlbsInstance )
  96. pWlbsInstance->Release();
  97. //do not return WBEM_E_FAILED, this causes a race condition
  98. hRes = WBEM_S_NO_ERROR;
  99. }
  100. catch(_com_error HResErr ) {
  101. TRACE_CRIT("%!FUNC! Caught a com_error exception : 0x%x", HResErr.Error());
  102. m_pResponseHandler->SetStatus(0, HResErr.Error(), NULL, NULL);
  103. if( pWlbsInstance )
  104. pWlbsInstance->Release();
  105. hRes = HResErr.Error();
  106. if( hRes == ERROR_FILE_NOT_FOUND )
  107. hRes = WBEM_E_NOT_FOUND;
  108. }
  109. catch(...) {
  110. TRACE_CRIT("%!FUNC! Caught an exception");
  111. if( pWlbsInstance )
  112. pWlbsInstance->Release();
  113. TRACE_CRIT("%!FUNC! Rethrowing exception");
  114. TRACE_CRIT("<-%!FUNC!");
  115. throw;
  116. }
  117. TRACE_CRIT("<-%!FUNC! return 0x%x", hRes);
  118. return hRes;
  119. }
  120. ////////////////////////////////////////////////////////////////////////////////
  121. //
  122. // CWLBS_NodeSetting::EnumInstances
  123. //
  124. // Purpose: This function obtains the NodeSetting data for the current host.
  125. // The node does not have to be a member of a cluster for this
  126. // to succeed.
  127. //
  128. ////////////////////////////////////////////////////////////////////////////////
  129. HRESULT CWLBS_NodeSetting::EnumInstances
  130. (
  131. BSTR /*a_bstrClass*/,
  132. long /* a_lFlags */,
  133. IWbemContext* /* a_pIContex */
  134. )
  135. {
  136. IWbemClassObject* pWlbsInstance = NULL;
  137. HRESULT hRes = 0;
  138. TRACE_CRIT("->%!FUNC!");
  139. try {
  140. DWORD dwNumClusters = 0;
  141. CWlbsClusterWrapper** ppCluster = NULL;
  142. g_pWlbsControl->EnumClusters(ppCluster, &dwNumClusters);
  143. if (dwNumClusters == 0)
  144. {
  145. TRACE_CRIT("%!FUNC! CWlbsControlWrapper::EnumClusters() returned no clusters, Throwing com_error WBEM_E_NOT_FOUND exception");
  146. throw _com_error( WBEM_E_NOT_FOUND );
  147. }
  148. for (DWORD i=0; i<dwNumClusters; i++)
  149. {
  150. //get the Wbem class instance
  151. SpawnInstance( MOF_NODESETTING::szName, &pWlbsInstance );
  152. //Convert status to string description
  153. FillWbemInstance(ppCluster[i], pWlbsInstance );
  154. //send the results back to WinMgMt
  155. m_pResponseHandler->Indicate( 1, &pWlbsInstance );
  156. }
  157. if( pWlbsInstance ) {
  158. pWlbsInstance->Release();
  159. pWlbsInstance = NULL;
  160. }
  161. m_pResponseHandler->SetStatus( 0, WBEM_S_NO_ERROR, NULL, NULL );
  162. hRes = WBEM_S_NO_ERROR;
  163. }
  164. catch(CErrorWlbsControl Err) {
  165. IWbemClassObject* pWbemExtStat = NULL;
  166. TRACE_CRIT("%!FUNC! Caught a Wlbs exception : 0x%x", Err.Error());
  167. CreateExtendedStatus( m_pNameSpace,
  168. &pWbemExtStat,
  169. Err.Error(),
  170. (PWCHAR)(Err.Description()) );
  171. m_pResponseHandler->SetStatus(0, WBEM_E_FAILED, NULL, pWbemExtStat);
  172. if( pWbemExtStat )
  173. pWbemExtStat->Release();
  174. if( pWlbsInstance )
  175. pWlbsInstance->Release();
  176. //do not return WBEM_E_FAILED, this causes a race condition
  177. hRes = WBEM_S_NO_ERROR;
  178. }
  179. catch(_com_error HResErr ) {
  180. TRACE_CRIT("%!FUNC! Caught a com_error exception : 0x%x", HResErr.Error());
  181. m_pResponseHandler->SetStatus(0, HResErr.Error(), NULL, NULL);
  182. if( pWlbsInstance )
  183. pWlbsInstance->Release();
  184. hRes = HResErr.Error();
  185. if( hRes == ERROR_FILE_NOT_FOUND )
  186. hRes = WBEM_E_NOT_FOUND;
  187. }
  188. catch(...) {
  189. TRACE_CRIT("%!FUNC! Caught an exception");
  190. if( pWlbsInstance )
  191. pWlbsInstance->Release();
  192. TRACE_CRIT("%!FUNC! Rethrowing exception");
  193. TRACE_CRIT("<-%!FUNC!");
  194. throw;
  195. }
  196. TRACE_CRIT("<-%!FUNC! return 0x%x", hRes);
  197. return hRes;
  198. }
  199. ////////////////////////////////////////////////////////////////////////////////
  200. //
  201. // CWLBS_NodeSetting::PutInstance
  202. //
  203. // Purpose: This function updates an instance of a MOF NodeSetting
  204. // class. The node does not have to be a member of a cluster.
  205. //
  206. ////////////////////////////////////////////////////////////////////////////////
  207. HRESULT CWLBS_NodeSetting::PutInstance
  208. (
  209. IWbemClassObject* a_pInstance,
  210. long /* a_lFlags */,
  211. IWbemContext* /* a_pIContex */
  212. )
  213. {
  214. VARIANT vHostName;
  215. HRESULT hRes = 0;
  216. TRACE_CRIT("->%!FUNC!");
  217. try {
  218. VariantInit( &vHostName );
  219. //get the host name value
  220. hRes = a_pInstance->Get( _bstr_t( MOF_NODESETTING::pProperties[MOF_NODESETTING::NAME] ),
  221. 0,
  222. &vHostName,
  223. NULL,
  224. NULL );
  225. if( FAILED( hRes ) )
  226. {
  227. TRACE_CRIT("%!FUNC! Error trying to retreive %ls property, IWbemClassObject::Get failed with error : 0x%x, Throwing com_error exception",MOF_NODESETTING::pProperties[MOF_NODESETTING::NAME], hRes);
  228. throw _com_error( hRes );
  229. }
  230. wstring wstrHostName( vHostName.bstrVal );
  231. DWORD dwClustIpOrIndex = ExtractClusterIP( wstrHostName );
  232. DWORD dwHostID = ExtractHostID( wstrHostName );
  233. CWlbsClusterWrapper* pCluster = g_pWlbsControl->GetClusterFromIpOrIndex(dwClustIpOrIndex);
  234. if( pCluster == NULL || (DWORD)-1 == dwHostID || pCluster->GetHostID() != dwHostID)
  235. {
  236. TRACE_CRIT("%!FUNC! (GetClusterFromIpOrIndex (Host Name : %ls) or ExtractHostID (Host Id : %d)) failed or Host Id does NOT match, Throwing com_error WBEM_E_NOT_FOUND exception",wstrHostName.data(), dwHostID);
  237. throw _com_error( WBEM_E_NOT_FOUND );
  238. }
  239. UpdateConfiguration(pCluster, a_pInstance );
  240. // CLD: Need to check return code for error
  241. if (S_OK != VariantClear( &vHostName ))
  242. {
  243. TRACE_CRIT("%!FUNC! VariantClear() failed, Throwing WBEM_E_FAILED exception");
  244. throw _com_error( WBEM_E_FAILED );
  245. }
  246. m_pResponseHandler->SetStatus( 0, WBEM_S_NO_ERROR, NULL, NULL );
  247. hRes = WBEM_S_NO_ERROR;
  248. }
  249. catch(CErrorWlbsControl Err) {
  250. IWbemClassObject* pWbemExtStat = NULL;
  251. TRACE_CRIT("%!FUNC! Caught a Wlbs exception : 0x%x", Err.Error());
  252. CreateExtendedStatus( m_pNameSpace,
  253. &pWbemExtStat,
  254. Err.Error(),
  255. (PWCHAR)(Err.Description()) );
  256. m_pResponseHandler->SetStatus(0, WBEM_E_FAILED, NULL, pWbemExtStat);
  257. if( pWbemExtStat )
  258. pWbemExtStat->Release();
  259. // CLD: Need to check return code for error
  260. // No throw here since we are already throwing an exception.
  261. VariantClear( &vHostName );
  262. //do not return WBEM_E_FAILED, this causes a race condition
  263. hRes = WBEM_S_NO_ERROR;
  264. }
  265. catch(_com_error HResErr ) {
  266. TRACE_CRIT("%!FUNC! Caught a com_error exception : 0x%x", HResErr.Error());
  267. m_pResponseHandler->SetStatus(0, HResErr.Error(), NULL, NULL);
  268. // CLD: Need to check return code for error
  269. // No throw here since we are already throwing an exception.
  270. VariantClear( &vHostName );
  271. hRes = HResErr.Error();
  272. }
  273. catch (...) {
  274. TRACE_CRIT("%!FUNC! Caught an exception");
  275. // CLD: Need to check return code for error
  276. // No throw here since we are already throwing an exception.
  277. VariantClear( &vHostName );
  278. TRACE_CRIT("%!FUNC! Rethrowing exception");
  279. TRACE_CRIT("<-%!FUNC!");
  280. throw;
  281. }
  282. TRACE_CRIT("<-%!FUNC! return 0x%x", hRes);
  283. return hRes;
  284. }
  285. ////////////////////////////////////////////////////////////////////////////////
  286. //
  287. // CWLBS_NodeSetting::ExecMethod
  288. //
  289. // Purpose:
  290. //
  291. ////////////////////////////////////////////////////////////////////////////////
  292. HRESULT CWLBS_NodeSetting::ExecMethod
  293. (
  294. const ParsedObjectPath* a_pParsedPath ,
  295. const BSTR& a_strMethodName,
  296. long /* a_lFlags */,
  297. IWbemContext* /* a_pIContex */,
  298. IWbemClassObject* a_pIInParams
  299. )
  300. {
  301. IWbemClassObject* pOutputInstance = NULL;
  302. IWbemClassObject* pWbemPortRule = NULL;
  303. HRESULT hRes = 0;
  304. CNodeConfiguration NodeConfig;
  305. VARIANT vValue ;
  306. TRACE_CRIT("->%!FUNC!");
  307. try {
  308. VariantInit( &vValue );
  309. VARIANT vHostName ;
  310. VariantInit( &vHostName );
  311. if (a_pParsedPath->m_paKeys == NULL)
  312. {
  313. //
  314. // No name specified
  315. //
  316. TRACE_CRIT("%!FUNC! Key (Clsuter IP) is not specified, Throwing com_error WBEM_E_INVALID_PARAMETER exception");
  317. throw _com_error( WBEM_E_INVALID_PARAMETER );
  318. }
  319. wstring wstrHostName = (*a_pParsedPath->m_paKeys)->m_vValue.bstrVal;
  320. DWORD dwClustIpOrIndex = ExtractClusterIP( wstrHostName );
  321. DWORD dwHostID = ExtractHostID( wstrHostName );
  322. CWlbsClusterWrapper* pCluster = g_pWlbsControl->GetClusterFromIpOrIndex(dwClustIpOrIndex);
  323. if( pCluster == NULL || (DWORD)-1 == dwHostID || pCluster->GetHostID() != dwHostID)
  324. {
  325. TRACE_CRIT("%!FUNC! (GetClusterFromIpOrIndex (Host Name : %ls) or ExtractHostID (Host Id : %d)) failed or Host Id does NOT match, Throwing com_error WBEM_E_NOT_FOUND exception",wstrHostName.data(), dwHostID);
  326. throw _com_error( WBEM_E_NOT_FOUND );
  327. }
  328. //determine the method being executed
  329. if( _wcsicmp( a_strMethodName, MOF_NODESETTING::pMethods[MOF_NODESETTING::GETPORT] ) == 0 ) {
  330. WLBS_PORT_RULE PortRule;
  331. // The GetPort method does NOT take vip as a parameter, so, if there is any port rule
  332. // that is specific to a vip (other than the "all vip"), we fail this method.
  333. // The "EffectiveVersion" registry value is checked for a value of CVY_VERSION_FULL to
  334. // see of there is any port rule that is specific to a vip
  335. pCluster->GetNodeConfig(NodeConfig);
  336. if(NodeConfig.dwEffectiveVersion == CVY_VERSION_FULL)
  337. {
  338. TRACE_CRIT("%!FUNC! %ls method called on a cluster that has per-vip port rules (Must call the \"Ex\" equivalent instead). Throwing com_error WBEM_E_INVALID_OPERATION exception", a_strMethodName);
  339. throw _com_error( WBEM_E_INVALID_OPERATION );
  340. }
  341. //get the output object instance
  342. GetMethodOutputInstance( MOF_NODESETTING::szName,
  343. a_strMethodName,
  344. &pOutputInstance);
  345. //get the Port
  346. hRes = a_pIInParams->Get
  347. (
  348. _bstr_t( MOF_PARAM::PORT_NUMBER ),
  349. 0,
  350. &vValue,
  351. NULL,
  352. NULL
  353. );
  354. if( vValue.vt != VT_I4 )
  355. {
  356. TRACE_CRIT("%!FUNC! Argument %ls for method %ls is NOT of type \"signed long\", Throwing com_error WBEM_E_INVALID_PARAMETER exception", MOF_PARAM::PORT_NUMBER, a_strMethodName);
  357. throw _com_error ( WBEM_E_INVALID_PARAMETER );
  358. }
  359. // Get the "All Vip" port rule for this vip
  360. pCluster->GetPortRule(IpAddressFromAbcdWsz(CVY_DEF_ALL_VIP), static_cast<DWORD>( vValue.lVal ), &PortRule );
  361. //create the appropriate port rule class
  362. switch( PortRule.mode ) {
  363. case WLBS_SINGLE:
  364. SpawnInstance( MOF_CLASSES::g_szMOFClassList[MOF_CLASSES::PRFAIL], &pWbemPortRule );
  365. CWLBS_PortRule::FillWbemInstance(MOF_CLASSES::g_szMOFClassList[MOF_CLASSES::PRFAIL], pCluster, pWbemPortRule, &PortRule );
  366. break;
  367. case WLBS_MULTI:
  368. SpawnInstance( MOF_CLASSES::g_szMOFClassList[MOF_CLASSES::PRLOADB], &pWbemPortRule );
  369. CWLBS_PortRule::FillWbemInstance(MOF_CLASSES::g_szMOFClassList[MOF_CLASSES::PRLOADB], pCluster, pWbemPortRule, &PortRule );
  370. break;
  371. case WLBS_NEVER:
  372. SpawnInstance( MOF_CLASSES::g_szMOFClassList[MOF_CLASSES::PRDIS], &pWbemPortRule );
  373. CWLBS_PortRule::FillWbemInstance(MOF_CLASSES::g_szMOFClassList[MOF_CLASSES::PRDIS], pCluster, pWbemPortRule, &PortRule );
  374. break;
  375. }
  376. vValue.vt = VT_UNKNOWN;
  377. vValue.punkVal = pWbemPortRule;
  378. pWbemPortRule->AddRef();
  379. hRes = pOutputInstance->Put( _bstr_t(MOF_PARAM::PORTRULE),
  380. 0,
  381. &vValue,
  382. 0 );
  383. // CLD: Need to check return code for error
  384. if (S_OK != VariantClear( &vValue ))
  385. {
  386. TRACE_CRIT("%!FUNC! VariantClear() failed, Throwing WBEM_E_FAILED exception");
  387. throw _com_error( WBEM_E_FAILED );
  388. }
  389. if( FAILED( hRes ) )
  390. {
  391. TRACE_CRIT("%!FUNC! IWbemClassObject::Put() returned error : 0x%x, Throwing com_error exception", hRes);
  392. throw _com_error( hRes );
  393. }
  394. if( pOutputInstance ) {
  395. hRes = m_pResponseHandler->Indicate(1, &pOutputInstance);
  396. if( FAILED( hRes ) )
  397. {
  398. TRACE_CRIT("%!FUNC! IWbemObjectSink::Indicate() returned error : 0x%x, Throwing com_error exception", hRes);
  399. throw _com_error( hRes );
  400. }
  401. }
  402. } else if( _wcsicmp( a_strMethodName, MOF_NODESETTING::pMethods[MOF_NODESETTING::GETPORT_EX] ) == 0 ) {
  403. WLBS_PORT_RULE PortRule;
  404. DWORD dwPort, dwVip;
  405. //get the output object instance
  406. GetMethodOutputInstance( MOF_NODESETTING::szName,
  407. a_strMethodName,
  408. &pOutputInstance);
  409. //get the vip
  410. hRes = a_pIInParams->Get
  411. (
  412. _bstr_t( MOF_PARAM::VIP ),
  413. 0,
  414. &vValue,
  415. NULL,
  416. NULL
  417. );
  418. if( vValue.vt != VT_BSTR )
  419. {
  420. TRACE_CRIT("%!FUNC! Argument %ls for method %ls is NOT of type \"BString\", Throwing com_error WBEM_E_INVALID_PARAMETER exception", MOF_PARAM::VIP, a_strMethodName);
  421. throw _com_error ( WBEM_E_INVALID_PARAMETER );
  422. }
  423. // If the VIP is "All Vip", then, fill in the numeric value
  424. // directly from the macro, else use the conversion function.
  425. // This is 'cos INADDR_NONE, the return value of inet_addr
  426. // function (called by IpAddressFromAbcdWsz) in the failure
  427. // case, is equivalent to the numeric value of CVY_DEF_ALL_VIP
  428. if (_wcsicmp(vValue.bstrVal, CVY_DEF_ALL_VIP) == 0) {
  429. dwVip = CVY_ALL_VIP_NUMERIC_VALUE;
  430. }
  431. else {
  432. dwVip = IpAddressFromAbcdWsz( vValue.bstrVal );
  433. if (dwVip == INADDR_NONE)
  434. {
  435. TRACE_CRIT("%!FUNC! Invalid value (%ls) passed for %ls. Throwing com_error WBEM_E_INVALID_PARAMETER exception", vValue.bstrVal, MOF_PARAM::VIP);
  436. throw _com_error ( WBEM_E_INVALID_PARAMETER );
  437. }
  438. }
  439. //get the Port
  440. hRes = a_pIInParams->Get
  441. (
  442. _bstr_t( MOF_PARAM::PORT_NUMBER ),
  443. 0,
  444. &vValue,
  445. NULL,
  446. NULL
  447. );
  448. if( vValue.vt != VT_I4 )
  449. {
  450. TRACE_CRIT("%!FUNC! Argument %ls for method %ls is NOT of type \"signed long\", Throwing com_error WBEM_E_INVALID_PARAMETER exception", MOF_PARAM::PORT_NUMBER, a_strMethodName);
  451. throw _com_error ( WBEM_E_INVALID_PARAMETER );
  452. }
  453. dwPort = vValue.lVal;
  454. // Get the port rule for this vip & this port
  455. pCluster->GetPortRule(dwVip, dwPort, &PortRule );
  456. //create the vip port rule class
  457. SpawnInstance( MOF_CLASSES::g_szMOFClassList[MOF_CLASSES::PORTRULE_EX], &pWbemPortRule );
  458. CWLBS_PortRule::FillWbemInstance(MOF_CLASSES::g_szMOFClassList[MOF_CLASSES::PORTRULE_EX], pCluster, pWbemPortRule, &PortRule );
  459. vValue.vt = VT_UNKNOWN;
  460. vValue.punkVal = pWbemPortRule;
  461. pWbemPortRule->AddRef();
  462. hRes = pOutputInstance->Put( _bstr_t(MOF_PARAM::PORTRULE),
  463. 0,
  464. &vValue,
  465. 0 );
  466. VariantClear( &vValue );
  467. if( FAILED( hRes ) )
  468. {
  469. TRACE_CRIT("%!FUNC! VariantClear() failed, Throwing WBEM_E_FAILED exception");
  470. throw _com_error( hRes );
  471. }
  472. if( pOutputInstance ) {
  473. hRes = m_pResponseHandler->Indicate(1, &pOutputInstance);
  474. if( FAILED( hRes ) )
  475. {
  476. TRACE_CRIT("%!FUNC! IWbemObjectSink::Indicate() returned error : 0x%x, Throwing com_error exception", hRes);
  477. throw _com_error( hRes );
  478. }
  479. }
  480. } else if( _wcsicmp( a_strMethodName, MOF_NODESETTING::pMethods[MOF_NODESETTING::LDSETT] ) == 0 ) {
  481. //
  482. // NOTE:
  483. // NLB, if needed, calls the PnP apis to disable and re-enable the network adapter, for the new NLB settings to take
  484. // effect. Since this operation involves unloading and loading of the device driver, PnP apis, attempt to enable
  485. // the "SeLoadDriverPrivilege" privilege in the impersonation access token. Enabling a privilege is successful only
  486. // when the privilege is present, in the first place to be enabled. When the wmi client and wmi provider are in the
  487. // same machine, it was observed that the "SeLoadDriverPrivilege" privilege was NOT event present in the impersonation
  488. // access token of the server. This is because, only the enabled privileges of the client are passed along to the server.
  489. // So, we now require that the client enable the "SeLoadDriverPrivilege" privilege in its access token before calling
  490. // this method. The following call to Check_Load_Unload_Driver_Privilege() checks if "SeLoadDriverPrivilege" privilege
  491. // is enabled in the impersonation access token. Although the PnP apis only require that this privilege be present,
  492. // we have decided to elevate the requirement to this privilege being present AND enabled. This is because, if the
  493. // privilege is NOT enabled, the operation to enable it may or may not succeed depending on the client's credentials.
  494. // --KarthicN, May 6, 2002.
  495. //
  496. if(!Check_Load_Unload_Driver_Privilege())
  497. {
  498. TRACE_CRIT("%!FUNC! Check_Load_Unload_Driver_Privilege() failed, Throwing WBEM_E_ACCESS_DENIED exception");
  499. throw _com_error( WBEM_E_ACCESS_DENIED );
  500. }
  501. DWORD dwReturnValue = pCluster->Commit(g_pWlbsControl);
  502. vValue.vt = VT_I4;
  503. vValue.lVal = static_cast<long>(dwReturnValue);
  504. //get the output object instance
  505. GetMethodOutputInstance( MOF_NODESETTING::szName,
  506. a_strMethodName,
  507. &pOutputInstance);
  508. hRes = pOutputInstance->Put(_bstr_t(L"ReturnValue"), 0, &vValue, 0);
  509. // CLD: Need to check return code for error
  510. if (S_OK != VariantClear( &vValue ))
  511. {
  512. TRACE_CRIT("%!FUNC! VariantClear() failed, Throwing WBEM_E_FAILED exception");
  513. throw _com_error( WBEM_E_FAILED );
  514. }
  515. if( FAILED( hRes ) )
  516. {
  517. TRACE_CRIT("%!FUNC! IWbemClassObject::Put() returned error : 0x%x, Throwing com_error exception", hRes);
  518. throw _com_error( hRes );
  519. }
  520. if( pOutputInstance ) {
  521. hRes = m_pResponseHandler->Indicate(1, &pOutputInstance);
  522. if( FAILED( hRes ) )
  523. {
  524. TRACE_CRIT("%!FUNC! IWbemObjectSink::Indicate() returned error : 0x%x, Throwing com_error exception", hRes);
  525. throw _com_error( hRes );
  526. }
  527. }
  528. } else if( _wcsicmp( a_strMethodName, MOF_NODESETTING::pMethods[MOF_NODESETTING::SETDEF] ) == 0 ) {
  529. pCluster->SetNodeDefaults();
  530. } else {
  531. TRACE_CRIT("%!FUNC! %ls method NOT implemented, Throwing WBEM_E_METHOD_NOT_IMPLEMENTED exception",a_strMethodName);
  532. throw _com_error( WBEM_E_METHOD_NOT_IMPLEMENTED );
  533. }
  534. //send the results back to WinMgMt
  535. //set the return value
  536. //release resources
  537. // CLD: Need to check return code for error
  538. if (S_OK != VariantClear( &vValue ))
  539. {
  540. TRACE_CRIT("%!FUNC! VariantClear() failed, Throwing WBEM_E_FAILED exception");
  541. throw _com_error( WBEM_E_FAILED );
  542. }
  543. if( pOutputInstance ) {
  544. pOutputInstance->Release();
  545. pOutputInstance = NULL;
  546. }
  547. m_pResponseHandler->SetStatus( 0, WBEM_S_NO_ERROR, NULL, NULL );
  548. hRes = WBEM_S_NO_ERROR;
  549. }
  550. catch(CErrorWlbsControl Err) {
  551. IWbemClassObject* pWbemExtStat = NULL;
  552. TRACE_CRIT("%!FUNC! Caught a Wlbs exception : 0x%x", Err.Error());
  553. CreateExtendedStatus( m_pNameSpace,
  554. &pWbemExtStat,
  555. Err.Error(),
  556. (PWCHAR)(Err.Description()) );
  557. m_pResponseHandler->SetStatus(0, WBEM_E_FAILED, NULL, pWbemExtStat);
  558. if( pWbemExtStat )
  559. pWbemExtStat->Release();
  560. // CLD: Need to check return code for error
  561. // No throw here since we are already throwing an exception.
  562. VariantClear( &vValue );
  563. if( pOutputInstance )
  564. pOutputInstance->Release();
  565. //do not return WBEM_E_FAILED, this causes a race condition
  566. hRes = WBEM_S_NO_ERROR;
  567. }
  568. catch(_com_error HResErr ) {
  569. TRACE_CRIT("%!FUNC! Caught a com_error exception : 0x%x", HResErr.Error());
  570. m_pResponseHandler->SetStatus(0, HResErr.Error(), NULL, NULL);
  571. // CLD: Need to check return code for error
  572. // No throw here since we are already throwing an exception.
  573. VariantClear( &vValue );
  574. if( pOutputInstance )
  575. pOutputInstance->Release();
  576. hRes = HResErr.Error();
  577. }
  578. catch ( ... ) {
  579. TRACE_CRIT("%!FUNC! Caught an exception");
  580. // CLD: Need to check return code for error
  581. // No throw here since we are already throwing an exception.
  582. VariantClear( &vValue );
  583. if( pOutputInstance )
  584. pOutputInstance->Release();
  585. TRACE_CRIT("%!FUNC! Rethrowing exception");
  586. TRACE_CRIT("<-%!FUNC!");
  587. throw;
  588. }
  589. TRACE_CRIT("<-%!FUNC! return 0x%x", hRes);
  590. return hRes;
  591. }
  592. ////////////////////////////////////////////////////////////////////////////////
  593. //
  594. // CWLBS_NodeSetting::FillWbemInstance
  595. //
  596. // Purpose: This function copies all of the data from a node configuration
  597. // structure to a WBEM instance.
  598. //
  599. ////////////////////////////////////////////////////////////////////////////////
  600. void CWLBS_NodeSetting::FillWbemInstance(CWlbsClusterWrapper* pCluster,
  601. IWbemClassObject* a_pWbemInstance )
  602. {
  603. namespace NODE = MOF_NODESETTING;
  604. TRACE_VERB("->%!FUNC!");
  605. ASSERT( a_pWbemInstance );
  606. CNodeConfiguration NodeConfig;
  607. pCluster->GetNodeConfig( NodeConfig );
  608. wstring wstrHostName;
  609. ConstructHostName( wstrHostName, pCluster->GetClusterIpOrIndex(g_pWlbsControl),
  610. pCluster->GetHostID() );
  611. //NAME
  612. HRESULT hRes = a_pWbemInstance->Put
  613. (
  614. _bstr_t( NODE::pProperties[NODE::NAME] ) ,
  615. 0 ,
  616. &_variant_t(wstrHostName.c_str()),
  617. NULL
  618. );
  619. if( FAILED( hRes ) )
  620. throw _com_error( hRes );
  621. //DEDIPADDRESS
  622. hRes = a_pWbemInstance->Put
  623. (
  624. _bstr_t( NODE::pProperties[NODE::DEDIPADDRESS] ),
  625. 0 ,
  626. &_variant_t(NodeConfig.szDedicatedIPAddress.c_str()),
  627. NULL
  628. );
  629. if( FAILED( hRes ) )
  630. throw _com_error( hRes );
  631. //DEDNETMASK
  632. hRes = a_pWbemInstance->Put
  633. (
  634. _bstr_t( NODE::pProperties[NODE::DEDNETMASK] ),
  635. 0 ,
  636. &_variant_t(NodeConfig.szDedicatedNetworkMask.c_str()),
  637. NULL
  638. );
  639. if( FAILED( hRes ) )
  640. throw _com_error( hRes );
  641. //NUMRULES
  642. hRes = a_pWbemInstance->Put
  643. (
  644. _bstr_t( NODE::pProperties[NODE::NUMRULES] ),
  645. 0 ,
  646. &_variant_t((long)NodeConfig.dwNumberOfRules),
  647. NULL
  648. );
  649. if( FAILED( hRes ) )
  650. throw _com_error( hRes );
  651. //HOSTPRI
  652. hRes = a_pWbemInstance->Put
  653. (
  654. _bstr_t( NODE::pProperties[NODE::HOSTPRI] ),
  655. 0 ,
  656. &_variant_t((long)NodeConfig.dwHostPriority),
  657. NULL
  658. );
  659. if( FAILED( hRes ) )
  660. throw _com_error( hRes );
  661. //MSGPERIOD
  662. hRes = a_pWbemInstance->Put
  663. (
  664. _bstr_t( NODE::pProperties[NODE::MSGPERIOD] ),
  665. 0 ,
  666. &_variant_t((long)NodeConfig.dwAliveMsgPeriod),
  667. NULL
  668. );
  669. if( FAILED( hRes ) )
  670. throw _com_error( hRes );
  671. //MSGTOLER
  672. hRes = a_pWbemInstance->Put
  673. (
  674. _bstr_t( NODE::pProperties[NODE::MSGTOLER] ),
  675. 0 ,
  676. &_variant_t((long)NodeConfig.dwAliveMsgTolerance),
  677. NULL
  678. );
  679. if( FAILED( hRes ) )
  680. throw _com_error( hRes );
  681. //CLUSMODEONSTART
  682. hRes = a_pWbemInstance->Put
  683. (
  684. _bstr_t( NODE::pProperties[NODE::CLUSMODEONSTART] ),
  685. 0 ,
  686. &_variant_t(NodeConfig.bClusterModeOnStart),
  687. NULL
  688. );
  689. if( FAILED( hRes ) )
  690. throw _com_error( hRes );
  691. //CLUSMODESUSPENDONSTART
  692. hRes = a_pWbemInstance->Put
  693. (
  694. _bstr_t( NODE::pProperties[NODE::CLUSMODESUSPONSTART] ),
  695. 0 ,
  696. &_variant_t(NodeConfig.bClusterModeSuspendOnStart),
  697. NULL
  698. );
  699. if( FAILED( hRes ) )
  700. throw _com_error( hRes );
  701. //PERSISTSUSPENDONREBOOT
  702. hRes = a_pWbemInstance->Put
  703. (
  704. _bstr_t( NODE::pProperties[NODE::PERSISTSUSPONREBOOT] ),
  705. 0 ,
  706. &_variant_t(NodeConfig.bPersistSuspendOnReboot),
  707. NULL
  708. );
  709. if( FAILED( hRes ) )
  710. throw _com_error( hRes );
  711. //NBTENABLE
  712. // hRes = a_pWbemInstance->Put
  713. // (
  714. // _bstr_t( NODE::pProperties[NODE::NBTENABLE] ),
  715. // 0 ,
  716. // &( _variant_t( NodeConfig.bNBTSupportEnable ) ) ,
  717. // NULL
  718. // );
  719. if( FAILED( hRes ) )
  720. throw _com_error( hRes );
  721. //REMOTEUDPPORT
  722. hRes = a_pWbemInstance->Put
  723. (
  724. _bstr_t( NODE::pProperties[NODE::REMOTEUDPPORT] ),
  725. 0 ,
  726. &_variant_t((long)NodeConfig.dwRemoteControlUDPPort),
  727. NULL
  728. );
  729. if( FAILED( hRes ) )
  730. throw _com_error( hRes );
  731. //MASKSRCMAC
  732. hRes = a_pWbemInstance->Put
  733. (
  734. _bstr_t( NODE::pProperties[NODE::MASKSRCMAC] ),
  735. 0 ,
  736. &_variant_t(NodeConfig.bMaskSourceMAC),
  737. NULL
  738. );
  739. if( FAILED( hRes ) )
  740. throw _com_error( hRes );
  741. //DESCPERALLOC
  742. hRes = a_pWbemInstance->Put
  743. (
  744. _bstr_t( NODE::pProperties[NODE::DESCPERALLOC] ),
  745. 0 ,
  746. &_variant_t((long)NodeConfig.dwDescriptorsPerAlloc),
  747. NULL
  748. );
  749. if( FAILED( hRes ) )
  750. throw _com_error( hRes );
  751. //MAXDESCALLOCS
  752. hRes = a_pWbemInstance->Put
  753. (
  754. _bstr_t( NODE::pProperties[NODE::MAXDESCALLOCS] ),
  755. 0 ,
  756. &_variant_t((long)NodeConfig.dwMaxDescriptorAllocs),
  757. NULL
  758. );
  759. if( FAILED( hRes ) )
  760. throw _com_error( hRes );
  761. //FILTERICMP
  762. hRes = a_pWbemInstance->Put
  763. (
  764. _bstr_t( NODE::pProperties[NODE::FILTERICMP] ),
  765. 0 ,
  766. &_variant_t((long)NodeConfig.dwFilterIcmp),
  767. NULL
  768. );
  769. if( FAILED( hRes ) )
  770. throw _com_error( hRes );
  771. //TCPDESCRIPTORTIMEOUT
  772. hRes = a_pWbemInstance->Put
  773. (
  774. _bstr_t( NODE::pProperties[NODE::TCPDESCRIPTORTIMEOUT] ),
  775. 0 ,
  776. &_variant_t((long)NodeConfig.dwTcpDescriptorTimeout),
  777. NULL
  778. );
  779. if( FAILED( hRes ) )
  780. throw _com_error( hRes );
  781. //IPSECDESCRIPTORTIMEOUT
  782. hRes = a_pWbemInstance->Put
  783. (
  784. _bstr_t( NODE::pProperties[NODE::IPSECDESCRIPTORTIMEOUT] ),
  785. 0 ,
  786. &_variant_t((long)NodeConfig.dwIpSecDescriptorTimeout),
  787. NULL
  788. );
  789. if( FAILED( hRes ) )
  790. throw _com_error( hRes );
  791. //NUMACTIONS
  792. hRes = a_pWbemInstance->Put
  793. (
  794. _bstr_t( NODE::pProperties[NODE::NUMACTIONS] ),
  795. 0 ,
  796. &_variant_t((long)NodeConfig.dwNumActions),
  797. NULL
  798. );
  799. if( FAILED( hRes ) )
  800. throw _com_error( hRes );
  801. //NUMPACKETS
  802. hRes = a_pWbemInstance->Put
  803. (
  804. _bstr_t( NODE::pProperties[NODE::NUMPACKETS] ),
  805. 0 ,
  806. &_variant_t((long)NodeConfig.dwNumPackets),
  807. NULL
  808. );
  809. if( FAILED( hRes ) )
  810. throw _com_error( hRes );
  811. //NUMALIVEMSGS
  812. hRes = a_pWbemInstance->Put
  813. (
  814. _bstr_t( NODE::pProperties[NODE::NUMALIVEMSGS] ),
  815. 0 ,
  816. &_variant_t((long)NodeConfig.dwNumAliveMsgs),
  817. NULL
  818. );
  819. if( FAILED( hRes ) )
  820. throw _com_error( hRes );
  821. //ADAPTERGUID
  822. GUID AdapterGuid = pCluster->GetAdapterGuid();
  823. WCHAR szAdapterGuid[128];
  824. StringFromGUID2(AdapterGuid, szAdapterGuid,
  825. sizeof(szAdapterGuid)/sizeof(szAdapterGuid[0]) );
  826. hRes = a_pWbemInstance->Put
  827. (
  828. _bstr_t( NODE::pProperties[NODE::ADAPTERGUID] ),
  829. 0 ,
  830. &_variant_t(szAdapterGuid),
  831. NULL
  832. );
  833. if( FAILED( hRes ) )
  834. throw _com_error( hRes );
  835. TRACE_VERB("<-%!FUNC!");
  836. }
  837. ////////////////////////////////////////////////////////////////////////////////
  838. //
  839. // CWLBS_NodeSetting::UpdateConfiguration
  840. //
  841. // Purpose: This function updates the configuration data for a member node or a
  842. // potential WLBS cluster node.
  843. //
  844. ////////////////////////////////////////////////////////////////////////////////
  845. void CWLBS_NodeSetting::UpdateConfiguration
  846. (
  847. CWlbsClusterWrapper* pCluster,
  848. IWbemClassObject* a_pInstance
  849. )
  850. {
  851. namespace NODE = MOF_NODESETTING;
  852. CNodeConfiguration NewConfiguration;
  853. CNodeConfiguration OldConfiguration;
  854. TRACE_VERB("->%!FUNC!");
  855. pCluster->GetNodeConfig( OldConfiguration );
  856. //Dedicated IP
  857. UpdateConfigProp
  858. (
  859. NewConfiguration.szDedicatedIPAddress,
  860. OldConfiguration.szDedicatedIPAddress,
  861. NODE::pProperties[NODE::DEDIPADDRESS],
  862. a_pInstance
  863. );
  864. //Dedicate Network Mask
  865. UpdateConfigProp
  866. (
  867. NewConfiguration.szDedicatedNetworkMask,
  868. OldConfiguration.szDedicatedNetworkMask,
  869. NODE::pProperties[NODE::DEDNETMASK],
  870. a_pInstance
  871. );
  872. //HostPriority
  873. UpdateConfigProp
  874. (
  875. NewConfiguration.dwHostPriority,
  876. OldConfiguration.dwHostPriority,
  877. NODE::pProperties[NODE::HOSTPRI],
  878. a_pInstance
  879. );
  880. //AliveMsgPeriod
  881. UpdateConfigProp
  882. (
  883. NewConfiguration.dwAliveMsgPeriod,
  884. OldConfiguration.dwAliveMsgPeriod,
  885. NODE::pProperties[NODE::MSGPERIOD],
  886. a_pInstance
  887. );
  888. //AliveMsgTolerance
  889. UpdateConfigProp
  890. (
  891. NewConfiguration.dwAliveMsgTolerance,
  892. OldConfiguration.dwAliveMsgTolerance,
  893. NODE::pProperties[NODE::MSGTOLER],
  894. a_pInstance
  895. );
  896. //ClusterModeOnStart
  897. UpdateConfigProp
  898. (
  899. NewConfiguration.bClusterModeOnStart,
  900. OldConfiguration.bClusterModeOnStart,
  901. NODE::pProperties[NODE::CLUSMODEONSTART],
  902. a_pInstance
  903. );
  904. //ClusterModeSuspendOnStart
  905. UpdateConfigProp
  906. (
  907. NewConfiguration.bClusterModeSuspendOnStart,
  908. OldConfiguration.bClusterModeSuspendOnStart,
  909. NODE::pProperties[NODE::CLUSMODESUSPONSTART],
  910. a_pInstance
  911. );
  912. //PersistSuspendOnReboot
  913. UpdateConfigProp
  914. (
  915. NewConfiguration.bPersistSuspendOnReboot,
  916. OldConfiguration.bPersistSuspendOnReboot,
  917. NODE::pProperties[NODE::PERSISTSUSPONREBOOT],
  918. a_pInstance
  919. );
  920. //NBTSupportEnable
  921. // UpdateConfigProp
  922. // (
  923. // NewConfiguration.bNBTSupportEnable,
  924. // OldConfiguration.bNBTSupportEnable,
  925. // NODE::pProperties[NODE::NBTENABLE],
  926. // a_pInstance
  927. // );
  928. //RemoteControlUDPPort
  929. UpdateConfigProp
  930. (
  931. NewConfiguration.dwRemoteControlUDPPort,
  932. OldConfiguration.dwRemoteControlUDPPort,
  933. NODE::pProperties[NODE::REMOTEUDPPORT],
  934. a_pInstance
  935. );
  936. //MaskSourceMAC
  937. UpdateConfigProp
  938. (
  939. NewConfiguration.bMaskSourceMAC,
  940. OldConfiguration.bMaskSourceMAC,
  941. NODE::pProperties[NODE::MASKSRCMAC],
  942. a_pInstance
  943. );
  944. //DescriptorsPerAlloc
  945. UpdateConfigProp
  946. (
  947. NewConfiguration.dwDescriptorsPerAlloc,
  948. OldConfiguration.dwDescriptorsPerAlloc,
  949. NODE::pProperties[NODE::DESCPERALLOC],
  950. a_pInstance
  951. );
  952. //MaxDescriptorAllocs
  953. UpdateConfigProp
  954. (
  955. NewConfiguration.dwMaxDescriptorAllocs,
  956. OldConfiguration.dwMaxDescriptorAllocs,
  957. NODE::pProperties[NODE::MAXDESCALLOCS],
  958. a_pInstance
  959. );
  960. //FilterIcmp
  961. UpdateConfigProp
  962. (
  963. NewConfiguration.dwFilterIcmp,
  964. OldConfiguration.dwFilterIcmp,
  965. NODE::pProperties[NODE::FILTERICMP],
  966. a_pInstance
  967. );
  968. //TcpDescriptorTimeout
  969. UpdateConfigProp
  970. (
  971. NewConfiguration.dwTcpDescriptorTimeout,
  972. OldConfiguration.dwTcpDescriptorTimeout,
  973. NODE::pProperties[NODE::TCPDESCRIPTORTIMEOUT],
  974. a_pInstance
  975. );
  976. //IpSecDescriptorTimeout
  977. UpdateConfigProp
  978. (
  979. NewConfiguration.dwIpSecDescriptorTimeout,
  980. OldConfiguration.dwIpSecDescriptorTimeout,
  981. NODE::pProperties[NODE::IPSECDESCRIPTORTIMEOUT],
  982. a_pInstance
  983. );
  984. //NumActions
  985. UpdateConfigProp
  986. (
  987. NewConfiguration.dwNumActions,
  988. OldConfiguration.dwNumActions,
  989. NODE::pProperties[NODE::NUMACTIONS],
  990. a_pInstance
  991. );
  992. //NumPackets
  993. UpdateConfigProp
  994. (
  995. NewConfiguration.dwNumPackets,
  996. OldConfiguration.dwNumPackets,
  997. NODE::pProperties[NODE::NUMPACKETS],
  998. a_pInstance
  999. );
  1000. //NumAliveMsgs
  1001. UpdateConfigProp
  1002. (
  1003. NewConfiguration.dwNumAliveMsgs,
  1004. OldConfiguration.dwNumAliveMsgs,
  1005. NODE::pProperties[NODE::NUMALIVEMSGS],
  1006. a_pInstance
  1007. );
  1008. pCluster->PutNodeConfig( NewConfiguration );
  1009. TRACE_VERB("<-%!FUNC!");
  1010. }