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.

235 lines
6.3 KiB

  1. //
  2. // rdrwrndlg.cpp Device redirection security warning dialog
  3. //
  4. #include "stdafx.h"
  5. #define TRC_GROUP TRC_GROUP_UI
  6. #define TRC_FILE "rdrwrndlg"
  7. #include <atrcapi.h>
  8. #include "rdrwrndlg.h"
  9. #include "autreg.h"
  10. CRedirectPromptDlg* CRedirectPromptDlg::_pRedirectPromptDlgInstance = NULL;
  11. CRedirectPromptDlg::CRedirectPromptDlg( HWND hwndOwner, HINSTANCE hInst,
  12. DWORD dwRedirectionsSpecified) :
  13. CDlgBase( hwndOwner, hInst, UI_IDD_RDC_SECURITY_WARN),
  14. _dwRedirectionsSpecified(dwRedirectionsSpecified)
  15. {
  16. DC_BEGIN_FN("CRedirectPromptDlg");
  17. TRC_ASSERT((NULL == CRedirectPromptDlg::_pRedirectPromptDlgInstance),
  18. (TB,_T("Clobbering existing dlg instance pointer\n")));
  19. TRC_ASSERT(_dwRedirectionsSpecified,(TB,
  20. _T("Redirection security dialog called with no redirs enabled")));
  21. CRedirectPromptDlg::_pRedirectPromptDlgInstance = this;
  22. _fNeverPromptMeAgain = FALSE;
  23. DC_END_FN();
  24. }
  25. CRedirectPromptDlg::~CRedirectPromptDlg()
  26. {
  27. CRedirectPromptDlg::_pRedirectPromptDlgInstance = NULL;
  28. }
  29. DCINT CRedirectPromptDlg::DoModal()
  30. {
  31. DCINT retVal = 0;
  32. DC_BEGIN_FN("DoModal");
  33. retVal = DialogBox(_hInstance, MAKEINTRESOURCE(_dlgResId),
  34. _hwndOwner, StaticDialogBoxProc);
  35. TRC_ASSERT((retVal != 0 && retVal != -1), (TB, _T("DialogBoxParam failed\n")));
  36. DC_END_FN();
  37. return retVal;
  38. }
  39. INT_PTR CALLBACK CRedirectPromptDlg::StaticDialogBoxProc(HWND hwndDlg,
  40. UINT uMsg,
  41. WPARAM wParam,
  42. LPARAM lParam)
  43. {
  44. //
  45. // Delegate to appropriate instance (only works for single instance dialogs)
  46. //
  47. DC_BEGIN_FN("StaticDialogBoxProc");
  48. DCINT retVal = 0;
  49. TRC_ASSERT(_pRedirectPromptDlgInstance,
  50. (TB, _T("Redirect warn dialog has NULL static instance ptr\n")));
  51. if(_pRedirectPromptDlgInstance)
  52. {
  53. retVal = _pRedirectPromptDlgInstance->DialogBoxProc(hwndDlg,
  54. uMsg,
  55. wParam,
  56. lParam);
  57. }
  58. DC_END_FN();
  59. return retVal;
  60. }
  61. //
  62. // Name: DialogBoxProc
  63. //
  64. // Purpose: Handles CRedirectPromptDlg dialog box
  65. //
  66. // Returns: TRUE if message dealt with
  67. // FALSE otherwise
  68. //
  69. // Params: See window documentation
  70. //
  71. //
  72. INT_PTR CALLBACK CRedirectPromptDlg::DialogBoxProc(HWND hwndDlg,
  73. UINT uMsg,
  74. WPARAM wParam,
  75. LPARAM lParam)
  76. {
  77. INT_PTR rc = FALSE;
  78. DC_BEGIN_FN("DialogBoxProc");
  79. switch (uMsg)
  80. {
  81. case WM_INITDIALOG:
  82. {
  83. _hwndDlg = hwndDlg;
  84. //Center the redirectprompt dialog on the screen
  85. CenterWindow(NULL);
  86. SetDialogAppIcon(hwndDlg);
  87. TCHAR szRedirectList[MAX_PATH];
  88. //
  89. // Get a string representing the redirection options
  90. //
  91. if (GetRedirectListString( szRedirectList, MAX_PATH - 1))
  92. {
  93. szRedirectList[MAX_PATH-1] = 0;
  94. SetDlgItemText(hwndDlg,
  95. UI_IDC_STATIC_DEVICES,
  96. szRedirectList);
  97. }
  98. rc = TRUE;
  99. }
  100. break;
  101. case WM_COMMAND:
  102. {
  103. switch (DC_GET_WM_COMMAND_ID(wParam))
  104. {
  105. case IDOK:
  106. {
  107. _fNeverPromptMeAgain = IsDlgButtonChecked(hwndDlg,
  108. UI_IDC_CHECK_NOPROMPT);
  109. EndDialog(hwndDlg, IDOK);
  110. }
  111. break;
  112. case IDCANCEL:
  113. {
  114. EndDialog(hwndDlg, IDCANCEL);
  115. }
  116. break;
  117. }
  118. }
  119. break;
  120. default:
  121. {
  122. rc = CDlgBase::DialogBoxProc(hwndDlg,
  123. uMsg,
  124. wParam,
  125. lParam);
  126. }
  127. break;
  128. }
  129. DC_END_FN();
  130. return(rc);
  131. } /* CRedirectPromptDlg::DialogBoxProc */
  132. BOOL CRedirectPromptDlg::GetRedirectListString(LPTSTR szBuf, UINT len)
  133. {
  134. TCHAR szTemp[SH_DISPLAY_STRING_MAX_LENGTH];
  135. BOOL fResult = FALSE;
  136. INT lenRemain = (INT)len;
  137. DC_BEGIN_FN("GetRedirectListString");
  138. memset(szBuf, 0, len);
  139. if (_dwRedirectionsSpecified & REDIRSEC_DRIVES)
  140. {
  141. memset(szTemp, 0, sizeof(szTemp));
  142. if (LoadString(_hInstance,
  143. UI_IDS_REDIRPROMPT_DRIVES,
  144. szTemp,
  145. SIZECHAR(szTemp) - 1))
  146. {
  147. _tcsncat(szBuf, szTemp, lenRemain);
  148. lenRemain -= (_tcslen(szTemp) + 2);
  149. if (lenRemain > 2)
  150. {
  151. _tcscat(szBuf, _T("\n"));
  152. lenRemain -= 2;
  153. }
  154. else
  155. {
  156. fResult = FALSE;
  157. DC_QUIT;
  158. }
  159. }
  160. else
  161. {
  162. fResult = FALSE;
  163. DC_QUIT;
  164. }
  165. }
  166. if (_dwRedirectionsSpecified & REDIRSEC_PORTS)
  167. {
  168. memset(szTemp, 0, sizeof(szTemp));
  169. if (LoadString(_hInstance,
  170. UI_IDS_REDIRPROMPT_PORTS,
  171. szTemp,
  172. SIZECHAR(szTemp) - 1))
  173. {
  174. _tcsncat(szBuf, szTemp, lenRemain);
  175. lenRemain -= (_tcslen(szTemp) + 2);
  176. if (lenRemain > 2)
  177. {
  178. _tcscat(szBuf, _T("\n"));
  179. lenRemain -= 2;
  180. }
  181. else
  182. {
  183. fResult = FALSE;
  184. DC_QUIT;
  185. }
  186. }
  187. else
  188. {
  189. fResult = FALSE;
  190. DC_QUIT;
  191. }
  192. }
  193. fResult = TRUE;
  194. DC_EXIT_POINT:
  195. DC_END_FN();
  196. return fResult;
  197. }