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.

144 lines
3.9 KiB

  1. //+---------------------------------------------------------------------------
  2. //
  3. // Scheduling Agent Service
  4. //
  5. // Microsoft Windows
  6. // Copyright (C) Microsoft Corporation, 1992 - 1996.
  7. //
  8. // File: policy.cxx
  9. //
  10. // Contents: Functions for implementing policy checking
  11. //
  12. // Classes: None.
  13. //
  14. // Functions: RegReadPolicyKey
  15. //
  16. // History: 04/23/98 CameronE created
  17. //
  18. //----------------------------------------------------------------------------
  19. #include "..\pch\headers.hxx"
  20. #pragma hdrstop
  21. #include "..\inc\policy.hxx"
  22. #include "..\inc\debug.hxx"
  23. #include <StrSafe.h>
  24. //+---------------------------------------------------------------------------
  25. //
  26. // Function: RegReadPolicyKey
  27. //
  28. // Synopsis: Determine whether a specified policy value is in the registry
  29. // and is on (exists, value > 0x0). Policy on means deny
  30. // the user permission to do a particular action in the UI only.
  31. //
  32. // Arguments: [lpszValue] -- value name, appended to the base key
  33. //
  34. // Returns: BOOL - true for value > 0 (policy active)
  35. //
  36. // Notes: None.
  37. //
  38. // History: 4/14/98 CameronE - created
  39. //
  40. //----------------------------------------------------------------------------
  41. BOOL
  42. RegReadPolicyKey(
  43. LPCTSTR lpszValue)
  44. {
  45. // TRACE_FUNCTION(RegReadPolicyKey) is too verbose
  46. schDebugOut((DEB_USER6, "RegReadPolicyKey\n"));
  47. // CODEWORK: This function is called way too often. See if we can cache
  48. // the results, or at least keep the key handle open.
  49. HKEY keyPolicy;
  50. BOOL fPolicy = FALSE;
  51. DWORD dwType;
  52. DWORD dwData;
  53. DWORD dwDataSize = sizeof(DWORD);
  54. //
  55. // It is possible to have a policy key under HKLM and/or HKCU
  56. // We assume that HKCU can shutoff what HKLM enables, but not vice
  57. // versa.
  58. //
  59. LONG lerr = RegOpenKeyEx( HKEY_LOCAL_MACHINE,
  60. TS_KEYPOLICY_BASE,
  61. 0,
  62. KEY_READ,
  63. &keyPolicy);
  64. if (lerr == ERROR_SUCCESS)
  65. {
  66. lerr = RegQueryValueEx( keyPolicy,
  67. lpszValue,
  68. NULL,
  69. &dwType,
  70. (BYTE *) &dwData,
  71. &dwDataSize);
  72. if (lerr == ERROR_SUCCESS)
  73. {
  74. if (dwType == REG_DWORD)
  75. {
  76. fPolicy = (dwData > 0);
  77. }
  78. else
  79. {
  80. schDebugOut((DEB_ITRACE, "HKLM Policy value not a DWORD!\n"));
  81. }
  82. }
  83. RegCloseKey(keyPolicy);
  84. }
  85. //
  86. // If HKLM policy value has shut off part of the UI on this machine,
  87. // return it now, so that HKCU cannot override a stricter machine policy.
  88. //
  89. if (fPolicy)
  90. {
  91. return fPolicy;
  92. }
  93. //
  94. // Otherwise, see if maybe it's just this user that can't do this task
  95. //
  96. lerr = RegOpenKeyEx( HKEY_CURRENT_USER,
  97. TS_KEYPOLICY_BASE,
  98. 0,
  99. KEY_READ,
  100. &keyPolicy);
  101. dwDataSize = sizeof(DWORD);
  102. if (lerr == ERROR_SUCCESS)
  103. {
  104. lerr = RegQueryValueEx( keyPolicy,
  105. lpszValue,
  106. NULL,
  107. &dwType,
  108. (BYTE *) &dwData,
  109. &dwDataSize);
  110. if (lerr == ERROR_SUCCESS)
  111. {
  112. if (dwType == REG_DWORD)
  113. {
  114. fPolicy = (dwData > 0);
  115. }
  116. else
  117. {
  118. schDebugOut((DEB_ITRACE, "HKCU Policy value not a DWORD!\n"));
  119. }
  120. }
  121. RegCloseKey(keyPolicy);
  122. }
  123. return fPolicy;
  124. }