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.

236 lines
5.3 KiB

  1. /*++
  2. Copyright (c) 1999-2000 Microsoft Corporation
  3. Module Name:
  4. salem.cpp
  5. Abstract:
  6. All Salem related function, this library is shared by termsrv.dll
  7. and salem sessmgr.exe
  8. Author:
  9. --*/
  10. #include <nt.h>
  11. #include <ntrtl.h>
  12. #include <nturtl.h>
  13. #include <ntlsa.h>
  14. #include <ntsam.h>
  15. #include <stdio.h>
  16. #include <string.h>
  17. #include <windows.h>
  18. #include <lm.h>
  19. #include <winsta.h>
  20. #include "regapi.h"
  21. extern "C" {
  22. BOOLEAN
  23. RegIsMachinePolicyAllowHelp();
  24. BOOLEAN
  25. RegIsMachineInHelpMode();
  26. }
  27. DWORD
  28. GetPolicyAllowGetHelpSetting(
  29. HKEY hKey,
  30. LPCTSTR pszKeyName,
  31. LPCTSTR pszValueName,
  32. IN DWORD* value
  33. )
  34. /*++
  35. Routine Description:
  36. Routine to query policy registry value.
  37. Parameters:
  38. hKey : Currently open registry key.
  39. pszKeyName : Pointer to a null-terminated string containing
  40. the name of the subkey to open.
  41. pszValueName : Pointer to a null-terminated string containing
  42. the name of the value to query
  43. value : Pointer to DWORD to receive GetHelp policy setting.
  44. Returns:
  45. ERROR_SUCCESS or error code from RegOpenKeyEx().
  46. --*/
  47. {
  48. DWORD dwStatus;
  49. HKEY hPolicyKey = NULL;
  50. DWORD dwType;
  51. DWORD cbData;
  52. //
  53. // Open registry key for system policy
  54. //
  55. dwStatus = RegOpenKeyEx(
  56. hKey,
  57. pszKeyName,
  58. 0,
  59. KEY_READ,
  60. &hPolicyKey
  61. );
  62. if( ERROR_SUCCESS == dwStatus )
  63. {
  64. // query value
  65. cbData = 0;
  66. dwType = 0;
  67. dwStatus = RegQueryValueEx(
  68. hPolicyKey,
  69. pszValueName,
  70. NULL,
  71. &dwType,
  72. NULL,
  73. &cbData
  74. );
  75. if( ERROR_SUCCESS == dwStatus )
  76. {
  77. if( REG_DWORD == dwType )
  78. {
  79. cbData = sizeof(DWORD);
  80. // our registry value is REG_DWORD, if different type,
  81. // assume not exist.
  82. dwStatus = RegQueryValueEx(
  83. hPolicyKey,
  84. pszValueName,
  85. NULL,
  86. &dwType,
  87. (LPBYTE)value,
  88. &cbData
  89. );
  90. ASSERT( ERROR_SUCCESS == dwStatus );
  91. }
  92. else
  93. {
  94. // bad registry key type, assume
  95. // key does not exist.
  96. dwStatus = ERROR_FILE_NOT_FOUND;
  97. }
  98. }
  99. RegCloseKey( hPolicyKey );
  100. }
  101. return dwStatus;
  102. }
  103. BOOLEAN
  104. RegIsMachinePolicyAllowHelp()
  105. /*++
  106. Routine Description:
  107. Check if 'GetHelp' is enabled on local machine, routine first query
  108. system policy registry key, if policy is not set, then read salem
  109. specific registry. Default to 'enable' is registry value does not
  110. exist.
  111. Parameters:
  112. None.
  113. Returns:
  114. TRUE/FALSE
  115. --*/
  116. {
  117. DWORD dwStatus;
  118. DWORD dwValue = 0;
  119. //
  120. // Open system policy registry key, if registry key/value
  121. // does not exist, assume it is enable and continue on
  122. // to local policy key.
  123. //
  124. dwStatus = GetPolicyAllowGetHelpSetting(
  125. HKEY_LOCAL_MACHINE,
  126. TS_POLICY_SUB_TREE,
  127. POLICY_TS_REMDSK_ALLOWTOGETHELP,
  128. &dwValue
  129. );
  130. if( ERROR_SUCCESS != dwStatus )
  131. {
  132. //
  133. // For local machine policy, our default value is
  134. // Not Allow to get help if registry key is not there
  135. //
  136. dwStatus = GetPolicyAllowGetHelpSetting(
  137. HKEY_LOCAL_MACHINE,
  138. REG_CONTROL_GETHELP,
  139. POLICY_TS_REMDSK_ALLOWTOGETHELP,
  140. &dwValue
  141. );
  142. if( ERROR_SUCCESS != dwStatus )
  143. {
  144. //
  145. // neither group policy nor machine policy has
  146. // set any value, default to disable.
  147. //
  148. dwValue = 0;
  149. }
  150. }
  151. return (dwValue == 1);
  152. }
  153. BOOLEAN
  154. RegIsMachineInHelpMode()
  155. /*++
  156. Routine Description:
  157. Check if 'InHelpMode' is set on local machine.
  158. Default to FALSE if registry value does not exist.
  159. Parameters:
  160. None.
  161. Returns:
  162. TRUE/FALSE
  163. --*/
  164. {
  165. DWORD dwStatus;
  166. DWORD dwValue = 0;
  167. //
  168. // The default value is NotInHelp if registry key is not there
  169. //
  170. dwStatus = GetPolicyAllowGetHelpSetting(
  171. HKEY_LOCAL_MACHINE,
  172. REG_CONTROL_TSERVER,
  173. REG_MACHINE_IN_HELP_MODE,
  174. &dwValue
  175. );
  176. if( ERROR_SUCCESS != dwStatus )
  177. {
  178. //
  179. // The value is not set, default to disable.
  180. //
  181. dwValue = 0;
  182. }
  183. return (dwValue == 1);
  184. }