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.

270 lines
8.5 KiB

  1. /**MOD+**********************************************************************/
  2. /* Module: securedset.cpp */
  3. /* */
  4. /* Class : CMsTscSecuredSettings */
  5. /* */
  6. /* Purpose: Implements secured scriptable settings interface */
  7. /* */
  8. /* Copyright(C) Microsoft Corporation 1999-2000 */
  9. /* */
  10. /* Author : Nadim Abdo (nadima) */
  11. /****************************************************************************/
  12. #include "stdafx.h"
  13. #include "securedset.h"
  14. #include "atlwarn.h"
  15. BEGIN_EXTERN_C
  16. #define TRC_GROUP TRC_GROUP_UI
  17. #define TRC_FILE "tsdbg"
  18. #include <atrcapi.h>
  19. END_EXTERN_C
  20. CMsTscSecuredSettings::CMsTscSecuredSettings()
  21. {
  22. m_pMsTsc=NULL;
  23. m_pUI=NULL;
  24. m_bLockedForWrite=FALSE;
  25. }
  26. CMsTscSecuredSettings::~CMsTscSecuredSettings()
  27. {
  28. }
  29. BOOL CMsTscSecuredSettings::SetParent(CMsTscAx* pMsTsc)
  30. {
  31. ATLASSERT(pMsTsc);
  32. m_pMsTsc = pMsTsc;
  33. return TRUE;
  34. }
  35. BOOL CMsTscSecuredSettings::SetUI(CUI* pUI)
  36. {
  37. ATLASSERT(pUI);
  38. if(!pUI)
  39. {
  40. return FALSE;
  41. }
  42. m_pUI = pUI;
  43. return TRUE;
  44. }
  45. /**PROC+*********************************************************************/
  46. /* Name: put_StartProgram */
  47. /* */
  48. /* Purpose: Alternate shell property input function. */
  49. /* */
  50. /**PROC-*********************************************************************/
  51. STDMETHODIMP CMsTscSecuredSettings::put_StartProgram(BSTR newVal)
  52. {
  53. //Delegate to parent's vtable interface for this setting
  54. if(m_pMsTsc && !GetLockedForWrite())
  55. {
  56. return m_pMsTsc->internal_PutStartProgram(newVal);
  57. }
  58. return E_FAIL;
  59. }
  60. /**PROC+*********************************************************************/
  61. /* Name: get_StartProgram */
  62. /* */
  63. /* Purpose: StartProgram property get function. */
  64. /* */
  65. /**PROC-*********************************************************************/
  66. STDMETHODIMP CMsTscSecuredSettings::get_StartProgram(BSTR* pStartProgram)
  67. {
  68. //Delegate to parent's vtable interface for this setting
  69. if(m_pMsTsc)
  70. {
  71. return m_pMsTsc->internal_GetStartProgram(pStartProgram);
  72. }
  73. return E_FAIL;
  74. }
  75. /**PROC+*********************************************************************/
  76. /* Name: put_WorkDir */
  77. /* */
  78. /* Purpose: Working Directory property input function. */
  79. /* */
  80. /**PROC-*********************************************************************/
  81. STDMETHODIMP CMsTscSecuredSettings::put_WorkDir(BSTR newVal)
  82. {
  83. //Delegate to parent's vtable interface for this setting
  84. if(m_pMsTsc && !GetLockedForWrite())
  85. {
  86. return m_pMsTsc->internal_PutWorkDir(newVal);
  87. }
  88. return E_FAIL;
  89. }
  90. /**PROC+*********************************************************************/
  91. /* Name: get_WorkDir */
  92. /* */
  93. /* Purpose: Working Directory property get function. */
  94. /* */
  95. /**PROC-*********************************************************************/
  96. STDMETHODIMP CMsTscSecuredSettings::get_WorkDir(BSTR* pWorkDir)
  97. {
  98. //Delegate to parent's vtable interface for this setting
  99. if(m_pMsTsc)
  100. {
  101. return m_pMsTsc->internal_GetWorkDir(pWorkDir);
  102. }
  103. return E_FAIL;
  104. }
  105. /**PROC+*********************************************************************/
  106. /* Name: put_FullScreen
  107. /*
  108. /* Purpose: Set fullscreen (and switches mode)
  109. /*
  110. /**PROC-*********************************************************************/
  111. STDMETHODIMP CMsTscSecuredSettings::put_FullScreen(BOOL fFullScreen)
  112. {
  113. //Delegate to parent's vtable interface for this setting
  114. if(m_pMsTsc)
  115. {
  116. return m_pMsTsc->internal_PutFullScreen(fFullScreen);
  117. }
  118. return E_FAIL;
  119. }
  120. /**PROC+*********************************************************************/
  121. /* Name: internal_GetFullScreen
  122. /*
  123. /* Purpose: get FullScreen mode
  124. /*
  125. /**PROC-*********************************************************************/
  126. STDMETHODIMP CMsTscSecuredSettings::get_FullScreen(BOOL* pfFullScreen)
  127. {
  128. if(m_pMsTsc)
  129. {
  130. return m_pMsTsc->internal_GetFullScreen(pfFullScreen);
  131. }
  132. return S_OK;
  133. }
  134. //
  135. // Check if reg key for drive redir is set to globally disable it
  136. //
  137. #define TS_DISABLEDRIVES_KEYNAME TEXT("SOFTWARE\\Microsoft\\Terminal Server Client")
  138. #define TS_DISABLEDRIVES TEXT("DisableDriveRedirection")
  139. BOOL CMsTscSecuredSettings::IsDriveRedirGloballyDisabled()
  140. {
  141. HKEY hKey = NULL;
  142. INT retVal = 0;
  143. BOOL fDriveRedirDisabled = FALSE;
  144. DC_BEGIN_FN("IsDriveRedirGloballyDisabled");
  145. //
  146. // Check if the security override reg key disables
  147. // drive redirection
  148. //
  149. retVal = RegOpenKeyEx(HKEY_LOCAL_MACHINE,
  150. TS_DISABLEDRIVES_KEYNAME,
  151. 0,
  152. KEY_READ,
  153. &hKey);
  154. if(ERROR_SUCCESS == retVal)
  155. {
  156. DWORD cbData = sizeof(DWORD);
  157. DWORD dwType,dwVal;
  158. retVal = RegQueryValueEx(hKey, TS_DISABLEDRIVES,
  159. NULL, &dwType,
  160. (PBYTE)&dwVal,
  161. &cbData);
  162. if(ERROR_SUCCESS == retVal && REG_DWORD == dwType)
  163. {
  164. fDriveRedirDisabled = (dwVal != 0);
  165. }
  166. RegCloseKey(hKey);
  167. }
  168. TRC_NRM((TB,_T("REG Security for drive redir is %d"),
  169. fDriveRedirDisabled));
  170. DC_END_FN();
  171. return fDriveRedirDisabled;
  172. }
  173. STDMETHODIMP CMsTscSecuredSettings::put_KeyboardHookMode(LONG KeyboardHookMode)
  174. {
  175. if(!GetLockedForWrite())
  176. {
  177. if(KeyboardHookMode == UTREG_UI_KEYBOARD_HOOK_NEVER ||
  178. KeyboardHookMode == UTREG_UI_KEYBOARD_HOOK_ALWAYS ||
  179. KeyboardHookMode == UTREG_UI_KEYBOARD_HOOK_FULLSCREEN)
  180. {
  181. m_pUI->_UI.keyboardHookMode = KeyboardHookMode;
  182. return S_OK;
  183. }
  184. else
  185. {
  186. return E_INVALIDARG;
  187. }
  188. }
  189. else
  190. {
  191. return E_FAIL;
  192. }
  193. }
  194. STDMETHODIMP CMsTscSecuredSettings::get_KeyboardHookMode(LONG* pKeyboardHookMode)
  195. {
  196. if(pKeyboardHookMode)
  197. {
  198. *pKeyboardHookMode = m_pUI->_UI.keyboardHookMode;
  199. return S_OK;
  200. }
  201. else
  202. {
  203. return E_INVALIDARG;
  204. }
  205. }
  206. STDMETHODIMP CMsTscSecuredSettings::put_AudioRedirectionMode(LONG audioRedirectionMode)
  207. {
  208. if(!GetLockedForWrite())
  209. {
  210. if(audioRedirectionMode == AUDIOREDIRECT_TO_CLIENT ||
  211. audioRedirectionMode == AUDIOREDIRECT_ON_SERVER ||
  212. audioRedirectionMode == AUDIOREDIRECT_NOAUDIO)
  213. {
  214. m_pUI->UI_SetAudioRedirectionMode(audioRedirectionMode);
  215. return S_OK;
  216. }
  217. else
  218. {
  219. return E_INVALIDARG;
  220. }
  221. }
  222. else
  223. {
  224. return E_FAIL;
  225. }
  226. }
  227. STDMETHODIMP CMsTscSecuredSettings::get_AudioRedirectionMode(LONG* pAudioRedirectionMode)
  228. {
  229. if(pAudioRedirectionMode)
  230. {
  231. *pAudioRedirectionMode = m_pUI->UI_GetAudioRedirectionMode();
  232. return S_OK;
  233. }
  234. else
  235. {
  236. return E_INVALIDARG;
  237. }
  238. }