wined3d: Use command buffer IDs for synchronisation in wined3d_buffer_gl_sync_apple().
[wine/zf.git] / dlls / crypt32 / main.c
blob4189da5a50526aa3357285f4bdd0c8e44258226a
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 <stdarg.h>
21 #include <stdio.h>
23 #include "windef.h"
24 #include "winbase.h"
25 #include "winternl.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;
37 const struct unix_funcs *unix_funcs = NULL;
39 static CRITICAL_SECTION prov_param_cs;
40 static CRITICAL_SECTION_DEBUG prov_param_cs_debug =
42 0, 0, &prov_param_cs,
43 { &prov_param_cs_debug.ProcessLocksList,
44 &prov_param_cs_debug.ProcessLocksList },
45 0, 0, { (DWORD_PTR)(__FILE__ ": prov_param_cs") }
47 static CRITICAL_SECTION prov_param_cs = { &prov_param_cs_debug, -1, 0, 0, 0, 0 };
49 BOOL WINAPI DllMain(HINSTANCE hInst, DWORD reason, PVOID pvReserved)
51 switch (reason)
53 case DLL_PROCESS_ATTACH:
54 hInstance = hInst;
55 DisableThreadLibraryCalls(hInst);
56 init_empty_store();
57 crypt_oid_init();
58 __wine_init_unix_lib( hInst, reason, NULL, &unix_funcs );
59 break;
60 case DLL_PROCESS_DETACH:
61 if (pvReserved) break;
62 crypt_oid_free();
63 crypt_sip_free();
64 default_chain_engine_free();
65 if (hDefProv) CryptReleaseContext(hDefProv, 0);
66 __wine_init_unix_lib( hInst, reason, NULL, NULL );
67 break;
69 return TRUE;
72 static HCRYPTPROV CRYPT_GetDefaultProvider(void)
74 if (!hDefProv)
76 HCRYPTPROV prov;
78 if (!CryptAcquireContextW(&prov, NULL, MS_ENH_RSA_AES_PROV_W,
79 PROV_RSA_AES, CRYPT_VERIFYCONTEXT))
80 return hDefProv;
81 InterlockedCompareExchangePointer((PVOID *)&hDefProv, (PVOID)prov,
82 NULL);
83 if (hDefProv != prov)
84 CryptReleaseContext(prov, 0);
86 return hDefProv;
89 typedef void * HLRUCACHE;
91 /* this function is called by Internet Explorer when it is about to verify a
92 * downloaded component. The first parameter appears to be a pointer to an
93 * unknown type, native fails unless it points to a buffer of at least 20 bytes.
94 * The second parameter appears to be an out parameter, whatever it's set to is
95 * passed (by cryptnet.dll) to I_CryptFlushLruCache.
97 BOOL WINAPI I_CryptCreateLruCache(void *unknown, HLRUCACHE *out)
99 FIXME("(%p, %p): stub!\n", unknown, out);
100 *out = (void *)0xbaadf00d;
101 return TRUE;
104 BOOL WINAPI I_CryptFindLruEntry(DWORD unk0, DWORD unk1)
106 FIXME("(%08x, %08x): stub!\n", unk0, unk1);
107 return FALSE;
110 BOOL WINAPI I_CryptFindLruEntryData(DWORD unk0, DWORD unk1, DWORD unk2)
112 FIXME("(%08x, %08x, %08x): stub!\n", unk0, unk1, unk2);
113 return FALSE;
116 BOOL WINAPI I_CryptCreateLruEntry(HLRUCACHE h, DWORD unk0, DWORD unk1)
118 FIXME("(%p, %08x, %08x): stub!\n", h, unk0, unk1);
119 return FALSE;
122 DWORD WINAPI I_CryptFlushLruCache(HLRUCACHE h, DWORD unk0, DWORD unk1)
124 FIXME("(%p, %08x, %08x): stub!\n", h, unk0, unk1);
125 return 0;
128 HLRUCACHE WINAPI I_CryptFreeLruCache(HLRUCACHE h, DWORD unk0, DWORD unk1)
130 FIXME("(%p, %08x, %08x): stub!\n", h, unk0, unk1);
131 return h;
134 LPVOID WINAPI CryptMemAlloc(ULONG cbSize)
136 return HeapAlloc(GetProcessHeap(), 0, cbSize);
139 LPVOID WINAPI CryptMemRealloc(LPVOID pv, ULONG cbSize)
141 return HeapReAlloc(GetProcessHeap(), 0, pv, cbSize);
144 VOID WINAPI CryptMemFree(LPVOID pv)
146 HeapFree(GetProcessHeap(), 0, pv);
149 DWORD WINAPI I_CryptAllocTls(void)
151 return TlsAlloc();
154 LPVOID WINAPI I_CryptDetachTls(DWORD dwTlsIndex)
156 LPVOID ret;
158 ret = TlsGetValue(dwTlsIndex);
159 TlsSetValue(dwTlsIndex, NULL);
160 return ret;
163 LPVOID WINAPI I_CryptGetTls(DWORD dwTlsIndex)
165 return TlsGetValue(dwTlsIndex);
168 BOOL WINAPI I_CryptSetTls(DWORD dwTlsIndex, LPVOID lpTlsValue)
170 return TlsSetValue(dwTlsIndex, lpTlsValue);
173 BOOL WINAPI I_CryptFreeTls(DWORD dwTlsIndex, DWORD unknown)
175 BOOL ret;
177 TRACE("(%d, %d)\n", dwTlsIndex, unknown);
179 ret = TlsFree(dwTlsIndex);
180 if (!ret) SetLastError( E_INVALIDARG );
181 return ret;
184 BOOL WINAPI I_CryptGetOssGlobal(DWORD x)
186 FIXME("%08x\n", x);
187 return FALSE;
190 static BOOL is_supported_algid(HCRYPTPROV prov, ALG_ID algid)
192 PROV_ENUMALGS prov_algs;
193 DWORD size = sizeof(prov_algs);
194 BOOL ret = FALSE;
196 /* This enumeration is not thread safe */
197 EnterCriticalSection(&prov_param_cs);
198 if (CryptGetProvParam(prov, PP_ENUMALGS, (BYTE *)&prov_algs, &size, CRYPT_FIRST))
202 if (prov_algs.aiAlgid == algid)
204 ret = TRUE;
205 break;
207 } while (CryptGetProvParam(prov, PP_ENUMALGS, (BYTE *)&prov_algs, &size, CRYPT_NEXT));
209 LeaveCriticalSection(&prov_param_cs);
210 return ret;
213 HCRYPTPROV WINAPI DECLSPEC_HOTPATCH I_CryptGetDefaultCryptProv(ALG_ID algid)
215 HCRYPTPROV prov, defprov;
217 TRACE("(%08x)\n", algid);
219 defprov = CRYPT_GetDefaultProvider();
221 if (algid && !is_supported_algid(defprov, algid))
223 DWORD i = 0, type, size;
225 while (CryptEnumProvidersW(i, NULL, 0, &type, NULL, &size))
227 WCHAR *name = CryptMemAlloc(size);
228 if (name)
230 if (CryptEnumProvidersW(i, NULL, 0, &type, name, &size))
232 if (CryptAcquireContextW(&prov, NULL, name, type, CRYPT_VERIFYCONTEXT))
234 if (is_supported_algid(prov, algid))
236 CryptMemFree(name);
237 return prov;
239 CryptReleaseContext(prov, 0);
242 CryptMemFree(name);
244 i++;
247 SetLastError(E_INVALIDARG);
248 return 0;
251 CryptContextAddRef(defprov, NULL, 0);
252 return defprov;
255 BOOL WINAPI I_CryptReadTrustedPublisherDWORDValueFromRegistry(LPCWSTR name,
256 DWORD *value)
258 HKEY key;
259 LONG rc;
260 BOOL ret = FALSE;
262 TRACE("(%s, %p)\n", debugstr_w(name), value);
264 *value = 0;
265 rc = RegCreateKeyW(HKEY_LOCAL_MACHINE, L"Software\\Policies\\Microsoft\\SystemCertificates\\TrustedPublisher\\Safer", &key);
266 if (rc == ERROR_SUCCESS)
268 DWORD size = sizeof(DWORD);
270 if (!RegQueryValueExW(key, name, NULL, NULL, (LPBYTE)value, &size))
271 ret = TRUE;
272 RegCloseKey(key);
274 return ret;
277 DWORD WINAPI I_CryptInstallOssGlobal(DWORD x, DWORD y, DWORD z)
279 static int ret = 8;
280 ret++;
281 FIXME("%08x %08x %08x, return value %d\n", x, y, z,ret);
282 return ret;
285 BOOL WINAPI I_CryptInstallAsn1Module(ASN1module_t x, DWORD y, void* z)
287 FIXME("(%p %08x %p): stub\n", x, y, z);
288 return TRUE;
291 BOOL WINAPI I_CryptUninstallAsn1Module(HCRYPTASN1MODULE x)
293 FIXME("(%08x): stub\n", x);
294 return TRUE;
297 ASN1decoding_t WINAPI I_CryptGetAsn1Decoder(HCRYPTASN1MODULE x)
299 FIXME("(%08x): stub\n", x);
300 return NULL;
303 ASN1encoding_t WINAPI I_CryptGetAsn1Encoder(HCRYPTASN1MODULE x)
305 FIXME("(%08x): stub\n", x);
306 return NULL;
309 BOOL WINAPI CryptProtectMemory(void *data, DWORD len, DWORD flags)
311 static int fixme_once;
312 if (!fixme_once++) FIXME("(%p %u %08x): stub\n", data, len, flags);
313 return TRUE;
316 BOOL WINAPI CryptUnprotectMemory(void *data, DWORD len, DWORD flags)
318 static int fixme_once;
319 if (!fixme_once++) FIXME("(%p %u %08x): stub\n", data, len, flags);
320 return TRUE;