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.

304 lines
8.0 KiB

  1. /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  2. Microsoft Windows, Copyright (C) Microsoft Corporation, 2000
  3. File: DialogUI.CPP
  4. Content: UI dialogs.
  5. History: 11-15-99 dsie created
  6. ------------------------------------------------------------------------------*/
  7. #include "StdAfx.h"
  8. #include "CAPICOM.h"
  9. #include "Certificate.h"
  10. #include "Settings.h"
  11. ////////////////////////////////////////////////////////////////////////////////
  12. //
  13. // typedefs.
  14. //
  15. typedef struct _CAPICOM_DIALOG_DATA
  16. {
  17. DWORD dwDlgId;
  18. WCHAR wszDomainName[INTERNET_MAX_URL_LENGTH];
  19. BOOL bWasApproved;
  20. BOOL bDoNotShowWasChecked;
  21. } CAPICOM_DIALOG_DATA, * PCAPICOM_DIALOG_DATA;
  22. static CAPICOM_DIALOG_DATA g_DialogData[] =
  23. {
  24. {IDD_STORE_OPEN_SECURITY_ALERT_DLG, '\0', FALSE, FALSE},
  25. {IDD_STORE_ADD_SECURITY_ALERT_DLG, '\0', FALSE, FALSE},
  26. {IDD_STORE_REMOVE_SECURITY_ALERT_DLG, '\0', FALSE, FALSE},
  27. {IDD_SIGN_SECURITY_ALERT_DLG, '\0', FALSE, FALSE},
  28. {IDD_DECRYPT_SECURITY_ALERT_DLG, '\0', FALSE, FALSE},
  29. };
  30. #define g_NumDialogs (ARRAYSIZE(g_DialogData))
  31. /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  32. Function : CenterWindow
  33. Synopsis : Certer the window to the screen.
  34. Parameter: HWND hwnd - Window handle.
  35. Remark :
  36. ------------------------------------------------------------------------------*/
  37. static void CenterWindow (HWND hwnd)
  38. {
  39. RECT rect;
  40. //
  41. // Sanity check.
  42. //
  43. ATLASSERT(hwnd);
  44. //
  45. // Get dimension of window.
  46. //
  47. if (::GetWindowRect(hwnd, &rect))
  48. {
  49. //
  50. // Calculate center point.
  51. //
  52. int wx = (::GetSystemMetrics(SM_CXSCREEN) - (rect.right - rect.left)) / 2;
  53. int wy = (::GetSystemMetrics(SM_CYSCREEN) - (rect.bottom - rect.top)) / 2;
  54. //
  55. // Position it.
  56. //
  57. if (wx > 0 && wy > 0)
  58. {
  59. ::SetWindowPos(hwnd, NULL, wx, wy, 0, 0, SWP_NOSIZE | SWP_NOZORDER);
  60. }
  61. }
  62. return;
  63. }
  64. /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  65. Function : UserApprovedOperationDlgProc
  66. Synopsis : UserApprovedOperation dialog proc.
  67. Remark :
  68. ------------------------------------------------------------------------------*/
  69. INT_PTR CALLBACK UserApprovedOperationDlgProc (HWND hDlg, // Handle to dialog box
  70. UINT uMsg, // Message
  71. WPARAM wParam, // First message parameter
  72. LPARAM lParam) // Second message parameter
  73. {
  74. PCAPICOM_DIALOG_DATA pDialogData = NULL;
  75. switch (uMsg)
  76. {
  77. case WM_INITDIALOG:
  78. {
  79. if (lParam)
  80. {
  81. ::SetWindowLongPtr(hDlg, GWLP_USERDATA, (LONG_PTR) lParam);
  82. }
  83. CenterWindow(hDlg);
  84. SetFocus(GetDlgItem(hDlg, IDNO));
  85. return TRUE;
  86. }
  87. case WM_COMMAND:
  88. {
  89. if (BN_CLICKED == HIWORD(wParam))
  90. {
  91. switch(LOWORD(wParam))
  92. {
  93. case IDYES:
  94. case IDNO:
  95. case IDCANCEL:
  96. {
  97. EndDialog(hDlg, LOWORD(wParam));
  98. return TRUE;
  99. }
  100. case IDC_DLG_NO_SHOW_AGAIN:
  101. {
  102. if (pDialogData = (PCAPICOM_DIALOG_DATA) ::GetWindowLongPtr(hDlg, GWLP_USERDATA))
  103. {
  104. if (BST_CHECKED == ::IsDlgButtonChecked(hDlg, IDC_DLG_NO_SHOW_AGAIN))
  105. {
  106. pDialogData->bDoNotShowWasChecked = TRUE;
  107. }
  108. else
  109. {
  110. pDialogData->bDoNotShowWasChecked = FALSE;
  111. }
  112. }
  113. return TRUE;
  114. }
  115. }
  116. }
  117. break;
  118. }
  119. case WM_CLOSE:
  120. {
  121. EndDialog(hDlg, IDNO);
  122. return 0;
  123. }
  124. }
  125. return FALSE;
  126. }
  127. /*++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  128. Function : UserApprovedOperation
  129. Synopsis : Pop UI to prompt user to approve an operation.
  130. Parameter: DWORD iddDialog - Dialog ID.
  131. LPWSTR pwszDomain - DNS name.
  132. Remark :
  133. ------------------------------------------------------------------------------*/
  134. HRESULT UserApprovedOperation (DWORD iddDialog, LPWSTR pwszDomain)
  135. {
  136. HRESULT hr = S_OK;
  137. INT_PTR iDlgRet = 0;
  138. PCAPICOM_DIALOG_DATA pDialogData = NULL;
  139. DebugTrace("Entering UserApprovedOperation().\n");
  140. //
  141. // Sanity check.
  142. //
  143. ATLASSERT(iddDialog);
  144. ATLASSERT(pwszDomain);
  145. //
  146. // Determine dialog box.
  147. //
  148. for (DWORD i = 0; i < g_NumDialogs; i++)
  149. {
  150. if (iddDialog == g_DialogData[i].dwDlgId)
  151. {
  152. break;
  153. }
  154. }
  155. if (i == g_NumDialogs)
  156. {
  157. hr = CAPICOM_E_INTERNAL;
  158. DebugTrace("Error [%#x]: Unknown dialog ID (iddDialog = %#x).\n", hr, iddDialog);
  159. goto ErrorExit;
  160. }
  161. //
  162. // Point to the dialog data.
  163. //
  164. pDialogData = &g_DialogData[i];
  165. //
  166. // Had the domain changed?
  167. //
  168. if (0 != _wcsicmp(pDialogData->wszDomainName, pwszDomain))
  169. {
  170. //
  171. // Reset stickiness.
  172. //
  173. pDialogData->bWasApproved = FALSE;
  174. pDialogData->bDoNotShowWasChecked = FALSE;
  175. wcsncpy(pDialogData->wszDomainName, pwszDomain, INTERNET_MAX_URL_LENGTH);
  176. pDialogData->wszDomainName[INTERNET_MAX_URL_LENGTH - 1] = '\0';
  177. }
  178. //
  179. // Pop if necessary.
  180. //
  181. if (pDialogData->bDoNotShowWasChecked)
  182. {
  183. //
  184. // The "Do not show..." had been previously checked, so we will
  185. // only allow the operation if it was previously allowed.
  186. //
  187. if (!pDialogData->bWasApproved)
  188. {
  189. hr = CAPICOM_E_CANCELLED;
  190. DebugTrace("Info: operation presumed cancelled since \"Do not show...\" was checked and the last response wasn't YES.\n");
  191. }
  192. }
  193. else
  194. {
  195. //
  196. // The "Do not show..." had not been checked previously, so pop.
  197. //
  198. if (-1 == (iDlgRet = ::DialogBoxParamA(_Module.GetResourceInstance(),
  199. (LPSTR) MAKEINTRESOURCE(iddDialog),
  200. NULL,
  201. UserApprovedOperationDlgProc,
  202. (LPARAM) pDialogData)))
  203. {
  204. hr = HRESULT_FROM_WIN32(::GetLastError());
  205. DebugTrace("Error [%#x]: DialogBoxParam() failed.\n");
  206. goto ErrorExit;
  207. }
  208. //
  209. // Check result.
  210. //
  211. if (IDYES == iDlgRet)
  212. {
  213. //
  214. // For Store.Open dialog, we always force the "Do not show..." condition.
  215. //
  216. if (IDD_STORE_OPEN_SECURITY_ALERT_DLG == iddDialog)
  217. {
  218. pDialogData->bDoNotShowWasChecked = TRUE;
  219. }
  220. pDialogData->bWasApproved = TRUE;
  221. }
  222. else
  223. {
  224. pDialogData->bWasApproved = FALSE;
  225. hr = CAPICOM_E_CANCELLED;
  226. DebugTrace("Info: operation has been cancelled by user.\n");
  227. }
  228. }
  229. CommonExit:
  230. DebugTrace("Leaving UserApprovedOperation().\n");
  231. return hr;
  232. ErrorExit:
  233. //
  234. // Sanity check.
  235. //
  236. ATLASSERT(FAILED(hr));
  237. goto CommonExit;
  238. }