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