Utility::GetPlatform*(): on Windows query the registry for version info#9699
Utility::GetPlatform*(): on Windows query the registry for version info#9699
Conversation
fe63342 to
b381210
Compare
|
@julianbrost I prefer this PR in favor of the OP-closes ones. And you? |
|
@LordHepipud What do you -as an expert- think of the concept in general? Of querying Registry instead of relying on the OSes the binary is aware of at compile time? |
lib/base/utility.cpp
Outdated
| union { | ||
| BYTE AsBytes[512]; | ||
| char AsChars[1] = {0}; | ||
| } Data; |
There was a problem hiding this comment.
It would be nice to have documentation on what this type is used for. I was struggling to wrap my head around this until I found the term type punning about union types :).
There was a problem hiding this comment.
Btw. using union types for type punning is UB. Also, in the cppreference explaination states this:
It is undefined behavior to read from the member of the union that wasn't most recently written.
There was a problem hiding this comment.
Would you prefer reinterpret_cast?
lib/base/utility.cpp
Outdated
| if (err == ERROR_SUCCESS) { | ||
| Defer regCloseKey ([hKey]() { (void)RegCloseKey(hKey); }); | ||
| RegistryString productName; | ||
| auto err (RegQueryValueExA(hKey, "ProductName", nullptr, nullptr, productName.Data.AsBytes, &productName.Size)); |
There was a problem hiding this comment.
Maybe you need another subkey to search for instead of ProductName e.g OsName, otherwise, it's still printing false positive information (Tested on fresh installed Windows 11 Pro).
PS C:\Users\yhabteab\Workspace\icinga2\build> .\Bin\Release\Debug\icinga2.exe --version
icinga2.exe - The Icinga 2 network monitoring daemon (version: v2.14.0-94-g88a32cdd0; debug)
Copyright (c) 2012-2023 Icinga GmbH (https://icinga.com/)
License GPLv2+: GNU GPL version 2 or later <https://gnu.org/licenses/gpl2.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
System information:
Platform: Windows
Platform version: Windows 10 Pro 23H2
Kernel: Windows
Kernel version: 6.3.22631
Architecture: x86_64
Build information:
Compiler: MSVC 19.29.30153.0 Build host: YONASHABTEAF0EE OpenSSL version: OpenSSL 3.0.12 24 Oct 2023
There was a problem hiding this comment.
It's already way better than the master branch though: Platform version: 8 xD
System information:
Platform: Windows
Platform version: 8
Kernel: Windows
Kernel version: 6.2
Architecture: x86_64There was a problem hiding this comment.
Wait, Windows 11 says "Windows 11" in one key, but "Windows 10" in another? Please could you screen your SOFTWARE\Microsoft\Windows NT\CurrentVersion in RegEdit?
It's already way better than the master branch though: Platform version: 8 xD
That's the point.👍
another subkey to search for instead of
ProductNamee.gOsName
Unfortunately there's no such thing in Server 2012 R2.
Also, "23H2" and the kernel version make the difference.
b381210 to
1bf4159
Compare
1bf4159 to
1e4aab1
Compare
1e4aab1 to
d88ce8f
Compare
d88ce8f to
42ff74e
Compare
not to have to adjust the code (see removed lines) for every new version.
42ff74e to
88fccc5
Compare
not to have to adjust the code (see removed lines) for every new version.
closes #7743
closes #9646
Windows 10
Works even as unpriv. user:
TODO
Output of
& "C:\Program Files\ICINGA2\sbin\icinga2.exe" --versionwith https://git.icinga.com/packaging/windows-icinga2/-/jobs/272428/artifacts/download (not necessarily as a particular user)