Leaked source code of windows server 2003
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.

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