1
0
mirror of https://github.com/SoftEtherVPN/SoftEtherVPN.git synced 2024-11-23 01:49:53 +03:00

Mayaqua/OS: improve UnixGetOsInfo() so that it retrieves info on recent Linux/BSD systems

This commit is contained in:
Davide Beatrici 2018-10-07 01:38:02 +02:00
parent 335e0503c9
commit afe994f252
2 changed files with 54 additions and 48 deletions

View File

@ -184,10 +184,6 @@
#define OPENVPN_MODE_L2 1 // TAP (Ethernet) #define OPENVPN_MODE_L2 1 // TAP (Ethernet)
#define OPENVPN_MODE_L3 2 // TUN (IP) #define OPENVPN_MODE_L3 2 // TUN (IP)
// Data
#define OPENVPN_DATA_OPTIONS 0
#define OPENVPN_DATA_PEERINFO 1
//// Type //// Type

View File

@ -125,6 +125,7 @@
#include <stdarg.h> #include <stdarg.h>
#include <time.h> #include <time.h>
#include <errno.h> #include <errno.h>
#include <sys/utsname.h>
#include <Mayaqua/Mayaqua.h> #include <Mayaqua/Mayaqua.h>
#ifdef UNIX_MACOS #ifdef UNIX_MACOS
@ -1057,6 +1058,8 @@ void UnixAlert(char *msg, char *caption)
// Get the information of the current OS // Get the information of the current OS
void UnixGetOsInfo(OS_INFO *info) void UnixGetOsInfo(OS_INFO *info)
{ {
struct utsname unix_info;
// Validate arguments // Validate arguments
if (info == NULL) if (info == NULL)
{ {
@ -1079,68 +1082,75 @@ void UnixGetOsInfo(OS_INFO *info)
info->OsType = OSTYPE_UNIX_UNKNOWN; info->OsType = OSTYPE_UNIX_UNKNOWN;
#endif #endif
info->OsServicePack = 0; info->OsSystemName = CopyStr(OsTypeToStr(info->OsType));
info->KernelName = CopyStr("UNIX");
if (info->OsType != OSTYPE_LINUX) if (uname(&unix_info) > -1)
{ {
info->OsSystemName = CopyStr("UNIX"); info->OsProductName = CopyStr(unix_info.sysname);
info->OsProductName = CopyStr("UNIX"); info->OsVersion = CopyStr(unix_info.release);
info->KernelVersion = CopyStr(unix_info.version);
} }
else else
{ {
info->OsSystemName = CopyStr("Linux"); Debug("UnixGetOsInfo(): uname() failed with error: %s\n", strerror(errno));
info->OsProductName = CopyStr("Linux");
}
if (info->OsType == OSTYPE_LINUX)
{
// Get the distribution name on Linux
BUF *b;
b = ReadDump("/etc/redhat-release");
if (b != NULL)
{
info->OsVersion = CfgReadNextLine(b);
info->OsVendorName = CopyStr("Red Hat, Inc.");
FreeBuf(b);
}
else
{
b = ReadDump("/etc/turbolinux-release");
if (b != NULL)
{
info->OsVersion = CfgReadNextLine(b);
info->OsVendorName = CopyStr("Turbolinux, Inc.");
FreeBuf(b);
}
else
{
info->OsVersion = CopyStr("Unknown Linux Version");
info->OsVendorName = CopyStr("Unknown Vendor");
}
}
info->KernelName = CopyStr("Linux Kernel");
b = ReadDump("/proc/sys/kernel/osrelease");
if (b != NULL)
{
info->KernelVersion = CfgReadNextLine(b);
FreeBuf(b);
}
else
{
info->KernelVersion = CopyStr("Unknown Version");
}
}
else
{
// In other cases
Free(info->OsProductName);
info->OsProductName = CopyStr(OsTypeToStr(info->OsType)); info->OsProductName = CopyStr(OsTypeToStr(info->OsType));
info->OsVersion = CopyStr("Unknown Version"); info->OsVersion = CopyStr("Unknown");
info->KernelName = CopyStr(OsTypeToStr(info->OsType)); info->KernelVersion = CopyStr("Unknown");
info->KernelVersion = CopyStr("Unknown Version");
} }
#ifdef UNIX_LINUX
{
BUF *buffer = ReadDump("/etc/os-release");
if (buffer == NULL)
{
buffer = ReadDump("/usr/lib/os-release");
}
if (buffer != NULL)
{
LIST *values = NewEntryList(buffer->Buf, "\n", "=");
FreeBuf(buffer);
if (EntryListHasKey(values, "NAME"))
{
char *str = EntryListStrValue(values, "NAME");
TrimQuotes(str);
Free(info->OsProductName);
info->OsProductName = CopyStr(str);
}
if (EntryListHasKey(values, "HOME_URL"))
{
char *str = EntryListStrValue(values, "HOME_URL");
TrimQuotes(str);
info->OsVendorName = CopyStr(str);
}
if (EntryListHasKey(values, "VERSION"))
{
char *str = EntryListStrValue(values, "VERSION");
TrimQuotes(str);
Free(info->OsVersion);
info->OsVersion = CopyStr(str);
}
else
{
// Debian testing/sid doesn't provide the version in /etc/os-release
buffer = ReadDump("/etc/debian_version");
if (buffer != NULL)
{
Free(info->OsVersion);
info->OsVersion = CfgReadNextLine(buffer);
FreeBuf(buffer);
}
}
FreeEntryList(values);
}
}
#endif
} }
// Examine whether the current OS is supported by the PacketiX VPN Kernel // Examine whether the current OS is supported by the PacketiX VPN Kernel