summaryrefslogtreecommitdiffstats
path: root/winpr
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--winpr/CMakeLists.txt14
-rw-r--r--winpr/include/winpr/comm.h3
-rw-r--r--winpr/include/winpr/crt.h11
-rw-r--r--winpr/include/winpr/environment.h9
-rw-r--r--winpr/include/winpr/file.h13
-rw-r--r--winpr/include/winpr/intrin.h2
-rw-r--r--winpr/include/winpr/io.h2
-rw-r--r--winpr/include/winpr/memory.h6
-rw-r--r--winpr/include/winpr/pipe.h3
-rw-r--r--winpr/include/winpr/pool.h2
-rw-r--r--winpr/include/winpr/synch.h39
-rw-r--r--winpr/include/winpr/sysinfo.h11
-rw-r--r--winpr/include/winpr/thread.h2
-rw-r--r--winpr/include/winpr/winpr.h10
-rw-r--r--winpr/include/winpr/winsock.h4
-rw-r--r--winpr/include/winpr/wtsapi.h10
-rw-r--r--winpr/libwinpr/CMakeLists.txt29
-rw-r--r--winpr/libwinpr/clipboard/synthetic_file.c20
-rw-r--r--winpr/libwinpr/comm/comm.c6
-rw-r--r--winpr/libwinpr/comm/comm_io.c8
-rw-r--r--winpr/libwinpr/comm/comm_serial_sys.c18
-rw-r--r--winpr/libwinpr/crt/alignment.c10
-rw-r--r--winpr/libwinpr/crt/test/TestUnicodeConversion.c8
-rw-r--r--winpr/libwinpr/file/file.c159
-rw-r--r--winpr/libwinpr/file/generic.c2
-rw-r--r--winpr/libwinpr/handle/CMakeLists.txt3
-rw-r--r--winpr/libwinpr/library/library.c9
-rw-r--r--winpr/libwinpr/ncrypt/ncrypt_pkcs11.c7
-rw-r--r--winpr/libwinpr/nt/CMakeLists.txt4
-rw-r--r--winpr/libwinpr/path/CMakeLists.txt4
-rw-r--r--winpr/libwinpr/path/path.c8
-rw-r--r--winpr/libwinpr/path/shell.c6
-rw-r--r--winpr/libwinpr/pool/CMakeLists.txt4
-rw-r--r--winpr/libwinpr/smartcard/smartcard_pcsc.c19
-rw-r--r--winpr/libwinpr/sspi/Kerberos/kerberos.c4
-rw-r--r--winpr/libwinpr/sspi/Kerberos/krb5glue_mit.c7
-rw-r--r--winpr/libwinpr/sspi/NTLM/ntlm.c6
-rw-r--r--winpr/libwinpr/sspi/NTLM/ntlm_av_pairs.c7
-rw-r--r--winpr/libwinpr/sspi/NTLM/ntlm_compute.c9
-rw-r--r--winpr/libwinpr/sspi/Negotiate/negotiate.c17
-rw-r--r--winpr/libwinpr/synch/timer.c11
-rw-r--r--winpr/libwinpr/synch/wait.c66
-rw-r--r--winpr/libwinpr/sysinfo/cpufeatures/cpu-features.c1
-rw-r--r--winpr/libwinpr/sysinfo/sysinfo.c150
-rw-r--r--winpr/libwinpr/thread/CMakeLists.txt4
-rw-r--r--winpr/libwinpr/thread/thread.h48
-rw-r--r--winpr/libwinpr/timezone/timezone.c7
-rw-r--r--winpr/libwinpr/utils/cmdline.c7
-rw-r--r--winpr/libwinpr/utils/collections/CountdownEvent.c10
-rw-r--r--winpr/libwinpr/utils/collections/HashTable.c3
-rw-r--r--winpr/libwinpr/utils/collections/PubSub.c3
-rw-r--r--winpr/libwinpr/utils/collections/StreamPool.c2
-rw-r--r--winpr/libwinpr/utils/wlog/PacketMessage.c37
-rw-r--r--winpr/tools/CMakeLists.txt28
-rw-r--r--winpr/tools/hash-cli/CMakeLists.txt30
-rw-r--r--winpr/tools/makecert-cli/CMakeLists.txt32
-rw-r--r--winpr/tools/makecert/CMakeLists.txt8
57 files changed, 486 insertions, 476 deletions
diff --git a/winpr/CMakeLists.txt b/winpr/CMakeLists.txt
index c21668f..f06aaf7 100644
--- a/winpr/CMakeLists.txt
+++ b/winpr/CMakeLists.txt
@@ -137,7 +137,7 @@ endif()
# Soname versioning
set(VERSION_REGEX "^(.*)([0-9]+)\\.([0-9]+)\\.([0-9]+)-?(.*)")
-set(RAW_VERSION_STRING "3.3.0")
+set(RAW_VERSION_STRING "3.5.0")
if(EXISTS "${PROJECT_SOURCE_DIR}/.source_tag")
file(READ ${PROJECT_SOURCE_DIR}/.source_tag RAW_VERSION_STRING)
elseif(USE_VERSION_FROM_GIT_TAG)
@@ -323,11 +323,6 @@ endif()
add_definitions(-DWINPR_EXPORTS)
-# Enable 64bit file support on linux and FreeBSD.
-if("${CMAKE_SYSTEM_NAME}" MATCHES "Linux" OR FREEBSD)
- add_definitions("-D_FILE_OFFSET_BITS=64")
-endif()
-
include_directories(${CMAKE_CURRENT_SOURCE_DIR}/include)
include_directories(${CMAKE_CURRENT_BINARY_DIR}/include)
@@ -346,12 +341,7 @@ endif()
add_subdirectory(include)
-set(MANPAGE_NAME wlog)
-if (WITH_BINARY_VERSIONING)
- set(MANPAGE_NAME wlog${WINPR_API_VERSION})
-endif()
-configure_file(wlog.7.in ${CMAKE_CURRENT_BINARY_DIR}/${MANPAGE_NAME}.7 @ONLY)
-install_freerdp_man(${CMAKE_CURRENT_BINARY_DIR}/${MANPAGE_NAME}.7 7)
+generate_and_install_freerdp_man_from_template("wlog" "7" "${WINPR_API_VERSION}")
# Exporting
export(PACKAGE winpr)
diff --git a/winpr/include/winpr/comm.h b/winpr/include/winpr/comm.h
index 9eb535c..2dbc4fd 100644
--- a/winpr/include/winpr/comm.h
+++ b/winpr/include/winpr/comm.h
@@ -25,8 +25,6 @@
#include <winpr/collections.h>
#include <winpr/file.h>
-#include <winpr/winpr.h>
-#include <winpr/wtypes.h>
#if defined __linux__ && !defined ANDROID
@@ -392,6 +390,7 @@ extern "C"
* also ensures that CommCreateFileA() has been registered through
* RegisterHandleCreator().
*/
+ WINPR_ATTR_MALLOC(CloseHandle, 1)
WINPR_API HANDLE CommCreateFileA(LPCSTR lpFileName, DWORD dwDesiredAccess, DWORD dwShareMode,
LPSECURITY_ATTRIBUTES lpSecurityAttributes,
DWORD dwCreationDisposition, DWORD dwFlagsAndAttributes,
diff --git a/winpr/include/winpr/crt.h b/winpr/include/winpr/crt.h
index 6c155ee..f42c953 100644
--- a/winpr/include/winpr/crt.h
+++ b/winpr/include/winpr/crt.h
@@ -190,27 +190,34 @@ extern "C"
{
#endif
+ WINPR_API void winpr_aligned_free(void* memblock);
+
+ WINPR_ATTR_MALLOC(winpr_aligned_free, 1)
WINPR_API void* winpr_aligned_malloc(size_t size, size_t alignment);
+ WINPR_ATTR_MALLOC(winpr_aligned_free, 1)
WINPR_API void* winpr_aligned_calloc(size_t count, size_t size, size_t alignment);
+ WINPR_ATTR_MALLOC(winpr_aligned_free, 1)
WINPR_API void* winpr_aligned_realloc(void* memblock, size_t size, size_t alignment);
+ WINPR_ATTR_MALLOC(winpr_aligned_free, 1)
WINPR_API void* winpr_aligned_recalloc(void* memblock, size_t num, size_t size,
size_t alignment);
+ WINPR_ATTR_MALLOC(winpr_aligned_free, 1)
WINPR_API void* winpr_aligned_offset_malloc(size_t size, size_t alignment, size_t offset);
+ WINPR_ATTR_MALLOC(winpr_aligned_free, 1)
WINPR_API void* winpr_aligned_offset_realloc(void* memblock, size_t size, size_t alignment,
size_t offset);
+ WINPR_ATTR_MALLOC(winpr_aligned_free, 1)
WINPR_API void* winpr_aligned_offset_recalloc(void* memblock, size_t num, size_t size,
size_t alignment, size_t offset);
WINPR_API size_t winpr_aligned_msize(void* memblock, size_t alignment, size_t offset);
- WINPR_API void winpr_aligned_free(void* memblock);
-
#ifdef __cplusplus
}
#endif
diff --git a/winpr/include/winpr/environment.h b/winpr/include/winpr/environment.h
index f530d59..c963f8c 100644
--- a/winpr/include/winpr/environment.h
+++ b/winpr/include/winpr/environment.h
@@ -87,7 +87,13 @@ extern "C"
* http://blogs.msdn.com/b/oldnewthing/archive/2013/01/17/10385718.aspx
*/
+ WINPR_API BOOL FreeEnvironmentStringsA(LPCH lpszEnvironmentBlock);
+ WINPR_API BOOL FreeEnvironmentStringsW(LPWCH lpszEnvironmentBlock);
+
+ WINPR_ATTR_MALLOC(FreeEnvironmentStringsA, 1)
WINPR_API LPCH GetEnvironmentStrings(VOID);
+
+ WINPR_ATTR_MALLOC(FreeEnvironmentStringsW, 1)
WINPR_API LPWCH GetEnvironmentStringsW(VOID);
WINPR_API BOOL SetEnvironmentStringsA(LPCH NewEnvironment);
@@ -96,9 +102,6 @@ extern "C"
WINPR_API DWORD ExpandEnvironmentStringsA(LPCSTR lpSrc, LPSTR lpDst, DWORD nSize);
WINPR_API DWORD ExpandEnvironmentStringsW(LPCWSTR lpSrc, LPWSTR lpDst, DWORD nSize);
- WINPR_API BOOL FreeEnvironmentStringsA(LPCH lpszEnvironmentBlock);
- WINPR_API BOOL FreeEnvironmentStringsW(LPWCH lpszEnvironmentBlock);
-
#ifdef __cplusplus
}
#endif
diff --git a/winpr/include/winpr/file.h b/winpr/include/winpr/file.h
index c455d74..09aa2c2 100644
--- a/winpr/include/winpr/file.h
+++ b/winpr/include/winpr/file.h
@@ -27,6 +27,7 @@
#include <winpr/nt.h>
#include <winpr/io.h>
#include <winpr/error.h>
+#include <winpr/handle.h>
#ifndef _WIN32
@@ -262,11 +263,13 @@ extern "C"
{
#endif
+ WINPR_ATTR_MALLOC(CloseHandle, 1)
WINPR_API HANDLE CreateFileA(LPCSTR lpFileName, DWORD dwDesiredAccess, DWORD dwShareMode,
LPSECURITY_ATTRIBUTES lpSecurityAttributes,
DWORD dwCreationDisposition, DWORD dwFlagsAndAttributes,
HANDLE hTemplateFile);
+ WINPR_ATTR_MALLOC(CloseHandle, 1)
WINPR_API HANDLE CreateFileW(LPCWSTR lpFileName, DWORD dwDesiredAccess, DWORD dwShareMode,
LPSECURITY_ATTRIBUTES lpSecurityAttributes,
DWORD dwCreationDisposition, DWORD dwFlagsAndAttributes,
@@ -359,12 +362,20 @@ extern "C"
WINPR_API BOOL SetFileTime(HANDLE hFile, const FILETIME* lpCreationTime,
const FILETIME* lpLastAccessTime, const FILETIME* lpLastWriteTime);
+ WINPR_API BOOL FindClose(HANDLE hFindFile);
+
+ WINPR_ATTR_MALLOC(FindClose, 1)
WINPR_API HANDLE FindFirstFileA(LPCSTR lpFileName, LPWIN32_FIND_DATAA lpFindFileData);
+
+ WINPR_ATTR_MALLOC(FindClose, 1)
WINPR_API HANDLE FindFirstFileW(LPCWSTR lpFileName, LPWIN32_FIND_DATAW lpFindFileData);
+ WINPR_ATTR_MALLOC(FindClose, 1)
WINPR_API HANDLE FindFirstFileExA(LPCSTR lpFileName, FINDEX_INFO_LEVELS fInfoLevelId,
LPVOID lpFindFileData, FINDEX_SEARCH_OPS fSearchOp,
LPVOID lpSearchFilter, DWORD dwAdditionalFlags);
+
+ WINPR_ATTR_MALLOC(FindClose, 1)
WINPR_API HANDLE FindFirstFileExW(LPCWSTR lpFileName, FINDEX_INFO_LEVELS fInfoLevelId,
LPVOID lpFindFileData, FINDEX_SEARCH_OPS fSearchOp,
LPVOID lpSearchFilter, DWORD dwAdditionalFlags);
@@ -372,8 +383,6 @@ extern "C"
WINPR_API BOOL FindNextFileA(HANDLE hFindFile, LPWIN32_FIND_DATAA lpFindFileData);
WINPR_API BOOL FindNextFileW(HANDLE hFindFile, LPWIN32_FIND_DATAW lpFindFileData);
- WINPR_API BOOL FindClose(HANDLE hFindFile);
-
WINPR_API BOOL CreateDirectoryA(LPCSTR lpPathName, LPSECURITY_ATTRIBUTES lpSecurityAttributes);
WINPR_API BOOL CreateDirectoryW(LPCWSTR lpPathName, LPSECURITY_ATTRIBUTES lpSecurityAttributes);
diff --git a/winpr/include/winpr/intrin.h b/winpr/include/winpr/intrin.h
index 066f45f..0e61d4d 100644
--- a/winpr/include/winpr/intrin.h
+++ b/winpr/include/winpr/intrin.h
@@ -22,7 +22,7 @@
#ifndef WINPR_INTRIN_H
#define WINPR_INTRIN_H
-#if !defined(_WIN32) || defined(__MINGW32__)
+#if !defined(_WIN32) || defined(__MINGW32__) || defined(_M_ARM64)
/**
* __lzcnt16, __lzcnt, __lzcnt64:
diff --git a/winpr/include/winpr/io.h b/winpr/include/winpr/io.h
index 2a0e34c..2df2316 100644
--- a/winpr/include/winpr/io.h
+++ b/winpr/include/winpr/io.h
@@ -22,6 +22,7 @@
#include <winpr/winpr.h>
#include <winpr/wtypes.h>
+#include <winpr/handle.h>
#ifdef _WIN32
@@ -71,6 +72,7 @@ extern "C"
DWORD nInBufferSize, LPVOID lpOutBuffer, DWORD nOutBufferSize,
LPDWORD lpBytesReturned, LPOVERLAPPED lpOverlapped);
+ WINPR_ATTR_MALLOC(CloseHandle, 1)
WINPR_API HANDLE CreateIoCompletionPort(HANDLE FileHandle, HANDLE ExistingCompletionPort,
ULONG_PTR CompletionKey,
DWORD NumberOfConcurrentThreads);
diff --git a/winpr/include/winpr/memory.h b/winpr/include/winpr/memory.h
index 850d6b2..09f83bd 100644
--- a/winpr/include/winpr/memory.h
+++ b/winpr/include/winpr/memory.h
@@ -37,14 +37,20 @@ extern "C"
{
#endif
+ WINPR_ATTR_MALLOC(CloseHandle, 1)
WINPR_API HANDLE CreateFileMappingA(HANDLE hFile, LPSECURITY_ATTRIBUTES lpAttributes,
DWORD flProtect, DWORD dwMaximumSizeHigh,
DWORD dwMaximumSizeLow, LPCSTR lpName);
+
+ WINPR_ATTR_MALLOC(CloseHandle, 1)
WINPR_API HANDLE CreateFileMappingW(HANDLE hFile, LPSECURITY_ATTRIBUTES lpAttributes,
DWORD flProtect, DWORD dwMaximumSizeHigh,
DWORD dwMaximumSizeLow, LPCWSTR lpName);
+ WINPR_ATTR_MALLOC(CloseHandle, 1)
WINPR_API HANDLE OpenFileMappingA(DWORD dwDesiredAccess, BOOL bInheritHandle, LPCSTR lpName);
+
+ WINPR_ATTR_MALLOC(CloseHandle, 1)
WINPR_API HANDLE OpenFileMappingW(DWORD dwDesiredAccess, BOOL bInheritHandle, LPCWSTR lpName);
WINPR_API LPVOID MapViewOfFile(HANDLE hFileMappingObject, DWORD dwDesiredAccess,
diff --git a/winpr/include/winpr/pipe.h b/winpr/include/winpr/pipe.h
index 932fda5..a31d5eb 100644
--- a/winpr/include/winpr/pipe.h
+++ b/winpr/include/winpr/pipe.h
@@ -73,10 +73,13 @@ extern "C"
* Named pipe
*/
+ WINPR_ATTR_MALLOC(CloseHandle, 1)
WINPR_API HANDLE CreateNamedPipeA(LPCSTR lpName, DWORD dwOpenMode, DWORD dwPipeMode,
DWORD nMaxInstances, DWORD nOutBufferSize,
DWORD nInBufferSize, DWORD nDefaultTimeOut,
LPSECURITY_ATTRIBUTES lpSecurityAttributes);
+
+ WINPR_ATTR_MALLOC(CloseHandle, 1)
WINPR_API HANDLE CreateNamedPipeW(LPCWSTR lpName, DWORD dwOpenMode, DWORD dwPipeMode,
DWORD nMaxInstances, DWORD nOutBufferSize,
DWORD nInBufferSize, DWORD nDefaultTimeOut,
diff --git a/winpr/include/winpr/pool.h b/winpr/include/winpr/pool.h
index 3160ae3..efc467c 100644
--- a/winpr/include/winpr/pool.h
+++ b/winpr/include/winpr/pool.h
@@ -110,7 +110,7 @@ typedef VOID (*PTP_WIN32_IO_CALLBACK)(PTP_CALLBACK_INSTANCE Instance, PVOID Cont
#define WINPR_THREAD_POOL 1
#elif defined(_WIN32) && (_WIN32_WINNT < 0x0600)
#define WINPR_THREAD_POOL 1
-#elif defined(__MINGW32__) && (__MINGW64_VERSION_MAJOR < 8)
+#elif defined(__MINGW32__) && (__MINGW64_VERSION_MAJOR < 7)
#define WINPR_THREAD_POOL 1
#endif
diff --git a/winpr/include/winpr/synch.h b/winpr/include/winpr/synch.h
index b310a3b..c59c979 100644
--- a/winpr/include/winpr/synch.h
+++ b/winpr/include/winpr/synch.h
@@ -44,17 +44,26 @@ extern "C"
/* Mutex */
#define CREATE_MUTEX_INITIAL_OWNER 0x00000001
+ WINPR_ATTR_MALLOC(CloseHandle, 1)
WINPR_API HANDLE CreateMutexA(LPSECURITY_ATTRIBUTES lpMutexAttributes, BOOL bInitialOwner,
LPCSTR lpName);
+
+ WINPR_ATTR_MALLOC(CloseHandle, 1)
WINPR_API HANDLE CreateMutexW(LPSECURITY_ATTRIBUTES lpMutexAttributes, BOOL bInitialOwner,
LPCWSTR lpName);
+ WINPR_ATTR_MALLOC(CloseHandle, 1)
WINPR_API HANDLE CreateMutexExA(LPSECURITY_ATTRIBUTES lpMutexAttributes, LPCSTR lpName,
DWORD dwFlags, DWORD dwDesiredAccess);
+
+ WINPR_ATTR_MALLOC(CloseHandle, 1)
WINPR_API HANDLE CreateMutexExW(LPSECURITY_ATTRIBUTES lpMutexAttributes, LPCWSTR lpName,
DWORD dwFlags, DWORD dwDesiredAccess);
+ WINPR_ATTR_MALLOC(CloseHandle, 1)
WINPR_API HANDLE OpenMutexA(DWORD dwDesiredAccess, BOOL bInheritHandle, LPCSTR lpName);
+
+ WINPR_ATTR_MALLOC(CloseHandle, 1)
WINPR_API HANDLE OpenMutexW(DWORD dwDesiredAccess, BOOL bInheritHandle, LPCWSTR lpName);
WINPR_API BOOL ReleaseMutex(HANDLE hMutex);
@@ -71,12 +80,18 @@ extern "C"
/* Semaphore */
+ WINPR_ATTR_MALLOC(CloseHandle, 1)
WINPR_API HANDLE CreateSemaphoreA(LPSECURITY_ATTRIBUTES lpSemaphoreAttributes,
LONG lInitialCount, LONG lMaximumCount, LPCSTR lpName);
+
+ WINPR_ATTR_MALLOC(CloseHandle, 1)
WINPR_API HANDLE CreateSemaphoreW(LPSECURITY_ATTRIBUTES lpSemaphoreAttributes,
LONG lInitialCount, LONG lMaximumCount, LPCWSTR lpName);
+ WINPR_ATTR_MALLOC(CloseHandle, 1)
WINPR_API HANDLE OpenSemaphoreA(DWORD dwDesiredAccess, BOOL bInheritHandle, LPCSTR lpName);
+
+ WINPR_ATTR_MALLOC(CloseHandle, 1)
WINPR_API HANDLE OpenSemaphoreW(DWORD dwDesiredAccess, BOOL bInheritHandle, LPCWSTR lpName);
#ifdef UNICODE
@@ -93,17 +108,26 @@ extern "C"
#define CREATE_EVENT_MANUAL_RESET 0x00000001
#define CREATE_EVENT_INITIAL_SET 0x00000002
+ WINPR_ATTR_MALLOC(CloseHandle, 1)
WINPR_API HANDLE CreateEventA(LPSECURITY_ATTRIBUTES lpEventAttributes, BOOL bManualReset,
BOOL bInitialState, LPCSTR lpName);
+
+ WINPR_ATTR_MALLOC(CloseHandle, 1)
WINPR_API HANDLE CreateEventW(LPSECURITY_ATTRIBUTES lpEventAttributes, BOOL bManualReset,
BOOL bInitialState, LPCWSTR lpName);
+ WINPR_ATTR_MALLOC(CloseHandle, 1)
WINPR_API HANDLE CreateEventExA(LPSECURITY_ATTRIBUTES lpEventAttributes, LPCSTR lpName,
DWORD dwFlags, DWORD dwDesiredAccess);
+
+ WINPR_ATTR_MALLOC(CloseHandle, 1)
WINPR_API HANDLE CreateEventExW(LPSECURITY_ATTRIBUTES lpEventAttributes, LPCWSTR lpName,
DWORD dwFlags, DWORD dwDesiredAccess);
+ WINPR_ATTR_MALLOC(CloseHandle, 1)
WINPR_API HANDLE OpenEventA(DWORD dwDesiredAccess, BOOL bInheritHandle, LPCSTR lpName);
+
+ WINPR_ATTR_MALLOC(CloseHandle, 1)
WINPR_API HANDLE OpenEventW(DWORD dwDesiredAccess, BOOL bInheritHandle, LPCWSTR lpName);
WINPR_API BOOL SetEvent(HANDLE hEvent);
@@ -225,14 +249,20 @@ extern "C"
typedef VOID (*PTIMERAPCROUTINE)(LPVOID lpArgToCompletionRoutine, DWORD dwTimerLowValue,
DWORD dwTimerHighValue);
+ WINPR_ATTR_MALLOC(CloseHandle, 1)
WINPR_API HANDLE CreateWaitableTimerA(LPSECURITY_ATTRIBUTES lpTimerAttributes,
BOOL bManualReset, LPCSTR lpTimerName);
+
+ WINPR_ATTR_MALLOC(CloseHandle, 1)
WINPR_API HANDLE CreateWaitableTimerW(LPSECURITY_ATTRIBUTES lpTimerAttributes,
BOOL bManualReset, LPCWSTR lpTimerName);
+ WINPR_ATTR_MALLOC(CloseHandle, 1)
WINPR_API HANDLE CreateWaitableTimerExA(LPSECURITY_ATTRIBUTES lpTimerAttributes,
LPCSTR lpTimerName, DWORD dwFlags,
DWORD dwDesiredAccess);
+
+ WINPR_ATTR_MALLOC(CloseHandle, 1)
WINPR_API HANDLE CreateWaitableTimerExW(LPSECURITY_ATTRIBUTES lpTimerAttributes,
LPCWSTR lpTimerName, DWORD dwFlags,
DWORD dwDesiredAccess);
@@ -246,8 +276,11 @@ extern "C"
LPVOID lpArgToCompletionRoutine, PREASON_CONTEXT WakeContext,
ULONG TolerableDelay);
+ WINPR_ATTR_MALLOC(CloseHandle, 1)
WINPR_API HANDLE OpenWaitableTimerA(DWORD dwDesiredAccess, BOOL bInheritHandle,
LPCSTR lpTimerName);
+
+ WINPR_ATTR_MALLOC(CloseHandle, 1)
WINPR_API HANDLE OpenWaitableTimerW(DWORD dwDesiredAccess, BOOL bInheritHandle,
LPCWSTR lpTimerName);
@@ -282,7 +315,9 @@ extern "C"
typedef VOID (*WAITORTIMERCALLBACK)(PVOID lpParameter, BOOLEAN TimerOrWaitFired);
+ WINPR_ATTR_MALLOC(CloseHandle, 1)
WINPR_API HANDLE CreateTimerQueue(void);
+
WINPR_API BOOL DeleteTimerQueue(HANDLE TimerQueue);
WINPR_API BOOL DeleteTimerQueueEx(HANDLE TimerQueue, HANDLE CompletionEvent);
@@ -395,13 +430,17 @@ extern "C"
WINPR_API VOID USleep(DWORD dwMicroseconds);
+ WINPR_ATTR_MALLOC(CloseHandle, 1)
WINPR_API HANDLE CreateFileDescriptorEventW(LPSECURITY_ATTRIBUTES lpEventAttributes,
BOOL bManualReset, BOOL bInitialState,
int FileDescriptor, ULONG mode);
+
+ WINPR_ATTR_MALLOC(CloseHandle, 1)
WINPR_API HANDLE CreateFileDescriptorEventA(LPSECURITY_ATTRIBUTES lpEventAttributes,
BOOL bManualReset, BOOL bInitialState,
int FileDescriptor, ULONG mode);
+ WINPR_ATTR_MALLOC(CloseHandle, 1)
WINPR_API HANDLE CreateWaitObjectEvent(LPSECURITY_ATTRIBUTES lpEventAttributes,
BOOL bManualReset, BOOL bInitialState, void* pObject);
diff --git a/winpr/include/winpr/sysinfo.h b/winpr/include/winpr/sysinfo.h
index d7d6dd8..61fadc3 100644
--- a/winpr/include/winpr/sysinfo.h
+++ b/winpr/include/winpr/sysinfo.h
@@ -322,6 +322,17 @@ extern "C"
#endif
+#define WINPR_TIME_NS_TO_S(ns) ((ns) / 1000000000ull)
+#define WINPR_TIME_NS_TO_MS(ns) ((ns) / 1000000ull)
+#define WINPR_TIME_NS_TO_US(ns) ((ns) / 1000ull)
+
+#define WINPR_TIME_NS_REM_NS(ns) ((ns) % 1000000000ull)
+#define WINPR_TIME_NS_REM_US(ns) (WINPR_TIME_NS_REM_NS(ns) / 1000ull)
+#define WINPR_TIME_NS_REM_MS(ns) (WINPR_TIME_NS_REM_US(ns) / 1000ull)
+
+ WINPR_API UINT64 winpr_GetTickCount64NS(void);
+ WINPR_API UINT64 winpr_GetUnixTimeNS(void);
+
WINPR_API DWORD GetTickCountPrecise(void);
WINPR_API BOOL IsProcessorFeaturePresentEx(DWORD ProcessorFeature);
diff --git a/winpr/include/winpr/thread.h b/winpr/include/winpr/thread.h
index 2f17603..b0bad74 100644
--- a/winpr/include/winpr/thread.h
+++ b/winpr/include/winpr/thread.h
@@ -198,10 +198,12 @@ extern "C"
#define CREATE_SUSPENDED 0x00000004
#define STACK_SIZE_PARAM_IS_A_RESERVATION 0x00010000
+ WINPR_ATTR_MALLOC(CloseHandle, 1)
WINPR_API HANDLE CreateThread(LPSECURITY_ATTRIBUTES lpThreadAttributes, SIZE_T dwStackSize,
LPTHREAD_START_ROUTINE lpStartAddress, LPVOID lpParameter,
DWORD dwCreationFlags, LPDWORD lpThreadId);
+ WINPR_ATTR_MALLOC(CloseHandle, 1)
WINPR_API HANDLE CreateRemoteThread(HANDLE hProcess, LPSECURITY_ATTRIBUTES lpThreadAttributes,
SIZE_T dwStackSize, LPTHREAD_START_ROUTINE lpStartAddress,
LPVOID lpParameter, DWORD dwCreationFlags,
diff --git a/winpr/include/winpr/winpr.h b/winpr/include/winpr/winpr.h
index 04311d8..a429c7a 100644
--- a/winpr/include/winpr/winpr.h
+++ b/winpr/include/winpr/winpr.h
@@ -119,6 +119,16 @@
#define INLINE inline
#endif
+#if defined(__GNUC__) || defined(__clang__)
+#define WINPR_ALIGN64 __attribute__((aligned(8)))
+#else
+#ifdef _WIN32
+#define WINPR_ALIGN64 __declspec(align(8))
+#else
+#define WINPR_ALIGN64
+#endif
+#endif
+
WINPR_API void winpr_get_version(int* major, int* minor, int* revision);
WINPR_API const char* winpr_get_version_string(void);
WINPR_API const char* winpr_get_build_revision(void);
diff --git a/winpr/include/winpr/winsock.h b/winpr/include/winpr/winsock.h
index 73dc9ae..dbf8462 100644
--- a/winpr/include/winpr/winsock.h
+++ b/winpr/include/winpr/winsock.h
@@ -297,10 +297,12 @@ extern "C"
WINPR_API void WSASetLastError(int iError);
WINPR_API int WSAGetLastError(void);
+ WINPR_API BOOL WSACloseEvent(HANDLE hEvent);
+
+ WINPR_ATTR_MALLOC(WSACloseEvent, 1)
WINPR_API HANDLE WSACreateEvent(void);
WINPR_API BOOL WSASetEvent(HANDLE hEvent);
WINPR_API BOOL WSAResetEvent(HANDLE hEvent);
- WINPR_API BOOL WSACloseEvent(HANDLE hEvent);
WINPR_API int WSAEventSelect(SOCKET s, WSAEVENT hEventObject, LONG lNetworkEvents);
diff --git a/winpr/include/winpr/wtsapi.h b/winpr/include/winpr/wtsapi.h
index bd5616f..9902ffe 100644
--- a/winpr/include/winpr/wtsapi.h
+++ b/winpr/include/winpr/wtsapi.h
@@ -1002,13 +1002,19 @@ extern "C"
WINPR_API BOOL WINAPI WTSEnumerateServersA(LPSTR pDomainName, DWORD Reserved, DWORD Version,
PWTS_SERVER_INFOA* ppServerInfo, DWORD* pCount);
+ WINPR_API VOID WINAPI WTSCloseServer(HANDLE hServer);
+
+ WINPR_ATTR_MALLOC(WTSCloseServer, 1)
WINPR_API HANDLE WINAPI WTSOpenServerW(LPWSTR pServerName);
+
+ WINPR_ATTR_MALLOC(WTSCloseServer, 1)
WINPR_API HANDLE WINAPI WTSOpenServerA(LPSTR pServerName);
+ WINPR_ATTR_MALLOC(WTSCloseServer, 1)
WINPR_API HANDLE WINAPI WTSOpenServerExW(LPWSTR pServerName);
- WINPR_API HANDLE WINAPI WTSOpenServerExA(LPSTR pServerName);
- WINPR_API VOID WINAPI WTSCloseServer(HANDLE hServer);
+ WINPR_ATTR_MALLOC(WTSCloseServer, 1)
+ WINPR_API HANDLE WINAPI WTSOpenServerExA(LPSTR pServerName);
WINPR_API BOOL WINAPI WTSEnumerateSessionsW(HANDLE hServer, DWORD Reserved, DWORD Version,
PWTS_SESSION_INFOW* ppSessionInfo, DWORD* pCount);
diff --git a/winpr/libwinpr/CMakeLists.txt b/winpr/libwinpr/CMakeLists.txt
index 4be2015..1c85d37 100644
--- a/winpr/libwinpr/CMakeLists.txt
+++ b/winpr/libwinpr/CMakeLists.txt
@@ -157,36 +157,13 @@ list(REMOVE_DUPLICATES WINPR_DEFINITIONS)
list(REMOVE_DUPLICATES WINPR_COMPILE_OPTIONS)
list(REMOVE_DUPLICATES WINPR_LINK_OPTIONS)
list(REMOVE_DUPLICATES WINPR_LINK_DIRS)
-list(REMOVE_DUPLICATES WINPR_LIBS_PRIVATE)
-list(REMOVE_DUPLICATES WINPR_LIBS_PUBLIC)
list(REMOVE_DUPLICATES WINPR_INCLUDES)
-# On windows create dll version information.
-# Vendor, product and year are already set in top level CMakeLists.txt
-if (WIN32)
- set (RC_VERSION_MAJOR ${WINPR_VERSION_MAJOR})
- set (RC_VERSION_MINOR ${WINPR_VERSION_MINOR})
- set (RC_VERSION_BUILD ${WINPR_VERSION_REVISION})
- set (RC_VERSION_FILE "${CMAKE_SHARED_LIBRARY_PREFIX}${MODULE_NAME}${WINPR_API_VERSION}${CMAKE_SHARED_LIBRARY_SUFFIX}" )
-
- configure_file(
- ${PROJECT_SOURCE_DIR}/cmake/WindowsDLLVersion.rc.in
- ${CMAKE_CURRENT_BINARY_DIR}/version.rc
- @ONLY)
-
- set (WINPR_SRCS ${WINPR_SRCS} ${CMAKE_CURRENT_BINARY_DIR}/version.rc)
- winpr_library_add_public("shlwapi")
-endif()
+AddTargetWithResourceFile(${MODULE_NAME} FALSE "${WINPR_VERSION}" WINPR_SRCS)
-add_library(${MODULE_NAME} ${WINPR_SRCS})
if (APPLE)
set_target_properties(${MODULE_NAME} PROPERTIES INTERPROCEDURAL_OPTIMIZATION FALSE)
endif()
-set_target_properties(${MODULE_NAME} PROPERTIES LINKER_LANGUAGE C)
-set_target_properties(${MODULE_NAME} PROPERTIES OUTPUT_NAME ${MODULE_NAME}${WINPR_API_VERSION})
-if (WITH_LIBRARY_VERSIONING)
- set_target_properties(${MODULE_NAME} PROPERTIES VERSION ${WINPR_VERSION} SOVERSION ${WINPR_API_VERSION})
-endif()
if (NOT BUILD_SHARED_LIBS)
set(LINK_OPTS_MODE PUBLIC)
@@ -206,8 +183,4 @@ install(TARGETS ${MODULE_NAME} COMPONENT libraries EXPORT WinPRTargets
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
-if (WITH_DEBUG_SYMBOLS AND MSVC AND BUILD_SHARED_LIBS)
- get_target_property(OUTPUT_FILENAME ${MODULE_NAME} OUTPUT_NAME)
- install(FILES ${CMAKE_PDB_BINARY_DIR}/${OUTPUT_FILENAME}.pdb DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT symbols)
-endif()
set_property(TARGET ${MODULE_NAME} PROPERTY FOLDER "WinPR/libwinpr")
diff --git a/winpr/libwinpr/clipboard/synthetic_file.c b/winpr/libwinpr/clipboard/synthetic_file.c
index 1421980..9a1084b 100644
--- a/winpr/libwinpr/clipboard/synthetic_file.c
+++ b/winpr/libwinpr/clipboard/synthetic_file.c
@@ -276,8 +276,14 @@ static BOOL add_directory_contents_to_list(wClipboard* clipboard, const WCHAR* l
const WCHAR* remote_name, wArrayList* files)
{
BOOL result = FALSE;
- const WCHAR* wildcard = "/\0*\0\0\0";
- const size_t wildcardLen = 3;
+ union
+ {
+ const char* c;
+ const WCHAR* w;
+ } wildcard;
+ const char buffer[6] = "/\0*\0\0\0";
+ wildcard.c = buffer;
+ const size_t wildcardLen = ARRAYSIZE(buffer) / sizeof(WCHAR);
WINPR_ASSERT(clipboard);
WINPR_ASSERT(local_name);
@@ -290,7 +296,7 @@ static BOOL add_directory_contents_to_list(wClipboard* clipboard, const WCHAR* l
return FALSE;
_wcsncat(namebuf, local_name, len);
- _wcsncat(namebuf, wildcard, wildcardLen);
+ _wcsncat(namebuf, wildcard.w, wildcardLen);
result = do_add_directory_contents_to_list(clipboard, local_name, remote_name, namebuf, files);
@@ -1079,7 +1085,6 @@ static UINT file_get_range(struct synthetic_file* file, UINT64 offset, UINT32 si
UINT error = NO_ERROR;
DWORD dwLow = 0;
DWORD dwHigh = 0;
- BYTE* buffer = NULL;
WINPR_ASSERT(file);
WINPR_ASSERT(actual_data);
@@ -1150,7 +1155,7 @@ static UINT file_get_range(struct synthetic_file* file, UINT64 offset, UINT32 si
}
}
- buffer = malloc(size);
+ BYTE* buffer = malloc(size);
if (!buffer)
{
error = ERROR_NOT_ENOUGH_MEMORY;
@@ -1158,6 +1163,7 @@ static UINT file_get_range(struct synthetic_file* file, UINT64 offset, UINT32 si
}
if (!ReadFile(file->fd, buffer, size, (LPDWORD)actual_size, NULL))
{
+ free(buffer);
error = GetLastError();
break;
}
@@ -1168,10 +1174,6 @@ static UINT file_get_range(struct synthetic_file* file, UINT64 offset, UINT32 si
*actual_size, file->offset);
} while (0);
- if (NO_ERROR != error)
- {
- free(buffer);
- }
synthetic_file_read_close(file, TRUE /* (error != NO_ERROR) && (size > 0) */);
return error;
}
diff --git a/winpr/libwinpr/comm/comm.c b/winpr/libwinpr/comm/comm.c
index c4e828e..cd68a40 100644
--- a/winpr/libwinpr/comm/comm.c
+++ b/winpr/libwinpr/comm/comm.c
@@ -1164,10 +1164,10 @@ HANDLE CommCreateFileA(LPCSTR lpDeviceName, DWORD dwDesiredAccess, DWORD dwShare
LPSECURITY_ATTRIBUTES lpSecurityAttributes, DWORD dwCreationDisposition,
DWORD dwFlagsAndAttributes, HANDLE hTemplateFile)
{
- CHAR devicePath[MAX_PATH];
- struct stat deviceStat;
+ CHAR devicePath[MAX_PATH] = { 0 };
+ struct stat deviceStat = { 0 };
WINPR_COMM* pComm = NULL;
- struct termios upcomingTermios;
+ struct termios upcomingTermios = { 0 };
if (!CommInitialized())
return INVALID_HANDLE_VALUE;
diff --git a/winpr/libwinpr/comm/comm_io.c b/winpr/libwinpr/comm/comm_io.c
index 9904eab..a89c452 100644
--- a/winpr/libwinpr/comm/comm_io.c
+++ b/winpr/libwinpr/comm/comm_io.c
@@ -186,8 +186,8 @@ BOOL CommReadFile(HANDLE hDevice, LPVOID lpBuffer, DWORD nNumberOfBytesToRead,
else
{
/* Tmax */
- Tmax = nNumberOfBytesToRead * pTimeouts->ReadTotalTimeoutMultiplier +
- pTimeouts->ReadTotalTimeoutConstant;
+ Tmax = 1ull * nNumberOfBytesToRead * pTimeouts->ReadTotalTimeoutMultiplier +
+ 1ull * pTimeouts->ReadTotalTimeoutConstant;
/* INDEFinitely */
if ((Tmax == 0) && (pTimeouts->ReadIntervalTimeout < MAXULONG) &&
@@ -398,8 +398,8 @@ BOOL CommWriteFile(HANDLE hDevice, LPCVOID lpBuffer, DWORD nNumberOfBytesToWrite
/* discard a possible and no more relevant event */
eventfd_read(pComm->fd_write_event, NULL);
/* ms */
- ULONGLONG Tmax = nNumberOfBytesToWrite * pComm->timeouts.WriteTotalTimeoutMultiplier +
- pComm->timeouts.WriteTotalTimeoutConstant;
+ ULONGLONG Tmax = 1ull * nNumberOfBytesToWrite * pComm->timeouts.WriteTotalTimeoutMultiplier +
+ 1ull * pComm->timeouts.WriteTotalTimeoutConstant;
/* NB: select() may update the timeout argument to indicate
* how much time was left. Keep the timeout variable out of
* the while() */
diff --git a/winpr/libwinpr/comm/comm_serial_sys.c b/winpr/libwinpr/comm/comm_serial_sys.c
index cae653c..185f017 100644
--- a/winpr/libwinpr/comm/comm_serial_sys.c
+++ b/winpr/libwinpr/comm/comm_serial_sys.c
@@ -1027,15 +1027,27 @@ static const ULONG _SERIAL_SYS_SUPPORTED_EV_MASK =
SERIAL_EV_EVENT2*/
;
+static BOOL is_wait_set(WINPR_COMM* pComm)
+{
+ WINPR_ASSERT(pComm);
+
+ EnterCriticalSection(&pComm->EventsLock);
+ const BOOL isWaiting = (pComm->PendingEvents & SERIAL_EV_WINPR_WAITING) != 0;
+ LeaveCriticalSection(&pComm->EventsLock);
+ return isWaiting;
+}
+
static BOOL _set_wait_mask(WINPR_COMM* pComm, const ULONG* pWaitMask)
{
ULONG possibleMask = 0;
+ WINPR_ASSERT(pComm);
+ WINPR_ASSERT(pWaitMask);
+
/* Stops pending IOCTL_SERIAL_WAIT_ON_MASK
* http://msdn.microsoft.com/en-us/library/ff546805%28v=vs.85%29.aspx
*/
-
- if (pComm->PendingEvents & SERIAL_EV_WINPR_WAITING)
+ if (is_wait_set(pComm))
{
/* FIXME: any doubt on reading PendingEvents out of a critical section? */
@@ -1044,7 +1056,7 @@ static BOOL _set_wait_mask(WINPR_COMM* pComm, const ULONG* pWaitMask)
LeaveCriticalSection(&pComm->EventsLock);
/* waiting the end of the pending _wait_on_mask() */
- while (pComm->PendingEvents & SERIAL_EV_WINPR_WAITING)
+ while (is_wait_set(pComm))
Sleep(10); /* 10ms */
}
diff --git a/winpr/libwinpr/crt/alignment.c b/winpr/libwinpr/crt/alignment.c
index e313c2d..71dd0e0 100644
--- a/winpr/libwinpr/crt/alignment.c
+++ b/winpr/libwinpr/crt/alignment.c
@@ -36,14 +36,6 @@
#include <stdlib.h>
-#if defined(__APPLE__)
-#include <malloc/malloc.h>
-#elif defined(__FreeBSD__) || defined(__OpenBSD__)
-#include <stdlib.h>
-#else
-#include <malloc.h>
-#endif
-
#include "../log.h"
#define TAG WINPR_TAG("crt")
@@ -108,7 +100,7 @@ void* winpr_aligned_offset_malloc(size_t size, size_t alignment, size_t offset)
/* malloc size + alignment to make sure we can align afterwards */
#if defined(_ISOC11_SOURCE)
base = aligned_alloc(alignment, alignsize);
-#elif _POSIX_C_SOURCE >= 200112L || _XOPEN_SOURCE >= 600
+#elif defined(_POSIX_C_SOURCE) && (_POSIX_C_SOURCE >= 200112L) || (_XOPEN_SOURCE >= 600)
if (posix_memalign(&base, alignment, alignsize) != 0)
return NULL;
#else
diff --git a/winpr/libwinpr/crt/test/TestUnicodeConversion.c b/winpr/libwinpr/crt/test/TestUnicodeConversion.c
index a5c4c75..187a068 100644
--- a/winpr/libwinpr/crt/test/TestUnicodeConversion.c
+++ b/winpr/libwinpr/crt/test/TestUnicodeConversion.c
@@ -24,10 +24,12 @@ typedef struct
// TODO: The unit tests do not check for valid code points, so always end the test
// strings with a simple ASCII symbol for now.
static const testcase_t unit_testcases[] = {
- { "foo", 3, "f\x00o\x00o\x00\x00\x00", 3 },
- { "foo", 4, "f\x00o\x00o\x00\x00\x00", 4 },
+ { "foo", 3, (const WCHAR*)"f\x00o\x00o\x00\x00\x00", 3 },
+ { "foo", 4, (const WCHAR*)"f\x00o\x00o\x00\x00\x00", 4 },
{ "✊🎅ęʥ꣸𑗊a", 19,
- "\x0a\x27\x3c\xd8\x85\xdf\x19\x01\xa5\x02\xf8\xa8\x05\xd8\xca\xdd\x61\x00\x00\x00", 9 }
+ (const WCHAR*)"\x0a\x27\x3c\xd8\x85\xdf\x19\x01\xa5\x02\xf8\xa8\x05\xd8\xca\xdd\x61\x00\x00"
+ "\x00",
+ 9 }
};
static void create_prefix(char* prefix, size_t prefixlen, size_t buffersize, SSIZE_T rc,
diff --git a/winpr/libwinpr/file/file.c b/winpr/libwinpr/file/file.c
index 01328b8..a016beb 100644
--- a/winpr/libwinpr/file/file.c
+++ b/winpr/libwinpr/file/file.c
@@ -21,11 +21,7 @@
#include <winpr/config.h>
#include <winpr/debug.h>
-
-#if defined(__FreeBSD_kernel__) && defined(__GLIBC__)
-#define _GNU_SOURCE
-#define KFREEBSD
-#endif
+#include <winpr/assert.h>
#include <winpr/wtypes.h>
#include <winpr/crt.h>
@@ -100,14 +96,15 @@ static BOOL FileCloseHandle(HANDLE handle)
static BOOL FileSetEndOfFile(HANDLE hFile)
{
WINPR_FILE* pFile = (WINPR_FILE*)hFile;
- INT64 size = 0;
if (!hFile)
return FALSE;
- size = _ftelli64(pFile->fp);
+ const INT64 size = _ftelli64(pFile->fp);
+ if (size < 0)
+ return FALSE;
- if (ftruncate(fileno(pFile->fp), size) < 0)
+ if (ftruncate(fileno(pFile->fp), (off_t)size) < 0)
{
char ebuffer[256] = { 0 };
WLog_ERR(TAG, "ftruncate %s failed with %s [0x%08X]", pFile->lpFileName,
@@ -565,100 +562,114 @@ static UINT64 FileTimeToUS(const FILETIME* ft)
return tmp;
}
+#if defined(_POSIX_C_SOURCE) && (_POSIX_C_SOURCE >= 200809L)
+static struct timespec filetimeToTimespec(const FILETIME* ftime)
+{
+ WINPR_ASSERT(ftime);
+ UINT64 tmp = FileTimeToUS(ftime);
+ struct timespec ts = { 0 };
+ ts.tv_sec = tmp / 1000000ULL;
+ ts.tv_nsec = (tmp % 1000000ULL) * 1000ULL;
+ return ts;
+}
+
static BOOL FileSetFileTime(HANDLE hFile, const FILETIME* lpCreationTime,
const FILETIME* lpLastAccessTime, const FILETIME* lpLastWriteTime)
{
- int rc = 0;
-#if defined(__APPLE__) || defined(ANDROID) || defined(__FreeBSD__) || defined(KFREEBSD)
- struct stat buf;
- /* OpenBSD, NetBSD and DragonflyBSD support POSIX futimens */
- struct timeval timevals[2];
-#else
- struct timespec times[2]; /* last access, last modification */
-#endif
+ struct timespec times[2] = { { UTIME_OMIT, UTIME_OMIT },
+ { UTIME_OMIT, UTIME_OMIT } }; /* last access, last modification */
WINPR_FILE* pFile = (WINPR_FILE*)hFile;
if (!hFile)
return FALSE;
-#if defined(__APPLE__) || defined(ANDROID) || defined(__FreeBSD__) || defined(KFREEBSD)
- rc = fstat(fileno(pFile->fp), &buf);
+ if (lpLastAccessTime)
+ times[0] = filetimeToTimespec(lpLastAccessTime);
- if (rc < 0)
+ if (lpLastWriteTime)
+ times[1] = filetimeToTimespec(lpLastWriteTime);
+
+ // TODO: Creation time can not be handled!
+ const int rc = futimens(fileno(pFile->fp), times);
+ if (rc != 0)
return FALSE;
-#endif
+ return TRUE;
+}
+#elif defined(__APPLE__) || defined(ANDROID) || defined(__FreeBSD__) || defined(KFREEBSD)
+static struct timeval filetimeToTimeval(const FILETIME* ftime)
+{
+ WINPR_ASSERT(ftime);
+ UINT64 tmp = FileTimeToUS(ftime);
+ struct timeval tv = { 0 };
+ tv.tv_sec = tmp / 1000000ULL;
+ tv.tv_usec = tmp % 1000000ULL;
+ return tv;
+}
- if (!lpLastAccessTime)
- {
+static struct timeval statToTimeval(const struct stat* sval)
+{
+ WINPR_ASSERT(sval);
+ struct timeval tv = { 0 };
#if defined(__FreeBSD__) || defined(__APPLE__) || defined(KFREEBSD)
- timevals[0].tv_sec = buf.st_atime;
+ tv.tv_sec = sval->st_atime;
#ifdef _POSIX_SOURCE
- TIMESPEC_TO_TIMEVAL(&timevals[0], &buf.st_atim);
+ TIMESPEC_TO_TIMEVAL(&tv, &sval->st_atim);
#else
- TIMESPEC_TO_TIMEVAL(&timevals[0], &buf.st_atimespec);
+ TIMESPEC_TO_TIMEVAL(&tv, &sval->st_atimespec);
#endif
#elif defined(ANDROID)
- timevals[0].tv_sec = buf.st_atime;
- timevals[0].tv_usec = buf.st_atimensec / 1000UL;
-#else
- times[0].tv_sec = UTIME_OMIT;
- times[0].tv_nsec = UTIME_OMIT;
+ tv.tv_sec = sval->st_atime;
+ tv.tv_usec = sval->st_atimensec / 1000UL;
#endif
- }
- else
- {
- UINT64 tmp = FileTimeToUS(lpLastAccessTime);
-#if defined(ANDROID) || defined(__FreeBSD__) || defined(__APPLE__) || defined(KFREEBSD)
- timevals[0].tv_sec = tmp / 1000000ULL;
- timevals[0].tv_usec = tmp % 1000000ULL;
-#else
- times[0].tv_sec = tmp / 1000000ULL;
- times[0].tv_nsec = (tmp % 1000000ULL) * 1000ULL;
-#endif
- }
+ return tv;
+}
- if (!lpLastWriteTime)
- {
-#if defined(__FreeBSD__) || defined(__APPLE__) || defined(KFREEBSD)
- timevals[1].tv_sec = buf.st_mtime;
-#ifdef _POSIX_SOURCE
- TIMESPEC_TO_TIMEVAL(&timevals[1], &buf.st_mtim);
-#else
- TIMESPEC_TO_TIMEVAL(&timevals[1], &buf.st_mtimespec);
-#endif
-#elif defined(ANDROID)
- timevals[1].tv_sec = buf.st_mtime;
- timevals[1].tv_usec = buf.st_mtimensec / 1000UL;
-#else
- times[1].tv_sec = UTIME_OMIT;
- times[1].tv_nsec = UTIME_OMIT;
-#endif
- }
- else
+static BOOL FileSetFileTime(HANDLE hFile, const FILETIME* lpCreationTime,
+ const FILETIME* lpLastAccessTime, const FILETIME* lpLastWriteTime)
+{
+ struct stat buf = { 0 };
+ /* OpenBSD, NetBSD and DragonflyBSD support POSIX futimens */
+ WINPR_FILE* pFile = (WINPR_FILE*)hFile;
+
+ if (!hFile)
+ return FALSE;
+
+ const int rc = fstat(fileno(pFile->fp), &buf);
+ if (rc < 0)
+ return FALSE;
+
+ struct timeval timevals[2] = { statToTimeval(&buf), statToTimeval(&buf) };
+ if (lpLastAccessTime)
+ timevals[0] = filetimeToTimeval(lpLastAccessTime);
+
+ if (lpLastWriteTime)
+ timevals[1] = filetimeToTimeval(lpLastWriteTime);
+
+ // TODO: Creation time can not be handled!
{
- UINT64 tmp = FileTimeToUS(lpLastWriteTime);
-#if defined(ANDROID) || defined(__FreeBSD__) || defined(__APPLE__) || defined(KFREEBSD)
- timevals[1].tv_sec = tmp / 1000000ULL;
- timevals[1].tv_usec = tmp % 1000000ULL;
-#else
- times[1].tv_sec = tmp / 1000000ULL;
- times[1].tv_nsec = (tmp % 1000000ULL) * 1000ULL;
-#endif
+ const int rc = utimes(pFile->lpFileName, timevals);
+ if (rc != 0)
+ return FALSE;
}
- // TODO: Creation time can not be handled!
-#if defined(ANDROID) || defined(__FreeBSD__) || defined(__APPLE__) || defined(KFREEBSD)
- rc = utimes(pFile->lpFileName, timevals);
+ return TRUE;
+}
#else
- rc = futimens(fileno(pFile->fp), times);
-#endif
+static BOOL FileSetFileTime(HANDLE hFile, const FILETIME* lpCreationTime,
+ const FILETIME* lpLastAccessTime, const FILETIME* lpLastWriteTime)
+{
+ WINPR_FILE* pFile = (WINPR_FILE*)hFile;
- if (rc != 0)
+ if (!hFile)
return FALSE;
+ WLog_WARN(TAG, "TODO: Creation, Access and Write time can not be handled!");
+ WLog_WARN(TAG,
+ "TODO: Define _POSIX_C_SOURCE >= 200809L or implement a platform specific handler!");
return TRUE;
}
+#endif
static HANDLE_OPS fileOps = {
FileIsHandled,
diff --git a/winpr/libwinpr/file/generic.c b/winpr/libwinpr/file/generic.c
index e1437ec..9318586 100644
--- a/winpr/libwinpr/file/generic.c
+++ b/winpr/libwinpr/file/generic.c
@@ -885,7 +885,7 @@ static WIN32_FILE_SEARCH* file_search_new(const char* name, size_t namelen, cons
WIN32_FILE_SEARCH* pFileSearch = (WIN32_FILE_SEARCH*)calloc(1, sizeof(WIN32_FILE_SEARCH));
if (!pFileSearch)
return NULL;
- strncpy(pFileSearch->magic, file_search_magic, sizeof(pFileSearch->magic));
+ strncpy(pFileSearch->magic, file_search_magic, sizeof(pFileSearch->magic) - 1);
pFileSearch->lpPath = strndup(name, namelen);
pFileSearch->lpPattern = strndup(pattern, patternlen);
diff --git a/winpr/libwinpr/handle/CMakeLists.txt b/winpr/libwinpr/handle/CMakeLists.txt
index 37c410e..48c7aea 100644
--- a/winpr/libwinpr/handle/CMakeLists.txt
+++ b/winpr/libwinpr/handle/CMakeLists.txt
@@ -18,6 +18,3 @@
winpr_module_add(handle.c handle.h nonehandle.c nonehandle.h)
-if(${CMAKE_SYSTEM_NAME} MATCHES SunOS)
- winpr_library_add_private(rt)
-endif()
diff --git a/winpr/libwinpr/library/library.c b/winpr/libwinpr/library/library.c
index 307dc20..0fa1fd1 100644
--- a/winpr/libwinpr/library/library.c
+++ b/winpr/libwinpr/library/library.c
@@ -274,18 +274,17 @@ DWORD GetModuleFileNameA(HMODULE hModule, LPSTR lpFilename, DWORD nSize)
if (!hModule)
{
- char buffer[4096];
+ char buffer[4096] = { 0 };
sprintf_s(path, ARRAYSIZE(path), "/proc/%d/exe", getpid());
- status = readlink(path, buffer, sizeof(buffer));
+ status = readlink(path, buffer, ARRAYSIZE(buffer) - 1);
- if (status < 0)
+ if ((status < 0) || (status >= ARRAYSIZE(buffer)))
{
SetLastError(ERROR_INTERNAL_ERROR);
return 0;
}
- buffer[status] = '\0';
- length = strnlen(buffer, sizeof(buffer));
+ length = strnlen(buffer, ARRAYSIZE(buffer));
if (length < nSize)
{
diff --git a/winpr/libwinpr/ncrypt/ncrypt_pkcs11.c b/winpr/libwinpr/ncrypt/ncrypt_pkcs11.c
index 08e6274..d579cb1 100644
--- a/winpr/libwinpr/ncrypt/ncrypt_pkcs11.c
+++ b/winpr/libwinpr/ncrypt/ncrypt_pkcs11.c
@@ -141,6 +141,7 @@ static BOOL attributes_have_unallocated_buffers(CK_ATTRIBUTE_PTR attributes, CK_
static BOOL attribute_allocate_attribute_array(CK_ATTRIBUTE_PTR attribute)
{
+ WINPR_ASSERT(attribute);
attribute->pValue = calloc(attribute->ulValueLen, sizeof(void*));
return !!attribute->pValue;
}
@@ -1189,11 +1190,7 @@ static SECURITY_STATUS initialize_pkcs11(HANDLE handle,
ret = (NCryptP11ProviderHandle*)ncrypt_new_handle(
WINPR_NCRYPT_PROVIDER, sizeof(*ret), NCryptP11GetProperty, NCryptP11StorageProvider_dtor);
if (!ret)
- {
- if (handle)
- FreeLibrary(handle);
return NTE_NO_MEMORY;
- }
ret->library = handle;
ret->baseProvider.enumKeysFn = NCryptP11EnumKeys;
@@ -1290,6 +1287,8 @@ SECURITY_STATUS NCryptOpenP11StorageProviderEx(NCRYPT_PROV_HANDLE* phProvider,
return ERROR_SUCCESS;
out_load_library:
+ if (library)
+ FreeLibrary(library);
modulePaths++;
}
diff --git a/winpr/libwinpr/nt/CMakeLists.txt b/winpr/libwinpr/nt/CMakeLists.txt
index ef335e4..6ad18d6 100644
--- a/winpr/libwinpr/nt/CMakeLists.txt
+++ b/winpr/libwinpr/nt/CMakeLists.txt
@@ -21,10 +21,6 @@ winpr_library_add_private(
${CMAKE_THREAD_LIBS_INIT}
${CMAKE_DL_LIBS})
-if(${CMAKE_SYSTEM_NAME} MATCHES SunOS)
- winpr_library_add_private(rt)
-endif()
-
if(BUILD_TESTING)
add_subdirectory(test)
endif()
diff --git a/winpr/libwinpr/path/CMakeLists.txt b/winpr/libwinpr/path/CMakeLists.txt
index 1e4ed92..a5a75c6 100644
--- a/winpr/libwinpr/path/CMakeLists.txt
+++ b/winpr/libwinpr/path/CMakeLists.txt
@@ -17,6 +17,10 @@
winpr_module_add(path.c shell.c)
+if (MSVC OR MINGW)
+ winpr_library_add_public(shlwapi)
+endif()
+
if (IOS)
winpr_module_add(shell_ios.m)
endif (IOS)
diff --git a/winpr/libwinpr/path/path.c b/winpr/libwinpr/path/path.c
index 82e6be1..3f20465 100644
--- a/winpr/libwinpr/path/path.c
+++ b/winpr/libwinpr/path/path.c
@@ -1002,7 +1002,7 @@ PCSTR PathGetSharedLibraryExtensionA(unsigned long dwFlags)
PCWSTR PathGetSharedLibraryExtensionW(unsigned long dwFlags)
{
- WCHAR buffer[6][16] = { 0 };
+ static WCHAR buffer[6][16] = { 0 };
const WCHAR* SharedLibraryExtensionDotDllW = InitializeConstWCharFromUtf8(
SharedLibraryExtensionDotDllA, buffer[0], ARRAYSIZE(buffer[0]));
const WCHAR* SharedLibraryExtensionDotSoW =
@@ -1131,11 +1131,12 @@ BOOL winpr_RemoveDirectory_RecursiveW(LPCWSTR lpPathName)
WCHAR starbuffer[8] = { 0 };
const WCHAR* star = InitializeConstWCharFromUtf8("*", starbuffer, ARRAYSIZE(starbuffer));
const HRESULT hr = NativePathCchAppendW(path_slash, path_slash_len, star);
+ HANDLE dir = INVALID_HANDLE_VALUE;
if (FAILED(hr))
goto fail;
WIN32_FIND_DATAW findFileData = { 0 };
- HANDLE dir = FindFirstFileW(path_slash, &findFileData);
+ dir = FindFirstFileW(path_slash, &findFileData);
if (dir == INVALID_HANDLE_VALUE)
goto fail;
@@ -1167,8 +1168,6 @@ BOOL winpr_RemoveDirectory_RecursiveW(LPCWSTR lpPathName)
break;
} while (ret && FindNextFileW(dir, &findFileData) != 0);
- FindClose(dir);
-
if (ret)
{
if (!RemoveDirectoryW(lpPathName))
@@ -1176,6 +1175,7 @@ BOOL winpr_RemoveDirectory_RecursiveW(LPCWSTR lpPathName)
}
fail:
+ FindClose(dir);
free(path_slash);
return ret;
}
diff --git a/winpr/libwinpr/path/shell.c b/winpr/libwinpr/path/shell.c
index 4380a9b..a1e7b4e 100644
--- a/winpr/libwinpr/path/shell.c
+++ b/winpr/libwinpr/path/shell.c
@@ -670,12 +670,6 @@ fail:
return ret;
}
-#else
-
-#ifdef _MSC_VER
-#pragma comment(lib, "shlwapi.lib")
-#endif
-
#endif
BOOL winpr_MoveFile(LPCSTR lpExistingFileName, LPCSTR lpNewFileName)
diff --git a/winpr/libwinpr/pool/CMakeLists.txt b/winpr/libwinpr/pool/CMakeLists.txt
index 2e25916..bf6a663 100644
--- a/winpr/libwinpr/pool/CMakeLists.txt
+++ b/winpr/libwinpr/pool/CMakeLists.txt
@@ -30,10 +30,6 @@ winpr_library_add_private(
${CMAKE_THREAD_LIBS_INIT}
${CMAKE_DL_LIBS})
-if(${CMAKE_SYSTEM_NAME} MATCHES SunOS)
- winpr_library_add_private(rt)
-endif()
-
if(BUILD_TESTING)
add_subdirectory(test)
endif()
diff --git a/winpr/libwinpr/smartcard/smartcard_pcsc.c b/winpr/libwinpr/smartcard/smartcard_pcsc.c
index fb04d56..0745f40 100644
--- a/winpr/libwinpr/smartcard/smartcard_pcsc.c
+++ b/winpr/libwinpr/smartcard/smartcard_pcsc.c
@@ -992,8 +992,14 @@ static LONG WINAPI PCSC_SCardListReadersW(SCARDCONTEXT hContext, LPCWSTR mszGrou
return SCARD_E_NO_MEMORY;
}
- status =
- PCSC_SCardListReaders_Internal(hContext, mszGroupsA, (LPSTR*)&mszReadersA, pcchReaders);
+ union
+ {
+ LPSTR* ppc;
+ LPSTR pc;
+ } cnv;
+ cnv.ppc = &mszReadersA;
+
+ status = PCSC_SCardListReaders_Internal(hContext, mszGroupsA, cnv.pc, pcchReaders);
if (status == SCARD_S_SUCCESS)
{
size_t size = 0;
@@ -2380,7 +2386,10 @@ static LONG WINAPI PCSC_SCardGetAttrib_Internal(SCARDHANDLE hCard, DWORD dwAttrI
status = g_PCSC.pfnSCardGetAttrib(hCard, pcsc_dwAttrId, tmp, &pcsc_cbAttrLen);
if (status != SCARD_S_SUCCESS)
+ {
free(tmp);
+ tmp = NULL;
+ }
else
PCSC_AddMemoryBlock(hContext, tmp);
*(BYTE**)pbAttr = tmp;
@@ -2768,6 +2777,9 @@ static LONG WINAPI PCSC_SCardReadCacheA(SCARDCONTEXT hContext, UUID* CardIdentif
{
PCSC_CACHE_ITEM* data = NULL;
PCSC_SCARDCONTEXT* ctx = PCSC_GetCardContextData(hContext);
+ if (!ctx)
+ return SCARD_E_INVALID_HANDLE;
+
char* id = card_id_and_name_a(CardIdentifier, LookupName);
data = HashTable_GetItemValue(ctx->cache, id);
@@ -2811,6 +2823,9 @@ static LONG WINAPI PCSC_SCardReadCacheW(SCARDCONTEXT hContext, UUID* CardIdentif
{
PCSC_CACHE_ITEM* data = NULL;
PCSC_SCARDCONTEXT* ctx = PCSC_GetCardContextData(hContext);
+ if (!ctx)
+ return SCARD_E_INVALID_HANDLE;
+
char* id = card_id_and_name_w(CardIdentifier, LookupName);
data = HashTable_GetItemValue(ctx->cache, id);
diff --git a/winpr/libwinpr/sspi/Kerberos/kerberos.c b/winpr/libwinpr/sspi/Kerberos/kerberos.c
index b7b71f9..3cf7786 100644
--- a/winpr/libwinpr/sspi/Kerberos/kerberos.c
+++ b/winpr/libwinpr/sspi/Kerberos/kerberos.c
@@ -657,6 +657,7 @@ static BOOL kerberos_rd_tgt_token(const sspi_gss_data* token, char** target, krb
*buf++ = '@';
strcpy(buf, str);
+ free(str);
return TRUE;
}
else if (val == KRB_TGT_REP)
@@ -1303,6 +1304,9 @@ static KRB_CONTEXT* get_context(PCtxtHandle phContext)
return NULL;
TCHAR* name = sspi_SecureHandleGetUpperPointer(phContext);
+ if (!name)
+ return NULL;
+
if (_tcscmp(KERBEROS_SSP_NAME, name) != 0)
return NULL;
return sspi_SecureHandleGetLowerPointer(phContext);
diff --git a/winpr/libwinpr/sspi/Kerberos/krb5glue_mit.c b/winpr/libwinpr/sspi/Kerberos/krb5glue_mit.c
index 2638b22..619f029 100644
--- a/winpr/libwinpr/sspi/Kerberos/krb5glue_mit.c
+++ b/winpr/libwinpr/sspi/Kerberos/krb5glue_mit.c
@@ -183,7 +183,10 @@ krb5_error_code krb5glue_get_init_creds(krb5_context ctx, krb5_principal princ,
rv = ENOMEM;
if (winpr_asprintf(&kdc_url, &size, "https://%s/KdcProxy", krb_settings->kdcUrl) <= 0)
+ {
+ free(kdc_url);
goto cleanup;
+ }
realm = calloc(princ->realm.length + 1, 1);
if (!realm)
@@ -210,7 +213,7 @@ krb5_error_code krb5glue_get_init_creds(krb5_context ctx, krb5_principal princ,
if ((rv = profile_flush_to_file(profile, tmp_profile_path)))
goto cleanup;
- profile_release(profile);
+ profile_abandon(profile);
profile = NULL;
if ((rv = profile_init_path(tmp_profile_path, &profile)))
goto cleanup;
@@ -239,7 +242,7 @@ cleanup:
krb5_get_init_creds_opt_free(ctx, gic_opt);
if (is_temp_ctx)
krb5_free_context(ctx);
- profile_release(profile);
+ profile_abandon(profile);
winpr_DeleteFile(tmp_profile_path);
free(tmp_profile_path);
diff --git a/winpr/libwinpr/sspi/NTLM/ntlm.c b/winpr/libwinpr/sspi/NTLM/ntlm.c
index 6a2ee6a..bc16a40 100644
--- a/winpr/libwinpr/sspi/NTLM/ntlm.c
+++ b/winpr/libwinpr/sspi/NTLM/ntlm.c
@@ -1255,7 +1255,10 @@ static SECURITY_STATUS SEC_ENTRY ntlm_MakeSignature(PCtxtHandle phContext, ULONG
WINPR_HMAC_CTX* hmac = winpr_HMAC_New();
if (!winpr_HMAC_Init(hmac, WINPR_MD_MD5, context->SendSigningKey, WINPR_MD5_DIGEST_LENGTH))
+ {
+ winpr_HMAC_Free(hmac);
return SEC_E_INTERNAL_ERROR;
+ }
Data_Write_UINT32(&seq_no, MessageSeqNo);
winpr_HMAC_Update(hmac, (BYTE*)&seq_no, 4);
@@ -1303,7 +1306,10 @@ static SECURITY_STATUS SEC_ENTRY ntlm_VerifySignature(PCtxtHandle phContext,
WINPR_HMAC_CTX* hmac = winpr_HMAC_New();
if (!winpr_HMAC_Init(hmac, WINPR_MD_MD5, context->RecvSigningKey, WINPR_MD5_DIGEST_LENGTH))
+ {
+ winpr_HMAC_Free(hmac);
return SEC_E_INTERNAL_ERROR;
+ }
Data_Write_UINT32(&seq_no, MessageSeqNo);
winpr_HMAC_Update(hmac, (BYTE*)&seq_no, 4);
diff --git a/winpr/libwinpr/sspi/NTLM/ntlm_av_pairs.c b/winpr/libwinpr/sspi/NTLM/ntlm_av_pairs.c
index 881a743..b270947 100644
--- a/winpr/libwinpr/sspi/NTLM/ntlm_av_pairs.c
+++ b/winpr/libwinpr/sspi/NTLM/ntlm_av_pairs.c
@@ -124,7 +124,6 @@ static INLINE BOOL ntlm_av_pair_get_id(const NTLM_AV_PAIR* pAvPair, size_t size,
ULONG ntlm_av_pair_list_length(NTLM_AV_PAIR* pAvPairList, size_t cbAvPairList)
{
- size_t size = 0;
size_t cbAvPair = 0;
NTLM_AV_PAIR* pAvPair = NULL;
@@ -132,8 +131,12 @@ ULONG ntlm_av_pair_list_length(NTLM_AV_PAIR* pAvPairList, size_t cbAvPairList)
if (!pAvPair)
return 0;
- size = ((PBYTE)pAvPair - (PBYTE)pAvPairList) + sizeof(NTLM_AV_PAIR);
+ if (pAvPair < pAvPairList)
+ return 0;
+
+ const size_t size = ((PBYTE)pAvPair - (PBYTE)pAvPairList) + sizeof(NTLM_AV_PAIR);
WINPR_ASSERT(size <= ULONG_MAX);
+ WINPR_ASSERT(size >= 0);
return (ULONG)size;
}
diff --git a/winpr/libwinpr/sspi/NTLM/ntlm_compute.c b/winpr/libwinpr/sspi/NTLM/ntlm_compute.c
index 9c6e818..69970c8 100644
--- a/winpr/libwinpr/sspi/NTLM/ntlm_compute.c
+++ b/winpr/libwinpr/sspi/NTLM/ntlm_compute.c
@@ -248,15 +248,12 @@ BOOL ntlm_write_ntlm_v2_response(wStream* s, const NTLMv2_RESPONSE* response)
void ntlm_current_time(BYTE* timestamp)
{
- FILETIME filetime = { 0 };
- ULARGE_INTEGER time64 = { 0 };
+ FILETIME ft = { 0 };
WINPR_ASSERT(timestamp);
- GetSystemTimeAsFileTime(&filetime);
- time64.u.LowPart = filetime.dwLowDateTime;
- time64.u.HighPart = filetime.dwHighDateTime;
- CopyMemory(timestamp, &(time64.QuadPart), 8);
+ GetSystemTimeAsFileTime(&ft);
+ CopyMemory(timestamp, &(ft), sizeof(ft));
}
/**
diff --git a/winpr/libwinpr/sspi/Negotiate/negotiate.c b/winpr/libwinpr/sspi/Negotiate/negotiate.c
index 7249399..66d8d53 100644
--- a/winpr/libwinpr/sspi/Negotiate/negotiate.c
+++ b/winpr/libwinpr/sspi/Negotiate/negotiate.c
@@ -97,13 +97,14 @@ static const WinPrAsn1_OID negoex_OID = { 10, (BYTE*)"\x2b\x06\x01\x04\x01\x82\x
#ifdef WITH_KRB5
static const SecPkg SecPkgTable[] = {
{ KERBEROS_SSP_NAME, &KERBEROS_SecurityFunctionTableA, &KERBEROS_SecurityFunctionTableW },
+ { KERBEROS_SSP_NAME, &KERBEROS_SecurityFunctionTableA, &KERBEROS_SecurityFunctionTableW },
{ NTLM_SSP_NAME, &NTLM_SecurityFunctionTableA, &NTLM_SecurityFunctionTableW }
};
static const Mech MechTable[] = {
{ &kerberos_u2u_OID, &SecPkgTable[0], ISC_REQ_INTEGRITY | ISC_REQ_USE_SESSION_KEY, TRUE },
- { &kerberos_OID, &SecPkgTable[0], ISC_REQ_INTEGRITY, TRUE },
- { &ntlm_OID, &SecPkgTable[1], 0, FALSE },
+ { &kerberos_OID, &SecPkgTable[1], ISC_REQ_INTEGRITY, TRUE },
+ { &ntlm_OID, &SecPkgTable[2], 0, FALSE },
};
#else
static const SecPkg SecPkgTable[] = { { NTLM_SSP_NAME, &NTLM_SecurityFunctionTableA,
@@ -599,7 +600,11 @@ static SECURITY_STATUS negotiate_mic_exchange(NEGOTIATE_CONTEXT* context, NegTok
}
/* When using NTLM cipher states need to be reset after mic exchange */
- if (_tcscmp(sspi_SecureHandleGetUpperPointer(&context->sub_context), NTLM_SSP_NAME) == 0)
+ const TCHAR* name = sspi_SecureHandleGetUpperPointer(&context->sub_context);
+ if (!name)
+ return SEC_E_INTERNAL_ERROR;
+
+ if (_tcscmp(name, NTLM_SSP_NAME) == 0)
{
if (!ntlm_reset_cipher_state(&context->sub_context))
return SEC_E_INTERNAL_ERROR;
@@ -674,6 +679,9 @@ static SECURITY_STATUS SEC_ENTRY negotiate_InitializeSecurityContextW(
if (!init_context.mech)
{
/* Use the output buffer to store the optimistic token */
+ if (!output_buffer)
+ goto cleanup;
+
CopyMemory(&output_token.mechToken, output_buffer, sizeof(SecBuffer));
if (bindings_buffer)
@@ -1127,7 +1135,8 @@ static SECURITY_STATUS SEC_ENTRY negotiate_AcceptSecurityContext(
return SEC_E_INVALID_TOKEN;
/* Use the output buffer to store the optimistic token */
- CopyMemory(&output_token.mechToken, output_buffer, sizeof(SecBuffer));
+ if (output_buffer)
+ CopyMemory(&output_token.mechToken, output_buffer, sizeof(SecBuffer));
status = context->mech->pkg->table->AcceptSecurityContext(
sub_cred, &context->sub_context, &mech_input, fContextReq | context->mech->flags,
diff --git a/winpr/libwinpr/synch/timer.c b/winpr/libwinpr/synch/timer.c
index 8238a88..354382c 100644
--- a/winpr/libwinpr/synch/timer.c
+++ b/winpr/libwinpr/synch/timer.c
@@ -707,11 +707,11 @@ static void timespec_add_ms(struct timespec* tspec, UINT32 ms)
static void timespec_gettimeofday(struct timespec* tspec)
{
- struct timeval tval;
WINPR_ASSERT(tspec);
- gettimeofday(&tval, NULL);
- tspec->tv_sec = tval.tv_sec;
- tspec->tv_nsec = tval.tv_usec * 1000;
+
+ const UINT64 ns = winpr_GetUnixTimeNS();
+ tspec->tv_sec = WINPR_TIME_NS_TO_S(ns);
+ tspec->tv_nsec = WINPR_TIME_NS_REM_NS(ns);
}
static INT64 timespec_compare(const struct timespec* tspec1, const struct timespec* tspec2)
@@ -881,12 +881,13 @@ static void* TimerQueueThread(void* arg)
status = pthread_cond_timedwait(&(timerQueue->cond), &(timerQueue->cond_mutex), &timeout);
FireExpiredTimerQueueTimers(timerQueue);
+ const BOOL bCancelled = timerQueue->bCancelled;
pthread_mutex_unlock(&(timerQueue->cond_mutex));
if ((status != ETIMEDOUT) && (status != 0))
break;
- if (timerQueue->bCancelled)
+ if (bCancelled)
break;
}
diff --git a/winpr/libwinpr/synch/wait.c b/winpr/libwinpr/synch/wait.c
index 3bef657..865f583 100644
--- a/winpr/libwinpr/synch/wait.c
+++ b/winpr/libwinpr/synch/wait.c
@@ -59,60 +59,16 @@
#include "../pipe/pipe.h"
-/* clock_gettime is not implemented on OSX prior to 10.12 */
-#if defined(__MACH__) && defined(__APPLE__)
-
-#include <mach/mach_time.h>
-
-#ifndef CLOCK_REALTIME
-#define CLOCK_REALTIME 0
-#endif
-
-#ifndef CLOCK_MONOTONIC
-#define CLOCK_MONOTONIC 0
-#endif
-
-/* clock_gettime is not implemented on OSX prior to 10.12 */
-int _mach_clock_gettime(int clk_id, struct timespec* t);
-
-int _mach_clock_gettime(int clk_id, struct timespec* t)
-{
- UINT64 time = 0;
- double seconds = 0.0;
- double nseconds = 0.0;
- mach_timebase_info_data_t timebase = { 0 };
- mach_timebase_info(&timebase);
- time = mach_absolute_time();
- nseconds = ((double)time * (double)timebase.numer) / ((double)timebase.denom);
- seconds = ((double)time * (double)timebase.numer) / ((double)timebase.denom * 1e9);
- t->tv_sec = seconds;
- t->tv_nsec = nseconds;
- return 0;
-}
-
-/* if clock_gettime is declared, then __CLOCK_AVAILABILITY will be defined */
-#ifdef __CLOCK_AVAILABILITY
-/* If we compiled with Mac OSX 10.12 or later, then clock_gettime will be declared
- * * but it may be NULL at runtime. So we need to check before using it. */
-int _mach_safe_clock_gettime(int clk_id, struct timespec* t);
-
-int _mach_safe_clock_gettime(int clk_id, struct timespec* t)
+static struct timespec ts_from_ns(void)
{
- if (clock_gettime)
- {
- return clock_gettime(clk_id, t);
- }
-
- return _mach_clock_gettime(clk_id, t);
+ const UINT64 ns = winpr_GetUnixTimeNS();
+ struct timespec timeout = { 0 };
+ timeout.tv_sec = WINPR_TIME_NS_TO_S(ns);
+ timeout.tv_nsec = WINPR_TIME_NS_REM_NS(ns);
+ ;
+ return timeout;
}
-#define clock_gettime _mach_safe_clock_gettime
-#else
-#define clock_gettime _mach_clock_gettime
-#endif
-
-#endif
-
/**
* Drop in replacement for pthread_mutex_timedlock
* http://code.google.com/p/android/issues/detail?id=7807
@@ -148,14 +104,14 @@ STATIC_NEEDED int pthread_mutex_timedlock(pthread_mutex_t* mutex,
unsigned long long diff = 0;
int retcode = -1;
/* This is just to avoid a completely busy wait */
- clock_gettime(CLOCK_MONOTONIC, &timenow);
+ timenow = ts_from_ns();
diff = ts_difftime(&timenow, timeout);
sleepytime.tv_sec = diff / 1000000000LL;
sleepytime.tv_nsec = diff % 1000000000LL;
while ((retcode = pthread_mutex_trylock(mutex)) == EBUSY)
{
- clock_gettime(CLOCK_MONOTONIC, &timenow);
+ timenow = ts_from_ns();
if (ts_difftime(timeout, &timenow) >= 0)
{
@@ -237,8 +193,8 @@ DWORD WaitForSingleObjectEx(HANDLE hHandle, DWORD dwMilliseconds, BOOL bAlertabl
if (dwMilliseconds != INFINITE)
{
int status = 0;
- struct timespec timeout = { 0 };
- clock_gettime(CLOCK_MONOTONIC, &timeout);
+ struct timespec timeout = ts_from_ns();
+
ts_add_ms(&timeout, dwMilliseconds);
status = pthread_mutex_timedlock(&mutex->mutex, &timeout);
diff --git a/winpr/libwinpr/sysinfo/cpufeatures/cpu-features.c b/winpr/libwinpr/sysinfo/cpufeatures/cpu-features.c
index d43b588..854c93a 100644
--- a/winpr/libwinpr/sysinfo/cpufeatures/cpu-features.c
+++ b/winpr/libwinpr/sysinfo/cpufeatures/cpu-features.c
@@ -73,6 +73,7 @@
#include <sys/system_properties.h>
#include <unistd.h>
#include <winpr/wtypes.h>
+#include <winpr/debug.h>
static pthread_once_t g_once;
static int g_inited;
diff --git a/winpr/libwinpr/sysinfo/sysinfo.c b/winpr/libwinpr/sysinfo/sysinfo.c
index f12f4eb..bf81b8b 100644
--- a/winpr/libwinpr/sysinfo/sysinfo.c
+++ b/winpr/libwinpr/sysinfo/sysinfo.c
@@ -33,9 +33,43 @@
#include <fcntl.h>
#endif
+#if !defined(_WIN32)
+#if defined(_POSIX_C_SOURCE) && (_POSIX_C_SOURCE >= 199309L)
+#include <time.h>
+#elif !defined(__APPLE__)
+#include <sys/time.h>
+#include <sys/sysinfo.h>
+#endif
+#endif
+
#include "../log.h"
#define TAG WINPR_TAG("sysinfo")
+#define FILETIME_TO_UNIX_OFFSET_S 11644473600UL
+
+#if defined(__MACH__) && defined(__APPLE__)
+
+#include <mach/mach_time.h>
+
+static UINT64 scaleHighPrecision(UINT64 i, UINT32 numer, UINT32 denom)
+{
+ UINT64 high = (i >> 32) * numer;
+ UINT64 low = (i & 0xffffffffull) * numer / denom;
+ UINT64 highRem = ((high % denom) << 32) / denom;
+ high /= denom;
+ return (high << 32) + highRem + low;
+}
+
+static UINT64 mac_get_time_ns(void)
+{
+ mach_timebase_info_data_t timebase = { 0 };
+ mach_timebase_info(&timebase);
+ UINT64 t = mach_absolute_time();
+ return scaleHighPrecision(t, timebase.numer, timebase.denom);
+}
+
+#endif
+
/**
* api-ms-win-core-sysinfo-l1-1-1.dll:
*
@@ -272,13 +306,14 @@ BOOL SetLocalTime(CONST SYSTEMTIME* lpSystemTime)
VOID GetSystemTimeAsFileTime(LPFILETIME lpSystemTimeAsFileTime)
{
- ULARGE_INTEGER time64;
- time64.u.HighPart = 0;
- /* time represented in tenths of microseconds since midnight of January 1, 1601 */
- time64.QuadPart = time(NULL) + 11644473600LL; /* Seconds since January 1, 1601 */
- time64.QuadPart *= 10000000; /* Convert timestamp to tenths of a microsecond */
- lpSystemTimeAsFileTime->dwLowDateTime = time64.u.LowPart;
- lpSystemTimeAsFileTime->dwHighDateTime = time64.u.HighPart;
+ union
+ {
+ UINT64 u64;
+ FILETIME ft;
+ } t;
+
+ t.u64 = (winpr_GetUnixTimeNS() / 100ull) + FILETIME_TO_UNIX_OFFSET_S * 10000000ull;
+ *lpSystemTimeAsFileTime = t.ft;
}
BOOL GetSystemTimeAdjustment(PDWORD lpTimeAdjustment, PDWORD lpTimeIncrement,
@@ -294,25 +329,7 @@ BOOL GetSystemTimeAdjustment(PDWORD lpTimeAdjustment, PDWORD lpTimeIncrement,
DWORD GetTickCount(void)
{
- DWORD ticks = 0;
-#ifdef __linux__
- struct timespec ts;
-
- if (!clock_gettime(CLOCK_MONOTONIC_RAW, &ts))
- ticks = (ts.tv_sec * 1000) + (ts.tv_nsec / 1000000);
-
-#else
- /**
- * FIXME: this is relative to the Epoch time, and we
- * need to return a value relative to the system uptime.
- */
- struct timeval tv;
-
- if (!gettimeofday(&tv, NULL))
- ticks = (tv.tv_sec * 1000) + (tv.tv_usec / 1000);
-
-#endif
- return ticks;
+ return GetTickCount64();
}
#endif // _WIN32
@@ -553,35 +570,80 @@ DWORD GetTickCount(void)
ULONGLONG winpr_GetTickCount64(void)
{
- ULONGLONG ticks = 0;
-#if defined(__linux__)
- struct timespec ts;
+ const UINT64 ns = winpr_GetTickCount64NS();
+ return WINPR_TIME_NS_TO_MS(ns);
+}
- if (!clock_gettime(CLOCK_MONOTONIC_RAW, &ts))
- ticks = (ts.tv_sec * 1000) + (ts.tv_nsec / 1000000);
+#endif
+UINT64 winpr_GetTickCount64NS(void)
+{
+ UINT64 ticks = 0;
+#if defined(_POSIX_C_SOURCE) && (_POSIX_C_SOURCE >= 199309L)
+ struct timespec ts = { 0 };
+
+ if (clock_gettime(CLOCK_MONOTONIC_RAW, &ts) == 0)
+ ticks = (ts.tv_sec * 1000000000ull) + ts.tv_nsec;
+#elif defined(__MACH__) && defined(__APPLE__)
+ ticks = mac_get_time_ns();
#elif defined(_WIN32)
- FILETIME ft;
- ULARGE_INTEGER ul;
- GetSystemTimeAsFileTime(&ft);
- ul.LowPart = ft.dwLowDateTime;
- ul.HighPart = ft.dwHighDateTime;
- ticks = ul.QuadPart;
+ LARGE_INTEGER li = { 0 };
+ LARGE_INTEGER freq = { 0 };
+ if (QueryPerformanceFrequency(&freq) && QueryPerformanceCounter(&li))
+ ticks = li.QuadPart * 1000000000ull / freq.QuadPart;
#else
- /**
- * FIXME: this is relative to the Epoch time, and we
- * need to return a value relative to the system uptime.
- */
- struct timeval tv;
+ struct timeval tv = { 0 };
- if (!gettimeofday(&tv, NULL))
- ticks = (tv.tv_sec * 1000) + (tv.tv_usec / 1000);
+ if (gettimeofday(&tv, NULL) == 0)
+ ticks = (tv.tv_sec * 1000000000ull) + (tv.tv_usec * 1000ull);
+
+ /* We need to trick here:
+ * this function should return the system uptime, but we need higher resolution.
+ * so on first call get the actual timestamp along with the system uptime.
+ *
+ * return the uptime measured from now on (e.g. current measure - first measure + uptime at
+ * first measure)
+ */
+ static UINT64 first = 0;
+ static UINT64 uptime = 0;
+ if (first == 0)
+ {
+ struct sysinfo info = { 0 };
+ if (sysinfo(&info) == 0)
+ {
+ first = ticks;
+ uptime = 1000000000ull * info.uptime;
+ }
+ }
+ ticks = ticks - first + uptime;
#endif
return ticks;
}
+UINT64 winpr_GetUnixTimeNS(void)
+{
+#if defined(_WIN32)
+
+ union
+ {
+ UINT64 u64;
+ FILETIME ft;
+ } t = { 0 };
+ GetSystemTimeAsFileTime(&t.ft);
+ return (t.u64 - FILETIME_TO_UNIX_OFFSET_S * 10000000ull) * 100ull;
+#elif defined(_POSIX_C_SOURCE) && (_POSIX_C_SOURCE >= 199309L)
+ struct timespec ts = { 0 };
+ if (clock_gettime(CLOCK_REALTIME, &ts) != 0)
+ return 0;
+ return ts.tv_sec * 1000000000ull + ts.tv_nsec;
+#else
+ struct timeval tv = { 0 };
+ if (gettimeofday(&tv, NULL) != 0)
+ return 0;
+ return tv.tv_sec * 1000000000ULL + tv.tv_usec * 1000ull;
#endif
+}
/* If x86 */
#ifdef _M_IX86_AMD64
diff --git a/winpr/libwinpr/thread/CMakeLists.txt b/winpr/libwinpr/thread/CMakeLists.txt
index bfc04dd..2e9cd05 100644
--- a/winpr/libwinpr/thread/CMakeLists.txt
+++ b/winpr/libwinpr/thread/CMakeLists.txt
@@ -25,10 +25,6 @@ winpr_module_add(
thread.h
tls.c)
-if(${CMAKE_SYSTEM_NAME} MATCHES SunOS)
- winpr_library_add_private(rt)
-endif()
-
if(BUILD_TESTING)
add_subdirectory(test)
endif()
diff --git a/winpr/libwinpr/thread/thread.h b/winpr/libwinpr/thread/thread.h
index aef9bc9..92d05d3 100644
--- a/winpr/libwinpr/thread/thread.h
+++ b/winpr/libwinpr/thread/thread.h
@@ -32,49 +32,39 @@
#include "../synch/event.h"
#include "apc.h"
-#ifdef __GNUC__
-#define ALIGN64 __attribute__((aligned(8)))
-#else
-#ifdef _WIN32
-#define ALIGN64 __declspec(align(8))
-#else
-#define ALIGN64
-#endif
-#endif
-
typedef void* (*pthread_start_routine)(void*);
typedef struct winpr_APC_item WINPR_APC_ITEM;
typedef struct
{
- ALIGN64 pthread_mutex_t mux;
- ALIGN64 pthread_cond_t cond;
- ALIGN64 BOOL val;
+ WINPR_ALIGN64 pthread_mutex_t mux;
+ WINPR_ALIGN64 pthread_cond_t cond;
+ WINPR_ALIGN64 BOOL val;
} mux_condition_bundle;
struct winpr_thread
{
WINPR_HANDLE common;
- ALIGN64 BOOL started;
- ALIGN64 WINPR_EVENT_IMPL event;
- ALIGN64 BOOL mainProcess;
- ALIGN64 BOOL detached;
- ALIGN64 BOOL joined;
- ALIGN64 BOOL exited;
- ALIGN64 DWORD dwExitCode;
- ALIGN64 pthread_t thread;
- ALIGN64 SIZE_T dwStackSize;
- ALIGN64 LPVOID lpParameter;
- ALIGN64 pthread_mutex_t mutex;
+ WINPR_ALIGN64 BOOL started;
+ WINPR_ALIGN64 WINPR_EVENT_IMPL event;
+ WINPR_ALIGN64 BOOL mainProcess;
+ WINPR_ALIGN64 BOOL detached;
+ WINPR_ALIGN64 BOOL joined;
+ WINPR_ALIGN64 BOOL exited;
+ WINPR_ALIGN64 DWORD dwExitCode;
+ WINPR_ALIGN64 pthread_t thread;
+ WINPR_ALIGN64 SIZE_T dwStackSize;
+ WINPR_ALIGN64 LPVOID lpParameter;
+ WINPR_ALIGN64 pthread_mutex_t mutex;
mux_condition_bundle isRunning;
mux_condition_bundle isCreated;
- ALIGN64 LPTHREAD_START_ROUTINE lpStartAddress;
- ALIGN64 LPSECURITY_ATTRIBUTES lpThreadAttributes;
- ALIGN64 APC_QUEUE apc;
+ WINPR_ALIGN64 LPTHREAD_START_ROUTINE lpStartAddress;
+ WINPR_ALIGN64 LPSECURITY_ATTRIBUTES lpThreadAttributes;
+ WINPR_ALIGN64 APC_QUEUE apc;
#if defined(WITH_DEBUG_THREADS)
- ALIGN64 void* create_stack;
- ALIGN64 void* exit_stack;
+ WINPR_ALIGN64 void* create_stack;
+ WINPR_ALIGN64 void* exit_stack;
#endif
};
diff --git a/winpr/libwinpr/timezone/timezone.c b/winpr/libwinpr/timezone/timezone.c
index f6d9874..6ca3e54 100644
--- a/winpr/libwinpr/timezone/timezone.c
+++ b/winpr/libwinpr/timezone/timezone.c
@@ -247,10 +247,11 @@ static char* winpr_get_unix_timezone_identifier_from_file(void)
#else
FILE* fp = NULL;
char* tzid = NULL;
-#if defined(__FreeBSD__) || defined(__OpenBSD__)
- fp = winpr_fopen("/var/db/zoneinfo", "r");
+#if !defined(WINPR_TIMEZONE_FILE)
+#error \
+ "Please define WINPR_TIMEZONE_FILE with the path to your timezone file (e.g. /etc/timezone or similar)"
#else
- fp = winpr_fopen("/etc/timezone", "r");
+ fp = winpr_fopen(WINPR_TIMEZONE_FILE, "r");
#endif
if (NULL == fp)
diff --git a/winpr/libwinpr/utils/cmdline.c b/winpr/libwinpr/utils/cmdline.c
index 3d93c0a..a524d62 100644
--- a/winpr/libwinpr/utils/cmdline.c
+++ b/winpr/libwinpr/utils/cmdline.c
@@ -515,13 +515,6 @@ static size_t get_element_count(const char* list, BOOL* failed, BOOL fullquoted)
if (!fullquoted)
{
int now = is_quoted(*it);
- if ((quoted == 0) && !first)
- {
- WLog_ERR(TAG, "Invalid argument (misplaced quote) '%s'", list);
- *failed = TRUE;
- return 0;
- }
-
if (now == quoted)
quoted = 0;
else if (quoted == 0)
diff --git a/winpr/libwinpr/utils/collections/CountdownEvent.c b/winpr/libwinpr/utils/collections/CountdownEvent.c
index fd23e0c..771ba54 100644
--- a/winpr/libwinpr/utils/collections/CountdownEvent.c
+++ b/winpr/libwinpr/utils/collections/CountdownEvent.c
@@ -48,7 +48,10 @@ struct CountdownEvent
size_t CountdownEvent_CurrentCount(wCountdownEvent* countdown)
{
WINPR_ASSERT(countdown);
- return countdown->count;
+ EnterCriticalSection(&countdown->lock);
+ const size_t rc = countdown->count;
+ LeaveCriticalSection(&countdown->lock);
+ return rc;
}
/**
@@ -58,7 +61,10 @@ size_t CountdownEvent_CurrentCount(wCountdownEvent* countdown)
size_t CountdownEvent_InitialCount(wCountdownEvent* countdown)
{
WINPR_ASSERT(countdown);
- return countdown->initialCount;
+ EnterCriticalSection(&countdown->lock);
+ const size_t rc = countdown->initialCount;
+ LeaveCriticalSection(&countdown->lock);
+ return rc;
}
/**
diff --git a/winpr/libwinpr/utils/collections/HashTable.c b/winpr/libwinpr/utils/collections/HashTable.c
index 7782b2b..8bbaf84 100644
--- a/winpr/libwinpr/utils/collections/HashTable.c
+++ b/winpr/libwinpr/utils/collections/HashTable.c
@@ -561,7 +561,8 @@ size_t HashTable_GetKeys(wHashTable* table, ULONG_PTR** ppKeys)
iKey = 0;
count = table->numOfElements;
- *ppKeys = NULL;
+ if (ppKeys)
+ *ppKeys = NULL;
if (count < 1)
{
diff --git a/winpr/libwinpr/utils/collections/PubSub.c b/winpr/libwinpr/utils/collections/PubSub.c
index 0efffb7..b95f26d 100644
--- a/winpr/libwinpr/utils/collections/PubSub.c
+++ b/winpr/libwinpr/utils/collections/PubSub.c
@@ -102,7 +102,7 @@ void PubSub_AddEventTypes(wPubSub* pubSub, wEventType* events, size_t count)
new_size = pubSub->size * 2;
new_event = (wEventType*)realloc(pubSub->events, new_size * sizeof(wEventType));
if (!new_event)
- return;
+ goto fail;
pubSub->size = new_size;
pubSub->events = new_event;
}
@@ -110,6 +110,7 @@ void PubSub_AddEventTypes(wPubSub* pubSub, wEventType* events, size_t count)
CopyMemory(&pubSub->events[pubSub->count], events, count * sizeof(wEventType));
pubSub->count += count;
+fail:
if (pubSub->synchronized)
PubSub_Unlock(pubSub);
}
diff --git a/winpr/libwinpr/utils/collections/StreamPool.c b/winpr/libwinpr/utils/collections/StreamPool.c
index 910309f..3ff113a 100644
--- a/winpr/libwinpr/utils/collections/StreamPool.c
+++ b/winpr/libwinpr/utils/collections/StreamPool.c
@@ -211,7 +211,7 @@ wStream* StreamPool_Take(wStreamPool* pool, size_t size)
if (!s)
goto out_fail;
}
- else
+ else if (s)
{
Stream_SetPosition(s, 0);
Stream_SetLength(s, Stream_Capacity(s));
diff --git a/winpr/libwinpr/utils/wlog/PacketMessage.c b/winpr/libwinpr/utils/wlog/PacketMessage.c
index cc1c812..17df1ec 100644
--- a/winpr/libwinpr/utils/wlog/PacketMessage.c
+++ b/winpr/libwinpr/utils/wlog/PacketMessage.c
@@ -29,27 +29,11 @@
#include <winpr/crt.h>
#include <winpr/file.h>
#include <winpr/stream.h>
+#include <winpr/sysinfo.h>
#include "../../log.h"
#define TAG WINPR_TAG("utils.wlog")
-#ifndef _WIN32
-#include <sys/time.h>
-#else
-#include <time.h>
-#include <sys/timeb.h>
-#include <winpr/windows.h>
-
-static int gettimeofday(struct timeval* tp, void* tz)
-{
- struct _timeb timebuffer;
- _ftime(&timebuffer);
- tp->tv_sec = (long)timebuffer.time;
- tp->tv_usec = timebuffer.millitm * 1000;
- return 0;
-}
-#endif
-
static BOOL Pcap_Read_Header(wPcap* pcap, wPcapHeader* header)
{
if (pcap && pcap->fp && fread((void*)header, sizeof(wPcapHeader), 1, pcap->fp) == 1)
@@ -89,8 +73,7 @@ static BOOL Pcap_Read_Record(wPcap* pcap, wPcapRecord* record)
static BOOL Pcap_Add_Record(wPcap* pcap, void* data, UINT32 length)
{
- wPcapRecord* record;
- struct timeval tp;
+ wPcapRecord* record = NULL;
if (!pcap->tail)
{
@@ -117,9 +100,10 @@ static BOOL Pcap_Add_Record(wPcap* pcap, void* data, UINT32 length)
record->length = length;
record->header.incl_len = length;
record->header.orig_len = length;
- gettimeofday(&tp, 0);
- record->header.ts_sec = tp.tv_sec;
- record->header.ts_usec = tp.tv_usec;
+
+ UINT64 ns = winpr_GetUnixTimeNS();
+ record->header.ts_sec = WINPR_TIME_NS_TO_S(ns);
+ record->header.ts_usec = WINPR_TIME_NS_REM_US(ns);
return TRUE;
}
@@ -380,7 +364,6 @@ BOOL WLog_PacketMessage_Write(wPcap* pcap, void* data, size_t length, DWORD flag
{
wTcpHeader tcp;
wIPv4Header ipv4;
- struct timeval tp;
wPcapRecord record;
wEthernetHeader ethernet;
ethernet.Type = 0x0800;
@@ -474,9 +457,11 @@ BOOL WLog_PacketMessage_Write(wPcap* pcap, void* data, size_t length, DWORD flag
record.header.incl_len = (UINT32)record.length + offset;
record.header.orig_len = (UINT32)record.length + offset;
record.next = NULL;
- gettimeofday(&tp, 0);
- record.header.ts_sec = tp.tv_sec;
- record.header.ts_usec = tp.tv_usec;
+
+ UINT64 ns = winpr_GetUnixTimeNS();
+ record.header.ts_sec = WINPR_TIME_NS_TO_S(ns);
+ record.header.ts_usec = WINPR_TIME_NS_REM_US(ns);
+
if (!Pcap_Write_RecordHeader(pcap, &record.header) ||
!WLog_PacketMessage_Write_EthernetHeader(pcap, &ethernet) ||
!WLog_PacketMessage_Write_IPv4Header(pcap, &ipv4) ||
diff --git a/winpr/tools/CMakeLists.txt b/winpr/tools/CMakeLists.txt
index ed7734d..d7446bc 100644
--- a/winpr/tools/CMakeLists.txt
+++ b/winpr/tools/CMakeLists.txt
@@ -82,32 +82,10 @@ add_subdirectory(makecert)
set(MODULE_NAME winpr-tools)
list(REMOVE_DUPLICATES WINPR_TOOLS_DEFINITIONS)
-list(REMOVE_DUPLICATES WINPR_TOOLS_LIBS)
list(REMOVE_DUPLICATES WINPR_TOOLS_INCLUDES)
include_directories(${WINPR_TOOLS_INCLUDES})
-# On windows create dll version information.
-# Vendor, product and year are already set in top level CMakeLists.txt
-if (WIN32)
- set (RC_VERSION_MAJOR ${WINPR_VERSION_MAJOR})
- set (RC_VERSION_MINOR ${WINPR_VERSION_MINOR})
- set (RC_VERSION_BUILD ${WINPR_VERSION_REVISION})
- set (RC_VERSION_FILE "${CMAKE_SHARED_LIBRARY_PREFIX}${MODULE_NAME}${WINPR_TOOLS_API_VERSION}${CMAKE_SHARED_LIBRARY_SUFFIX}" )
-
- configure_file(
- ${PROJECT_SOURCE_DIR}/cmake/WindowsDLLVersion.rc.in
- ${CMAKE_CURRENT_BINARY_DIR}/version.rc
- @ONLY)
-
- set (WINPR_TOOLS_SRCS ${WINPR_TOOLS_SRCS} ${CMAKE_CURRENT_BINARY_DIR}/version.rc)
-endif()
-
-add_library(${MODULE_NAME} ${WINPR_TOOLS_SRCS})
-set_target_properties(${MODULE_NAME} PROPERTIES LINKER_LANGUAGE C)
-set_target_properties(${MODULE_NAME} PROPERTIES OUTPUT_NAME ${MODULE_NAME}${WINPR_TOOLS_API_VERSION})
-if (WITH_LIBRARY_VERSIONING)
- set_target_properties(${MODULE_NAME} PROPERTIES VERSION ${WINPR_TOOLS_VERSION} SOVERSION ${WINPR_TOOLS_API_VERSION})
-endif()
+AddTargetWithResourceFile(${MODULE_NAME} FALSE "${WINPR_VERSION}" WINPR_TOOLS_SRCS)
add_definitions(${WINPR_DEFINITIONS})
target_include_directories(${MODULE_NAME} INTERFACE $<INSTALL_INTERFACE:include/winpr${WINPR_VERSION_MAJOR}>)
@@ -118,10 +96,6 @@ install(TARGETS ${MODULE_NAME} COMPONENT libraries EXPORT WinPR-toolsTargets
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
-if (WITH_DEBUG_SYMBOLS AND MSVC AND BUILD_SHARED_LIBS)
- get_target_property(OUTPUT_FILENAME ${MODULE_NAME} OUTPUT_NAME)
- install(FILES ${CMAKE_PDB_BINARY_DIR}/${OUTPUT_FILENAME}.pdb DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT symbols)
-endif()
set_property(TARGET ${MODULE_NAME} PROPERTY FOLDER "WinPR/Tools")
# Add all command line utilities
diff --git a/winpr/tools/hash-cli/CMakeLists.txt b/winpr/tools/hash-cli/CMakeLists.txt
index 8f583d3..8eb9e66 100644
--- a/winpr/tools/hash-cli/CMakeLists.txt
+++ b/winpr/tools/hash-cli/CMakeLists.txt
@@ -21,39 +21,13 @@ set(MODULE_PREFIX "WINPR_TOOLS_HASH")
set(${MODULE_PREFIX}_SRCS
hash.c)
-# On windows create dll version information.
-# Vendor, product and year are already set in top level CMakeLists.txt
-if (WIN32)
- set(RC_VERSION_MAJOR ${WINPR_VERSION_MAJOR})
- set(RC_VERSION_MINOR ${WINPR_VERSION_MINOR})
- set(RC_VERSION_BUILD ${WINPR_VERSION_REVISION})
- set(RC_VERSION_FILE "${MODULE_NAME}${CMAKE_EXECUTABLE_SUFFIX}")
-
- configure_file(
- ${PROJECT_SOURCE_DIR}/cmake/WindowsDLLVersion.rc.in
- ${CMAKE_CURRENT_BINARY_DIR}/version.rc
- @ONLY)
-
- set(${MODULE_PREFIX}_SRCS ${${MODULE_PREFIX}_SRCS} ${CMAKE_CURRENT_BINARY_DIR}/version.rc)
-endif()
-
-add_executable(${MODULE_NAME} ${${MODULE_PREFIX}_SRCS})
+AddTargetWithResourceFile(${MODULE_NAME} TRUE "${WINPR_VERSION}" ${MODULE_PREFIX}_SRCS)
set(${MODULE_PREFIX}_LIBS winpr)
-set(MANPAGE_NAME "${MODULE_NAME}")
-if (WITH_BINARY_VERSIONING)
- set_target_properties(${MODULE_NAME} PROPERTIES OUTPUT_NAME "${MODULE_NAME}${WINPR_API_VERSION}")
- set(MANPAGE_NAME "${MODULE_NAME}${WINPR_API_VERSION}")
-endif()
target_link_libraries(${MODULE_NAME} ${${MODULE_PREFIX}_LIBS})
install(TARGETS ${MODULE_NAME} DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT tools EXPORT WinPRTargets)
-if (WITH_DEBUG_SYMBOLS AND MSVC)
- install(FILES ${PROJECT_BINARY_DIR}/${MODULE_NAME}.pdb DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT symbols)
-endif()
-
set_property(TARGET ${MODULE_NAME} PROPERTY FOLDER "WinPR/Tools")
-configure_file(winpr-hash.1.in ${CMAKE_CURRENT_BINARY_DIR}/${MANPAGE_NAME}.1)
-install_freerdp_man(${CMAKE_CURRENT_BINARY_DIR}/${MANPAGE_NAME}.1 1)
+generate_and_install_freerdp_man_from_template(${MODULE_NAME} "1" "${WINPR_API_VERSION}")
diff --git a/winpr/tools/makecert-cli/CMakeLists.txt b/winpr/tools/makecert-cli/CMakeLists.txt
index e92d6f2..fe9c6f7 100644
--- a/winpr/tools/makecert-cli/CMakeLists.txt
+++ b/winpr/tools/makecert-cli/CMakeLists.txt
@@ -22,42 +22,14 @@ set(MODULE_PREFIX "WINPR_MAKECERT")
set(${MODULE_PREFIX}_SRCS
main.c)
-# On windows create dll version information.
-# Vendor, product and year are already set in top level CMakeLists.txt
-if (WIN32)
- set(RC_VERSION_MAJOR ${WINPR_VERSION_MAJOR})
- set(RC_VERSION_MINOR ${WINPR_VERSION_MINOR})
- set(RC_VERSION_BUILD ${WINPR_VERSION_REVISION})
- set(RC_VERSION_FILE "${MODULE_NAME}${CMAKE_EXECUTABLE_SUFFIX}")
-
- configure_file(
- ${PROJECT_SOURCE_DIR}/cmake/WindowsDLLVersion.rc.in
- ${CMAKE_CURRENT_BINARY_DIR}/version.rc
- @ONLY)
-
- set(${MODULE_PREFIX}_SRCS ${${MODULE_PREFIX}_SRCS} ${CMAKE_CURRENT_BINARY_DIR}/version.rc)
-endif()
-
-add_executable(${MODULE_NAME} ${${MODULE_PREFIX}_SRCS})
+AddTargetWithResourceFile(${MODULE_NAME} TRUE "${WINPR_VERSION}" ${MODULE_PREFIX}_SRCS)
set(${MODULE_PREFIX}_LIBS winpr-tools)
target_link_libraries(${MODULE_NAME} ${${MODULE_PREFIX}_LIBS} winpr)
-set(MANPAGE_NAME ${MODULE_NAME})
-if (WITH_BINARY_VERSIONING)
- set_target_properties(${MODULE_NAME}
- PROPERTIES
- OUTPUT_NAME "${MODULE_NAME}${WINPR_API_VERSION}"
- )
- set(MANPAGE_NAME ${MODULE_NAME}${WINPR_API_VERSION})
-endif()
set_property(TARGET ${MODULE_NAME} PROPERTY FOLDER "WinPR/Tools")
install(TARGETS ${MODULE_NAME} DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT tools EXPORT WinPRTargets)
-if (WITH_DEBUG_SYMBOLS AND MSVC)
- install(FILES ${CMAKE_PDB_BINARY_DIR}/${MODULE_NAME}.pdb DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT symbols)
-endif()
-configure_file(winpr-makecert.1.in ${CMAKE_CURRENT_BINARY_DIR}/${MANPAGE_NAME}.1)
-install_freerdp_man(${CMAKE_CURRENT_BINARY_DIR}/${MANPAGE_NAME}.1 1)
+generate_and_install_freerdp_man_from_template(${MODULE_NAME} "1" "${WINPR_API_VERSION}")
diff --git a/winpr/tools/makecert/CMakeLists.txt b/winpr/tools/makecert/CMakeLists.txt
index a41cccd..de3ef92 100644
--- a/winpr/tools/makecert/CMakeLists.txt
+++ b/winpr/tools/makecert/CMakeLists.txt
@@ -32,13 +32,7 @@ endif()
winpr_tools_module_add(${${MODULE_PREFIX}_SRCS})
if(OPENSSL_FOUND)
- if(WIN32)
- list(APPEND ${MODULE_PREFIX}_LIBS ${OPENSSL_LIBRARIES})
- else()
- # if ${OPENSSL_LIBRARIES} libssl and libcrypto is linked
- # therefor explicitly link against libcrypto
- list(APPEND ${MODULE_PREFIX}_LIBS ${OPENSSL_CRYPTO_LIBRARIES})
- endif()
+ list(APPEND ${MODULE_PREFIX}_LIBS ${OPENSSL_LIBRARIES})
endif()
if(MBEDTLS_FOUND)