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.

228 lines
5.5 KiB

  1. // Copyright (C) 2001 Microsoft Corporation
  2. //
  3. // verify that the domain of this upgraded BDC has been upgraded to
  4. // Active Directory, and that we can find a DS DC for that domain
  5. // NTRAID#NTBUG9-490197-2001/11/20-sburns
  6. //
  7. // 20 Nov 2001 sburns
  8. #include "headers.hxx"
  9. #include "page.hpp"
  10. #include "CheckDomainUpgradedPage.hpp"
  11. #include "resource.h"
  12. #include "state.hpp"
  13. #include "common.hpp"
  14. CheckDomainUpgradedPage::CheckDomainUpgradedPage()
  15. :
  16. DCPromoWizardPage(
  17. IDD_CHECK_DOMAIN_UPGRADED,
  18. IDS_CHECK_DOMAIN_UPGRADED_TITLE,
  19. IDS_CHECK_DOMAIN_UPGRADED_SUBTITLE)
  20. {
  21. LOG_CTOR(CheckDomainUpgradedPage);
  22. }
  23. CheckDomainUpgradedPage::~CheckDomainUpgradedPage()
  24. {
  25. LOG_DTOR(CheckDomainUpgradedPage);
  26. }
  27. // bool
  28. // CheckDomainUpgradedPage::OnNotify(
  29. // HWND /* windowFrom */ ,
  30. // UINT_PTR controlIDFrom,
  31. // UINT code,
  32. // LPARAM /* lParam */ )
  33. // {
  34. // // LOG_FUNCTION(CheckDomainUpgradedPage::OnNotify);
  35. //
  36. // bool result = false;
  37. //
  38. // if (controlIDFrom == IDC_JUMP)
  39. // {
  40. // switch (code)
  41. // {
  42. // case NM_CLICK:
  43. // case NM_RETURN:
  44. // {
  45. // ShowTroubleshooter(hwnd, IDS_CONFIG_DNS_HELP_TOPIC);
  46. // result = true;
  47. // }
  48. // default:
  49. // {
  50. // // do nothing
  51. //
  52. // break;
  53. // }
  54. // }
  55. // }
  56. //
  57. // return result;
  58. // }
  59. void
  60. CheckDomainUpgradedPage::OnInit()
  61. {
  62. LOG_FUNCTION(CheckDomainUpgradedPage::OnInit);
  63. }
  64. bool
  65. CheckDomainUpgradedPage::OnSetActive()
  66. {
  67. LOG_FUNCTION(CheckDomainUpgradedPage::OnSetActive);
  68. State& state = State::GetInstance();
  69. ASSERT(state.GetRunContext() == State::BDC_UPGRADE);
  70. ASSERT(state.GetOperation() == State::REPLICA);
  71. if (state.RunHiddenUnattended() || CheckDsDcFoundAndUpdatePageText())
  72. {
  73. LOG(L"planning to Skip CheckDomainUpgradedPage");
  74. Wizard& wiz = GetWizard();
  75. if (wiz.IsBacktracking())
  76. {
  77. // backup once again
  78. wiz.Backtrack(hwnd);
  79. return true;
  80. }
  81. int nextPage = CheckDomainUpgradedPage::Validate();
  82. if (nextPage != -1)
  83. {
  84. LOG(L"skipping CheckDomainUpgradedPage");
  85. wiz.SetNextPageID(hwnd, nextPage);
  86. return true;
  87. }
  88. state.ClearHiddenWhileUnattended();
  89. }
  90. Win::PropSheet_SetWizButtons(
  91. Win::GetParent(hwnd),
  92. PSWIZB_BACK | PSWIZB_NEXT);
  93. return true;
  94. }
  95. int
  96. CheckDomainUpgradedPage::Validate()
  97. {
  98. LOG_FUNCTION(CheckDomainUpgradedPage::Validate);
  99. int nextPage = -1;
  100. if (CheckDsDcFoundAndUpdatePageText())
  101. {
  102. nextPage = IDD_GET_CREDENTIALS;
  103. }
  104. else
  105. {
  106. String message = String::load(IDS_CONVERT_PDC_FIRST);
  107. popup.Info(hwnd, message);
  108. }
  109. return nextPage;
  110. }
  111. // Returns true if the domain that this machine was a BDC for has been
  112. // upgraded to Active Directory, false if not, or if we can't tell. We tell
  113. // by attempting to find a DS DC for the domain. We set the page text and
  114. // save the domain name based on our attempt.
  115. bool
  116. CheckDomainUpgradedPage::CheckDsDcFoundAndUpdatePageText()
  117. {
  118. LOG_FUNCTION(CheckDomainUpgradedPage::CheckDsDcFoundAndUpdatePageText);
  119. State& state = State::GetInstance();
  120. bool result = false;
  121. int messageId = IDS_DOMAIN_NOT_UPGRADED_OR_NETWORK_ERROR;
  122. String domainNetbiosName = state.GetComputer().GetDomainNetbiosName();
  123. Win::WaitCursor wait;
  124. do
  125. {
  126. // First, attempt to find a DS DC
  127. DOMAIN_CONTROLLER_INFO* info = 0;
  128. HRESULT hr =
  129. MyDsGetDcName(
  130. 0,
  131. domainNetbiosName,
  132. DS_DIRECTORY_SERVICE_REQUIRED | DS_RETURN_DNS_NAME,
  133. info);
  134. if (SUCCEEDED(hr) && info)
  135. {
  136. if ((info->Flags & DS_DNS_DOMAIN_FLAG) && info->DomainName)
  137. {
  138. // we found a DS domain
  139. state.SetReplicaDomainDNSName(info->DomainName);
  140. messageId = IDS_DOMAIN_WAS_UPGRADED;
  141. result = true;
  142. }
  143. ::NetApiBufferFree(info);
  144. break;
  145. }
  146. // That attempt failed, so try again for any DC (DS or otherwise) for
  147. // the domain.
  148. // This is not a Dr. DNS (DiagnoseDcNotFound) failure case, since the
  149. // code to get the domain name is not using the DNS domain name.
  150. hr = MyDsGetDcName(0, domainNetbiosName, 0, info);
  151. if (SUCCEEDED(hr) && info)
  152. {
  153. // If that succeeds, then we know the that domain is not upgraded
  154. // yet, or that a DS DC of the domain is not reachable via its
  155. // netbios name, which is probably a net connectivity problem or
  156. // WINS problem.
  157. ::NetApiBufferFree(info);
  158. messageId = IDS_DOMAIN_NOT_UPGRADED_OR_NETWORK_ERROR;
  159. break;
  160. }
  161. // Here, we can't find a DC of any kind for the domain.
  162. // If that fails, then we can't find any dc for the domain, and
  163. // have a net connectivty or WINS problem.
  164. messageId = IDS_NETWORK_ERROR;
  165. }
  166. while (0);
  167. Win::SetDlgItemText(
  168. hwnd,
  169. IDC_MESSAGE,
  170. String::format(messageId, domainNetbiosName.c_str()));
  171. return result;
  172. }