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.

159 lines
2.6 KiB

  1. // Copyright (C) 1997-2000 Microsoft Corporation
  2. //
  3. // get syskey for replica from media page
  4. //
  5. // 25 Apr 2000 sburns
  6. #include "headers.hxx"
  7. #include "resource.h"
  8. #include "page.hpp"
  9. #include "SyskeyPromptDialog.hpp"
  10. #include "state.hpp"
  11. static const DWORD HELP_MAP[] =
  12. {
  13. 0, 0
  14. };
  15. SyskeyPromptDialog::SyskeyPromptDialog()
  16. :
  17. Dialog(IDD_SYSKEY_PROMPT, HELP_MAP)
  18. {
  19. LOG_CTOR(SyskeyPromptDialog);
  20. }
  21. SyskeyPromptDialog::~SyskeyPromptDialog()
  22. {
  23. LOG_DTOR(SyskeyPromptDialog);
  24. }
  25. void
  26. SyskeyPromptDialog::OnInit()
  27. {
  28. LOG_FUNCTION(SyskeyPromptDialog::OnInit);
  29. Win::Edit_LimitText(Win::GetDlgItem(hwnd, IDC_SYSKEY), PWLEN);
  30. State& state = State::GetInstance();
  31. if (state.UsingAnswerFile())
  32. {
  33. EncryptedString option =
  34. state.GetEncryptedAnswerFileOption(AnswerFile::OPTION_SYSKEY);
  35. if (!option.IsEmpty())
  36. {
  37. Win::SetDlgItemText(hwnd, IDC_SYSKEY, option);
  38. }
  39. }
  40. if (state.RunHiddenUnattended())
  41. {
  42. if (Validate())
  43. {
  44. Win::EndDialog(hwnd, IDOK);
  45. }
  46. else
  47. {
  48. state.ClearHiddenWhileUnattended();
  49. }
  50. }
  51. }
  52. bool
  53. SyskeyPromptDialog::OnCommand(
  54. HWND /* windowFrom */ ,
  55. unsigned controlIdFrom,
  56. unsigned code)
  57. {
  58. // LOG_FUNCTION(SyskeyPromptDialog::OnCommand);
  59. switch (controlIdFrom)
  60. {
  61. case IDC_SYSKEY:
  62. {
  63. if (code == EN_CHANGE)
  64. {
  65. SetChanged(controlIdFrom);
  66. return true;
  67. }
  68. break;
  69. }
  70. case IDOK:
  71. {
  72. if (code == BN_CLICKED)
  73. {
  74. if (Validate())
  75. {
  76. Win::EndDialog(hwnd, controlIdFrom);
  77. }
  78. }
  79. break;
  80. }
  81. case IDCANCEL:
  82. {
  83. if (code == BN_CLICKED)
  84. {
  85. Win::EndDialog(hwnd, controlIdFrom);
  86. }
  87. break;
  88. }
  89. default:
  90. {
  91. // do nothing
  92. break;
  93. }
  94. }
  95. return false;
  96. }
  97. bool
  98. SyskeyPromptDialog::Validate()
  99. {
  100. LOG_FUNCTION(SyskeyPromptDialog::Validate);
  101. State& state = State::GetInstance();
  102. bool result = false;
  103. do
  104. {
  105. EncryptedString syskey =
  106. Win::GetEncryptedDlgItemText(hwnd, IDC_SYSKEY);
  107. if (syskey.IsEmpty())
  108. {
  109. popup.Gripe(hwnd, IDC_SYSKEY, IDS_MUST_ENTER_SYSKEY);
  110. break;
  111. }
  112. state.SetSyskey(syskey);
  113. result = true;
  114. }
  115. while (0);
  116. LOG(result ? L"true" : L"false");
  117. return result;
  118. }