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.

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