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 offsetof(SECPKG_FUNCTION_TABLE, \
37 SpSetContextAttributes)
38 #define SECPKG_FUNCTION_TABLE_SIZE_2 offsetof(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);
60 ok(cTables == 2, "cTables: %d\n", cTables);
61 ok(pTables2 != NULL,"pTables: %p\n", pTables2);
63 /* We can call it as many times we want. */
64 status = pSpLsaModeInitialize(0x10000, &Version, &pTables, &cTables);
65 ok(status == STATUS_SUCCESS, "status: 0x%x\n", status);
66 ok(cTables == 2, "cTables: %d\n", cTables);
67 ok(pTables != NULL, "pTables: %p\n", pTables);
68 /* It will always return the same pointer. */
69 ok(pTables == pTables2, "pTables: %p, pTables2: %p\n", pTables, pTables2);
71 status = pSpLsaModeInitialize(0x23456, &Version, &pTables, &cTables);
72 ok(status == STATUS_SUCCESS, "status: 0x%x\n", status);
73 ok(cTables == 2, "cTables: %d\n", cTables);
74 ok(pTables != NULL, "pTables: %p\n", pTables);
75 ok(pTables == pTables2, "pTables: %p, pTables2: %p\n", pTables, pTables2);
77 /* Bad versions to SpUserModeInitialize. Parameters unchanged */
81 status = pSpUserModeInitialize(0, &Version, &pUserTables, &cUserTables);
82 ok(status == STATUS_INVALID_PARAMETER, "status: 0x%x\n", status);
83 ok(Version == 0xdead, "Version: 0x%x\n", Version);
84 ok(cUserTables == 0xdead, "cTables: %d\n", cUserTables);
85 ok(pUserTables == NULL, "pUserTables: %p\n", pUserTables);
87 status = pSpUserModeInitialize(0x20000, &Version, &pUserTables,
89 ok(status == STATUS_INVALID_PARAMETER, "status: 0x%x\n", status);
90 ok(Version == 0xdead, "Version: 0x%x\n", Version);
91 ok(cUserTables == 0xdead, "cTables: %d\n", cUserTables);
92 ok(pUserTables == NULL, "pUserTables: %p\n", pUserTables);
94 /* Good version to SpUserModeInitialize */
95 status = pSpUserModeInitialize(SECPKG_INTERFACE_VERSION, &Version,
96 &pUserTables, &cUserTables);
97 ok(status == STATUS_SUCCESS, "status: 0x%x\n", status);
98 ok(Version == SECPKG_INTERFACE_VERSION, "Version: 0x%x\n", Version);
99 ok(cUserTables == 2, "cUserTables: %d\n", cUserTables);
100 ok(pUserTables != NULL, "pUserTables: %p\n", pUserTables);
102 /* Initializing user again */
103 status = pSpUserModeInitialize(SECPKG_INTERFACE_VERSION, &Version,
104 &pUserTables2, &cTables);
105 ok(status == STATUS_SUCCESS, "status: 0x%x\n", status);
106 ok(pUserTables == pUserTables2, "pUserTables: %p, pUserTables2: %p\n",
107 pUserTables, pUserTables2);
110 /* A helper function to find the dispatch table of the next package.
111 Needed because SECPKG_FUNCTION_TABLE's size depend on the version */
112 static PSECPKG_FUNCTION_TABLE getNextSecPkgTable(PSECPKG_FUNCTION_TABLE pTable,
117 if (Version == SECPKG_INTERFACE_VERSION)
118 size = SECPKG_FUNCTION_TABLE_SIZE_1;
119 else if (Version == SECPKG_INTERFACE_VERSION_2)
120 size = SECPKG_FUNCTION_TABLE_SIZE_2;
121 else if (Version == SECPKG_INTERFACE_VERSION_3)
122 size = SECPKG_FUNCTION_TABLE_SIZE_3;
124 ok(FALSE, "Unknown package version 0x%x\n", Version);
128 return (PSECPKG_FUNCTION_TABLE)((PBYTE)pTable + size);
131 static void testGetInfo(void)
133 PSECPKG_FUNCTION_TABLE pTables;
134 SecPkgInfoW PackageInfo;
135 ULONG cTables, Version;
138 /* Get the dispatch table */
139 status = pSpLsaModeInitialize(0, &Version, &pTables, &cTables);
140 ok(status == STATUS_SUCCESS, "status: 0x%x\n", status);
142 /* Passing NULL into ->GetInfo causes a crash. */
144 /* First package: Unified */
145 status = pTables->GetInfo(&PackageInfo);
146 ok(status == STATUS_SUCCESS, "status: 0x%x\n", status);
147 ok(PackageInfo.fCapabilities == 0x107b3, "fCapabilities: 0x%lx\n",
148 PackageInfo.fCapabilities);
149 ok(PackageInfo.wVersion == 1, "wVersion: %d\n", PackageInfo.wVersion);
150 ok(PackageInfo.wRPCID == 14, "wRPCID: %d\n", PackageInfo.wRPCID);
151 ok(PackageInfo.cbMaxToken == 0x4000, "cbMaxToken: 0x%lx\n",
152 PackageInfo.cbMaxToken);
154 /* Second package: SChannel */
155 pTables = getNextSecPkgTable(pTables, Version);
158 status = pTables->GetInfo(&PackageInfo);
159 ok(status == STATUS_SUCCESS, "status: 0x%x\n", status);
160 ok(PackageInfo.fCapabilities == 0x107b3, "fCapabilities: 0x%lx\n",
161 PackageInfo.fCapabilities);
162 ok(PackageInfo.wVersion == 1, "wVersion: %d\n", PackageInfo.wVersion);
163 ok(PackageInfo.wRPCID == 14, "wRPCID: %d\n", PackageInfo.wRPCID);
164 ok(PackageInfo.cbMaxToken == 0x4000, "cbMaxToken: 0x%lx\n",
165 PackageInfo.cbMaxToken);
170 HMODULE hMod = LoadLibraryA("schannel.dll");
172 skip("schannel.dll not found.\n");
176 pSpLsaModeInitialize = (void *)GetProcAddress(hMod, "SpLsaModeInitialize");
177 pSpUserModeInitialize = (void *)GetProcAddress(hMod, "SpUserModeInitialize");
179 if (pSpLsaModeInitialize && pSpUserModeInitialize)
184 else skip( "schannel functions not found\n" );