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 static NTSTATUS (NTAPI *pSpLsaModeInitialize)(ULONG, PULONG,
36 PSECPKG_FUNCTION_TABLE*, PULONG);
37 static NTSTATUS (NTAPI *pSpUserModeInitialize)(ULONG, PULONG,
38 PSECPKG_USER_FUNCTION_TABLE*, PULONG);
40 static void testInitialize(void)
42 PSECPKG_USER_FUNCTION_TABLE pUserTables, pUserTables2;
43 PSECPKG_FUNCTION_TABLE pTables, pTables2;
44 ULONG cTables = 0, cUserTables = 0, Version = 0;
47 /* Passing NULL into one of the parameters of SpLsaModeInitialize or
48 SpUserModeInitialize causes a crash. */
50 /* SpLsaModeInitialize does not care about the LSA version. */
51 status = pSpLsaModeInitialize(0, &Version, &pTables2, &cTables);
52 ok(status == STATUS_SUCCESS, "status: 0x%x\n", status);
53 ok(cTables == 2, "cTables: %d\n", cTables);
54 ok(pTables2 != NULL,"pTables: %p\n", pTables2);
56 /* We can call it as many times we want. */
57 status = pSpLsaModeInitialize(0x10000, &Version, &pTables, &cTables);
58 ok(status == STATUS_SUCCESS, "status: 0x%x\n", status);
59 ok(cTables == 2, "cTables: %d\n", cTables);
60 ok(pTables != NULL, "pTables: %p\n", pTables);
61 /* It will always return the same pointer. */
62 ok(pTables == pTables2, "pTables: %p, pTables2: %p\n", pTables, pTables2);
64 status = pSpLsaModeInitialize(0x23456, &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 ok(pTables == pTables2, "pTables: %p, pTables2: %p\n", pTables, pTables2);
70 /* Bad versions to SpUserModeInitialize. Parameters unchanged */
74 status = pSpUserModeInitialize(0, &Version, &pUserTables, &cUserTables);
75 ok(status == STATUS_INVALID_PARAMETER, "status: 0x%x\n", status);
76 ok(Version == 0xdead, "Version: 0x%x\n", Version);
77 ok(cUserTables == 0xdead, "cTables: %d\n", cUserTables);
78 ok(pUserTables == NULL, "pUserTables: %p\n", pUserTables);
80 status = pSpUserModeInitialize(0x20000, &Version, &pUserTables,
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 /* Good version to SpUserModeInitialize */
88 status = pSpUserModeInitialize(SECPKG_INTERFACE_VERSION, &Version,
89 &pUserTables, &cUserTables);
90 ok(status == STATUS_SUCCESS, "status: 0x%x\n", status);
91 ok(Version == SECPKG_INTERFACE_VERSION, "Version: 0x%x\n", Version);
92 ok(cUserTables == 2, "cUserTables: %d\n", cUserTables);
93 ok(pUserTables != NULL, "pUserTables: %p\n", pUserTables);
95 /* Initializing user again */
96 status = pSpUserModeInitialize(SECPKG_INTERFACE_VERSION, &Version,
97 &pUserTables2, &cTables);
98 ok(status == STATUS_SUCCESS, "status: 0x%x\n", status);
99 ok(pUserTables == pUserTables2, "pUserTables: %p, pUserTables2: %p\n",
100 pUserTables, pUserTables2);
103 /* A helper function to find the dispatch table of the next package.
104 Needed because SECPKG_FUNCTION_TABLE's size depend on the version */
105 static PSECPKG_FUNCTION_TABLE getNextSecPkgTable(PSECPKG_FUNCTION_TABLE pTable,
110 if (Version == SECPKG_INTERFACE_VERSION)
111 size = SECPKG_FUNCTION_TABLE_SIZE_1;
112 else if (Version == SECPKG_INTERFACE_VERSION_2)
113 size = SECPKG_FUNCTION_TABLE_SIZE_2;
114 else if (Version == SECPKG_INTERFACE_VERSION_3)
115 size = SECPKG_FUNCTION_TABLE_SIZE_3;
117 ok(FALSE, "Unknown package version 0x%x\n", Version);
121 return (PSECPKG_FUNCTION_TABLE)((PBYTE)pTable + size);
124 static void testGetInfo(void)
126 PSECPKG_FUNCTION_TABLE pTables;
127 SecPkgInfoW PackageInfo;
128 ULONG cTables, Version;
131 /* Get the dispatch table */
132 status = pSpLsaModeInitialize(0, &Version, &pTables, &cTables);
133 ok(status == STATUS_SUCCESS, "status: 0x%x\n", status);
135 /* Passing NULL into ->GetInfo causes a crash. */
137 /* First package: Unified */
138 status = pTables->GetInfo(&PackageInfo);
139 ok(status == STATUS_SUCCESS, "status: 0x%x\n", status);
140 ok(PackageInfo.fCapabilities == 0x107b3, "fCapabilities: 0x%lx\n",
141 PackageInfo.fCapabilities);
142 ok(PackageInfo.wVersion == 1, "wVersion: %d\n", PackageInfo.wVersion);
143 ok(PackageInfo.wRPCID == 14, "wRPCID: %d\n", PackageInfo.wRPCID);
144 ok(PackageInfo.cbMaxToken == 0x4000, "cbMaxToken: 0x%lx\n",
145 PackageInfo.cbMaxToken);
147 /* Second package: SChannel */
148 pTables = getNextSecPkgTable(pTables, Version);
151 status = pTables->GetInfo(&PackageInfo);
152 ok(status == STATUS_SUCCESS, "status: 0x%x\n", status);
153 ok(PackageInfo.fCapabilities == 0x107b3, "fCapabilities: 0x%lx\n",
154 PackageInfo.fCapabilities);
155 ok(PackageInfo.wVersion == 1, "wVersion: %d\n", PackageInfo.wVersion);
156 ok(PackageInfo.wRPCID == 14, "wRPCID: %d\n", PackageInfo.wRPCID);
157 ok(PackageInfo.cbMaxToken == 0x4000, "cbMaxToken: 0x%lx\n",
158 PackageInfo.cbMaxToken);
163 HMODULE hMod = LoadLibraryA("schannel.dll");
165 skip("schannel.dll not found.\n");
169 pSpLsaModeInitialize = GetProcAddress(hMod, "SpLsaModeInitialize");
170 pSpUserModeInitialize = GetProcAddress(hMod, "SpUserModeInitialize");
172 if (pSpLsaModeInitialize && pSpUserModeInitialize)
177 else skip( "schannel functions not found\n" );