ReactOS 0.4.15-dev-7924-g5949c20
register.c
Go to the documentation of this file.
1/* Unit test suite for wintrust API functions
2 *
3 * Copyright 2006 Paul Vriens
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
21#include <stdarg.h>
22#include <stdio.h>
23
24#include "windows.h"
25#include "softpub.h"
26#include "wintrust.h"
27#include "winreg.h"
28
29#include "wine/test.h"
30
31static BOOL (WINAPI * pWintrustAddActionID)(GUID*, DWORD, CRYPT_REGISTER_ACTIONID*);
32static BOOL (WINAPI * pWintrustAddDefaultForUsage)(const CHAR*,CRYPT_PROVIDER_REGDEFUSAGE*);
33static void (WINAPI * pWintrustGetRegPolicyFlags)(DWORD *);
34static BOOL (WINAPI * pWintrustLoadFunctionPointers)(GUID *, CRYPT_PROVIDER_FUNCTIONS *);
35static BOOL (WINAPI * pWintrustRemoveActionID)(GUID*);
36static BOOL (WINAPI * pWintrustSetRegPolicyFlags)(DWORD);
37
38static void InitFunctionPtrs(void)
39{
40 HMODULE hWintrust = GetModuleHandleA("wintrust.dll");
41
42#define WINTRUST_GET_PROC(func) \
43 p ## func = (void*)GetProcAddress(hWintrust, #func); \
44 if(!p ## func) \
45 trace("GetProcAddress(%s) failed\n", #func);
46
53
54#undef WINTRUST_GET_PROC
55}
56
57static void test_AddRem_ActionID(void)
58{
59 static WCHAR DummyDllW[] = {'d','e','a','d','b','e','e','f','.','d','l','l',0 };
60 static WCHAR DummyFunctionW[] = {'d','u','m','m','y','f','u','n','c','t','i','o','n',0 };
61 GUID ActionID = { 0xdeadbeef, 0xdead, 0xbeef, { 0xde,0xad,0xbe,0xef,0xde,0xad,0xbe,0xef }};
62 CRYPT_REGISTER_ACTIONID ActionIDFunctions;
63 CRYPT_TRUST_REG_ENTRY EmptyProvider = { 0, NULL, NULL };
64 CRYPT_TRUST_REG_ENTRY DummyProvider = { sizeof(CRYPT_TRUST_REG_ENTRY), DummyDllW, DummyFunctionW };
65 BOOL ret;
66
67 if (!pWintrustAddActionID || !pWintrustRemoveActionID)
68 {
69 win_skip("WintrustAddActionID and/or WintrustRemoveActionID are not available\n");
70 return;
71 }
72
73 /* All NULL */
74 SetLastError(0xdeadbeef);
75 ret = pWintrustAddActionID(NULL, 0, NULL);
76 ok (!ret, "Expected WintrustAddActionID to fail.\n");
77 ok (GetLastError() == ERROR_INVALID_PARAMETER /* XP/W2K3 */ ||
78 GetLastError() == 0xdeadbeef /* Win98/NT4/W2K */,
79 "Expected ERROR_INVALID_PARAMETER(W2K3) or 0xdeadbeef(Win98/NT4/W2K), got %u.\n", GetLastError());
80
81 /* NULL functions */
82 SetLastError(0xdeadbeef);
83 ret = pWintrustAddActionID(&ActionID, 0, NULL);
84 ok (!ret, "Expected WintrustAddActionID to fail.\n");
85 ok (GetLastError() == ERROR_INVALID_PARAMETER /* XP/W2K3 */ ||
86 GetLastError() == 0xdeadbeef /* Win98/NT4/W2K */,
87 "Expected ERROR_INVALID_PARAMETER(W2K3) or 0xdeadbeef(Win98/NT4/W2K), got %u.\n", GetLastError());
88
89 /* All OK (although no functions defined), except cbStruct is not set in ActionIDFunctions */
90 SetLastError(0xdeadbeef);
91 memset(&ActionIDFunctions, 0, sizeof(CRYPT_REGISTER_ACTIONID));
92 ret = pWintrustAddActionID(&ActionID, 0, &ActionIDFunctions);
93 ok (!ret, "Expected WintrustAddActionID to fail.\n");
94 ok (GetLastError() == ERROR_INVALID_PARAMETER /* XP/W2K3 */ ||
95 GetLastError() == 0xdeadbeef /* Win98/NT4/W2K */,
96 "Expected ERROR_INVALID_PARAMETER(W2K3) or 0xdeadbeef(Win98/NT4/W2K), got %u.\n", GetLastError());
97
98 /* All OK (although no functions defined) and cbStruct is set now */
99 SetLastError(0xdeadbeef);
100 memset(&ActionIDFunctions, 0, sizeof(CRYPT_REGISTER_ACTIONID));
101 ActionIDFunctions.cbStruct = sizeof(CRYPT_REGISTER_ACTIONID);
102 ret = pWintrustAddActionID(&ActionID, 0, &ActionIDFunctions);
103 ok (ret, "Expected WintrustAddActionID to succeed.\n");
105 "Expected ERROR_INVALID_PARAMETER, got %u.\n", GetLastError());
106
107 /* All OK and all (but 1) functions are correctly defined. The DLL and entrypoints
108 * are not present.
109 */
110 memset(&ActionIDFunctions, 0, sizeof(CRYPT_REGISTER_ACTIONID));
111 ActionIDFunctions.cbStruct = sizeof(CRYPT_REGISTER_ACTIONID);
112 ActionIDFunctions.sInitProvider = DummyProvider;
113 ActionIDFunctions.sObjectProvider = DummyProvider;
114 ActionIDFunctions.sSignatureProvider = EmptyProvider;
115 ActionIDFunctions.sCertificateProvider = DummyProvider;
116 ActionIDFunctions.sCertificatePolicyProvider = DummyProvider;
117 ActionIDFunctions.sFinalPolicyProvider = DummyProvider;
118 ActionIDFunctions.sTestPolicyProvider = DummyProvider;
119 ActionIDFunctions.sCleanupProvider = DummyProvider;
120 SetLastError(0xdeadbeef);
121 ret = pWintrustAddActionID(&ActionID, 0, &ActionIDFunctions);
122 ok (ret, "Expected WintrustAddActionID to succeed.\n");
125 "Expected ERROR_INVALID_PARAMETER or ERROR_ACCESS_DENIED, got %u.\n",
126 GetLastError());
127
128 /* All OK and all functions are correctly defined. The DLL and entrypoints
129 * are not present.
130 */
131 memset(&ActionIDFunctions, 0, sizeof(CRYPT_REGISTER_ACTIONID));
132 ActionIDFunctions.cbStruct = sizeof(CRYPT_REGISTER_ACTIONID);
133 ActionIDFunctions.sInitProvider = DummyProvider;
134 ActionIDFunctions.sObjectProvider = DummyProvider;
135 ActionIDFunctions.sSignatureProvider = DummyProvider;
136 ActionIDFunctions.sCertificateProvider = DummyProvider;
137 ActionIDFunctions.sCertificatePolicyProvider = DummyProvider;
138 ActionIDFunctions.sFinalPolicyProvider = DummyProvider;
139 ActionIDFunctions.sTestPolicyProvider = DummyProvider;
140 ActionIDFunctions.sCleanupProvider = DummyProvider;
141 SetLastError(0xdeadbeef);
142 ret = pWintrustAddActionID(&ActionID, 0, &ActionIDFunctions);
143 ok (ret, "Expected WintrustAddActionID to succeed.\n");
144 ok (GetLastError() == 0xdeadbeef || GetLastError() == ERROR_ACCESS_DENIED,
145 "Expected 0xdeadbeef or ERROR_ACCESS_DENIED, got %u.\n",
146 GetLastError());
147
148 SetLastError(0xdeadbeef);
149 ret = pWintrustRemoveActionID(&ActionID);
150 ok ( ret, "WintrustRemoveActionID failed : %d\n", GetLastError());
151 ok ( GetLastError() == 0xdeadbeef, "Last error should not have been changed: %u\n", GetLastError());
152
153 /* NULL input */
154 SetLastError(0xdeadbeef);
155 ret = pWintrustRemoveActionID(NULL);
156 ok (ret, "Expected WintrustRemoveActionID to succeed.\n");
158 "Expected ERROR_INVALID_PARAMETER, got %u.\n", GetLastError());
159
160 /* The passed GUID is removed by a previous call, so it's basically a test with a nonexistent Trust provider */
161 SetLastError(0xdeadbeef);
162 ret = pWintrustRemoveActionID(&ActionID);
163 ok (ret, "Expected WintrustRemoveActionID to succeed.\n");
164 ok (GetLastError() == 0xdeadbeef,
165 "Expected 0xdeadbeef, got %u.\n", GetLastError());
166}
167
168static void test_AddDefaultForUsage(void)
169{
170 BOOL ret;
171 static GUID ActionID = { 0xdeadbeef, 0xdead, 0xbeef, { 0xde,0xad,0xbe,0xef,0xde,0xad,0xbe,0xef }};
172 static WCHAR DummyDllW[] = {'d','e','a','d','b','e','e','f','.','d','l','l',0 };
173 static CHAR DummyFunction[] = "dummyfunction";
174 static const CHAR oid[] = "1.2.3.4.5.6.7.8.9.10";
175 static CRYPT_PROVIDER_REGDEFUSAGE DefUsage;
176
177 if (!pWintrustAddDefaultForUsage)
178 {
179 win_skip("WintrustAddDefaultForUsage is not available\n");
180 return;
181 }
182
183 /* All NULL */
184 SetLastError(0xdeadbeef);
185 ret = pWintrustAddDefaultForUsage(NULL, NULL);
186 ok (!ret, "Expected WintrustAddDefaultForUsage to fail.\n");
188 "Expected ERROR_INVALID_PARAMETER, got %u.\n", GetLastError());
189
190 /* NULL defusage */
191 SetLastError(0xdeadbeef);
192 ret = pWintrustAddDefaultForUsage(oid, NULL);
193 ok (!ret, "Expected WintrustAddDefaultForUsage to fail.\n");
195 "Expected ERROR_INVALID_PARAMETER, got %u.\n", GetLastError());
196
197 /* NULL oid and proper defusage */
198 memset(&DefUsage, 0 , sizeof(CRYPT_PROVIDER_REGDEFUSAGE));
199 DefUsage.cbStruct = sizeof(CRYPT_PROVIDER_REGDEFUSAGE);
200 DefUsage.pgActionID = &ActionID;
201 DefUsage.pwszDllName = DummyDllW;
202 DefUsage.pwszLoadCallbackDataFunctionName = DummyFunction;
203 DefUsage.pwszFreeCallbackDataFunctionName = DummyFunction;
204 SetLastError(0xdeadbeef);
205 ret = pWintrustAddDefaultForUsage(NULL, &DefUsage);
206 ok (!ret, "Expected WintrustAddDefaultForUsage to fail.\n");
208 "Expected ERROR_INVALID_PARAMETER, got %u.\n", GetLastError());
209
210 /* cbStruct set to 0 */
211 memset(&DefUsage, 0 , sizeof(CRYPT_PROVIDER_REGDEFUSAGE));
212 DefUsage.cbStruct = 0;
213 DefUsage.pgActionID = &ActionID;
214 DefUsage.pwszDllName = DummyDllW;
215 DefUsage.pwszLoadCallbackDataFunctionName = DummyFunction;
216 DefUsage.pwszFreeCallbackDataFunctionName = DummyFunction;
217 SetLastError(0xdeadbeef);
218 ret = pWintrustAddDefaultForUsage(oid, &DefUsage);
219 ok (!ret, "Expected WintrustAddDefaultForUsage to fail.\n");
221 "Expected ERROR_INVALID_PARAMETER, got %u.\n", GetLastError());
222}
223
225{
226 BOOL ret;
229
230 if (!pWintrustLoadFunctionPointers)
231 {
232 win_skip("WintrustLoadFunctionPointers is not available\n");
233 return;
234 }
235 SetLastError(0xdeadbeef);
236 ret = pWintrustLoadFunctionPointers(NULL, NULL);
237 ok(!ret && GetLastError() == 0xdeadbeef, "Expected failure\n");
238 SetLastError(0xdeadbeef);
239 ret = pWintrustLoadFunctionPointers(&action, NULL);
240 ok(!ret && GetLastError() == 0xdeadbeef, "Expected failure\n");
241
242 SetLastError(0xdeadbeef);
243 ret = pWintrustLoadFunctionPointers(NULL, &funcs);
244 ok(!ret, "WintrustLoadFunctionPointers succeeded\n");
246 GetLastError() == 0xdeadbeef /* W2K and XP-SP1 */,
247 "Expected ERROR_INVALID_PARAMETER or 0xdeadbeef, got %d\n", GetLastError());
248
249 SetLastError(0xdeadbeef);
250 funcs.cbStruct = 0;
251 ret = pWintrustLoadFunctionPointers(&action, &funcs);
252 ok(!ret && GetLastError() == 0xdeadbeef, "Expected failure\n");
253 SetLastError(0xdeadbeef);
254 funcs.cbStruct = sizeof(funcs);
255 ret = pWintrustLoadFunctionPointers(&action, &funcs);
256 ok(ret, "WintrustLoadFunctionPointers failed: %d\n", GetLastError());
257 ok(funcs.pfnAlloc != NULL, "Expected a pointer\n");
258 ok(funcs.pfnFree != NULL, "Expected a pointer\n");
259}
260
261static void test_RegPolicyFlags(void)
262{
263 /* Default state value 0x00023c00, which is
264 * WTPF_IGNOREREVOCATIONONTS |
265 * WTPF_OFFLINEOKNBU_COM |
266 * WTPF_OFFLINEOKNBU_IND |
267 * WTPF_OFFLINEOK_COM |
268 * WTPF_OFFLINEOK_IND
269 */
270 static const CHAR Software_Publishing[] =
271 "Software\\Microsoft\\Windows\\CurrentVersion\\Wintrust\\"
272 "Trust Providers\\Software Publishing";
273 static const CHAR State[] = "State";
274 HKEY key;
275 LONG r;
276 DWORD flags1, flags2, flags3, size;
277 BOOL ret;
278
279 if (!pWintrustGetRegPolicyFlags || !pWintrustSetRegPolicyFlags)
280 {
281 win_skip("Policy flags functions not present\n");
282 return;
283 }
284
285 pWintrustGetRegPolicyFlags(&flags2);
286
288 &key);
289 ok(!r, "RegOpenKeyEx failed: %d\n", r);
290
291 size = sizeof(flags1);
292 r = RegQueryValueExA(key, State, NULL, NULL, (LPBYTE)&flags1, &size);
293 ok(!r || r == ERROR_FILE_NOT_FOUND, "RegQueryValueEx failed: %d\n", r);
294 if (!r)
295 ok(flags1 == flags2, "Got %08x flags instead of %08x\n", flags1, flags2);
296
297 flags3 = flags2 | 1;
298 ret = pWintrustSetRegPolicyFlags(flags3);
299 ok(ret, "WintrustSetRegPolicyFlags failed: %d\n", GetLastError());
300 size = sizeof(flags1);
301 r = RegQueryValueExA(key, State, NULL, NULL, (LPBYTE)&flags1, &size);
302 ok(!r, "RegQueryValueEx failed: %d\n", r);
303 ok(flags1 == flags3, "Got %08x flags instead of %08x\n", flags1, flags3);
304
305 pWintrustSetRegPolicyFlags(flags2);
306
308}
309
310START_TEST(register)
311{
313
318}
#define ok(value,...)
Definition: atltest.h:57
#define START_TEST(x)
Definition: atltest.h:75
#define RegCloseKey(hKey)
Definition: registry.h:49
#define NULL
Definition: types.h:112
LONG WINAPI RegOpenKeyExA(_In_ HKEY hKey, _In_ LPCSTR lpSubKey, _In_ DWORD ulOptions, _In_ REGSAM samDesired, _Out_ PHKEY phkResult)
Definition: reg.c:3298
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:4009
#define ERROR_INVALID_PARAMETER
Definition: compat.h:101
#define SetLastError(x)
Definition: compat.h:752
#define ERROR_ACCESS_DENIED
Definition: compat.h:97
HMODULE WINAPI DECLSPEC_HOTPATCH GetModuleHandleA(LPCSTR lpModuleName)
Definition: loader.c:812
const WCHAR * action
Definition: action.c:7479
BOOL WINAPI WintrustLoadFunctionPointers(GUID *pgActionID, CRYPT_PROVIDER_FUNCTIONS *pPfns)
Definition: register.c:841
BOOL WINAPI WintrustAddActionID(GUID *pgActionID, DWORD fdwFlags, CRYPT_REGISTER_ACTIONID *psProvInfo)
Definition: register.c:238
BOOL WINAPI WintrustRemoveActionID(GUID *pgActionID)
Definition: register.c:337
BOOL WINAPI WintrustAddDefaultForUsage(const char *pszUsageOID, CRYPT_PROVIDER_REGDEFUSAGE *psDefUsage)
Definition: register.c:733
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
GLdouble GLdouble GLdouble r
Definition: gl.h:2055
GLsizeiptr size
Definition: glext.h:5919
#define ERROR_FILE_NOT_FOUND
Definition: disk.h:79
static void test_RegPolicyFlags(void)
Definition: register.c:261
#define WINTRUST_GET_PROC(func)
static DWORD
Definition: register.c:31
static void InitFunctionPtrs(void)
Definition: register.c:38
static void test_AddRem_ActionID(void)
Definition: register.c:57
static void test_LoadFunctionPointers(void)
Definition: register.c:224
static void test_AddDefaultForUsage(void)
Definition: register.c:168
#define BOOL
Definition: nt_native.h:43
#define KEY_ALL_ACCESS
Definition: nt_native.h:1041
long LONG
Definition: pedump.c:60
#define win_skip
Definition: test.h:160
static struct __wine_debug_functions funcs
Definition: debug.c:59
#define memset(x, y, z)
Definition: compat.h:39
#define WINTRUST_ACTION_GENERIC_VERIFY_V2
Definition: softpub.h:108
char * pwszLoadCallbackDataFunctionName
Definition: wintrust.h:190
char * pwszFreeCallbackDataFunctionName
Definition: wintrust.h:191
CRYPT_TRUST_REG_ENTRY sCertificateProvider
Definition: wintrust.h:178
CRYPT_TRUST_REG_ENTRY sInitProvider
Definition: wintrust.h:175
CRYPT_TRUST_REG_ENTRY sTestPolicyProvider
Definition: wintrust.h:181
CRYPT_TRUST_REG_ENTRY sCertificatePolicyProvider
Definition: wintrust.h:179
CRYPT_TRUST_REG_ENTRY sFinalPolicyProvider
Definition: wintrust.h:180
CRYPT_TRUST_REG_ENTRY sCleanupProvider
Definition: wintrust.h:182
CRYPT_TRUST_REG_ENTRY sObjectProvider
Definition: wintrust.h:176
CRYPT_TRUST_REG_ENTRY sSignatureProvider
Definition: wintrust.h:177
Definition: wintrust.h:166
Definition: copy.c:22
unsigned char * LPBYTE
Definition: typedefs.h:53
int ret
DWORD WINAPI GetLastError(void)
Definition: except.c:1042
#define WINAPI
Definition: msvc.h:6
#define HKEY_CURRENT_USER
Definition: winreg.h:11
struct _CRYPT_PROVIDER_REGDEFUSAGE CRYPT_PROVIDER_REGDEFUSAGE
struct _CRYPT_REGISTER_ACTIONID CRYPT_REGISTER_ACTIONID
struct _CRYPT_TRUST_REG_ENTRY CRYPT_TRUST_REG_ENTRY
static const WCHAR Software_Publishing[]
void WINAPI WintrustGetRegPolicyFlags(DWORD *pdwPolicyFlags)
BOOL WINAPI WintrustSetRegPolicyFlags(DWORD dwPolicyFlags)
__wchar_t WCHAR
Definition: xmlstorage.h:180
char CHAR
Definition: xmlstorage.h:175