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.

329 lines
7.0 KiB

  1. // Copyright (c) 1997-1999 Microsoft Corporation
  2. //
  3. // Post-operation code
  4. //
  5. // 1 Dec 1999 sburns
  6. #include "headers.hxx"
  7. #include "ProgressDialog.hpp"
  8. #include "state.hpp"
  9. #include "shortcut.hpp"
  10. #include "dnssetup.hpp"
  11. #include "resource.h"
  12. void
  13. InstallDisplaySpecifiers(ProgressDialog& dialog)
  14. {
  15. LOG_FUNCTION(InstallDisplaySpecifiers);
  16. State& state = State::GetInstance();
  17. // applies only to 1st dc in forest
  18. ASSERT(state.GetOperation() == State::FOREST);
  19. HRESULT hr = S_OK;
  20. do
  21. {
  22. // install display specifiers for all locales supported by the
  23. // product. 298923, 380160
  24. RegistryKey key;
  25. hr = key.Create(HKEY_LOCAL_MACHINE, REGSTR_PATH_RUNONCE);
  26. BREAK_ON_FAILED_HRESULT(hr);
  27. String exePath = Win::GetSystemDirectory() + L"\\dcphelp.exe";
  28. hr = key.SetValue(L"dcpromo disp spec import", exePath);
  29. BREAK_ON_FAILED_HRESULT(hr);
  30. }
  31. while (0);
  32. if (FAILED(hr))
  33. {
  34. popup.Error(
  35. dialog.GetHWND(),
  36. hr,
  37. IDS_LANGUAGE_FIXUP_FAILED);
  38. state.AddFinishMessage(
  39. String::load(IDS_LANGUAGE_FIXUP_FAILED_FINISH));
  40. }
  41. }
  42. void
  43. DoDnsConfiguration(ProgressDialog& dialog)
  44. {
  45. LOG_FUNCTION(DoDnsConfiguration);
  46. State& state = State::GetInstance();
  47. // applies only in new domain scenarios
  48. ASSERT(
  49. state.GetOperation() == State::FOREST
  50. or state.GetOperation() == State::TREE
  51. or state.GetOperation() == State::CHILD);
  52. if (state.ShouldInstallAndConfigureDns())
  53. {
  54. String domain = state.GetNewDomainDNSName();
  55. if (!InstallAndConfigureDns(dialog, domain))
  56. {
  57. state.AddFinishMessage(String::load(IDS_ERROR_DNS_CONFIG_FAILED));
  58. }
  59. }
  60. }
  61. // Disables media sense so that the tcp/ip stack doesn't unload if the
  62. // net card is yanked. This to allow laptop demos of the DS. 353687
  63. void
  64. DisableMediaSense()
  65. {
  66. LOG_FUNCTION(DisableMediaSense);
  67. HRESULT hr = S_OK;
  68. do
  69. {
  70. RegistryKey key;
  71. static String
  72. TCPIP_KEY(L"System\\CurrentControlSet\\Services\\Tcpip\\Parameters");
  73. hr = key.Create(HKEY_LOCAL_MACHINE, TCPIP_KEY);
  74. BREAK_ON_FAILED_HRESULT(hr);
  75. hr = key.SetValue(L"DisableDHCPMediaSense", 1);
  76. BREAK_ON_FAILED_HRESULT(hr);
  77. LOG(L"DHCP Media sense disabled");
  78. }
  79. while (0);
  80. #ifdef LOGGING_BUILD
  81. if (FAILED(hr))
  82. {
  83. LOG(L"DHCP Media sense NOT disabled");
  84. }
  85. #endif
  86. }
  87. // Disables an old LSA notification thing. 326033
  88. void
  89. DisablePassfiltDll()
  90. {
  91. LOG_FUNCTION(DisablePassfiltDll);
  92. HRESULT hr = S_OK;
  93. do
  94. {
  95. RegistryKey key;
  96. static String
  97. LSA_KEY(L"System\\CurrentControlSet\\Control\\Lsa");
  98. hr =
  99. key.Open(
  100. HKEY_LOCAL_MACHINE,
  101. LSA_KEY,
  102. KEY_READ | KEY_WRITE | KEY_QUERY_VALUE);
  103. BREAK_ON_FAILED_HRESULT(hr);
  104. StringList values;
  105. hr = key.GetValue(L"Notification Packages", std::back_inserter(values));
  106. BREAK_ON_FAILED_HRESULT(hr);
  107. // remove all instances of "passfilt.dll" from the set of strings, if
  108. // present.
  109. static String PASSFILT(L"passfilt.dll");
  110. size_t startElements = values.size();
  111. StringList::iterator last = values.end();
  112. for (
  113. StringList::iterator i = values.begin();
  114. i != last;
  115. /* empty */ )
  116. {
  117. if (i->icompare(PASSFILT) == 0)
  118. {
  119. values.erase(i++);
  120. }
  121. else
  122. {
  123. ++i;
  124. }
  125. }
  126. // if changed, write it back to the registry
  127. if (values.size() != startElements)
  128. {
  129. hr =
  130. key.SetValue(
  131. L"Notification Packages",
  132. values.begin(),
  133. values.end());
  134. BREAK_ON_FAILED_HRESULT(hr);
  135. LOG(L"passfilt.dll removed");
  136. }
  137. else
  138. {
  139. LOG(L"passfilt.dll not found");
  140. }
  141. }
  142. while (0);
  143. #ifdef LOGGING_BUILD
  144. if (FAILED(hr))
  145. {
  146. LOG(L"Notification Packages not updated due to error.");
  147. }
  148. #endif
  149. }
  150. // If the promotion was for a downlevel DC upgrade, then check if the local
  151. // machine's dns hostname is bad, if so, add a message to the finish page. A
  152. // bad name is one we believe will have problems being registered in DNS after
  153. // a promotion.
  154. //
  155. // Since the computer cannot be renamed during a downlevel upgrade, we defer
  156. // this message til the end of the upgrade. (If the machine is not a
  157. // downlevel upgrade, then the wizard startup code detects the bad name and
  158. // blocks until the name is fixed.
  159. void
  160. CheckComputerNameOnDownlevelUpgrade()
  161. {
  162. LOG_FUNCTION(CheckComputerNameOnDownlevelUpgrade);
  163. State& state = State::GetInstance();
  164. State::RunContext context = state.GetRunContext();
  165. if (
  166. context != State::BDC_UPGRADE
  167. && context != State::PDC_UPGRADE)
  168. {
  169. // machine is not a downlevel DC upgrade, so we need do nothing
  170. return;
  171. }
  172. // Then check the computer name to ensure that it can be registered in
  173. // DNS.
  174. String hostname =
  175. Win::GetComputerNameEx(::ComputerNamePhysicalDnsHostname);
  176. DNS_STATUS status =
  177. MyDnsValidateName(hostname, ::DnsNameHostnameLabel);
  178. switch (status)
  179. {
  180. case DNS_ERROR_NON_RFC_NAME:
  181. {
  182. state.AddFinishMessage(
  183. String::format(
  184. IDS_FINISH_NON_RFC_COMPUTER_NAME,
  185. hostname.c_str()));
  186. break;
  187. }
  188. case DNS_ERROR_NUMERIC_NAME:
  189. {
  190. state.AddFinishMessage(
  191. String::format(
  192. IDS_FINISH_NUMERIC_COMPUTER_NAME,
  193. hostname.c_str()));
  194. break;
  195. }
  196. case DNS_ERROR_INVALID_NAME_CHAR:
  197. case ERROR_INVALID_NAME:
  198. {
  199. state.AddFinishMessage(
  200. String::format(
  201. IDS_FINISH_BAD_COMPUTER_NAME,
  202. hostname.c_str()));
  203. break;
  204. }
  205. case ERROR_SUCCESS:
  206. default:
  207. {
  208. break;
  209. }
  210. }
  211. }
  212. void
  213. DoPostOperationStuff(ProgressDialog& progress)
  214. {
  215. LOG_FUNCTION(DoPostOperationStuff);
  216. State& state = State::GetInstance();
  217. switch (state.GetOperation())
  218. {
  219. case State::FOREST:
  220. {
  221. // a new forest has been created
  222. InstallDisplaySpecifiers(progress); // 228682
  223. // fall-thru
  224. }
  225. case State::TREE:
  226. case State::CHILD:
  227. {
  228. // a new domain has been created
  229. DoDnsConfiguration(progress);
  230. // fall-thru
  231. }
  232. case State::REPLICA:
  233. {
  234. // DoToolsInstallation(progress); // 220660
  235. PromoteConfigureToolShortcuts(progress);
  236. DisableMediaSense(); // 353687
  237. DisablePassfiltDll(); // 326033
  238. // NTRAID#NTBUG9-268715-2001/01/04-sburns
  239. CheckComputerNameOnDownlevelUpgrade();
  240. break;
  241. }
  242. case State::ABORT_BDC_UPGRADE:
  243. case State::DEMOTE:
  244. {
  245. DemoteConfigureToolShortcuts(progress); // 366738
  246. break;
  247. }
  248. case State::NONE:
  249. {
  250. ASSERT(false);
  251. break;
  252. }
  253. }
  254. }