From 630affb47c485c830db9b00a5c83a047a7e63c5d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc-Andr=C3=A9=20Moreau?= Date: Mon, 18 Jun 2012 22:22:39 -0400 Subject: [PATCH] libwinpr-sysinfo: initial commit --- include/winpr/sysinfo.h | 151 +++++++++++++++++++++++++++++++++++ winpr/CMakeLists.txt | 1 + winpr/sspi/NTLM/ntlm.c | 8 +- winpr/sysinfo/CMakeLists.txt | 28 +++++++ winpr/sysinfo/sysinfo.c | 141 ++++++++++++++++++++++++++++++++ 5 files changed, 327 insertions(+), 2 deletions(-) create mode 100644 include/winpr/sysinfo.h create mode 100644 winpr/sysinfo/CMakeLists.txt create mode 100644 winpr/sysinfo/sysinfo.c diff --git a/include/winpr/sysinfo.h b/include/winpr/sysinfo.h new file mode 100644 index 000000000..85ba5bdc4 --- /dev/null +++ b/include/winpr/sysinfo.h @@ -0,0 +1,151 @@ +/** + * WinPR: Windows Portable Runtime + * System Information + * + * Copyright 2012 Marc-Andre Moreau + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef WINPR_SYSINFO_H +#define WINPR_SYSINFO_H + +#include +#include +#include +#include +#include + +#ifndef _WIN32 + +typedef enum _COMPUTER_NAME_FORMAT +{ + ComputerNameNetBIOS, + ComputerNameDnsHostname, + ComputerNameDnsDomain, + ComputerNameDnsFullyQualified, + ComputerNamePhysicalNetBIOS, + ComputerNamePhysicalDnsHostname, + ComputerNamePhysicalDnsDomain, + ComputerNamePhysicalDnsFullyQualified, + ComputerNameMax +} COMPUTER_NAME_FORMAT; + +WINPR_API BOOL GetComputerNameExA(COMPUTER_NAME_FORMAT NameType, LPSTR lpBuffer, LPDWORD nSize); +WINPR_API BOOL GetComputerNameExW(COMPUTER_NAME_FORMAT NameType, LPWSTR lpBuffer, LPDWORD nSize); + +#ifdef UNICODE +#define GetComputerNameEx GetComputerNameExW +#else +#define GetComputerNameEx GetComputerNameExA +#endif + +typedef struct _OSVERSIONINFOA +{ + DWORD dwOSVersionInfoSize; + DWORD dwMajorVersion; + DWORD dwMinorVersion; + DWORD dwBuildNumber; + DWORD dwPlatformId; + CHAR szCSDVersion[128]; +} OSVERSIONINFOA, *POSVERSIONINFOA, *LPOSVERSIONINFOA; + +typedef struct _OSVERSIONINFOW +{ + DWORD dwOSVersionInfoSize; + DWORD dwMajorVersion; + DWORD dwMinorVersion; + DWORD dwBuildNumber; + DWORD dwPlatformId; + WCHAR szCSDVersion[128]; +} OSVERSIONINFOW, *POSVERSIONINFOW, *LPOSVERSIONINFOW; + +typedef struct _OSVERSIONINFOEXA +{ + DWORD dwOSVersionInfoSize; + DWORD dwMajorVersion; + DWORD dwMinorVersion; + DWORD dwBuildNumber; + DWORD dwPlatformId; + CHAR szCSDVersion[128]; + WORD wServicePackMajor; + WORD wServicePackMinor; + WORD wSuiteMask; + BYTE wProductType; + BYTE wReserved; +} OSVERSIONINFOEXA, *POSVERSIONINFOEXA, *LPOSVERSIONINFOEXA; + +typedef struct _OSVERSIONINFOEXW +{ + DWORD dwOSVersionInfoSize; + DWORD dwMajorVersion; + DWORD dwMinorVersion; + DWORD dwBuildNumber; + DWORD dwPlatformId; + WCHAR szCSDVersion[128]; + WORD wServicePackMajor; + WORD wServicePackMinor; + WORD wSuiteMask; + BYTE wProductType; + BYTE wReserved; +} OSVERSIONINFOEXW, *POSVERSIONINFOEXW, *LPOSVERSIONINFOEXW; + +#ifdef UNICODE +#define OSVERSIONINFO OSVERSIONINFOW +#define OSVERSIONINFOEX OSVERSIONINFOEXW +#define POSVERSIONINFO POSVERSIONINFOW +#define POSVERSIONINFOEX POSVERSIONINFOEXW +#define LPOSVERSIONINFO LPOSVERSIONINFOW +#define LPOSVERSIONINFOEX LPOSVERSIONINFOEXW +#else +#define OSVERSIONINFO OSVERSIONINFOA +#define OSVERSIONINFOEX OSVERSIONINFOEXA +#define POSVERSIONINFO POSVERSIONINFOA +#define POSVERSIONINFOEX POSVERSIONINFOEXA +#define LPOSVERSIONINFO LPOSVERSIONINFOA +#define LPOSVERSIONINFOEX LPOSVERSIONINFOEXA +#endif + +#define VER_PLATFORM_WIN32_NT 0x00000002 + +#define VER_SUITE_BACKOFFICE 0x00000004 +#define VER_SUITE_BLADE 0x00000400 +#define VER_SUITE_COMPUTE_SERVER 0x00004000 +#define VER_SUITE_DATACENTER 0x00000080 +#define VER_SUITE_ENTERPRISE 0x00000002 +#define VER_SUITE_EMBEDDEDNT 0x00000040 +#define VER_SUITE_PERSONAL 0x00000200 +#define VER_SUITE_SINGLEUSERTS 0x00000100 +#define VER_SUITE_SMALLBUSINESS 0x00000001 +#define VER_SUITE_SMALLBUSINESS_RESTRICTED 0x00000020 +#define VER_SUITE_STORAGE_SERVER 0x00002000 +#define VER_SUITE_TERMINAL 0x00000010 +#define VER_SUITE_WH_SERVER 0x00008000 + +#define VER_NT_DOMAIN_CONTROLLER 0x0000002 +#define VER_NT_SERVER 0x0000003 +#define VER_NT_WORKSTATION 0x0000001 + +WINPR_API BOOL GetVersionExA(LPOSVERSIONINFOA lpVersionInformation); +WINPR_API BOOL GetVersionExW(LPOSVERSIONINFOW lpVersionInformation); + +#ifdef UNICODE +#define GetVersionEx GetVersionExW +#else +#define GetVersionEx GetVersionExA +#endif + +#endif + +#endif /* WINPR_SYSINFO_H */ + diff --git a/winpr/CMakeLists.txt b/winpr/CMakeLists.txt index 1b4e1b5f9..f878434da 100644 --- a/winpr/CMakeLists.txt +++ b/winpr/CMakeLists.txt @@ -22,6 +22,7 @@ add_subdirectory(utils) add_subdirectory(heap) add_subdirectory(handle) add_subdirectory(synch) +add_subdirectory(sysinfo) add_subdirectory(bcrypt) add_subdirectory(rpc) add_subdirectory(sspi) diff --git a/winpr/sspi/NTLM/ntlm.c b/winpr/sspi/NTLM/ntlm.c index ba3480d31..1d9c3917f 100644 --- a/winpr/sspi/NTLM/ntlm.c +++ b/winpr/sspi/NTLM/ntlm.c @@ -142,7 +142,9 @@ SECURITY_STATUS SEC_ENTRY ntlm_AcquireCredentialsHandleA(SEC_CHAR* pszPrincipal, credentials = sspi_CredentialsNew(); identity = (SEC_WINNT_AUTH_IDENTITY*) pAuthData; - CopyMemory(&(credentials->identity), identity, sizeof(SEC_WINNT_AUTH_IDENTITY)); + + if (identity != NULL) + CopyMemory(&(credentials->identity), identity, sizeof(SEC_WINNT_AUTH_IDENTITY)); sspi_SecureHandleSetLowerPointer(phCredential, (void*) credentials); sspi_SecureHandleSetUpperPointer(phCredential, (void*) NTLM_PACKAGE_NAME); @@ -154,7 +156,9 @@ SECURITY_STATUS SEC_ENTRY ntlm_AcquireCredentialsHandleA(SEC_CHAR* pszPrincipal, credentials = sspi_CredentialsNew(); identity = (SEC_WINNT_AUTH_IDENTITY*) pAuthData; - CopyMemory(&(credentials->identity), identity, sizeof(SEC_WINNT_AUTH_IDENTITY)); + + if (identity != NULL) + CopyMemory(&(credentials->identity), identity, sizeof(SEC_WINNT_AUTH_IDENTITY)); sspi_SecureHandleSetLowerPointer(phCredential, (void*) credentials); sspi_SecureHandleSetUpperPointer(phCredential, (void*) NTLM_PACKAGE_NAME); diff --git a/winpr/sysinfo/CMakeLists.txt b/winpr/sysinfo/CMakeLists.txt new file mode 100644 index 000000000..cf82e0be7 --- /dev/null +++ b/winpr/sysinfo/CMakeLists.txt @@ -0,0 +1,28 @@ +# WinPR: Windows Portable Runtime +# libwinpr-sysinfo cmake build script +# +# Copyright 2011 O.S. Systems Software Ltda. +# Copyright 2011 Otavio Salvador +# Copyright 2011 Marc-Andre Moreau +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +set(WINPR_SYSINFO_SRCS + sysinfo.c) + +add_library(winpr-sysinfo ${WINPR_SYSINFO_SRCS}) + +set_target_properties(winpr-sysinfo PROPERTIES VERSION ${FREERDP_VERSION_FULL} SOVERSION ${FREERDP_VERSION} PREFIX "lib") + +install(TARGETS winpr-sysinfo DESTINATION ${CMAKE_INSTALL_LIBDIR}) + diff --git a/winpr/sysinfo/sysinfo.c b/winpr/sysinfo/sysinfo.c new file mode 100644 index 000000000..9e44e84f2 --- /dev/null +++ b/winpr/sysinfo/sysinfo.c @@ -0,0 +1,141 @@ +/** + * WinPR: Windows Portable Runtime + * System Information + * + * Copyright 2012 Marc-Andre Moreau + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include + +/** + * api-ms-win-core-sysinfo-l1-1-1.dll: + * + * EnumSystemFirmwareTables + * GetComputerNameExA + * GetComputerNameExW + * GetDynamicTimeZoneInformation + * GetLocalTime + * GetLogicalProcessorInformation + * GetLogicalProcessorInformationEx + * GetNativeSystemInfo + * GetProductInfo + * GetSystemDirectoryA + * GetSystemDirectoryW + * GetSystemFirmwareTable + * GetSystemInfo + * GetSystemTime + * GetSystemTimeAdjustment + * GetSystemTimeAsFileTime + * GetSystemWindowsDirectoryA + * GetSystemWindowsDirectoryW + * GetTickCount + * GetTickCount64 + * GetTimeZoneInformation + * GetTimeZoneInformationForYear + * GetVersion + * GetVersionExA + * GetVersionExW + * GetWindowsDirectoryA + * GetWindowsDirectoryW + * GlobalMemoryStatusEx + * SetComputerNameExW + * SetDynamicTimeZoneInformation + * SetLocalTime + * SetSystemTime + * SetTimeZoneInformation + * SystemTimeToFileTime + * SystemTimeToTzSpecificLocalTime + * TzSpecificLocalTimeToSystemTime + * VerSetConditionMask + */ + +#ifndef _WIN32 + +#include +#include + +BOOL GetComputerNameExA(COMPUTER_NAME_FORMAT NameType, LPSTR lpBuffer, LPDWORD nSize) +{ + switch (NameType) + { + case ComputerNameNetBIOS: + case ComputerNameDnsHostname: + case ComputerNameDnsDomain: + case ComputerNameDnsFullyQualified: + case ComputerNamePhysicalNetBIOS: + case ComputerNamePhysicalDnsHostname: + case ComputerNamePhysicalDnsDomain: + case ComputerNamePhysicalDnsFullyQualified: + + if (gethostname(lpBuffer, *nSize) < 0) + return 0; + + break; + + default: + return 0; + break; + } + + return 1; +} + +BOOL GetComputerNameExW(COMPUTER_NAME_FORMAT NameType, LPWSTR lpBuffer, LPDWORD nSize) +{ + printf("GetComputerNameExW unimplemented\n"); + return 0; +} + +/* OSVERSIONINFOEX Structure: + * http://msdn.microsoft.com/en-us/library/windows/desktop/ms724833 + */ + +BOOL GetVersionExA(LPOSVERSIONINFOA lpVersionInformation) +{ + /* Windows 7 SP1 Version Info */ + + if ((lpVersionInformation->dwOSVersionInfoSize == sizeof(OSVERSIONINFOA)) || + (lpVersionInformation->dwOSVersionInfoSize == sizeof(OSVERSIONINFOEXA))) + { + lpVersionInformation->dwMajorVersion = 6; + lpVersionInformation->dwMinorVersion = 1; + lpVersionInformation->dwBuildNumber = 7601; + lpVersionInformation->dwPlatformId = VER_PLATFORM_WIN32_NT; + ZeroMemory(lpVersionInformation->szCSDVersion, sizeof(lpVersionInformation->szCSDVersion)); + + if (lpVersionInformation->dwOSVersionInfoSize == sizeof(OSVERSIONINFOEXA)) + { + LPOSVERSIONINFOEXA lpVersionInformationEx = (LPOSVERSIONINFOEXA) lpVersionInformation; + + lpVersionInformationEx->wServicePackMajor = 1; + lpVersionInformationEx->wServicePackMinor = 0; + lpVersionInformationEx->wSuiteMask = 0; + lpVersionInformationEx->wProductType = VER_NT_WORKSTATION; + lpVersionInformationEx->wReserved = 0; + } + + return 1; + } + + return 0; +} + +BOOL GetVersionExW(LPOSVERSIONINFOW lpVersionInformation) +{ + printf("GetVersionExW unimplemented\n"); + return 1; +} + +#endif