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.

116 lines
3.2 KiB

  1. // --------------------------------------------------------------------------
  2. // Module Name: UserSettings.h
  3. //
  4. // Copyright (c) 2000, Microsoft Corporation
  5. //
  6. // A class to handle opening and reading/writing from the HKCU key in either
  7. // an impersonation context or not.
  8. //
  9. // History: 2000-04-26 vtan created
  10. // --------------------------------------------------------------------------
  11. #include "StandardHeader.h"
  12. #include "UserSettings.h"
  13. #include <sddl.h>
  14. #include "RegistryResources.h"
  15. #include "TokenInformation.h"
  16. // --------------------------------------------------------------------------
  17. // CUserSettings::CUserSettings
  18. //
  19. // Arguments:
  20. //
  21. // Returns: <none>
  22. //
  23. // Purpose:
  24. //
  25. // History: 2000-04-26 vtan created
  26. // --------------------------------------------------------------------------
  27. CUserSettings::CUserSettings (void) :
  28. _hKeyCurrentUser(HKEY_CURRENT_USER)
  29. {
  30. HANDLE hToken;
  31. if (OpenThreadToken(GetCurrentThread(), TOKEN_QUERY, FALSE, &hToken) != FALSE)
  32. {
  33. PSID pSID;
  34. CTokenInformation tokenInformation(hToken);
  35. pSID = tokenInformation.GetUserSID();
  36. if (pSID != NULL)
  37. {
  38. LPTSTR pszSIDString;
  39. if (ConvertSidToStringSid(pSID, &pszSIDString) != FALSE)
  40. {
  41. TW32(RegOpenKeyEx(HKEY_USERS,
  42. pszSIDString,
  43. 0,
  44. KEY_READ,
  45. &_hKeyCurrentUser));
  46. ReleaseMemory(pszSIDString);
  47. }
  48. }
  49. TBOOL(CloseHandle(hToken));
  50. }
  51. }
  52. // --------------------------------------------------------------------------
  53. // CUserSettings::~CUserSettings
  54. //
  55. // Arguments:
  56. //
  57. // Returns: <none>
  58. //
  59. // Purpose:
  60. //
  61. // History: 2000-04-26 vtan created
  62. // --------------------------------------------------------------------------
  63. CUserSettings::~CUserSettings (void)
  64. {
  65. if (HKEY_CURRENT_USER != _hKeyCurrentUser)
  66. {
  67. TW32(RegCloseKey(_hKeyCurrentUser));
  68. _hKeyCurrentUser = HKEY_CURRENT_USER;
  69. }
  70. }
  71. // --------------------------------------------------------------------------
  72. // CUserSettings::IsRestrictedNoClose
  73. //
  74. // Arguments:
  75. //
  76. // Returns: bool
  77. //
  78. // Purpose:
  79. //
  80. // History: 2000-04-26 vtan created
  81. // --------------------------------------------------------------------------
  82. bool CUserSettings::IsRestrictedNoClose (void)
  83. {
  84. bool fIsRestrictedNoClose;
  85. CRegKey regKey;
  86. fIsRestrictedNoClose = false;
  87. if (ERROR_SUCCESS == regKey.Open(_hKeyCurrentUser,
  88. TEXT("Software\\Microsoft\\Windows\\CurrentVersion\\Policies\\Explorer"),
  89. KEY_QUERY_VALUE))
  90. {
  91. DWORD dwValue;
  92. if (ERROR_SUCCESS == regKey.GetDWORD(TEXT("NoClose"),
  93. dwValue))
  94. {
  95. fIsRestrictedNoClose = (dwValue != 0);
  96. }
  97. }
  98. return(fIsRestrictedNoClose);
  99. }