Porting fixes.
[wine/gsoc_dplay.git] / dlls / crypt32 / main.c
blob2160fa3aa6fe222f6e3eca025a44f31a76c0b9de
1 /*
2 * Copyright 2002 Mike McCormack for CodeWeavers
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.
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.
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
19 #include "config.h"
20 #include <stdarg.h>
21 #include <stdio.h>
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"
31 WINE_DEFAULT_DEBUG_CHANNEL(crypt);
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)
36 FIXME("stub!\n");
37 return FALSE;
40 /* these functions all have an unknown number of args */
41 BOOL WINAPI I_CryptFindLruEntryData(DWORD x)
43 FIXME("stub!\n");
44 return FALSE;
47 BOOL WINAPI I_CryptFlushLruCache(DWORD x)
49 FIXME("stub!\n");
50 return FALSE;
53 BOOL WINAPI I_CryptFreeLruCache(DWORD x)
55 FIXME("stub!\n");
56 return FALSE;
59 BOOL WINAPI CryptProtectData(DATA_BLOB* pDataIn, LPCWSTR szDataDescr, DATA_BLOB* pOptionalEntropy,
60 PVOID pvReserved, CRYPTPROTECT_PROMPTSTRUCT* pPromptStruct,
61 DWORD dwFlags, DATA_BLOB* pDataOut)
63 FIXME("stub!\n");
64 return FALSE;
67 BOOL WINAPI CryptSIPRemoveProvider(GUID *pgProv)
69 FIXME("stub!\n");
70 return FALSE;
73 /* convert a guid to a wide character string */
74 static void CRYPT_guid2wstr( LPGUID guid, LPWSTR wstr )
76 char str[40];
78 sprintf(str, "{%08lX-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X}",
79 guid->Data1, guid->Data2, guid->Data3,
80 guid->Data4[0], guid->Data4[1], guid->Data4[2], guid->Data4[3],
81 guid->Data4[4], guid->Data4[5], guid->Data4[6], guid->Data4[7] );
82 MultiByteToWideChar( CP_ACP, 0, str, -1, wstr, 40 );
86 * Helper for CryptSIPAddProvider
88 * Add a registry key containing a dll name and function under
89 * "Software\\Microsoft\\Cryptography\\OID\\EncodingType 0\\<func>\\<guid>"
91 static LONG CRYPT_SIPWriteFunction( LPGUID guid, LPCWSTR szKey,
92 LPCWSTR szDll, LPCWSTR szFunction )
94 static const WCHAR szOID[] = {
95 'S','o','f','t','w','a','r','e','\\',
96 'M','i','c','r','o','s','o','f','t','\\',
97 'C','r','y','p','t','o','g','r','a','p','h','y','\\',
98 'O','I','D','\\',
99 'E','n','c','o','d','i','n','g','T','y','p','e',' ','0','\\',
100 'C','r','y','p','t','S','I','P','D','l','l', 0 };
101 static const WCHAR szBackSlash[] = { '\\', 0 };
102 static const WCHAR szDllName[] = { 'D','l','l',0 };
103 static const WCHAR szFuncName[] = { 'F','u','n','c','N','a','m','e',0 };
104 WCHAR szFullKey[ 0x100 ];
105 LONG r;
106 HKEY hKey;
108 if( !szFunction )
109 return ERROR_SUCCESS;
111 /* max length of szFullKey depends on our code only, so we won't overrun */
112 lstrcpyW( szFullKey, szOID );
113 lstrcatW( szFullKey, szKey );
114 lstrcatW( szFullKey, szBackSlash );
115 CRYPT_guid2wstr( guid, &szFullKey[ lstrlenW( szFullKey ) ] );
116 lstrcatW( szFullKey, szBackSlash );
118 TRACE("key is %s\n", debugstr_w( szFullKey ) );
120 r = RegCreateKeyW( HKEY_LOCAL_MACHINE, szFullKey, &hKey );
121 if( r != ERROR_SUCCESS )
122 return r;
124 /* write the values */
125 RegSetValueExW( hKey, szFuncName, 0, REG_SZ, (const BYTE*) szFunction,
126 ( lstrlenW( szFunction ) + 1 ) * sizeof (WCHAR) );
127 RegSetValueExW( hKey, szDllName, 0, REG_SZ, (const BYTE*) szDll,
128 ( lstrlenW( szDll ) + 1) * sizeof (WCHAR) );
130 RegCloseKey( hKey );
132 return ERROR_SUCCESS;
135 BOOL WINAPI CryptSIPAddProvider(SIP_ADD_NEWPROVIDER *psNewProv)
137 static const WCHAR szCreate[] = {
138 'C','r','e','a','t','e',
139 'I','n','d','i','r','e','c','t','D','a','t','a',0};
140 static const WCHAR szGetSigned[] = {
141 'G','e','t','S','i','g','n','e','d','D','a','t','a','M','s','g',0};
142 static const WCHAR szIsMyFile[] = {
143 'I','s','M','y','F','i','l','e','T','y','p','e', 0 };
144 static const WCHAR szPutSigned[] = {
145 'P','u','t','S','i','g','n','e','d','D','a','t','a','M','s','g',0};
146 static const WCHAR szRemoveSigned[] = {
147 'R','e','m','o','v','e',
148 'S','i','g','n','e','d','D','a','t','a','M','s','g',0};
149 static const WCHAR szVerify[] = {
150 'V','e','r','i','f','y',
151 'I','n','d','i','r','e','c','t','D','a','t','a',0};
153 TRACE("%p\n", psNewProv);
155 if( !psNewProv )
156 return FALSE;
158 TRACE("%s %s %s %s\n",
159 debugstr_guid( psNewProv->pgSubject ),
160 debugstr_w( psNewProv->pwszDLLFileName ),
161 debugstr_w( psNewProv->pwszMagicNumber ),
162 debugstr_w( psNewProv->pwszIsFunctionName ) );
164 #define CRYPT_SIPADDPROV( key, field ) \
165 CRYPT_SIPWriteFunction( psNewProv->pgSubject, key, \
166 psNewProv->pwszDLLFileName, psNewProv->field)
168 CRYPT_SIPADDPROV( szGetSigned, pwszGetFuncName );
169 CRYPT_SIPADDPROV( szPutSigned, pwszPutFuncName );
170 CRYPT_SIPADDPROV( szCreate, pwszCreateFuncName );
171 CRYPT_SIPADDPROV( szVerify, pwszVerifyFuncName );
172 CRYPT_SIPADDPROV( szRemoveSigned, pwszRemoveFuncName );
173 CRYPT_SIPADDPROV( szIsMyFile, pwszIsFunctionNameFmt2 );
175 #undef CRYPT_SIPADDPROV
177 return TRUE;
180 BOOL WINAPI CryptSIPRetrieveSubjectGuid
181 (LPCWSTR FileName, HANDLE hFileIn, GUID *pgSubject)
183 FIXME("stub!\n");
184 return FALSE;
187 BOOL WINAPI CryptSIPLoad
188 (const GUID *pgSubject, DWORD dwFlags, SIP_DISPATCH_INFO *pSipDispatch)
190 FIXME("stub!\n");
191 return FALSE;
194 BOOL WINAPI CryptGetOIDFunctionValue(DWORD dwEncodingType, LPCSTR pszFuncName,
195 LPCSTR pszOID, LPCWSTR pwszValueName,
196 DWORD *pdwValueType, BYTE *pbValueData,
197 DWORD *pcbValueData)
199 FIXME("(%lx,%s,%s,%s,%p,%p,%p) stub!\n", dwEncodingType, pszFuncName, pszOID,
200 debugstr_w(pwszValueName), pdwValueType, pbValueData, pcbValueData);
201 return FALSE;
204 BOOL WINAPI CryptRegisterDefaultOIDFunction(DWORD dwEncodingType,
205 LPCSTR pszFuncName, DWORD dwIndex,
206 LPCWSTR pwszDll)
208 FIXME("(%lx,%s,%lx,%s) stub!\n", dwEncodingType, pszFuncName, dwIndex,
209 debugstr_w(pwszDll));
210 return FALSE;
213 BOOL WINAPI CryptRegisterOIDFunction(DWORD dwEncodingType, LPCSTR pszFuncName,
214 LPCSTR pszOID, LPCWSTR pwszDll, LPCSTR pszOverrideFuncName)
216 LONG r;
217 static const char szOID[] = "Software\\Microsoft\\Cryptography\\OID";
218 static const char szType1[] = "EncodingType 1";
219 static const WCHAR szDllName[] = { 'D','l','l',0 };
220 HKEY hKey;
221 LPSTR szKey;
222 UINT len;
224 TRACE("%lx %s %s %s %s\n", dwEncodingType, pszFuncName, pszOID,
225 debugstr_w(pwszDll), pszOverrideFuncName);
227 if( dwEncodingType & PKCS_7_ASN_ENCODING )
228 FIXME("PKCS_7_ASN_ENCODING not implemented\n");
230 if( dwEncodingType & X509_ASN_ENCODING )
232 /* construct the name of the key */
233 len = sizeof szOID + sizeof szType1 + 2 +
234 lstrlenA( pszFuncName ) + lstrlenA( pszOID );
235 szKey = HeapAlloc( GetProcessHeap(), 0, len );
236 if( !szKey )
237 return FALSE;
238 sprintf( szKey, "%s\\%s\\%s\\%s",
239 szOID, szType1, pszFuncName, pszOID );
241 TRACE("Key name is %s\n", debugstr_a( szKey ) );
243 r = RegCreateKeyA( HKEY_LOCAL_MACHINE, szKey, &hKey );
244 HeapFree( GetProcessHeap(), 0, szKey );
245 if( r != ERROR_SUCCESS )
246 return FALSE;
248 /* write the values */
249 RegSetValueExA( hKey, "FuncName", 0, REG_SZ, pszOverrideFuncName,
250 lstrlenA( pszOverrideFuncName ) + 1 );
251 RegSetValueExW( hKey, szDllName, 0, REG_SZ, (const BYTE*) pwszDll,
252 (lstrlenW( pwszDll ) + 1) * sizeof (WCHAR) );
254 RegCloseKey( hKey );
257 return TRUE;