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.

182 lines
3.3 KiB

  1. // Copyright (C) 1997 Microsoft Corporation
  2. //
  3. // Admin password page
  4. //
  5. // 2-4-98 sburns
  6. #include "headers.hxx"
  7. #include "adpass.hpp"
  8. #include "resource.h"
  9. #include "state.hpp"
  10. #include "ds.hpp"
  11. AdminPasswordPage::AdminPasswordPage()
  12. :
  13. DCPromoWizardPage(
  14. IDD_ADMIN_PASSWORD,
  15. IDS_PASSWORD_PAGE_TITLE,
  16. IDS_PASSWORD_PAGE_SUBTITLE)
  17. {
  18. LOG_CTOR(AdminPasswordPage);
  19. }
  20. AdminPasswordPage::~AdminPasswordPage()
  21. {
  22. LOG_DTOR(AdminPasswordPage);
  23. }
  24. void
  25. AdminPasswordPage::OnInit()
  26. {
  27. LOG_FUNCTION(AdminPasswordPage::OnInit);
  28. // NTRAID#NTBUG9-202238-2000/11/07-sburns
  29. password.Init(Win::GetDlgItem(hwnd, IDC_PASSWORD));
  30. confirm.Init(Win::GetDlgItem(hwnd, IDC_CONFIRM));
  31. State& state = State::GetInstance();
  32. if (state.UsingAnswerFile())
  33. {
  34. EncodedString pwd =
  35. state.GetEncodedAnswerFileOption(State::OPTION_ADMIN_PASSWORD);
  36. Win::SetDlgItemText(hwnd, IDC_PASSWORD, pwd);
  37. Win::SetDlgItemText(hwnd, IDC_CONFIRM, pwd);
  38. }
  39. }
  40. static
  41. String
  42. getPasswordMessage()
  43. {
  44. LOG_FUNCTION(getPasswordMessage);
  45. State& state = State::GetInstance();
  46. unsigned id = IDS_ENTER_DOMAIN_ADMIN_PASSWORD;
  47. switch (state.GetOperation())
  48. {
  49. case State::FOREST:
  50. case State::TREE:
  51. case State::CHILD:
  52. {
  53. // do nothing, id is already set.
  54. break;
  55. }
  56. case State::ABORT_BDC_UPGRADE:
  57. case State::DEMOTE:
  58. {
  59. id = IDS_ENTER_LOCAL_ADMIN_PASSWORD;
  60. break;
  61. }
  62. case State::REPLICA:
  63. case State::NONE:
  64. default:
  65. {
  66. ASSERT(false);
  67. break;
  68. }
  69. }
  70. return String::load(id);
  71. }
  72. bool
  73. AdminPasswordPage::OnSetActive()
  74. {
  75. LOG_FUNCTION(AdminPasswordPage::OnSetActive);
  76. State& state = State::GetInstance();
  77. if (state.RunHiddenUnattended())
  78. {
  79. // fully-qualify the Validate call, as it is virtual...
  80. int nextPage = AdminPasswordPage::Validate();
  81. if (nextPage != -1)
  82. {
  83. GetWizard().SetNextPageID(hwnd, nextPage);
  84. }
  85. else
  86. {
  87. state.ClearHiddenWhileUnattended();
  88. }
  89. }
  90. Win::PropSheet_SetWizButtons(
  91. Win::GetParent(hwnd),
  92. PSWIZB_BACK | PSWIZB_NEXT);
  93. Win::SetDlgItemText(hwnd, IDC_MESSAGE, getPasswordMessage());
  94. return true;
  95. }
  96. int
  97. AdminPasswordPage::Validate()
  98. {
  99. LOG_FUNCTION(AdminPasswordPage::Validate);
  100. EncodedString password =
  101. Win::GetEncodedDlgItemText(hwnd, IDC_PASSWORD);
  102. EncodedString confirm =
  103. Win::GetEncodedDlgItemText(hwnd, IDC_CONFIRM);
  104. if (password != confirm)
  105. {
  106. String blank;
  107. Win::SetDlgItemText(hwnd, IDC_PASSWORD, blank);
  108. Win::SetDlgItemText(hwnd, IDC_CONFIRM, blank);
  109. popup.Gripe(
  110. hwnd,
  111. IDC_PASSWORD,
  112. IDS_PASSWORD_MISMATCH);
  113. return -1;
  114. }
  115. State& state = State::GetInstance();
  116. state.SetAdminPassword(password);
  117. int nextPage = -1;
  118. switch (state.GetOperation())
  119. {
  120. case State::ABORT_BDC_UPGRADE:
  121. case State::DEMOTE:
  122. {
  123. nextPage = IDD_CONFIRMATION;
  124. break;
  125. }
  126. case State::REPLICA:
  127. case State::FOREST:
  128. case State::TREE:
  129. case State::CHILD:
  130. case State::NONE:
  131. default:
  132. {
  133. ASSERT(false);
  134. break;
  135. }
  136. }
  137. return nextPage;
  138. }