[NTOS:SE] Capture the groups length when creating a token
[reactos.git] / dll / shellext / cryptext / cryptext.c
1 /*
2 * PROJECT: ReactOS CryptExt Shell Extension
3 * LICENSE: GPL-2.0+ (https://spdx.org/licenses/GPL-2.0+)
4 * PURPOSE: cryptext implementation
5 * COPYRIGHT: Copyright 2019 Mark Jansen (mark.jansen@reactos.org)
6 */
7
8 #include "precomp.h"
9
10 HINSTANCE g_hInstance;
11
12 BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID lpReserved)
13 {
14 switch (dwReason)
15 {
16 case DLL_PROCESS_ATTACH:
17 g_hInstance = hInstance;
18 DisableThreadLibraryCalls(hInstance);
19 break;
20 }
21
22 return TRUE;
23 }
24
25 EXTERN_C
26 VOID WINAPI CryptExtOpenCERW(HWND hWnd, HINSTANCE hInst, LPCWSTR file, DWORD nCmdShow)
27 {
28 PCCERT_CONTEXT pvContext;
29 if (file)
30 {
31 if (CryptQueryObject(CERT_QUERY_OBJECT_FILE, file, CERT_QUERY_CONTENT_FLAG_CERT, CERT_QUERY_FORMAT_FLAG_ALL,
32 0, NULL, NULL, NULL, NULL, NULL, (CONST VOID**)&pvContext))
33 {
34 CRYPTUI_VIEWCERTIFICATE_STRUCTW CertViewInfo = {0};
35 CertViewInfo.dwSize = sizeof(CertViewInfo);
36 CertViewInfo.pCertContext = pvContext;
37 CryptUIDlgViewCertificateW(&CertViewInfo, NULL);
38 CertFreeCertificateContext(pvContext);
39 }
40 else
41 {
42 WCHAR Message[MAX_PATH];
43
44 if (LoadStringW(g_hInstance, IDS_INVALIDFILE, Message, MAX_PATH))
45 {
46 MessageBoxW(NULL, Message, NULL, MB_OK);
47 }
48 else
49 {
50 MessageBoxW(NULL, L"This is not a valid certificate file.", NULL, MB_OK);
51 }
52 }
53 }
54 }
55
56 EXTERN_C
57 VOID WINAPI CryptExtOpenCER(HWND hWnd, HINSTANCE hInst, LPCSTR file, DWORD nCmdShow)
58 {
59 LPWSTR fileW;
60 int len;
61
62 if (file)
63 {
64
65 len = MultiByteToWideChar(CP_ACP, 0, file, -1, NULL, 0);
66 fileW = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
67 if (fileW)
68 {
69 MultiByteToWideChar(CP_ACP, 0, file, -1, fileW, len);
70 CryptExtOpenCERW(hWnd, hInst, fileW, nCmdShow);
71 HeapFree(GetProcessHeap(), 0, fileW);
72 }
73 }
74 }