ReactOS  0.4.15-dev-1386-g5cb9f87
main.c File Reference
#include <stdarg.h>
#include "windef.h"
#include "winbase.h"
#include "wincrypt.h"
#include "mssip.h"
#include "objbase.h"
#include "initguid.h"
#include "wine/debug.h"
Include dependency graph for main.c:

Go to the source code of this file.

Macros

#define COBJMACROS
 

Functions

 WINE_DEFAULT_DEBUG_CHANNEL (msisip)
 
BOOL WINAPI DllMain (HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved)
 
HRESULT WINAPI DllRegisterServer (void)
 
HRESULT WINAPI DllUnregisterServer (void)
 
BOOL WINAPI MsiSIPGetSignedDataMsg (SIP_SUBJECTINFO *pSubjectInfo, DWORD *pdwEncodingType, DWORD dwIndex, DWORD *pcbSignedDataMsg, BYTE *pbSignedDataMsg)
 
 DEFINE_GUID (CLSID_MsiTransform, 0x000c1082, 0x0000, 0x0000, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46)
 
 DEFINE_GUID (CLSID_MsiDatabase, 0x000c1084, 0x0000, 0x0000, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46)
 
 DEFINE_GUID (CLSID_MsiPatch, 0x000c1086, 0x0000, 0x0000, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x46)
 
BOOL WINAPI MsiSIPIsMyTypeOfFile (WCHAR *name, GUID *subject)
 

Variables

static GUID mySubject
 

Macro Definition Documentation

◆ COBJMACROS

#define COBJMACROS

Definition at line 24 of file main.c.

Function Documentation

◆ DEFINE_GUID() [1/3]

DEFINE_GUID ( CLSID_MsiTransform  ,
0x000c1082  ,
0x0000  ,
0x0000  ,
0xc0  ,
0x00  ,
0x00  ,
0x00  ,
0x00  ,
0x00  ,
0x00  ,
0x46   
)

◆ DEFINE_GUID() [2/3]

DEFINE_GUID ( CLSID_MsiDatabase  ,
0x000c1084  ,
0x0000  ,
0x0000  ,
0xc0  ,
0x00  ,
0x00  ,
0x00  ,
0x00  ,
0x00  ,
0x00  ,
0x46   
)

◆ DEFINE_GUID() [3/3]

DEFINE_GUID ( CLSID_MsiPatch  ,
0x000c1086  ,
0x0000  ,
0x0000  ,
0xc0  ,
0x00  ,
0x00  ,
0x00  ,
0x00  ,
0x00  ,
0x00  ,
0x46   
)

◆ DllMain()

BOOL WINAPI DllMain ( HINSTANCE  hinstDLL,
DWORD  fdwReason,
LPVOID  lpvReserved 
)

Definition at line 31 of file main.c.

32 {
33  TRACE("(0x%p, %d, %p)\n", hinstDLL, fdwReason, lpvReserved);
34 
35  switch (fdwReason)
36  {
37  case DLL_WINE_PREATTACH:
38  return FALSE; /* prefer native version */
39  case DLL_PROCESS_ATTACH:
40  DisableThreadLibraryCalls(hinstDLL);
41  break;
42  }
43 
44  return TRUE;
45 }
#define TRUE
Definition: types.h:120
BOOL WINAPI DisableThreadLibraryCalls(IN HMODULE hLibModule)
Definition: loader.c:85
#define DLL_PROCESS_ATTACH
Definition: compat.h:131
static IN DWORD IN LPVOID lpvReserved
#define FALSE
Definition: types.h:117
#define TRACE(s)
Definition: solgame.cpp:4

◆ DllRegisterServer()

HRESULT WINAPI DllRegisterServer ( void  )

Definition at line 53 of file main.c.

54 {
55  static WCHAR msisip[] = { 'M','S','I','S','I','P','.','D','L','L',0 };
56  static WCHAR getSignedDataMsg[] = { 'M','s','i','S','I','P','G','e','t',
57  'S','i','g','n','e','d','D','a','t','a','M','s','g',0 };
58  static WCHAR putSignedDataMsg[] = { 'M','s','i','S','I','P','P','u','t',
59  'S','i','g','n','e','d','D','a','t','a','M','s','g',0 };
60  static WCHAR createIndirectData[] = { 'M','s','i','S','I','P',
61  'C','r','e','a','t','e','I','n','d','i','r','e','c','t','D','a','t','a',
62  0 };
63  static WCHAR verifyIndirectData[] = { 'M','s','i','S','I','P',
64  'V','e','r','i','f','y','I','n','d','i','r','e','c','t','D','a','t','a',
65  0 };
66  static WCHAR removeSignedDataMsg[] = { 'M','s','i','S','I','P','R','e','m',
67  'o','v','e','S','i','g','n','e','d','D','a','t','a','M','s','g', 0 };
68  static WCHAR isMyTypeOfFile[] = { 'M','s','i','S','I','P',
69  'I','s','M','y','T','y','p','e','O','f','F','i','l','e',0 };
70 
72 
73  memset(&prov, 0, sizeof(prov));
74  prov.cbStruct = sizeof(prov);
75  prov.pwszDLLFileName = msisip;
76  prov.pgSubject = &mySubject;
77  prov.pwszGetFuncName = getSignedDataMsg;
78  prov.pwszPutFuncName = putSignedDataMsg;
79  prov.pwszCreateFuncName = createIndirectData;
80  prov.pwszVerifyFuncName = verifyIndirectData;
81  prov.pwszRemoveFuncName = removeSignedDataMsg;
82  prov.pwszIsFunctionNameFmt2 = isMyTypeOfFile;
83  prov.pwszGetCapFuncName = NULL;
84  return CryptSIPAddProvider(&prov) ? S_OK : S_FALSE;
85 }
WCHAR * pwszGetFuncName
Definition: mssip.h:152
WCHAR * pwszVerifyFuncName
Definition: mssip.h:155
WCHAR * pwszDLLFileName
Definition: mssip.h:147
static GUID mySubject
Definition: main.c:47
GUID * pgSubject
Definition: mssip.h:145
WCHAR * pwszPutFuncName
Definition: mssip.h:153
#define S_FALSE
Definition: winerror.h:2357
__wchar_t WCHAR
Definition: xmlstorage.h:180
BOOL WINAPI CryptSIPAddProvider(SIP_ADD_NEWPROVIDER *psNewProv)
Definition: sip.c:207
WCHAR * pwszIsFunctionNameFmt2
Definition: mssip.h:158
#define S_OK
Definition: intsafe.h:51
WCHAR * pwszGetCapFuncName
Definition: mssip.h:161
#define NULL
Definition: types.h:112
WCHAR * pwszRemoveFuncName
Definition: mssip.h:156
#define memset(x, y, z)
Definition: compat.h:39
WCHAR * pwszCreateFuncName
Definition: mssip.h:154

◆ DllUnregisterServer()

HRESULT WINAPI DllUnregisterServer ( void  )

Definition at line 90 of file main.c.

91 {
93  return S_OK;
94 }
static GUID mySubject
Definition: main.c:47
BOOL WINAPI CryptSIPRemoveProvider(GUID *pgProv)
Definition: sip.c:112
#define S_OK
Definition: intsafe.h:51

◆ MsiSIPGetSignedDataMsg()

BOOL WINAPI MsiSIPGetSignedDataMsg ( SIP_SUBJECTINFO pSubjectInfo,
DWORD pdwEncodingType,
DWORD  dwIndex,
DWORD pcbSignedDataMsg,
BYTE pbSignedDataMsg 
)

Definition at line 99 of file main.c.

102 {
103  static const WCHAR digitalSig[] = { 5,'D','i','g','i','t','a','l',
104  'S','i','g','n','a','t','u','r','e',0 };
105  BOOL ret = FALSE;
106  IStorage *stg = NULL;
107  HRESULT r;
108  IStream *stm = NULL;
109  BYTE hdr[2], len[sizeof(DWORD)];
110  DWORD count, lenBytes, dataBytes;
111 
112  TRACE("(%p %p %d %p %p)\n", pSubjectInfo, pdwEncodingType, dwIndex,
113  pcbSignedDataMsg, pbSignedDataMsg);
114 
115  r = StgOpenStorage(pSubjectInfo->pwsFileName, NULL,
117  if (FAILED(r))
118  {
119  TRACE("couldn't open %s\n", debugstr_w(pSubjectInfo->pwsFileName));
120  goto end;
121  }
122 
123  r = IStorage_OpenStream(stg, digitalSig, 0,
125  if (FAILED(r))
126  {
127  TRACE("couldn't find digital signature stream\n");
128  goto freestorage;
129  }
130 
131  r = IStream_Read(stm, hdr, sizeof(hdr), &count);
132  if (FAILED(r) || count != sizeof(hdr))
133  goto freestream;
134  if (hdr[0] != 0x30)
135  {
136  WARN("unexpected data in digital sig: 0x%02x%02x\n", hdr[0], hdr[1]);
137  goto freestream;
138  }
139 
140  /* Read the asn.1 length from the stream. Only supports definite-length
141  * values, which DER-encoded signatures should be.
142  */
143  if (hdr[1] == 0x80)
144  {
145  WARN("indefinite-length encoding not supported!\n");
146  goto freestream;
147  }
148  else if (hdr[1] & 0x80)
149  {
150  DWORD temp;
151  LPBYTE ptr;
152 
153  lenBytes = hdr[1] & 0x7f;
154  if (lenBytes > sizeof(DWORD))
155  {
156  WARN("asn.1 length too long (%d)\n", lenBytes);
157  goto freestream;
158  }
159  r = IStream_Read(stm, len, lenBytes, &count);
160  if (FAILED(r) || count != lenBytes)
161  goto freestream;
162  dataBytes = 0;
163  temp = lenBytes;
164  ptr = len;
165  while (temp--)
166  {
167  dataBytes <<= 8;
168  dataBytes |= *ptr++;
169  }
170  }
171  else
172  {
173  lenBytes = 0;
174  dataBytes = hdr[1];
175  }
176 
177  if (!pbSignedDataMsg)
178  {
179  *pcbSignedDataMsg = 2 + lenBytes + dataBytes;
180  ret = TRUE;
181  }
182  else if (*pcbSignedDataMsg < 2 + lenBytes + dataBytes)
183  {
185  *pcbSignedDataMsg = 2 + lenBytes + dataBytes;
186  }
187  else
188  {
189  LPBYTE ptr = pbSignedDataMsg;
190 
191  memcpy(ptr, hdr, sizeof(hdr));
192  ptr += sizeof(hdr);
193  if (lenBytes)
194  {
195  memcpy(ptr, len, lenBytes);
196  ptr += lenBytes;
197  }
198  r = IStream_Read(stm, ptr, dataBytes, &count);
199  if (SUCCEEDED(r) && count == dataBytes)
200  {
201  *pdwEncodingType = X509_ASN_ENCODING | PKCS_7_ASN_ENCODING;
202  *pcbSignedDataMsg = 2 + lenBytes + dataBytes;
203  ret = TRUE;
204  }
205  }
206 
207 freestream:
208  IStream_Release(stm);
209 freestorage:
210  IStorage_Release(stg);
211 end:
212 
213  TRACE("returning %d\n", ret);
214  return ret;
215 }
char hdr[14]
Definition: iptest.cpp:33
#define STGM_SHARE_EXCLUSIVE
Definition: objbase.h:922
#define TRUE
Definition: types.h:120
GLdouble GLdouble GLdouble r
Definition: gl.h:2055
GLuint GLuint GLsizei count
Definition: gl.h:1545
#define WARN(fmt,...)
Definition: debug.h:112
#define PKCS_7_ASN_ENCODING
Definition: wincrypt.h:2299
#define DWORD
Definition: nt_native.h:44
#define X509_ASN_ENCODING
Definition: wincrypt.h:2297
unsigned char * LPBYTE
Definition: typedefs.h:53
#define FALSE
Definition: types.h:117
unsigned int BOOL
Definition: ntddk_ex.h:94
if SUCCEEDED(hr)
#define debugstr_w
Definition: kernel32.h:32
static PVOID ptr
Definition: dispmode.c:27
#define STGM_READ
Definition: objbase.h:916
#define TRACE(s)
Definition: solgame.cpp:4
__wchar_t WCHAR
Definition: xmlstorage.h:180
LONG HRESULT
Definition: typedefs.h:79
HRESULT WINAPI StgOpenStorage(const OLECHAR *pwcsName, IStorage *pstgPriority, DWORD grfMode, SNB snbExclude, DWORD reserved, IStorage **ppstgOpen)
Definition: storage32.c:8755
#define STGM_DIRECT
Definition: objbase.h:913
unsigned long DWORD
Definition: ntddk_ex.h:95
#define SetLastError(x)
Definition: compat.h:611
GLuint GLuint end
Definition: gl.h:1545
int ret
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
GLenum GLsizei len
Definition: glext.h:6722
unsigned char BYTE
Definition: xxhash.c:193
static calc_node_t temp
Definition: rpn_ieee.c:38
#define NULL
Definition: types.h:112
#define STGM_SHARE_DENY_WRITE
Definition: objbase.h:921
LPCWSTR pwsFileName
Definition: mssip.h:54
#define ERROR_INSUFFICIENT_BUFFER
Definition: dderror.h:10

◆ MsiSIPIsMyTypeOfFile()

BOOL WINAPI MsiSIPIsMyTypeOfFile ( WCHAR name,
GUID subject 
)

Definition at line 224 of file main.c.

225 {
226  BOOL ret = FALSE;
227  IStorage *stg = NULL;
228  HRESULT r;
229 
230  TRACE("(%s, %p)\n", debugstr_w(name), subject);
231 
233  NULL, 0, &stg);
234  if (SUCCEEDED(r))
235  {
236  STATSTG stat;
237 
238  r = IStorage_Stat(stg, &stat, STATFLAG_NONAME);
239  if (SUCCEEDED(r))
240  {
241  if (IsEqualGUID(&stat.clsid, &CLSID_MsiDatabase) ||
242  IsEqualGUID(&stat.clsid, &CLSID_MsiPatch) ||
243  IsEqualGUID(&stat.clsid, &CLSID_MsiTransform))
244  {
245  ret = TRUE;
246  *subject = mySubject;
247  }
248  }
249  IStorage_Release(stg);
250  }
251  return ret;
252 }
#define TRUE
Definition: types.h:120
GLdouble GLdouble GLdouble r
Definition: gl.h:2055
static GUID mySubject
Definition: main.c:47
#define FALSE
Definition: types.h:117
unsigned int BOOL
Definition: ntddk_ex.h:94
if SUCCEEDED(hr)
#define debugstr_w
Definition: kernel32.h:32
#define STGM_READ
Definition: objbase.h:916
#define TRACE(s)
Definition: solgame.cpp:4
LONG HRESULT
Definition: typedefs.h:79
HRESULT WINAPI StgOpenStorage(const OLECHAR *pwcsName, IStorage *pstgPriority, DWORD grfMode, SNB snbExclude, DWORD reserved, IStorage **ppstgOpen)
Definition: storage32.c:8755
#define STGM_DIRECT
Definition: objbase.h:913
int ret
Definition: stat.h:55
_CRTIMP int __cdecl stat(const char *_Filename, struct stat *_Stat)
Definition: stat.h:345
#define NULL
Definition: types.h:112
BOOL WINAPI IsEqualGUID(REFGUID rguid1, REFGUID rguid2)
Definition: compobj.c:4112
Definition: name.c:38
#define STGM_SHARE_DENY_WRITE
Definition: objbase.h:921

◆ WINE_DEFAULT_DEBUG_CHANNEL()

WINE_DEFAULT_DEBUG_CHANNEL ( msisip  )

Variable Documentation

◆ mySubject

GUID mySubject
static
Initial value:
= { 0x000c10f1, 0x0000, 0x0000,
{ 0xc0,0x00,0x00,0x00,0x00,0x00,0x00,0x46 }}

Definition at line 47 of file main.c.

Referenced by DllRegisterServer(), DllUnregisterServer(), and MsiSIPIsMyTypeOfFile().