mirror of
https://github.com/tgstation/tgstation-server.git
synced 2026-08-22 04:27:19 +01:00
move to IsSuperUser
This commit is contained in:
@@ -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>
|
||||
|
||||
Reference in New Issue
Block a user