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.

265 lines
4.7 KiB

  1. // Copyright (C) 1997 Microsoft Corporation
  2. //
  3. // new forest page
  4. //
  5. // 1-6-98 sburns
  6. #include "headers.hxx"
  7. #include "resource.h"
  8. #include "page.hpp"
  9. #include "ForestPage.hpp"
  10. #include "state.hpp"
  11. #include "common.hpp"
  12. ForestPage::ForestPage()
  13. :
  14. DCPromoWizardPage(
  15. IDD_NEW_FOREST,
  16. IDS_NEW_FOREST_PAGE_TITLE,
  17. IDS_NEW_FOREST_PAGE_SUBTITLE)
  18. {
  19. LOG_CTOR(ForestPage);
  20. }
  21. ForestPage::~ForestPage()
  22. {
  23. LOG_DTOR(ForestPage);
  24. }
  25. void
  26. ForestPage::OnInit()
  27. {
  28. LOG_FUNCTION(ForestPage::OnInit);
  29. Win::Edit_LimitText(
  30. Win::GetDlgItem(hwnd, IDC_DOMAIN),
  31. DNS_DOMAIN_NAME_MAX_LIMIT_DUE_TO_POLICY);
  32. State& state = State::GetInstance();
  33. if (state.UsingAnswerFile())
  34. {
  35. Win::SetDlgItemText(
  36. hwnd,
  37. IDC_DOMAIN,
  38. state.GetAnswerFileOption(State::OPTION_NEW_DOMAIN_NAME));
  39. }
  40. }
  41. static
  42. void
  43. enable(HWND dialog)
  44. {
  45. ASSERT(Win::IsWindow(dialog));
  46. int next =
  47. !Win::GetTrimmedDlgItemText(dialog, IDC_DOMAIN).empty()
  48. ? PSWIZB_NEXT : 0;
  49. Win::PropSheet_SetWizButtons(
  50. Win::GetParent(dialog),
  51. PSWIZB_BACK | next);
  52. }
  53. bool
  54. ForestPage::OnCommand(
  55. HWND /* windowFrom */ ,
  56. unsigned controlIDFrom,
  57. unsigned code)
  58. {
  59. // LOG_FUNCTION(ForestPage::OnCommand);
  60. switch (controlIDFrom)
  61. {
  62. case IDC_DOMAIN:
  63. {
  64. if (code == EN_CHANGE)
  65. {
  66. SetChanged(controlIDFrom);
  67. enable(hwnd);
  68. }
  69. break;
  70. }
  71. default:
  72. {
  73. // do nothing
  74. break;
  75. }
  76. }
  77. return false;
  78. }
  79. bool
  80. ForestPage::OnSetActive()
  81. {
  82. LOG_FUNCTION(ForestPage::OnSetActive);
  83. ASSERT(State::GetInstance().GetOperation() == State::FOREST);
  84. Win::PropSheet_SetWizButtons(
  85. Win::GetParent(hwnd),
  86. PSWIZB_BACK);
  87. State& state = State::GetInstance();
  88. if (state.RunHiddenUnattended())
  89. {
  90. int nextPage = ForestPage::Validate();
  91. if (nextPage != -1)
  92. {
  93. GetWizard().SetNextPageID(hwnd, nextPage);
  94. }
  95. else
  96. {
  97. state.ClearHiddenWhileUnattended();
  98. }
  99. }
  100. enable(hwnd);
  101. return true;
  102. }
  103. bool
  104. ForestValidateDomainDoesNotExist(
  105. HWND dialog,
  106. int editResID)
  107. {
  108. LOG_FUNCTION(ForestValidateDomainDoesNotExist);
  109. ASSERT(Win::IsWindow(dialog));
  110. ASSERT(editResID > 0);
  111. // this can take awhile.
  112. Win::WaitCursor cursor;
  113. String name = Win::GetTrimmedDlgItemText(dialog, editResID);
  114. // The invoking code should verify this condition, but we will handle
  115. // it just in case.
  116. ASSERT(!name.empty());
  117. bool valid = true;
  118. String message;
  119. do
  120. {
  121. if (name.empty())
  122. {
  123. message = String::load(IDS_MUST_ENTER_DOMAIN);
  124. valid = false;
  125. break;
  126. }
  127. if (IsDomainReachable(name))
  128. {
  129. message = String::format(IDS_DOMAIN_NAME_IN_USE, name.c_str());
  130. valid = false;
  131. break;
  132. }
  133. HRESULT hr = MyNetValidateName(name, ::NetSetupNonExistentDomain);
  134. if (hr == Win32ToHresult(ERROR_DUP_NAME))
  135. {
  136. message = String::format(IDS_DOMAIN_NAME_IN_USE, name.c_str());
  137. valid = false;
  138. break;
  139. }
  140. if (hr == Win32ToHresult(ERROR_NETWORK_UNREACHABLE))
  141. {
  142. // 25968
  143. if (
  144. popup.MessageBox(
  145. dialog,
  146. String::format(
  147. IDS_NET_NOT_REACHABLE,
  148. name.c_str()),
  149. MB_YESNO | MB_ICONWARNING) != IDYES)
  150. {
  151. message.erase();
  152. valid = false;
  153. HWND edit = Win::GetDlgItem(dialog, editResID);
  154. Win::SendMessage(edit, EM_SETSEL, 0, -1);
  155. Win::SetFocus(edit);
  156. }
  157. }
  158. // otherwise the domain does not exist
  159. }
  160. while (0);
  161. if (!valid && !message.empty())
  162. {
  163. popup.Gripe(dialog, editResID, message);
  164. }
  165. return valid;
  166. }
  167. int
  168. ForestPage::Validate()
  169. {
  170. LOG_FUNCTION(ForestPage::Validate);
  171. String domain = Win::GetTrimmedDlgItemText(hwnd, IDC_DOMAIN);
  172. if (domain.empty())
  173. {
  174. popup.Gripe(hwnd, IDC_DOMAIN, IDS_MUST_ENTER_DOMAIN);
  175. return -1;
  176. }
  177. State& state = State::GetInstance();
  178. int nextPage =
  179. state.GetRunContext() == State::PDC_UPGRADE
  180. ? IDD_FOREST_VERSION
  181. : IDD_NETBIOS_NAME;
  182. if (WasChanged(IDC_DOMAIN))
  183. {
  184. if (
  185. !ValidateDomainDnsNameSyntax(hwnd, IDC_DOMAIN, true)
  186. || !ConfirmNetbiosLookingNameIsReallyDnsName(hwnd, IDC_DOMAIN)
  187. // do this test last, as it is expensive
  188. || !ForestValidateDomainDoesNotExist(hwnd, IDC_DOMAIN))
  189. {
  190. nextPage = -1;
  191. }
  192. else
  193. {
  194. ClearChanges();
  195. }
  196. }
  197. if (nextPage != -1)
  198. {
  199. state.SetNewDomainDNSName(domain);
  200. }
  201. return nextPage;
  202. }