crypt32: Remove unneeded casts of zero.
[wine] / dlls / crypt32 / main.c
1 /*
2  * Copyright 2002 Mike McCormack for CodeWeavers
3  * Copyright 2005 Juan Lang
4  *
5  * This library is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
18  */
19
20 #include "config.h"
21 #include <stdarg.h>
22 #include <stdio.h>
23
24 #include "windef.h"
25 #include "winbase.h"
26 #include "wincrypt.h"
27 #include "winreg.h"
28 #include "winuser.h"
29 #include "i_cryptasn1tls.h"
30 #include "crypt32_private.h"
31 #include "wine/debug.h"
32
33 WINE_DEFAULT_DEBUG_CHANNEL(crypt);
34
35 static HCRYPTPROV hDefProv;
36 HINSTANCE hInstance;
37
38 BOOL WINAPI DllMain(HINSTANCE hInst, DWORD fdwReason, PVOID pvReserved)
39 {
40     switch (fdwReason)
41     {
42         case DLL_PROCESS_ATTACH:
43             hInstance = hInst;
44             DisableThreadLibraryCalls(hInst);
45             crypt_oid_init();
46             break;
47         case DLL_PROCESS_DETACH:
48             crypt_oid_free();
49             crypt_sip_free();
50             root_store_free();
51             default_chain_engine_free();
52             /* Don't release the default provider on process shutdown, there's
53              * no guarantee the provider dll hasn't already been unloaded.
54              */
55             if (hDefProv && !pvReserved) CryptReleaseContext(hDefProv, 0);
56             break;
57     }
58     return TRUE;
59 }
60
61 HCRYPTPROV CRYPT_GetDefaultProvider(void)
62 {
63     if (!hDefProv)
64     {
65         HCRYPTPROV prov;
66
67         CryptAcquireContextW(&prov, NULL, MS_ENHANCED_PROV_W, PROV_RSA_FULL,
68          CRYPT_VERIFYCONTEXT);
69         InterlockedCompareExchangePointer((PVOID *)&hDefProv, (PVOID)prov,
70          NULL);
71         if (hDefProv != prov)
72             CryptReleaseContext(prov, 0);
73     }
74     return hDefProv;
75 }
76
77 typedef void * HLRUCACHE;
78
79 /* this function is called by Internet Explorer when it is about to verify a
80  * downloaded component.  The first parameter appears to be a pointer to an
81  * unknown type, native fails unless it points to a buffer of at least 20 bytes.
82  * The second parameter appears to be an out parameter, whatever it's set to is
83  * passed (by cryptnet.dll) to I_CryptFlushLruCache.
84  */
85 BOOL WINAPI I_CryptCreateLruCache(void *unknown, HLRUCACHE *out)
86 {
87     FIXME("(%p, %p): stub!\n", unknown, out);
88     *out = (void *)0xbaadf00d;
89     return TRUE;
90 }
91
92 BOOL WINAPI I_CryptFindLruEntry(DWORD unk0, DWORD unk1)
93 {
94     FIXME("(%08x, %08x): stub!\n", unk0, unk1);
95     return FALSE;
96 }
97
98 BOOL WINAPI I_CryptFindLruEntryData(DWORD unk0, DWORD unk1, DWORD unk2)
99 {
100     FIXME("(%08x, %08x, %08x): stub!\n", unk0, unk1, unk2);
101     return FALSE;
102 }
103
104 BOOL WINAPI I_CryptCreateLruEntry(HLRUCACHE h, DWORD unk0, DWORD unk1)
105 {
106     FIXME("(%p, %08x, %08x): stub!\n", h, unk0, unk1);
107     return FALSE;
108 }
109
110 DWORD WINAPI I_CryptFlushLruCache(HLRUCACHE h, DWORD unk0, DWORD unk1)
111 {
112     FIXME("(%p, %08x, %08x): stub!\n", h, unk0, unk1);
113     return 0;
114 }
115
116 HLRUCACHE WINAPI I_CryptFreeLruCache(HLRUCACHE h, DWORD unk0, DWORD unk1)
117 {
118     FIXME("(%p, %08x, %08x): stub!\n", h, unk0, unk1);
119     return h;
120 }
121
122 LPVOID WINAPI CryptMemAlloc(ULONG cbSize)
123 {
124     return HeapAlloc(GetProcessHeap(), 0, cbSize);
125 }
126
127 LPVOID WINAPI CryptMemRealloc(LPVOID pv, ULONG cbSize)
128 {
129     return HeapReAlloc(GetProcessHeap(), 0, pv, cbSize);
130 }
131
132 VOID WINAPI CryptMemFree(LPVOID pv)
133 {
134     HeapFree(GetProcessHeap(), 0, pv);
135 }
136
137 DWORD WINAPI I_CryptAllocTls(void)
138 {
139     return TlsAlloc();
140 }
141
142 LPVOID WINAPI I_CryptDetachTls(DWORD dwTlsIndex)
143 {
144     LPVOID ret;
145
146     ret = TlsGetValue(dwTlsIndex);
147     TlsSetValue(dwTlsIndex, NULL);
148     return ret;
149 }
150
151 LPVOID WINAPI I_CryptGetTls(DWORD dwTlsIndex)
152 {
153     return TlsGetValue(dwTlsIndex);
154 }
155
156 BOOL WINAPI I_CryptSetTls(DWORD dwTlsIndex, LPVOID lpTlsValue)
157 {
158     return TlsSetValue(dwTlsIndex, lpTlsValue);
159 }
160
161 BOOL WINAPI I_CryptFreeTls(DWORD dwTlsIndex, DWORD unknown)
162 {
163     TRACE("(%d, %d)\n", dwTlsIndex, unknown);
164     return TlsFree(dwTlsIndex);
165 }
166
167 BOOL WINAPI I_CryptGetOssGlobal(DWORD x)
168 {
169     FIXME("%08x\n", x);
170     return FALSE;
171 }
172
173 HCRYPTPROV WINAPI I_CryptGetDefaultCryptProv(DWORD reserved)
174 {
175     HCRYPTPROV ret;
176
177     TRACE("(%08x)\n", reserved);
178
179     if (reserved)
180     {
181         SetLastError(E_INVALIDARG);
182         return 0;
183     }
184     ret = CRYPT_GetDefaultProvider();
185     CryptContextAddRef(ret, NULL, 0);
186     return ret;
187 }
188
189 BOOL WINAPI I_CryptReadTrustedPublisherDWORDValueFromRegistry(LPCWSTR name,
190  DWORD *value)
191 {
192     static const WCHAR safer[] = { 
193      'S','o','f','t','w','a','r','e','\\','P','o','l','i','c','i','e','s','\\',
194      'M','i','c','r','o','s','o','f','t','\\','S','y','s','t','e','m',
195      'C','e','r','t','i','f','i','c','a','t','e','s','\\',
196      'T','r','u','s','t','e','d','P','u','b','l','i','s','h','e','r','\\',
197      'S','a','f','e','r',0 };
198     HKEY key;
199     LONG rc;
200     BOOL ret = FALSE;
201
202     TRACE("(%s, %p)\n", debugstr_w(name), value);
203
204     *value = 0;
205     rc = RegCreateKeyW(HKEY_LOCAL_MACHINE, safer, &key);
206     if (rc == ERROR_SUCCESS)
207     {
208         DWORD size = sizeof(DWORD);
209
210         if (!RegQueryValueExW(key, name, NULL, NULL, (LPBYTE)value, &size))
211             ret = TRUE;
212         RegCloseKey(key);
213     }
214     return ret;
215 }
216
217 DWORD WINAPI I_CryptInstallOssGlobal(DWORD x, DWORD y, DWORD z)
218 {
219     static int ret = 8;
220     ret++;
221     FIXME("%08x %08x %08x, return value %d\n", x, y, z,ret);
222     return ret;
223 }
224
225 BOOL WINAPI I_CryptInstallAsn1Module(ASN1module_t x, DWORD y, void* z)
226 {
227     FIXME("(%p %08x %p): stub\n", x, y, z);
228     return TRUE;
229 }
230
231 BOOL WINAPI I_CryptUninstallAsn1Module(HCRYPTASN1MODULE x)
232 {
233     FIXME("(%08x): stub\n", x);
234     return TRUE;
235 }
236
237 ASN1decoding_t WINAPI I_CryptGetAsn1Decoder(HCRYPTASN1MODULE x)
238 {
239     FIXME("(%08x): stub\n", x);
240     return NULL;
241 }
242
243 ASN1encoding_t WINAPI I_CryptGetAsn1Encoder(HCRYPTASN1MODULE x)
244 {
245     FIXME("(%08x): stub\n", x);
246     return NULL;
247 }