ReactOS  0.4.14-dev-114-gc8cbd56
main.c
Go to the documentation of this file.
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 
34 
37 
40 {
41  0, 0, &prov_param_cs,
44  0, 0, { (DWORD_PTR)(__FILE__ ": prov_param_cs") }
45 };
46 static CRITICAL_SECTION prov_param_cs = { &prov_param_cs_debug, -1, 0, 0, 0, 0 };
47 
49 {
50  switch (fdwReason)
51  {
52  case DLL_PROCESS_ATTACH:
53  hInstance = hInst;
57  break;
58  case DLL_PROCESS_DETACH:
59  if (pvReserved) break;
64  break;
65  }
66  return TRUE;
67 }
68 
70 {
71  if (!hDefProv)
72  {
73  HCRYPTPROV prov;
74 
77  return hDefProv;
79  NULL);
80  if (hDefProv != prov)
81  CryptReleaseContext(prov, 0);
82  }
83  return hDefProv;
84 }
85 
86 typedef void * HLRUCACHE;
87 
88 /* this function is called by Internet Explorer when it is about to verify a
89  * downloaded component. The first parameter appears to be a pointer to an
90  * unknown type, native fails unless it points to a buffer of at least 20 bytes.
91  * The second parameter appears to be an out parameter, whatever it's set to is
92  * passed (by cryptnet.dll) to I_CryptFlushLruCache.
93  */
95 {
96  FIXME("(%p, %p): stub!\n", unknown, out);
97  *out = (void *)0xbaadf00d;
98  return TRUE;
99 }
100 
102 {
103  FIXME("(%08x, %08x): stub!\n", unk0, unk1);
104  return FALSE;
105 }
106 
108 {
109  FIXME("(%08x, %08x, %08x): stub!\n", unk0, unk1, unk2);
110  return FALSE;
111 }
112 
114 {
115  FIXME("(%p, %08x, %08x): stub!\n", h, unk0, unk1);
116  return FALSE;
117 }
118 
120 {
121  FIXME("(%p, %08x, %08x): stub!\n", h, unk0, unk1);
122  return 0;
123 }
124 
126 {
127  FIXME("(%p, %08x, %08x): stub!\n", h, unk0, unk1);
128  return h;
129 }
130 
132 {
133  return HeapAlloc(GetProcessHeap(), 0, cbSize);
134 }
135 
137 {
138  return HeapReAlloc(GetProcessHeap(), 0, pv, cbSize);
139 }
140 
142 {
143  HeapFree(GetProcessHeap(), 0, pv);
144 }
145 
147 {
148  return TlsAlloc();
149 }
150 
152 {
153  LPVOID ret;
154 
157  return ret;
158 }
159 
161 {
162  return TlsGetValue(dwTlsIndex);
163 }
164 
166 {
167  return TlsSetValue(dwTlsIndex, lpTlsValue);
168 }
169 
171 {
172  BOOL ret;
173 
174  TRACE("(%d, %d)\n", dwTlsIndex, unknown);
175 
177  if (!ret) SetLastError( E_INVALIDARG );
178  return ret;
179 }
180 
182 {
183  FIXME("%08x\n", x);
184  return FALSE;
185 }
186 
188 {
189  PROV_ENUMALGS prov_algs;
190  DWORD size = sizeof(prov_algs);
191  BOOL ret = FALSE;
192 
193  /* This enumeration is not thread safe */
195  if (CryptGetProvParam(prov, PP_ENUMALGS, (BYTE *)&prov_algs, &size, CRYPT_FIRST))
196  {
197  do
198  {
199  if (prov_algs.aiAlgid == algid)
200  {
201  ret = TRUE;
202  break;
203  }
204  } while (CryptGetProvParam(prov, PP_ENUMALGS, (BYTE *)&prov_algs, &size, CRYPT_NEXT));
205  }
207  return ret;
208 }
209 
211 {
212  HCRYPTPROV prov, defprov;
213 
214  TRACE("(%08x)\n", algid);
215 
216  defprov = CRYPT_GetDefaultProvider();
217 
218  if (algid && !is_supported_algid(defprov, algid))
219  {
220  DWORD i = 0, type, size;
221 
222  while (CryptEnumProvidersW(i, NULL, 0, &type, NULL, &size))
223  {
225  if (name)
226  {
227  if (CryptEnumProvidersW(i, NULL, 0, &type, name, &size))
228  {
230  {
231  if (is_supported_algid(prov, algid))
232  {
234  return prov;
235  }
236  CryptReleaseContext(prov, 0);
237  }
238  }
240  }
241  i++;
242  }
243 
245  return 0;
246  }
247 
248  CryptContextAddRef(defprov, NULL, 0);
249  return defprov;
250 }
251 
253  DWORD *value)
254 {
255  static const WCHAR safer[] = {
256  'S','o','f','t','w','a','r','e','\\','P','o','l','i','c','i','e','s','\\',
257  'M','i','c','r','o','s','o','f','t','\\','S','y','s','t','e','m',
258  'C','e','r','t','i','f','i','c','a','t','e','s','\\',
259  'T','r','u','s','t','e','d','P','u','b','l','i','s','h','e','r','\\',
260  'S','a','f','e','r',0 };
261  HKEY key;
262  LONG rc;
263  BOOL ret = FALSE;
264 
265  TRACE("(%s, %p)\n", debugstr_w(name), value);
266 
267  *value = 0;
268  rc = RegCreateKeyW(HKEY_LOCAL_MACHINE, safer, &key);
269  if (rc == ERROR_SUCCESS)
270  {
271  DWORD size = sizeof(DWORD);
272 
274  ret = TRUE;
275  RegCloseKey(key);
276  }
277  return ret;
278 }
279 
281 {
282  static int ret = 8;
283  ret++;
284  FIXME("%08x %08x %08x, return value %d\n", x, y, z,ret);
285  return ret;
286 }
287 
289 {
290  FIXME("(%p %08x %p): stub\n", x, y, z);
291  return TRUE;
292 }
293 
295 {
296  FIXME("(%08x): stub\n", x);
297  return TRUE;
298 }
299 
301 {
302  FIXME("(%08x): stub\n", x);
303  return NULL;
304 }
305 
307 {
308  FIXME("(%08x): stub\n", x);
309  return NULL;
310 }
311 
313 {
314  static int fixme_once;
315  if (!fixme_once++) FIXME("(%p %u %08x): stub\n", data, len, flags);
316  return TRUE;
317 }
318 
320 {
321  static int fixme_once;
322  if (!fixme_once++) FIXME("(%p %u %08x): stub\n", data, len, flags);
323  return TRUE;
324 }
static HCRYPTPROV hDefProv
Definition: main.c:35
#define TRUE
Definition: types.h:120
BOOL WINAPI CryptProtectMemory(void *data, DWORD len, DWORD flags)
Definition: main.c:312
#define ERROR_SUCCESS
Definition: deptool.c:10
unsigned int ALG_ID
Definition: wincrypt.h:45
#define DWORD_PTR
Definition: treelist.c:76
const WCHAR * LPCWSTR
Definition: xmlstorage.h:185
DWORD WINAPI I_CryptInstallOssGlobal(DWORD x, DWORD y, DWORD z)
Definition: main.c:280
WINE_DEFAULT_DEBUG_CHANNEL(wmic)
BOOL WINAPI TlsSetValue(IN DWORD Index, IN LPVOID Value)
Definition: thread.c:1264
void crypt_sip_free(void) DECLSPEC_HIDDEN
Definition: sip.c:610
#define CRYPT_FIRST
Definition: wincrypt.h:2060
DWORD WINAPI I_CryptAllocTls(void)
Definition: main.c:146
BOOL WINAPI DisableThreadLibraryCalls(IN HMODULE hLibModule)
Definition: loader.c:85
GLuint GLuint GLsizei GLenum type
Definition: gl.h:1545
BOOL WINAPI I_CryptReadTrustedPublisherDWORDValueFromRegistry(LPCWSTR name, DWORD *value)
Definition: main.c:252
GLint GLint GLint GLint GLint x
Definition: gl.h:1548
#define DLL_PROCESS_ATTACH
Definition: compat.h:120
#define CRYPT_NEXT
Definition: wincrypt.h:2061
void WINAPI EnterCriticalSection(LPCRITICAL_SECTION)
#define DWORD
Definition: nt_native.h:44
ASN1decoding_t WINAPI I_CryptGetAsn1Decoder(HCRYPTASN1MODULE x)
Definition: main.c:300
BOOL WINAPI I_CryptSetTls(DWORD dwTlsIndex, LPVOID lpTlsValue)
Definition: main.c:165
GLfloat GLfloat GLfloat GLfloat h
Definition: glext.h:7723
BOOL WINAPI CryptAcquireContextW(HCRYPTPROV *phProv, LPCWSTR pszContainer, LPCWSTR pszProvider, DWORD dwProvType, DWORD dwFlags)
Definition: crypt.c:358
LPVOID WINAPI I_CryptDetachTls(DWORD dwTlsIndex)
Definition: main.c:151
static DWORD unk1
Definition: cursoricon.c:1521
HINSTANCE hInst
Definition: main.c:29
BOOL WINAPI I_CryptCreateLruEntry(HLRUCACHE h, DWORD unk0, DWORD unk1)
Definition: main.c:113
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
LPVOID WINAPI CryptMemAlloc(ULONG cbSize)
Definition: main.c:131
void init_empty_store(void) DECLSPEC_HIDDEN
Definition: store.c:1511
LONG WINAPI RegCloseKey(HKEY hKey)
Definition: reg.c:423
unsigned char * LPBYTE
Definition: typedefs.h:52
BOOL WINAPI CryptUnprotectMemory(void *data, DWORD len, DWORD flags)
Definition: main.c:319
unsigned int BOOL
Definition: ntddk_ex.h:94
long LONG
Definition: pedump.c:60
#define debugstr_w
Definition: kernel32.h:32
BOOL WINAPI CryptContextAddRef(HCRYPTPROV hProv, DWORD *pdwReserved, DWORD dwFlags)
Definition: crypt.c:613
#define FIXME(fmt,...)
Definition: debug.h:110
#define InterlockedCompareExchangePointer
Definition: interlocked.h:129
#define PROV_RSA_AES
Definition: wincrypt.h:2056
#define E_INVALIDARG
Definition: ddrawi.h:101
GLdouble GLdouble z
Definition: glext.h:5874
#define PP_ENUMALGS
Definition: wincrypt.h:2082
smooth NULL
Definition: ftsmooth.c:416
BOOL WINAPI I_CryptFindLruEntryData(DWORD unk0, DWORD unk1, DWORD unk2)
Definition: main.c:107
#define DLL_PROCESS_DETACH
Definition: compat.h:119
BOOL WINAPI CryptEnumProvidersW(DWORD dwIndex, DWORD *pdwReserved, DWORD dwFlags, DWORD *pdwProvType, LPWSTR pszProvName, DWORD *pcbProvName)
Definition: crypt.c:1141
#define DECLSPEC_HOTPATCH
Definition: _mingw.h:240
BOOL WINAPI I_CryptFindLruEntry(DWORD unk0, DWORD unk1)
Definition: main.c:101
#define TRACE(s)
Definition: solgame.cpp:4
GLsizeiptr size
Definition: glext.h:5919
#define GetProcessHeap()
Definition: compat.h:395
PVOID WINAPI HeapAlloc(HANDLE, DWORD, SIZE_T)
LONG WINAPI RegQueryValueExW(_In_ HKEY hkeyorg, _In_ LPCWSTR name, _In_ LPDWORD reserved, _In_ LPDWORD type, _In_ LPBYTE data, _In_ LPDWORD count)
Definition: reg.c:4116
BOOL WINAPI TlsFree(IN DWORD Index)
Definition: thread.c:1154
__wchar_t WCHAR
Definition: xmlstorage.h:180
static LPCSTR DWORD void * pvReserved
Definition: str.c:196
#define WINAPI
Definition: msvc.h:8
static FILE * out
Definition: regtests2xml.c:44
unsigned long DWORD
Definition: ntddk_ex.h:95
#define SetLastError(x)
Definition: compat.h:409
HINSTANCE hInstance
Definition: main.c:36
Definition: id3.c:18
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950
GLbitfield flags
Definition: glext.h:7161
LPVOID WINAPI CryptMemRealloc(LPVOID pv, ULONG cbSize)
Definition: main.c:136
int ret
HKEY key
Definition: reg.c:42
static CRITICAL_SECTION_DEBUG prov_param_cs_debug
Definition: main.c:39
void * HLRUCACHE
Definition: main.c:86
GLenum GLsizei len
Definition: glext.h:6722
unsigned char BYTE
Definition: mem.h:68
LONG WINAPI RegCreateKeyW(HKEY hKey, LPCWSTR lpSubKey, PHKEY phkResult)
Definition: reg.c:1199
DWORD WINAPI TlsAlloc(VOID)
Definition: thread.c:1088
static const WCHAR MS_ENH_RSA_AES_PROV_W[]
Definition: wincrypt.h:2012
LIST_ENTRY ProcessLocksList
Definition: winbase.h:855
DWORD HCRYPTASN1MODULE
LPVOID WINAPI I_CryptGetTls(DWORD dwTlsIndex)
Definition: main.c:160
#define CRYPT_VERIFYCONTEXT
Definition: wincrypt.h:2069
int type
Definition: main.c:85
static DWORD dwTlsIndex
Definition: wintirpc.c:34
ULONG_PTR HCRYPTPROV
Definition: wincrypt.h:46
BOOL WINAPI I_CryptFreeTls(DWORD dwTlsIndex, DWORD unknown)
Definition: main.c:170
#define HeapReAlloc
Definition: compat.h:393
ASN1encoding_t WINAPI I_CryptGetAsn1Encoder(HCRYPTASN1MODULE x)
Definition: main.c:306
BOOL WINAPI CryptGetProvParam(HCRYPTPROV hProv, DWORD dwParam, BYTE *pbData, DWORD *pdwDataLen, DWORD dwFlags)
Definition: crypt.c:1693
static HCRYPTPROV CRYPT_GetDefaultProvider(void)
Definition: main.c:69
GLint GLint GLint GLint GLint GLint y
Definition: gl.h:1548
VOID WINAPI CryptMemFree(LPVOID pv)
Definition: main.c:141
LPVOID WINAPI TlsGetValue(IN DWORD Index)
Definition: thread.c:1228
BOOL WINAPI CryptReleaseContext(HCRYPTPROV hProv, ULONG_PTR dwFlags)
Definition: crypt.c:651
Definition: name.c:36
HCRYPTPROV WINAPI DECLSPEC_HOTPATCH I_CryptGetDefaultCryptProv(ALG_ID algid)
Definition: main.c:210
unsigned int ULONG
Definition: retypes.h:1
static BOOL is_supported_algid(HCRYPTPROV prov, ALG_ID algid)
Definition: main.c:187
BOOL WINAPI I_CryptInstallAsn1Module(ASN1module_t x, DWORD y, void *z)
Definition: main.c:288
void WINAPI LeaveCriticalSection(LPCRITICAL_SECTION)
void default_chain_engine_free(void)
Definition: chain.c:255
static CRITICAL_SECTION prov_param_cs
Definition: main.c:38
HLRUCACHE WINAPI I_CryptFreeLruCache(HLRUCACHE h, DWORD unk0, DWORD unk1)
Definition: main.c:125
BOOL WINAPI I_CryptGetOssGlobal(DWORD x)
Definition: main.c:181
#define HeapFree(x, y, z)
Definition: compat.h:394
void crypt_oid_init(void) DECLSPEC_HIDDEN
Definition: oid.c:1914
BOOL WINAPI I_CryptUninstallAsn1Module(HCRYPTASN1MODULE x)
Definition: main.c:294
DWORD WINAPI I_CryptFlushLruCache(HLRUCACHE h, DWORD unk0, DWORD unk1)
Definition: main.c:119
BOOL WINAPI I_CryptCreateLruCache(void *unknown, HLRUCACHE *out)
Definition: main.c:94
Definition: path.c:42
void crypt_oid_free(void) DECLSPEC_HIDDEN
Definition: oid.c:1920
BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID lpReserved)
Definition: main.c:26
#define HKEY_LOCAL_MACHINE
Definition: winreg.h:12