mcicda: Exclude unused headers.
[wine] / dlls / schannel / tests / main.c
1 /*
2  * Schannel tests
3  *
4  * Copyright 2006 Yuval Fledel
5  *
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.
10  *
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.
15  *
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
19  */
20
21 #include <stdio.h>
22 #include <stdarg.h>
23 #include "ntstatus.h"
24 #define WIN32_NO_STATUS
25 #include <windef.h>
26 #include <winbase.h>
27 #define SECURITY_WIN32
28 #include <security.h>
29 #include <schannel.h>
30 #include <ntsecapi.h>
31 #include <ntsecpkg.h>
32
33 #include "wine/test.h"
34
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);
39
40 static void testInitialize(void)
41 {
42     PSECPKG_USER_FUNCTION_TABLE pUserTables, pUserTables2;
43     PSECPKG_FUNCTION_TABLE pTables, pTables2;
44     ULONG cTables = 0, cUserTables = 0, Version = 0;
45     NTSTATUS status;
46
47     /* Passing NULL into one of the parameters of SpLsaModeInitialize or
48        SpUserModeInitialize causes a crash. */
49
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);
55
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);
63
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);
69
70     /* Bad versions to SpUserModeInitialize. Parameters unchanged */
71     Version = 0xdead;
72     cUserTables = 0xdead;
73     pUserTables = NULL;
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);
79
80     status = pSpUserModeInitialize(0x20000, &Version, &pUserTables,
81                                    &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);
86
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);
94
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);
101 }
102
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,
106                                                  ULONG Version)
107 {
108     size_t size;
109
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;
116     else {
117         ok(FALSE, "Unknown package version 0x%x\n", Version);
118         return NULL;
119     }
120
121     return (PSECPKG_FUNCTION_TABLE)((PBYTE)pTable + size);
122 }
123
124 static void testGetInfo(void)
125 {
126     PSECPKG_FUNCTION_TABLE pTables;
127     SecPkgInfoW PackageInfo;
128     ULONG cTables, Version;
129     NTSTATUS status;
130
131     /* Get the dispatch table */
132     status = pSpLsaModeInitialize(0, &Version, &pTables, &cTables);
133     ok(status == STATUS_SUCCESS, "status: 0x%x\n", status);
134
135     /* Passing NULL into ->GetInfo causes a crash. */
136
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);
146
147     /* Second package: SChannel */
148     pTables = getNextSecPkgTable(pTables, Version);
149     if (!pTables)
150         return;
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);
159 }
160
161 START_TEST(main)
162 {
163     HMODULE hMod = LoadLibraryA("schannel.dll");
164     if (!hMod) {
165         skip("schannel.dll not found.\n");
166         return;
167     }
168
169     pSpLsaModeInitialize  = GetProcAddress(hMod, "SpLsaModeInitialize");
170     pSpUserModeInitialize = GetProcAddress(hMod, "SpUserModeInitialize");
171
172     if (pSpLsaModeInitialize && pSpUserModeInitialize)
173     {
174         testInitialize();
175         testGetInfo();
176     }
177     else skip( "schannel functions not found\n" );
178
179     FreeLibrary(hMod);
180 }