move to IsSuperUser

This commit is contained in:
ZephyrTFA
2024-08-18 13:41:06 -04:00
parent 5e3c1d03d4
commit 259fd60ddf
3 changed files with 11 additions and 25 deletions
@@ -24,6 +24,12 @@ namespace Tgstation.Server.Host.Security
/// </summary>
bool CanCreateSymlinks { get; }
/// <summary>
/// Is this identity a SuperUser for the OS.
/// See Administrator on Windows or root on Linux.
/// </summary>
bool? IsSuperUser { get; }
/// <summary>
/// Clone the <see cref="ISystemIdentity"/> creating another copy that must have <see cref="IDisposable.Dispose"/> called on it.
/// </summary>
@@ -11,31 +11,8 @@ namespace Tgstation.Server.Host.Security
/// </summary>
sealed class PosixSystemIdentity : ISystemIdentity
{
/// <summary>
/// True if TGS is running under root.
/// </summary>
bool isRoot = false;
/// <summary>
/// True if <see cref="isRoot" /> is populated.
/// </summary>
bool isRootChecked = false;
/// <summary>
/// Checks whether TGS is running under the root user.
/// </summary>
/// <returns>True if running under root. False otherwise.</returns>
public bool IsRoot()
{
if (isRootChecked)
{
return isRoot;
}
isRoot = Syscall.getuid() == 0;
isRootChecked = true;
return isRoot;
}
/// <inheritdoc />
public bool? IsSuperUser => Syscall.getuid() == 0;
/// <inheritdoc />
public string Uid => throw new NotImplementedException();
@@ -24,6 +24,9 @@ namespace Tgstation.Server.Host.Security
/// <inheritdoc />
public bool CanCreateSymlinks => canCreateSymlinks ?? throw new NotSupportedException();
/// <inheritdoc />
public bool? IsSuperUser => identity?.IsSystem;
/// <summary>
/// The <see cref="WindowsIdentity"/> for the <see cref="WindowsSystemIdentity"/>.
/// </summary>