Skip to content

Commit abb2a62

Browse files
committed
Make sure that Krb5ConfigDefaults uses correct values on each supported platform
use .NET 8 updated OS detection but change as little code as possible
1 parent 7811d43 commit abb2a62

File tree

3 files changed

+25
-9
lines changed

3 files changed

+25
-9
lines changed

Kerberos.NET/Configuration/Krb5ConfigDefaults.cs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,10 @@ public class Krb5ConfigDefaults : Krb5ConfigObject
5353
[DefaultValue("FILE:%APPDATA%\\Kerberos.NET\\.krb5cc")]
5454
#elif LINUX
5555
[DefaultValue("FILE:%HOME%/.config/Kerberos.NET/.krb5cc")]
56-
#else
56+
#elif MACOS
5757
[DefaultValue("FILE:%HOME%/Library/Preferences/Kerberos.NET/.krb5cc")]
58+
#else
59+
#error Unknown platform
5860
#endif
5961
[DisplayName("default_ccache_name")]
6062
public string DefaultCCacheName { get; set; }
@@ -66,8 +68,10 @@ public class Krb5ConfigDefaults : Krb5ConfigObject
6668
[DefaultValue("%APPDATA%\\Kerberos.NET\\client.keytab")]
6769
#elif LINUX
6870
[DefaultValue("%HOME%/.config/Kerberos.NET/client.keytab")]
69-
#else
71+
#elif MACOS
7072
[DefaultValue("%HOME%/Library/Preferences/Kerberos.NET/client.keytab")]
73+
#else
74+
#error Unknown platform
7175
#endif
7276
[DisplayName("default_client_keytab_name")]
7377
public string DefaultClientKeytabName { get; set; }
@@ -79,8 +83,10 @@ public class Krb5ConfigDefaults : Krb5ConfigObject
7983
[DefaultValue("%APPDATA%\\Kerberos.NET\\server.keytab")]
8084
#elif LINUX
8185
[DefaultValue("%HOME%/.config/Kerberos.NET/server.keytab")]
82-
#else
86+
#elif MACOS
8387
[DefaultValue("%HOME%/Library/Preferences/Kerberos.NET/server.keytab")]
88+
#else
89+
#error Unknown platform
8490
#endif
8591
[DisplayName("default_keytab_name")]
8692
public string DefaultKeytabName { get; set; }

Kerberos.NET/Kerberos.NET.csproj

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,18 @@
1313
<DefineConstants>WEAKCRYPTO</DefineConstants>
1414
</PropertyGroup>
1515

16+
<PropertyGroup Condition=" '$(OS)' == 'Windows_NT' ">
17+
<DefineConstants>$(DefineConstants);WINDOWS</DefineConstants>
18+
</PropertyGroup>
19+
20+
<PropertyGroup Condition="'$(OS)' == 'Unix' And $(NETCoreSdkPortableRuntimeIdentifier.StartsWith('linux'))">
21+
<DefineConstants>$(DefineConstants);LINUX</DefineConstants>
22+
</PropertyGroup>
23+
24+
<PropertyGroup Condition="'$(OS)' == 'Unix' And $(NETCoreSdkPortableRuntimeIdentifier.StartsWith('osx'))">
25+
<DefineConstants>$(DefineConstants);MACOS</DefineConstants>
26+
</PropertyGroup>
27+
1628
<ItemGroup>
1729
<AdditionalFiles Include="..\stylecop.json" Link="stylecop.json" />
1830
</ItemGroup>

Kerberos.NET/OSPlatform.cs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,14 @@
11
using System;
2+
using RtIs = System.Runtime.InteropServices;
23

34
namespace Kerberos.NET
45
{
56
public static class OSPlatform
67
{
7-
public static readonly bool IsWindows = Environment.OSVersion.Platform == PlatformID.Win32S
8-
|| Environment.OSVersion.Platform == PlatformID.Win32Windows
9-
|| Environment.OSVersion.Platform == PlatformID.Win32NT
10-
|| Environment.OSVersion.Platform == PlatformID.WinCE;
8+
public static readonly bool IsWindows = RtIs.RuntimeInformation.IsOSPlatform(RtIs.OSPlatform.Windows);
119

12-
public static readonly bool IsLinux = Environment.OSVersion.Platform == PlatformID.Unix;
10+
public static readonly bool IsLinux = RtIs.RuntimeInformation.IsOSPlatform(RtIs.OSPlatform.Linux);
1311

14-
public static readonly bool IsOsX = Environment.OSVersion.Platform == PlatformID.MacOSX;
12+
public static readonly bool IsOsX = RtIs.RuntimeInformation.IsOSPlatform(RtIs.OSPlatform.OSX);
1513
}
1614
}

0 commit comments

Comments
 (0)