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.

177 lines
2.8 KiB

  1. // Copyright (C) 1997-2000 Microsoft Corporation
  2. //
  3. // get syskey on diskette 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 "SyskeyDiskDialog.hpp"
  10. #include "state.hpp"
  11. static const DWORD HELP_MAP[] =
  12. {
  13. 0, 0
  14. };
  15. SyskeyDiskDialog::SyskeyDiskDialog()
  16. :
  17. Dialog(IDD_SYSKEY_DISK, HELP_MAP)
  18. {
  19. LOG_CTOR(SyskeyDiskDialog);
  20. }
  21. SyskeyDiskDialog::~SyskeyDiskDialog()
  22. {
  23. LOG_DTOR(SyskeyDiskDialog);
  24. }
  25. void
  26. SyskeyDiskDialog::OnInit()
  27. {
  28. LOG_FUNCTION(SyskeyDiskDialog::OnInit);
  29. State& state = State::GetInstance();
  30. if (state.RunHiddenUnattended())
  31. {
  32. if (Validate())
  33. {
  34. Win::EndDialog(hwnd, IDOK);
  35. }
  36. else
  37. {
  38. state.ClearHiddenWhileUnattended();
  39. }
  40. }
  41. }
  42. bool
  43. SyskeyDiskDialog::OnCommand(
  44. HWND /* windowFrom */ ,
  45. unsigned controlIdFrom,
  46. unsigned code)
  47. {
  48. // LOG_FUNCTION(SyskeyDiskDialog::OnCommand);
  49. switch (controlIdFrom)
  50. {
  51. case IDOK:
  52. {
  53. if (code == BN_CLICKED)
  54. {
  55. if (Validate())
  56. {
  57. Win::EndDialog(hwnd, controlIdFrom);
  58. }
  59. }
  60. break;
  61. }
  62. case IDCANCEL:
  63. {
  64. if (code == BN_CLICKED)
  65. {
  66. Win::EndDialog(hwnd, controlIdFrom);
  67. }
  68. break;
  69. }
  70. default:
  71. {
  72. // do nothing
  73. break;
  74. }
  75. }
  76. return false;
  77. }
  78. HRESULT
  79. SyskeyDiskDialog::LocateSyskey(HWND hwnd)
  80. {
  81. LOG_FUNCTION(LocateSyskey);
  82. HRESULT hr = S_OK;
  83. do
  84. {
  85. if (FS::PathExists(L"A:\\StartKey.Key"))
  86. {
  87. LOG(L"syskey found on a:");
  88. // The only drive the syskey may be present on is A:. Winlogon
  89. // also hardcodes A:, which they may change someday, but not today.
  90. // NTRAID#NTBUG9-522068-2002/01/23-sburns
  91. EncryptedString es;
  92. es.Encrypt(L"A:");
  93. State::GetInstance().SetSyskey(es);
  94. break;
  95. }
  96. hr = E_FAIL;
  97. if (hwnd)
  98. {
  99. popup.Error(hwnd, IDS_SYSKEY_NOT_FOUND);
  100. }
  101. }
  102. while (0);
  103. LOG_HRESULT(hr);
  104. return hr;
  105. }
  106. bool
  107. SyskeyDiskDialog::Validate()
  108. {
  109. LOG_FUNCTION(SyskeyDiskDialog::Validate);
  110. bool result = false;
  111. do
  112. {
  113. // look for the syskey
  114. HRESULT hr = LocateSyskey(hwnd);
  115. if (FAILED(hr))
  116. {
  117. // LocateSyskey will take care of emitting error messages, so
  118. // we just need to bail out here
  119. break;
  120. }
  121. result = true;
  122. }
  123. while (0);
  124. LOG(result ? L"true" : L"false");
  125. return result;
  126. }