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) info->OsProductName = CopyStr(OsTypeToStr(info->OsType));
info->OsVersion = CopyStr("Unknown");
info->KernelVersion = CopyStr("Unknown");
}
#ifdef UNIX_LINUX
{ {
// Get the distribution name on Linux BUF *buffer = ReadDump("/etc/os-release");
BUF *b; if (buffer == NULL)
b = ReadDump("/etc/redhat-release");
if (b != NULL)
{ {
info->OsVersion = CfgReadNextLine(b); buffer = ReadDump("/usr/lib/os-release");
info->OsVendorName = CopyStr("Red Hat, Inc.");
FreeBuf(b);
} }
else
if (buffer != NULL)
{ {
b = ReadDump("/etc/turbolinux-release"); LIST *values = NewEntryList(buffer->Buf, "\n", "=");
if (b != NULL)
FreeBuf(buffer);
if (EntryListHasKey(values, "NAME"))
{ {
info->OsVersion = CfgReadNextLine(b); char *str = EntryListStrValue(values, "NAME");
info->OsVendorName = CopyStr("Turbolinux, Inc."); TrimQuotes(str);
FreeBuf(b); 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 else
{ {
info->OsVersion = CopyStr("Unknown Linux Version"); // Debian testing/sid doesn't provide the version in /etc/os-release
info->OsVendorName = CopyStr("Unknown Vendor"); buffer = ReadDump("/etc/debian_version");
if (buffer != NULL)
{
Free(info->OsVersion);
info->OsVersion = CfgReadNextLine(buffer);
FreeBuf(buffer);
}
} }
}
info->KernelName = CopyStr("Linux Kernel"); FreeEntryList(values);
b = ReadDump("/proc/sys/kernel/osrelease");
if (b != NULL)
{
info->KernelVersion = CfgReadNextLine(b);
FreeBuf(b);
}
else
{
info->KernelVersion = CopyStr("Unknown Version");
} }
} }
else #endif
{
// In other cases
Free(info->OsProductName);
info->OsProductName = CopyStr(OsTypeToStr(info->OsType));
info->OsVersion = CopyStr("Unknown Version");
info->KernelName = CopyStr(OsTypeToStr(info->OsType));
info->KernelVersion = CopyStr("Unknown Version");
}
} }
// Examine whether the current OS is supported by the PacketiX VPN Kernel // Examine whether the current OS is supported by the PacketiX VPN Kernel