Skip to content

Commit

Permalink
Add guard rail to ensure we don't try to install on < IIS 10
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewlock committed Feb 12, 2025
1 parent 4bd714a commit d77915f
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 0 deletions.
12 changes: 12 additions & 0 deletions tracer/src/Datadog.FleetInstaller/Commands/CommandBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,18 @@ protected bool IsValidEnvironment(CommandResult commandResult)
return false;
}

if (!RegistryHelper.TryGetIisVersion(Log.Instance, out var version))
{
commandResult.ErrorMessage = "This installer requires IIS 10.0 or later. Could not determine the IIS version; is the IIS feature enabled?";
return false;
}

if (version.Major < 10)
{
commandResult.ErrorMessage = $"This installer requires IIS 10.0 or later. Detected IIS version {version.Major}.{version.Minor}";
return false;
}

return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,9 @@
<PackageReference Include="System.CommandLine" Version="2.0.0-beta4.22272.1" />
</ItemGroup>

<ItemGroup>
<Compile Include="..\Datadog.Trace\Util\System.Diagnostics.CodeAnalysis.Attributes.cs" Link="Util\%(Filename)%(Extension)" />
<Compile Include="..\Datadog.Trace\Util\System.Runtime.CompilerServices.Attributes.cs" Link="Util\%(Filename)%(Extension)" />
</ItemGroup>

</Project>
31 changes: 31 additions & 0 deletions tracer/src/Datadog.FleetInstaller/RegistryHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
// </copyright>

using System;
using System.Diagnostics.CodeAnalysis;
using Microsoft.Win32;

namespace Datadog.FleetInstaller;
Expand Down Expand Up @@ -61,4 +62,34 @@ public static bool RemoveCrashTrackingKey(ILogger log, TracerValues values, stri
return false;
}
}

public static bool TryGetIisVersion(ILogger log, [NotNullWhen(true)] out Version? version)
{
const string registryKeyName = @"Software\Microsoft\InetStp";

log.WriteInfo($"Reading IIS information from registry key: '{registryKeyName}'");

try
{
var key = Registry.LocalMachine.OpenSubKey(registryKeyName);
if (key is null)
{
log.WriteInfo("IIS registry key not found");
version = null;
return false;
}

var major = key.GetValue("MajorVersion") as int? ?? 0;
var minor = key.GetValue("MinorVersion") as int? ?? 0;

version = new(major: major, minor: minor);
return true;
}
catch (Exception ex)
{
log.WriteError(ex, $"Error reading the IIS Version from the registry key '{registryKeyName}'");
version = null;
return false;
}
}
}

0 comments on commit d77915f

Please sign in to comment.