crypt32: Add stubs for I_CryptFindLruEntry and I_CryptCreateLruEntry.
[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
37 BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD fdwReason, PVOID pvReserved)
38 {
39     switch (fdwReason)
40     {
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             default_chain_engine_free();
49             if (hDefProv) CryptReleaseContext(hDefProv, 0);
50             break;
51     }
52     return TRUE;
53 }
54
55 HCRYPTPROV CRYPT_GetDefaultProvider(void)
56 {
57     if (!hDefProv)
58         CryptAcquireContextW(&hDefProv, NULL, MS_ENHANCED_PROV_W,
59          PROV_RSA_FULL, CRYPT_VERIFYCONTEXT);
60     return hDefProv;
61 }
62
63 typedef void * HLRUCACHE;
64
65 /* this function is called by Internet Explorer when it is about to verify a
66  * downloaded component.  The first parameter appears to be a pointer to an
67  * unknown type, native fails unless it points to a buffer of at least 20 bytes.
68  * The second parameter appears to be an out parameter, whatever it's set to is
69  * passed (by cryptnet.dll) to I_CryptFlushLruCache.
70  */
71 BOOL WINAPI I_CryptCreateLruCache(void *unknown, HLRUCACHE *out)
72 {
73     FIXME("(%p, %p): stub!\n", unknown, out);
74     *out = (void *)0xbaadf00d;
75     return TRUE;
76 }
77
78 BOOL WINAPI I_CryptFindLruEntry(DWORD unk0, DWORD unk1)
79 {
80     FIXME("(%08x, %08x): stub!\n", unk0, unk1);
81     return FALSE;
82 }
83
84 BOOL WINAPI I_CryptFindLruEntryData(DWORD unk0, DWORD unk1, DWORD unk2)
85 {
86     FIXME("(%08x, %08x, %08x): stub!\n", unk0, unk1, unk2);
87     return FALSE;
88 }
89
90 BOOL WINAPI I_CryptCreateLruEntry(HLRUCACHE h, DWORD unk0, DWORD unk1)
91 {
92     FIXME("(%p, %08x, %08x): stub!\n", h, unk0, unk1);
93     return FALSE;
94 }
95
96 DWORD WINAPI I_CryptFlushLruCache(HLRUCACHE h, DWORD unk0, DWORD unk1)
97 {
98     FIXME("(%p, %08x, %08x): stub!\n", h, unk0, unk1);
99     return 0;
100 }
101
102 HLRUCACHE WINAPI I_CryptFreeLruCache(HLRUCACHE h, DWORD unk0, DWORD unk1)
103 {
104     FIXME("(%p, %08x, %08x): stub!\n", h, unk0, unk1);
105     return h;
106 }
107
108 LPVOID WINAPI CryptMemAlloc(ULONG cbSize)
109 {
110     return HeapAlloc(GetProcessHeap(), 0, cbSize);
111 }
112
113 LPVOID WINAPI CryptMemRealloc(LPVOID pv, ULONG cbSize)
114 {
115     return HeapReAlloc(GetProcessHeap(), 0, pv, cbSize);
116 }
117
118 VOID WINAPI CryptMemFree(LPVOID pv)
119 {
120     HeapFree(GetProcessHeap(), 0, pv);
121 }
122
123 DWORD WINAPI I_CryptAllocTls(void)
124 {
125     return TlsAlloc();
126 }
127
128 LPVOID WINAPI I_CryptDetachTls(DWORD dwTlsIndex)
129 {
130     LPVOID ret;
131
132     ret = TlsGetValue(dwTlsIndex);
133     TlsSetValue(dwTlsIndex, NULL);
134     return ret;
135 }
136
137 LPVOID WINAPI I_CryptGetTls(DWORD dwTlsIndex)
138 {
139     return TlsGetValue(dwTlsIndex);
140 }
141
142 BOOL WINAPI I_CryptSetTls(DWORD dwTlsIndex, LPVOID lpTlsValue)
143 {
144     return TlsSetValue(dwTlsIndex, lpTlsValue);
145 }
146
147 BOOL WINAPI I_CryptFreeTls(DWORD dwTlsIndex, DWORD unknown)
148 {
149     TRACE("(%d, %d)\n", dwTlsIndex, unknown);
150     return TlsFree(dwTlsIndex);
151 }
152
153 BOOL WINAPI I_CryptGetOssGlobal(DWORD x)
154 {
155     FIXME("%08x\n", x);
156     return FALSE;
157 }
158
159 HCRYPTPROV WINAPI I_CryptGetDefaultCryptProv(DWORD reserved)
160 {
161     HCRYPTPROV ret;
162
163     TRACE("(%08x)\n", reserved);
164
165     if (reserved)
166     {
167         SetLastError(E_INVALIDARG);
168         return (HCRYPTPROV)0;
169     }
170     ret = CRYPT_GetDefaultProvider();
171     CryptContextAddRef(ret, NULL, 0);
172     return ret;
173 }
174
175 BOOL WINAPI I_CryptReadTrustedPublisherDWORDValueFromRegistry(LPCWSTR name,
176  DWORD *value)
177 {
178     static const WCHAR safer[] = { 
179      'S','o','f','t','w','a','r','e','\\','P','o','l','i','c','i','e','s','\\',
180      'M','i','c','r','o','s','o','f','t','\\','S','y','s','t','e','m',
181      'C','e','r','t','i','f','i','c','a','t','e','s','\\',
182      'T','r','u','s','t','e','d','P','u','b','l','i','s','h','e','r','\\',
183      'S','a','f','e','r',0 };
184     HKEY key;
185     LONG rc;
186     BOOL ret = FALSE;
187
188     TRACE("(%s, %p)\n", debugstr_w(name), value);
189
190     *value = 0;
191     rc = RegCreateKeyW(HKEY_LOCAL_MACHINE, safer, &key);
192     if (rc == ERROR_SUCCESS)
193     {
194         DWORD size = sizeof(DWORD);
195
196         if (!RegQueryValueExW(key, name, NULL, NULL, (LPBYTE)value, &size))
197             ret = TRUE;
198         RegCloseKey(key);
199     }
200     return ret;
201 }
202
203 DWORD WINAPI I_CryptInstallOssGlobal(DWORD x, DWORD y, DWORD z)
204 {
205     static int ret = 8;
206     ret++;
207     FIXME("%08x %08x %08x, return value %d\n", x, y, z,ret);
208     return ret;
209 }
210
211 BOOL WINAPI I_CryptInstallAsn1Module(ASN1module_t x, DWORD y, void* z)
212 {
213     FIXME("(%p %08x %p): stub\n", x, y, z);
214     return TRUE;
215 }
216
217 BOOL WINAPI I_CryptUninstallAsn1Module(HCRYPTASN1MODULE x)
218 {
219     FIXME("(%08x): stub\n", x);
220     return TRUE;
221 }
222
223 ASN1decoding_t WINAPI I_CryptGetAsn1Decoder(HCRYPTASN1MODULE x)
224 {
225     FIXME("(%08x): stub\n", x);
226     return NULL;
227 }
228
229 ASN1encoding_t WINAPI I_CryptGetAsn1Encoder(HCRYPTASN1MODULE x)
230 {
231     FIXME("(%08x): stub\n", x);
232     return NULL;
233 }
234
235 BOOL WINAPI CryptFormatObject(DWORD dwCertEncodingType, DWORD dwFormatType,
236  DWORD dwFormatStrType, void *pFormatStruct, LPCSTR lpszStructType,
237  const BYTE *pbEncoded, DWORD cbEncoded, void *pbFormat, DWORD *pcbFormat)
238 {
239     FIXME("(%08x, %d, %d, %p, %s, %p, %d, %p, %p): stub\n",
240      dwCertEncodingType, dwFormatType, dwFormatStrType, pFormatStruct,
241      debugstr_a(lpszStructType), pbEncoded, cbEncoded, pbFormat, pcbFormat);
242     return FALSE;
243 }