1 /*
2  * Subject Interface Package tests
3  *
4  * Copyright 2006 Paul Vriens
5  * Copyright 2008 Juan Lang
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public
9  * License as published by the Free Software Foundation; either
10  * version 2.1 of the License, or (at your option) any later version.
11  *
12  * This library is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with this library; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
20  */
21 
22 #include <stdio.h>
23 #include <stdarg.h>
24 #include <windef.h>
25 #include <winbase.h>
26 #include <winerror.h>
27 #include <winnls.h>
28 #include <wincrypt.h>
29 #include <mssip.h>
30 
31 #include "wine/test.h"
32 
33 static BOOL (WINAPI * funcCryptSIPGetSignedDataMsg)(SIP_SUBJECTINFO *,DWORD *,DWORD,DWORD *,BYTE *);
34 static BOOL (WINAPI * funcCryptSIPPutSignedDataMsg)(SIP_SUBJECTINFO *,DWORD,DWORD *,DWORD,BYTE *);
35 static BOOL (WINAPI * funcCryptSIPCreateIndirectData)(SIP_SUBJECTINFO *,DWORD *,SIP_INDIRECT_DATA *);
36 static BOOL (WINAPI * funcCryptSIPVerifyIndirectData)(SIP_SUBJECTINFO *,SIP_INDIRECT_DATA *);
37 static BOOL (WINAPI * funcCryptSIPRemoveSignedDataMsg)(SIP_SUBJECTINFO *,DWORD);
38 
39 static void test_AddRemoveProvider(void)
40 {
41     BOOL ret;
42     SIP_ADD_NEWPROVIDER newprov;
43     GUID actionid = { 0xdeadbe, 0xefde, 0xadbe, { 0xef,0xde,0xad,0xbe,0xef,0xde,0xad,0xbe }};
44     static WCHAR dummydll[]      = {'d','e','a','d','b','e','e','f','.','d','l','l',0 };
45     static WCHAR dummyfunction[] = {'d','u','m','m','y','f','u','n','c','t','i','o','n',0 };
46 
47     /* NULL check */
48     SetLastError(0xdeadbeef);
49     ret = CryptSIPRemoveProvider(NULL);
50     ok (!ret, "Expected CryptSIPRemoveProvider to fail.\n");
51     ok (GetLastError() == ERROR_INVALID_PARAMETER,
52         "Expected ERROR_INVALID_PARAMETER, got %d.\n", GetLastError());
53 
54     /* nonexistent provider should result in a registry error */
55     SetLastError(0xdeadbeef);
56     ret = CryptSIPRemoveProvider(&actionid);
57     if (!ret && GetLastError() == ERROR_ACCESS_DENIED)
58     {
59         /* Apparently the needed rights are checked before the existence of the provider */
60         skip("Need admin rights\n");
61     }
62     else
63     {
64         /* On some Win98 systems, CryptSIPRemoveProvider always succeeds if
65          * the arguments are correct, whether or not the registry key is
66          * present, so don't test ret, just check the last error if it does
67          * return FALSE.
68          */
69         if (!ret)
70             ok (GetLastError() == ERROR_FILE_NOT_FOUND,
71                 "Expected ERROR_FILE_NOT_FOUND, got %d.\n", GetLastError());
72     }
73 
74     /* Everything OK, pwszIsFunctionName and pwszIsFunctionNameFmt2 are left NULL
75      * as allowed */
76 
77     memset(&newprov, 0, sizeof(SIP_ADD_NEWPROVIDER));
78     newprov.cbStruct = sizeof(SIP_ADD_NEWPROVIDER);
79     newprov.pgSubject = &actionid;
80     newprov.pwszDLLFileName = dummydll;
81     newprov.pwszGetFuncName = dummyfunction;
82     newprov.pwszPutFuncName = dummyfunction;
83     newprov.pwszCreateFuncName = dummyfunction;
84     newprov.pwszVerifyFuncName = dummyfunction;
85     newprov.pwszRemoveFuncName = dummyfunction;
86     SetLastError(0xdeadbeef);
87     ret = CryptSIPAddProvider(&newprov);
88     if (!ret && GetLastError() == ERROR_ACCESS_DENIED)
89     {
90         skip("Need admin rights\n");
91         return;
92     }
93     ok ( ret, "CryptSIPAddProvider should have succeeded, last error %d\n", GetLastError());
94 
95     /* Dummy provider will be deleted, but the function still fails because
96      * pwszIsFunctionName and pwszIsFunctionNameFmt2 are not present in the
97      * registry.
98      */
99     SetLastError(0xdeadbeef);
100     ret = CryptSIPRemoveProvider(&actionid);
101     /* On some Win98 systems, CryptSIPRemoveProvider always succeeds if
102      * the arguments are correct, whether or not the registry key is
103      * present, so don't test ret, just check the last error if it does
104      * return FALSE.
105      */
106     if (!ret)
107         ok (GetLastError() == ERROR_FILE_NOT_FOUND,
108             "Expected ERROR_FILE_NOT_FOUND, got %d.\n", GetLastError());
109 
110     /* Everything OK */
111     memset(&newprov, 0, sizeof(SIP_ADD_NEWPROVIDER));
112     newprov.cbStruct = sizeof(SIP_ADD_NEWPROVIDER);
113     newprov.pgSubject = &actionid;
114     newprov.pwszDLLFileName = dummydll;
115     newprov.pwszGetFuncName = dummyfunction;
116     newprov.pwszPutFuncName = dummyfunction;
117     newprov.pwszCreateFuncName = dummyfunction;
118     newprov.pwszVerifyFuncName = dummyfunction;
119     newprov.pwszRemoveFuncName = dummyfunction;
120     newprov.pwszIsFunctionNameFmt2 = dummyfunction;
121     newprov.pwszIsFunctionName = dummyfunction;
122     /* If GetCapFuncName set to NULL, then CryptSIPRemoveProvider fails on win 8 */
123     newprov.pwszGetCapFuncName = dummyfunction;
124 
125     SetLastError(0xdeadbeef);
126     ret = CryptSIPAddProvider(&newprov);
127     ok ( ret, "CryptSIPAddProvider should have succeeded, last error %d\n", GetLastError());
128 
129     /* Dummy provider should be deleted */
130     SetLastError(0xdeadbeef);
131     ret = CryptSIPRemoveProvider(&actionid);
132     ok ( ret, "CryptSIPRemoveProvider should have succeeded, last error %d\n", GetLastError());
133 }
134 
135 static const BYTE cabFileData[] = {
136 0x4d,0x53,0x43,0x46,0x00,0x00,0x00,0x00,0x50,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
137 0x2c,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0x01,0x01,0x00,0x01,0x00,0x00,0x00,
138 0xef,0xbe,0xff,0xff,0x42,0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x06,0x00,0x00,0x00,
139 0x00,0x00,0x00,0x00,0x00,0x00,0xf7,0x38,0x4b,0xac,0x00,0x00,0x61,0x2e,0x74,0x78,
140 0x74,0x00,0x6d,0x5a,0x72,0x78,0x06,0x00,0x06,0x00,0x61,0x2e,0x74,0x78,0x74,0x0a,
141 };
142 
143 static void test_SIPRetrieveSubjectGUID(void)
144 {
145     BOOL ret;
146     GUID subject;
147     HANDLE file;
148     static const CHAR windir[] = "windir";
149     static const CHAR regeditExe[] = "regedit.exe";
150     static const GUID nullSubject  = { 0x0, 0x0, 0x0, { 0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0 }};
151     static const WCHAR deadbeef[]  = { 'c',':','\\','d','e','a','d','b','e','e','f','.','d','b','f',0 };
152     /* Couldn't find a name for this GUID, it's the one used for 95% of the files */
153     static const GUID unknownGUID = { 0xC689AAB8, 0x8E78, 0x11D0, { 0x8C,0x47,0x00,0xC0,0x4F,0xC2,0x95,0xEE }};
154     static const GUID cabGUID = { 0xc689aaba, 0x8e78, 0x11d0, {0x8c,0x47,0x00,0xc0,0x4f,0xc2,0x95,0xee }};
155     static CHAR  regeditPath[MAX_PATH];
156     static WCHAR regeditPathW[MAX_PATH];
157     static CHAR path[MAX_PATH];
158     static CHAR tempfile[MAX_PATH];
159     static WCHAR tempfileW[MAX_PATH];
160     DWORD written;
161 
162     /* NULL check */
163     SetLastError(0xdeadbeef);
164     ret = CryptSIPRetrieveSubjectGuid(NULL, NULL, NULL);
165     ok ( !ret, "Expected CryptSIPRetrieveSubjectGuid to fail\n");
166     ok (GetLastError() == ERROR_INVALID_PARAMETER,
167         "Expected ERROR_INVALID_PARAMETER, got %d.\n", GetLastError());
168 
169     /* Test with a nonexistent file (hopefully) */
170     SetLastError(0xdeadbeef);
171     /* Set subject to something other than zeros */
172     memset(&subject, 1, sizeof(GUID));
173     ret = CryptSIPRetrieveSubjectGuid(deadbeef, NULL, &subject);
174     ok ( !ret, "Expected CryptSIPRetrieveSubjectGuid to fail\n");
175     ok (GetLastError() == ERROR_FILE_NOT_FOUND ||
176         GetLastError() == ERROR_PATH_NOT_FOUND,
177         "Expected ERROR_FILE_NOT_FOUND or ERROR_PATH_NOT_FOUND, got %d.\n",
178         GetLastError());
179     ok(IsEqualGUID(&subject, &nullSubject),
180        "Expected a NULL GUID for c:\\deadbeef.dbf, not %s\n", wine_dbgstr_guid(&subject));
181 
182     /* Now with an executable that should exist
183      *
184      * Use A-functions where possible as that should be available on all platforms
185      */
186     ret = GetEnvironmentVariableA(windir, regeditPath, MAX_PATH);
187     ok (ret > 0, "expected GEVA(windir) to succeed, last error %d\n", GetLastError());
188     strcat(regeditPath, "\\");
189     strcat(regeditPath, regeditExe);
190     MultiByteToWideChar( CP_ACP, 0, regeditPath,
191                          strlen(regeditPath)+1, regeditPathW,
192                          sizeof(regeditPathW)/sizeof(regeditPathW[0]) );
193 
194     SetLastError(0xdeadbeef);
195     memset(&subject, 1, sizeof(GUID));
196     ret = CryptSIPRetrieveSubjectGuid(regeditPathW, NULL, &subject);
197     ok ( ret, "Expected CryptSIPRetrieveSubjectGuid to succeed\n");
198     ok(IsEqualGUID(&subject, &unknownGUID),
199        "Expected (%s), got (%s).\n", wine_dbgstr_guid(&unknownGUID), wine_dbgstr_guid(&subject));
200 
201     /* The same thing but now with a handle instead of a filename */
202     file = CreateFileA(regeditPath, GENERIC_READ, 0, NULL, OPEN_EXISTING, 0, NULL);
203     SetLastError(0xdeadbeef);
204     memset(&subject, 1, sizeof(GUID));
205     ret = CryptSIPRetrieveSubjectGuid(NULL, file, &subject);
206     ok ( ret, "Expected CryptSIPRetrieveSubjectGuid to succeed\n");
207     ok(IsEqualGUID(&subject, &unknownGUID),
208        "Expected (%s), got (%s).\n", wine_dbgstr_guid(&unknownGUID), wine_dbgstr_guid(&subject));
209     CloseHandle(file);
210 
211     /* And both */
212     file = CreateFileA(regeditPath, GENERIC_READ, 0, NULL, OPEN_EXISTING, 0, NULL);
213     SetLastError(0xdeadbeef);
214     memset(&subject, 1, sizeof(GUID));
215     ret = CryptSIPRetrieveSubjectGuid(regeditPathW, file, &subject);
216     ok ( ret, "Expected CryptSIPRetrieveSubjectGuid to succeed\n");
217     ok(IsEqualGUID(&subject, &unknownGUID),
218        "Expected (%s), got (%s).\n", wine_dbgstr_guid(&unknownGUID), wine_dbgstr_guid(&subject));
219     CloseHandle(file);
220 
221     /* Now with an empty file */
222     GetTempPathA(sizeof(path), path);
223     GetTempFileNameA(path, "sip", 0 , tempfile);
224     MultiByteToWideChar( CP_ACP, 0, tempfile,
225                          strlen(tempfile)+1, tempfileW,
226                          sizeof(tempfileW)/sizeof(tempfileW[0]) );
227 
228     SetLastError(0xdeadbeef);
229     memset(&subject, 1, sizeof(GUID));
230     ret = CryptSIPRetrieveSubjectGuid(tempfileW, NULL, &subject);
231     ok ( !ret, "Expected CryptSIPRetrieveSubjectGuid to fail\n");
232     ok ( GetLastError() == ERROR_FILE_INVALID ||
233          GetLastError() == ERROR_INVALID_PARAMETER /* Vista */ ||
234          GetLastError() == ERROR_SUCCESS /* most Win98 */ ||
235          GetLastError() == TRUST_E_SUBJECT_FORM_UNKNOWN /* some Win98 */,
236         "Expected ERROR_FILE_INVALID, ERROR_INVALID_PARAMETER, ERROR_SUCCESS or TRUST_E_SUBJECT_FORM_UNKNOWN, got 0x%08x\n", GetLastError());
237     ok(IsEqualGUID(&subject, &nullSubject),
238        "Expected a NULL GUID for empty file %s, not %s\n", tempfile, wine_dbgstr_guid(&subject));
239 
240     /* Use a file with a size of 3 (at least < 4) */
241     file = CreateFileA(tempfile, GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL);
242     WriteFile(file, "123", 3, &written, NULL);
243     CloseHandle(file);
244 
245     SetLastError(0xdeadbeef);
246     memset(&subject, 1, sizeof(GUID));
247     ret = CryptSIPRetrieveSubjectGuid(tempfileW, NULL, &subject);
248     ok ( !ret, "Expected CryptSIPRetrieveSubjectGuid to fail\n");
249     ok ( GetLastError() == ERROR_INVALID_PARAMETER ||
250          GetLastError() == ERROR_SUCCESS /* most Win98 */ ||
251          GetLastError() == TRUST_E_SUBJECT_FORM_UNKNOWN /* some Win98 */,
252         "Expected ERROR_INVALID_PARAMETER, ERROR_SUCCESS or TRUST_E_SUBJECT_FORM_UNKNOWN, got 0x%08x\n", GetLastError());
253     ok(IsEqualGUID(&subject, &nullSubject),
254        "Expected a NULL GUID for empty file %s, not %s\n", tempfile, wine_dbgstr_guid(&subject));
255 
256     /* And now >= 4 */
257     file = CreateFileA(tempfile, GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL);
258     WriteFile(file, "1234", 4, &written, NULL);
259     CloseHandle(file);
260 
261     SetLastError(0xdeadbeef);
262     memset(&subject, 1, sizeof(GUID));
263     ret = CryptSIPRetrieveSubjectGuid(tempfileW, NULL, &subject);
264     ok ( !ret, "Expected CryptSIPRetrieveSubjectGuid to fail\n");
265     ok ( GetLastError() == TRUST_E_SUBJECT_FORM_UNKNOWN ||
266          GetLastError() == ERROR_SUCCESS /* Win98 */,
267         "Expected TRUST_E_SUBJECT_FORM_UNKNOWN or ERROR_SUCCESS, got 0x%08x\n", GetLastError());
268     ok(IsEqualGUID(&subject, &nullSubject),
269        "Expected a NULL GUID for empty file %s, not %s\n", tempfile, wine_dbgstr_guid(&subject));
270 
271     /* Clean up */
272     DeleteFileA(tempfile);
273 
274     /* Create a file with just the .cab header 'MSCF' */
275     SetLastError(0xdeadbeef);
276     file = CreateFileA(tempfile, GENERIC_WRITE, 0, NULL, CREATE_NEW, 0, NULL);
277     ok(file != INVALID_HANDLE_VALUE, "failed with %u\n", GetLastError());
278     WriteFile(file, cabFileData, 4, &written, NULL);
279     CloseHandle(file);
280 
281     SetLastError(0xdeadbeef);
282     memset(&subject, 1, sizeof(GUID));
283     ret = CryptSIPRetrieveSubjectGuid(tempfileW, NULL, &subject);
284     ok( ret, "CryptSIPRetrieveSubjectGuid failed: %d (0x%08x)\n",
285             GetLastError(), GetLastError() );
286     ok(IsEqualGUID(&subject, &cabGUID),
287        "Expected GUID %s for cabinet file, not %s\n", wine_dbgstr_guid(&cabGUID), wine_dbgstr_guid(&subject));
288 
289     /* Clean up */
290     DeleteFileA(tempfile);
291 
292     /* Create a .cab file */
293     SetLastError(0xdeadbeef);
294     file = CreateFileA(tempfile, GENERIC_WRITE, 0, NULL, CREATE_NEW, 0, NULL);
295     ok(file != INVALID_HANDLE_VALUE, "failed with %u\n", GetLastError());
296     WriteFile(file, cabFileData, sizeof(cabFileData), &written, NULL);
297     CloseHandle(file);
298 
299     SetLastError(0xdeadbeef);
300     memset(&subject, 1, sizeof(GUID));
301     ret = CryptSIPRetrieveSubjectGuid(tempfileW, NULL, &subject);
302     ok( ret, "CryptSIPRetrieveSubjectGuid failed: %d (0x%08x)\n",
303             GetLastError(), GetLastError() );
304     ok(IsEqualGUID(&subject, &cabGUID),
305        "Expected GUID %s for cabinet file, not %s\n", wine_dbgstr_guid(&cabGUID), wine_dbgstr_guid(&subject));
306 
307     /* Clean up */
308     DeleteFileA(tempfile);
309 }
310 
311 static void test_SIPLoad(void)
312 {
313     BOOL ret;
314     GUID subject;
315     static GUID dummySubject = { 0xdeadbeef, 0xdead, 0xbeef, { 0xde,0xad,0xbe,0xef,0xde,0xad,0xbe,0xef }};
316     static GUID unknown      = { 0xC689AABA, 0x8E78, 0x11D0, { 0x8C,0x47,0x00,0xC0,0x4F,0xC2,0x95,0xEE }}; /* WINTRUST.DLL */
317     static GUID unknown2     = { 0xDE351A43, 0x8E59, 0x11D0, { 0x8C,0x47,0x00,0xC0,0x4F,0xC2,0x95,0xEE }}; /* WINTRUST.DLL */
318     /* The next SIP is available on Windows and on Wine */
319     static GUID unknown3     = { 0x000C10F1, 0x0000, 0x0000, { 0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x46 }}; /* MSISIP.DLL */
320     SIP_DISPATCH_INFO sdi;
321     HMODULE hCrypt;
322 
323     /* All NULL */
324     SetLastError(0xdeadbeef);
325     ret = CryptSIPLoad(NULL, 0, NULL);
326     ok ( !ret, "Expected CryptSIPLoad to fail\n");
327     ok ( GetLastError() == ERROR_INVALID_PARAMETER,
328         "Expected ERROR_INVALID_PARAMETER, got 0x%08x\n", GetLastError());
329 
330     /* Only pSipDispatch NULL */
331     SetLastError(0xdeadbeef);
332     ret = CryptSIPLoad(&subject, 0, NULL);
333     ok ( !ret, "Expected CryptSIPLoad to fail\n");
334     ok ( GetLastError() == ERROR_INVALID_PARAMETER,
335         "Expected ERROR_INVALID_PARAMETER, got 0x%08x\n", GetLastError());
336 
337     /* No NULLs, but nonexistent pgSubject */
338     SetLastError(0xdeadbeef);
339     memset(&sdi, 0, sizeof(SIP_DISPATCH_INFO));
340     sdi.cbSize = sizeof(SIP_DISPATCH_INFO);
341     sdi.pfGet = (pCryptSIPGetSignedDataMsg)0xdeadbeef;
342     ret = CryptSIPLoad(&dummySubject, 0, &sdi);
343     ok ( !ret, "Expected CryptSIPLoad to fail\n");
344     ok ( GetLastError() == TRUST_E_SUBJECT_FORM_UNKNOWN,
345         "Expected TRUST_E_SUBJECT_FORM_UNKNOWN, got 0x%08x\n", GetLastError());
346     ok( sdi.pfGet == (pCryptSIPGetSignedDataMsg)0xdeadbeef, "Expected no change to the function pointer\n");
347 
348     hCrypt = GetModuleHandleA("crypt32.dll");
349     funcCryptSIPGetSignedDataMsg = (void*)GetProcAddress(hCrypt, "CryptSIPGetSignedDataMsg");
350     funcCryptSIPPutSignedDataMsg = (void*)GetProcAddress(hCrypt, "CryptSIPPutSignedDataMsg");
351     funcCryptSIPCreateIndirectData = (void*)GetProcAddress(hCrypt, "CryptSIPCreateIndirectData");
352     funcCryptSIPVerifyIndirectData = (void*)GetProcAddress(hCrypt, "CryptSIPVerifyIndirectData");
353     funcCryptSIPRemoveSignedDataMsg = (void*)GetProcAddress(hCrypt, "CryptSIPRemoveSignedDataMsg");
354 
355     /* All OK */
356     SetLastError(0xdeadbeef);
357     memset(&sdi, 0, sizeof(SIP_DISPATCH_INFO));
358     sdi.cbSize = sizeof(SIP_DISPATCH_INFO);
359     sdi.pfGet = (pCryptSIPGetSignedDataMsg)0xdeadbeef;
360     ret = CryptSIPLoad(&unknown, 0, &sdi);
361     ok ( ret, "Expected CryptSIPLoad to succeed\n");
362     /* On native the last error will always be ERROR_PROC_NOT_FOUND as native searches for the function DllCanUnloadNow
363      * in WINTRUST.DLL (in this case). This function is not available in WINTRUST.DLL.
364      * For now there's no need to implement this is Wine as I doubt any program will rely on
365      * this last error when the call succeeded.
366      */
367     ok( sdi.pfGet != (pCryptSIPGetSignedDataMsg)0xdeadbeef, "Expected a function pointer to be loaded.\n");
368 
369     /* The function addresses returned by CryptSIPLoad are actually the addresses of
370      * crypt32's own functions. A function calling these addresses will end up first
371      * calling crypt32 functions which in its turn call the equivalent in the SIP
372      * as dictated by the given GUID.
373      */
374     if (funcCryptSIPGetSignedDataMsg && funcCryptSIPPutSignedDataMsg && funcCryptSIPCreateIndirectData &&
375         funcCryptSIPVerifyIndirectData && funcCryptSIPRemoveSignedDataMsg)
376         ok (sdi.pfGet == funcCryptSIPGetSignedDataMsg &&
377             sdi.pfPut == funcCryptSIPPutSignedDataMsg &&
378             sdi.pfCreate == funcCryptSIPCreateIndirectData &&
379             sdi.pfVerify == funcCryptSIPVerifyIndirectData &&
380             sdi.pfRemove == funcCryptSIPRemoveSignedDataMsg,
381             "Expected function addresses to be from crypt32\n");
382     else
383         trace("Couldn't load function pointers\n");
384 
385     /* All OK, but different GUID (same SIP though) */
386     SetLastError(0xdeadbeef);
387     memset(&sdi, 0, sizeof(SIP_DISPATCH_INFO));
388     sdi.cbSize = sizeof(SIP_DISPATCH_INFO);
389     sdi.pfGet = (pCryptSIPGetSignedDataMsg)0xdeadbeef;
390     ret = CryptSIPLoad(&unknown2, 0, &sdi);
391     ok ( ret, "Expected CryptSIPLoad to succeed\n");
392     /* This call on its own would have resulted in an ERROR_PROC_NOT_FOUND, but the previous
393      * call to CryptSIPLoad already loaded wintrust.dll. As this information is cached,
394      * CryptSIPLoad will not try to search for the already mentioned DllCanUnloadNow.
395      */
396     ok( sdi.pfGet != (pCryptSIPGetSignedDataMsg)0xdeadbeef, "Expected a function pointer to be loaded.\n");
397 
398     /* All OK, but other SIP */
399     SetLastError(0xdeadbeef);
400     memset(&sdi, 0, sizeof(SIP_DISPATCH_INFO));
401     sdi.cbSize = sizeof(SIP_DISPATCH_INFO);
402     sdi.pfGet = (pCryptSIPGetSignedDataMsg)0xdeadbeef;
403     ret = CryptSIPLoad(&unknown3, 0, &sdi);
404     if (ret)
405     {
406         /* The SIP is known so we can safely assume that the next tests can be done */
407 
408         /* As msisip.dll is not checked yet by any of the previous calls, the
409          * function DllCanUnloadNow will be checked again in msisip.dll (it's not present)
410          */
411         ok( sdi.pfGet != (pCryptSIPGetSignedDataMsg)0xdeadbeef, "Expected a function pointer to be loaded.\n");
412 
413         /* This is another SIP but this test proves the function addresses are the same as
414          * in the previous test.
415          */
416         if (funcCryptSIPGetSignedDataMsg && funcCryptSIPPutSignedDataMsg && funcCryptSIPCreateIndirectData &&
417             funcCryptSIPVerifyIndirectData && funcCryptSIPRemoveSignedDataMsg)
418             ok (sdi.pfGet == funcCryptSIPGetSignedDataMsg &&
419                 sdi.pfPut == funcCryptSIPPutSignedDataMsg &&
420                 sdi.pfCreate == funcCryptSIPCreateIndirectData &&
421                 sdi.pfVerify == funcCryptSIPVerifyIndirectData &&
422                 sdi.pfRemove == funcCryptSIPRemoveSignedDataMsg,
423                 "Expected function addresses to be from crypt32\n");
424         else
425             trace("Couldn't load function pointers\n");
426     }
427 
428     /* Reserved parameter not 0 */
429     SetLastError(0xdeadbeef);
430     memset(&sdi, 0, sizeof(SIP_DISPATCH_INFO));
431     sdi.cbSize = sizeof(SIP_DISPATCH_INFO);
432     sdi.pfGet = (pCryptSIPGetSignedDataMsg)0xdeadbeef;
433     ret = CryptSIPLoad(&unknown, 1, &sdi);
434     ok ( !ret, "Expected CryptSIPLoad to fail\n");
435     ok ( GetLastError() == ERROR_INVALID_PARAMETER,
436         "Expected ERROR_INVALID_PARAMETER, got 0x%08x\n", GetLastError());
437     ok( sdi.pfGet == (pCryptSIPGetSignedDataMsg)0xdeadbeef, "Expected no change to the function pointer\n");
438 }
439 
440 START_TEST(sip)
441 {
442     test_AddRemoveProvider();
443     /* It seems that the caching for loaded dlls is shared between CryptSIPRetrieveSubjectGUID
444      * and CryptSIPLoad. The tests have to be in this order to succeed. This is because in the last
445      * test for CryptSIPRetrieveSubjectGUID, several SIPs will be loaded (on Windows).
446      */
447     test_SIPLoad();
448     test_SIPRetrieveSubjectGUID();
449 }
450