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.

311 lines
6.3 KiB

  1. // Copyright (C) 1997 Microsoft Corporation
  2. //
  3. // new child page
  4. //
  5. // 12-22-97 sburns
  6. #include "headers.hxx"
  7. #include "page.hpp"
  8. #include "ChildPage.hpp"
  9. #include "resource.h"
  10. #include "dns.hpp"
  11. #include "common.hpp"
  12. #include "state.hpp"
  13. ChildPage::ChildPage()
  14. :
  15. DCPromoWizardPage(
  16. IDD_NEW_CHILD,
  17. IDS_CHILD_PAGE_TITLE,
  18. IDS_CHILD_PAGE_SUBTITLE)
  19. {
  20. LOG_CTOR(ChildPage);
  21. }
  22. ChildPage::~ChildPage()
  23. {
  24. LOG_DTOR(ChildPage);
  25. }
  26. void
  27. ChildPage::OnInit()
  28. {
  29. LOG_FUNCTION(ChildPage::OnInit);
  30. Win::Edit_LimitText(
  31. Win::GetDlgItem(hwnd, IDC_PARENT),
  32. DNS_DOMAIN_NAME_MAX_LIMIT_DUE_TO_POLICY);
  33. Win::Edit_LimitText(
  34. Win::GetDlgItem(hwnd, IDC_LEAF),
  35. Dns::MAX_LABEL_LENGTH);
  36. State& state = State::GetInstance();
  37. if (state.UsingAnswerFile())
  38. {
  39. Win::SetDlgItemText(
  40. hwnd,
  41. IDC_PARENT,
  42. state.GetAnswerFileOption(State::OPTION_PARENT_DOMAIN_NAME));
  43. Win::SetDlgItemText(
  44. hwnd,
  45. IDC_LEAF,
  46. state.GetAnswerFileOption(State::OPTION_CHILD_NAME));
  47. }
  48. else
  49. {
  50. // default domain is that to which the server is joined.
  51. Win::SetDlgItemText(
  52. hwnd,
  53. IDC_PARENT,
  54. state.GetComputer().GetDomainDnsName());
  55. // @@ if PDC_UPGRADE, set the pdc flat name as the leaf name here
  56. }
  57. }
  58. static
  59. void
  60. enable(HWND dialog)
  61. {
  62. ASSERT(Win::IsWindow(dialog));
  63. int next =
  64. ( !Win::GetTrimmedDlgItemText(dialog, IDC_PARENT).empty()
  65. && !Win::GetTrimmedDlgItemText(dialog, IDC_LEAF).empty() )
  66. ? PSWIZB_NEXT : 0;
  67. Win::PropSheet_SetWizButtons(
  68. Win::GetParent(dialog),
  69. PSWIZB_BACK | next);
  70. }
  71. bool
  72. ChildPage::OnCommand(
  73. HWND /* windowFrom */ ,
  74. unsigned controlIDFrom,
  75. unsigned code)
  76. {
  77. // LOG_FUNCTION(ChildPage::OnCommand);
  78. switch (controlIDFrom)
  79. {
  80. case IDC_BROWSE:
  81. {
  82. if (code == BN_CLICKED)
  83. {
  84. String domain = BrowseForDomain(hwnd);
  85. if (!domain.empty())
  86. {
  87. Win::SetDlgItemText(hwnd, IDC_PARENT, domain);
  88. }
  89. return true;
  90. }
  91. break;
  92. }
  93. case IDC_LEAF:
  94. case IDC_PARENT:
  95. {
  96. if (code == EN_CHANGE)
  97. {
  98. SetChanged(controlIDFrom);
  99. String parent = Win::GetTrimmedDlgItemText(hwnd, IDC_PARENT);
  100. String leaf = Win::GetTrimmedDlgItemText(hwnd, IDC_LEAF);
  101. String domain = leaf + L"." + parent;
  102. Win::SetDlgItemText(hwnd, IDC_DOMAIN, domain);
  103. enable(hwnd);
  104. return true;
  105. }
  106. break;
  107. }
  108. default:
  109. {
  110. // do nothing
  111. break;
  112. }
  113. }
  114. return false;
  115. }
  116. bool
  117. ChildPage::OnSetActive()
  118. {
  119. LOG_FUNCTION(ChildPage::OnSetActive);
  120. ASSERT(State::GetInstance().GetOperation() == State::CHILD);
  121. Win::PropSheet_SetWizButtons(
  122. Win::GetParent(hwnd),
  123. PSWIZB_BACK);
  124. State& state = State::GetInstance();
  125. if (state.RunHiddenUnattended())
  126. {
  127. int nextPage = ChildPage::Validate();
  128. if (nextPage != -1)
  129. {
  130. GetWizard().SetNextPageID(hwnd, nextPage);
  131. }
  132. else
  133. {
  134. state.ClearHiddenWhileUnattended();
  135. }
  136. }
  137. enable(hwnd);
  138. return true;
  139. }
  140. int
  141. ChildPage::Validate()
  142. {
  143. LOG_FUNCTION(Child::Validate);
  144. String parent = Win::GetTrimmedDlgItemText(hwnd, IDC_PARENT);
  145. String leaf = Win::GetTrimmedDlgItemText(hwnd, IDC_LEAF);
  146. String domain = leaf + L"." + parent;
  147. State& state = State::GetInstance();
  148. int nextPage = -1;
  149. // SPB:251431 do validation even if this page is untouched, as upstream
  150. // pages may have been changed in such a fashion that re-validation is
  151. // required.
  152. // if (!WasChanged(IDC_PARENT) && !WasChanged(IDC_LEAF))
  153. // {
  154. // return nextPage;
  155. // }
  156. do
  157. {
  158. if (parent.empty())
  159. {
  160. popup.Gripe(hwnd, IDC_PARENT, IDS_MUST_ENTER_PARENT);
  161. break;
  162. }
  163. if (leaf.empty())
  164. {
  165. popup.Gripe(hwnd, IDC_LEAF, IDS_MUST_ENTER_LEAF);
  166. break;
  167. }
  168. bool parentIsNonRfc = false;
  169. if (
  170. !ValidateDomainDnsNameSyntax(
  171. hwnd,
  172. IDC_PARENT,
  173. true,
  174. &parentIsNonRfc))
  175. {
  176. break;
  177. }
  178. if (!ValidateChildDomainLeafNameLabel(hwnd, IDC_LEAF, parentIsNonRfc))
  179. {
  180. break;
  181. }
  182. // now ensure that the parent domain exists
  183. String dnsName;
  184. if (!ValidateDomainExists(hwnd, IDC_PARENT, dnsName))
  185. {
  186. break;
  187. }
  188. if (!dnsName.empty())
  189. {
  190. // the user specified the netbios name of the domain, and
  191. // confirmed it, so use the dns domain name returned.
  192. parent = dnsName;
  193. domain = leaf + L"." + parent;
  194. Win::SetDlgItemText(hwnd, IDC_PARENT, dnsName);
  195. Win::SetDlgItemText(hwnd, IDC_DOMAIN, domain);
  196. }
  197. if (!state.IsDomainInForest(parent))
  198. {
  199. popup.Gripe(
  200. hwnd,
  201. IDC_DOMAIN,
  202. String::format(
  203. IDS_DOMAIN_NOT_IN_FOREST,
  204. parent.c_str(),
  205. state.GetUserForestName().c_str()));
  206. break;
  207. }
  208. if (domain.length() > DNS_DOMAIN_NAME_MAX_LIMIT_DUE_TO_POLICY)
  209. {
  210. String message =
  211. String::format(
  212. IDS_DNS_NAME_TOO_LONG,
  213. domain.c_str(),
  214. DNS_DOMAIN_NAME_MAX_LIMIT_DUE_TO_POLICY,
  215. DNS_DOMAIN_NAME_MAX_LIMIT_DUE_TO_POLICY_UTF8);
  216. popup.Gripe(hwnd, IDC_LEAF, message);
  217. break;
  218. }
  219. // validate the resulting child domain name, not warning on non-RFCness
  220. if (
  221. !ValidateDomainDnsNameSyntax(
  222. hwnd,
  223. domain,
  224. IDC_LEAF,
  225. !parentIsNonRfc) )
  226. {
  227. break;
  228. }
  229. // now ensure that the child domain name does not exist
  230. if (!ValidateDomainDoesNotExist(hwnd, domain, IDC_LEAF))
  231. {
  232. break;
  233. }
  234. // valid
  235. ClearChanges();
  236. state.SetParentDomainDNSName(Win::GetTrimmedDlgItemText(hwnd, IDC_PARENT));
  237. state.SetNewDomainDNSName(domain);
  238. nextPage =
  239. state.GetRunContext() == State::PDC_UPGRADE
  240. ? IDD_PATHS
  241. : IDD_NETBIOS_NAME;
  242. }
  243. while (0);
  244. return nextPage;
  245. }