4 * Copyright 2006 Yuval Fledel
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
24 #define WIN32_NO_STATUS
27 #define SECURITY_WIN32
33 #include "wine/test.h"
35 /* Helper macros to find the size of SECPKG_FUNCTION_TABLE */
36 #define SECPKG_FUNCTION_TABLE_SIZE_1 FIELD_OFFSET(SECPKG_FUNCTION_TABLE, \
38 #define SECPKG_FUNCTION_TABLE_SIZE_2 FIELD_OFFSET(SECPKG_FUNCTION_TABLE, \
39 SetCredentialsAttributes)
40 #define SECPKG_FUNCTION_TABLE_SIZE_3 sizeof(SECPKG_FUNCTION_TABLE)
42 static NTSTATUS (NTAPI *pSpLsaModeInitialize)(ULONG, PULONG,
43 PSECPKG_FUNCTION_TABLE*, PULONG);
44 static NTSTATUS (NTAPI *pSpUserModeInitialize)(ULONG, PULONG,
45 PSECPKG_USER_FUNCTION_TABLE*, PULONG);
47 static void testInitialize(void)
49 PSECPKG_USER_FUNCTION_TABLE pUserTables, pUserTables2;
50 PSECPKG_FUNCTION_TABLE pTables, pTables2;
51 ULONG cTables = 0, cUserTables = 0, Version = 0;
54 /* Passing NULL into one of the parameters of SpLsaModeInitialize or
55 SpUserModeInitialize causes a crash. */
57 /* SpLsaModeInitialize does not care about the LSA version. */
58 status = pSpLsaModeInitialize(0, &Version, &pTables2, &cTables);
59 ok(status == STATUS_SUCCESS, "status: 0x%x\n", status);
61 broken(cTables == 1), /* Win2k */
62 "cTables: %d\n", cTables);
63 ok(pTables2 != NULL,"pTables: %p\n", pTables2);
65 /* We can call it as many times we want. */
66 status = pSpLsaModeInitialize(0x10000, &Version, &pTables, &cTables);
67 ok(status == STATUS_SUCCESS, "status: 0x%x\n", status);
69 broken(cTables == 1), /* Win2k */
70 "cTables: %d\n", cTables);
71 ok(pTables != NULL, "pTables: %p\n", pTables);
72 /* It will always return the same pointer. */
73 ok(pTables == pTables2, "pTables: %p, pTables2: %p\n", pTables, pTables2);
75 status = pSpLsaModeInitialize(0x23456, &Version, &pTables, &cTables);
76 ok(status == STATUS_SUCCESS, "status: 0x%x\n", status);
78 broken(cTables == 1), /* Win2k */
79 "cTables: %d\n", cTables);
80 ok(pTables != NULL, "pTables: %p\n", pTables);
81 ok(pTables == pTables2, "pTables: %p, pTables2: %p\n", pTables, pTables2);
83 /* Bad versions to SpUserModeInitialize. Parameters unchanged */
87 status = pSpUserModeInitialize(0, &Version, &pUserTables, &cUserTables);
88 ok(status == STATUS_INVALID_PARAMETER, "status: 0x%x\n", status);
89 ok(Version == 0xdead, "Version: 0x%x\n", Version);
90 ok(cUserTables == 0xdead, "cTables: %d\n", cUserTables);
91 ok(pUserTables == NULL, "pUserTables: %p\n", pUserTables);
93 status = pSpUserModeInitialize(0x20000, &Version, &pUserTables,
95 ok(status == STATUS_INVALID_PARAMETER, "status: 0x%x\n", status);
96 ok(Version == 0xdead, "Version: 0x%x\n", Version);
97 ok(cUserTables == 0xdead, "cTables: %d\n", cUserTables);
98 ok(pUserTables == NULL, "pUserTables: %p\n", pUserTables);
100 /* Good version to SpUserModeInitialize */
101 status = pSpUserModeInitialize(SECPKG_INTERFACE_VERSION, &Version,
102 &pUserTables, &cUserTables);
103 ok(status == STATUS_SUCCESS, "status: 0x%x\n", status);
104 ok(Version == SECPKG_INTERFACE_VERSION, "Version: 0x%x\n", Version);
105 ok(cUserTables == 2 ||
106 broken(cUserTables == 4), /* Win2k */
107 "cUserTables: %d\n", cUserTables);
108 ok(pUserTables != NULL, "pUserTables: %p\n", pUserTables);
110 /* Initializing user again */
111 status = pSpUserModeInitialize(SECPKG_INTERFACE_VERSION, &Version,
112 &pUserTables2, &cTables);
113 ok(status == STATUS_SUCCESS, "status: 0x%x\n", status);
114 ok(pUserTables == pUserTables2, "pUserTables: %p, pUserTables2: %p\n",
115 pUserTables, pUserTables2);
118 /* A helper function to find the dispatch table of the next package.
119 Needed because SECPKG_FUNCTION_TABLE's size depend on the version */
120 static PSECPKG_FUNCTION_TABLE getNextSecPkgTable(PSECPKG_FUNCTION_TABLE pTable,
125 if (Version == SECPKG_INTERFACE_VERSION)
126 size = SECPKG_FUNCTION_TABLE_SIZE_1;
127 else if (Version == SECPKG_INTERFACE_VERSION_2)
128 size = SECPKG_FUNCTION_TABLE_SIZE_2;
129 else if (Version == SECPKG_INTERFACE_VERSION_3)
130 size = SECPKG_FUNCTION_TABLE_SIZE_3;
132 ok(FALSE, "Unknown package version 0x%x\n", Version);
136 return (PSECPKG_FUNCTION_TABLE)((PBYTE)pTable + size);
139 static void testGetInfo(void)
141 PSECPKG_FUNCTION_TABLE pTables;
142 SecPkgInfoW PackageInfo;
143 ULONG cTables, Version;
146 /* Get the dispatch table */
147 status = pSpLsaModeInitialize(0, &Version, &pTables, &cTables);
148 ok(status == STATUS_SUCCESS, "status: 0x%x\n", status);
150 /* Passing NULL into ->GetInfo causes a crash. */
152 /* First package: Unified */
153 status = pTables->GetInfo(&PackageInfo);
154 ok(status == STATUS_SUCCESS, "status: 0x%x\n", status);
155 ok(PackageInfo.fCapabilities == 0x107b3, "fCapabilities: 0x%x\n",
156 PackageInfo.fCapabilities);
157 ok(PackageInfo.wVersion == 1, "wVersion: %d\n", PackageInfo.wVersion);
158 ok(PackageInfo.wRPCID == 14, "wRPCID: %d\n", PackageInfo.wRPCID);
159 ok(PackageInfo.cbMaxToken == 0x4000 ||
160 PackageInfo.cbMaxToken == 0x6000, /* Vista */
161 "cbMaxToken: 0x%x\n",
162 PackageInfo.cbMaxToken);
167 win_skip("Second package missing\n");
170 pTables = getNextSecPkgTable(pTables, Version);
173 status = pTables->GetInfo(&PackageInfo);
174 ok(status == STATUS_SUCCESS ||
175 status == SEC_E_UNSUPPORTED_FUNCTION, /* win2k3 */
176 "status: 0x%x\n", status);
178 if (status == STATUS_SUCCESS)
180 ok(PackageInfo.fCapabilities == 0x107b3, "fCapabilities: 0x%x\n",
181 PackageInfo.fCapabilities);
182 ok(PackageInfo.wVersion == 1, "wVersion: %d\n", PackageInfo.wVersion);
183 ok(PackageInfo.wRPCID == 14, "wRPCID: %d\n", PackageInfo.wRPCID);
184 ok(PackageInfo.cbMaxToken == 0x4000, "cbMaxToken: 0x%x\n",
185 PackageInfo.cbMaxToken);
191 HMODULE hMod = LoadLibraryA("schannel.dll");
193 win_skip("schannel.dll not available\n");
197 pSpLsaModeInitialize = (void *)GetProcAddress(hMod, "SpLsaModeInitialize");
198 pSpUserModeInitialize = (void *)GetProcAddress(hMod, "SpUserModeInitialize");
200 if (pSpLsaModeInitialize && pSpUserModeInitialize)
205 else win_skip( "schannel functions not found\n" );