configure: Changes from running autconf after previous patch.
[wine/hacks.git] / dlls / crypt32 / main.c
blobdb9dc1a946a2eda04009d2702ce8b5b57ccee44f
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;
36 HINSTANCE hInstance;
38 BOOL WINAPI DllMain(HINSTANCE hInst, DWORD fdwReason, PVOID pvReserved)
40 switch (fdwReason)
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.
55 if (hDefProv && !pvReserved) CryptReleaseContext(hDefProv, 0);
56 break;
58 return TRUE;
61 HCRYPTPROV CRYPT_GetDefaultProvider(void)
63 if (!hDefProv)
65 HCRYPTPROV prov;
67 if (!CryptAcquireContextW(&prov, NULL, MS_ENH_RSA_AES_PROV_W,
68 PROV_RSA_AES, CRYPT_VERIFYCONTEXT))
69 return hDefProv;
70 InterlockedCompareExchangePointer((PVOID *)&hDefProv, (PVOID)prov,
71 NULL);
72 if (hDefProv != prov)
73 CryptReleaseContext(prov, 0);
75 return hDefProv;
78 typedef void * HLRUCACHE;
80 /* this function is called by Internet Explorer when it is about to verify a
81 * downloaded component. The first parameter appears to be a pointer to an
82 * unknown type, native fails unless it points to a buffer of at least 20 bytes.
83 * The second parameter appears to be an out parameter, whatever it's set to is
84 * passed (by cryptnet.dll) to I_CryptFlushLruCache.
86 BOOL WINAPI I_CryptCreateLruCache(void *unknown, HLRUCACHE *out)
88 FIXME("(%p, %p): stub!\n", unknown, out);
89 *out = (void *)0xbaadf00d;
90 return TRUE;
93 BOOL WINAPI I_CryptFindLruEntry(DWORD unk0, DWORD unk1)
95 FIXME("(%08x, %08x): stub!\n", unk0, unk1);
96 return FALSE;
99 BOOL WINAPI I_CryptFindLruEntryData(DWORD unk0, DWORD unk1, DWORD unk2)
101 FIXME("(%08x, %08x, %08x): stub!\n", unk0, unk1, unk2);
102 return FALSE;
105 BOOL WINAPI I_CryptCreateLruEntry(HLRUCACHE h, DWORD unk0, DWORD unk1)
107 FIXME("(%p, %08x, %08x): stub!\n", h, unk0, unk1);
108 return FALSE;
111 DWORD WINAPI I_CryptFlushLruCache(HLRUCACHE h, DWORD unk0, DWORD unk1)
113 FIXME("(%p, %08x, %08x): stub!\n", h, unk0, unk1);
114 return 0;
117 HLRUCACHE WINAPI I_CryptFreeLruCache(HLRUCACHE h, DWORD unk0, DWORD unk1)
119 FIXME("(%p, %08x, %08x): stub!\n", h, unk0, unk1);
120 return h;
123 LPVOID WINAPI CryptMemAlloc(ULONG cbSize)
125 return HeapAlloc(GetProcessHeap(), 0, cbSize);
128 LPVOID WINAPI CryptMemRealloc(LPVOID pv, ULONG cbSize)
130 return HeapReAlloc(GetProcessHeap(), 0, pv, cbSize);
133 VOID WINAPI CryptMemFree(LPVOID pv)
135 HeapFree(GetProcessHeap(), 0, pv);
138 DWORD WINAPI I_CryptAllocTls(void)
140 return TlsAlloc();
143 LPVOID WINAPI I_CryptDetachTls(DWORD dwTlsIndex)
145 LPVOID ret;
147 ret = TlsGetValue(dwTlsIndex);
148 TlsSetValue(dwTlsIndex, NULL);
149 return ret;
152 LPVOID WINAPI I_CryptGetTls(DWORD dwTlsIndex)
154 return TlsGetValue(dwTlsIndex);
157 BOOL WINAPI I_CryptSetTls(DWORD dwTlsIndex, LPVOID lpTlsValue)
159 return TlsSetValue(dwTlsIndex, lpTlsValue);
162 BOOL WINAPI I_CryptFreeTls(DWORD dwTlsIndex, DWORD unknown)
164 BOOL ret;
166 TRACE("(%d, %d)\n", dwTlsIndex, unknown);
168 ret = TlsFree(dwTlsIndex);
169 if (!ret) SetLastError( E_INVALIDARG );
170 return ret;
173 BOOL WINAPI I_CryptGetOssGlobal(DWORD x)
175 FIXME("%08x\n", x);
176 return FALSE;
179 HCRYPTPROV WINAPI I_CryptGetDefaultCryptProv(DWORD reserved)
181 HCRYPTPROV ret;
183 TRACE("(%08x)\n", reserved);
185 if (reserved)
187 SetLastError(E_INVALIDARG);
188 return 0;
190 ret = CRYPT_GetDefaultProvider();
191 CryptContextAddRef(ret, NULL, 0);
192 return ret;
195 BOOL WINAPI I_CryptReadTrustedPublisherDWORDValueFromRegistry(LPCWSTR name,
196 DWORD *value)
198 static const WCHAR safer[] = {
199 'S','o','f','t','w','a','r','e','\\','P','o','l','i','c','i','e','s','\\',
200 'M','i','c','r','o','s','o','f','t','\\','S','y','s','t','e','m',
201 'C','e','r','t','i','f','i','c','a','t','e','s','\\',
202 'T','r','u','s','t','e','d','P','u','b','l','i','s','h','e','r','\\',
203 'S','a','f','e','r',0 };
204 HKEY key;
205 LONG rc;
206 BOOL ret = FALSE;
208 TRACE("(%s, %p)\n", debugstr_w(name), value);
210 *value = 0;
211 rc = RegCreateKeyW(HKEY_LOCAL_MACHINE, safer, &key);
212 if (rc == ERROR_SUCCESS)
214 DWORD size = sizeof(DWORD);
216 if (!RegQueryValueExW(key, name, NULL, NULL, (LPBYTE)value, &size))
217 ret = TRUE;
218 RegCloseKey(key);
220 return ret;
223 DWORD WINAPI I_CryptInstallOssGlobal(DWORD x, DWORD y, DWORD z)
225 static int ret = 8;
226 ret++;
227 FIXME("%08x %08x %08x, return value %d\n", x, y, z,ret);
228 return ret;
231 BOOL WINAPI I_CryptInstallAsn1Module(ASN1module_t x, DWORD y, void* z)
233 FIXME("(%p %08x %p): stub\n", x, y, z);
234 return TRUE;
237 BOOL WINAPI I_CryptUninstallAsn1Module(HCRYPTASN1MODULE x)
239 FIXME("(%08x): stub\n", x);
240 return TRUE;
243 ASN1decoding_t WINAPI I_CryptGetAsn1Decoder(HCRYPTASN1MODULE x)
245 FIXME("(%08x): stub\n", x);
246 return NULL;
249 ASN1encoding_t WINAPI I_CryptGetAsn1Encoder(HCRYPTASN1MODULE x)
251 FIXME("(%08x): stub\n", x);
252 return NULL;