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.

246 lines
5.3 KiB

  1. // Copyright (c) 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. static PCWSTR DOMAIN_PAGE_HELP = L"cys.chm::/typical_setup.htm#typicaldomainname";
  14. ADDomainPage::ADDomainPage()
  15. :
  16. CYSWizardPage(
  17. IDD_AD_DOMAIN_NAME_PAGE,
  18. IDS_AD_DOMAIN_TITLE,
  19. IDS_AD_DOMAIN_SUBTITLE,
  20. DOMAIN_PAGE_HELP)
  21. {
  22. LOG_CTOR(ADDomainPage);
  23. }
  24. ADDomainPage::~ADDomainPage()
  25. {
  26. LOG_DTOR(ADDomainPage);
  27. }
  28. void
  29. ADDomainPage::OnInit()
  30. {
  31. LOG_FUNCTION(ADDomainPage::OnInit);
  32. CYSWizardPage::OnInit();
  33. // Set the default DNS domain name
  34. SetDefaultDNSName();
  35. }
  36. void
  37. ADDomainPage::SetDefaultDNSName()
  38. {
  39. LOG_FUNCTION(ADDomainPage::SetDefaultDNSName);
  40. // default to smallbusiness.local unless we can construct
  41. // the name from the RegisteredOrganization regkey
  42. String newDomainDNSName = L"smallbusiness.local";
  43. do
  44. {
  45. String organizationName;
  46. bool regResult =
  47. GetRegKeyValue(
  48. CYS_ORGNAME_REGKEY,
  49. CYS_ORGNAME_VALUE,
  50. organizationName);
  51. if (!regResult || organizationName.empty())
  52. {
  53. // default back to smallbusiness.local
  54. LOG(L"Failed to read the orgname from registry so defaulting to smallbusiness.local");
  55. break;
  56. }
  57. String dnsName = String::format(IDS_EXPRESS_DNS_NAME_FORMAT, organizationName.c_str());
  58. DNSNameSyntaxError dnsNameError =
  59. ValidateDomainDnsNameSyntax(dnsName);
  60. if (dnsNameError == DNS_NAME_VALID ||
  61. dnsNameError == DNS_NAME_NON_RFC ||
  62. dnsNameError == DNS_NAME_NON_RFC_WITH_UNDERSCORE)
  63. {
  64. LOG(
  65. String::format(
  66. L"Name is either valid or non RFC: %1",
  67. dnsName.c_str()));
  68. newDomainDNSName = dnsName;
  69. break;
  70. }
  71. // since the name was invalid, try trimming
  72. // some illegal characters (note that space is included)
  73. static const String illegalDNSCharacters = L"\\ \'{|}~[]^`:;<>=?@!\"#$%^&()+/,*.";
  74. static const String emptyString = L"";
  75. organizationName = organizationName.replace_each_of(illegalDNSCharacters, emptyString);
  76. LOG(
  77. String::format(
  78. L"organization name after stripping: %1",
  79. organizationName.c_str()));
  80. dnsName = String::format(IDS_EXPRESS_DNS_NAME_FORMAT, organizationName.c_str());
  81. dnsNameError =
  82. ValidateDomainDnsNameSyntax(dnsName);
  83. if (dnsNameError == DNS_NAME_VALID ||
  84. dnsNameError == DNS_NAME_NON_RFC ||
  85. dnsNameError == DNS_NAME_NON_RFC_WITH_UNDERSCORE)
  86. {
  87. LOG(
  88. String::format(
  89. L"Stripped name is either valid or non RFC: %1",
  90. dnsName.c_str()));
  91. newDomainDNSName = dnsName;
  92. break;
  93. }
  94. // fall back to using smallbusiness.local
  95. LOG(L"All attempts to convert the organization name have failed.");
  96. } while (false);
  97. LOG(
  98. String::format(
  99. L"Using DNS name: %1",
  100. newDomainDNSName.c_str()));
  101. Win::SetDlgItemText(
  102. hwnd,
  103. IDC_DOMAIN,
  104. newDomainDNSName);
  105. }
  106. static
  107. void
  108. enable(HWND dialog)
  109. {
  110. ASSERT(Win::IsWindow(dialog));
  111. int next =
  112. !Win::GetTrimmedDlgItemText(dialog, IDC_DOMAIN).empty()
  113. ? PSWIZB_NEXT : 0;
  114. Win::PropSheet_SetWizButtons(
  115. Win::GetParent(dialog),
  116. PSWIZB_BACK | next);
  117. }
  118. bool
  119. ADDomainPage::OnSetActive()
  120. {
  121. LOG_FUNCTION(ADDomainPage::OnSetActive);
  122. Win::Edit_LimitText(
  123. Win::GetDlgItem(hwnd, IDC_DOMAIN),
  124. DNS_DOMAIN_NAME_MAX_LIMIT_DUE_TO_POLICY);
  125. enable(hwnd);
  126. return true;
  127. }
  128. bool
  129. ADDomainPage::OnCommand(
  130. HWND /* windowFrom */ ,
  131. unsigned controlIDFrom,
  132. unsigned code)
  133. {
  134. // LOG_FUNCTION(ForestPage::OnCommand);
  135. switch (controlIDFrom)
  136. {
  137. case IDC_DOMAIN:
  138. {
  139. if (code == EN_CHANGE)
  140. {
  141. enable(hwnd);
  142. }
  143. break;
  144. }
  145. default:
  146. {
  147. // do nothing
  148. break;
  149. }
  150. }
  151. return false;
  152. }
  153. int
  154. ADDomainPage::Validate()
  155. {
  156. LOG_FUNCTION(ADDomainPage::Validate);
  157. int nextPage = -1;
  158. do
  159. {
  160. String domain = Win::GetTrimmedDlgItemText(hwnd, IDC_DOMAIN);
  161. LOG(String::format(L"domain = %1", domain.c_str()));
  162. if (!ValidateDomainDnsNameSyntax(hwnd, IDC_DOMAIN, popup))
  163. {
  164. nextPage = -1;
  165. break;
  166. }
  167. if (!ConfirmNetbiosLookingNameIsReallyDnsName(hwnd, IDC_DOMAIN, popup))
  168. {
  169. nextPage = -1;
  170. break;
  171. }
  172. // do this test last, as it is expensive
  173. if (!ForestValidateDomainDoesNotExist(hwnd, IDC_DOMAIN, popup))
  174. {
  175. nextPage = -1;
  176. break;
  177. }
  178. InstallationUnitProvider::GetInstance().GetADInstallationUnit().SetNewDomainDNSName(domain);
  179. nextPage = IDD_NETBIOS_NAME;
  180. } while(false);
  181. LOG(String::format(L"%1!d!", nextPage));
  182. return nextPage;
  183. }