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.

213 lines
5.9 KiB

  1. ///////////////////////////////////////////////////////////////////////////////
  2. //
  3. // Copyright (c) Microsoft Corporation
  4. //
  5. // SYNOPSIS
  6. //
  7. // Defines the class MigrateEapConfig.
  8. //
  9. ///////////////////////////////////////////////////////////////////////////////
  10. #include "stdafx.h"
  11. #include "MigrateEapConfig.h"
  12. #include "raseapif.h"
  13. #include "iasapi.h"
  14. const wchar_t MigrateEapConfig::profilesPath[] =
  15. L"Root\0"
  16. L"Microsoft Internet Authentication Service\0"
  17. L"RadiusProfiles\0";
  18. MigrateEapConfig::MigrateEapConfig(
  19. const CGlobalData& newGlobalData
  20. )
  21. : globalData(newGlobalData),
  22. msNPAllowedEapType(L"msNPAllowedEapType"),
  23. msEapConfig(L"msEAPConfiguration")
  24. {
  25. memset(cachedTypes, 0, sizeof(cachedTypes));
  26. long status = eapKey.Open(
  27. HKEY_LOCAL_MACHINE,
  28. RAS_EAP_REGISTRY_LOCATION,
  29. KEY_READ
  30. );
  31. if (status != NO_ERROR)
  32. {
  33. _com_issue_error(HRESULT_FROM_WIN32(status));
  34. }
  35. }
  36. void MigrateEapConfig::Execute()
  37. {
  38. long profilesId;
  39. globalData.m_pObjects->WalkPath(profilesPath, profilesId);
  40. long profileId;
  41. _bstr_t profileName;
  42. HRESULT hr = globalData.m_pObjects->GetObject(
  43. profileName,
  44. profileId,
  45. profilesId
  46. );
  47. for (long index = 1; SUCCEEDED(hr); ++index)
  48. {
  49. ReadProfile(profileId);
  50. WriteProfile(profileId);
  51. hr = globalData.m_pObjects->GetNextObject(
  52. profileName,
  53. profileId,
  54. profilesId,
  55. index
  56. );
  57. }
  58. }
  59. void MigrateEapConfig::ReadProfile(long profileId)
  60. {
  61. // Clear the data from the previous profile.
  62. profileConfig.Clear();
  63. _bstr_t propName, propValue;
  64. long varType;
  65. HRESULT hr = globalData.m_pProperties->GetProperty(
  66. profileId,
  67. propName,
  68. varType,
  69. propValue
  70. );
  71. for (long index = 1; SUCCEEDED(hr); ++index)
  72. {
  73. if (propName == msNPAllowedEapType)
  74. {
  75. if (varType != VT_I4)
  76. {
  77. _com_issue_error(E_UNEXPECTED);
  78. }
  79. AddConfigForType(propValue);
  80. }
  81. hr = globalData.m_pProperties->GetNextProperty(
  82. profileId,
  83. propName,
  84. varType,
  85. propValue,
  86. index
  87. );
  88. }
  89. }
  90. void MigrateEapConfig::WriteProfile(long profileId)
  91. {
  92. if (profileConfig.IsEmpty())
  93. {
  94. return;
  95. }
  96. _variant_t configVariant;
  97. _com_util::CheckError(
  98. profileConfig.Store(configVariant)
  99. );
  100. const SAFEARRAY* sa = V_ARRAY(&configVariant);
  101. VARIANT* begin = static_cast<VARIANT*>(sa->pvData);
  102. VARIANT* end = begin + sa->rgsabound[0].cElements;
  103. for (VARIANT* i = begin; i != end; ++i)
  104. {
  105. _com_util::CheckError(
  106. IASVariantChangeType(i, i, 0, VT_BSTR)
  107. );
  108. globalData.m_pProperties->InsertProperty(
  109. profileId,
  110. msEapConfig,
  111. (VT_UI1 | VT_ARRAY),
  112. _bstr_t(V_BSTR(i))
  113. );
  114. }
  115. }
  116. void MigrateEapConfig::AddConfigForType(const wchar_t* typeName)
  117. {
  118. BYTE typeId = static_cast<BYTE>(_wtol(typeName));
  119. GetGlobalConfig(typeId, typeName);
  120. EapProfile::ConstConfigData data;
  121. globalConfig.Get(typeId, data);
  122. _com_util::CheckError(
  123. profileConfig.Set(typeId, data)
  124. );
  125. }
  126. void MigrateEapConfig::GetGlobalConfig(BYTE typeId, const wchar_t* typeName)
  127. {
  128. // Have we already retrieved the config for this type?
  129. if (cachedTypes[typeId])
  130. {
  131. return;
  132. }
  133. long status;
  134. CRegKey providerKey;
  135. status = providerKey.Open(eapKey, typeName, KEY_READ);
  136. if (status != NO_ERROR)
  137. {
  138. _com_issue_error(HRESULT_FROM_WIN32(status));
  139. }
  140. DWORD dataType;
  141. wchar_t clsidString[40];
  142. DWORD dataLength = sizeof(clsidString);
  143. status = RegQueryValueExW(
  144. providerKey,
  145. RAS_EAP_VALUENAME_CONFIG_CLSID,
  146. 0,
  147. &dataType,
  148. reinterpret_cast<BYTE*>(clsidString),
  149. &dataLength
  150. );
  151. if (status == NO_ERROR)
  152. {
  153. if ((dataType != REG_SZ) || (dataLength < sizeof(wchar_t)))
  154. {
  155. _com_issue_error(HRESULT_FROM_WIN32(ERROR_INVALID_DATA));
  156. }
  157. IEAPProviderConfig2Ptr configObj(clsidString);
  158. if (configObj != 0)
  159. {
  160. EapProfile::ConfigData data;
  161. _com_util::CheckError(
  162. configObj->GetGlobalConfig(
  163. typeId,
  164. &(data.value),
  165. &(data.length)
  166. )
  167. );
  168. _com_util::CheckError(
  169. globalConfig.Set(static_cast<BYTE>(typeId), data)
  170. );
  171. }
  172. }
  173. else if (status != ERROR_FILE_NOT_FOUND)
  174. {
  175. _com_issue_error(HRESULT_FROM_WIN32(status));
  176. }
  177. cachedTypes[typeId] = true;
  178. }