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.

291 lines
6.4 KiB

  1. // Copyright (c) 2001 Microsoft Corporation
  2. //
  3. // File: NetbiosPage.cpp
  4. //
  5. // Synopsis: Defines the new netbios 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 "NetbiosPage.h"
  13. static PCWSTR NETBIOS_PAGE_HELP = L"cys.chm::/typical_setup.htm#typicalnetbios";
  14. NetbiosDomainPage::NetbiosDomainPage()
  15. :
  16. CYSWizardPage(
  17. IDD_NETBIOS_NAME,
  18. IDS_NETBIOS_NAME_TITLE,
  19. IDS_NETBIOS_NAME_SUBTITLE,
  20. NETBIOS_PAGE_HELP)
  21. {
  22. LOG_CTOR(NetbiosDomainPage);
  23. }
  24. NetbiosDomainPage::~NetbiosDomainPage()
  25. {
  26. LOG_DTOR(NetbiosDomainPage);
  27. }
  28. void
  29. NetbiosDomainPage::OnInit()
  30. {
  31. LOG_FUNCTION(NetbiosDomainPage::OnInit);
  32. CYSWizardPage::OnInit();
  33. Win::Edit_LimitText(
  34. Win::GetDlgItem(hwnd, IDC_NETBIOS),
  35. MAX_NETBIOS_NAME_LENGTH);
  36. }
  37. static
  38. void
  39. enable(HWND dialog)
  40. {
  41. ASSERT(Win::IsWindow(dialog));
  42. int next =
  43. !Win::GetTrimmedDlgItemText(dialog, IDC_NETBIOS).empty()
  44. ? PSWIZB_NEXT : 0;
  45. Win::PropSheet_SetWizButtons(
  46. Win::GetParent(dialog),
  47. PSWIZB_BACK | next);
  48. }
  49. HRESULT
  50. MyDsRoleDnsNameToFlatName(
  51. const String& domainDNSName,
  52. String& result,
  53. bool& nameWasTweaked)
  54. {
  55. LOG_FUNCTION(MyDsRoleDnsNameToFlatName);
  56. ASSERT(!domainDNSName.empty());
  57. nameWasTweaked = false;
  58. result.erase();
  59. LOG(L"Calling DsRoleDnsNameToFlatName");
  60. LOG( L"lpServer : (null)");
  61. LOG(String::format(L"lpDnsName : %1", domainDNSName.c_str()));
  62. PWSTR flatName = 0;
  63. ULONG flags = 0;
  64. HRESULT hr =
  65. Win32ToHresult(
  66. ::DsRoleDnsNameToFlatName(
  67. 0, // this server
  68. domainDNSName.c_str(),
  69. &flatName,
  70. &flags));
  71. LOG_HRESULT(hr);
  72. if (SUCCEEDED(hr) && flatName)
  73. {
  74. LOG(String::format(L"lpFlatName : %1", flatName));
  75. LOG(String::format(L"lpStatusFlag : %1!X!", flags));
  76. result = flatName;
  77. if (result.length() > DNLEN)
  78. {
  79. result.resize(DNLEN);
  80. }
  81. ::DsRoleFreeMemory(flatName);
  82. // the name was tweaked if it is not the default. 338443
  83. nameWasTweaked = !(flags & DSROLE_FLATNAME_DEFAULT);
  84. }
  85. return hr;
  86. }
  87. // return true if the name generated has already been validated, false
  88. // if not.
  89. bool
  90. GenerateDefaultNetbiosName(HWND parent)
  91. {
  92. LOG_FUNCTION(GenerateDefaultNetbiosName);
  93. ASSERT(Win::IsWindow(parent));
  94. Win::CursorSetting cursor(IDC_WAIT);
  95. bool result = false;
  96. String dnsDomainName =
  97. InstallationUnitProvider::GetInstance().GetADInstallationUnit().GetNewDomainDNSName();
  98. bool nameWasTweaked = false;
  99. String generatedName;
  100. HRESULT hr =
  101. MyDsRoleDnsNameToFlatName(
  102. dnsDomainName,
  103. generatedName,
  104. nameWasTweaked);
  105. if (FAILED(hr))
  106. {
  107. // if the api call failed, the name could not have been validated.
  108. result = false;
  109. // fall back to just the first 15 characters of the first label
  110. generatedName =
  111. dnsDomainName.substr(0, min(DNLEN, dnsDomainName.find(L'.')));
  112. LOG(String::format(L"falling back to %1", generatedName.c_str()));
  113. }
  114. else
  115. {
  116. // the api validated the name for us.
  117. result = true;
  118. }
  119. generatedName.to_upper();
  120. if (generatedName.is_numeric())
  121. {
  122. // the generated name is all-numeric. This is not allowed. So we
  123. // toss it out. 368777 bis
  124. generatedName.erase();
  125. nameWasTweaked = false;
  126. }
  127. Win::SetDlgItemText(
  128. parent,
  129. IDC_NETBIOS,
  130. generatedName);
  131. // inform the user that the default NetBIOS name was adjusted due
  132. // to name collision on the network
  133. if (nameWasTweaked)
  134. {
  135. popup.Info(
  136. parent,
  137. String::format(
  138. IDS_GENERATED_NAME_WAS_TWEAKED,
  139. generatedName.c_str()));
  140. }
  141. return result;
  142. }
  143. bool
  144. NetbiosDomainPage::OnSetActive()
  145. {
  146. LOG_FUNCTION(NetbiosDomainPage::OnSetActive);
  147. Win::PropSheet_SetWizButtons(
  148. Win::GetParent(hwnd),
  149. PSWIZB_BACK);
  150. String dnsDomainName =
  151. InstallationUnitProvider::GetInstance().GetADInstallationUnit().GetNewDomainDNSName();
  152. Win::SetDlgItemText(
  153. hwnd,
  154. IDC_DOMAIN_DNS_EDIT,
  155. dnsDomainName);
  156. // do this here instead of in init to regenerate a default name if the
  157. // user has not annointed one already.
  158. if (InstallationUnitProvider::GetInstance().GetADInstallationUnit().GetNewDomainNetbiosName().empty())
  159. {
  160. GenerateDefaultNetbiosName(hwnd);
  161. }
  162. enable(hwnd);
  163. return true;
  164. }
  165. bool
  166. NetbiosDomainPage::OnCommand(
  167. HWND /* windowFrom */ ,
  168. unsigned controlIDFrom,
  169. unsigned code)
  170. {
  171. // LOG_FUNCTION(NetbiosDomainPage::OnCommand);
  172. switch (controlIDFrom)
  173. {
  174. case IDC_NETBIOS:
  175. {
  176. if (code == EN_CHANGE)
  177. {
  178. SetChanged(controlIDFrom);
  179. enable(hwnd);
  180. }
  181. break;
  182. }
  183. default:
  184. {
  185. // do nothing
  186. break;
  187. }
  188. }
  189. return false;
  190. }
  191. int
  192. NetbiosDomainPage::Validate()
  193. {
  194. LOG_FUNCTION(NetbiosDomainPage::Validate);
  195. int nextPage = IDD_MILESTONE_PAGE;
  196. if (!ValidateDomainNetbiosName(hwnd, IDC_NETBIOS, popup))
  197. {
  198. nextPage = -1;
  199. }
  200. else
  201. {
  202. String netbiosName = Win::GetTrimmedDlgItemText(hwnd, IDC_NETBIOS);
  203. InstallationUnitProvider::GetInstance().GetADInstallationUnit().SetNewDomainNetbiosName(netbiosName);
  204. // If there is more than one NIC we need to offer the user routing
  205. // and firewall. This also ensures we can distinguish between
  206. // the public and private NICs
  207. if (State::GetInstance().GetNICCount() > 1)
  208. {
  209. InstallationUnitProvider::GetInstance().
  210. GetRRASInstallationUnit().SetExpressPathValues(true);
  211. }
  212. // Check to see if there are any DNS servers configured
  213. // on any of the interfaces. If there are then we will just
  214. // use those. If not we will ask the user to provide them
  215. // using the DNS Forwarders page.
  216. if (!State::GetInstance().HasDNSServerOnAnyNicToForwardTo())
  217. {
  218. nextPage = IDD_DNS_FORWARDER_PAGE;
  219. }
  220. }
  221. return nextPage;
  222. }