ReactOS 0.4.15-dev-8093-g3285f69
main.c
Go to the documentation of this file.
1/*
2 * Miscellaneous secur32 tests
3 *
4 * Copyright 2005, 2006 Kai Blin
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#define SECURITY_WIN32
22
23#include <stdarg.h>
24#include <stdio.h>
25
26#include <windef.h>
27#include <winbase.h>
28#include <sspi.h>
29
30#include "wine/test.h"
31
33static PSecurityFunctionTableA (SEC_ENTRY * pInitSecurityInterfaceA)(void);
34static SECURITY_STATUS (SEC_ENTRY * pEnumerateSecurityPackagesA)(PULONG, PSecPkgInfoA*);
35static SECURITY_STATUS (SEC_ENTRY * pFreeContextBuffer)(PVOID pv);
36static SECURITY_STATUS (SEC_ENTRY * pQuerySecurityPackageInfoA)(SEC_CHAR*, PSecPkgInfoA*);
37static SECURITY_STATUS (SEC_ENTRY * pAcquireCredentialsHandleA)(SEC_CHAR*, SEC_CHAR*,
39static SECURITY_STATUS (SEC_ENTRY * pInitializeSecurityContextA)(PCredHandle, PCtxtHandle,
42static SECURITY_STATUS (SEC_ENTRY * pCompleteAuthToken)(PCtxtHandle, PSecBufferDesc);
43static SECURITY_STATUS (SEC_ENTRY * pAcceptSecurityContext)(PCredHandle, PCtxtHandle,
46static SECURITY_STATUS (SEC_ENTRY * pFreeCredentialsHandle)(PCredHandle);
47static SECURITY_STATUS (SEC_ENTRY * pDeleteSecurityContext)(PCtxtHandle);
49
50static void InitFunctionPtrs(void)
51{
52 secdll = LoadLibraryA("secur32.dll");
53 if(!secdll)
54 secdll = LoadLibraryA("security.dll");
55 if(secdll)
56 {
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");
68 }
69}
70
71/*---------------------------------------------------------*/
72/* General helper functions */
73
75{
76 static char buf[20];
77
78#define _SEC_ERR(x) case (x): return #x;
79 switch(status)
80 {
100 default:
101 sprintf(buf, "%08x\n", status);
102 return buf;
103 }
104#undef _SEC_ERR
105}
106
107/*---------------------------------------------------------*/
108/* Helper for testQuerySecurityPagageInfo */
109
110static SECURITY_STATUS setupPackageA(SEC_CHAR *p_package_name,
111 PSecPkgInfoA *p_pkg_info)
112{
114
115 ret = pQuerySecurityPackageInfoA( p_package_name, p_pkg_info);
116 return ret;
117}
118
119/*--------------------------------------------------------- */
120/* The test functions */
121
123{
124 PSecurityFunctionTableA sec_fun_table = NULL;
125
126 sec_fun_table = pInitSecurityInterfaceA();
127 ok(sec_fun_table != NULL, "InitSecurityInterface() returned NULL.\n");
128
129}
130
132{
133
134 SECURITY_STATUS sec_status;
135 ULONG num_packages, i;
136 PSecPkgInfoA pkg_info = NULL;
137
138 trace("Running testEnumerateSecurityPackages\n");
139
140 sec_status = pEnumerateSecurityPackagesA(&num_packages, &pkg_info);
141
142 ok(sec_status == SEC_E_OK,
143 "EnumerateSecurityPackages() should return %d, not %08x\n",
144 SEC_E_OK, sec_status);
145
146 if (num_packages == 0)
147 {
149 ok(num_packages > 0, "Number of sec packages should be > 0 ,but is %d\n",
150 num_packages);
151 skip("no sec packages to check\n");
152 return;
153 }
154 else
155 ok(num_packages > 0, "Number of sec packages should be > 0 ,but is %d\n",
156 num_packages);
157
158 ok(pkg_info != NULL,
159 "pkg_info should not be NULL after EnumerateSecurityPackages\n");
160
161 trace("Number of packages: %d\n", num_packages);
162 for(i = 0; i < num_packages; ++i){
163 trace("%d: Package \"%s\"\n", i, pkg_info[i].Name);
164 trace("Supported flags:\n");
165#define X(flag) \
166 if(pkg_info[i].fCapabilities & flag) \
167 trace("\t" #flag "\n")
168
193#undef X
194 trace("Comment: %s\n", pkg_info[i].Comment);
195 trace("\n");
196 }
197
198 pFreeContextBuffer(pkg_info);
199}
200
201
203{
204 SECURITY_STATUS sec_status;
205 PSecPkgInfoA pkg_info;
206 static SEC_CHAR ntlm[] = "NTLM",
207 winetest[] = "Winetest";
208
209 trace("Running testQuerySecurityPackageInfo\n");
210
211 /* Test with an existing package. Test should pass */
212
213 pkg_info = (void *)0xdeadbeef;
214 sec_status = setupPackageA(ntlm, &pkg_info);
215
216 ok((sec_status == SEC_E_OK) || (sec_status == SEC_E_SECPKG_NOT_FOUND) ||
217 broken(sec_status == SEC_E_UNSUPPORTED_FUNCTION), /* win95 */
218 "Return value of QuerySecurityPackageInfo() shouldn't be %s\n",
219 getSecError(sec_status) );
220
221 if (sec_status == SEC_E_OK)
222 {
223 ok(pkg_info != (void *)0xdeadbeef, "wrong pkg_info address %p\n", pkg_info);
224 ok(pkg_info->wVersion == 1, "wVersion always should be 1, but is %d\n", pkg_info->wVersion);
225 /* there is no point in testing pkg_info->cbMaxToken since it varies
226 * between implementations.
227 */
228
229 sec_status = pFreeContextBuffer(pkg_info);
230 ok( sec_status == SEC_E_OK,
231 "Return value of FreeContextBuffer() shouldn't be %s\n",
232 getSecError(sec_status) );
233 }
234
235 /* Test with a nonexistent package, test should fail */
236
237 pkg_info = (void *)0xdeadbeef;
238 sec_status = pQuerySecurityPackageInfoA(winetest, &pkg_info);
239
240 ok( sec_status == SEC_E_SECPKG_NOT_FOUND,
241 "Return value of QuerySecurityPackageInfo() should be %s for a nonexistent package\n",
243
244 ok(pkg_info == (void *)0xdeadbeef, "wrong pkg_info address %p\n", pkg_info);
245}
246
248{
250 if(pInitSecurityInterfaceA)
252 if(pFreeContextBuffer)
253 {
254 if(pEnumerateSecurityPackagesA)
256 if(pQuerySecurityPackageInfoA)
257 {
259 }
260 }
261 if(secdll)
263}
#define broken(x)
Definition: _sntprintf.h:21
@ Comment
Definition: asmpp.cpp:34
#define ok(value,...)
Definition: atltest.h:57
#define skip(...)
Definition: atltest.h:64
#define START_TEST(x)
Definition: atltest.h:75
int trace
Definition: main.c:57
#define NULL
Definition: types.h:112
#define GetProcAddress(x, y)
Definition: compat.h:753
#define FreeLibrary(x)
Definition: compat.h:748
HINSTANCE WINAPI DECLSPEC_HOTPATCH LoadLibraryA(LPCSTR lpLibFileName)
Definition: loader.c:111
#define X(x)
#define SEC_ENTRY
Definition: stubs.c:6
int main()
Definition: test.c:6
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
#define sprintf(buf, format,...)
Definition: sprintf.c:55
#define todo_wine
Definition: custom.c:79
static PULONG
Definition: main.c:61
static void testEnumerateSecurityPackages(void)
Definition: main.c:131
static HMODULE secdll
Definition: main.c:32
static void testQuerySecurityPackageInfo(void)
Definition: main.c:202
static PSecPkgInfoA *static SEC_CHAR PLUID
Definition: main.c:38
static void InitFunctionPtrs(void)
Definition: main.c:50
static SECURITY_STATUS setupPackageA(SEC_CHAR *p_package_name, PSecPkgInfoA *p_pkg_info)
Definition: main.c:110
static PSecPkgInfoA *static SEC_CHAR PCredHandle
Definition: main.c:38
static void testInitSecurityInterface(void)
Definition: main.c:122
static const char * getSecError(SECURITY_STATUS status)
Definition: main.c:74
#define _SEC_ERR(x)
static PCtxtHandle
Definition: main.c:39
static PSecPkgInfoA *static SEC_CHAR SEC_GET_KEY_FN
Definition: main.c:38
static PSecPkgInfoA *static SEC_CHAR PTimeStamp
Definition: main.c:38
static SEC_CHAR PSecBufferDesc
Definition: main.c:40
static CHAR winetest[]
Definition: info.c:56
#define SECPKG_FLAG_APPCONTAINER_CHECKS
Definition: sspi.h:149
#define SECPKG_FLAG_TOKEN_ONLY
Definition: sspi.h:128
LONG SECURITY_STATUS
Definition: sspi.h:34
#define SECPKG_FLAG_IMPERSONATION
Definition: sspi.h:134
#define SECPKG_FLAG_CLIENT_ONLY
Definition: sspi.h:132
#define SECPKG_FLAG_APPCONTAINER_PASSTHROUGH
Definition: sspi.h:148
#define SECPKG_FLAG_STREAM
Definition: sspi.h:136
#define SECPKG_FLAG_EXTENDED_ERROR
Definition: sspi.h:133
#define SECPKG_FLAG_PRIVACY
Definition: sspi.h:127
CHAR SEC_CHAR
Definition: sspi.h:30
#define SECPKG_FLAG_RESTRICTED_TOKENS
Definition: sspi.h:145
#define SECPKG_FLAG_MULTI_REQUIRED
Definition: sspi.h:131
#define SECPKG_FLAG_CONNECTION
Definition: sspi.h:130
#define SECPKG_FLAG_NEGOTIABLE
Definition: sspi.h:137
#define SECPKG_FLAG_DELEGATION
Definition: sspi.h:143
#define SECPKG_FLAG_INTEGRITY
Definition: sspi.h:126
#define SECPKG_FLAG_ASCII_BUFFERS
Definition: sspi.h:140
struct _SECURITY_FUNCTION_TABLE_A * PSecurityFunctionTableA
#define SECPKG_FLAG_MUTUAL_AUTH
Definition: sspi.h:142
#define SECPKG_FLAG_DATAGRAM
Definition: sspi.h:129
#define SECPKG_FLAG_NEGO_EXTENDER
Definition: sspi.h:146
#define SECPKG_FLAG_NEGOTIABLE2
Definition: sspi.h:147
#define SECPKG_FLAG_LOGON
Definition: sspi.h:139
#define SECPKG_FLAG_READONLY_WITH_CHECKSUM
Definition: sspi.h:144
#define SECPKG_FLAG_FRAGMENT
Definition: sspi.h:141
#define SECPKG_FLAG_ACCEPT_WIN32_NAME
Definition: sspi.h:135
#define SECPKG_FLAG_GSS_COMPATIBLE
Definition: sspi.h:138
static QUERY_CONTEXT_ATTRIBUTES_FN_A pQueryContextAttributesA
Definition: schannel.c:32
unsigned short wVersion
Definition: sspi.h:105
Definition: ps.c:97
void * PVOID
Definition: typedefs.h:50
uint32_t ULONG
Definition: typedefs.h:59
int ret
#define SEC_E_OK
Definition: winerror.h:2356
#define SEC_E_INVALID_HANDLE
Definition: winerror.h:2910
#define SEC_E_LOGON_DENIED
Definition: winerror.h:2921
#define SEC_E_INTERNAL_ERROR
Definition: winerror.h:2913
#define SEC_E_CANNOT_INSTALL
Definition: winerror.h:2916
#define SEC_E_NO_IMPERSONATION
Definition: winerror.h:2920
#define SEC_E_UNSUPPORTED_FUNCTION
Definition: winerror.h:2911
#define SEC_E_NOT_OWNER
Definition: winerror.h:2915
#define SEC_E_BUFFER_TOO_SMALL
Definition: winerror.h:2937
#define SEC_E_ILLEGAL_MESSAGE
Definition: winerror.h:2943
#define SEC_E_SECPKG_NOT_FOUND
Definition: winerror.h:2914
#define SEC_E_CANNOT_PACK
Definition: winerror.h:2918
#define SEC_E_INVALID_TOKEN
Definition: winerror.h:2917
#define SEC_E_OUT_OF_SEQUENCE
Definition: winerror.h:2925
#define SEC_E_NO_CREDENTIALS
Definition: winerror.h:2923
#define SEC_E_QOP_NOT_SUPPORTED
Definition: winerror.h:2919
#define SEC_E_INSUFFICIENT_MEMORY
Definition: winerror.h:2909
#define SEC_I_CONTINUE_NEEDED
Definition: winerror.h:2927
#define SEC_E_TARGET_UNKNOWN
Definition: winerror.h:2912