2 * Miscellaneous secur32 tests
4 * Copyright 2005, 2006 Kai Blin
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
21 #define SECURITY_WIN32
30 #include "wine/test.h"
32 static HMODULE secdll;
33 static PSecurityFunctionTableA (SEC_ENTRY * pInitSecurityInterfaceA)(void);
34 static SECURITY_STATUS (SEC_ENTRY * pEnumerateSecurityPackagesA)(PULONG, PSecPkgInfoA*);
35 static SECURITY_STATUS (SEC_ENTRY * pFreeContextBuffer)(PVOID pv);
36 static SECURITY_STATUS (SEC_ENTRY * pQuerySecurityPackageInfoA)(SEC_CHAR*, PSecPkgInfoA*);
37 static SECURITY_STATUS (SEC_ENTRY * pAcquireCredentialsHandleA)(SEC_CHAR*, SEC_CHAR*,
38 ULONG, PLUID, PVOID, SEC_GET_KEY_FN, PVOID, PCredHandle, PTimeStamp);
39 static SECURITY_STATUS (SEC_ENTRY * pInitializeSecurityContextA)(PCredHandle, PCtxtHandle,
40 SEC_CHAR*, ULONG, ULONG, ULONG, PSecBufferDesc, ULONG,
41 PCtxtHandle, PSecBufferDesc, PULONG, PTimeStamp);
42 static SECURITY_STATUS (SEC_ENTRY * pCompleteAuthToken)(PCtxtHandle, PSecBufferDesc);
43 static SECURITY_STATUS (SEC_ENTRY * pAcceptSecurityContext)(PCredHandle, PCtxtHandle,
44 PSecBufferDesc, ULONG, ULONG, PCtxtHandle, PSecBufferDesc,
46 static SECURITY_STATUS (SEC_ENTRY * pFreeCredentialsHandle)(PCredHandle);
47 static SECURITY_STATUS (SEC_ENTRY * pDeleteSecurityContext)(PCtxtHandle);
48 static SECURITY_STATUS (SEC_ENTRY * pQueryContextAttributesA)(PCtxtHandle, ULONG, PVOID);
50 static void InitFunctionPtrs(void)
52 secdll = LoadLibraryA("secur32.dll");
54 secdll = LoadLibraryA("security.dll");
57 pInitSecurityInterfaceA = (PVOID)GetProcAddress(secdll, "InitSecurityInterfaceA");
58 pEnumerateSecurityPackagesA = (PVOID)GetProcAddress(secdll, "EnumerateSecurityPackagesA");
59 pFreeContextBuffer = (PVOID)GetProcAddress(secdll, "FreeContextBuffer");
60 pQuerySecurityPackageInfoA = (PVOID)GetProcAddress(secdll, "QuerySecurityPackageInfoA");
61 pAcquireCredentialsHandleA = (PVOID)GetProcAddress(secdll, "AcquireCredentialsHandleA");
62 pInitializeSecurityContextA = (PVOID)GetProcAddress(secdll, "InitializeSecurityContextA");
63 pCompleteAuthToken = (PVOID)GetProcAddress(secdll, "CompleteAuthToken");
64 pAcceptSecurityContext = (PVOID)GetProcAddress(secdll, "AcceptSecurityContext");
65 pFreeCredentialsHandle = (PVOID)GetProcAddress(secdll, "FreeCredentialsHandle");
66 pDeleteSecurityContext = (PVOID)GetProcAddress(secdll, "DeleteSecurityContext");
67 pQueryContextAttributesA = (PVOID)GetProcAddress(secdll, "QueryContextAttributesA");
71 /*---------------------------------------------------------*/
72 /* General helper functions */
74 static const char* getSecError(SECURITY_STATUS status)
78 #define _SEC_ERR(x) case (x): return #x;
82 _SEC_ERR(SEC_E_INSUFFICIENT_MEMORY);
83 _SEC_ERR(SEC_E_INVALID_HANDLE);
84 _SEC_ERR(SEC_E_UNSUPPORTED_FUNCTION);
85 _SEC_ERR(SEC_E_TARGET_UNKNOWN);
86 _SEC_ERR(SEC_E_INTERNAL_ERROR);
87 _SEC_ERR(SEC_E_SECPKG_NOT_FOUND);
88 _SEC_ERR(SEC_E_NOT_OWNER);
89 _SEC_ERR(SEC_E_CANNOT_INSTALL);
90 _SEC_ERR(SEC_E_INVALID_TOKEN);
91 _SEC_ERR(SEC_E_CANNOT_PACK);
92 _SEC_ERR(SEC_E_QOP_NOT_SUPPORTED);
93 _SEC_ERR(SEC_E_NO_IMPERSONATION);
94 _SEC_ERR(SEC_I_CONTINUE_NEEDED);
95 _SEC_ERR(SEC_E_BUFFER_TOO_SMALL);
96 _SEC_ERR(SEC_E_ILLEGAL_MESSAGE);
97 _SEC_ERR(SEC_E_LOGON_DENIED);
98 _SEC_ERR(SEC_E_NO_CREDENTIALS);
99 _SEC_ERR(SEC_E_OUT_OF_SEQUENCE);
101 sprintf(buf, "%08x\n", status);
107 /*---------------------------------------------------------*/
108 /* Helper for testQuerySecurityPagageInfo */
110 static SECURITY_STATUS setupPackageA(SEC_CHAR *p_package_name,
111 PSecPkgInfo *p_pkg_info)
115 ret = pQuerySecurityPackageInfoA( p_package_name, p_pkg_info);
119 /*--------------------------------------------------------- */
120 /* The test functions */
122 static void testInitSecurityInterface(void)
124 PSecurityFunctionTable sec_fun_table = NULL;
126 sec_fun_table = pInitSecurityInterfaceA();
127 ok(sec_fun_table != NULL, "InitSecurityInterface() returned NULL.\n");
131 static void testEnumerateSecurityPackages(void)
134 SECURITY_STATUS sec_status;
135 ULONG num_packages, i;
136 PSecPkgInfo pkg_info = NULL;
138 trace("Running testEnumerateSecurityPackages\n");
140 sec_status = pEnumerateSecurityPackagesA(&num_packages, &pkg_info);
142 ok(sec_status == SEC_E_OK,
143 "EnumerateSecurityPackages() should return %d, not %08x\n",
144 SEC_E_OK, sec_status);
146 ok(num_packages > 0, "Number of sec packages should be > 0 ,but is %d\n",
150 "pkg_info should not be NULL after EnumerateSecurityPackages\n");
152 trace("Number of packages: %d\n", num_packages);
153 for(i = 0; i < num_packages; ++i){
154 trace("%d: Package \"%s\"\n", i, pkg_info[i].Name);
155 trace("Supported flags:\n");
156 if(pkg_info[i].fCapabilities & SECPKG_FLAG_INTEGRITY)
157 trace("\tSECPKG_FLAG_INTEGRITY\n");
158 if(pkg_info[i].fCapabilities & SECPKG_FLAG_PRIVACY)
159 trace("\tSECPKG_FLAG_PRIVACY\n");
160 if(pkg_info[i].fCapabilities & SECPKG_FLAG_TOKEN_ONLY)
161 trace("\tSECPKG_FLAG_TOKEN_ONLY\n");
162 if(pkg_info[i].fCapabilities & SECPKG_FLAG_DATAGRAM)
163 trace("\tSECPKG_FLAG_DATAGRAM\n");
164 if(pkg_info[i].fCapabilities & SECPKG_FLAG_CONNECTION)
165 trace("\tSECPKG_FLAG_CONNECTION\n");
166 if(pkg_info[i].fCapabilities & SECPKG_FLAG_MULTI_REQUIRED)
167 trace("\tSECPKG_FLAG_MULTI_REQUIRED\n");
168 if(pkg_info[i].fCapabilities & SECPKG_FLAG_CLIENT_ONLY)
169 trace("\tSECPKG_FLAG_CLIENT_ONLY\n");
170 if(pkg_info[i].fCapabilities & SECPKG_FLAG_EXTENDED_ERROR)
171 trace("\tSECPKG_FLAG_EXTENDED_ERROR\n");
172 if(pkg_info[i].fCapabilities & SECPKG_FLAG_IMPERSONATION)
173 trace("\tSECPKG_FLAG_IMPERSONATION\n");
174 if(pkg_info[i].fCapabilities & SECPKG_FLAG_ACCEPT_WIN32_NAME)
175 trace("\tSECPKG_FLAG_ACCEPT_WIN32_NAME\n");
176 if(pkg_info[i].fCapabilities & SECPKG_FLAG_STREAM)
177 trace("\tSECPKG_FLAG_STREAM\n");
178 if(pkg_info[i].fCapabilities & SECPKG_FLAG_READONLY_WITH_CHECKSUM)
179 trace("\tSECPKG_FLAG_READONLY_WITH_CHECKSUM\n");
180 trace("Comment: %s\n", pkg_info[i].Comment);
184 pFreeContextBuffer(pkg_info);
188 static void testQuerySecurityPackageInfo(void)
190 SECURITY_STATUS sec_status;
191 PSecPkgInfo pkg_info;
192 static SEC_CHAR ntlm[] = "NTLM",
193 winetest[] = "Winetest";
195 trace("Running testQuerySecurityPackageInfo\n");
197 /* Test with an existing package. Test should pass */
199 pkg_info = (void *)0xdeadbeef;
200 sec_status = setupPackageA(ntlm, &pkg_info);
202 ok((sec_status == SEC_E_OK) || (sec_status == SEC_E_SECPKG_NOT_FOUND),
203 "Return value of QuerySecurityPackageInfo() shouldn't be %s\n",
204 getSecError(sec_status) );
206 if (sec_status == SEC_E_OK)
208 ok(pkg_info != (void *)0xdeadbeef, "wrong pkg_info address %p\n", pkg_info);
209 ok(pkg_info->wVersion == 1, "wVersion always should be 1, but is %d\n", pkg_info->wVersion);
210 /* there is no point in testing pkg_info->cbMaxToken since it varies
211 * between implementations.
215 sec_status = pFreeContextBuffer(pkg_info);
217 ok( sec_status == SEC_E_OK,
218 "Return value of FreeContextBuffer() shouldn't be %s\n",
219 getSecError(sec_status) );
221 /* Test with a nonexistent package, test should fail */
223 pkg_info = (void *)0xdeadbeef;
224 sec_status = pQuerySecurityPackageInfoA(winetest, &pkg_info);
226 ok( sec_status == SEC_E_SECPKG_NOT_FOUND,
227 "Return value of QuerySecurityPackageInfo() should be %s for a nonexistent package\n",
228 getSecError(SEC_E_SECPKG_NOT_FOUND));
230 ok(pkg_info == (void *)0xdeadbeef, "wrong pkg_info address %p\n", pkg_info);
232 sec_status = pFreeContextBuffer(pkg_info);
234 ok( sec_status == SEC_E_OK,
235 "Return value of FreeContextBuffer() shouldn't be %s\n",
236 getSecError(sec_status) );
242 if(pInitSecurityInterfaceA)
243 testInitSecurityInterface();
244 if(pFreeContextBuffer)
246 if(pEnumerateSecurityPackagesA)
247 testEnumerateSecurityPackages();
248 if(pQuerySecurityPackageInfoA)
250 testQuerySecurityPackageInfo();