wine.inf: We should not override existing associations.
[wine/hacks.git] / dlls / crypt32 / main.c
blobf3e8a38d490f5617d9c801bfc98b031fd5846ffa
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 "winnls.h"
29 #include "mssip.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 if (hDefProv) CryptReleaseContext(hDefProv, 0);
48 break;
50 return TRUE;
53 HCRYPTPROV CRYPT_GetDefaultProvider(void)
55 if (!hDefProv)
56 CryptAcquireContextW(&hDefProv, NULL, MS_ENHANCED_PROV_W,
57 PROV_RSA_FULL, CRYPT_VERIFYCONTEXT);
58 return hDefProv;
61 typedef void * HLRUCACHE;
63 /* this function is called by Internet Explorer when it is about to verify a
64 * downloaded component. The first parameter appears to be a pointer to an
65 * unknown type, native fails unless it points to a buffer of at least 20 bytes.
66 * The second parameter appears to be an out parameter, whatever it's set to is
67 * passed (by cryptnet.dll) to I_CryptFlushLruCache.
69 BOOL WINAPI I_CryptCreateLruCache(void *unknown, HLRUCACHE *out)
71 FIXME("(%p, %p): stub!\n", unknown, out);
72 *out = (void *)0xbaadf00d;
73 return TRUE;
76 BOOL WINAPI I_CryptFindLruEntryData(DWORD unk0, DWORD unk1, DWORD unk2)
78 FIXME("(%08lx, %08lx, %08lx): stub!\n", unk0, unk1, unk2);
79 return FALSE;
82 DWORD WINAPI I_CryptFlushLruCache(HLRUCACHE h, DWORD unk0, DWORD unk1)
84 FIXME("(%p, %08lx, %08lx): stub!\n", h, unk0, unk1);
85 return 0;
88 HLRUCACHE WINAPI I_CryptFreeLruCache(HLRUCACHE h, DWORD unk0, DWORD unk1)
90 FIXME("(%p, %08lx, %08lx): stub!\n", h, unk0, unk1);
91 return h;
94 BOOL WINAPI CryptSIPRemoveProvider(GUID *pgProv)
96 FIXME("stub!\n");
97 return FALSE;
100 /* convert a guid to a wide character string */
101 static void CRYPT_guid2wstr( LPGUID guid, LPWSTR wstr )
103 char str[40];
105 sprintf(str, "{%08lX-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X}",
106 guid->Data1, guid->Data2, guid->Data3,
107 guid->Data4[0], guid->Data4[1], guid->Data4[2], guid->Data4[3],
108 guid->Data4[4], guid->Data4[5], guid->Data4[6], guid->Data4[7] );
109 MultiByteToWideChar( CP_ACP, 0, str, -1, wstr, 40 );
113 * Helper for CryptSIPAddProvider
115 * Add a registry key containing a dll name and function under
116 * "Software\\Microsoft\\Cryptography\\OID\\EncodingType 0\\<func>\\<guid>"
118 static LONG CRYPT_SIPWriteFunction( LPGUID guid, LPCWSTR szKey,
119 LPCWSTR szDll, LPCWSTR szFunction )
121 static const WCHAR szOID[] = {
122 'S','o','f','t','w','a','r','e','\\',
123 'M','i','c','r','o','s','o','f','t','\\',
124 'C','r','y','p','t','o','g','r','a','p','h','y','\\',
125 'O','I','D','\\',
126 'E','n','c','o','d','i','n','g','T','y','p','e',' ','0','\\',
127 'C','r','y','p','t','S','I','P','D','l','l', 0 };
128 static const WCHAR szBackSlash[] = { '\\', 0 };
129 static const WCHAR szDllName[] = { 'D','l','l',0 };
130 static const WCHAR szFuncName[] = { 'F','u','n','c','N','a','m','e',0 };
131 WCHAR szFullKey[ 0x100 ];
132 LONG r;
133 HKEY hKey;
135 if( !szFunction )
136 return ERROR_SUCCESS;
138 /* max length of szFullKey depends on our code only, so we won't overrun */
139 lstrcpyW( szFullKey, szOID );
140 lstrcatW( szFullKey, szKey );
141 lstrcatW( szFullKey, szBackSlash );
142 CRYPT_guid2wstr( guid, &szFullKey[ lstrlenW( szFullKey ) ] );
143 lstrcatW( szFullKey, szBackSlash );
145 TRACE("key is %s\n", debugstr_w( szFullKey ) );
147 r = RegCreateKeyW( HKEY_LOCAL_MACHINE, szFullKey, &hKey );
148 if( r != ERROR_SUCCESS )
149 return r;
151 /* write the values */
152 RegSetValueExW( hKey, szFuncName, 0, REG_SZ, (const BYTE*) szFunction,
153 ( lstrlenW( szFunction ) + 1 ) * sizeof (WCHAR) );
154 RegSetValueExW( hKey, szDllName, 0, REG_SZ, (const BYTE*) szDll,
155 ( lstrlenW( szDll ) + 1) * sizeof (WCHAR) );
157 RegCloseKey( hKey );
159 return ERROR_SUCCESS;
162 BOOL WINAPI CryptSIPAddProvider(SIP_ADD_NEWPROVIDER *psNewProv)
164 static const WCHAR szCreate[] = {
165 'C','r','e','a','t','e',
166 'I','n','d','i','r','e','c','t','D','a','t','a',0};
167 static const WCHAR szGetSigned[] = {
168 'G','e','t','S','i','g','n','e','d','D','a','t','a','M','s','g',0};
169 static const WCHAR szIsMyFile[] = {
170 'I','s','M','y','F','i','l','e','T','y','p','e', 0 };
171 static const WCHAR szPutSigned[] = {
172 'P','u','t','S','i','g','n','e','d','D','a','t','a','M','s','g',0};
173 static const WCHAR szRemoveSigned[] = {
174 'R','e','m','o','v','e',
175 'S','i','g','n','e','d','D','a','t','a','M','s','g',0};
176 static const WCHAR szVerify[] = {
177 'V','e','r','i','f','y',
178 'I','n','d','i','r','e','c','t','D','a','t','a',0};
180 TRACE("%p\n", psNewProv);
182 if( !psNewProv )
183 return FALSE;
185 TRACE("%s %s %s %s\n",
186 debugstr_guid( psNewProv->pgSubject ),
187 debugstr_w( psNewProv->pwszDLLFileName ),
188 debugstr_w( psNewProv->pwszMagicNumber ),
189 debugstr_w( psNewProv->pwszIsFunctionName ) );
191 #define CRYPT_SIPADDPROV( key, field ) \
192 CRYPT_SIPWriteFunction( psNewProv->pgSubject, key, \
193 psNewProv->pwszDLLFileName, psNewProv->field)
195 CRYPT_SIPADDPROV( szGetSigned, pwszGetFuncName );
196 CRYPT_SIPADDPROV( szPutSigned, pwszPutFuncName );
197 CRYPT_SIPADDPROV( szCreate, pwszCreateFuncName );
198 CRYPT_SIPADDPROV( szVerify, pwszVerifyFuncName );
199 CRYPT_SIPADDPROV( szRemoveSigned, pwszRemoveFuncName );
200 CRYPT_SIPADDPROV( szIsMyFile, pwszIsFunctionNameFmt2 );
202 #undef CRYPT_SIPADDPROV
204 return TRUE;
207 BOOL WINAPI CryptSIPRetrieveSubjectGuid
208 (LPCWSTR FileName, HANDLE hFileIn, GUID *pgSubject)
210 FIXME("stub!\n");
211 return FALSE;
214 BOOL WINAPI CryptSIPLoad
215 (const GUID *pgSubject, DWORD dwFlags, SIP_DISPATCH_INFO *pSipDispatch)
217 FIXME("stub!\n");
218 return FALSE;
221 LPVOID WINAPI CryptMemAlloc(ULONG cbSize)
223 return HeapAlloc(GetProcessHeap(), 0, cbSize);
226 LPVOID WINAPI CryptMemRealloc(LPVOID pv, ULONG cbSize)
228 return HeapReAlloc(GetProcessHeap(), 0, pv, cbSize);
231 VOID WINAPI CryptMemFree(LPVOID pv)
233 HeapFree(GetProcessHeap(), 0, pv);
236 DWORD WINAPI I_CryptAllocTls(void)
238 return TlsAlloc();
241 LPVOID WINAPI I_CryptDetachTls(DWORD dwTlsIndex)
243 LPVOID ret;
245 ret = TlsGetValue(dwTlsIndex);
246 TlsSetValue(dwTlsIndex, NULL);
247 return ret;
250 LPVOID WINAPI I_CryptGetTls(DWORD dwTlsIndex)
252 return TlsGetValue(dwTlsIndex);
255 BOOL WINAPI I_CryptSetTls(DWORD dwTlsIndex, LPVOID lpTlsValue)
257 return TlsSetValue(dwTlsIndex, lpTlsValue);
260 BOOL WINAPI I_CryptFreeTls(DWORD dwTlsIndex, DWORD unknown)
262 TRACE("(%ld, %ld)\n", dwTlsIndex, unknown);
263 return TlsFree(dwTlsIndex);
266 BOOL WINAPI I_CryptGetOssGlobal(DWORD x)
268 FIXME("%08lx\n", x);
269 return FALSE;
272 BOOL WINAPI I_CryptInstallOssGlobal(DWORD x, DWORD y, DWORD z)
274 FIXME("%08lx %08lx %08lx\n", x, y, z);
275 return FALSE;
278 BOOL WINAPI I_CryptInstallAsn1Module(void *x, DWORD y, DWORD z)
280 FIXME("%p %08lx %08lx\n", x, y, z);
281 return TRUE;
284 BOOL WINAPI CryptQueryObject(DWORD dwObjectType, const void* pvObject,
285 DWORD dwExpectedContentTypeFlags, DWORD dwExpectedFormatTypeFlags,
286 DWORD dwFlags, DWORD* pdwMsgAndCertEncodingType, DWORD* pdwContentType,
287 DWORD* pdwFormatType, HCERTSTORE* phCertStore, HCRYPTMSG* phMsg,
288 const void** ppvContext)
290 FIXME( "%08lx %p %08lx %08lx %08lx %p %p %p %p %p %p", dwObjectType,
291 pvObject, dwExpectedContentTypeFlags, dwExpectedFormatTypeFlags,
292 dwFlags, pdwMsgAndCertEncodingType, pdwContentType, pdwFormatType,
293 phCertStore, phMsg, ppvContext);
294 return FALSE;
297 BOOL WINAPI CryptVerifyMessageSignature(PCRYPT_VERIFY_MESSAGE_PARA pVerifyPara,
298 DWORD dwSignerIndex, const BYTE* pbSignedBlob, DWORD cbSignedBlob,
299 BYTE* pbDecoded, DWORD* pcbDecoded, PCCERT_CONTEXT* ppSignerCert)
301 FIXME("stub: %p, %ld, %p, %ld, %p, %p, %p\n",
302 pVerifyPara, dwSignerIndex, pbSignedBlob, cbSignedBlob,
303 pbDecoded, pcbDecoded, ppSignerCert);
304 return FALSE;