winpr: fix unit tests on Windows

This commit is contained in:
Marc-André Moreau 2013-09-19 13:50:00 -04:00
parent 929d292f35
commit 0c17eb1a23
8 changed files with 215 additions and 117 deletions

View File

@ -280,50 +280,6 @@ enum FILE_FS_DEVICE_FLAG
FILE_DEVICE_SECURE_OPEN = 0x00000100
};
enum FILE_INFORMATION_CLASS
{
FileDirectoryInformation = 1,
FileFullDirectoryInformation,
FileBothDirectoryInformation,
FileBasicInformation,
FileStandardInformation,
FileInternalInformation,
FileEaInformation,
FileAccessInformation,
FileNameInformation,
FileRenameInformation,
FileLinkInformation,
FileNamesInformation,
FileDispositionInformation,
FilePositionInformation,
FileFullEaInformation,
FileModeInformation,
FileAlignmentInformation,
FileAllInformation,
FileAllocationInformation,
FileEndOfFileInformation,
FileAlternateNameInformation,
FileStreamInformation,
FilePipeInformation,
FilePipeLocalInformation,
FilePipeRemoteInformation,
FileMailslotQueryInformation,
FileMailslotSetInformation,
FileCompressionInformation,
FileObjectIdInformation,
FileUnknownInformation1,
FileMoveClusterInformation,
FileQuotaInformation,
FileReparsePointInformation,
FileNetworkOpenInformation,
FileAttributeTagInformation,
FileTrackingInformation,
FileIdBothDirectoryInformation,
FileIdFullDirectoryInformation,
FileValidDataLengthInformation,
FileShortNameInformation
};
enum FILE_FS_INFORMATION_CLASS
{
FileFsVolumeInformation = 1,

View File

@ -23,6 +23,7 @@
#include <winpr/winpr.h>
#include <winpr/wtypes.h>
#include <winpr/nt.h>
#include <winpr/sspi.h>
#include <winpr/error.h>
#include <winpr/credentials.h>

View File

@ -87,6 +87,29 @@
#endif
/* Defined in wincred.h, do not redefine */
#ifdef _WIN32
#include <wincred.h>
#else
#define STATUS_LOGON_FAILURE ((NTSTATUS)0xC000006DL)
#define STATUS_WRONG_PASSWORD ((NTSTATUS)0xC000006AL)
#define STATUS_PASSWORD_EXPIRED ((NTSTATUS)0xC0000071L)
#define STATUS_PASSWORD_MUST_CHANGE ((NTSTATUS)0xC0000224L)
#define STATUS_ACCESS_DENIED ((NTSTATUS)0xC0000022L)
#define STATUS_DOWNGRADE_DETECTED ((NTSTATUS)0xC0000388L)
#define STATUS_AUTHENTICATION_FIREWALL_FAILED ((NTSTATUS)0xC0000413L)
#define STATUS_ACCOUNT_DISABLED ((NTSTATUS)0xC0000072L)
#define STATUS_ACCOUNT_RESTRICTION ((NTSTATUS)0xC000006EL)
#define STATUS_ACCOUNT_LOCKED_OUT ((NTSTATUS)0xC0000234L)
#define STATUS_ACCOUNT_EXPIRED ((NTSTATUS)0xC0000193L)
#define STATUS_LOGON_TYPE_NOT_GRANTED ((NTSTATUS)0xC000015BL)
#endif
#define FACILITY_DEBUGGER 0x1
#define FACILITY_RPC_RUNTIME 0x2
#define FACILITY_RPC_STUBS 0x3
@ -309,7 +332,7 @@
#define STATUS_INVALID_VIEW_SIZE ((NTSTATUS)0xC000001F)
#define STATUS_INVALID_FILE_FOR_SECTION ((NTSTATUS)0xC0000020)
#define STATUS_ALREADY_COMMITTED ((NTSTATUS)0xC0000021)
#define STATUS_ACCESS_DENIED ((NTSTATUS)0xC0000022)
//#define STATUS_ACCESS_DENIED ((NTSTATUS)0xC0000022)
#define STATUS_BUFFER_TOO_SMALL ((NTSTATUS)0xC0000023)
#define STATUS_OBJECT_TYPE_MISMATCH ((NTSTATUS)0xC0000024)
//#define STATUS_NONCONTINUABLE_EXCEPTION ((NTSTATUS)0xC0000025)
@ -380,15 +403,15 @@
#define STATUS_MEMBER_IN_GROUP ((NTSTATUS)0xC0000067)
#define STATUS_MEMBER_NOT_IN_GROUP ((NTSTATUS)0xC0000068)
#define STATUS_LAST_ADMIN ((NTSTATUS)0xC0000069)
#define STATUS_WRONG_PASSWORD ((NTSTATUS)0xC000006A)
//#define STATUS_WRONG_PASSWORD ((NTSTATUS)0xC000006A)
#define STATUS_ILL_FORMED_PASSWORD ((NTSTATUS)0xC000006B)
#define STATUS_PASSWORD_RESTRICTION ((NTSTATUS)0xC000006C)
#define STATUS_LOGON_FAILURE ((NTSTATUS)0xC000006D)
#define STATUS_ACCOUNT_RESTRICTION ((NTSTATUS)0xC000006E)
//#define STATUS_LOGON_FAILURE ((NTSTATUS)0xC000006D)
//#define STATUS_ACCOUNT_RESTRICTION ((NTSTATUS)0xC000006E)
#define STATUS_INVALID_LOGON_HOURS ((NTSTATUS)0xC000006F)
#define STATUS_INVALID_WORKSTATION ((NTSTATUS)0xC0000070)
#define STATUS_PASSWORD_EXPIRED ((NTSTATUS)0xC0000071)
#define STATUS_ACCOUNT_DISABLED ((NTSTATUS)0xC0000072)
//#define STATUS_PASSWORD_EXPIRED ((NTSTATUS)0xC0000071)
//#define STATUS_ACCOUNT_DISABLED ((NTSTATUS)0xC0000072)
#define STATUS_NONE_MAPPED ((NTSTATUS)0xC0000073)
#define STATUS_TOO_MANY_LUIDS_REQUESTED ((NTSTATUS)0xC0000074)
#define STATUS_LUIDS_EXHAUSTED ((NTSTATUS)0xC0000075)
@ -621,7 +644,7 @@
#define STATUS_INTERNAL_DB_ERROR ((NTSTATUS)0xC0000158)
#define STATUS_FULLSCREEN_MODE ((NTSTATUS)0xC0000159)
#define STATUS_TOO_MANY_CONTEXT_IDS ((NTSTATUS)0xC000015A)
#define STATUS_LOGON_TYPE_NOT_GRANTED ((NTSTATUS)0xC000015B)
//#define STATUS_LOGON_TYPE_NOT_GRANTED ((NTSTATUS)0xC000015B)
#define STATUS_NOT_REGISTRY_FILE ((NTSTATUS)0xC000015C)
#define STATUS_NT_CROSS_ENCRYPTION_REQUIRED ((NTSTATUS)0xC000015D)
#define STATUS_DOMAIN_CTRLR_CONFIG_ERROR ((NTSTATUS)0xC000015E)
@ -674,7 +697,7 @@
#define STATUS_TRUST_FAILURE ((NTSTATUS)0xC0000190)
#define STATUS_MUTANT_LIMIT_EXCEEDED ((NTSTATUS)0xC0000191)
#define STATUS_NETLOGON_NOT_STARTED ((NTSTATUS)0xC0000192)
#define STATUS_ACCOUNT_EXPIRED ((NTSTATUS)0xC0000193)
//#define STATUS_ACCOUNT_EXPIRED ((NTSTATUS)0xC0000193)
#define STATUS_POSSIBLE_DEADLOCK ((NTSTATUS)0xC0000194)
#define STATUS_NETWORK_CREDENTIAL_CONFLICT ((NTSTATUS)0xC0000195)
#define STATUS_REMOTE_SESSION_LIMIT ((NTSTATUS)0xC0000196)
@ -718,7 +741,7 @@
#define STATUS_IMAGE_CHECKSUM_MISMATCH ((NTSTATUS)0xC0000221)
#define STATUS_LOST_WRITEBEHIND_DATA ((NTSTATUS)0xC0000222)
#define STATUS_CLIENT_SERVER_PARAMETERS_INVALID ((NTSTATUS)0xC0000223)
#define STATUS_PASSWORD_MUST_CHANGE ((NTSTATUS)0xC0000224)
//#define STATUS_PASSWORD_MUST_CHANGE ((NTSTATUS)0xC0000224)
#define STATUS_NOT_FOUND ((NTSTATUS)0xC0000225)
#define STATUS_NOT_TINY_STREAM ((NTSTATUS)0xC0000226)
#define STATUS_RECOVERY_FAILURE ((NTSTATUS)0xC0000227)
@ -734,7 +757,7 @@
#define STATUS_MARSHALL_OVERFLOW ((NTSTATUS)0xC0000231)
#define STATUS_INVALID_VARIANT ((NTSTATUS)0xC0000232)
#define STATUS_DOMAIN_CONTROLLER_NOT_FOUND ((NTSTATUS)0xC0000233)
#define STATUS_ACCOUNT_LOCKED_OUT ((NTSTATUS)0xC0000234)
//#define STATUS_ACCOUNT_LOCKED_OUT ((NTSTATUS)0xC0000234)
#define STATUS_HANDLE_NOT_CLOSABLE ((NTSTATUS)0xC0000235)
#define STATUS_CONNECTION_REFUSED ((NTSTATUS)0xC0000236)
#define STATUS_GRACEFUL_DISCONNECT ((NTSTATUS)0xC0000237)
@ -968,7 +991,7 @@
#define STATUS_SMARTCARD_NO_CERTIFICATE ((NTSTATUS)0xC0000385)
#define STATUS_SMARTCARD_NO_KEYSET ((NTSTATUS)0xC0000386)
#define STATUS_SMARTCARD_IO_ERROR ((NTSTATUS)0xC0000387)
#define STATUS_DOWNGRADE_DETECTED ((NTSTATUS)0xC0000388)
//#define STATUS_DOWNGRADE_DETECTED ((NTSTATUS)0xC0000388)
#define STATUS_SMARTCARD_CERT_REVOKED ((NTSTATUS)0xC0000389)
#define STATUS_ISSUING_CA_UNTRUSTED ((NTSTATUS)0xC000038A)
#define STATUS_REVOCATION_OFFLINE_C ((NTSTATUS)0xC000038B)
@ -994,7 +1017,7 @@
#define STATUS_PARAMETER_QUOTA_EXCEEDED ((NTSTATUS)0xC0000410)
#define STATUS_HIBERNATION_FAILURE ((NTSTATUS)0xC0000411)
#define STATUS_DELAY_LOAD_FAILED ((NTSTATUS)0xC0000412)
#define STATUS_AUTHENTICATION_FIREWALL_FAILED ((NTSTATUS)0xC0000413)
//#define STATUS_AUTHENTICATION_FIREWALL_FAILED ((NTSTATUS)0xC0000413)
#define STATUS_VDM_DISALLOWED ((NTSTATUS)0xC0000414)
#define STATUS_HUNG_DISPLAY_DRIVER_THREAD ((NTSTATUS)0xC0000415)
//#define STATUS_INVALID_CRUNTIME_PARAMETER ((NTSTATUS)0xC0000417)
@ -1246,6 +1269,71 @@
/* Defined in winternl.h, always define since we do not include this header */
#ifdef _WIN32
/**
* winternl.h contains an incomplete definition of enum FILE_INFORMATION_CLASS
* avoid conflict by prefixing the winternl.h definition by _WINTERNL_ and then
* make a complete definition of enum FILE_INFORMATION_CLASS ourselves.
*
* For more information, refer to [MS-FSCC]: File System Control Codes:
* http://msdn.microsoft.com/en-us/library/cc231987.aspx
*/
#define _FILE_INFORMATION_CLASS _WINTERNL_FILE_INFORMATION_CLASS
#define FileDirectoryInformation _WINTERNL_FileDirectoryInformation
#include <winternl.h>
#undef _FILE_INFORMATION_CLASS
#undef FileDirectoryInformation
enum FILE_INFORMATION_CLASS
{
FileDirectoryInformation = 1,
FileFullDirectoryInformation,
FileBothDirectoryInformation,
FileBasicInformation,
FileStandardInformation,
FileInternalInformation,
FileEaInformation,
FileAccessInformation,
FileNameInformation,
FileRenameInformation,
FileLinkInformation,
FileNamesInformation,
FileDispositionInformation,
FilePositionInformation,
FileFullEaInformation,
FileModeInformation,
FileAlignmentInformation,
FileAllInformation,
FileAllocationInformation,
FileEndOfFileInformation,
FileAlternateNameInformation,
FileStreamInformation,
FilePipeInformation,
FilePipeLocalInformation,
FilePipeRemoteInformation,
FileMailslotQueryInformation,
FileMailslotSetInformation,
FileCompressionInformation,
FileObjectIdInformation,
FileUnknownInformation1,
FileMoveClusterInformation,
FileQuotaInformation,
FileReparsePointInformation,
FileNetworkOpenInformation,
FileAttributeTagInformation,
FileTrackingInformation,
FileIdBothDirectoryInformation,
FileIdFullDirectoryInformation,
FileValidDataLengthInformation,
FileShortNameInformation
};
#else
#define FILE_SUPERSEDE 0x00000000
#define FILE_OPEN 0x00000001
#define FILE_CREATE 0x00000002
@ -1293,7 +1381,63 @@
#define FILE_EXISTS 0x00000004
#define FILE_DOES_NOT_EXIST 0x00000005
#ifndef _WIN32
typedef CONST char *PCSZ;
typedef struct _STRING
{
USHORT Length;
USHORT MaximumLength;
PCHAR Buffer;
} STRING;
typedef STRING *PSTRING;
typedef STRING ANSI_STRING;
typedef PSTRING PANSI_STRING;
typedef PSTRING PCANSI_STRING;
typedef STRING OEM_STRING;
typedef PSTRING POEM_STRING;
typedef CONST STRING* PCOEM_STRING;
typedef struct _LSA_UNICODE_STRING
{
USHORT Length;
USHORT MaximumLength;
PWSTR Buffer;
} LSA_UNICODE_STRING, *PLSA_UNICODE_STRING, UNICODE_STRING, *PUNICODE_STRING;
#define OBJ_INHERIT 0x00000002L
#define OBJ_PERMANENT 0x00000010L
#define OBJ_EXCLUSIVE 0x00000020L
#define OBJ_CASE_INSENSITIVE 0x00000040L
#define OBJ_OPENIF 0x00000080L
#define OBJ_OPENLINK 0x00000100L
#define OBJ_KERNEL_HANDLE 0x00000200L
#define OBJ_FORCE_ACCESS_CHECK 0x00000400L
#define OBJ_VALID_ATTRIBUTES 0x000007F2L
typedef struct _OBJECT_ATTRIBUTES
{
ULONG Length;
HANDLE RootDirectory;
PUNICODE_STRING ObjectName;
ULONG Attributes;
PVOID SecurityDescriptor;
PVOID SecurityQualityOfService;
} OBJECT_ATTRIBUTES;
typedef OBJECT_ATTRIBUTES *POBJECT_ATTRIBUTES;
typedef struct _IO_STATUS_BLOCK
{
union
{
NTSTATUS status;
PVOID Pointer;
};
ULONG_PTR Information;
} IO_STATUS_BLOCK, *PIO_STATUS_BLOCK;
typedef VOID (*PIO_APC_ROUTINE)(PVOID ApcContext, PIO_STATUS_BLOCK IoStatusBlock, ULONG Reserved);
typedef struct _PEB PEB;
typedef struct _PEB* PPEB;
@ -1377,64 +1521,6 @@ struct _TEB
typedef DWORD ACCESS_MASK;
typedef ACCESS_MASK* PACCESS_MASK;
typedef CONST char *PCSZ;
typedef struct _STRING
{
USHORT Length;
USHORT MaximumLength;
PCHAR Buffer;
} STRING;
typedef STRING *PSTRING;
typedef STRING ANSI_STRING;
typedef PSTRING PANSI_STRING;
typedef PSTRING PCANSI_STRING;
typedef STRING OEM_STRING;
typedef PSTRING POEM_STRING;
typedef CONST STRING* PCOEM_STRING;
typedef struct _LSA_UNICODE_STRING
{
USHORT Length;
USHORT MaximumLength;
PWSTR Buffer;
} LSA_UNICODE_STRING, *PLSA_UNICODE_STRING, UNICODE_STRING, *PUNICODE_STRING;
#define OBJ_INHERIT 0x00000002L
#define OBJ_PERMANENT 0x00000010L
#define OBJ_EXCLUSIVE 0x00000020L
#define OBJ_CASE_INSENSITIVE 0x00000040L
#define OBJ_OPENIF 0x00000080L
#define OBJ_OPENLINK 0x00000100L
#define OBJ_KERNEL_HANDLE 0x00000200L
#define OBJ_FORCE_ACCESS_CHECK 0x00000400L
#define OBJ_VALID_ATTRIBUTES 0x000007F2L
typedef struct _OBJECT_ATTRIBUTES
{
ULONG Length;
HANDLE RootDirectory;
PUNICODE_STRING ObjectName;
ULONG Attributes;
PVOID SecurityDescriptor;
PVOID SecurityQualityOfService;
} OBJECT_ATTRIBUTES;
typedef OBJECT_ATTRIBUTES *POBJECT_ATTRIBUTES;
typedef struct _IO_STATUS_BLOCK
{
union
{
NTSTATUS status;
PVOID Pointer;
};
ULONG_PTR Information;
} IO_STATUS_BLOCK, *PIO_STATUS_BLOCK;
typedef VOID (*PIO_APC_ROUTINE)(PVOID ApcContext, PIO_STATUS_BLOCK IoStatusBlock, ULONG Reserved);
#ifdef __cplusplus
extern "C" {
#endif

View File

@ -271,6 +271,12 @@ WINPR_API BOOL CancelWaitableTimer(HANDLE hTimer);
#endif
#if ((_WIN32) && (_WIN32_WINNT < 0x0600))
WINPR_API BOOL InitializeCriticalSectionEx(LPCRITICAL_SECTION lpCriticalSection, DWORD dwSpinCount, DWORD Flags);
#endif
/* Extended API */
WINPR_API VOID USleep(DWORD dwMicroseconds);

View File

@ -5,6 +5,7 @@
int TestNtCreateFile(int argc, char* argv[])
{
#ifndef _WIN32
HANDLE handle;
NTSTATUS ntstatus;
ULONG CreateOptions;
@ -25,6 +26,7 @@ int TestNtCreateFile(int argc, char* argv[])
ntstatus = NtCreateFile(&handle, DesiredAccess, &attributes, &ioStatusBlock, 0, 0, 0, CreateOptions, 0, 0, 0);
RtlFreeUnicodeString(&uString);
#endif
return 0;
}

View File

@ -5,6 +5,7 @@
int TestNtCurrentTeb(int argc, char* argv[])
{
#ifndef _WIN32
PTEB teb;
teb = NtCurrentTeb();
@ -14,7 +15,7 @@ int TestNtCurrentTeb(int argc, char* argv[])
printf("NtCurrentTeb() returned NULL\n");
return -1;
}
#endif
return 0;
}

View File

@ -22,6 +22,7 @@
#include "config.h"
#endif
#include <winpr/tchar.h>
#include <winpr/synch.h>
#include <winpr/sysinfo.h>
#include <winpr/interlocked.h>
@ -233,3 +234,49 @@ VOID DeleteCriticalSection(LPCRITICAL_SECTION lpCriticalSection)
}
#endif
#if ((_WIN32) && (_WIN32_WINNT < 0x0600))
typedef BOOL (*PINITIALIZE_CRITICAL_SECTION_EX_FN)(LPCRITICAL_SECTION lpCriticalSection, DWORD dwSpinCount, DWORD Flags);
static HMODULE g_KERNEL32_Library = NULL;
static BOOL g_InitializeCriticalSectionEx_Detected = FALSE;
static BOOL g_InitializeCriticalSectionEx_Available = FALSE;
static PINITIALIZE_CRITICAL_SECTION_EX_FN g_pInitializeCriticalSectionEx = NULL;
BOOL InitializeCriticalSectionEx(LPCRITICAL_SECTION lpCriticalSection, DWORD dwSpinCount, DWORD Flags)
{
if (!g_InitializeCriticalSectionEx_Detected)
{
g_KERNEL32_Library = LoadLibrary(_T("kernel32.dll"));
if (g_KERNEL32_Library)
{
g_pInitializeCriticalSectionEx = (PINITIALIZE_CRITICAL_SECTION_EX_FN)
GetProcAddress(g_KERNEL32_Library, "InitializeCriticalSectionEx");
g_InitializeCriticalSectionEx_Available = (g_pInitializeCriticalSectionEx) ? TRUE : FALSE;
}
else
{
g_InitializeCriticalSectionEx_Available = FALSE;
}
g_InitializeCriticalSectionEx_Detected = TRUE;
}
if (g_InitializeCriticalSectionEx_Available)
{
/* Vista and later */
return g_pInitializeCriticalSectionEx(lpCriticalSection, dwSpinCount, Flags);
}
else
{
/* Windows XP */
InitializeCriticalSection(lpCriticalSection);
}
return TRUE;
}
#endif

View File

@ -7,7 +7,6 @@
#include <winpr/thread.h>
#include <winpr/interlocked.h>
#define TEST_SYNC_CRITICAL_TEST1_RUNTIME_MS 500
#define TEST_SYNC_CRITICAL_TEST1_RUNS 4