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.

147 lines
3.2 KiB

  1. // Copyright (C) 1999 Microsoft Corporation
  2. //
  3. // Safe Mode Administrator password page
  4. //
  5. // 6-3-99 sburns
  6. #include "headers.hxx"
  7. #include "safemode.hpp"
  8. #include "resource.h"
  9. #include "state.hpp"
  10. #include "ds.hpp"
  11. SafeModePasswordPage::SafeModePasswordPage()
  12. :
  13. DCPromoWizardPage(
  14. IDD_SAFE_MODE_PASSWORD,
  15. IDS_SAFE_MODE_PASSWORD_PAGE_TITLE,
  16. IDS_SAFE_MODE_PASSWORD_PAGE_SUBTITLE)
  17. {
  18. LOG_CTOR(SafeModePasswordPage);
  19. }
  20. SafeModePasswordPage::~SafeModePasswordPage()
  21. {
  22. LOG_DTOR(SafeModePasswordPage);
  23. }
  24. void
  25. SafeModePasswordPage::OnInit()
  26. {
  27. LOG_FUNCTION(SafeModePasswordPage::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(
  36. State::OPTION_SAFE_MODE_ADMIN_PASSWORD);
  37. Win::SetDlgItemText(hwnd, IDC_PASSWORD, pwd);
  38. Win::SetDlgItemText(hwnd, IDC_CONFIRM, pwd);
  39. }
  40. }
  41. bool
  42. SafeModePasswordPage::OnSetActive()
  43. {
  44. LOG_FUNCTION(SafeModePasswordPage::OnSetActive);
  45. State& state = State::GetInstance();
  46. if (state.RunHiddenUnattended())
  47. {
  48. if (
  49. ( state.GetRunContext() == State::BDC_UPGRADE
  50. || state.GetRunContext() == State::PDC_UPGRADE)
  51. && !state.IsSafeModeAdminPwdOptionPresent())
  52. {
  53. // If you are upgrading a downlevel DC, and running unattended, then
  54. // you must specify a safemode password. In a non-upgrade case, if
  55. // the user does not specify a safemode password, we pass a flag to
  56. // the promote APIs to copy the current user's password as the
  57. // safemode password. In the upgrade case, the system is running
  58. // under a bogus account with a random password, so copying that
  59. // random password would be a bad idea. So we force the user to
  60. // supply a password.
  61. state.ClearHiddenWhileUnattended();
  62. popup.Gripe(
  63. hwnd,
  64. IDC_PASSWORD,
  65. IDS_SAFEMODE_PASSWORD_REQUIRED);
  66. }
  67. else
  68. {
  69. int nextPage = Validate();
  70. if (nextPage != -1)
  71. {
  72. GetWizard().SetNextPageID(hwnd, nextPage);
  73. }
  74. else
  75. {
  76. state.ClearHiddenWhileUnattended();
  77. }
  78. }
  79. }
  80. Win::PropSheet_SetWizButtons(
  81. Win::GetParent(hwnd),
  82. PSWIZB_BACK | PSWIZB_NEXT);
  83. return true;
  84. }
  85. int
  86. SafeModePasswordPage::Validate()
  87. {
  88. LOG_FUNCTION(SafeModePasswordPage::Validate);
  89. EncodedString password =
  90. Win::GetEncodedDlgItemText(hwnd, IDC_PASSWORD);
  91. EncodedString confirm =
  92. Win::GetEncodedDlgItemText(hwnd, IDC_CONFIRM);
  93. if (password != confirm)
  94. {
  95. String blank;
  96. Win::SetDlgItemText(hwnd, IDC_PASSWORD, blank);
  97. Win::SetDlgItemText(hwnd, IDC_CONFIRM, blank);
  98. popup.Gripe(
  99. hwnd,
  100. IDC_PASSWORD,
  101. IDS_PASSWORD_MISMATCH);
  102. return -1;
  103. }
  104. State& state = State::GetInstance();
  105. state.SetSafeModeAdminPassword(password);
  106. return IDD_CONFIRMATION;
  107. }