ReactOS  0.4.11-dev-195-gef016bf
sip.c
Go to the documentation of this file.
1 /*
2  * Copyright 2002 Mike McCormack for CodeWeavers
3  * Copyright 2005-2008 Juan Lang
4  * Copyright 2006 Paul Vriens
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19  */
20 
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 "winnls.h"
29 #include "mssip.h"
30 #include "winuser.h"
31 
32 #include "wine/debug.h"
33 #include "wine/list.h"
34 
36 
37 static const WCHAR szOID[] = {
38  'S','o','f','t','w','a','r','e','\\',
39  'M','i','c','r','o','s','o','f','t','\\',
40  'C','r','y','p','t','o','g','r','a','p','h','y','\\',
41  'O','I','D','\\',
42  'E','n','c','o','d','i','n','g','T','y','p','e',' ','0','\\',
43  'C','r','y','p','t','S','I','P','D','l','l', 0 };
44 
45 static const WCHAR szPutSigned[] = {
46  'P','u','t','S','i','g','n','e','d','D','a','t','a','M','s','g','\\',0};
47 static const WCHAR szGetSigned[] = {
48  'G','e','t','S','i','g','n','e','d','D','a','t','a','M','s','g','\\',0};
49 static const WCHAR szRemoveSigned[] = {
50  'R','e','m','o','v','e','S','i','g','n','e','d','D','a','t','a','M','s','g','\\',0};
51 static const WCHAR szCreate[] = {
52  'C','r','e','a','t','e','I','n','d','i','r','e','c','t','D','a','t','a','\\',0};
53 static const WCHAR szVerify[] = {
54  'V','e','r','i','f','y','I','n','d','i','r','e','c','t','D','a','t','a','\\',0};
55 static const WCHAR szIsMyFile[] = {
56  'I','s','M','y','F','i','l','e','T','y','p','e','\\',0};
57 static const WCHAR szIsMyFile2[] = {
58  'I','s','M','y','F','i','l','e','T','y','p','e','2','\\',0};
59 
60 static const WCHAR szDllName[] = { 'D','l','l',0 };
61 static const WCHAR szFuncName[] = { 'F','u','n','c','N','a','m','e',0 };
62 
63 /* convert a guid to a wide character string */
64 static void CRYPT_guid2wstr( const GUID *guid, LPWSTR wstr )
65 {
66  char str[40];
67 
68  sprintf(str, "{%08X-%04X-%04X-%02X%02X-%02X%02X%02X%02X%02X%02X}",
69  guid->Data1, guid->Data2, guid->Data3,
70  guid->Data4[0], guid->Data4[1], guid->Data4[2], guid->Data4[3],
71  guid->Data4[4], guid->Data4[5], guid->Data4[6], guid->Data4[7] );
72  MultiByteToWideChar( CP_ACP, 0, str, -1, wstr, 40 );
73 }
74 
75 /***********************************************************************
76  * CRYPT_SIPDeleteFunction
77  *
78  * Helper function for CryptSIPRemoveProvider
79  */
80 static LONG CRYPT_SIPDeleteFunction( const GUID *guid, LPCWSTR szKey )
81 {
82  WCHAR szFullKey[ 0x100 ];
84 
85  /* max length of szFullKey depends on our code only, so we won't overrun */
86  lstrcpyW( szFullKey, szOID );
87  lstrcatW( szFullKey, szKey );
88  CRYPT_guid2wstr( guid, &szFullKey[ lstrlenW( szFullKey ) ] );
89 
90  r = RegDeleteKeyW(HKEY_LOCAL_MACHINE, szFullKey);
91 
92  return r;
93 }
94 
95 /***********************************************************************
96  * CryptSIPRemoveProvider (CRYPT32.@)
97  *
98  * Remove a SIP provider and its functions from the registry.
99  *
100  * PARAMS
101  * pgProv [I] Pointer to a GUID for this SIP provider
102  *
103  * RETURNS
104  * Success: TRUE.
105  * Failure: FALSE. (Look at GetLastError()).
106  *
107  * NOTES
108  * Registry errors are always reported via SetLastError(). Every registry
109  * deletion will be tried.
110  */
112 {
113  LONG r = ERROR_SUCCESS;
114  LONG remove_error = ERROR_SUCCESS;
115 
116  TRACE("%s\n", debugstr_guid(pgProv));
117 
118  if (!pgProv)
119  {
121  return FALSE;
122  }
123 
124 
125 #define CRYPT_SIPREMOVEPROV( key ) \
126  r = CRYPT_SIPDeleteFunction( pgProv, key); \
127  if (r != ERROR_SUCCESS) remove_error = r
128 
136 
137 #undef CRYPT_SIPREMOVEPROV
138 
139  if (remove_error != ERROR_SUCCESS)
140  {
141  SetLastError(remove_error);
142  return FALSE;
143  }
144 
145  return TRUE;
146 }
147 
148 /*
149  * Helper for CryptSIPAddProvider
150  *
151  * Add a registry key containing a dll name and function under
152  * "Software\\Microsoft\\Cryptography\\OID\\EncodingType 0\<func>\<guid>"
153  */
155  LPCWSTR szDll, LPCWSTR szFunction )
156 {
157  WCHAR szFullKey[ 0x100 ];
158  LONG r = ERROR_SUCCESS;
159  HKEY hKey;
160 
161  if( !szFunction )
162  return ERROR_SUCCESS;
163 
164  /* max length of szFullKey depends on our code only, so we won't overrun */
165  lstrcpyW( szFullKey, szOID );
166  lstrcatW( szFullKey, szKey );
167  CRYPT_guid2wstr( guid, &szFullKey[ lstrlenW( szFullKey ) ] );
168 
169  TRACE("key is %s\n", debugstr_w( szFullKey ) );
170 
171  r = RegCreateKeyW( HKEY_LOCAL_MACHINE, szFullKey, &hKey );
172  if( r != ERROR_SUCCESS ) goto error_close_key;
173 
174  /* write the values */
175  r = RegSetValueExW( hKey, szFuncName, 0, REG_SZ, (const BYTE*) szFunction,
176  ( lstrlenW( szFunction ) + 1 ) * sizeof (WCHAR) );
177  if( r != ERROR_SUCCESS ) goto error_close_key;
178  r = RegSetValueExW( hKey, szDllName, 0, REG_SZ, (const BYTE*) szDll,
179  ( lstrlenW( szDll ) + 1) * sizeof (WCHAR) );
180 
181 error_close_key:
182 
183  RegCloseKey( hKey );
184 
185  return r;
186 }
187 
188 /***********************************************************************
189  * CryptSIPAddProvider (CRYPT32.@)
190  *
191  * Add a SIP provider and its functions to the registry.
192  *
193  * PARAMS
194  * psNewProv [I] Pointer to a structure with information about
195  * the functions this SIP provider can perform.
196  *
197  * RETURNS
198  * Success: TRUE.
199  * Failure: FALSE. (Look at GetLastError()).
200  *
201  * NOTES
202  * Registry errors are always reported via SetLastError(). If a
203  * registry error occurs the rest of the registry write operations
204  * will be skipped.
205  */
207 {
208  LONG r = ERROR_SUCCESS;
209 
210  TRACE("%p\n", psNewProv);
211 
212  if (!psNewProv ||
213  psNewProv->cbStruct < FIELD_OFFSET(SIP_ADD_NEWPROVIDER, pwszGetCapFuncName) ||
214  !psNewProv->pwszGetFuncName ||
215  !psNewProv->pwszPutFuncName ||
216  !psNewProv->pwszCreateFuncName ||
217  !psNewProv->pwszVerifyFuncName ||
218  !psNewProv->pwszRemoveFuncName)
219  {
221  return FALSE;
222  }
223 
224  TRACE("%s %s %s %s %s\n",
225  debugstr_guid( psNewProv->pgSubject ),
226  debugstr_w( psNewProv->pwszDLLFileName ),
227  debugstr_w( psNewProv->pwszMagicNumber ),
228  debugstr_w( psNewProv->pwszIsFunctionName ),
229  debugstr_w( psNewProv->pwszIsFunctionNameFmt2 ) );
230 
231 #define CRYPT_SIPADDPROV( key, field ) \
232  r = CRYPT_SIPWriteFunction( psNewProv->pgSubject, key, \
233  psNewProv->pwszDLLFileName, psNewProv->field); \
234  if (r != ERROR_SUCCESS) goto end_function
235 
236  CRYPT_SIPADDPROV( szPutSigned, pwszPutFuncName );
237  CRYPT_SIPADDPROV( szGetSigned, pwszGetFuncName );
238  CRYPT_SIPADDPROV( szRemoveSigned, pwszRemoveFuncName );
239  CRYPT_SIPADDPROV( szCreate, pwszCreateFuncName );
240  CRYPT_SIPADDPROV( szVerify, pwszVerifyFuncName );
241  CRYPT_SIPADDPROV( szIsMyFile, pwszIsFunctionName );
242  CRYPT_SIPADDPROV( szIsMyFile2, pwszIsFunctionNameFmt2 );
243 
244 #undef CRYPT_SIPADDPROV
245 
246 end_function:
247 
248  if (r != ERROR_SUCCESS)
249  {
250  SetLastError(r);
251  return FALSE;
252  }
253 
254  return TRUE;
255 }
256 
258 {
259  LONG r;
260  DWORD size;
261  WCHAR dllName[MAX_PATH];
262  char functionName[MAX_PATH];
263  HMODULE lib;
264  void *func = NULL;
265 
266  /* Read the DLL entry */
267  size = sizeof(dllName);
268  r = RegQueryValueExW(key, szDllName, NULL, NULL, (LPBYTE)dllName, &size);
269  if (r) goto end;
270 
271  /* Read the Function entry */
272  size = sizeof(functionName);
273  r = RegQueryValueExA(key, "FuncName", NULL, NULL, (LPBYTE)functionName,
274  &size);
275  if (r) goto end;
276 
277  lib = LoadLibraryW(dllName);
278  if (!lib)
279  goto end;
280  func = GetProcAddress(lib, functionName);
281  if (func)
282  *pLib = lib;
283  else
284  FreeLibrary(lib);
285 
286 end:
287  return func;
288 }
289 
290 /***********************************************************************
291  * CryptSIPRetrieveSubjectGuid (CRYPT32.@)
292  *
293  * Determine the right SIP GUID for the given file.
294  *
295  * PARAMS
296  * FileName [I] Filename.
297  * hFileIn [I] Optional handle to the file.
298  * pgSubject [O] The SIP's GUID.
299  *
300  * RETURNS
301  * Success: TRUE. pgSubject contains the SIP GUID.
302  * Failure: FALSE. (Look at GetLastError()).
303  *
304  * NOTES
305  * On failure pgSubject will contain a NULL GUID.
306  * The handle is always preferred above the filename.
307  */
309  (LPCWSTR FileName, HANDLE hFileIn, GUID *pgSubject)
310 {
311  HANDLE hFile;
312  BOOL bRet = FALSE;
313  DWORD count;
314  LARGE_INTEGER zero, oldPos;
315  /* FIXME, find out if there is a name for this GUID */
316  static const GUID unknown = { 0xC689AAB8, 0x8E78, 0x11D0, { 0x8C,0x47,0x00,0xC0,0x4F,0xC2,0x95,0xEE }};
317  static const GUID cabGUID = { 0xc689aaba, 0x8e78, 0x11d0, {0x8c,0x47,0x00,0xc0,0x4f,0xc2,0x95,0xee }};
318  static const GUID catGUID = { 0xDE351A43, 0x8E59, 0x11D0, { 0x8C,0x47,0x00,0xC0,0x4F,0xC2,0x95,0xEE }};
319  static const WORD dosHdr = IMAGE_DOS_SIGNATURE;
320  static const BYTE cabHdr[] = { 'M','S','C','F' };
322  WCHAR szFullKey[ 0x100 ];
323  LONG r = ERROR_SUCCESS;
324  HKEY key;
325 
326  TRACE("(%s %p %p)\n", wine_dbgstr_w(FileName), hFileIn, pgSubject);
327 
328  if (!pgSubject || (!FileName && !hFileIn))
329  {
331  return FALSE;
332  }
333 
334  /* Set pgSubject to zero's */
335  memset(pgSubject, 0 , sizeof(GUID));
336 
337  if (hFileIn)
338  /* Use the given handle, make sure not to close this one ourselves */
339  hFile = hFileIn;
340  else
341  {
343  /* Last error is set by CreateFile */
344  if (hFile == INVALID_HANDLE_VALUE) return FALSE;
345  }
346 
347  zero.QuadPart = 0;
348  SetFilePointerEx(hFile, zero, &oldPos, FILE_CURRENT);
349  SetFilePointer(hFile, 0, NULL, FILE_BEGIN);
350  if (!ReadFile(hFile, hdr, sizeof(hdr), &count, NULL))
351  goto cleanup;
352 
353  if (count < SIP_MAX_MAGIC_NUMBER)
354  {
356  goto cleanup;
357  }
358 
359  TRACE("file magic = 0x%02x%02x%02x%02x\n", hdr[0], hdr[1], hdr[2], hdr[3]);
360  /* As everything is in place now we start looking at the file header */
361  if (!memcmp(hdr, &dosHdr, sizeof(dosHdr)))
362  {
363  *pgSubject = unknown;
365  bRet = TRUE;
366  goto cleanup;
367  }
368  /* Quick-n-dirty check for a cab file. */
369  if (!memcmp(hdr, cabHdr, sizeof(cabHdr)))
370  {
371  *pgSubject = cabGUID;
373  bRet = TRUE;
374  goto cleanup;
375  }
376  /* If it's asn.1-encoded, it's probably a .cat file. */
377  if (hdr[0] == 0x30)
378  {
379  DWORD fileLen = GetFileSize(hFile, NULL);
380 
381  TRACE("fileLen = %d\n", fileLen);
382  /* Sanity-check length */
383  if (hdr[1] < 0x80 && fileLen == 2 + hdr[1])
384  {
385  *pgSubject = catGUID;
387  bRet = TRUE;
388  goto cleanup;
389  }
390  else if (hdr[1] == 0x80)
391  {
392  /* Indefinite length, can't verify with just the header, assume it
393  * is.
394  */
395  *pgSubject = catGUID;
397  bRet = TRUE;
398  goto cleanup;
399  }
400  else
401  {
402  BYTE lenBytes = hdr[1] & 0x7f;
403 
404  if (lenBytes == 1 && fileLen == 2 + lenBytes + hdr[2])
405  {
406  *pgSubject = catGUID;
408  bRet = TRUE;
409  goto cleanup;
410  }
411  else if (lenBytes == 2 && fileLen == 2 + lenBytes +
412  (hdr[2] << 8 | hdr[3]))
413  {
414  *pgSubject = catGUID;
416  bRet = TRUE;
417  goto cleanup;
418  }
419  else if (fileLen > 0xffff)
420  {
421  /* The file size must be greater than 2 bytes in length, so
422  * assume it is a .cat file
423  */
424  *pgSubject = catGUID;
426  bRet = TRUE;
427  goto cleanup;
428  }
429  }
430  }
431 
432  /* Check for supported functions using CryptSIPDllIsMyFileType */
433  /* max length of szFullKey depends on our code only, so we won't overrun */
434  lstrcpyW(szFullKey, szOID);
435  lstrcatW(szFullKey, szIsMyFile);
436  r = RegOpenKeyExW(HKEY_LOCAL_MACHINE, szFullKey, 0, KEY_READ, &key);
437  if (r == ERROR_SUCCESS)
438  {
439  DWORD index = 0, size;
440  WCHAR subKeyName[MAX_PATH];
441 
442  do {
443  size = sizeof(subKeyName) / sizeof(subKeyName[0]);
444  r = RegEnumKeyExW(key, index++, subKeyName, &size, NULL, NULL,
445  NULL, NULL);
446  if (r == ERROR_SUCCESS)
447  {
448  HKEY subKey;
449 
450  r = RegOpenKeyExW(key, subKeyName, 0, KEY_READ, &subKey);
451  if (r == ERROR_SUCCESS)
452  {
453  HMODULE lib;
455  &lib);
456 
457  if (isMy)
458  {
459  bRet = isMy(hFile, pgSubject);
460  FreeLibrary(lib);
461  }
462  RegCloseKey(subKey);
463  }
464  }
465  } while (!bRet && r == ERROR_SUCCESS);
466  RegCloseKey(key);
467  }
468 
469  /* Check for supported functions using CryptSIPDllIsMyFileType2 */
470  if (!bRet)
471  {
472  lstrcpyW(szFullKey, szOID);
473  lstrcatW(szFullKey, szIsMyFile2);
474  r = RegOpenKeyExW(HKEY_LOCAL_MACHINE, szFullKey, 0, KEY_READ, &key);
475  if (r == ERROR_SUCCESS)
476  {
477  DWORD index = 0, size;
478  WCHAR subKeyName[MAX_PATH];
479 
480  do {
481  size = sizeof(subKeyName) / sizeof(subKeyName[0]);
482  r = RegEnumKeyExW(key, index++, subKeyName, &size, NULL, NULL,
483  NULL, NULL);
484  if (r == ERROR_SUCCESS)
485  {
486  HKEY subKey;
487 
488  r = RegOpenKeyExW(key, subKeyName, 0, KEY_READ, &subKey);
489  if (r == ERROR_SUCCESS)
490  {
491  HMODULE lib;
492  pfnIsFileSupportedName isMy2 =
493  CRYPT_LoadSIPFuncFromKey(subKey, &lib);
494 
495  if (isMy2)
496  {
497  bRet = isMy2((LPWSTR)FileName, pgSubject);
498  FreeLibrary(lib);
499  }
500  RegCloseKey(subKey);
501  }
502  }
503  } while (!bRet && r == ERROR_SUCCESS);
504  RegCloseKey(key);
505  }
506  }
507 
508  if (!bRet)
510 
511 cleanup:
512  /* If we didn't open this one we shouldn't close it (hFile is a copy),
513  * but we should reset the file pointer to its original position.
514  */
515  if (!hFileIn)
516  CloseHandle(hFile);
517  else
518  SetFilePointerEx(hFile, oldPos, NULL, FILE_BEGIN);
519 
520  return bRet;
521 }
522 
524  HKEY *key)
525 {
526  WCHAR szFullKey[ 0x100 ];
527 
528  lstrcpyW(szFullKey, szOID);
529  lstrcatW(szFullKey, function);
530  CRYPT_guid2wstr(guid, &szFullKey[lstrlenW(szFullKey)]);
531  return RegOpenKeyExW(HKEY_LOCAL_MACHINE, szFullKey, 0, KEY_READ, key);
532 }
533 
534 /* Loads the function named function for the SIP specified by pgSubject, and
535  * returns it if found. Returns NULL on error. If the function is loaded,
536  * *pLib is set to the library in which it is found.
537  */
538 static void *CRYPT_LoadSIPFunc(const GUID *pgSubject, LPCWSTR function,
539  HMODULE *pLib)
540 {
541  LONG r;
542  HKEY key;
543  void *func = NULL;
544 
545  TRACE("(%s, %s)\n", debugstr_guid(pgSubject), debugstr_w(function));
546 
547  r = CRYPT_OpenSIPFunctionKey(pgSubject, function, &key);
548  if (!r)
549  {
550  func = CRYPT_LoadSIPFuncFromKey(key, pLib);
551  RegCloseKey(key);
552  }
553  TRACE("returning %p\n", func);
554  return func;
555 }
556 
557 typedef struct _WINE_SIP_PROVIDER {
560  struct list entry;
562 
563 static struct list providers = { &providers, &providers };
566 {
567  0, 0, &providers_cs,
568  { &providers_cs_debug.ProcessLocksList,
569  &providers_cs_debug.ProcessLocksList },
570  0, 0, { (DWORD_PTR)(__FILE__ ": providers_cs") }
571 };
572 static CRITICAL_SECTION providers_cs = { &providers_cs_debug, -1, 0, 0, 0, 0 };
573 
574 static void CRYPT_CacheSIP(const GUID *pgSubject, SIP_DISPATCH_INFO *info)
575 {
577 
578  if (prov)
579  {
580  prov->subject = *pgSubject;
581  prov->info = *info;
582  EnterCriticalSection(&providers_cs);
583  list_add_tail(&providers, &prov->entry);
584  LeaveCriticalSection(&providers_cs);
585  }
586 }
587 
588 static WINE_SIP_PROVIDER *CRYPT_GetCachedSIP(const GUID *pgSubject)
589 {
590  WINE_SIP_PROVIDER *provider = NULL, *ret = NULL;
591 
592  EnterCriticalSection(&providers_cs);
593  LIST_FOR_EACH_ENTRY(provider, &providers, WINE_SIP_PROVIDER, entry)
594  {
595  if (IsEqualGUID(pgSubject, &provider->subject))
596  break;
597  }
598  if (provider && IsEqualGUID(pgSubject, &provider->subject))
599  ret = provider;
600  LeaveCriticalSection(&providers_cs);
601  return ret;
602 }
603 
604 static inline BOOL CRYPT_IsSIPCached(const GUID *pgSubject)
605 {
606  return CRYPT_GetCachedSIP(pgSubject) != NULL;
607 }
608 
609 void crypt_sip_free(void)
610 {
611  WINE_SIP_PROVIDER *prov, *next;
612 
613  LIST_FOR_EACH_ENTRY_SAFE(prov, next, &providers, WINE_SIP_PROVIDER, entry)
614  {
615  list_remove(&prov->entry);
616  FreeLibrary(prov->info.hSIP);
617  CryptMemFree(prov);
618  }
619  DeleteCriticalSection(&providers_cs);
620 }
621 
622 /* Loads the SIP for pgSubject into the global cache. Returns FALSE if the
623  * SIP isn't registered or is invalid.
624  */
625 static BOOL CRYPT_LoadSIP(const GUID *pgSubject)
626 {
627  SIP_DISPATCH_INFO sip = { 0 };
628  HMODULE lib = NULL, temp = NULL;
629 
630  sip.pfGet = CRYPT_LoadSIPFunc(pgSubject, szGetSigned, &lib);
631  if (!sip.pfGet)
632  goto error;
633  sip.pfPut = CRYPT_LoadSIPFunc(pgSubject, szPutSigned, &temp);
634  if (!sip.pfPut || temp != lib)
635  goto error;
636  FreeLibrary(temp);
637  temp = NULL;
638  sip.pfCreate = CRYPT_LoadSIPFunc(pgSubject, szCreate, &temp);
639  if (!sip.pfCreate || temp != lib)
640  goto error;
641  FreeLibrary(temp);
642  temp = NULL;
643  sip.pfVerify = CRYPT_LoadSIPFunc(pgSubject, szVerify, &temp);
644  if (!sip.pfVerify || temp != lib)
645  goto error;
646  FreeLibrary(temp);
647  temp = NULL;
648  sip.pfRemove = CRYPT_LoadSIPFunc(pgSubject, szRemoveSigned, &temp);
649  if (!sip.pfRemove || temp != lib)
650  goto error;
651  FreeLibrary(temp);
652  sip.hSIP = lib;
653  CRYPT_CacheSIP(pgSubject, &sip);
654  return TRUE;
655 
656 error:
657  FreeLibrary(lib);
658  FreeLibrary(temp);
660  return FALSE;
661 }
662 
663 /***********************************************************************
664  * CryptSIPLoad (CRYPT32.@)
665  *
666  * Load some internal crypt32 functions into a SIP_DISPATCH_INFO structure.
667  *
668  * PARAMS
669  * pgSubject [I] The GUID.
670  * dwFlags [I] Flags.
671  * pSipDispatch [I] The loaded functions.
672  *
673  * RETURNS
674  * Success: TRUE. pSipDispatch contains the functions.
675  * Failure: FALSE. (Look at GetLastError()).
676  *
677  * NOTES
678  * CryptSIPLoad uses caching for the list of GUIDs and whether a SIP is
679  * already loaded.
680  *
681  * An application calls CryptSipLoad which will return a structure with the
682  * function addresses of some internal crypt32 functions. The application will
683  * then call these functions which will be forwarded to the appropriate SIP.
684  *
685  * CryptSIPLoad will load the needed SIP but doesn't unload this dll. The unloading
686  * is done when crypt32 is unloaded.
687  */
689  (const GUID *pgSubject, DWORD dwFlags, SIP_DISPATCH_INFO *pSipDispatch)
690 {
691  TRACE("(%s %d %p)\n", debugstr_guid(pgSubject), dwFlags, pSipDispatch);
692 
693  if (!pgSubject || dwFlags != 0 || !pSipDispatch)
694  {
696  return FALSE;
697  }
698  if (!CRYPT_IsSIPCached(pgSubject) && !CRYPT_LoadSIP(pgSubject))
699  return FALSE;
700 
701  pSipDispatch->hSIP = NULL;
702  pSipDispatch->pfGet = CryptSIPGetSignedDataMsg;
703  pSipDispatch->pfPut = CryptSIPPutSignedDataMsg;
704  pSipDispatch->pfCreate = CryptSIPCreateIndirectData;
705  pSipDispatch->pfVerify = CryptSIPVerifyIndirectData;
706  pSipDispatch->pfRemove = CryptSIPRemoveSignedDataMsg;
707 
708  return TRUE;
709 }
710 
711 /***********************************************************************
712  * CryptSIPCreateIndirectData (CRYPT32.@)
713  */
715  SIP_INDIRECT_DATA* pIndirectData)
716 {
717  WINE_SIP_PROVIDER *sip;
718  BOOL ret = FALSE;
719 
720  TRACE("(%p %p %p)\n", pSubjectInfo, pcbIndirectData, pIndirectData);
721 
722  if (!pSubjectInfo || !pSubjectInfo->pgSubjectType || !pcbIndirectData)
723  {
725  return FALSE;
726  }
727  if ((sip = CRYPT_GetCachedSIP(pSubjectInfo->pgSubjectType)))
728  ret = sip->info.pfCreate(pSubjectInfo, pcbIndirectData, pIndirectData);
729  TRACE("returning %d\n", ret);
730  return ret;
731 }
732 
733 /***********************************************************************
734  * CryptSIPGetSignedDataMsg (CRYPT32.@)
735  */
736 BOOL WINAPI CryptSIPGetSignedDataMsg(SIP_SUBJECTINFO* pSubjectInfo, DWORD* pdwEncodingType,
737  DWORD dwIndex, DWORD* pcbSignedDataMsg, BYTE* pbSignedDataMsg)
738 {
739  WINE_SIP_PROVIDER *sip;
740  BOOL ret = FALSE;
741 
742  TRACE("(%p %p %d %p %p)\n", pSubjectInfo, pdwEncodingType, dwIndex,
743  pcbSignedDataMsg, pbSignedDataMsg);
744 
745  if ((sip = CRYPT_GetCachedSIP(pSubjectInfo->pgSubjectType)))
746  ret = sip->info.pfGet(pSubjectInfo, pdwEncodingType, dwIndex,
747  pcbSignedDataMsg, pbSignedDataMsg);
748  TRACE("returning %d\n", ret);
749  return ret;
750 }
751 
752 /***********************************************************************
753  * CryptSIPPutSignedDataMsg (CRYPT32.@)
754  */
756  DWORD* pdwIndex, DWORD cbSignedDataMsg, BYTE* pbSignedDataMsg)
757 {
758  WINE_SIP_PROVIDER *sip;
759  BOOL ret = FALSE;
760 
761  TRACE("(%p %d %p %d %p)\n", pSubjectInfo, pdwEncodingType, pdwIndex,
762  cbSignedDataMsg, pbSignedDataMsg);
763 
764  if ((sip = CRYPT_GetCachedSIP(pSubjectInfo->pgSubjectType)))
765  ret = sip->info.pfPut(pSubjectInfo, pdwEncodingType, pdwIndex,
766  cbSignedDataMsg, pbSignedDataMsg);
767  TRACE("returning %d\n", ret);
768  return ret;
769 }
770 
771 /***********************************************************************
772  * CryptSIPRemoveSignedDataMsg (CRYPT32.@)
773  */
775  DWORD dwIndex)
776 {
777  WINE_SIP_PROVIDER *sip;
778  BOOL ret = FALSE;
779 
780  TRACE("(%p %d)\n", pSubjectInfo, dwIndex);
781 
782  if ((sip = CRYPT_GetCachedSIP(pSubjectInfo->pgSubjectType)))
783  ret = sip->info.pfRemove(pSubjectInfo, dwIndex);
784  TRACE("returning %d\n", ret);
785  return ret;
786 }
787 
788 /***********************************************************************
789  * CryptSIPVerifyIndirectData (CRYPT32.@)
790  */
792  SIP_INDIRECT_DATA* pIndirectData)
793 {
794  WINE_SIP_PROVIDER *sip;
795  BOOL ret = FALSE;
796 
797  TRACE("(%p %p)\n", pSubjectInfo, pIndirectData);
798 
799  if ((sip = CRYPT_GetCachedSIP(pSubjectInfo->pgSubjectType)))
800  ret = sip->info.pfVerify(pSubjectInfo, pIndirectData);
801  TRACE("returning %d\n", ret);
802  return ret;
803 }
804 
805 /***********************************************************************
806  * CryptSIPRetrieveSubjectGuidForCatalogFile (CRYPT32.@)
807  */
809 {
810  FIXME("(%s %p %p)\n", debugstr_w(filename), handle, subject);
812  return FALSE;
813 }
SIP_DISPATCH_INFO info
Definition: sip.c:559
static const WCHAR szIsMyFile2[]
Definition: sip.c:57
#define ERROR_INVALID_PARAMETER
Definition: compat.h:91
GLenum func
Definition: glext.h:6028
static struct list providers
Definition: sip.c:563
BOOL WINAPI SetFilePointerEx(HANDLE hFile, LARGE_INTEGER liDistanceToMove, PLARGE_INTEGER lpNewFilePointer, DWORD dwMoveMethod)
Definition: fileinfo.c:327
#define SIP_MAX_MAGIC_NUMBER
Definition: mssip.h:45
LONG WINAPI RegQueryValueExA(_In_ HKEY hkeyorg, _In_ LPCSTR name, _In_ LPDWORD reserved, _Out_opt_ LPDWORD type, _Out_opt_ LPBYTE data, _Inout_opt_ LPDWORD count)
Definition: reg.c:4041
static CRITICAL_SECTION providers_cs
Definition: sip.c:564
unsigned short WORD
Definition: ntddk_ex.h:93
#define TRUE
Definition: types.h:120
#define CloseHandle
Definition: compat.h:398
char hdr[14]
Definition: iptest.cpp:33
int memcmp(void *Buffer1, void *Buffer2, ACPI_SIZE Count)
Definition: utclib.c:112
#define ERROR_SUCCESS
Definition: deptool.c:10
BOOL WINAPI CryptSIPVerifyIndirectData(SIP_SUBJECTINFO *pSubjectInfo, SIP_INDIRECT_DATA *pIndirectData)
Definition: sip.c:791
#define error(str)
Definition: mkdosfs.c:1605
WCHAR * pwszGetFuncName
Definition: mssip.h:152
static const WCHAR szDllName[]
Definition: sip.c:60
WCHAR * pwszVerifyFuncName
Definition: mssip.h:155
BOOL WINAPI CryptSIPRetrieveSubjectGuidForCatalogFile(LPCWSTR filename, HANDLE handle, GUID *subject)
Definition: sip.c:808
pCryptSIPGetSignedDataMsg pfGet
Definition: mssip.h:129
#define CRYPT_SIPADDPROV(key, field)
#define KEY_READ
Definition: nt_native.h:1023
__wchar_t WCHAR
Definition: xmlstorage.h:180
GLdouble GLdouble GLdouble r
Definition: gl.h:2055
WCHAR * pwszDLLFileName
Definition: mssip.h:147
#define CP_ACP
Definition: compat.h:99
unsigned char * LPBYTE
Definition: typedefs.h:52
#define FILE_CURRENT
Definition: winbase.h:113
uint8_t entry
Definition: isohybrid.c:63
struct list entry
Definition: sip.c:560
BOOL WINAPI CryptSIPRetrieveSubjectGuid(LPCWSTR FileName, HANDLE hFileIn, GUID *pgSubject)
Definition: sip.c:309
LONG WINAPI RegDeleteKeyW(_In_ HKEY hKey, _In_ LPCWSTR lpSubKey)
Definition: reg.c:1240
pCryptSIPCreateIndirectData pfCreate
Definition: mssip.h:131
const WCHAR * LPCWSTR
Definition: xmlstorage.h:185
#define INVALID_HANDLE_VALUE
Definition: compat.h:391
static const WCHAR szOID[]
Definition: sip.c:37
static const WCHAR szGetSigned[]
Definition: sip.c:47
GUID subject
Definition: sip.c:558
GLuint GLuint end
Definition: gl.h:1545
pCryptSIPPutSignedDataMsg pfPut
Definition: mssip.h:130
void WINAPI EnterCriticalSection(LPCRITICAL_SECTION)
const char * filename
Definition: ioapi.h:135
#define lstrlenW
Definition: compat.h:407
static const WCHAR szRemoveSigned[]
Definition: sip.c:49
DWORD DWORD
Definition: winlogon.h:84
#define FILE_SHARE_READ
Definition: compat.h:125
static const WCHAR szIsMyFile[]
Definition: sip.c:55
DWORD WINAPI DECLSPEC_HOTPATCH SetFilePointer(HANDLE hFile, LONG lDistanceToMove, PLONG lpDistanceToMoveHigh, DWORD dwMoveMethod)
Definition: fileinfo.c:204
#define IMAGE_DOS_SIGNATURE
Definition: pedump.c:89
#define sprintf(buf, format,...)
Definition: sprintf.c:55
__WINE_SERVER_LIST_INLINE void list_add_tail(struct list *list, struct list *elem)
Definition: list.h:102
BOOL WINAPI CryptSIPPutSignedDataMsg(SIP_SUBJECTINFO *pSubjectInfo, DWORD pdwEncodingType, DWORD *pdwIndex, DWORD cbSignedDataMsg, BYTE *pbSignedDataMsg)
Definition: sip.c:755
#define LIST_FOR_EACH_ENTRY(elem, list, type, field)
Definition: list.h:198
static const GUID catGUID
Definition: crypt.c:1359
LPVOID WINAPI CryptMemAlloc(ULONG cbSize)
Definition: main.c:121
const GUID * guid
LONG WINAPI RegCloseKey(HKEY hKey)
Definition: reg.c:423
GUID * pgSubject
Definition: mssip.h:145
#define FALSE
Definition: types.h:117
WCHAR * pwszPutFuncName
Definition: mssip.h:153
long LONG
Definition: pedump.c:60
static LONG CRYPT_SIPWriteFunction(const GUID *guid, LPCWSTR szKey, LPCWSTR szDll, LPCWSTR szFunction)
Definition: sip.c:154
static const WCHAR szPutSigned[]
Definition: sip.c:45
static CRITICAL_SECTION_DEBUG providers_cs_debug
Definition: sip.c:565
#define debugstr_w
Definition: kernel32.h:32
#define FIXME(fmt,...)
Definition: debug.h:110
char * wine_dbgstr_w(const wchar_t *wstr)
Definition: CString.cpp:62
BOOL WINAPI CryptSIPRemoveProvider(GUID *pgProv)
Definition: sip.c:111
pCryptSIPVerifyIndirectData pfVerify
Definition: mssip.h:132
const WCHAR * str
BOOL WINAPI CryptSIPGetSignedDataMsg(SIP_SUBJECTINFO *pSubjectInfo, DWORD *pdwEncodingType, DWORD dwIndex, DWORD *pcbSignedDataMsg, BYTE *pbSignedDataMsg)
Definition: sip.c:736
#define LoadLibraryW(x)
Definition: compat.h:404
smooth NULL
Definition: ftsmooth.c:416
struct _WINE_SIP_PROVIDER WINE_SIP_PROVIDER
GLuint index
Definition: glext.h:6031
static LONG CRYPT_SIPDeleteFunction(const GUID *guid, LPCWSTR szKey)
Definition: sip.c:80
#define debugstr_guid
Definition: kernel32.h:35
static void * CRYPT_LoadSIPFunc(const GUID *pgSubject, LPCWSTR function, HMODULE *pLib)
Definition: sip.c:538
#define OPEN_EXISTING
Definition: compat.h:426
static LONG CRYPT_OpenSIPFunctionKey(const GUID *guid, LPCWSTR function, HKEY *key)
Definition: sip.c:523
static const GUID cabGUID
Definition: crypt.c:1357
LONG WINAPI RegSetValueExW(_In_ HKEY hKey, _In_ LPCWSTR lpValueName, _In_ DWORD Reserved, _In_ DWORD dwType, _In_ CONST BYTE *lpData, _In_ DWORD cbData)
Definition: reg.c:4917
__WINE_SERVER_LIST_INLINE void list_remove(struct list *elem)
Definition: list.h:108
#define TRACE(s)
Definition: solgame.cpp:4
#define FreeLibrary(x)
Definition: compat.h:405
unsigned int BOOL
Definition: ntddk_ex.h:94
GLsizeiptr size
Definition: glext.h:5919
LONG WINAPI RegQueryValueExW(_In_ HKEY hkeyorg, _In_ LPCWSTR name, _In_ LPDWORD reserved, _In_ LPDWORD type, _In_ LPBYTE data, _In_ LPDWORD count)
Definition: reg.c:4134
static void * CRYPT_LoadSIPFuncFromKey(HKEY key, HMODULE *pLib)
Definition: sip.c:257
void WINAPI DeleteCriticalSection(PCRITICAL_SECTION)
HANDLE HKEY
Definition: registry.h:24
BOOL WINAPI CryptSIPAddProvider(SIP_ADD_NEWPROVIDER *psNewProv)
Definition: sip.c:206
GUID * pgSubjectType
Definition: mssip.h:52
#define MAX_PATH
Definition: compat.h:26
GLuint GLuint GLsizei count
Definition: gl.h:1545
DWORD WINAPI GetFileSize(HANDLE hFile, LPDWORD lpFileSizeHigh)
Definition: fileinfo.c:481
#define SetLastError(x)
Definition: compat.h:409
static void CRYPT_CacheSIP(const GUID *pgSubject, SIP_DISPATCH_INFO *info)
Definition: sip.c:574
Definition: id3.c:18
WINE_DEFAULT_DEBUG_CHANNEL(crypt)
int ret
static double zero
Definition: j0_y0.c:96
#define FILE_ATTRIBUTE_NORMAL
Definition: compat.h:126
BOOL WINAPI CryptSIPRemoveSignedDataMsg(SIP_SUBJECTINFO *pSubjectInfo, DWORD dwIndex)
Definition: sip.c:774
_In_ PCCERT_CONTEXT _In_ DWORD dwFlags
Definition: wincrypt.h:1175
HKEY key
Definition: reg.c:42
LONG WINAPI RegCreateKeyW(HKEY hKey, LPCWSTR lpSubKey, PHKEY phkResult)
Definition: reg.c:1202
Definition: _list.h:228
BOOL(WINAPI * pfnIsFileSupportedName)(WCHAR *, GUID *)
Definition: mssip.h:138
#define GENERIC_READ
Definition: compat.h:124
static stack_node_t temp
Definition: rpn.c:18
LIST_ENTRY ProcessLocksList
Definition: winbase.h:848
_In_ HANDLE hFile
Definition: mswsock.h:90
#define WINAPI
Definition: msvc.h:20
BOOL WINAPI CryptSIPCreateIndirectData(SIP_SUBJECTINFO *pSubjectInfo, DWORD *pcbIndirectData, SIP_INDIRECT_DATA *pIndirectData)
Definition: sip.c:714
WCHAR * pwszIsFunctionNameFmt2
Definition: mssip.h:158
unsigned char BYTE
Definition: ntddk_ex.h:96
#define S_OK
Definition: intsafe.h:59
#define FILE_BEGIN
Definition: winbase.h:112
const XML_Char XML_Encoding * info
Definition: expat.h:530
DWORD *typedef HANDLE
Definition: winlogon.h:61
static unsigned __int64 next
Definition: rand_nt.c:6
#define DWORD_PTR
Definition: generated.c:24
#define LIST_FOR_EACH_ENTRY_SAFE(cursor, cursor2, list, type, field)
Definition: list.h:204
#define lstrcpyW
Definition: compat.h:406
#define TRUST_E_SUBJECT_FORM_UNKNOWN
Definition: winerror.h:3114
void crypt_sip_free(void)
Definition: sip.c:609
BOOL(WINAPI * pfnIsFileSupported)(HANDLE, GUID *)
Definition: mssip.h:137
#define CRYPT_SIPREMOVEPROV(key)
#define FIELD_OFFSET(t, f)
Definition: typedefs.h:254
BOOL WINAPI IsEqualGUID(REFGUID rguid1, REFGUID rguid2)
Definition: compobj.c:4024
BOOL WINAPI CryptSIPLoad(const GUID *pgSubject, DWORD dwFlags, SIP_DISPATCH_INFO *pSipDispatch)
Definition: sip.c:689
static WINE_SIP_PROVIDER * CRYPT_GetCachedSIP(const GUID *pgSubject)
Definition: sip.c:588
#define MultiByteToWideChar
Definition: compat.h:100
#define CreateFileW
Definition: compat.h:400
HANDLE HMODULE
Definition: typedefs.h:75
VOID WINAPI CryptMemFree(LPVOID pv)
Definition: main.c:131
LONG WINAPI RegOpenKeyExW(HKEY hKey, LPCWSTR lpSubKey, DWORD ulOptions, REGSAM samDesired, PHKEY phkResult)
Definition: reg.c:3381
pCryptSIPRemoveSignedDataMsg pfRemove
Definition: mssip.h:133
char * cleanup(char *str)
Definition: wpickclick.c:99
#define GetProcAddress(x, y)
Definition: compat.h:410
WCHAR * pwszRemoveFuncName
Definition: mssip.h:156
LONG WINAPI RegEnumKeyExW(_In_ HKEY hKey, _In_ DWORD dwIndex, _Out_ LPWSTR lpName, _Inout_ LPDWORD lpcbName, _Reserved_ LPDWORD lpReserved, _Out_opt_ LPWSTR lpClass, _Inout_opt_ LPDWORD lpcbClass, _Out_opt_ PFILETIME lpftLastWriteTime)
Definition: reg.c:2541
LPWSTR WINAPI lstrcatW(LPWSTR lpString1, LPCWSTR lpString2)
Definition: lstring.c:274
static void CRYPT_guid2wstr(const GUID *guid, LPWSTR wstr)
Definition: sip.c:64
void WINAPI LeaveCriticalSection(LPCRITICAL_SECTION)
static BOOL CRYPT_LoadSIP(const GUID *pgSubject)
Definition: sip.c:625
BOOL WINAPI ReadFile(IN HANDLE hFile, IN LPVOID lpBuffer, IN DWORD nNumberOfBytesToRead, OUT LPDWORD lpNumberOfBytesRead OPTIONAL, IN LPOVERLAPPED lpOverlapped OPTIONAL)
Definition: rw.c:123
#define memset(x, y, z)
Definition: compat.h:39
WCHAR * pwszCreateFuncName
Definition: mssip.h:154
WCHAR * LPWSTR
Definition: xmlstorage.h:184
WCHAR * pwszMagicNumber
Definition: mssip.h:148
static const WCHAR szCreate[]
Definition: sip.c:51
static const WCHAR szVerify[]
Definition: sip.c:53
static const WCHAR szFuncName[]
Definition: sip.c:61
static BOOL CRYPT_IsSIPCached(const GUID *pgSubject)
Definition: sip.c:604
LONGLONG QuadPart
Definition: typedefs.h:112
Definition: path.c:42
#define HKEY_LOCAL_MACHINE
Definition: winreg.h:12
#define REG_SZ
Definition: layer.c:22
WCHAR * pwszIsFunctionName
Definition: mssip.h:150