shdocvw: Support URLs passed by reference in WebBrowser_Navigate2.
[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 /* Helper macros to find the size of SECPKG_FUNCTION_TABLE */
36 #define SECPKG_FUNCTION_TABLE_SIZE_1 FIELD_OFFSET(SECPKG_FUNCTION_TABLE, \
37     SetContextAttributes)
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)
41
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);
46
47 static void testInitialize(void)
48 {
49     PSECPKG_USER_FUNCTION_TABLE pUserTables, pUserTables2;
50     PSECPKG_FUNCTION_TABLE pTables, pTables2;
51     ULONG cTables = 0, cUserTables = 0, Version = 0;
52     NTSTATUS status;
53
54     /* Passing NULL into one of the parameters of SpLsaModeInitialize or
55        SpUserModeInitialize causes a crash. */
56
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 ||
61        broken(cTables == 1), /* Win2k */
62        "cTables: %d\n", cTables);
63     ok(pTables2 != NULL,"pTables: %p\n", pTables2);
64
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);
68     ok(cTables == 2 ||
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);
74
75     status = pSpLsaModeInitialize(0x23456, &Version, &pTables, &cTables);
76     ok(status == STATUS_SUCCESS, "status: 0x%x\n", status);
77     ok(cTables == 2 ||
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);
82
83     /* Bad versions to SpUserModeInitialize. Parameters unchanged */
84     Version = 0xdead;
85     cUserTables = 0xdead;
86     pUserTables = NULL;
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);
92
93     status = pSpUserModeInitialize(0x20000, &Version, &pUserTables,
94                                    &cUserTables);
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);
99
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);
109
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);
116 }
117
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,
121                                                  ULONG Version)
122 {
123     size_t size;
124
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;
131     else {
132         ok(FALSE, "Unknown package version 0x%x\n", Version);
133         return NULL;
134     }
135
136     return (PSECPKG_FUNCTION_TABLE)((PBYTE)pTable + size);
137 }
138
139 static void testGetInfo(void)
140 {
141     PSECPKG_FUNCTION_TABLE pTables;
142     SecPkgInfoW PackageInfo;
143     ULONG cTables, Version;
144     NTSTATUS status;
145
146     /* Get the dispatch table */
147     status = pSpLsaModeInitialize(0, &Version, &pTables, &cTables);
148     ok(status == STATUS_SUCCESS, "status: 0x%x\n", status);
149
150     /* Passing NULL into ->GetInfo causes a crash. */
151
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);
163
164     /* Second package */
165     if (cTables == 1)
166     {
167         win_skip("Second package missing\n");
168         return;
169     }
170     pTables = getNextSecPkgTable(pTables, Version);
171     if (!pTables)
172         return;
173     status = pTables->GetInfo(&PackageInfo);
174     ok(status == STATUS_SUCCESS ||
175        status == SEC_E_UNSUPPORTED_FUNCTION, /* win2k3 */
176        "status: 0x%x\n", status);
177
178     if (status == STATUS_SUCCESS)
179     {
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);
186     }
187 }
188
189 START_TEST(main)
190 {
191     HMODULE hMod = LoadLibraryA("schannel.dll");
192     if (!hMod) {
193         win_skip("schannel.dll not available\n");
194         return;
195     }
196
197     pSpLsaModeInitialize  = (void *)GetProcAddress(hMod, "SpLsaModeInitialize");
198     pSpUserModeInitialize = (void *)GetProcAddress(hMod, "SpUserModeInitialize");
199
200     if (pSpLsaModeInitialize && pSpUserModeInitialize)
201     {
202         testInitialize();
203         testGetInfo();
204     }
205     else win_skip( "schannel functions not found\n" );
206
207     FreeLibrary(hMod);
208 }