PageRenderTime 25ms CodeModel.GetById 32ms RepoModel.GetById 1ms app.codeStats 0ms

/dlls/wintrust/tests/register.c

https://github.com/mirrors/wine
C | 318 lines | 246 code | 30 blank | 42 comment | 34 complexity | c98239d400d6daec9d8945883d7ca7ef MD5 | raw file
Possible License(s): LGPL-3.0, LGPL-2.1, LGPL-2.0, CC-BY-SA-3.0, BSD-3-Clause
  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. #include <stdarg.h>
  21. #include <stdio.h>
  22. #include "windows.h"
  23. #include "softpub.h"
  24. #include "wintrust.h"
  25. #include "winreg.h"
  26. #include "wine/test.h"
  27. static BOOL (WINAPI * pWintrustAddActionID)(GUID*, DWORD, CRYPT_REGISTER_ACTIONID*);
  28. static BOOL (WINAPI * pWintrustAddDefaultForUsage)(const CHAR*,CRYPT_PROVIDER_REGDEFUSAGE*);
  29. static void (WINAPI * pWintrustGetRegPolicyFlags)(DWORD *);
  30. static BOOL (WINAPI * pWintrustLoadFunctionPointers)(GUID *, CRYPT_PROVIDER_FUNCTIONS *);
  31. static BOOL (WINAPI * pWintrustRemoveActionID)(GUID*);
  32. static BOOL (WINAPI * pWintrustSetRegPolicyFlags)(DWORD);
  33. static void InitFunctionPtrs(void)
  34. {
  35. HMODULE hWintrust = GetModuleHandleA("wintrust.dll");
  36. #define WINTRUST_GET_PROC(func) \
  37. p ## func = (void*)GetProcAddress(hWintrust, #func); \
  38. if(!p ## func) \
  39. trace("GetProcAddress(%s) failed\n", #func);
  40. WINTRUST_GET_PROC(WintrustAddActionID)
  41. WINTRUST_GET_PROC(WintrustAddDefaultForUsage)
  42. WINTRUST_GET_PROC(WintrustGetRegPolicyFlags)
  43. WINTRUST_GET_PROC(WintrustLoadFunctionPointers)
  44. WINTRUST_GET_PROC(WintrustRemoveActionID)
  45. WINTRUST_GET_PROC(WintrustSetRegPolicyFlags)
  46. #undef WINTRUST_GET_PROC
  47. }
  48. static void test_AddRem_ActionID(void)
  49. {
  50. static WCHAR DummyDllW[] = {'d','e','a','d','b','e','e','f','.','d','l','l',0 };
  51. static WCHAR DummyFunctionW[] = {'d','u','m','m','y','f','u','n','c','t','i','o','n',0 };
  52. GUID ActionID = { 0xdeadbeef, 0xdead, 0xbeef, { 0xde,0xad,0xbe,0xef,0xde,0xad,0xbe,0xef }};
  53. CRYPT_REGISTER_ACTIONID ActionIDFunctions;
  54. CRYPT_TRUST_REG_ENTRY EmptyProvider = { 0, NULL, NULL };
  55. CRYPT_TRUST_REG_ENTRY DummyProvider = { sizeof(CRYPT_TRUST_REG_ENTRY), DummyDllW, DummyFunctionW };
  56. BOOL ret;
  57. if (!pWintrustAddActionID || !pWintrustRemoveActionID)
  58. {
  59. win_skip("WintrustAddActionID and/or WintrustRemoveActionID are not available\n");
  60. return;
  61. }
  62. /* All NULL */
  63. SetLastError(0xdeadbeef);
  64. ret = pWintrustAddActionID(NULL, 0, NULL);
  65. ok (!ret, "Expected WintrustAddActionID to fail.\n");
  66. ok (GetLastError() == ERROR_INVALID_PARAMETER /* XP/W2K3 */ ||
  67. GetLastError() == 0xdeadbeef /* Win98/NT4/W2K */,
  68. "Expected ERROR_INVALID_PARAMETER(W2K3) or 0xdeadbeef(Win98/NT4/W2K), got %lu.\n", GetLastError());
  69. /* NULL functions */
  70. SetLastError(0xdeadbeef);
  71. ret = pWintrustAddActionID(&ActionID, 0, NULL);
  72. ok (!ret, "Expected WintrustAddActionID to fail.\n");
  73. ok (GetLastError() == ERROR_INVALID_PARAMETER /* XP/W2K3 */ ||
  74. GetLastError() == 0xdeadbeef /* Win98/NT4/W2K */,
  75. "Expected ERROR_INVALID_PARAMETER(W2K3) or 0xdeadbeef(Win98/NT4/W2K), got %lu.\n", GetLastError());
  76. /* All OK (although no functions defined), except cbStruct is not set in ActionIDFunctions */
  77. SetLastError(0xdeadbeef);
  78. memset(&ActionIDFunctions, 0, sizeof(CRYPT_REGISTER_ACTIONID));
  79. ret = pWintrustAddActionID(&ActionID, 0, &ActionIDFunctions);
  80. ok (!ret, "Expected WintrustAddActionID to fail.\n");
  81. ok (GetLastError() == ERROR_INVALID_PARAMETER /* XP/W2K3 */ ||
  82. GetLastError() == 0xdeadbeef /* Win98/NT4/W2K */,
  83. "Expected ERROR_INVALID_PARAMETER(W2K3) or 0xdeadbeef(Win98/NT4/W2K), got %lu.\n", GetLastError());
  84. /* All OK (although no functions defined) and cbStruct is set now */
  85. SetLastError(0xdeadbeef);
  86. memset(&ActionIDFunctions, 0, sizeof(CRYPT_REGISTER_ACTIONID));
  87. ActionIDFunctions.cbStruct = sizeof(CRYPT_REGISTER_ACTIONID);
  88. ret = pWintrustAddActionID(&ActionID, 0, &ActionIDFunctions);
  89. ok (ret, "Expected WintrustAddActionID to succeed.\n");
  90. ok (GetLastError() == ERROR_INVALID_PARAMETER,
  91. "Expected ERROR_INVALID_PARAMETER, got %lu.\n", GetLastError());
  92. /* All OK and all (but 1) functions are correctly defined. The DLL and entrypoints
  93. * are not present.
  94. */
  95. memset(&ActionIDFunctions, 0, sizeof(CRYPT_REGISTER_ACTIONID));
  96. ActionIDFunctions.cbStruct = sizeof(CRYPT_REGISTER_ACTIONID);
  97. ActionIDFunctions.sInitProvider = DummyProvider;
  98. ActionIDFunctions.sObjectProvider = DummyProvider;
  99. ActionIDFunctions.sSignatureProvider = EmptyProvider;
  100. ActionIDFunctions.sCertificateProvider = DummyProvider;
  101. ActionIDFunctions.sCertificatePolicyProvider = DummyProvider;
  102. ActionIDFunctions.sFinalPolicyProvider = DummyProvider;
  103. ActionIDFunctions.sTestPolicyProvider = DummyProvider;
  104. ActionIDFunctions.sCleanupProvider = DummyProvider;
  105. SetLastError(0xdeadbeef);
  106. ret = pWintrustAddActionID(&ActionID, 0, &ActionIDFunctions);
  107. ok (ret, "Expected WintrustAddActionID to succeed.\n");
  108. ok (GetLastError() == ERROR_INVALID_PARAMETER ||
  109. GetLastError() == ERROR_ACCESS_DENIED,
  110. "Expected ERROR_INVALID_PARAMETER or ERROR_ACCESS_DENIED, got %lu.\n",
  111. GetLastError());
  112. /* All OK and all functions are correctly defined. The DLL and entrypoints
  113. * are not present.
  114. */
  115. memset(&ActionIDFunctions, 0, sizeof(CRYPT_REGISTER_ACTIONID));
  116. ActionIDFunctions.cbStruct = sizeof(CRYPT_REGISTER_ACTIONID);
  117. ActionIDFunctions.sInitProvider = DummyProvider;
  118. ActionIDFunctions.sObjectProvider = DummyProvider;
  119. ActionIDFunctions.sSignatureProvider = DummyProvider;
  120. ActionIDFunctions.sCertificateProvider = DummyProvider;
  121. ActionIDFunctions.sCertificatePolicyProvider = DummyProvider;
  122. ActionIDFunctions.sFinalPolicyProvider = DummyProvider;
  123. ActionIDFunctions.sTestPolicyProvider = DummyProvider;
  124. ActionIDFunctions.sCleanupProvider = DummyProvider;
  125. SetLastError(0xdeadbeef);
  126. ret = pWintrustAddActionID(&ActionID, 0, &ActionIDFunctions);
  127. ok (ret, "Expected WintrustAddActionID to succeed.\n");
  128. ok (GetLastError() == 0xdeadbeef || GetLastError() == ERROR_ACCESS_DENIED,
  129. "Expected 0xdeadbeef or ERROR_ACCESS_DENIED, got %lu.\n",
  130. GetLastError());
  131. SetLastError(0xdeadbeef);
  132. ret = pWintrustRemoveActionID(&ActionID);
  133. ok ( ret, "WintrustRemoveActionID failed : %ld\n", GetLastError());
  134. ok ( GetLastError() == 0xdeadbeef, "Last error should not have been changed: %lu\n", GetLastError());
  135. /* NULL input */
  136. SetLastError(0xdeadbeef);
  137. ret = pWintrustRemoveActionID(NULL);
  138. ok (ret, "Expected WintrustRemoveActionID to succeed.\n");
  139. ok (GetLastError() == ERROR_INVALID_PARAMETER,
  140. "Expected ERROR_INVALID_PARAMETER, got %lu.\n", GetLastError());
  141. /* The passed GUID is removed by a previous call, so it's basically a test with a nonexistent Trust provider */
  142. SetLastError(0xdeadbeef);
  143. ret = pWintrustRemoveActionID(&ActionID);
  144. ok (ret, "Expected WintrustRemoveActionID to succeed.\n");
  145. ok (GetLastError() == 0xdeadbeef,
  146. "Expected 0xdeadbeef, got %lu.\n", GetLastError());
  147. }
  148. static void test_AddDefaultForUsage(void)
  149. {
  150. BOOL ret;
  151. static GUID ActionID = { 0xdeadbeef, 0xdead, 0xbeef, { 0xde,0xad,0xbe,0xef,0xde,0xad,0xbe,0xef }};
  152. static WCHAR DummyDllW[] = {'d','e','a','d','b','e','e','f','.','d','l','l',0 };
  153. static CHAR DummyFunction[] = "dummyfunction";
  154. static const CHAR oid[] = "1.2.3.4.5.6.7.8.9.10";
  155. static CRYPT_PROVIDER_REGDEFUSAGE DefUsage;
  156. if (!pWintrustAddDefaultForUsage)
  157. {
  158. win_skip("WintrustAddDefaultForUsage is not available\n");
  159. return;
  160. }
  161. /* All NULL */
  162. SetLastError(0xdeadbeef);
  163. ret = pWintrustAddDefaultForUsage(NULL, NULL);
  164. ok (!ret, "Expected WintrustAddDefaultForUsage to fail.\n");
  165. ok (GetLastError() == ERROR_INVALID_PARAMETER,
  166. "Expected ERROR_INVALID_PARAMETER, got %lu.\n", GetLastError());
  167. /* NULL defusage */
  168. SetLastError(0xdeadbeef);
  169. ret = pWintrustAddDefaultForUsage(oid, NULL);
  170. ok (!ret, "Expected WintrustAddDefaultForUsage to fail.\n");
  171. ok (GetLastError() == ERROR_INVALID_PARAMETER,
  172. "Expected ERROR_INVALID_PARAMETER, got %lu.\n", GetLastError());
  173. /* NULL oid and proper defusage */
  174. memset(&DefUsage, 0 , sizeof(CRYPT_PROVIDER_REGDEFUSAGE));
  175. DefUsage.cbStruct = sizeof(CRYPT_PROVIDER_REGDEFUSAGE);
  176. DefUsage.pgActionID = &ActionID;
  177. DefUsage.pwszDllName = DummyDllW;
  178. DefUsage.pwszLoadCallbackDataFunctionName = DummyFunction;
  179. DefUsage.pwszFreeCallbackDataFunctionName = DummyFunction;
  180. SetLastError(0xdeadbeef);
  181. ret = pWintrustAddDefaultForUsage(NULL, &DefUsage);
  182. ok (!ret, "Expected WintrustAddDefaultForUsage to fail.\n");
  183. ok (GetLastError() == ERROR_INVALID_PARAMETER,
  184. "Expected ERROR_INVALID_PARAMETER, got %lu.\n", GetLastError());
  185. /* cbStruct set to 0 */
  186. memset(&DefUsage, 0 , sizeof(CRYPT_PROVIDER_REGDEFUSAGE));
  187. DefUsage.cbStruct = 0;
  188. DefUsage.pgActionID = &ActionID;
  189. DefUsage.pwszDllName = DummyDllW;
  190. DefUsage.pwszLoadCallbackDataFunctionName = DummyFunction;
  191. DefUsage.pwszFreeCallbackDataFunctionName = DummyFunction;
  192. SetLastError(0xdeadbeef);
  193. ret = pWintrustAddDefaultForUsage(oid, &DefUsage);
  194. ok (!ret, "Expected WintrustAddDefaultForUsage to fail.\n");
  195. ok (GetLastError() == ERROR_INVALID_PARAMETER,
  196. "Expected ERROR_INVALID_PARAMETER, got %lu.\n", GetLastError());
  197. }
  198. static void test_LoadFunctionPointers(void)
  199. {
  200. BOOL ret;
  201. CRYPT_PROVIDER_FUNCTIONS funcs = {0};
  202. GUID action = WINTRUST_ACTION_GENERIC_VERIFY_V2;
  203. if (!pWintrustLoadFunctionPointers)
  204. {
  205. win_skip("WintrustLoadFunctionPointers is not available\n");
  206. return;
  207. }
  208. SetLastError(0xdeadbeef);
  209. ret = pWintrustLoadFunctionPointers(NULL, NULL);
  210. ok(!ret && GetLastError() == 0xdeadbeef, "Expected failure\n");
  211. SetLastError(0xdeadbeef);
  212. ret = pWintrustLoadFunctionPointers(&action, NULL);
  213. ok(!ret && GetLastError() == 0xdeadbeef, "Expected failure\n");
  214. SetLastError(0xdeadbeef);
  215. ret = pWintrustLoadFunctionPointers(NULL, &funcs);
  216. ok(!ret, "WintrustLoadFunctionPointers succeeded\n");
  217. ok(GetLastError() == ERROR_INVALID_PARAMETER ||
  218. GetLastError() == 0xdeadbeef /* W2K and XP-SP1 */,
  219. "Expected ERROR_INVALID_PARAMETER or 0xdeadbeef, got %ld\n", GetLastError());
  220. SetLastError(0xdeadbeef);
  221. funcs.cbStruct = 0;
  222. ret = pWintrustLoadFunctionPointers(&action, &funcs);
  223. ok(!ret && GetLastError() == 0xdeadbeef, "Expected failure\n");
  224. SetLastError(0xdeadbeef);
  225. funcs.cbStruct = sizeof(funcs);
  226. ret = pWintrustLoadFunctionPointers(&action, &funcs);
  227. ok(ret, "WintrustLoadFunctionPointers failed: %ld\n", GetLastError());
  228. ok(funcs.pfnAlloc != NULL, "Expected a pointer\n");
  229. ok(funcs.pfnFree != NULL, "Expected a pointer\n");
  230. }
  231. static void test_RegPolicyFlags(void)
  232. {
  233. /* Default state value 0x00023c00, which is
  234. * WTPF_IGNOREREVOCATIONONTS |
  235. * WTPF_OFFLINEOKNBU_COM |
  236. * WTPF_OFFLINEOKNBU_IND |
  237. * WTPF_OFFLINEOK_COM |
  238. * WTPF_OFFLINEOK_IND
  239. */
  240. static const CHAR Software_Publishing[] =
  241. "Software\\Microsoft\\Windows\\CurrentVersion\\Wintrust\\"
  242. "Trust Providers\\Software Publishing";
  243. static const CHAR State[] = "State";
  244. HKEY key;
  245. LONG r;
  246. DWORD flags1, flags2, flags3, size;
  247. BOOL ret;
  248. if (!pWintrustGetRegPolicyFlags || !pWintrustSetRegPolicyFlags)
  249. {
  250. win_skip("Policy flags functions not present\n");
  251. return;
  252. }
  253. pWintrustGetRegPolicyFlags(&flags2);
  254. r = RegOpenKeyExA(HKEY_CURRENT_USER, Software_Publishing, 0, KEY_ALL_ACCESS,
  255. &key);
  256. ok(!r, "RegOpenKeyEx failed: %ld\n", r);
  257. size = sizeof(flags1);
  258. r = RegQueryValueExA(key, State, NULL, NULL, (LPBYTE)&flags1, &size);
  259. ok(!r || r == ERROR_FILE_NOT_FOUND, "RegQueryValueEx failed: %ld\n", r);
  260. if (!r)
  261. ok(flags1 == flags2, "Got %08lx flags instead of %08lx\n", flags1, flags2);
  262. flags3 = flags2 | 1;
  263. ret = pWintrustSetRegPolicyFlags(flags3);
  264. ok(ret, "WintrustSetRegPolicyFlags failed: %ld\n", GetLastError());
  265. size = sizeof(flags1);
  266. r = RegQueryValueExA(key, State, NULL, NULL, (LPBYTE)&flags1, &size);
  267. ok(!r, "RegQueryValueEx failed: %ld\n", r);
  268. ok(flags1 == flags3, "Got %08lx flags instead of %08lx\n", flags1, flags3);
  269. pWintrustSetRegPolicyFlags(flags2);
  270. RegCloseKey(key);
  271. }
  272. START_TEST(register)
  273. {
  274. InitFunctionPtrs();
  275. test_AddRem_ActionID();
  276. test_AddDefaultForUsage();
  277. test_LoadFunctionPointers();
  278. test_RegPolicyFlags();
  279. }