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.

173 lines
5.0 KiB

  1. FROM: nt\base\cluster\mgmt\cluscfg\server\cenumcluscfgipaddresses.cpp
  2. HRESULT
  3. CEnumClusCfgIPAddresses::HrGetAdapterConfiguration(
  4. IWbemClassObject * pNetworkAdapterIn
  5. )
  6. {
  7. TraceFunc( "" );
  8. HRESULT hr = S_OK;
  9. BSTR bstrQuery = NULL;
  10. BSTR bstrWQL = NULL;
  11. VARIANT var;
  12. WCHAR sz[ 256 ];
  13. IEnumWbemClassObject * pConfigurations = NULL;
  14. ULONG ulReturned;
  15. IWbemClassObject * pConfiguration = NULL;
  16. int cFound = 0;
  17. BSTR bstrAdapterName = NULL;
  18. int idx;
  19. VariantInit( &var );
  20. bstrWQL = TraceSysAllocString( L"WQL" );
  21. if ( bstrWQL == NULL )
  22. {
  23. goto OutOfMemory;
  24. } // if:
  25. hr = THR( HrGetWMIProperty( pNetworkAdapterIn, L"DeviceID", VT_BSTR, &var ) );
  26. if ( FAILED( hr ) )
  27. {
  28. goto Cleanup;
  29. } // if:
  30. _snwprintf( sz, ARRAYSIZE( sz ), L"Associators of {Win32_NetworkAdapter.DeviceID='%s'} where AssocClass=Win32_NetworkAdapterSetting", var.bstrVal );
  31. bstrQuery = TraceSysAllocString( sz );
  32. if ( bstrQuery == NULL )
  33. {
  34. goto OutOfMemory;
  35. } // if:
  36. VariantClear( &var );
  37. hr = THR( HrGetWMIProperty( pNetworkAdapterIn, L"NetConnectionID", VT_BSTR, &var ) );
  38. if ( FAILED( hr ) )
  39. {
  40. goto Cleanup;
  41. } // if:
  42. bstrAdapterName = TraceSysAllocString( var.bstrVal );
  43. if ( bstrAdapterName == NULL )
  44. {
  45. goto OutOfMemory;
  46. } // if:
  47. hr = THR( m_pIWbemServices->ExecQuery( bstrWQL, bstrQuery, WBEM_FLAG_FORWARD_ONLY, NULL, &pConfigurations ) );
  48. if ( FAILED( hr ) )
  49. {
  50. STATUS_REPORT_STRING(
  51. TASKID_Major_Find_Devices,
  52. TASKID_Minor_WMI_NetworkAdapterSetting_Qry_Failed,
  53. IDS_ERROR_WMI_NETWORKADAPTERSETTINGS_QRY_FAILED,
  54. bstrAdapterName,
  55. hr
  56. );
  57. goto Cleanup;
  58. } // if:
  59. for ( idx = 0; ; idx++ )
  60. {
  61. hr = pConfigurations->Next( WBEM_INFINITE, 1, &pConfiguration, &ulReturned );
  62. if ( ( hr == S_OK ) && ( ulReturned == 1 ) )
  63. {
  64. //
  65. // KB: 25-AUG-2000 GalenB
  66. //
  67. // WMI only supports one configuration per adapter!
  68. //
  69. Assert( idx < 1 );
  70. VariantClear( &var );
  71. hr = THR( HrGetWMIProperty( pConfiguration, L"IPEnabled", VT_BOOL, &var ) );
  72. if ( FAILED( hr ) )
  73. {
  74. goto Cleanup;
  75. } // if:
  76. //
  77. // If this configuration is not for TCP/IP then skip it.
  78. //
  79. if ( ( var.vt != VT_BOOL ) || ( var.boolVal != VARIANT_TRUE ) )
  80. {
  81. hr = S_FALSE;
  82. STATUS_REPORT_STRING( TASKID_Major_Find_Devices, TASKID_Minor_Non_Tcp_Config, IDS_WARNING__NON_TCP_CONFIG, bstrAdapterName, hr );
  83. continue;
  84. } // if:
  85. hr = STHR( HrSaveIPAddresses( bstrAdapterName, pConfiguration ) );
  86. if ( FAILED( hr ) )
  87. {
  88. goto Cleanup;
  89. } // if:
  90. //
  91. // KB: 24-AUG-2000 GalenB
  92. //
  93. // If any configuration returns S_FALSE then we skip.
  94. //
  95. if ( hr == S_FALSE )
  96. {
  97. pConfiguration->Release();
  98. pConfiguration = NULL;
  99. continue;
  100. } // if:
  101. cFound++;
  102. pConfiguration->Release();
  103. pConfiguration = NULL;
  104. } // if:
  105. else if ( ( hr == S_FALSE ) && ( ulReturned == 0 ) )
  106. {
  107. hr = S_OK;
  108. break;
  109. } // else if:
  110. else
  111. {
  112. STATUS_REPORT_STRING( TASKID_Major_Find_Devices, TASKID_Minor_WQL_Qry_Next_Failed, IDS_ERROR_WQL_QRY_NEXT_FAILED, bstrQuery, hr );
  113. goto Cleanup;
  114. } // else:
  115. } // for:
  116. //
  117. // If we didn't find any valid configurations then we should return S_FALSE
  118. // to tell the caller to ingore that adpater.
  119. //
  120. if ( cFound == 0 )
  121. {
  122. hr = S_FALSE;
  123. STATUS_REPORT_STRING( TASKID_Major_Find_Devices, TASKID_Minor_No_Valid_TCP_Configs, IDS_WARNING_NO_VALID_TCP_CONFIGS, bstrAdapterName, hr );
  124. } // if:
  125. goto Cleanup;
  126. OutOfMemory:
  127. hr = THR( E_OUTOFMEMORY );
  128. STATUS_REPORT( TASKID_Major_Find_Devices, TASKID_Minor_HrGetAdapterConfiguration, IDS_ERROR_OUTOFMEMORY, hr );
  129. Cleanup:
  130. VariantClear( &var );
  131. TraceSysFreeString( bstrQuery );
  132. TraceSysFreeString( bstrWQL );
  133. TraceSysFreeString( bstrAdapterName );
  134. if ( pConfiguration != NULL )
  135. {
  136. pConfiguration->Release();
  137. } // if:
  138. if ( pConfigurations != NULL )
  139. {
  140. pConfigurations->Release();
  141. } // if:
  142. HRETURN( hr );
  143. } //*** CEnumClusCfgIPAddresses::HrGetAdapterConfiguration