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.

301 lines
5.5 KiB

  1. // Copyright (C) 1997 Microsoft Corporation
  2. //
  3. // replica page
  4. //
  5. // 12-22-97 sburns
  6. #include "headers.hxx"
  7. #include "page.hpp"
  8. #include "ReplicaPage.hpp"
  9. #include "resource.h"
  10. #include "ds.hpp"
  11. #include "common.hpp"
  12. #include "state.hpp"
  13. #include "dns.hpp"
  14. ReplicaPage::ReplicaPage()
  15. :
  16. DCPromoWizardPage(
  17. IDD_REPLICA,
  18. IDS_REPLICA_PAGE_TITLE,
  19. IDS_REPLICA_PAGE_SUBTITLE)
  20. {
  21. LOG_CTOR(ReplicaPage);
  22. }
  23. ReplicaPage::~ReplicaPage()
  24. {
  25. LOG_DTOR(ReplicaPage);
  26. }
  27. void
  28. ReplicaPage::Enable()
  29. {
  30. int next =
  31. !Win::GetTrimmedDlgItemText(hwnd, IDC_DOMAIN).empty()
  32. ? PSWIZB_NEXT : 0;
  33. Win::PropSheet_SetWizButtons(
  34. Win::GetParent(hwnd),
  35. PSWIZB_BACK | next);
  36. }
  37. bool
  38. ReplicaPage::OnCommand(
  39. HWND /* windowFrom */ ,
  40. unsigned controlIDFrom,
  41. unsigned code)
  42. {
  43. // LOG_FUNCTION(ReplicaPage::OnCommand);
  44. switch (controlIDFrom)
  45. {
  46. case IDC_BROWSE:
  47. {
  48. if (code == BN_CLICKED)
  49. {
  50. String domain = BrowseForDomain(hwnd);
  51. if (!domain.empty())
  52. {
  53. Win::SetDlgItemText(hwnd, IDC_DOMAIN, domain);
  54. }
  55. return true;
  56. }
  57. break;
  58. }
  59. case IDC_DOMAIN:
  60. {
  61. if (code == EN_CHANGE)
  62. {
  63. SetChanged(controlIDFrom);
  64. Enable();
  65. }
  66. break;
  67. }
  68. default:
  69. {
  70. // do nothing
  71. break;
  72. }
  73. }
  74. return false;
  75. }
  76. void
  77. ReplicaPage::OnInit()
  78. {
  79. LOG_FUNCTION(ReplicaPage::OnInit);
  80. Win::Edit_LimitText(
  81. Win::GetDlgItem(hwnd, IDC_DOMAIN),
  82. DNS_DOMAIN_NAME_MAX_LIMIT_DUE_TO_POLICY);
  83. State& state = State::GetInstance();
  84. if (state.UsingAnswerFile())
  85. {
  86. // Ignore the answerfile if we got the domain name from the
  87. // ReplicateFromMediaPage.
  88. if (
  89. !state.ReplicateFromMedia()
  90. || state.GetReplicaDomainDNSName().empty())
  91. {
  92. Win::SetDlgItemText(
  93. hwnd,
  94. IDC_DOMAIN,
  95. state.GetAnswerFileOption(
  96. State::OPTION_REPLICA_DOMAIN_NAME));
  97. }
  98. }
  99. else
  100. {
  101. // default domain is that the server is joined to.
  102. Win::SetDlgItemText(
  103. hwnd,
  104. IDC_DOMAIN,
  105. state.GetComputer().GetDomainDnsName());
  106. }
  107. }
  108. bool
  109. ReplicaPage::ShouldSkipPage()
  110. {
  111. LOG_FUNCTION(ReplicaPage::ShouldSkipPage);
  112. bool result = false;
  113. State& state = State::GetInstance();
  114. do
  115. {
  116. // check to see if we got the domain name from the
  117. // ReplicateFromMediaPage. If so, then we don't need to show this
  118. // page.
  119. if (
  120. state.ReplicateFromMedia()
  121. && !state.GetReplicaDomainDNSName().empty() )
  122. {
  123. // dns domain name is from the ReplicateFromMediaPage, which
  124. // saved that name in the state instance. So put that name
  125. // in the ui.
  126. Win::SetDlgItemText(
  127. hwnd,
  128. IDC_DOMAIN,
  129. state.GetReplicaDomainDNSName());
  130. result = true;
  131. break;
  132. }
  133. if (state.RunHiddenUnattended())
  134. {
  135. result = true;
  136. break;
  137. }
  138. }
  139. while (0);
  140. LOG(result ? L"true" : L"false");
  141. return result;
  142. }
  143. bool
  144. ReplicaPage::OnSetActive()
  145. {
  146. LOG_FUNCTION(ReplicaPage::OnSetActive);
  147. ASSERT(State::GetInstance().GetOperation() == State::REPLICA);
  148. Win::PropSheet_SetWizButtons(
  149. Win::GetParent(hwnd),
  150. PSWIZB_BACK);
  151. State& state = State::GetInstance();
  152. if (ShouldSkipPage())
  153. {
  154. LOG(L"skipping ReplicaPage");
  155. Wizard& wiz = GetWizard();
  156. if (wiz.IsBacktracking())
  157. {
  158. // backup once again
  159. wiz.Backtrack(hwnd);
  160. return true;
  161. }
  162. int nextPage = ReplicaPage::Validate();
  163. if (nextPage != -1)
  164. {
  165. wiz.SetNextPageID(hwnd, nextPage);
  166. }
  167. else
  168. {
  169. state.ClearHiddenWhileUnattended();
  170. }
  171. }
  172. Enable();
  173. return true;
  174. }
  175. int
  176. ReplicaPage::Validate()
  177. {
  178. LOG_FUNCTION(ReplicaPage::Validate);
  179. int nextPage = -1;
  180. // SPB:251431 do validation even if this page is untouched, as upstream
  181. // pages may have been changed in such a fashion that re-validation is
  182. // required.
  183. // if (!WasChanged(IDC_DOMAIN))
  184. // {
  185. // return nextPage;
  186. // }
  187. do
  188. {
  189. String domain = Win::GetTrimmedDlgItemText(hwnd, IDC_DOMAIN);
  190. if (domain.empty())
  191. {
  192. popup.Gripe(hwnd, IDC_DOMAIN, IDS_MUST_ENTER_DOMAIN);
  193. break;
  194. }
  195. if (!ValidateDomainDnsNameSyntax(hwnd, IDC_DOMAIN, true))
  196. {
  197. break;
  198. }
  199. // now ensure that the domain exists
  200. String dnsName;
  201. if (!ValidateDomainExists(hwnd, IDC_DOMAIN, dnsName))
  202. {
  203. break;
  204. }
  205. if (!dnsName.empty())
  206. {
  207. // the user specified the netbios name of the domain, and
  208. // confirmed it, so use the dns domain name returned.
  209. Win::SetDlgItemText(hwnd, IDC_DOMAIN, dnsName);
  210. domain = dnsName;
  211. }
  212. State& state = State::GetInstance();
  213. if (!state.IsDomainInForest(domain))
  214. {
  215. popup.Gripe(
  216. hwnd,
  217. IDC_DOMAIN,
  218. String::format(
  219. IDS_DOMAIN_NOT_IN_FOREST,
  220. domain.c_str(),
  221. state.GetUserForestName().c_str()));
  222. break;
  223. }
  224. // valid
  225. ClearChanges();
  226. state.SetReplicaDomainDNSName(domain);
  227. nextPage = IDD_PATHS;
  228. }
  229. while (0);
  230. return nextPage;
  231. }