ntdll: Fix compilation on systems that don't support nameless unions.
[wine] / dlls / wintrust / wintrust_main.c
1 /*
2  * Copyright 2001 Rein Klazes
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
17  */
18
19 #include "config.h"
20
21 #include <stdarg.h>
22
23 #include "windef.h"
24 #include "winbase.h"
25 #include "winerror.h"
26 #include "winreg.h"
27 #include "guiddef.h"
28 #include "wintrust.h"
29 #include "softpub.h"
30 #include "mscat.h"
31 #include "objbase.h"
32
33 #include "wine/debug.h"
34
35 WINE_DEFAULT_DEBUG_CHANNEL(wintrust);
36
37
38 /***********************************************************************
39  *              DllMain  (WINTRUST.@)
40  */
41 BOOL WINAPI DllMain( HINSTANCE inst, DWORD reason, LPVOID reserved )
42 {
43     switch(reason)
44     {
45     case DLL_WINE_PREATTACH:
46         return FALSE;  /* prefer native version */
47     case DLL_PROCESS_ATTACH:
48         DisableThreadLibraryCalls( inst );
49         break;
50     }
51     return TRUE;
52 }
53
54 /***********************************************************************
55  *              TrustIsCertificateSelfSigned (WINTRUST.@)
56  */
57 BOOL WINAPI TrustIsCertificateSelfSigned( PCCERT_CONTEXT cert )
58 {
59     BOOL ret;
60
61     TRACE("%p\n", cert);
62     ret = CertCompareCertificateName(cert->dwCertEncodingType,
63      &cert->pCertInfo->Subject, &cert->pCertInfo->Issuer);
64     return ret;
65 }
66
67 /***********************************************************************
68  *              WinVerifyTrust (WINTRUST.@)
69  *
70  * Verifies an object by calling the specified trust provider.
71  *
72  * PARAMS
73  *   hwnd       [I] Handle to a caller window.
74  *   ActionID   [I] Pointer to a GUID that identifies the action to perform.
75  *   ActionData [I] Information used by the trust provider to verify the object.
76  *
77  * RETURNS
78  *   Success: Zero.
79  *   Failure: A TRUST_E_* error code.
80  *
81  * NOTES
82  *   Trust providers can be found at:
83  *   HKLM\SOFTWARE\Microsoft\Cryptography\Providers\Trust\
84  */
85 LONG WINAPI WinVerifyTrust( HWND hwnd, GUID *ActionID, LPVOID ActionData )
86 {
87     FIXME("%p %s %p\n", hwnd, debugstr_guid(ActionID), ActionData);
88     return ERROR_SUCCESS;
89 }
90
91 /***********************************************************************
92  *              WinVerifyTrustEx (WINTRUST.@)
93  */
94 HRESULT WINAPI WinVerifyTrustEx( HWND hwnd, GUID *ActionID,
95  WINTRUST_DATA* ActionData )
96 {
97     FIXME("%p %s %p\n", hwnd, debugstr_guid(ActionID), ActionData);
98     return S_OK;
99 }
100
101 /***********************************************************************
102  *              WTHelperGetProvSignerFromChain (WINTRUST.@)
103  */
104 CRYPT_PROVIDER_SGNR * WINAPI WTHelperGetProvSignerFromChain(
105  CRYPT_PROVIDER_DATA *pProvData, DWORD idxSigner, BOOL fCounterSigner,
106  DWORD idxCounterSigner)
107 {
108     FIXME("%p %d %d %d\n", pProvData, idxSigner, fCounterSigner,
109      idxCounterSigner);
110     return NULL;
111 }
112
113 /***********************************************************************
114  *              WTHelperProvDataFromStateData (WINTRUST.@)
115  */
116 CRYPT_PROVIDER_DATA * WINAPI WTHelperProvDataFromStateData(HANDLE hStateData)
117 {
118     FIXME("%p\n", hStateData);
119     return NULL;
120 }
121
122 static const WCHAR Software_Publishing[] = {
123  'S','o','f','t','w','a','r','e','\\',
124  'M','i','c','r','o','s','o','f','t','\\',
125  'W','i','n','d','o','w','s','\\',
126  'C','u','r','r','e','n','t','V','e','r','s','i','o','n','\\',
127  'W','i','n','t','r','u','s','t','\\',
128  'T','r','u','s','t',' ','P','r','o','v','i','d','e','r','s','\\',
129  'S','o','f','t','w','a','r','e',' ',
130  'P','u','b','l','i','s','h','i','n','g',0 };
131 static const WCHAR State[] = { 'S','t','a','t','e',0 };
132
133 /***********************************************************************
134  *              WintrustGetRegPolicyFlags (WINTRUST.@)
135  */
136 void WINAPI WintrustGetRegPolicyFlags( DWORD* pdwPolicyFlags )
137 {
138     HKEY key;
139     LONG r;
140
141     TRACE("%p\n", pdwPolicyFlags);
142
143     *pdwPolicyFlags = 0;
144     r = RegCreateKeyExW(HKEY_CURRENT_USER, Software_Publishing, 0, NULL, 0,
145      KEY_READ, NULL, &key, NULL);
146     if (!r)
147     {
148         DWORD size = sizeof(DWORD);
149
150         r = RegQueryValueExW(key, State, NULL, NULL, (LPBYTE)pdwPolicyFlags,
151          &size);
152         RegCloseKey(key);
153         if (r)
154         {
155             /* Failed to query, create and return default value */
156             *pdwPolicyFlags = WTPF_IGNOREREVOCATIONONTS |
157              WTPF_OFFLINEOKNBU_COM |
158              WTPF_OFFLINEOKNBU_IND |
159              WTPF_OFFLINEOK_COM |
160              WTPF_OFFLINEOK_IND;
161             WintrustSetRegPolicyFlags(*pdwPolicyFlags);
162         }
163     }
164 }
165
166 /***********************************************************************
167  *              WintrustSetRegPolicyFlags (WINTRUST.@)
168  */
169 BOOL WINAPI WintrustSetRegPolicyFlags( DWORD dwPolicyFlags)
170 {
171     HKEY key;
172     LONG r;
173
174     TRACE("%x\n", dwPolicyFlags);
175
176     r = RegCreateKeyExW(HKEY_CURRENT_USER, Software_Publishing, 0,
177      NULL, 0, KEY_WRITE, NULL, &key, NULL);
178     if (!r)
179     {
180         r = RegSetValueExW(key, State, 0, REG_DWORD, (LPBYTE)&dwPolicyFlags,
181          sizeof(DWORD));
182         RegCloseKey(key);
183     }
184     if (r) SetLastError(r);
185     return r == ERROR_SUCCESS;
186 }