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.

198 lines
5.8 KiB

  1. //
  2. // security.h
  3. //
  4. // Implementation of CTSSecurity
  5. // TS Client Shell Security functions
  6. //
  7. // Copyright(C) Microsoft Corporation 2001
  8. // Author: Nadim Abdo (nadima)
  9. //
  10. //
  11. #include "stdafx.h"
  12. #define TRC_GROUP TRC_GROUP_UI
  13. #define TRC_FILE "security"
  14. #include <atrcapi.h>
  15. #include "security.h"
  16. #include "tscsetting.h"
  17. #include "rdrwrndlg.h"
  18. #include "autreg.h"
  19. #include "autil.h"
  20. CTSSecurity::CTSSecurity()
  21. {
  22. }
  23. CTSSecurity::~CTSSecurity()
  24. {
  25. }
  26. DWORD CTSSecurity::MakePromptFlags(BOOL fRedirectDrives,
  27. BOOL fRedirectPorts)
  28. {
  29. DWORD dwFlags = REDIRSEC_PROMPT_EVERYTHING;
  30. if (fRedirectDrives)
  31. {
  32. dwFlags |= REDIRSEC_DRIVES;
  33. }
  34. if (fRedirectPorts)
  35. {
  36. dwFlags |= REDIRSEC_PORTS;
  37. }
  38. return dwFlags;
  39. }
  40. //
  41. // AllowConnection
  42. // Purpose: Does security cheks to determine if the connection should
  43. // proceed based on selected redirection options. This function
  44. // will look at the security policy in the registry for that
  45. // server and decide if the user needs to be prompted.
  46. // If so it will pop UI.
  47. //
  48. // Params:
  49. // hwndOwner - owning window (parents the dialog if we pop UI)
  50. // hInstance - app instance for loading resources
  51. // szServer - server name we are connecting to
  52. // fRedirectDrives - drive redir requested
  53. // fRedirectPorts - port redirection requested
  54. // fRedirectSmartCards - scard redir requested
  55. //
  56. // Returns: BOOLean TRUE if connection is allowed with these settings
  57. // false otherwise
  58. //
  59. // NOTE: Can POP Modal UI
  60. //
  61. //
  62. BOOL CTSSecurity::AllowConnection(HWND hwndOwner,
  63. HINSTANCE hInstance,
  64. LPCTSTR szServer,
  65. BOOL fRedirectDrives,
  66. BOOL fRedirectPorts)
  67. {
  68. BOOL fAllowCon = FALSE;
  69. CUT ut;
  70. DWORD dwSecurityLevel;
  71. DC_BEGIN_FN("AllowConnection");
  72. //
  73. // First read the security level policy
  74. //
  75. dwSecurityLevel = ut.UT_ReadRegistryInt(
  76. UTREG_SECTION,
  77. REG_KEYNAME_SECURITYLEVEL,
  78. TSC_SECLEVEL_MEDIUM);
  79. if (TSC_SECLEVEL_LOW == dwSecurityLevel)
  80. {
  81. TRC_NRM((TB,_T("Security level policy is set to low: check passed")));
  82. fAllowCon = TRUE;
  83. DC_QUIT;
  84. }
  85. if (fRedirectDrives ||
  86. fRedirectPorts)
  87. {
  88. DWORD dwSecurityFilter;
  89. DWORD dwSelectedOptions;
  90. DWORD dwFlagsToPrompt;
  91. //
  92. // Get the security filter for this server name
  93. //
  94. dwSecurityFilter = REDIRSEC_PROMPT_EVERYTHING;
  95. dwSecurityFilter = ut.UT_ReadRegistryInt(
  96. REG_SECURITY_FILTER_SECTION,
  97. (LPTSTR)szServer,
  98. REDIRSEC_PROMPT_EVERYTHING);
  99. dwSelectedOptions = MakePromptFlags(fRedirectDrives,
  100. fRedirectPorts);
  101. TRC_ALT((TB,_T("Filter 0x%x Selected:0x%x"),
  102. dwSecurityFilter,
  103. dwSelectedOptions));
  104. //
  105. // Check if the filter allows the selected options
  106. // thru without prompt. The filter indicates which bits
  107. // are lalowed without prompt so NOT to see if any bits with
  108. // prompt remain.
  109. //
  110. dwFlagsToPrompt = dwSelectedOptions & ~dwSecurityFilter;
  111. if (dwFlagsToPrompt)
  112. {
  113. INT dlgRet;
  114. //
  115. // One or more options need a user prompt
  116. // so pop the security UI
  117. //
  118. CRedirectPromptDlg rdrPromptDlg(hwndOwner,
  119. hInstance,
  120. dwSelectedOptions);
  121. dlgRet = rdrPromptDlg.DoModal();
  122. if (IDOK == dlgRet)
  123. {
  124. //
  125. // User is allowing redirection to happen
  126. //
  127. if (rdrPromptDlg.GetNeverPrompt())
  128. {
  129. DWORD dwNewFilterBits;
  130. //
  131. // We need to modify the filter bits
  132. // by OR'ing in the current redirection settings
  133. // and writing them back to the registry
  134. //
  135. dwNewFilterBits = dwSelectedOptions | dwSecurityFilter;
  136. if (!ut.UT_WriteRegistryInt(
  137. REG_SECURITY_FILTER_SECTION,
  138. (LPTSTR)szServer,
  139. REDIRSEC_PROMPT_EVERYTHING,
  140. dwNewFilterBits))
  141. {
  142. TRC_ERR((TB,_T("Failed to write prompt bits to reg")));
  143. }
  144. }
  145. fAllowCon = TRUE;
  146. }
  147. else
  148. {
  149. //
  150. // User hit cancel which means don't allow
  151. // the connection to proceed
  152. //
  153. TRC_NRM((TB,_T("User canceled out of security dialog")));
  154. fAllowCon = FALSE;
  155. DC_QUIT;
  156. }
  157. }
  158. else
  159. {
  160. //
  161. // No option is selected that requires a prompt
  162. //
  163. fAllowCon = TRUE;
  164. DC_QUIT;
  165. }
  166. }
  167. else
  168. {
  169. //
  170. // No 'unsafe' device redirections requested so we just
  171. // allow the connection to go thru
  172. //
  173. fAllowCon = TRUE;
  174. }
  175. DC_END_FN();
  176. DC_EXIT_POINT:
  177. return fAllowCon;
  178. }