From 3d231cfcef4a83a8e42a5df0c9b9a85c96cfd1e5 Mon Sep 17 00:00:00 2001 From: ZephyrTFA Date: Sun, 18 Aug 2024 13:48:25 -0400 Subject: [PATCH] remove nullable --- .../Components/InstanceManager.cs | 10 ++-------- src/Tgstation.Server.Host/Security/ISystemIdentity.cs | 2 +- .../Security/PosixSystemIdentity.cs | 2 +- .../Security/WindowsSystemIdentity.cs | 10 +++++----- 4 files changed, 9 insertions(+), 15 deletions(-) diff --git a/src/Tgstation.Server.Host/Components/InstanceManager.cs b/src/Tgstation.Server.Host/Components/InstanceManager.cs index c984de9ad2..73fdf2b857 100644 --- a/src/Tgstation.Server.Host/Components/InstanceManager.cs +++ b/src/Tgstation.Server.Host/Components/InstanceManager.cs @@ -676,15 +676,9 @@ namespace Tgstation.Server.Host.Components if (!systemIdentity.CanCreateSymlinks) throw new InvalidOperationException($"The user running {Constants.CanonicalPackageName} cannot create symlinks! Please try running as an administrative user!"); - if (!platformIdentifier.IsWindows && systemIdentity.IsSuperUser!.Value) + if (!platformIdentifier.IsWindows && systemIdentity.IsSuperUser) { - if (systemIdentity.IsSuperUser is not { } superUser) - { - throw new InvalidOperationException("Failed to determine if running as root."); - } - - if (superUser) - logger.LogWarning("TGS is being run as the root account. This is not recommended and may prevent launch in a future version."); + logger.LogWarning("TGS is being run as the root account. This is not recommended and may prevent launch in a future version."); } } diff --git a/src/Tgstation.Server.Host/Security/ISystemIdentity.cs b/src/Tgstation.Server.Host/Security/ISystemIdentity.cs index af3b2a0171..f976066e50 100644 --- a/src/Tgstation.Server.Host/Security/ISystemIdentity.cs +++ b/src/Tgstation.Server.Host/Security/ISystemIdentity.cs @@ -28,7 +28,7 @@ namespace Tgstation.Server.Host.Security /// Is this identity a SuperUser for the OS. /// See Administrator on Windows or root on Linux. /// - bool? IsSuperUser { get; } + bool IsSuperUser { get; } /// /// Clone the creating another copy that must have called on it. diff --git a/src/Tgstation.Server.Host/Security/PosixSystemIdentity.cs b/src/Tgstation.Server.Host/Security/PosixSystemIdentity.cs index ed661f90de..ea8e23d3e8 100644 --- a/src/Tgstation.Server.Host/Security/PosixSystemIdentity.cs +++ b/src/Tgstation.Server.Host/Security/PosixSystemIdentity.cs @@ -12,7 +12,7 @@ namespace Tgstation.Server.Host.Security sealed class PosixSystemIdentity : ISystemIdentity { /// - public bool? IsSuperUser => Syscall.getuid() == 0; + public bool IsSuperUser => Syscall.getuid() == 0; /// public string Uid => throw new NotImplementedException(); diff --git a/src/Tgstation.Server.Host/Security/WindowsSystemIdentity.cs b/src/Tgstation.Server.Host/Security/WindowsSystemIdentity.cs index f1c3588b88..486d8d795c 100644 --- a/src/Tgstation.Server.Host/Security/WindowsSystemIdentity.cs +++ b/src/Tgstation.Server.Host/Security/WindowsSystemIdentity.cs @@ -22,10 +22,10 @@ namespace Tgstation.Server.Host.Security public string Username => userPrincipal?.Name ?? identity!.Name; /// - public bool CanCreateSymlinks => canCreateSymlinks ?? throw new NotSupportedException(); + public bool CanCreateSymlinks => IsSuperUser; /// - public bool? IsSuperUser => identity?.IsSystem; + public bool IsSuperUser => IsSuperUser; /// /// The for the . @@ -38,9 +38,9 @@ namespace Tgstation.Server.Host.Security readonly UserPrincipal? userPrincipal; /// - /// Backing field for . + /// Backing field for . /// - readonly bool? canCreateSymlinks; + readonly bool? isAdmin; /// /// Initializes a new instance of the class. @@ -52,7 +52,7 @@ namespace Tgstation.Server.Host.Security if (identity.IsAnonymous) throw new ArgumentException($"Cannot use anonymous {nameof(WindowsIdentity)} as a {nameof(WindowsSystemIdentity)}!", nameof(identity)); - canCreateSymlinks = new WindowsPrincipal(identity).IsInRole(WindowsBuiltInRole.Administrator); + isAdmin = new WindowsPrincipal(identity).IsInRole(WindowsBuiltInRole.Administrator); } ///