push 585d938e6dafa7e4b71343fb5b928a9214e5518c
[wine/hacks.git] / dlls / crypt32 / main.c
blob922dd1955a7a3a9d8394406812d07d77d3e659be
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)
63 HCRYPTPROV prov;
65 CryptAcquireContextW(&prov, NULL, MS_ENHANCED_PROV_W, PROV_RSA_FULL,
66 CRYPT_VERIFYCONTEXT);
67 InterlockedCompareExchangePointer((PVOID *)&hDefProv, (PVOID)prov,
68 NULL);
69 if (hDefProv != prov)
70 CryptReleaseContext(prov, 0);
72 return hDefProv;
75 typedef void * HLRUCACHE;
77 /* this function is called by Internet Explorer when it is about to verify a
78 * downloaded component. The first parameter appears to be a pointer to an
79 * unknown type, native fails unless it points to a buffer of at least 20 bytes.
80 * The second parameter appears to be an out parameter, whatever it's set to is
81 * passed (by cryptnet.dll) to I_CryptFlushLruCache.
83 BOOL WINAPI I_CryptCreateLruCache(void *unknown, HLRUCACHE *out)
85 FIXME("(%p, %p): stub!\n", unknown, out);
86 *out = (void *)0xbaadf00d;
87 return TRUE;
90 BOOL WINAPI I_CryptFindLruEntry(DWORD unk0, DWORD unk1)
92 FIXME("(%08x, %08x): stub!\n", unk0, unk1);
93 return FALSE;
96 BOOL WINAPI I_CryptFindLruEntryData(DWORD unk0, DWORD unk1, DWORD unk2)
98 FIXME("(%08x, %08x, %08x): stub!\n", unk0, unk1, unk2);
99 return FALSE;
102 BOOL WINAPI I_CryptCreateLruEntry(HLRUCACHE h, DWORD unk0, DWORD unk1)
104 FIXME("(%p, %08x, %08x): stub!\n", h, unk0, unk1);
105 return FALSE;
108 DWORD WINAPI I_CryptFlushLruCache(HLRUCACHE h, DWORD unk0, DWORD unk1)
110 FIXME("(%p, %08x, %08x): stub!\n", h, unk0, unk1);
111 return 0;
114 HLRUCACHE WINAPI I_CryptFreeLruCache(HLRUCACHE h, DWORD unk0, DWORD unk1)
116 FIXME("(%p, %08x, %08x): stub!\n", h, unk0, unk1);
117 return h;
120 LPVOID WINAPI CryptMemAlloc(ULONG cbSize)
122 return HeapAlloc(GetProcessHeap(), 0, cbSize);
125 LPVOID WINAPI CryptMemRealloc(LPVOID pv, ULONG cbSize)
127 return HeapReAlloc(GetProcessHeap(), 0, pv, cbSize);
130 VOID WINAPI CryptMemFree(LPVOID pv)
132 HeapFree(GetProcessHeap(), 0, pv);
135 DWORD WINAPI I_CryptAllocTls(void)
137 return TlsAlloc();
140 LPVOID WINAPI I_CryptDetachTls(DWORD dwTlsIndex)
142 LPVOID ret;
144 ret = TlsGetValue(dwTlsIndex);
145 TlsSetValue(dwTlsIndex, NULL);
146 return ret;
149 LPVOID WINAPI I_CryptGetTls(DWORD dwTlsIndex)
151 return TlsGetValue(dwTlsIndex);
154 BOOL WINAPI I_CryptSetTls(DWORD dwTlsIndex, LPVOID lpTlsValue)
156 return TlsSetValue(dwTlsIndex, lpTlsValue);
159 BOOL WINAPI I_CryptFreeTls(DWORD dwTlsIndex, DWORD unknown)
161 TRACE("(%d, %d)\n", dwTlsIndex, unknown);
162 return TlsFree(dwTlsIndex);
165 BOOL WINAPI I_CryptGetOssGlobal(DWORD x)
167 FIXME("%08x\n", x);
168 return FALSE;
171 HCRYPTPROV WINAPI I_CryptGetDefaultCryptProv(DWORD reserved)
173 HCRYPTPROV ret;
175 TRACE("(%08x)\n", reserved);
177 if (reserved)
179 SetLastError(E_INVALIDARG);
180 return (HCRYPTPROV)0;
182 ret = CRYPT_GetDefaultProvider();
183 CryptContextAddRef(ret, NULL, 0);
184 return ret;
187 BOOL WINAPI I_CryptReadTrustedPublisherDWORDValueFromRegistry(LPCWSTR name,
188 DWORD *value)
190 static const WCHAR safer[] = {
191 'S','o','f','t','w','a','r','e','\\','P','o','l','i','c','i','e','s','\\',
192 'M','i','c','r','o','s','o','f','t','\\','S','y','s','t','e','m',
193 'C','e','r','t','i','f','i','c','a','t','e','s','\\',
194 'T','r','u','s','t','e','d','P','u','b','l','i','s','h','e','r','\\',
195 'S','a','f','e','r',0 };
196 HKEY key;
197 LONG rc;
198 BOOL ret = FALSE;
200 TRACE("(%s, %p)\n", debugstr_w(name), value);
202 *value = 0;
203 rc = RegCreateKeyW(HKEY_LOCAL_MACHINE, safer, &key);
204 if (rc == ERROR_SUCCESS)
206 DWORD size = sizeof(DWORD);
208 if (!RegQueryValueExW(key, name, NULL, NULL, (LPBYTE)value, &size))
209 ret = TRUE;
210 RegCloseKey(key);
212 return ret;
215 DWORD WINAPI I_CryptInstallOssGlobal(DWORD x, DWORD y, DWORD z)
217 static int ret = 8;
218 ret++;
219 FIXME("%08x %08x %08x, return value %d\n", x, y, z,ret);
220 return ret;
223 BOOL WINAPI I_CryptInstallAsn1Module(ASN1module_t x, DWORD y, void* z)
225 FIXME("(%p %08x %p): stub\n", x, y, z);
226 return TRUE;
229 BOOL WINAPI I_CryptUninstallAsn1Module(HCRYPTASN1MODULE x)
231 FIXME("(%08x): stub\n", x);
232 return TRUE;
235 ASN1decoding_t WINAPI I_CryptGetAsn1Decoder(HCRYPTASN1MODULE x)
237 FIXME("(%08x): stub\n", x);
238 return NULL;
241 ASN1encoding_t WINAPI I_CryptGetAsn1Encoder(HCRYPTASN1MODULE x)
243 FIXME("(%08x): stub\n", x);
244 return NULL;
247 BOOL WINAPI CryptFormatObject(DWORD dwCertEncodingType, DWORD dwFormatType,
248 DWORD dwFormatStrType, void *pFormatStruct, LPCSTR lpszStructType,
249 const BYTE *pbEncoded, DWORD cbEncoded, void *pbFormat, DWORD *pcbFormat)
251 FIXME("(%08x, %d, %d, %p, %s, %p, %d, %p, %p): stub\n",
252 dwCertEncodingType, dwFormatType, dwFormatStrType, pFormatStruct,
253 debugstr_a(lpszStructType), pbEncoded, cbEncoded, pbFormat, pcbFormat);
254 return FALSE;