Use shell icon cache instead of an own IExtractIcon implementation.
[wine] / dlls / crypt32 / main.c
1 /*
2  * Copyright 2002 Mike McCormack for CodeWeavers
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17  */
18
19 #include "config.h"
20 #include <stdarg.h>
21 #include <stdio.h>
22
23 #include "windef.h"
24 #include "winbase.h"
25 #include "wincrypt.h"
26 #include "winreg.h"
27 #include "winnls.h"
28 #include "mssip.h"
29 #include "wine/debug.h"
30
31 WINE_DEFAULT_DEBUG_CHANNEL(crypt);
32
33 /* this function is called by Internet Explorer when it is about to verify a downloaded component */
34 BOOL WINAPI I_CryptCreateLruCache(DWORD x, DWORD y)
35 {
36     FIXME("stub!\n");
37     return FALSE;
38 }
39
40 /* these functions all have an unknown number of args */
41 BOOL WINAPI I_CryptFindLruEntryData(DWORD x)
42 {
43     FIXME("stub!\n");
44     return FALSE;
45 }
46
47 BOOL WINAPI I_CryptFlushLruCache(DWORD x)
48 {
49     FIXME("stub!\n");
50     return FALSE;
51 }
52
53 BOOL WINAPI I_CryptFreeLruCache(DWORD x)
54 {
55     FIXME("stub!\n");
56     return FALSE;
57 }
58
59 BOOL WINAPI CryptSIPRemoveProvider(GUID *pgProv)
60 {
61     FIXME("stub!\n");
62     return FALSE;
63 }
64
65 /* convert a guid to a wide character string */
66 static void CRYPT_guid2wstr( LPGUID guid, LPWSTR wstr )
67 {
68     char str[40];
69
70     sprintf(str, "{%08lX-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X}",
71            guid->Data1, guid->Data2, guid->Data3,
72            guid->Data4[0], guid->Data4[1], guid->Data4[2], guid->Data4[3],
73            guid->Data4[4], guid->Data4[5], guid->Data4[6], guid->Data4[7] );
74     MultiByteToWideChar( CP_ACP, 0, str, -1, wstr, 40 );
75 }
76
77 /*
78  * Helper for CryptSIPAddProvider
79  *
80  * Add a registry key containing a dll name and function under
81  *  "Software\\Microsoft\\Cryptography\\OID\\EncodingType 0\\<func>\\<guid>"
82  */
83 static LONG CRYPT_SIPWriteFunction( LPGUID guid, LPCWSTR szKey, 
84               LPCWSTR szDll, LPCWSTR szFunction )
85 {
86     static const WCHAR szOID[] = {
87         'S','o','f','t','w','a','r','e','\\',
88         'M','i','c','r','o','s','o','f','t','\\',
89         'C','r','y','p','t','o','g','r','a','p','h','y','\\',
90         'O','I','D','\\',
91         'E','n','c','o','d','i','n','g','T','y','p','e',' ','0','\\',
92         'C','r','y','p','t','S','I','P','D','l','l', 0 };
93     static const WCHAR szBackSlash[] = { '\\', 0 };
94     static const WCHAR szDllName[] = { 'D','l','l',0 };
95     static const WCHAR szFuncName[] = { 'F','u','n','c','N','a','m','e',0 };
96     WCHAR szFullKey[ 0x100 ];
97     LONG r;
98     HKEY hKey;
99
100     if( !szFunction )
101          return ERROR_SUCCESS;
102
103     /* max length of szFullKey depends on our code only, so we won't overrun */
104     lstrcpyW( szFullKey, szOID );
105     lstrcatW( szFullKey, szKey );
106     lstrcatW( szFullKey, szBackSlash );
107     CRYPT_guid2wstr( guid, &szFullKey[ lstrlenW( szFullKey ) ] );
108     lstrcatW( szFullKey, szBackSlash );
109
110     TRACE("key is %s\n", debugstr_w( szFullKey ) );
111
112     r = RegCreateKeyW( HKEY_LOCAL_MACHINE, szFullKey, &hKey );
113     if( r != ERROR_SUCCESS )
114         return r;
115
116     /* write the values */
117     RegSetValueExW( hKey, szFuncName, 0, REG_SZ, (const BYTE*) szFunction,
118                     ( lstrlenW( szFunction ) + 1 ) * sizeof (WCHAR) );
119     RegSetValueExW( hKey, szDllName, 0, REG_SZ, (const BYTE*) szDll,
120                     ( lstrlenW( szDll ) + 1) * sizeof (WCHAR) );
121
122     RegCloseKey( hKey );
123
124     return ERROR_SUCCESS;
125 }
126
127 BOOL WINAPI CryptSIPAddProvider(SIP_ADD_NEWPROVIDER *psNewProv)
128 {
129     static const WCHAR szCreate[] = {
130        'C','r','e','a','t','e',
131        'I','n','d','i','r','e','c','t','D','a','t','a',0};
132     static const WCHAR szGetSigned[] = {
133        'G','e','t','S','i','g','n','e','d','D','a','t','a','M','s','g',0};
134     static const WCHAR szIsMyFile[] = {
135        'I','s','M','y','F','i','l','e','T','y','p','e', 0 };
136     static const WCHAR szPutSigned[] = {
137        'P','u','t','S','i','g','n','e','d','D','a','t','a','M','s','g',0};
138     static const WCHAR szRemoveSigned[] = {
139        'R','e','m','o','v','e',
140        'S','i','g','n','e','d','D','a','t','a','M','s','g',0};
141     static const WCHAR szVerify[] = {
142        'V','e','r','i','f','y',
143        'I','n','d','i','r','e','c','t','D','a','t','a',0};
144
145     TRACE("%p\n", psNewProv);
146
147     if( !psNewProv )
148         return FALSE;
149
150     TRACE("%s %s %s %s\n",
151           debugstr_guid( psNewProv->pgSubject ),
152           debugstr_w( psNewProv->pwszDLLFileName ),
153           debugstr_w( psNewProv->pwszMagicNumber ),
154           debugstr_w( psNewProv->pwszIsFunctionName ) );
155
156 #define CRYPT_SIPADDPROV( key, field ) \
157     CRYPT_SIPWriteFunction( psNewProv->pgSubject, key, \
158            psNewProv->pwszDLLFileName, psNewProv->field)
159
160     CRYPT_SIPADDPROV( szGetSigned, pwszGetFuncName );
161     CRYPT_SIPADDPROV( szPutSigned, pwszPutFuncName );
162     CRYPT_SIPADDPROV( szCreate, pwszCreateFuncName );
163     CRYPT_SIPADDPROV( szVerify, pwszVerifyFuncName );
164     CRYPT_SIPADDPROV( szRemoveSigned, pwszRemoveFuncName );
165     CRYPT_SIPADDPROV( szIsMyFile, pwszIsFunctionNameFmt2 );
166
167 #undef CRYPT_SIPADDPROV
168
169     return TRUE;
170 }
171
172 BOOL WINAPI CryptSIPRetrieveSubjectGuid
173       (LPCWSTR FileName, HANDLE hFileIn, GUID *pgSubject)
174 {
175     FIXME("stub!\n");
176     return FALSE;
177 }
178
179 BOOL WINAPI CryptSIPLoad
180        (const GUID *pgSubject, DWORD dwFlags, SIP_DISPATCH_INFO *pSipDispatch)
181 {
182     FIXME("stub!\n");
183     return FALSE;
184 }
185
186 BOOL WINAPI CryptRegisterDefaultOIDFunction(DWORD dwEncodingType,
187                                      LPCSTR pszFuncName, DWORD dwIndex,
188                                      LPCWSTR pwszDll)
189 {
190     FIXME("(%lx,%s,%lx,%s) stub!\n", dwEncodingType, pszFuncName, dwIndex,
191           debugstr_w(pwszDll));
192     return FALSE;
193 }