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.

245 lines
7.0 KiB

  1. /*
  2. ** c e r e r d l g . c p p
  3. **
  4. ** Purpose:
  5. ** Handles the certificate error dialog box
  6. **
  7. ** History
  8. ** 2/17/97: (t-erikne) Created.
  9. **
  10. ** Copyright (C) Microsoft Corp. 1997.
  11. */
  12. ///////////////////////////////////////////////////////////////////////////
  13. //
  14. // Depends on
  15. //
  16. #include "pch.hxx"
  17. #include <resource.h>
  18. #include <mimeole.h>
  19. #include "demand.h"
  20. #include "secutil.h"
  21. // from globals.h
  22. //N why didn't this work?
  23. //extern IMimeAllocator *g_pMoleAlloc;
  24. ///////////////////////////////////////////////////////////////////////////
  25. //
  26. // Prototypes
  27. //
  28. INT_PTR CALLBACK CertErrorDlgProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam);
  29. static void FillListView(HWND hwndList, IMimeAddressTable *pAdrTable);
  30. static void InitListView(HWND hwndList);
  31. ///////////////////////////////////////////////////////////////////////////
  32. //
  33. // Functions
  34. //
  35. INT_PTR CALLBACK CertErrorDlgProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
  36. {
  37. CERTERRPARAM * pCertErrParam = NULL;
  38. IMimeAddressTable *pAdrTable = NULL;
  39. TCHAR szText[CCHMAX_STRINGRES];
  40. switch (message)
  41. {
  42. case WM_INITDIALOG:
  43. HWND hwndList;
  44. CenterDialog(hwnd);
  45. // save our cookie pointer
  46. Assert(pAdrTable == NULL);
  47. pCertErrParam = (CERTERRPARAM *) lParam;
  48. pAdrTable = pCertErrParam->pAdrTable;
  49. Assert(pAdrTable != NULL);
  50. //N not needed right now
  51. //SetWindowLong(hwnd, DWL_USER, (LONG)pAdrTable);
  52. // set initial state of controls
  53. hwndList = GetDlgItem(hwnd, idcCertList);
  54. if (hwndList)
  55. {
  56. InitListView(hwndList);
  57. FillListView(hwndList, pAdrTable);
  58. }
  59. // Force Encryption change static text and disable OK button)
  60. if(pCertErrParam->fForceEncryption)
  61. {
  62. szText[0] = _T('\0');
  63. AthLoadString(idsSecPolicyForceEncr,
  64. szText, ARRAYSIZE(szText));
  65. SetDlgItemText(hwnd, idcErrStat, szText);
  66. EnableWindow(GetDlgItem(hwnd, IDOK), FALSE);
  67. }
  68. return(TRUE);
  69. case WM_HELP:
  70. case WM_CONTEXTMENU:
  71. //return OnContextHelp(hwnd, message, wParam, lParam, g_rgCtxMapMailRead);
  72. return FALSE; // BUGBUG: should no doubt do something else here
  73. case WM_COMMAND:
  74. // remember to bail if the cookie is null
  75. switch (LOWORD(wParam))
  76. {
  77. case IDOK:
  78. {
  79. }
  80. // fall through...
  81. case IDCANCEL:
  82. EndDialog(hwnd, LOWORD(wParam));
  83. return(TRUE);
  84. break;
  85. }
  86. break; // wm_command
  87. case WM_CLOSE:
  88. SendMessage(hwnd, WM_COMMAND, IDCANCEL, 0L);
  89. return (TRUE);
  90. } // message switch
  91. return(FALSE);
  92. }
  93. void InitListView(HWND hwndList)
  94. {
  95. LV_COLUMN lvc;
  96. RECT rc;
  97. // Set up the columns. The first column will be for the person's
  98. // name and the second for the certificate error
  99. GetClientRect(hwndList, &rc);
  100. lvc.mask = LVCF_FMT | LVCF_WIDTH;
  101. lvc.fmt = LVCFMT_LEFT;
  102. lvc.cx = rc.right / 2;
  103. ListView_InsertColumn(hwndList, 0, &lvc);
  104. ListView_InsertColumn(hwndList, 1, &lvc);
  105. }
  106. void FillListView(HWND hwndList, IMimeAddressTable *pAdrTable)
  107. {
  108. IMimeEnumAddressTypes *pEnum;
  109. const ULONG numToGet = 1;
  110. ADDRESSPROPS rAddress;
  111. LV_ITEM lvi;
  112. TCHAR szText[CCHMAX_STRINGRES];
  113. Assert(g_pMoleAlloc && hwndList && pAdrTable);
  114. if (FAILED(pAdrTable->EnumTypes(IAT_ALL, IAP_ADRTYPE | IAP_CERTSTATE | IAP_FRIENDLY, &pEnum)))
  115. return;
  116. lvi.mask = LVIF_TEXT;
  117. lvi.iItem = 0;
  118. lvi.stateMask = 0;
  119. while(S_OK == pEnum->Next(numToGet, &rAddress, NULL))
  120. {
  121. if (CERTIFICATE_OK != rAddress.certstate)
  122. {
  123. // if this is the sender and the problem is that the cert
  124. // is missing, ignore it. We handle that elsewhere
  125. if (IAT_FROM == rAddress.dwAdrType &&
  126. FMissingCert(rAddress.certstate))
  127. {
  128. continue;
  129. }
  130. // we have a body worthy of viewing
  131. if (NULL != rAddress.pszFriendly)
  132. {
  133. lvi.iSubItem = 0;
  134. lvi.pszText = rAddress.pszFriendly;
  135. if (-1 == ListView_InsertItem(hwndList, &lvi))
  136. goto freecont;
  137. // now compute the actual certificate error text
  138. // subtract one becuse the enum is zero-based
  139. AthLoadString(idsSecurityCertMissing+(UINT)rAddress.certstate-1,
  140. szText, ARRAYSIZE(szText));
  141. lvi.iSubItem = 1;
  142. lvi.pszText = szText;
  143. ListView_SetItem(hwndList, &lvi);
  144. }
  145. }
  146. freecont:
  147. g_pMoleAlloc->FreeAddressProps(&rAddress);
  148. }
  149. ReleaseObj(pEnum);
  150. return;
  151. }
  152. INT_PTR CALLBACK CertWarnDlgProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
  153. {
  154. ERRIDS *pErrIds = NULL;
  155. TCHAR szRes[CCHMAX_STRINGRES];
  156. switch (message)
  157. {
  158. case WM_INITDIALOG:
  159. CenterDialog(hwnd);
  160. // save our cookie pointer
  161. Assert(pErrIds == NULL);
  162. pErrIds = (ERRIDS *)lParam;
  163. Assert(pErrIds != NULL);
  164. //N not needed right now
  165. //SetWindowLong(hwnd, DWL_USER, (LONG)pAdrTable);
  166. // set initial state of controls
  167. AthLoadString(pErrIds->idsText1, szRes, sizeof(szRes));
  168. SetDlgItemText(hwnd, idcStatic1, szRes);
  169. AthLoadString(pErrIds->idsText2, szRes, sizeof(szRes));
  170. SetDlgItemText(hwnd, idcStatic2, szRes);
  171. return(TRUE);
  172. case WM_HELP:
  173. case WM_CONTEXTMENU:
  174. //return OnContextHelp(hwnd, message, wParam, lParam, g_rgCtxMapMailRead);
  175. return FALSE; // BUGBUG: should no doubt do something else here
  176. case WM_COMMAND:
  177. // remember to bail if the cookie is null
  178. switch (LOWORD(wParam))
  179. {
  180. case IDOK:
  181. // fall through...
  182. case IDC_DONTSIGN:
  183. // fall through...
  184. case IDCANCEL:
  185. EndDialog(hwnd, LOWORD(wParam));
  186. return(TRUE);
  187. break;
  188. }
  189. break; // wm_command
  190. case WM_CLOSE:
  191. SendMessage(hwnd, WM_COMMAND, IDCANCEL, 0L);
  192. return (TRUE);
  193. } // message switch
  194. return(FALSE);
  195. }