From 67986ea298aa0e12dab478441e0ae783c7bbeda0 Mon Sep 17 00:00:00 2001 From: David Fort Date: Fri, 12 Nov 2021 11:20:04 +0100 Subject: [PATCH] Fix compilation with mingw This patch addresses some issues when compiling against mingw. With these changes FreeRDP can be compiled out-of-the box on a Ubuntu 20.04. --- channels/audin/client/winmm/audin_winmm.c | 5 ++ client/Windows/CMakeLists.txt | 4 +- client/Windows/cli/wfreerdp.c | 2 +- client/Windows/{ => resource}/FreeRDP.ico | Bin client/Windows/{ => resource}/resource.h | 0 client/Windows/resource/wfreerdp.rc | 14 +++++ client/Windows/wf_client.c | 2 +- client/Windows/wf_floatbar.c | 4 +- client/Windows/wfreerdp.rc | 14 ----- libfreerdp/CMakeLists.txt | 3 + winpr/include/winpr/error.h | 9 +++ winpr/include/winpr/pool.h | 61 +++++++++++-------- winpr/include/winpr/smartcard.h | 18 ++++++ winpr/include/winpr/spec.h | 2 + winpr/include/winpr/sspi.h | 52 +++++++++++++--- winpr/libwinpr/sspi/NTLM/ntlm.h | 15 +++++ winpr/libwinpr/utils/collections/ArrayList.c | 2 +- winpr/libwinpr/wtsapi/wtsapi.c | 10 ++- 18 files changed, 162 insertions(+), 55 deletions(-) rename client/Windows/{ => resource}/FreeRDP.ico (100%) rename client/Windows/{ => resource}/resource.h (100%) create mode 100644 client/Windows/resource/wfreerdp.rc delete mode 100644 client/Windows/wfreerdp.rc diff --git a/channels/audin/client/winmm/audin_winmm.c b/channels/audin/client/winmm/audin_winmm.c index 5532d81b7..158ec1f03 100644 --- a/channels/audin/client/winmm/audin_winmm.c +++ b/channels/audin/client/winmm/audin_winmm.c @@ -37,6 +37,11 @@ #include "audin_main.h" +/* fix missing definitions in mingw */ +#ifndef WAVE_MAPPED_DEFAULT_COMMUNICATION_DEVICE +#define WAVE_MAPPED_DEFAULT_COMMUNICATION_DEVICE 0x0010 +#endif + typedef struct _AudinWinmmDevice { IAudinDevice iface; diff --git a/client/Windows/CMakeLists.txt b/client/Windows/CMakeLists.txt index f707954ea..c2e88411a 100644 --- a/client/Windows/CMakeLists.txt +++ b/client/Windows/CMakeLists.txt @@ -35,8 +35,8 @@ set(${MODULE_PREFIX}_SRCS wf_client.h wf_floatbar.c wf_floatbar.h - wfreerdp.rc - resource.h) + resource/wfreerdp.rc + resource/resource.h) # On windows create dll version information. # Vendor, product and year are already set in top level CMakeLists.txt diff --git a/client/Windows/cli/wfreerdp.c b/client/Windows/cli/wfreerdp.c index 1346c458a..4e1770b72 100644 --- a/client/Windows/cli/wfreerdp.c +++ b/client/Windows/cli/wfreerdp.c @@ -36,7 +36,7 @@ #include #include -#include "resource.h" +#include "../resource/resource.h" #include "wf_client.h" diff --git a/client/Windows/FreeRDP.ico b/client/Windows/resource/FreeRDP.ico similarity index 100% rename from client/Windows/FreeRDP.ico rename to client/Windows/resource/FreeRDP.ico diff --git a/client/Windows/resource.h b/client/Windows/resource/resource.h similarity index 100% rename from client/Windows/resource.h rename to client/Windows/resource/resource.h diff --git a/client/Windows/resource/wfreerdp.rc b/client/Windows/resource/wfreerdp.rc new file mode 100644 index 000000000..71446c599 --- /dev/null +++ b/client/Windows/resource/wfreerdp.rc @@ -0,0 +1,14 @@ + +#include "resource.h" + +IDI_ICON1 ICON "FreeRDP.ico" +IDB_MINIMIZE BITMAP "minimize.bmp" +IDB_MINIMIZE_ACT BITMAP "minimize_active.bmp" +IDB_LOCK BITMAP "lock.bmp" +IDB_LOCK_ACT BITMAP "lock_active.bmp" +IDB_UNLOCK BITMAP "unlock.bmp" +IDB_UNLOCK_ACT BITMAP "unlock_active.bmp" +IDB_CLOSE BITMAP "close.bmp" +IDB_CLOSE_ACT BITMAP "close_active.bmp" +IDB_RESTORE BITMAP "restore.bmp" +IDB_RESTORE_ACT BITMAP "restore_active.bmp" diff --git a/client/Windows/wf_client.c b/client/Windows/wf_client.c index 79955e2fe..a52a1b57b 100644 --- a/client/Windows/wf_client.c +++ b/client/Windows/wf_client.c @@ -64,7 +64,7 @@ #include "wf_client.h" -#include "resource.h" +#include "resource/resource.h" #define TAG CLIENT_TAG("windows") diff --git a/client/Windows/wf_floatbar.c b/client/Windows/wf_floatbar.c index e07e3767a..cb84b626f 100644 --- a/client/Windows/wf_floatbar.c +++ b/client/Windows/wf_floatbar.c @@ -20,10 +20,10 @@ #include #include -#include "resource.h" - #include "wf_client.h" #include "wf_floatbar.h" + +#include "resource/resource.h" #include "wf_gdi.h" #ifdef _MSC_VER #pragma comment(lib, "Msimg32.lib") diff --git a/client/Windows/wfreerdp.rc b/client/Windows/wfreerdp.rc deleted file mode 100644 index cec908f46..000000000 --- a/client/Windows/wfreerdp.rc +++ /dev/null @@ -1,14 +0,0 @@ - -#include "resource.h" - -IDI_ICON1 ICON "FreeRDP.ico" -IDB_MINIMIZE BITMAP "resource\\minimize.bmp" -IDB_MINIMIZE_ACT BITMAP "resource\\minimize_active.bmp" -IDB_LOCK BITMAP "resource\\lock.bmp" -IDB_LOCK_ACT BITMAP "resource\\lock_active.bmp" -IDB_UNLOCK BITMAP "resource\\unlock.bmp" -IDB_UNLOCK_ACT BITMAP "resource\\unlock_active.bmp" -IDB_CLOSE BITMAP "resource\\close.bmp" -IDB_CLOSE_ACT BITMAP "resource\\close_active.bmp" -IDB_RESTORE BITMAP "resource\\restore.bmp" -IDB_RESTORE_ACT BITMAP "resource\\restore_active.bmp" diff --git a/libfreerdp/CMakeLists.txt b/libfreerdp/CMakeLists.txt index eb5194d18..7ce5dbf66 100644 --- a/libfreerdp/CMakeLists.txt +++ b/libfreerdp/CMakeLists.txt @@ -392,6 +392,9 @@ if (WITH_LIBRARY_VERSIONING) set_target_properties(${MODULE_NAME} PROPERTIES VERSION ${FREERDP_VERSION} SOVERSION ${FREERDP_API_VERSION}) endif() +if (MINGW) + freerdp_library_add(ucrt) +endif() target_link_libraries(${MODULE_NAME} PRIVATE ${LIBFREERDP_LIBS} winpr) diff --git a/winpr/include/winpr/error.h b/winpr/include/winpr/error.h index 02c67d23d..856d1b3a1 100644 --- a/winpr/include/winpr/error.h +++ b/winpr/include/winpr/error.h @@ -27,6 +27,15 @@ #include +/* mingw is possibly missing some definitions */ +#ifndef RPC_S_PROXY_ACCESS_DENIED +#define RPC_S_PROXY_ACCESS_DENIED 0x000006C1 +#endif + +#ifndef RPC_S_COOKIE_AUTH_FAILED +#define RPC_S_COOKIE_AUTH_FAILED 0x00000729 +#endif + #else #ifndef NO_ERROR diff --git a/winpr/include/winpr/pool.h b/winpr/include/winpr/pool.h index 93ba94812..c27fa0fd8 100644 --- a/winpr/include/winpr/pool.h +++ b/winpr/include/winpr/pool.h @@ -86,7 +86,7 @@ typedef VOID (*PTP_TIMER_CALLBACK)(PTP_CALLBACK_INSTANCE Instance, PVOID Context typedef VOID (*PTP_WAIT_CALLBACK)(PTP_CALLBACK_INSTANCE Instance, PVOID Context, PTP_WAIT Wait, TP_WAIT_RESULT WaitResult); -#endif +#endif /* _WIN32 not defined */ /* There is a bug in the Win8 header that defines the IO @@ -210,6 +210,42 @@ extern "C" #define SetThreadpoolThreadMinimum winpr_SetThreadpoolThreadMinimum #define SetThreadpoolThreadMaximum winpr_SetThreadpoolThreadMaximum + + /* Callback */ + + WINPR_API BOOL winpr_CallbackMayRunLong(PTP_CALLBACK_INSTANCE pci); + + /* Callback Clean-up */ + + WINPR_API VOID winpr_SetEventWhenCallbackReturns(PTP_CALLBACK_INSTANCE pci, HANDLE evt); + WINPR_API VOID winpr_ReleaseSemaphoreWhenCallbackReturns(PTP_CALLBACK_INSTANCE pci, HANDLE sem, + DWORD crel); + WINPR_API VOID winpr_ReleaseMutexWhenCallbackReturns(PTP_CALLBACK_INSTANCE pci, HANDLE mut); + WINPR_API VOID winpr_LeaveCriticalSectionWhenCallbackReturns(PTP_CALLBACK_INSTANCE pci, + PCRITICAL_SECTION pcs); + WINPR_API VOID winpr_FreeLibraryWhenCallbackReturns(PTP_CALLBACK_INSTANCE pci, HMODULE mod); + WINPR_API VOID winpr_DisassociateCurrentThreadFromCallback(PTP_CALLBACK_INSTANCE pci); + +#define SetEventWhenCallbackReturns winpr_SetEventWhenCallbackReturns +#define ReleaseSemaphoreWhenCallbackReturns winpr_ReleaseSemaphoreWhenCallbackReturns +#define ReleaseMutexWhenCallbackReturns winpr_ReleaseMutexWhenCallbackReturns +#define LeaveCriticalSectionWhenCallbackReturns winpr_LeaveCriticalSectionWhenCallbackReturns +#define FreeLibraryWhenCallbackReturns winpr_FreeLibraryWhenCallbackReturns +#define DisassociateCurrentThreadFromCallback winpr_DisassociateCurrentThreadFromCallback + +#endif /* WINPR_THREAD_POOL */ + +#if !defined(_WIN32) +#define WINPR_CALLBACK_ENVIRON 1 +#elif defined(_WIN32) && (_WIN32_WINNT < 0x0600) +#define WINPR_CALLBACK_ENVIRON 1 +#elif defined(__MINGW32__) && (__MINGW64_VERSION_MAJOR < 9) +#define WINPR_CALLBACK_ENVIRON 1 +#endif + +#ifdef WINPR_CALLBACK_ENVIRON + /* some version of mingw are missing Callback Environment functions */ + /* Callback Environment */ static INLINE VOID InitializeThreadpoolEnvironment(PTP_CALLBACK_ENVIRON pcbe) @@ -243,29 +279,6 @@ extern "C" { pcbe->RaceDll = mod; } - - /* Callback */ - - WINPR_API BOOL winpr_CallbackMayRunLong(PTP_CALLBACK_INSTANCE pci); - - /* Callback Clean-up */ - - WINPR_API VOID winpr_SetEventWhenCallbackReturns(PTP_CALLBACK_INSTANCE pci, HANDLE evt); - WINPR_API VOID winpr_ReleaseSemaphoreWhenCallbackReturns(PTP_CALLBACK_INSTANCE pci, HANDLE sem, - DWORD crel); - WINPR_API VOID winpr_ReleaseMutexWhenCallbackReturns(PTP_CALLBACK_INSTANCE pci, HANDLE mut); - WINPR_API VOID winpr_LeaveCriticalSectionWhenCallbackReturns(PTP_CALLBACK_INSTANCE pci, - PCRITICAL_SECTION pcs); - WINPR_API VOID winpr_FreeLibraryWhenCallbackReturns(PTP_CALLBACK_INSTANCE pci, HMODULE mod); - WINPR_API VOID winpr_DisassociateCurrentThreadFromCallback(PTP_CALLBACK_INSTANCE pci); - -#define SetEventWhenCallbackReturns winpr_SetEventWhenCallbackReturns -#define ReleaseSemaphoreWhenCallbackReturns winpr_ReleaseSemaphoreWhenCallbackReturns -#define ReleaseMutexWhenCallbackReturns winpr_ReleaseMutexWhenCallbackReturns -#define LeaveCriticalSectionWhenCallbackReturns winpr_LeaveCriticalSectionWhenCallbackReturns -#define FreeLibraryWhenCallbackReturns winpr_FreeLibraryWhenCallbackReturns -#define DisassociateCurrentThreadFromCallback winpr_DisassociateCurrentThreadFromCallback - #endif #ifdef __cplusplus diff --git a/winpr/include/winpr/smartcard.h b/winpr/include/winpr/smartcard.h index 5303922b2..4ec89f5c6 100644 --- a/winpr/include/winpr/smartcard.h +++ b/winpr/include/winpr/smartcard.h @@ -115,6 +115,24 @@ #endif +/* ------------------------ missing definition with mingw --------------------*/ +#ifndef SCARD_E_PIN_CACHE_EXPIRED +#define SCARD_E_PIN_CACHE_EXPIRED (HRESULT)(0x80100032L) +#endif + +#ifndef SCARD_E_NO_PIN_CACHE +#define SCARD_E_NO_PIN_CACHE (HRESULT)(0x80100033L) +#endif + +#ifndef SCARD_E_READ_ONLY_CARD +#define SCARD_E_READ_ONLY_CARD (HRESULT)(0x80100034L) +#endif + +#ifndef SCARD_W_CACHE_ITEM_TOO_BIG +#define SCARD_W_CACHE_ITEM_TOO_BIG (HRESULT)(0x80100072L) +#endif +/* -------------------------------------------------------------------------- */ + #define SCARD_ATR_LENGTH 33 #define SCARD_PROTOCOL_UNDEFINED 0x00000000u diff --git a/winpr/include/winpr/spec.h b/winpr/include/winpr/spec.h index d1a2d740a..198f74725 100644 --- a/winpr/include/winpr/spec.h +++ b/winpr/include/winpr/spec.h @@ -965,6 +965,7 @@ extern "C++" #endif +#if !defined(__MINGW32__) #if defined(_WIN32) || defined(__CYGWIN__) #ifdef __GNUC__ #define DECLSPEC_EXPORT __attribute__((dllexport)) @@ -982,5 +983,6 @@ extern "C++" #define DECLSPEC_IMPORT #endif #endif +#endif #endif /* WINPR_SPEC_H */ diff --git a/winpr/include/winpr/sspi.h b/winpr/include/winpr/sspi.h index 71b168b43..97ae99a10 100644 --- a/winpr/include/winpr/sspi.h +++ b/winpr/include/winpr/sspi.h @@ -222,6 +222,41 @@ typedef SecPkgInfoW* PSecPkgInfoW; #endif +/* ============== some definitions missing in mingw ========================*/ +#ifndef SEC_E_INVALID_PARAMETER +#define SEC_E_INVALID_PARAMETER (SECURITY_STATUS)0x8009035DL +#endif + +#ifndef SEC_E_DELEGATION_POLICY +#define SEC_E_DELEGATION_POLICY (SECURITY_STATUS)0x8009035EL +#endif + +#ifndef SEC_E_POLICY_NLTM_ONLY +#define SEC_E_POLICY_NLTM_ONLY (SECURITY_STATUS)0x8009035FL +#endif + +#ifndef SEC_E_NO_CONTEXT +#define SEC_E_NO_CONTEXT (SECURITY_STATUS)0x80090361L +#endif + +#ifndef SEC_E_PKU2U_CERT_FAILURE +#define SEC_E_PKU2U_CERT_FAILURE (SECURITY_STATUS)0x80090362L +#endif + +#ifndef SEC_E_MUTUAL_AUTH_FAILED +#define SEC_E_MUTUAL_AUTH_FAILED (SECURITY_STATUS)0x80090363L +#endif + +#ifndef SEC_I_SIGNATURE_NEEDED +#define SEC_I_SIGNATURE_NEEDED (SECURITY_STATUS)0x0009035CL +#endif + +#ifndef SEC_I_NO_RENEGOTIATION +#define SEC_I_NO_RENEGOTIATION (SECURITY_STATUS)0x00090360L +#endif + +/* ==================================================================================== */ + #define SECURITY_NATIVE_DREP 0x00000010 #define SECURITY_NETWORK_DREP 0x00000000 @@ -334,13 +369,6 @@ struct _SEC_CHANNEL_BINDINGS }; typedef struct _SEC_CHANNEL_BINDINGS SEC_CHANNEL_BINDINGS; -struct _SecPkgContext_Bindings -{ - UINT32 BindingsLength; - SEC_CHANNEL_BINDINGS* Bindings; -}; -typedef struct _SecPkgContext_Bindings SecPkgContext_Bindings; - struct _SecPkgContext_EapKeyBlock { BYTE rgbKeys[128]; @@ -485,6 +513,16 @@ typedef SecPkgCredentials_NamesW* PSecPkgCredentials_NamesW; #endif +#if !defined(_WIN32) || defined(_UWP) || defined(__MINGW32__) +struct _SecPkgContext_Bindings +{ + UINT32 BindingsLength; + SEC_CHANNEL_BINDINGS* Bindings; +}; +typedef struct _SecPkgContext_Bindings SecPkgContext_Bindings; +#endif + + /* InitializeSecurityContext Flags */ #define ISC_REQ_DELEGATE 0x00000001 diff --git a/winpr/libwinpr/sspi/NTLM/ntlm.h b/winpr/libwinpr/sspi/NTLM/ntlm.h index 21ae893a3..1f24e7962 100644 --- a/winpr/libwinpr/sspi/NTLM/ntlm.h +++ b/winpr/libwinpr/sspi/NTLM/ntlm.h @@ -77,6 +77,20 @@ enum _NTLM_STATE }; typedef enum _NTLM_STATE NTLM_STATE; +#ifdef __MINGW32__ +typedef MSV1_0_AVID NTLM_AV_ID; + +#if __MINGW64_VERSION_MAJOR < 9 +enum { + MsvAvTimestamp = MsvAvFlags + 1, + MsvAvRestrictions, + MsvAvTargetName, + MsvAvChannelBindings, + MsvAvSingleHost = MsvAvRestrictions +}; + +#endif +#else enum _NTLM_AV_ID { MsvAvEOL, @@ -92,6 +106,7 @@ enum _NTLM_AV_ID MsvAvChannelBindings }; typedef enum _NTLM_AV_ID NTLM_AV_ID; +#endif /* __MINGW32__ */ struct _NTLM_AV_PAIR { diff --git a/winpr/libwinpr/utils/collections/ArrayList.c b/winpr/libwinpr/utils/collections/ArrayList.c index e4f52fc75..5f09693ed 100644 --- a/winpr/libwinpr/utils/collections/ArrayList.c +++ b/winpr/libwinpr/utils/collections/ArrayList.c @@ -27,7 +27,7 @@ #include #include -#if defined(_WIN32) && (_MSC_VER < 1800) +#if defined(_WIN32) && (_MSC_VER < 1800) && !defined(__MINGW32__) #define va_copy(dest, src) (dest = src) #endif diff --git a/winpr/libwinpr/wtsapi/wtsapi.c b/winpr/libwinpr/wtsapi/wtsapi.c index 04c59f9fa..7c49ac46a 100644 --- a/winpr/libwinpr/wtsapi/wtsapi.c +++ b/winpr/libwinpr/wtsapi/wtsapi.c @@ -52,9 +52,13 @@ static const WtsApiFunctionTable* g_WtsApi = NULL; static HMODULE g_WtsApi32Module = NULL; static WtsApiFunctionTable WtsApi32_WtsApiFunctionTable = { 0 }; -#define WTSAPI32_LOAD_PROC(_name, _type) \ - WtsApi32_WtsApiFunctionTable.p##_name = (##_type)GetProcAddress(g_WtsApi32Module, "WT" \ - "S" #_name); +#ifdef __MINGW32__ +#define WTSAPI32_LOAD_PROC(NAME, TYPE) \ + WtsApi32_WtsApiFunctionTable.p##NAME = (TYPE)GetProcAddress(g_WtsApi32Module, "WTS" #NAME); +#else +#define WTSAPI32_LOAD_PROC(NAME, TYPE) \ + WtsApi32_WtsApiFunctionTable.p##NAME = (##TYPE)GetProcAddress(g_WtsApi32Module, "WTS" #NAME); +#endif static BOOL WtsApi32_InitializeWtsApi(void) {