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.

423 lines
14 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. //
  5. // Copyright (C) Microsoft Corporation, 1997 - 1999
  6. //
  7. // File: crlgen.cpp
  8. //
  9. //--------------------------------------------------------------------------
  10. #include "global.hxx"
  11. #include <dbgdef.h>
  12. extern HINSTANCE HinstDll;
  13. extern HMODULE HmodRichEdit;
  14. static const HELPMAP helpmap[] = {
  15. {IDC_CRL_GENERAL_ITEM_LIST, IDH_CRLVIEW_GENERAL_ITEM_LIST},
  16. {IDC_CRL_GENERAL_DETAIL_EDIT, IDH_CRLVIEW_GENERAL_ITEM_EDIT}
  17. };
  18. //////////////////////////////////////////////////////////////////////////////////////
  19. // This function will take a HWND for a list view and a certinfo struct and display
  20. // all the V1 fields of the cert in the list view
  21. //////////////////////////////////////////////////////////////////////////////////////
  22. static void DisplayV1Fields(HWND hWndListView, PCRL_INFO pCrlInfo, DWORD *index)
  23. {
  24. LPWSTR pwszText;
  25. WCHAR szFieldText[_MAX_PATH]; // used for calls to LoadString only
  26. LV_ITEMW lvI;
  27. char szVersion[32];
  28. LPWSTR pszVersion;
  29. FILETIME tempFileTime;
  30. //
  31. // set up the fields in the list view item struct that don't change from item to item
  32. //
  33. lvI.mask = LVIF_TEXT | LVIF_IMAGE | LVIF_PARAM | LVIF_STATE;
  34. lvI.state = 0;
  35. lvI.stateMask = 0;
  36. lvI.pszText = szFieldText;
  37. lvI.iSubItem = 0;
  38. lvI.iImage = IMAGE_V1;
  39. lvI.lParam = (LPARAM)NULL;
  40. //
  41. // version
  42. //
  43. lvI.iItem = (*index)++;
  44. LoadStringU(HinstDll, IDS_ADV_VERSION, szFieldText, ARRAYSIZE(szFieldText));
  45. lvI.cchTextMax = wcslen(szFieldText);
  46. wsprintfA(szVersion, "V%d", pCrlInfo->dwVersion+1);
  47. if (NULL != (pszVersion = CertUIMkWStr(szVersion)))
  48. {
  49. lvI.lParam = (LPARAM) MakeListDisplayHelper(FALSE, pszVersion, NULL, 0);
  50. ListView_InsertItemU(hWndListView, &lvI);
  51. ListView_SetItemTextU(hWndListView, (*index)-1 , 1, pszVersion);
  52. }
  53. //
  54. // issuer
  55. //
  56. LoadStringU(HinstDll, IDS_ADV_ISSUER, szFieldText, ARRAYSIZE(szFieldText));
  57. lvI.cchTextMax = wcslen(szFieldText);
  58. if (FormatDNNameString(&pwszText, pCrlInfo->Issuer.pbData, pCrlInfo->Issuer.cbData, TRUE))
  59. {
  60. lvI.iItem = (*index)++;
  61. lvI.lParam = (LPARAM) MakeListDisplayHelper(FALSE, pwszText, NULL, 0);
  62. ListView_InsertItemU(hWndListView, &lvI);
  63. if (FormatDNNameString(&pwszText, pCrlInfo->Issuer.pbData, pCrlInfo->Issuer.cbData, FALSE))
  64. {
  65. ListView_SetItemTextU(hWndListView, (*index)-1 , 1, pwszText);
  66. free(pwszText);
  67. }
  68. }
  69. //
  70. // Effective Data
  71. //
  72. if (FormatDateString(&pwszText, pCrlInfo->ThisUpdate, TRUE, TRUE, hWndListView))
  73. {
  74. lvI.iItem = (*index)++;
  75. LoadStringU(HinstDll, IDS_ADV_THISUPDATE, szFieldText, ARRAYSIZE(szFieldText));
  76. lvI.cchTextMax = wcslen(szFieldText);
  77. lvI.lParam = (LPARAM) MakeListDisplayHelper(FALSE, pwszText, NULL, 0);
  78. ListView_InsertItemU(hWndListView, &lvI);
  79. ListView_SetItemTextU(hWndListView, (*index)-1 , 1, pwszText);
  80. }
  81. //
  82. // Next Update
  83. //
  84. memset(&tempFileTime, 0, sizeof(FILETIME));
  85. if (memcmp(&tempFileTime, &(pCrlInfo->NextUpdate), sizeof(FILETIME)) != 0)
  86. {
  87. if (FormatDateString(&pwszText, pCrlInfo->NextUpdate, TRUE, TRUE, hWndListView))
  88. {
  89. lvI.iItem = (*index)++;
  90. LoadStringU(HinstDll, IDS_ADV_NEXTUPDATE, szFieldText, ARRAYSIZE(szFieldText));
  91. lvI.cchTextMax = wcslen(szFieldText);
  92. lvI.lParam = (LPARAM) MakeListDisplayHelper(FALSE, pwszText, NULL, 0);
  93. ListView_InsertItemU(hWndListView, &lvI);
  94. ListView_SetItemTextU(hWndListView, (*index)-1 , 1, pwszText);
  95. }
  96. }
  97. //
  98. // signature algorithm
  99. //
  100. if (FormatAlgorithmString(&pwszText, &(pCrlInfo->SignatureAlgorithm)))
  101. {
  102. lvI.iItem = (*index)++;
  103. LoadStringU(HinstDll, IDS_ADV_SIG_ALG, szFieldText, ARRAYSIZE(szFieldText));
  104. lvI.cchTextMax = wcslen(szFieldText);
  105. lvI.lParam = (LPARAM) MakeListDisplayHelper(FALSE, pwszText, NULL, 0);
  106. ListView_InsertItemU(hWndListView, &lvI);
  107. ListView_SetItemTextU(hWndListView, (*index)-1 , 1, pwszText);
  108. }
  109. }
  110. INT_PTR APIENTRY ViewPageCRLGeneral(HWND hwndDlg, UINT msg, WPARAM wParam,
  111. LPARAM lParam)
  112. {
  113. DWORD i;
  114. PROPSHEETPAGE *ps;
  115. PCCRL_CONTEXT pcrl;
  116. CRL_VIEW_HELPER *pviewhelp;
  117. HIMAGELIST hIml;
  118. HWND hWndListView;
  119. HWND hwnd;
  120. LV_COLUMNW lvC;
  121. WCHAR szText[CRYPTUI_MAX_STRING_SIZE];
  122. WCHAR szCompareText[CRYPTUI_MAX_STRING_SIZE];
  123. PCRL_INFO pCrlInfo;
  124. LVITEMW lvI;
  125. LPNMLISTVIEW pnmv;
  126. CHARFORMAT chFormat;
  127. switch ( msg ) {
  128. case WM_INITDIALOG:
  129. //
  130. // save the pviewhelp struct in DWLP_USER so it can always be accessed
  131. //
  132. ps = (PROPSHEETPAGE *) lParam;
  133. pviewhelp = (CRL_VIEW_HELPER *) (ps->lParam);
  134. pcrl = pviewhelp->pcvcrl->pCRLContext;
  135. SetWindowLongPtr(hwndDlg, DWLP_USER, (DWORD_PTR) pviewhelp);
  136. //
  137. // clear the text in the detail edit box
  138. //
  139. CryptUISetRicheditTextW(hwndDlg, IDC_CRL_GENERAL_DETAIL_EDIT, L"");
  140. //
  141. // get the handle of the list view control
  142. //
  143. hWndListView = GetDlgItem(hwndDlg, IDC_CRL_GENERAL_ITEM_LIST);
  144. //
  145. // initialize the image list for the list view, load the icons,
  146. // then add the image list to the list view
  147. //
  148. hIml = ImageList_LoadImage(HinstDll, MAKEINTRESOURCE(IDB_PROPLIST), 0, 4, RGB(0,128,128), IMAGE_BITMAP, 0);
  149. if (hIml != NULL)
  150. {
  151. ListView_SetImageList(hWndListView, hIml, LVSIL_SMALL);
  152. }
  153. //
  154. // initialize the columns in the list view
  155. //
  156. lvC.mask = LVCF_FMT | LVCF_WIDTH | LVCF_TEXT | LVCF_SUBITEM;
  157. lvC.fmt = LVCFMT_LEFT; // Left-align the column.
  158. lvC.pszText = szText; // The text for the column.
  159. // Add the columns. They are loaded from a string table.
  160. lvC.iSubItem = 0;
  161. lvC.cx = 130;
  162. LoadStringU(HinstDll, IDS_FIELD, szText, ARRAYSIZE(szText));
  163. if (ListView_InsertColumnU(hWndListView, 0, &lvC) == -1)
  164. {
  165. // error
  166. }
  167. lvC.cx = 190;
  168. LoadStringU(HinstDll, IDS_VALUE, szText, ARRAYSIZE(szText));
  169. if (ListView_InsertColumnU(hWndListView, 1, &lvC) == -1)
  170. {
  171. // error
  172. }
  173. //
  174. // add all the certificate fields to the list box
  175. //
  176. i = 0;
  177. DisplayV1Fields(hWndListView, pcrl->pCrlInfo, &i);
  178. DisplayExtensions(hWndListView, pcrl->pCrlInfo->cExtension, pcrl->pCrlInfo->rgExtension, FALSE, &i);
  179. DisplayExtensions(hWndListView, pcrl->pCrlInfo->cExtension, pcrl->pCrlInfo->rgExtension, TRUE, &i);
  180. //
  181. // set the style in the list view so that it highlights an entire line
  182. //
  183. SendMessageA(hWndListView, LVM_SETEXTENDEDLISTVIEWSTYLE, 0, LVS_EX_FULLROWSELECT);
  184. //
  185. // load the header icon and fill in the header text and set styles for the header edit control
  186. //
  187. pviewhelp->hIcon = LoadIcon(HinstDll, MAKEINTRESOURCE(IDI_REVOCATIONLIST));
  188. LoadStringU(HinstDll, IDS_CRL_INFORMATION, (LPWSTR)szText, ARRAYSIZE(szText));
  189. CryptUISetRicheditTextW(hwndDlg, IDC_CRL_GENERAL_HEADER_EDIT, szText);
  190. CertSubclassEditControlForArrowCursor(GetDlgItem(hwndDlg, IDC_CRL_GENERAL_HEADER_EDIT));
  191. memset(&chFormat, 0, sizeof(chFormat));
  192. chFormat.cbSize = sizeof(chFormat);
  193. chFormat.dwMask = CFM_BOLD;
  194. chFormat.dwEffects = CFE_BOLD;
  195. SendMessageA(GetDlgItem(hwndDlg, IDC_CRL_GENERAL_HEADER_EDIT), EM_SETCHARFORMAT, SCF_ALL, (LPARAM) &chFormat);
  196. return TRUE;
  197. case WM_NOTIFY:
  198. pviewhelp = (CRL_VIEW_HELPER *) GetWindowLongPtr(hwndDlg, DWLP_USER);
  199. pcrl = pviewhelp->pcvcrl->pCRLContext;
  200. pCrlInfo = pcrl->pCrlInfo;
  201. switch (((NMHDR FAR *) lParam)->code)
  202. {
  203. case PSN_SETACTIVE:
  204. break;
  205. case PSN_APPLY:
  206. SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, (LRESULT)TRUE);
  207. break;
  208. case PSN_KILLACTIVE:
  209. SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, (LRESULT)FALSE);
  210. return TRUE;
  211. case PSN_RESET:
  212. SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, (LRESULT)FALSE);
  213. break;
  214. case PSN_QUERYCANCEL:
  215. pviewhelp->fCancelled = TRUE;
  216. return FALSE;
  217. case PSN_HELP:
  218. pviewhelp = (CRL_VIEW_HELPER *) GetWindowLongPtr(hwndDlg, DWLP_USER);
  219. if (FIsWin95) {
  220. //WinHelpA(hwndDlg, (LPSTR) pviewhelp->pcvcrl->szHelpFileName,
  221. // HELP_CONTEXT, pviewhelp->pcvcrl->dwHelpId);
  222. }
  223. else {
  224. //WinHelpW(hwndDlg, pviewhelp->pcvcrl->szHelpFileName, HELP_CONTEXT,
  225. // pviewhelp->pcvcrl->dwHelpId);
  226. }
  227. return TRUE;
  228. case LVN_ITEMCHANGING:
  229. if ((((NMHDR FAR *) lParam)->idFrom) != IDC_CRL_GENERAL_ITEM_LIST)
  230. {
  231. break;
  232. }
  233. pnmv = (LPNMLISTVIEW) lParam;
  234. if (pnmv->uNewState & LVIS_SELECTED)
  235. {
  236. DisplayHelperTextInEdit(
  237. GetDlgItem(hwndDlg, IDC_CRL_GENERAL_ITEM_LIST),
  238. hwndDlg,
  239. IDC_CRL_GENERAL_DETAIL_EDIT,
  240. pnmv->iItem);
  241. }
  242. return TRUE;
  243. case NM_CLICK:
  244. break;
  245. case NM_SETFOCUS:
  246. switch (((NMHDR FAR *) lParam)->idFrom)
  247. {
  248. case IDC_CRL_GENERAL_ITEM_LIST:
  249. hWndListView = GetDlgItem(hwndDlg, IDC_CRL_GENERAL_ITEM_LIST);
  250. if ((ListView_GetItemCount(hWndListView) != 0) &&
  251. (ListView_GetNextItem(hWndListView, -1, LVNI_SELECTED) == -1))
  252. {
  253. memset(&lvI, 0, sizeof(lvI));
  254. lvI.mask = LVIF_STATE;
  255. lvI.iItem = 0;
  256. lvI.state = LVIS_FOCUSED;
  257. lvI.stateMask = LVIS_FOCUSED;
  258. ListView_SetItem(hWndListView, &lvI);
  259. }
  260. break;
  261. }
  262. break;
  263. }
  264. break;
  265. case WM_COMMAND:
  266. pviewhelp = (CRL_VIEW_HELPER *) GetWindowLongPtr(hwndDlg, DWLP_USER);
  267. pcrl = pviewhelp->pcvcrl->pCRLContext;
  268. pCrlInfo = pcrl->pCrlInfo;
  269. switch (LOWORD(wParam))
  270. {
  271. case IDHELP:
  272. if (FIsWin95) {
  273. //WinHelpA(hwndDlg, (LPSTR) pviewhelp->pcvcrl->szHelpFileName,
  274. // HELP_CONTEXT, pviewhelp->pcvcrl->dwHelpId);
  275. }
  276. else {
  277. //WinHelpW(hwndDlg, pviewhelp->pcvcrl->szHelpFileName, HELP_CONTEXT,
  278. // pviewhelp->pcvcrl->dwHelpId);
  279. }
  280. return TRUE;
  281. }
  282. break;
  283. case WM_PAINT:
  284. RECT rect;
  285. PAINTSTRUCT paintstruct;
  286. HDC hdc;
  287. COLORREF colorRef;
  288. pviewhelp = (CRL_VIEW_HELPER *) GetWindowLongPtr(hwndDlg, DWLP_USER);
  289. if (GetUpdateRect(hwndDlg, &rect, FALSE))
  290. {
  291. hdc = BeginPaint(hwndDlg, &paintstruct);
  292. if (hdc == NULL)
  293. {
  294. EndPaint(hwndDlg, &paintstruct);
  295. break;
  296. }
  297. colorRef = GetBkColor(hdc);
  298. SendMessageA(GetDlgItem(hwndDlg, IDC_CRL_GENERAL_HEADER_EDIT), EM_SETBKGNDCOLOR, 0, (LPARAM) colorRef);
  299. if (pviewhelp->hIcon != NULL)
  300. {
  301. DrawIcon(
  302. hdc,
  303. ICON_X_POS,
  304. ICON_Y_POS,
  305. pviewhelp->hIcon);
  306. }
  307. EndPaint(hwndDlg, &paintstruct);
  308. }
  309. break;
  310. case WM_DESTROY:
  311. pviewhelp = (CRL_VIEW_HELPER *) GetWindowLongPtr(hwndDlg, DWLP_USER);
  312. //
  313. // get all the items in the list view and free the lParam
  314. // associated with each of them (lParam is the helper sruct)
  315. //
  316. hWndListView = GetDlgItem(hwndDlg, IDC_CRL_GENERAL_ITEM_LIST);
  317. memset(&lvI, 0, sizeof(lvI));
  318. lvI.iItem = ListView_GetItemCount(hWndListView) - 1;
  319. lvI.mask = LVIF_PARAM;
  320. while (lvI.iItem >= 0)
  321. {
  322. if (ListView_GetItemU(hWndListView, &lvI))
  323. {
  324. FreeListDisplayHelper((PLIST_DISPLAY_HELPER) lvI.lParam);
  325. }
  326. lvI.iItem--;
  327. }
  328. if (pviewhelp->hIcon != NULL)
  329. {
  330. DeleteObject(pviewhelp->hIcon);
  331. pviewhelp->hIcon = NULL;
  332. }
  333. break;
  334. case WM_HELP:
  335. case WM_CONTEXTMENU:
  336. if (msg == WM_HELP)
  337. {
  338. hwnd = GetDlgItem(hwndDlg, ((LPHELPINFO)lParam)->iCtrlId);
  339. }
  340. else
  341. {
  342. hwnd = (HWND) wParam;
  343. }
  344. if ((hwnd != GetDlgItem(hwndDlg, IDC_CRL_GENERAL_ITEM_LIST)) &&
  345. (hwnd != GetDlgItem(hwndDlg, IDC_CRL_GENERAL_DETAIL_EDIT)))
  346. {
  347. SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, (LRESULT)TRUE);
  348. return TRUE;
  349. }
  350. else
  351. {
  352. return OnContextHelp(hwndDlg, msg, wParam, lParam, helpmap);
  353. }
  354. }
  355. return FALSE;
  356. }