Skip to content

WIP: Improve Windows (Server) version detection #7743

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

dnsmichi
Copy link
Contributor

@dnsmichi dnsmichi commented Jan 8, 2020

Rationale: I was looking into additional Windows environment specifics and thought it would be a good idea to evaluate this again. With the recent VS compiler update, we can also detected Windows 10 (yay), available since the VS2015 SDK.

Detecting the servers is actually fun with the build numbers, especially to distinguish between Server 2016 and 2019.

If this PR works out, @widhalmt should be even happier.

Resources

Screen Shot 2020-01-08 at 14 20 52
Screen Shot 2020-01-08 at 14 20 59
Screen Shot 2020-01-08 at 14 21 06

@dnsmichi dnsmichi added area/cli Command line helpers area/windows Windows agent and plugins labels Jan 8, 2020
@dnsmichi
Copy link
Contributor Author

dnsmichi commented Feb 7, 2020

This PR is needed to improve the output in #7819.

@dnsmichi
Copy link
Contributor Author

IsWindows10OrGreater() still doesn't work, since we do not target that specifically. And even with the set target, it doesn't work.

https://docs.microsoft.com/en-us/windows/win32/sysinfo/operating-system-version

For applications that have been manifested for Windows 8.1 or Windows 10. Applications not manifested for Windows 8.1 or Windows 10 will return the Windows 8 OS version value (6.2). To manifest your applications for Windows 8.1 or Windows 10, refer to Targeting your application for Windows.

https://docs.microsoft.com/en-us/windows/win32/sysinfo/targeting-your-application-at-windows-8-1

In Windows 8.1 and Windows 10, the GetVersion and GetVersionEx functions have been deprecated. In Windows 10, the VerifyVersionInfo function has also been deprecated. While you can still call the deprecated functions, if your application does not specifically target Windows 8.1 or Windows 10, the functions will return the Windows 8 version (6.2).

So we need an app.manifest which is compiled into the final icinga2.exe. I'm playing around with that.

@dnsmichi dnsmichi changed the title CLI: Improve Windows (Server) version detection WIP: CLI: Improve Windows (Server) version detection Feb 10, 2020
@dnsmichi dnsmichi changed the title WIP: CLI: Improve Windows (Server) version detection WIP: Improve Windows (Server) version detection Feb 10, 2020
@dnsmichi dnsmichi self-assigned this Feb 10, 2020
@Al2Klimov Al2Klimov marked this pull request as draft June 29, 2020 10:08
@Al2Klimov Al2Klimov added this to the 2.13.0 milestone Nov 23, 2020
@julianbrost julianbrost removed this from the 2.13.0 milestone May 31, 2021
@julianbrost
Copy link
Contributor

So if I understand correctly, Icinga at the moment displays some imprecise version on any recent version of Windows? If so, I think it might be worth looking into this. But I can't believe that there's no way to just get some version string in Windows that we could use.

@julianbrost julianbrost assigned julianbrost and unassigned dnsmichi Sep 9, 2021
@Al2Klimov
Copy link
Member

Any news here?

@julianbrost julianbrost removed their assignment Jan 20, 2023
@julianbrost
Copy link
Contributor

Not from my side. Wanted to have a look at it but you know, there's always something more important to do.

@Al2Klimov
Copy link
Member

I can't believe that there's no way to just get some version string in Windows that we could use.

https://learn.microsoft.com/de-de/windows/win32/sysinfo/getting-the-system-version?redirectedfrom=MSDN

Copy link
Member

@Al2Klimov Al2Klimov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Opera Momentaufnahme_2023-01-30_164740_cloud netways de

This BREAKS CMake < v3.4 on Windows. At least this works at all.
@cla-bot
Copy link

cla-bot bot commented Feb 1, 2023

Thank you for your pull request and welcome to our community. We could not parse the GitHub identity of the following contributors: Michael Friedrich.
This is most likely caused by a git client misconfiguration; please make sure to:

  1. check if your git client is configured with an email to sign commits git config --list | grep email
  2. If not, set it up using git config --global user.email [email protected]
  3. Make sure that the git commit email is configured in your GitHub account settings, see https://github.com/settings/emails

Al2Klimov
Al2Klimov previously approved these changes Feb 1, 2023
Copy link
Member

@Al2Klimov Al2Klimov left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Much better!

PS C:\Users\aklimov\icinga2> C:\Users\aklimov\icinga2\build\Bin\Release\Debug\icinga2.exe --version
(...)
System information:
  Platform: Windows
  Platform version: 10 or greater
  Kernel: Windows
  Kernel version: 10.0
(...)

@Al2Klimov Al2Klimov marked this pull request as ready for review February 1, 2023 15:58
@julianbrost
Copy link
Contributor

Is there a list of potentially breaking changes between these versions? They probably don't emulate the old version just for the purpose of making it harder for you to figure out the version you're actually running on.

@Al2Klimov
Copy link
Member

Good question. Very good question.

@Al2Klimov
Copy link
Member

CC @LordHepipud

@Al2Klimov
Copy link
Member

Al2Klimov commented Feb 1, 2023

Shouldn't this basically just be a question of compiles/runs yes/no?

@Al2Klimov
Copy link
Member

At least it works for me.

@LordHepipud
Copy link
Contributor

Packages is working on Windows 2012 R2. Output is also correct now:

System Information:
  Platforn: Windows
  Platform version: Server 2012 R2
  Kernel: Windows
  Kernel version: 6.3-9600
  Architecture: x86_64

@julianbrost
Copy link
Contributor

Is there a list of potentially breaking changes between these versions?

Answering my own question:

I haven't looked through this in detail, but there seems to be nothing that will obviously be a problem.

Copy link
Contributor

@julianbrost julianbrost left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is also a commit in this PR where the commit message is just "WIP".

Comment on lines 1447 to 1462
*platformVersion = "Server 2008 (EOL)";
}

} else {
if (IsWindows10OrGreater())
*platformVersion = "10 or greater";
else if (IsWindows8Point1OrGreater())
*platformVersion = "8.1";
else if (IsWindows8OrGreater())
*platformVersion = "8";
else if (IsWindows7SP1OrGreater())
*platformVersion = "7 SP1 (EOL)";
else if (IsWindows7OrGreater())
*platformVersion = "7 (EOL)";
else
*platformVersion = "Vista (EOL)";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would not put any EOL information in here. It's just a maintenance burden. It already seems to be outdated.

@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="utf-8"?>
<asmv1:assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1" xmlns:asmv1="urn:schemas-microsoft-com:asm.v1" xmlns:asmv2="urn:schemas-microsoft-com:asm.v2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<assemblyIdentity version="1.0.0.0" name="MyApplication.app"/>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

MyApplication.app looks like a placeholder. Shouldn't this be replaced with something more meaningful?

@cla-bot cla-bot bot removed the cla/signed label Feb 15, 2023
@Icinga Icinga deleted a comment from cla-bot bot Feb 15, 2023
@Al2Klimov
Copy link
Member

It indeed was work in progress and now I've finished it.

Comment on lines +1431 to +1448
// https://stackoverflow.com/questions/53393150/c-how-to-detect-windows-server-2019
// https://techthoughts.info/windows-version-numbers/
if (IsWindowsServer()) {
// 2019 Server +
if (IsWindowsVersionOrGreater(10, 0, 1803)) {
*platformVersion = "Server 2019 or greater";
// 2016 Server
} else if (IsWindowsVersionOrGreater(10, 0, 1607)) {
*platformVersion = "Server 2016";
// 2012 R2
} else if (IsWindowsVersionOrGreater(6, 3, 0)) {
*platformVersion = "Server 2012 R2";
// 2012
} else if (IsWindowsVersionOrGreater(6, 2, 0)) {
*platformVersion = "Server 2012";
} else {
*platformVersion = "Server 2008";
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What versions besides 2012 R2 was this tested on? According to the documentation of IsWindowsVersionOrGreater, the third parameter is named wServicePackMajor and to me it's unclear if that would refer to the version number like 1607 or a build number like 14393 or something completely different like 2 as in SP2.

So this should be tested on two 10.0 version, i.e. 2016 and 2019 to ensure that this parameter isn't totally wrong.

Comment on lines +1435 to +1436
if (IsWindowsVersionOrGreater(10, 0, 1803)) {
*platformVersion = "Server 2019 or greater";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The source given in the comment right above lists 1803 twice, for both a 2016 and a 2019 version. On the other hand, Wikipedia lists 1809 as the first 2019 version.

According to the Microsoft documentation, the check functions for desktop versions can be used in conjunction with IsWindowsServer():

For example, a call to IsWindowsXPSP3OrGreater will return true on Windows Server 2008. Applications that need to distinguish between server and client versions of Windows should call IsWindowsServer.

Would this be good enough for detecting the server release on the granularity we need? Or is there a version that we couldn't distinguish that way? Would at least save us from dealing with the magic numbers involved in this super-intuitive versioning scheme.

@@ -0,0 +1,19 @@
<?xml version="1.0" encoding="utf-8"?>
<asmv1:assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1" xmlns:asmv1="urn:schemas-microsoft-com:asm.v1" xmlns:asmv2="urn:schemas-microsoft-com:asm.v2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<assemblyIdentity version="1.0.0.0" name="Icinga 2"/>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Documentation for name:

Uniquely names the application or assembly. Use the following format for the name: Organization.Division.Name. For example Microsoft.Windows.mysampleApp. Required.

So doesn't look like a name for human consumption but rather like a scoped identifier. Also not sure if you're supposed to use spaces in there. There's also an example with a 2 level name, so my suggestion for the value would be Icinga.Icinga2.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/cli Command line helpers area/windows Windows agent and plugins cla/signed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants