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.

217 lines
4.1 KiB

  1. // Copyright (c) 1997-2001 Microsoft Corporation
  2. //
  3. // File: DomainPage.cpp
  4. //
  5. // Synopsis: Defines the new domain name page used in the
  6. // Express path for the CYS Wizard
  7. //
  8. // History: 02/08/2001 JeffJon Created
  9. #include "pch.h"
  10. #include "resource.h"
  11. #include "InstallationUnitProvider.h"
  12. #include "DomainPage.h"
  13. #include "state.h"
  14. static PCWSTR DOMAIN_PAGE_HELP = L"cys.chm::/cys_configuring_first_server.htm";
  15. ADDomainPage::ADDomainPage()
  16. :
  17. CYSWizardPage(
  18. IDD_AD_DOMAIN_NAME_PAGE,
  19. IDS_AD_DOMAIN_TITLE,
  20. IDS_AD_DOMAIN_SUBTITLE,
  21. DOMAIN_PAGE_HELP)
  22. {
  23. LOG_CTOR(ADDomainPage);
  24. }
  25. ADDomainPage::~ADDomainPage()
  26. {
  27. LOG_DTOR(ADDomainPage);
  28. }
  29. void
  30. ADDomainPage::OnInit()
  31. {
  32. LOG_FUNCTION(ADDomainPage::OnInit);
  33. }
  34. static
  35. void
  36. enable(HWND dialog)
  37. {
  38. ASSERT(Win::IsWindow(dialog));
  39. int next =
  40. !Win::GetTrimmedDlgItemText(dialog, IDC_DOMAIN).empty()
  41. ? PSWIZB_NEXT : 0;
  42. Win::PropSheet_SetWizButtons(
  43. Win::GetParent(dialog),
  44. PSWIZB_BACK | next);
  45. }
  46. bool
  47. ADDomainPage::OnSetActive()
  48. {
  49. LOG_FUNCTION(ADDomainPage::OnSetActive);
  50. Win::Edit_LimitText(
  51. Win::GetDlgItem(hwnd, IDC_DOMAIN),
  52. DNS_DOMAIN_NAME_MAX_LIMIT_DUE_TO_POLICY);
  53. enable(hwnd);
  54. return true;
  55. }
  56. bool
  57. ADDomainPage::OnCommand(
  58. HWND /* windowFrom */ ,
  59. unsigned controlIDFrom,
  60. unsigned code)
  61. {
  62. // LOG_FUNCTION(ForestPage::OnCommand);
  63. switch (controlIDFrom)
  64. {
  65. case IDC_DOMAIN:
  66. {
  67. if (code == EN_CHANGE)
  68. {
  69. enable(hwnd);
  70. }
  71. break;
  72. }
  73. default:
  74. {
  75. // do nothing
  76. break;
  77. }
  78. }
  79. return false;
  80. }
  81. bool
  82. ForestValidateDomainDoesNotExist(
  83. HWND dialog,
  84. int editResID)
  85. {
  86. LOG_FUNCTION(ForestValidateDomainDoesNotExist);
  87. ASSERT(Win::IsWindow(dialog));
  88. ASSERT(editResID > 0);
  89. // this can take awhile.
  90. Win::WaitCursor cursor;
  91. String name = Win::GetTrimmedDlgItemText(dialog, editResID);
  92. // The invoking code should verify this condition, but we will handle
  93. // it just in case.
  94. ASSERT(!name.empty());
  95. bool valid = true;
  96. String message;
  97. do
  98. {
  99. if (name.empty())
  100. {
  101. message = String::load(IDS_MUST_ENTER_DOMAIN);
  102. valid = false;
  103. break;
  104. }
  105. if (IsDomainReachable(name))
  106. {
  107. message = String::format(IDS_DOMAIN_NAME_IN_USE, name.c_str());
  108. valid = false;
  109. break;
  110. }
  111. HRESULT hr = MyNetValidateName(name, ::NetSetupNonExistentDomain);
  112. if (hr == Win32ToHresult(ERROR_DUP_NAME))
  113. {
  114. message = String::format(IDS_DOMAIN_NAME_IN_USE, name.c_str());
  115. valid = false;
  116. break;
  117. }
  118. if (hr == Win32ToHresult(ERROR_NETWORK_UNREACHABLE))
  119. {
  120. // 25968
  121. if (
  122. popup.MessageBox(
  123. dialog,
  124. String::format(
  125. IDS_NET_NOT_REACHABLE,
  126. name.c_str()),
  127. MB_YESNO | MB_ICONWARNING) != IDYES)
  128. {
  129. message.erase();
  130. valid = false;
  131. HWND edit = Win::GetDlgItem(dialog, editResID);
  132. Win::SendMessage(edit, EM_SETSEL, 0, -1);
  133. Win::SetFocus(edit);
  134. }
  135. }
  136. // otherwise the domain does not exist
  137. }
  138. while (0);
  139. if (!valid && !message.empty())
  140. {
  141. popup.Gripe(dialog, editResID, message);
  142. }
  143. return valid;
  144. }
  145. int
  146. ADDomainPage::Validate()
  147. {
  148. LOG_FUNCTION(ADDomainPage::Validate);
  149. int nextPage = -1;
  150. String domain = Win::GetTrimmedDlgItemText(hwnd, IDC_DOMAIN);
  151. if (domain.empty())
  152. {
  153. popup.Gripe(hwnd, IDC_DOMAIN, IDS_MUST_ENTER_DOMAIN);
  154. return -1;
  155. }
  156. if (
  157. !ValidateDomainDnsNameSyntax(hwnd, IDC_DOMAIN, true)
  158. || !ConfirmNetbiosLookingNameIsReallyDnsName(hwnd, IDC_DOMAIN)
  159. // do this test last, as it is expensive
  160. || !ForestValidateDomainDoesNotExist(hwnd, IDC_DOMAIN))
  161. {
  162. nextPage = -1;
  163. }
  164. else
  165. {
  166. InstallationUnitProvider::GetInstance().GetADInstallationUnit().SetNewDomainDNSName(domain);
  167. nextPage = IDD_NETBIOS_NAME;
  168. }
  169. return nextPage;
  170. }