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.

118 lines
2.6 KiB

  1. // File: syspol.cpp
  2. //
  3. // System policies
  4. //
  5. // This class tries to be efficient by only opening the key once
  6. // and using KEY_QUERY_VALUE.
  7. //
  8. // Normally the policy keys don't exist, so the default setting is very important.
  9. #include "precomp.h"
  10. #include "syspol.h"
  11. HKEY SysPol::m_hkey = NULL;
  12. /* F E N S U R E K E Y O P E N */
  13. /*-------------------------------------------------------------------------
  14. %%Function: FEnsureKeyOpen
  15. -------------------------------------------------------------------------*/
  16. bool SysPol::FEnsureKeyOpen(void)
  17. {
  18. if (NULL == m_hkey)
  19. {
  20. long lErr = ::RegOpenKeyEx(HKEY_CURRENT_USER, POLICIES_KEY, 0, KEY_QUERY_VALUE, &m_hkey);
  21. if (ERROR_SUCCESS != lErr)
  22. {
  23. WARNING_OUT(("FEnsureKeyOpen: problem opening system policy key. Err=%08X", lErr));
  24. return false;
  25. }
  26. }
  27. return true;
  28. }
  29. void SysPol::CloseKey(void)
  30. {
  31. if (NULL != m_hkey)
  32. {
  33. ::RegCloseKey(m_hkey);
  34. m_hkey = NULL;
  35. }
  36. }
  37. /* G E T N U M B E R */
  38. /*-------------------------------------------------------------------------
  39. %%Function: GetNumber
  40. -------------------------------------------------------------------------*/
  41. DWORD SysPol::GetNumber(LPCTSTR pszName, DWORD dwDefault)
  42. {
  43. if (FEnsureKeyOpen())
  44. {
  45. DWORD dwType = REG_BINARY;
  46. DWORD dwValue = 0L;
  47. DWORD dwSize = sizeof(dwValue);
  48. long lErr = ::RegQueryValueEx(m_hkey, pszName, 0, &dwType, (LPBYTE)&dwValue, &dwSize);
  49. if ((lErr == ERROR_SUCCESS) &&
  50. ((REG_DWORD == dwType) || ((REG_BINARY == dwType) && (sizeof(dwValue) == dwSize))) )
  51. {
  52. dwDefault = dwValue;
  53. }
  54. }
  55. return dwDefault;
  56. }
  57. //////////////////////
  58. // Positive Settings
  59. bool SysPol::AllowDirectoryServices(void)
  60. {
  61. return (0 == GetNumber(REGVAL_POL_NO_DIRECTORY_SERVICES, DEFAULT_POL_NO_DIRECTORY_SERVICES));
  62. }
  63. bool SysPol::AllowAddingServers(void)
  64. {
  65. if (!AllowDirectoryServices())
  66. return FALSE;
  67. return (0 == GetNumber(REGVAL_POL_NO_ADDING_NEW_ULS, DEFAULT_POL_NO_ADDING_NEW_ULS));
  68. }
  69. //////////////////////
  70. // Negative Settings
  71. bool SysPol::NoAudio(void)
  72. {
  73. return (0 != GetNumber(REGVAL_POL_NO_AUDIO, DEFAULT_POL_NO_AUDIO));
  74. }
  75. bool SysPol::NoVideoSend(void)
  76. {
  77. return (0 != GetNumber(REGVAL_POL_NO_VIDEO_SEND, DEFAULT_POL_NO_VIDEO_SEND));
  78. }
  79. bool SysPol::NoVideoReceive(void)
  80. {
  81. return (0 != GetNumber(REGVAL_POL_NO_VIDEO_RECEIVE, DEFAULT_POL_NO_VIDEO_RECEIVE));
  82. }
  83. UINT SysPol::GetMaximumBandwidth()
  84. {
  85. UINT uRet;
  86. RegEntry re(POLICIES_KEY, HKEY_CURRENT_USER, FALSE);
  87. uRet = re.GetNumberIniStyle(REGVAL_POL_MAX_BANDWIDTH, 0);
  88. return uRet;
  89. }