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.

96 lines
2.5 KiB

  1. #include "mslocusr.h"
  2. #include "msluglob.h"
  3. #include <md5.h>
  4. HRESULT VerifySupervisorPassword(LPCSTR pszPassword)
  5. {
  6. #ifdef MSLOCUSR_USE_SUPERVISOR_PASSWORD
  7. if (!::fSupervisorKeyInit) {
  8. HKEY hkeyRating;
  9. LONG err;
  10. err = RegOpenKey(HKEY_LOCAL_MACHINE, ::szRATINGS, &hkeyRating);
  11. if (hkeyRating != NULL) {
  12. DWORD cbData = sizeof(::abSupervisorKey);
  13. DWORD dwType;
  14. err = ::RegQueryValueEx(hkeyRating, ::szRatingsSupervisorKeyName, NULL,
  15. &dwType, (LPBYTE)::abSupervisorKey, &cbData);
  16. if (err != ERROR_SUCCESS)
  17. err = ::RegQueryValueEx(hkeyRating, ::szUsersSupervisorKeyName, NULL,
  18. &dwType, (LPBYTE)::abSupervisorKey, &cbData);
  19. ::RegCloseKey(hkeyRating);
  20. if (err == ERROR_SUCCESS) {
  21. if (dwType != REG_BINARY || cbData != sizeof(::abSupervisorKey)) {
  22. return E_UNEXPECTED;
  23. }
  24. ::fSupervisorKeyInit = TRUE;
  25. }
  26. }
  27. else
  28. err = ERROR_FILE_NOT_FOUND;
  29. if (err != ERROR_SUCCESS) {
  30. return HRESULT_FROM_WIN32(err);
  31. }
  32. }
  33. if (pszPassword == NULL)
  34. return ResultFromScode(S_FALSE);
  35. MD5_CTX ctx;
  36. MD5Init(&ctx);
  37. MD5Update(&ctx, (const BYTE *)pszPassword, ::strlenf(pszPassword)+1);
  38. MD5Final(&ctx);
  39. return ResultFromScode(::memcmpf(::abSupervisorKey, ctx.digest, sizeof(::abSupervisorKey)) ? S_FALSE : S_OK);
  40. #else
  41. return S_OK; /* everybody's a supervisor */
  42. #endif
  43. }
  44. HRESULT ChangeSupervisorPassword(LPCSTR pszOldPassword, LPCSTR pszNewPassword)
  45. {
  46. #ifdef MSLOCUSR_USE_SUPERVISOR_PASSWORD
  47. HRESULT hres;
  48. hres = ::VerifySupervisorPassword(pszOldPassword);
  49. if (hres == S_FALSE) {
  50. return E_ACCESSDENIED;
  51. }
  52. MD5_CTX ctx;
  53. MD5Init(&ctx);
  54. MD5Update(&ctx, (const BYTE *)pszNewPassword, ::strlenf(pszNewPassword)+1);
  55. MD5Final(&ctx);
  56. ::memcpyf(::abSupervisorKey, ctx.digest, sizeof(::abSupervisorKey));
  57. ::fSupervisorKeyInit = TRUE;
  58. HKEY hkeyRating;
  59. LONG err = RegOpenKey(HKEY_LOCAL_MACHINE, ::szRATINGS, &hkeyRating);
  60. if (err == ERROR_SUCCESS) {
  61. char abTemp[sizeof(::abSupervisorKey)];
  62. LPCSTR pszValueToSet;
  63. DWORD dwType;
  64. DWORD cbData = sizeof(abTemp);
  65. if (::RegQueryValueEx(hkeyRating, ::szRatingsSupervisorKeyName, NULL,
  66. &dwType, (LPBYTE)abTemp, &cbData) == ERROR_SUCCESS)
  67. pszValueToSet = ::szRatingsSupervisorKeyName;
  68. else
  69. pszValueToSet = ::szUsersSupervisorKeyName;
  70. ::RegSetValueEx(hkeyRating, pszValueToSet, NULL,
  71. REG_BINARY, (const BYTE *)::abSupervisorKey, sizeof(::abSupervisorKey));
  72. ::RegCloseKey(hkeyRating);
  73. }
  74. #endif
  75. return NOERROR;
  76. }