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.

269 lines
5.2 KiB

  1. // Copyright (C) 1997 Microsoft Corporation
  2. //
  3. // new tree page
  4. //
  5. // 1-7-98 sburns
  6. #include "headers.hxx"
  7. #include "page.hpp"
  8. #include "TreePage.hpp"
  9. #include "resource.h"
  10. #include "state.hpp"
  11. #include "common.hpp"
  12. #include "dns.hpp"
  13. TreePage::TreePage()
  14. :
  15. DCPromoWizardPage(
  16. IDD_NEW_TREE,
  17. IDS_TREE_PAGE_TITLE,
  18. IDS_TREE_PAGE_SUBTITLE)
  19. {
  20. LOG_CTOR(TreePage);
  21. }
  22. TreePage::~TreePage()
  23. {
  24. LOG_DTOR(TreePage);
  25. }
  26. void
  27. TreePage::OnInit()
  28. {
  29. LOG_FUNCTION(TreePage::OnInit);
  30. Win::Edit_LimitText(
  31. Win::GetDlgItem(hwnd, IDC_DOMAIN),
  32. DNS_DOMAIN_NAME_MAX_LIMIT_DUE_TO_POLICY);
  33. State& state = State::GetInstance();
  34. if (state.UsingAnswerFile())
  35. {
  36. // this will cause IDC_DOMAIN to be marked changed, so the validation
  37. // code will be called.
  38. Win::SetDlgItemText(
  39. hwnd,
  40. IDC_DOMAIN,
  41. state.GetAnswerFileOption(
  42. State::OPTION_NEW_DOMAIN_NAME));
  43. }
  44. }
  45. static
  46. void
  47. enable(HWND dialog)
  48. {
  49. ASSERT(Win::IsWindow(dialog));
  50. int next =
  51. !Win::GetTrimmedDlgItemText(dialog, IDC_DOMAIN).empty()
  52. ? PSWIZB_NEXT
  53. : 0;
  54. Win::PropSheet_SetWizButtons(
  55. Win::GetParent(dialog),
  56. PSWIZB_BACK | next);
  57. }
  58. bool
  59. TreePage::OnSetActive()
  60. {
  61. LOG_FUNCTION(TreePage::OnSetActive);
  62. ASSERT(State::GetInstance().GetOperation() == State::TREE);
  63. Win::PropSheet_SetWizButtons(
  64. Win::GetParent(hwnd),
  65. PSWIZB_BACK);
  66. State& state = State::GetInstance();
  67. if (state.RunHiddenUnattended())
  68. {
  69. int nextPage = Validate();
  70. if (nextPage != -1)
  71. {
  72. GetWizard().SetNextPageID(hwnd, nextPage);
  73. }
  74. else
  75. {
  76. state.ClearHiddenWhileUnattended();
  77. }
  78. }
  79. enable(hwnd);
  80. return true;
  81. }
  82. bool
  83. TreePage::OnCommand(
  84. HWND /* windowFrom */ ,
  85. unsigned controlIDFrom,
  86. unsigned code)
  87. {
  88. // LOG_FUNCTION(TreePage::OnCommand);
  89. switch (controlIDFrom)
  90. {
  91. case IDC_DOMAIN:
  92. {
  93. if (code == EN_CHANGE)
  94. {
  95. SetChanged(controlIDFrom);
  96. enable(hwnd);
  97. }
  98. break;
  99. }
  100. default:
  101. {
  102. // do nothing
  103. break;
  104. }
  105. }
  106. return false;
  107. }
  108. int
  109. TreePage::Validate()
  110. {
  111. LOG_FUNCTION(TreePage::Validate);
  112. String domain = Win::GetTrimmedDlgItemText(hwnd, IDC_DOMAIN);
  113. if (domain.empty())
  114. {
  115. popup.Gripe(hwnd, IDC_DOMAIN, IDS_MUST_ENTER_DOMAIN);
  116. return -1;
  117. }
  118. State& state = State::GetInstance();
  119. int nextPage =
  120. state.GetRunContext() == State::PDC_UPGRADE
  121. ? IDD_PATHS
  122. : IDD_NETBIOS_NAME;
  123. // SPB:251431 do validation even if this page is untouched, as upstream
  124. // pages may have been changed in such a fashion that re-validation is
  125. // required.
  126. // if (!WasChanged(IDC_DOMAIN))
  127. // {
  128. // return nextPage;
  129. // }
  130. do
  131. {
  132. // verify that the new domain name is properly formatted and does
  133. // not exist.
  134. if (
  135. !ValidateDomainDnsNameSyntax(hwnd, IDC_DOMAIN, true)
  136. || !ConfirmNetbiosLookingNameIsReallyDnsName(hwnd, IDC_DOMAIN)
  137. // do this test last, as it is expensive
  138. || !ValidateDomainDoesNotExist(hwnd, IDC_DOMAIN) )
  139. {
  140. break;
  141. }
  142. domain = Win::GetTrimmedDlgItemText(hwnd, IDC_DOMAIN);
  143. String conflictingDomain;
  144. switch (state.DomainFitsInForest(domain, conflictingDomain))
  145. {
  146. case DnsNameCompareLeftParent:
  147. {
  148. // can't encompass another tree
  149. popup.Gripe(
  150. hwnd,
  151. IDC_DOMAIN,
  152. String::format(
  153. IDS_SUPERIOR_TO_TREE,
  154. domain.c_str(),
  155. conflictingDomain.c_str()));
  156. break;
  157. }
  158. case DnsNameCompareRightParent:
  159. {
  160. // should be a child domain instead
  161. popup.Gripe(
  162. hwnd,
  163. IDC_DOMAIN,
  164. String::format(
  165. IDS_INFERIOR_TO_TREE,
  166. domain.c_str(),
  167. conflictingDomain.c_str()));
  168. break;
  169. }
  170. case DnsNameCompareEqual:
  171. {
  172. // shouldn't happen, ValidateDomainDNSName call above would
  173. // have caught it.
  174. ASSERT(false);
  175. popup.Gripe(
  176. hwnd,
  177. IDC_DOMAIN,
  178. String::format(IDS_DOMAIN_NAME_IN_USE, domain.c_str()));
  179. break;
  180. }
  181. case DnsNameCompareInvalid:
  182. {
  183. // shouldn't happen, ValidateDomainDNSName call above would
  184. // have caught it.
  185. ASSERT(false);
  186. popup.Gripe(
  187. hwnd,
  188. IDC_DOMAIN,
  189. String::format(
  190. IDS_BAD_DNS_SYNTAX,
  191. domain.c_str(),
  192. Dns::MAX_LABEL_LENGTH));
  193. break;
  194. }
  195. case DnsNameCompareNotEqual:
  196. {
  197. // valid
  198. ClearChanges();
  199. state.SetParentDomainDNSName(state.GetUserForestName());
  200. state.SetNewDomainDNSName(domain);
  201. return nextPage;
  202. }
  203. default:
  204. {
  205. ASSERT(false);
  206. break;
  207. }
  208. }
  209. }
  210. while (0);
  211. return -1;
  212. }