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.

195 lines
4.1 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 "common.hpp"
  11. #include "ds.hpp"
  12. SafeModePasswordPage::SafeModePasswordPage()
  13. :
  14. DCPromoWizardPage(
  15. IDD_SAFE_MODE_PASSWORD,
  16. IDS_SAFE_MODE_PASSWORD_PAGE_TITLE,
  17. IDS_SAFE_MODE_PASSWORD_PAGE_SUBTITLE)
  18. {
  19. LOG_CTOR(SafeModePasswordPage);
  20. }
  21. SafeModePasswordPage::~SafeModePasswordPage()
  22. {
  23. LOG_DTOR(SafeModePasswordPage);
  24. }
  25. // NTRAID#NTBUG9-510389-2002/01/22-sburns
  26. bool
  27. SafeModePasswordPage::OnNotify(
  28. HWND /* windowFrom */ ,
  29. UINT_PTR controlIDFrom,
  30. UINT code,
  31. LPARAM /* lParam */ )
  32. {
  33. // LOG_FUNCTION(WelcomePage::OnNotify);
  34. bool result = false;
  35. switch (code)
  36. {
  37. case NM_CLICK:
  38. case NM_RETURN:
  39. {
  40. switch (controlIDFrom)
  41. {
  42. case IDC_HELP_LINK:
  43. {
  44. Win::HtmlHelp(
  45. hwnd,
  46. L"adconcepts.chm::/adhelpdcpromo_DSrestorepage.htm",
  47. HH_DISPLAY_TOPIC,
  48. 0);
  49. result = true;
  50. break;
  51. }
  52. default:
  53. {
  54. // do nothing
  55. break;
  56. }
  57. }
  58. }
  59. default:
  60. {
  61. // do nothing
  62. break;
  63. }
  64. }
  65. return result;
  66. }
  67. void
  68. SafeModePasswordPage::OnInit()
  69. {
  70. LOG_FUNCTION(SafeModePasswordPage::OnInit);
  71. // NTRAID#NTBUG9-202238-2000/11/07-sburns
  72. password.Init(Win::GetDlgItem(hwnd, IDC_PASSWORD));
  73. confirm.Init(Win::GetDlgItem(hwnd, IDC_CONFIRM));
  74. State& state = State::GetInstance();
  75. if (state.UsingAnswerFile())
  76. {
  77. EncryptedString pwd =
  78. state.GetEncryptedAnswerFileOption(
  79. AnswerFile::OPTION_SAFE_MODE_ADMIN_PASSWORD);
  80. Win::SetDlgItemText(hwnd, IDC_PASSWORD, pwd);
  81. Win::SetDlgItemText(hwnd, IDC_CONFIRM, pwd);
  82. }
  83. Win::PostMessage(
  84. Win::GetParent(hwnd),
  85. WM_NEXTDLGCTL,
  86. reinterpret_cast<WPARAM>(Win::GetDlgItem(hwnd, IDC_PASSWORD)),
  87. TRUE);
  88. }
  89. bool
  90. SafeModePasswordPage::OnSetActive()
  91. {
  92. LOG_FUNCTION(SafeModePasswordPage::OnSetActive);
  93. State& state = State::GetInstance();
  94. if (state.RunHiddenUnattended())
  95. {
  96. if (
  97. ( state.GetRunContext() == State::BDC_UPGRADE
  98. || state.GetRunContext() == State::PDC_UPGRADE)
  99. && !state.IsSafeModeAdminPwdOptionPresent())
  100. {
  101. // If you are upgrading a downlevel DC, and running unattended, then
  102. // you must specify a safemode password. In a non-upgrade case, if
  103. // the user does not specify a safemode password, we pass a flag to
  104. // the promote APIs to copy the current user's password as the
  105. // safemode password. In the upgrade case, the system is running
  106. // under a bogus account with a random password, so copying that
  107. // random password would be a bad idea. So we force the user to
  108. // supply a password.
  109. state.ClearHiddenWhileUnattended();
  110. popup.Gripe(
  111. hwnd,
  112. IDC_PASSWORD,
  113. IDS_SAFEMODE_PASSWORD_REQUIRED);
  114. }
  115. else
  116. {
  117. int nextPage = Validate();
  118. if (nextPage != -1)
  119. {
  120. GetWizard().SetNextPageID(hwnd, nextPage);
  121. }
  122. else
  123. {
  124. state.ClearHiddenWhileUnattended();
  125. }
  126. }
  127. }
  128. Win::PropSheet_SetWizButtons(
  129. Win::GetParent(hwnd),
  130. PSWIZB_BACK | PSWIZB_NEXT);
  131. return true;
  132. }
  133. int
  134. SafeModePasswordPage::Validate()
  135. {
  136. LOG_FUNCTION(SafeModePasswordPage::Validate);
  137. int result = -1;
  138. EncryptedString password;
  139. if (IsValidPassword(hwnd, IDC_PASSWORD, IDC_CONFIRM, true, password))
  140. {
  141. State::GetInstance().SetSafeModeAdminPassword(password);
  142. result = IDD_CONFIRMATION;
  143. }
  144. return result;
  145. }