2 * Subject Interface Package tests
4 * Copyright 2006 Paul Vriens
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.
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.
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
30 #include "wine/test.h"
32 static char *show_guid(const GUID *guid)
34 static char guidstring[39];
37 "{%08lx-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x}",
38 guid->Data1, guid->Data2, guid->Data3,
39 guid->Data4[0], guid->Data4[1], guid->Data4[2], guid->Data4[3],
40 guid->Data4[4], guid->Data4[5], guid->Data4[6], guid->Data4[7] );
45 static void test_AddRemoveProvider(void)
48 SIP_ADD_NEWPROVIDER newprov;
49 GUID actionid = { 0xdeadbe, 0xefde, 0xadbe, { 0xef,0xde,0xad,0xbe,0xef,0xde,0xad,0xbe }};
50 static WCHAR dummydll[] = {'d','e','a','d','b','e','e','f','.','d','l','l',0 };
51 static WCHAR dummyfunction[] = {'d','u','m','m','y','f','u','n','c','t','i','o','n',0 };
54 SetLastError(0xdeadbeef);
55 ret = CryptSIPRemoveProvider(NULL);
56 ok (!ret, "Expected CryptSIPRemoveProvider to fail.\n");
57 ok (GetLastError() == ERROR_INVALID_PARAMETER,
58 "Expected ERROR_INVALID_PARAMETER, got %ld.\n", GetLastError());
60 /* nonexistent provider should result in a registry error */
61 SetLastError(0xdeadbeef);
62 ret = CryptSIPRemoveProvider(&actionid);
63 ok (!ret, "Expected CryptSIPRemoveProvider to fail.\n");
64 ok (GetLastError() == ERROR_FILE_NOT_FOUND,
65 "Expected ERROR_FILE_NOT_FOUND, got %ld.\n", GetLastError());
67 /* Everything OK, pwszIsFunctionName and pwszIsFunctionNameFmt2 are left NULL
70 memset(&newprov, 0, sizeof(SIP_ADD_NEWPROVIDER));
71 newprov.cbStruct = sizeof(SIP_ADD_NEWPROVIDER);
72 newprov.pgSubject = &actionid;
73 newprov.pwszDLLFileName = dummydll;
74 newprov.pwszGetFuncName = dummyfunction;
75 newprov.pwszPutFuncName = dummyfunction;
76 newprov.pwszCreateFuncName = dummyfunction;
77 newprov.pwszVerifyFuncName = dummyfunction;
78 newprov.pwszRemoveFuncName = dummyfunction;
79 SetLastError(0xdeadbeef);
80 ret = CryptSIPAddProvider(&newprov);
81 ok ( ret, "CryptSIPAddProvider should have succeeded\n");
82 ok ( GetLastError() == 0xdeadbeef, "Expected 0xdeadbeef, got %ld\n",
85 /* Dummy provider will be deleted, but the function still fails because
86 * pwszIsFunctionName and pwszIsFunctionNameFmt2 are not present in the
89 SetLastError(0xdeadbeef);
90 ret = CryptSIPRemoveProvider(&actionid);
91 ok (!ret, "Expected CryptSIPRemoveProvider to fail.\n");
92 ok (GetLastError() == ERROR_FILE_NOT_FOUND,
93 "Expected ERROR_FILE_NOT_FOUND, got %ld.\n", GetLastError());
96 memset(&newprov, 0, sizeof(SIP_ADD_NEWPROVIDER));
97 newprov.cbStruct = sizeof(SIP_ADD_NEWPROVIDER);
98 newprov.pgSubject = &actionid;
99 newprov.pwszDLLFileName = dummydll;
100 newprov.pwszGetFuncName = dummyfunction;
101 newprov.pwszPutFuncName = dummyfunction;
102 newprov.pwszCreateFuncName = dummyfunction;
103 newprov.pwszVerifyFuncName = dummyfunction;
104 newprov.pwszRemoveFuncName = dummyfunction;
105 newprov.pwszIsFunctionNameFmt2 = dummyfunction;
106 newprov.pwszIsFunctionName = dummyfunction;
107 SetLastError(0xdeadbeef);
108 ret = CryptSIPAddProvider(&newprov);
109 ok ( ret, "CryptSIPAddProvider should have succeeded\n");
110 ok ( GetLastError() == 0xdeadbeef, "Expected 0xdeadbeef, got %ld\n",
113 /* Dummy provider should be deleted */
114 SetLastError(0xdeadbeef);
115 ret = CryptSIPRemoveProvider(&actionid);
116 ok ( ret, "CryptSIPRemoveProvider should have succeeded\n");
117 ok ( GetLastError() == 0xdeadbeef, "Expected 0xdeadbeef, got %ld\n",
121 static void test_SIPRetrieveSubjectGUID(void)
126 static const CHAR windir[] = "windir";
127 static const CHAR regeditExe[] = "regedit.exe";
128 static const GUID nullSubject = { 0x0, 0x0, 0x0, { 0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0 }};
129 static const WCHAR deadbeef[] = { 'c',':','\\','d','e','a','d','b','e','e','f','.','d','b','f',0 };
130 /* Couldn't find a name for this GUID, it's the one used for 95% of the files */
131 static const GUID unknownGUID = { 0xC689AAB8, 0x8E78, 0x11D0, { 0x8C,0x47,0x00,0xC0,0x4F,0xC2,0x95,0xEE }};
132 static CHAR regeditPath[MAX_PATH];
133 static WCHAR regeditPathW[MAX_PATH];
134 static CHAR path[MAX_PATH];
135 static CHAR tempfile[MAX_PATH];
136 static WCHAR tempfileW[MAX_PATH];
140 SetLastError(0xdeadbeef);
141 ret = CryptSIPRetrieveSubjectGuid(NULL, NULL, NULL);
142 ok ( !ret, "Expected CryptSIPRetrieveSubjectGuid to fail\n");
144 ok (GetLastError() == ERROR_INVALID_PARAMETER,
145 "Expected ERROR_INVALID_PARAMETER, got %ld.\n", GetLastError());
147 /* Test with a non-existent file (hopefully) */
148 SetLastError(0xdeadbeef);
149 /* Set subject to something other than zero's */
150 memset(&subject, 1, sizeof(GUID));
151 ret = CryptSIPRetrieveSubjectGuid(deadbeef, NULL, &subject);
152 ok ( !ret, "Expected CryptSIPRetrieveSubjectGuid to fail\n");
155 ok (GetLastError() == ERROR_FILE_NOT_FOUND,
156 "Expected ERROR_FILE_NOT_FOUND, got %ld.\n", GetLastError());
157 ok ( !memcmp(&subject, &nullSubject, sizeof(GUID)),
158 "Expected a NULL GUID for c:\\deadbeef.dbf, not %s\n", show_guid(&subject));
161 /* Now with an executable that should exist
163 * Use A-functions where possible as that should be available on all platforms
165 GetEnvironmentVariableA(windir, regeditPath, MAX_PATH);
166 sprintf(regeditPath, "%s\\%s", regeditPath, regeditExe);
167 MultiByteToWideChar( CP_ACP, 0, regeditPath,
168 strlen(regeditPath)+1, regeditPathW,
169 sizeof(regeditPathW)/sizeof(regeditPathW[0]) );
171 SetLastError(0xdeadbeef);
172 memset(&subject, 1, sizeof(GUID));
173 ret = CryptSIPRetrieveSubjectGuid(regeditPathW, NULL, &subject);
176 ok ( ret, "Expected CryptSIPRetrieveSubjectGuid to succeed\n");
177 ok ( GetLastError() == ERROR_SUCCESS,
178 "Expected ERROR_SUCCESS, got 0x%08lx\n", GetLastError());
179 ok ( !memcmp(&subject, &unknownGUID, sizeof(GUID)),
180 "Expected (%s), got (%s).\n", show_guid(&unknownGUID), show_guid(&subject));
183 /* The same thing but now with a handle instead of a filename */
184 file = CreateFileA(regeditPath, GENERIC_READ, 0, NULL, OPEN_EXISTING, 0, NULL);
185 SetLastError(0xdeadbeef);
186 memset(&subject, 1, sizeof(GUID));
187 ret = CryptSIPRetrieveSubjectGuid(NULL, file, &subject);
190 ok ( ret, "Expected CryptSIPRetrieveSubjectGuid to succeed\n");
191 ok ( GetLastError() == ERROR_SUCCESS,
192 "Expected ERROR_SUCCESS, got 0x%08lx\n", GetLastError());
193 ok ( !memcmp(&subject, &unknownGUID, sizeof(GUID)),
194 "Expected (%s), got (%s).\n", show_guid(&unknownGUID), show_guid(&subject));
199 file = CreateFileA(regeditPath, GENERIC_READ, 0, NULL, OPEN_EXISTING, 0, NULL);
200 SetLastError(0xdeadbeef);
201 memset(&subject, 1, sizeof(GUID));
202 ret = CryptSIPRetrieveSubjectGuid(regeditPathW, file, &subject);
205 ok ( ret, "Expected CryptSIPRetrieveSubjectGuid to succeed\n");
206 ok ( GetLastError() == ERROR_SUCCESS,
207 "Expected ERROR_SUCCESS, got 0x%08lx\n", GetLastError());
208 ok ( !memcmp(&subject, &unknownGUID, sizeof(GUID)),
209 "Expected (%s), got (%s).\n", show_guid(&unknownGUID), show_guid(&subject));
213 /* Now with an empty file */
214 GetTempPathA(sizeof(path), path);
215 GetTempFileNameA(path, "sip", 0 , tempfile);
216 MultiByteToWideChar( CP_ACP, 0, tempfile,
217 strlen(tempfile)+1, tempfileW,
218 sizeof(tempfileW)/sizeof(tempfileW[0]) );
220 SetLastError(0xdeadbeef);
221 memset(&subject, 1, sizeof(GUID));
222 ret = CryptSIPRetrieveSubjectGuid(tempfileW, NULL, &subject);
223 ok ( !ret, "Expected CryptSIPRetrieveSubjectGuid to fail\n");
226 ok ( GetLastError() == ERROR_FILE_INVALID ||
227 GetLastError() == S_OK /* Win98 */,
228 "Expected ERROR_FILE_INVALID or S_OK, got 0x%08lx\n", GetLastError());
229 ok ( !memcmp(&subject, &nullSubject, sizeof(GUID)),
230 "Expected a NULL GUID for empty file %s, not %s\n", tempfile, show_guid(&subject));
233 /* Use a file with a size of 3 (at least < 4) */
234 file = CreateFileA(tempfile, GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL);
235 WriteFile(file, "123", 3, &written, NULL);
238 SetLastError(0xdeadbeef);
239 memset(&subject, 1, sizeof(GUID));
240 ret = CryptSIPRetrieveSubjectGuid(tempfileW, NULL, &subject);
241 ok ( !ret, "Expected CryptSIPRetrieveSubjectGuid to fail\n");
244 ok ( GetLastError() == ERROR_INVALID_PARAMETER ||
245 GetLastError() == S_OK /* Win98 */,
246 "Expected ERROR_INVALID_PARAMETER or S_OK, got 0x%08lx\n", GetLastError());
247 ok ( !memcmp(&subject, &nullSubject, sizeof(GUID)),
248 "Expected a NULL GUID for empty file %s, not %s\n", tempfile, show_guid(&subject));
252 file = CreateFileA(tempfile, GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL);
253 WriteFile(file, "1234", 4, &written, NULL);
256 SetLastError(0xdeadbeef);
257 memset(&subject, 1, sizeof(GUID));
258 ret = CryptSIPRetrieveSubjectGuid(tempfileW, NULL, &subject);
259 ok ( !ret, "Expected CryptSIPRetrieveSubjectGuid to fail\n");
262 ok ( GetLastError() == TRUST_E_SUBJECT_FORM_UNKNOWN ||
263 GetLastError() == S_OK /* Win98 */,
264 "Expected TRUST_E_SUBJECT_FORM_UNKNOWN or S_OK, got 0x%08lx\n", GetLastError());
265 ok ( !memcmp(&subject, &nullSubject, sizeof(GUID)),
266 "Expected a NULL GUID for empty file %s, not %s\n", tempfile, show_guid(&subject));
270 DeleteFileA(tempfile);
273 static void test_SIPLoad(void)
277 static GUID dummySubject = { 0xdeadbeef, 0xdead, 0xbeef, { 0xde,0xad,0xbe,0xef,0xde,0xad,0xbe,0xef }};
278 static GUID unknown = { 0xC689AABA, 0x8E78, 0x11D0, { 0x8C,0x47,0x00,0xC0,0x4F,0xC2,0x95,0xEE }};
279 SIP_DISPATCH_INFO sdi;
282 SetLastError(0xdeadbeef);
283 ret = CryptSIPLoad(NULL, 0, NULL);
284 ok ( !ret, "Expected CryptSIPLoad to fail\n");
286 ok ( GetLastError() == ERROR_INVALID_PARAMETER,
287 "Expected ERROR_INVALID_PARAMETER, got 0x%08lx\n", GetLastError());
289 /* Only pSipDispatch NULL */
290 SetLastError(0xdeadbeef);
291 ret = CryptSIPLoad(&subject, 0, NULL);
292 ok ( !ret, "Expected CryptSIPLoad to fail\n");
294 ok ( GetLastError() == ERROR_INVALID_PARAMETER,
295 "Expected ERROR_INVALID_PARAMETER, got 0x%08lx\n", GetLastError());
297 /* No NULLs, but nonexistent pgSubject */
298 SetLastError(0xdeadbeef);
299 memset(&sdi, 0, sizeof(SIP_DISPATCH_INFO));
300 sdi.cbSize = sizeof(SIP_DISPATCH_INFO);
301 ret = CryptSIPLoad(&dummySubject, 0, &sdi);
302 ok ( !ret, "Expected CryptSIPLoad to fail\n");
304 ok ( GetLastError() == TRUST_E_SUBJECT_FORM_UNKNOWN,
305 "Expected TRUST_E_SUBJECT_FORM_UNKNOWN, got 0x%08lx\n", GetLastError());
307 /* cbSize not initialized */
308 SetLastError(0xdeadbeef);
309 memset(&sdi, 0, sizeof(SIP_DISPATCH_INFO));
310 ret = CryptSIPLoad(&dummySubject, 0, &sdi);
311 ok ( !ret, "Expected CryptSIPLoad to fail\n");
313 ok ( GetLastError() == TRUST_E_SUBJECT_FORM_UNKNOWN,
314 "Expected TRUST_E_SUBJECT_FORM_UNKNOWN, got 0x%08lx\n", GetLastError());
316 /* cbSize not initialized, but valid subject (named unknown but registered by wintrust) */
317 SetLastError(0xdeadbeef);
318 memset(&sdi, 0, sizeof(SIP_DISPATCH_INFO));
319 ret = CryptSIPLoad(&unknown, 0, &sdi);
322 ok ( ret, "Expected CryptSIPLoad to succeed\n");
323 ok ( GetLastError() == ERROR_PROC_NOT_FOUND,
324 "Expected ERROR_PROC_NOT_FOUND, got 0x%08lx\n", GetLastError());
328 SetLastError(0xdeadbeef);
329 memset(&sdi, 0, sizeof(SIP_DISPATCH_INFO));
330 sdi.cbSize = sizeof(SIP_DISPATCH_INFO);
331 ret = CryptSIPLoad(&unknown, 0, &sdi);
333 ok ( ret, "Expected CryptSIPLoad to succeed\n");
334 ok ( GetLastError() == 0xdeadbeef,
335 "Expected 0xdeadbeef, got 0x%08lx\n", GetLastError());
337 /* Reserved parameter not 0 */
338 SetLastError(0xdeadbeef);
339 memset(&sdi, 0, sizeof(SIP_DISPATCH_INFO));
340 sdi.cbSize = sizeof(SIP_DISPATCH_INFO);
341 ret = CryptSIPLoad(&unknown, 1, &sdi);
342 ok ( !ret, "Expected CryptSIPLoad to fail\n");
344 ok ( GetLastError() == ERROR_INVALID_PARAMETER,
345 "Expected ERROR_INVALID_PARAMETER, got 0x%08lx\n", GetLastError());
350 test_AddRemoveProvider();
351 test_SIPRetrieveSubjectGUID();