ReactOS  0.4.15-dev-1049-g1062a29
main.c File Reference
#include <stdio.h>
#include <stdarg.h>
#include "ntstatus.h"
#include <windef.h>
#include <winbase.h>
#include <security.h>
#include <schannel.h>
#include <ntsecapi.h>
#include <ntsecpkg.h>
#include "wine/test.h"
Include dependency graph for main.c:

Go to the source code of this file.

Macros

#define WIN32_NO_STATUS
 
#define SECURITY_WIN32
 
#define SECPKG_FUNCTION_TABLE_SIZE_1
 
#define SECPKG_FUNCTION_TABLE_SIZE_2
 
#define SECPKG_FUNCTION_TABLE_SIZE_3
 
#define SECPKG_FUNCTION_TABLE_SIZE_4
 
#define SECPKG_FUNCTION_TABLE_SIZE_5
 
#define SECPKG_FUNCTION_TABLE_SIZE_6
 
#define SECPKG_FUNCTION_TABLE_SIZE_7   sizeof(SECPKG_FUNCTION_TABLE)
 
#define LSA_BASE_CAPS
 

Functions

static NTSTATUS (NTAPI *pSpLsaModeInitialize)(ULONG
 
static void testInitialize (void)
 
static PSECPKG_FUNCTION_TABLE getNextSecPkgTable (PSECPKG_FUNCTION_TABLE pTable, ULONG Version)
 
static void testGetInfo (void)
 
 START_TEST (main)
 

Variables

static PULONG
 

Macro Definition Documentation

◆ LSA_BASE_CAPS

#define LSA_BASE_CAPS
Value:
( \
SECPKG_FLAG_INTEGRITY | \
SECPKG_FLAG_PRIVACY | \
SECPKG_FLAG_CONNECTION | \
SECPKG_FLAG_MULTI_REQUIRED | \
SECPKG_FLAG_EXTENDED_ERROR | \
SECPKG_FLAG_IMPERSONATION | \
SECPKG_FLAG_ACCEPT_WIN32_NAME | \
SECPKG_FLAG_STREAM | \
SECPKG_FLAG_MUTUAL_AUTH )

Definition at line 50 of file main.c.

◆ SECPKG_FUNCTION_TABLE_SIZE_1

#define SECPKG_FUNCTION_TABLE_SIZE_1
Value:
#define SetContextAttributes
Definition: sspi.h:942
#define FIELD_OFFSET(t, f)
Definition: typedefs.h:255

Definition at line 36 of file main.c.

◆ SECPKG_FUNCTION_TABLE_SIZE_2

#define SECPKG_FUNCTION_TABLE_SIZE_2
Value:
SetCredentialsAttributes)
#define FIELD_OFFSET(t, f)
Definition: typedefs.h:255

Definition at line 38 of file main.c.

◆ SECPKG_FUNCTION_TABLE_SIZE_3

#define SECPKG_FUNCTION_TABLE_SIZE_3
Value:
ChangeAccountPassword)
#define FIELD_OFFSET(t, f)
Definition: typedefs.h:255

Definition at line 40 of file main.c.

◆ SECPKG_FUNCTION_TABLE_SIZE_4

#define SECPKG_FUNCTION_TABLE_SIZE_4
Value:
QueryMetaData)
#define FIELD_OFFSET(t, f)
Definition: typedefs.h:255

Definition at line 42 of file main.c.

◆ SECPKG_FUNCTION_TABLE_SIZE_5

#define SECPKG_FUNCTION_TABLE_SIZE_5
Value:
ValidateTargetInfo)
#define FIELD_OFFSET(t, f)
Definition: typedefs.h:255

Definition at line 44 of file main.c.

◆ SECPKG_FUNCTION_TABLE_SIZE_6

#define SECPKG_FUNCTION_TABLE_SIZE_6
Value:
PostLogonUser)
#define FIELD_OFFSET(t, f)
Definition: typedefs.h:255

Definition at line 46 of file main.c.

◆ SECPKG_FUNCTION_TABLE_SIZE_7

#define SECPKG_FUNCTION_TABLE_SIZE_7   sizeof(SECPKG_FUNCTION_TABLE)

Definition at line 48 of file main.c.

◆ SECURITY_WIN32

#define SECURITY_WIN32

Definition at line 27 of file main.c.

◆ WIN32_NO_STATUS

#define WIN32_NO_STATUS

Definition at line 24 of file main.c.

Function Documentation

◆ getNextSecPkgTable()

static PSECPKG_FUNCTION_TABLE getNextSecPkgTable ( PSECPKG_FUNCTION_TABLE  pTable,
ULONG  Version 
)
static

Definition at line 139 of file main.c.

141 {
142  size_t size;
143  PSECPKG_FUNCTION_TABLE pNextTable;
144 
159  else {
160  ok(FALSE, "Unknown package version 0x%x\n", Version);
161  return NULL;
162  }
163 
164  pNextTable = (PSECPKG_FUNCTION_TABLE)((PBYTE)pTable + size);
165  /* Win7 function tables appear to be SECPKG_INTERFACE_VERSION_6 format,
166  but unfortunately SpLsaModeInitialize returns SECPKG_INTERFACE_VERSION_3.
167  We detect that by comparing the "Initialize" pointer from the old table
168  to the "FreeCredentialsHandle" pointer of the new table. These functions
169  have different numbers of arguments, so they can't possibly point to the
170  same implementation */
171  if (broken((void *) pTable->Initialize == (void *) pNextTable->FreeCredentialsHandle &&
172  pNextTable->FreeCredentialsHandle != NULL))
173  {
174  win_skip("Invalid function pointers for next package\n");
175  return NULL;
176  }
177 
178  return pNextTable;
179 }
#define SECPKG_INTERFACE_VERSION_3
Definition: ntsecpkg.h:36
#define SECPKG_FUNCTION_TABLE_SIZE_5
Definition: main.c:44
IN PVOID IN PVOID IN USHORT Version
Definition: pci.h:361
SpFreeCredentialsHandleFn * FreeCredentialsHandle
Definition: ntsecpkg.h:479
#define SECPKG_INTERFACE_VERSION_6
Definition: ntsecpkg.h:39
#define FALSE
Definition: types.h:117
#define SECPKG_INTERFACE_VERSION_2
Definition: ntsecpkg.h:35
smooth NULL
Definition: ftsmooth.c:416
#define SECPKG_INTERFACE_VERSION
Definition: ntsecpkg.h:34
#define SECPKG_FUNCTION_TABLE_SIZE_7
Definition: main.c:48
#define SECPKG_FUNCTION_TABLE_SIZE_4
Definition: main.c:42
GLsizeiptr size
Definition: glext.h:5919
#define SECPKG_INTERFACE_VERSION_7
Definition: ntsecpkg.h:40
#define SECPKG_FUNCTION_TABLE_SIZE_2
Definition: main.c:38
#define SECPKG_FUNCTION_TABLE_SIZE_1
Definition: main.c:36
#define broken(x)
Definition: _sntprintf.h:21
struct _SECPKG_FUNCTION_TABLE * PSECPKG_FUNCTION_TABLE
#define ok(value,...)
Definition: atltest.h:57
#define SECPKG_FUNCTION_TABLE_SIZE_6
Definition: main.c:46
static const EHCI_PERIOD pTable[]
Definition: usbehci.c:29
#define SECPKG_FUNCTION_TABLE_SIZE_3
Definition: main.c:40
#define SECPKG_INTERFACE_VERSION_5
Definition: ntsecpkg.h:38
#define win_skip
Definition: test.h:149
BYTE * PBYTE
Definition: pedump.c:66
#define SECPKG_INTERFACE_VERSION_4
Definition: ntsecpkg.h:37

Referenced by testGetInfo().

◆ NTSTATUS()

static NTSTATUS ( NTAPI pSpLsaModeInitialize)
static

◆ START_TEST()

START_TEST ( main  )

Definition at line 240 of file main.c.

241 {
242  HMODULE hMod = LoadLibraryA("schannel.dll");
243  if (!hMod) {
244  win_skip("schannel.dll not available\n");
245  return;
246  }
247 
248  pSpLsaModeInitialize = (void *)GetProcAddress(hMod, "SpLsaModeInitialize");
249  pSpUserModeInitialize = (void *)GetProcAddress(hMod, "SpUserModeInitialize");
250 
251  if (pSpLsaModeInitialize && pSpUserModeInitialize)
252  {
253  testInitialize();
254  testGetInfo();
255  }
256  else win_skip( "schannel functions not found\n" );
257 
258  FreeLibrary(hMod);
259 }
HINSTANCE WINAPI DECLSPEC_HOTPATCH LoadLibraryA(LPCSTR lpLibFileName)
Definition: loader.c:111
#define FreeLibrary(x)
Definition: compat.h:496
static void testGetInfo(void)
Definition: main.c:181
static void testInitialize(void)
Definition: main.c:66
#define GetProcAddress(x, y)
Definition: compat.h:501
#define win_skip
Definition: test.h:149

◆ testGetInfo()

static void testGetInfo ( void  )
static

Definition at line 181 of file main.c.

182 {
183  PSECPKG_FUNCTION_TABLE pTables;
184  SecPkgInfoW PackageInfo;
185  ULONG cTables, Version;
187 
188  /* Get the dispatch table */
189  status = pSpLsaModeInitialize(0, &Version, &pTables, &cTables);
190  ok(status == STATUS_SUCCESS, "status: 0x%x\n", status);
191 
192  /* Passing NULL into ->GetInfo causes a crash. */
193 
194  /* First package: Unified */
195  status = pTables->GetInfo(&PackageInfo);
196  ok(status == STATUS_SUCCESS, "status: 0x%x\n", status);
197  ok(PackageInfo.fCapabilities == LSA_BASE_CAPS ||
199  "fCapabilities: 0x%x\n", PackageInfo.fCapabilities);
200  ok(PackageInfo.wVersion == 1, "wVersion: %d\n", PackageInfo.wVersion);
201  ok(PackageInfo.wRPCID == 14, "wRPCID: %d\n", PackageInfo.wRPCID);
202  ok(PackageInfo.cbMaxToken == 0x4000 ||
203  PackageInfo.cbMaxToken == 0x6000, /* Vista */
204  "cbMaxToken: 0x%x\n",
205  PackageInfo.cbMaxToken);
206 
207  /* Second package */
208  if (cTables == 1)
209  {
210  win_skip("Second package missing\n");
211  return;
212  }
213  pTables = getNextSecPkgTable(pTables, Version);
214  if (!pTables)
215  return;
216  if (!pTables->GetInfo)
217  {
218  win_skip("GetInfo function missing\n");
219  return;
220  }
221  status = pTables->GetInfo(&PackageInfo);
222  ok(SUCCEEDED(status) ||
223  status == SEC_E_UNSUPPORTED_FUNCTION, /* win2k3 */
224  "status: 0x%x\n", status);
225 
226  if (SUCCEEDED(status))
227  {
228  ok(PackageInfo.fCapabilities == LSA_BASE_CAPS ||
230  "fCapabilities: 0x%x\n", PackageInfo.fCapabilities);
231  ok(PackageInfo.wVersion == 1, "wVersion: %d\n", PackageInfo.wVersion);
232  ok(PackageInfo.wRPCID == 14, "wRPCID: %d\n", PackageInfo.wRPCID);
233  ok(PackageInfo.cbMaxToken == 0x4000 ||
234  PackageInfo.cbMaxToken == 0x6000, /* Win7 */
235  "cbMaxToken: 0x%x\n",
236  PackageInfo.cbMaxToken);
237  }
238 }
IN PVOID IN PVOID IN USHORT Version
Definition: pci.h:361
LONG NTSTATUS
Definition: precomp.h:26
unsigned short wVersion
Definition: sspi.h:115
#define SEC_E_UNSUPPORTED_FUNCTION
Definition: winerror.h:2911
ULONG fCapabilities
Definition: sspi.h:114
ULONG cbMaxToken
Definition: sspi.h:117
unsigned short wRPCID
Definition: sspi.h:116
static PSECPKG_FUNCTION_TABLE getNextSecPkgTable(PSECPKG_FUNCTION_TABLE pTable, ULONG Version)
Definition: main.c:139
#define ok(value,...)
Definition: atltest.h:57
SpGetInfoFn * GetInfo
Definition: ntsecpkg.h:475
#define SECPKG_FLAG_APPCONTAINER_PASSTHROUGH
Definition: sspi.h:148
unsigned int ULONG
Definition: retypes.h:1
#define LSA_BASE_CAPS
Definition: main.c:50
return STATUS_SUCCESS
Definition: btrfs.c:3014
static SERVICE_STATUS status
Definition: service.c:31
#define win_skip
Definition: test.h:149
#define SUCCEEDED(hr)
Definition: intsafe.h:49
Definition: ps.c:97

Referenced by START_TEST().

◆ testInitialize()

static void testInitialize ( void  )
static

Definition at line 66 of file main.c.

67 {
68  PSECPKG_USER_FUNCTION_TABLE pUserTables, pUserTables2;
69  PSECPKG_FUNCTION_TABLE pTables, pTables2;
70  ULONG cTables = 0, cUserTables = 0, Version = 0;
72 
73  /* Passing NULL into one of the parameters of SpLsaModeInitialize or
74  SpUserModeInitialize causes a crash. */
75 
76  /* SpLsaModeInitialize does not care about the LSA version. */
77  status = pSpLsaModeInitialize(0, &Version, &pTables2, &cTables);
78  ok(status == STATUS_SUCCESS, "status: 0x%x\n", status);
79  ok(cTables == 2 ||
80  broken(cTables == 1), /* Win2k */
81  "cTables: %d\n", cTables);
82  ok(pTables2 != NULL,"pTables: %p\n", pTables2);
83 
84  /* We can call it as many times we want. */
85  status = pSpLsaModeInitialize(0x10000, &Version, &pTables, &cTables);
86  ok(status == STATUS_SUCCESS, "status: 0x%x\n", status);
87  ok(cTables == 2 ||
88  broken(cTables == 1), /* Win2k */
89  "cTables: %d\n", cTables);
90  ok(pTables != NULL, "pTables: %p\n", pTables);
91  /* It will always return the same pointer. */
92  ok(pTables == pTables2, "pTables: %p, pTables2: %p\n", pTables, pTables2);
93 
94  status = pSpLsaModeInitialize(0x23456, &Version, &pTables, &cTables);
95  ok(status == STATUS_SUCCESS, "status: 0x%x\n", status);
96  ok(cTables == 2 ||
97  broken(cTables == 1), /* Win2k */
98  "cTables: %d\n", cTables);
99  ok(pTables != NULL, "pTables: %p\n", pTables);
100  ok(pTables == pTables2, "pTables: %p, pTables2: %p\n", pTables, pTables2);
101 
102  /* Bad versions to SpUserModeInitialize. Parameters unchanged */
103  Version = 0xdead;
104  cUserTables = 0xdead;
105  pUserTables = NULL;
106  status = pSpUserModeInitialize(0, &Version, &pUserTables, &cUserTables);
107  ok(status == STATUS_INVALID_PARAMETER, "status: 0x%x\n", status);
108  ok(Version == 0xdead, "Version: 0x%x\n", Version);
109  ok(cUserTables == 0xdead, "cTables: %d\n", cUserTables);
110  ok(pUserTables == NULL, "pUserTables: %p\n", pUserTables);
111 
112  status = pSpUserModeInitialize(0x20000, &Version, &pUserTables,
113  &cUserTables);
114  ok(status == STATUS_INVALID_PARAMETER, "status: 0x%x\n", status);
115  ok(Version == 0xdead, "Version: 0x%x\n", Version);
116  ok(cUserTables == 0xdead, "cTables: %d\n", cUserTables);
117  ok(pUserTables == NULL, "pUserTables: %p\n", pUserTables);
118 
119  /* Good version to SpUserModeInitialize */
120  status = pSpUserModeInitialize(SECPKG_INTERFACE_VERSION, &Version,
121  &pUserTables, &cUserTables);
122  ok(status == STATUS_SUCCESS, "status: 0x%x\n", status);
123  ok(Version == SECPKG_INTERFACE_VERSION, "Version: 0x%x\n", Version);
124  ok(cUserTables == 2 ||
125  broken(cUserTables == 4), /* Win2k */
126  "cUserTables: %d\n", cUserTables);
127  ok(pUserTables != NULL, "pUserTables: %p\n", pUserTables);
128 
129  /* Initializing user again */
130  status = pSpUserModeInitialize(SECPKG_INTERFACE_VERSION, &Version,
131  &pUserTables2, &cTables);
132  ok(status == STATUS_SUCCESS, "status: 0x%x\n", status);
133  ok(pUserTables == pUserTables2, "pUserTables: %p, pUserTables2: %p\n",
134  pUserTables, pUserTables2);
135 }
IN PVOID IN PVOID IN USHORT Version
Definition: pci.h:361
#define STATUS_INVALID_PARAMETER
Definition: udferr_usr.h:135
LONG NTSTATUS
Definition: precomp.h:26
smooth NULL
Definition: ftsmooth.c:416
#define SECPKG_INTERFACE_VERSION
Definition: ntsecpkg.h:34
#define broken(x)
Definition: _sntprintf.h:21
#define ok(value,...)
Definition: atltest.h:57
unsigned int ULONG
Definition: retypes.h:1
return STATUS_SUCCESS
Definition: btrfs.c:3014
static SERVICE_STATUS status
Definition: service.c:31
Definition: ps.c:97

Referenced by START_TEST().

Variable Documentation

◆ PULONG

Definition at line 61 of file main.c.