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.

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