crypt32: Don't release default crypto provider on process shutdown.
[wine/gsoc_dplay.git] / dlls / crypt32 / main.c
blobfa90ee057264dff5f3750202deb92d356437261f
1 /*
2 * Copyright 2002 Mike McCormack for CodeWeavers
3 * Copyright 2005 Juan Lang
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.
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.
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
20 #include "config.h"
21 #include <stdarg.h>
22 #include <stdio.h>
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"
33 WINE_DEFAULT_DEBUG_CHANNEL(crypt);
35 static HCRYPTPROV hDefProv;
37 BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD fdwReason, PVOID pvReserved)
39 switch (fdwReason)
41 case DLL_PROCESS_ATTACH:
42 DisableThreadLibraryCalls(hInstance);
43 crypt_oid_init(hInstance);
44 break;
45 case DLL_PROCESS_DETACH:
46 crypt_oid_free();
47 crypt_sip_free();
48 root_store_free();
49 default_chain_engine_free();
50 /* Don't release the default provider on process shutdown, there's
51 * no guarantee the provider dll hasn't already been unloaded.
53 if (hDefProv && !pvReserved) CryptReleaseContext(hDefProv, 0);
54 break;
56 return TRUE;
59 HCRYPTPROV CRYPT_GetDefaultProvider(void)
61 if (!hDefProv)
62 CryptAcquireContextW(&hDefProv, NULL, MS_ENHANCED_PROV_W,
63 PROV_RSA_FULL, CRYPT_VERIFYCONTEXT);
64 return hDefProv;
67 typedef void * HLRUCACHE;
69 /* this function is called by Internet Explorer when it is about to verify a
70 * downloaded component. The first parameter appears to be a pointer to an
71 * unknown type, native fails unless it points to a buffer of at least 20 bytes.
72 * The second parameter appears to be an out parameter, whatever it's set to is
73 * passed (by cryptnet.dll) to I_CryptFlushLruCache.
75 BOOL WINAPI I_CryptCreateLruCache(void *unknown, HLRUCACHE *out)
77 FIXME("(%p, %p): stub!\n", unknown, out);
78 *out = (void *)0xbaadf00d;
79 return TRUE;
82 BOOL WINAPI I_CryptFindLruEntry(DWORD unk0, DWORD unk1)
84 FIXME("(%08x, %08x): stub!\n", unk0, unk1);
85 return FALSE;
88 BOOL WINAPI I_CryptFindLruEntryData(DWORD unk0, DWORD unk1, DWORD unk2)
90 FIXME("(%08x, %08x, %08x): stub!\n", unk0, unk1, unk2);
91 return FALSE;
94 BOOL WINAPI I_CryptCreateLruEntry(HLRUCACHE h, DWORD unk0, DWORD unk1)
96 FIXME("(%p, %08x, %08x): stub!\n", h, unk0, unk1);
97 return FALSE;
100 DWORD WINAPI I_CryptFlushLruCache(HLRUCACHE h, DWORD unk0, DWORD unk1)
102 FIXME("(%p, %08x, %08x): stub!\n", h, unk0, unk1);
103 return 0;
106 HLRUCACHE WINAPI I_CryptFreeLruCache(HLRUCACHE h, DWORD unk0, DWORD unk1)
108 FIXME("(%p, %08x, %08x): stub!\n", h, unk0, unk1);
109 return h;
112 LPVOID WINAPI CryptMemAlloc(ULONG cbSize)
114 return HeapAlloc(GetProcessHeap(), 0, cbSize);
117 LPVOID WINAPI CryptMemRealloc(LPVOID pv, ULONG cbSize)
119 return HeapReAlloc(GetProcessHeap(), 0, pv, cbSize);
122 VOID WINAPI CryptMemFree(LPVOID pv)
124 HeapFree(GetProcessHeap(), 0, pv);
127 DWORD WINAPI I_CryptAllocTls(void)
129 return TlsAlloc();
132 LPVOID WINAPI I_CryptDetachTls(DWORD dwTlsIndex)
134 LPVOID ret;
136 ret = TlsGetValue(dwTlsIndex);
137 TlsSetValue(dwTlsIndex, NULL);
138 return ret;
141 LPVOID WINAPI I_CryptGetTls(DWORD dwTlsIndex)
143 return TlsGetValue(dwTlsIndex);
146 BOOL WINAPI I_CryptSetTls(DWORD dwTlsIndex, LPVOID lpTlsValue)
148 return TlsSetValue(dwTlsIndex, lpTlsValue);
151 BOOL WINAPI I_CryptFreeTls(DWORD dwTlsIndex, DWORD unknown)
153 TRACE("(%d, %d)\n", dwTlsIndex, unknown);
154 return TlsFree(dwTlsIndex);
157 BOOL WINAPI I_CryptGetOssGlobal(DWORD x)
159 FIXME("%08x\n", x);
160 return FALSE;
163 HCRYPTPROV WINAPI I_CryptGetDefaultCryptProv(DWORD reserved)
165 HCRYPTPROV ret;
167 TRACE("(%08x)\n", reserved);
169 if (reserved)
171 SetLastError(E_INVALIDARG);
172 return (HCRYPTPROV)0;
174 ret = CRYPT_GetDefaultProvider();
175 CryptContextAddRef(ret, NULL, 0);
176 return ret;
179 BOOL WINAPI I_CryptReadTrustedPublisherDWORDValueFromRegistry(LPCWSTR name,
180 DWORD *value)
182 static const WCHAR safer[] = {
183 'S','o','f','t','w','a','r','e','\\','P','o','l','i','c','i','e','s','\\',
184 'M','i','c','r','o','s','o','f','t','\\','S','y','s','t','e','m',
185 'C','e','r','t','i','f','i','c','a','t','e','s','\\',
186 'T','r','u','s','t','e','d','P','u','b','l','i','s','h','e','r','\\',
187 'S','a','f','e','r',0 };
188 HKEY key;
189 LONG rc;
190 BOOL ret = FALSE;
192 TRACE("(%s, %p)\n", debugstr_w(name), value);
194 *value = 0;
195 rc = RegCreateKeyW(HKEY_LOCAL_MACHINE, safer, &key);
196 if (rc == ERROR_SUCCESS)
198 DWORD size = sizeof(DWORD);
200 if (!RegQueryValueExW(key, name, NULL, NULL, (LPBYTE)value, &size))
201 ret = TRUE;
202 RegCloseKey(key);
204 return ret;
207 DWORD WINAPI I_CryptInstallOssGlobal(DWORD x, DWORD y, DWORD z)
209 static int ret = 8;
210 ret++;
211 FIXME("%08x %08x %08x, return value %d\n", x, y, z,ret);
212 return ret;
215 BOOL WINAPI I_CryptInstallAsn1Module(ASN1module_t x, DWORD y, void* z)
217 FIXME("(%p %08x %p): stub\n", x, y, z);
218 return TRUE;
221 BOOL WINAPI I_CryptUninstallAsn1Module(HCRYPTASN1MODULE x)
223 FIXME("(%08x): stub\n", x);
224 return TRUE;
227 ASN1decoding_t WINAPI I_CryptGetAsn1Decoder(HCRYPTASN1MODULE x)
229 FIXME("(%08x): stub\n", x);
230 return NULL;
233 ASN1encoding_t WINAPI I_CryptGetAsn1Encoder(HCRYPTASN1MODULE x)
235 FIXME("(%08x): stub\n", x);
236 return NULL;
239 BOOL WINAPI CryptFormatObject(DWORD dwCertEncodingType, DWORD dwFormatType,
240 DWORD dwFormatStrType, void *pFormatStruct, LPCSTR lpszStructType,
241 const BYTE *pbEncoded, DWORD cbEncoded, void *pbFormat, DWORD *pcbFormat)
243 FIXME("(%08x, %d, %d, %p, %s, %p, %d, %p, %p): stub\n",
244 dwCertEncodingType, dwFormatType, dwFormatStrType, pFormatStruct,
245 debugstr_a(lpszStructType), pbEncoded, cbEncoded, pbFormat, pcbFormat);
246 return FALSE;