mirror of
https://github.com/tgstation/tgstation-server.git
synced 2026-08-27 15:07:03 +01:00
More security improvements to the wrappers
This commit is contained in:
@@ -13,7 +13,12 @@ namespace TGS.Interface.Wrappers
|
||||
InstanceMetadata Metadata { get; }
|
||||
|
||||
/// <summary>
|
||||
/// The <see cref="ITGAdministration"/> component
|
||||
/// Check if the connected user is an administrator of the <see cref="IInstance"/>
|
||||
/// </summary>
|
||||
bool UserIsAdministrator { get; }
|
||||
|
||||
/// <summary>
|
||||
/// The <see cref="ITGAdministration"/> component. Will be <see langword="null"/> if <see cref="UserIsAdministrator"/> is <see langword="false"/>
|
||||
/// </summary>
|
||||
ITGAdministration Administration { get; }
|
||||
|
||||
|
||||
@@ -7,12 +7,12 @@ namespace TGS.Interface.Wrappers
|
||||
/// <summary>
|
||||
/// Wrapper representing a <see cref="ITGSService"/>
|
||||
/// </summary>
|
||||
public interface IServer : ITGSService
|
||||
public interface IServer
|
||||
{
|
||||
/// <summary>
|
||||
/// The <see cref="System.Version"/> of the <see cref="IServer"/>
|
||||
/// </summary>
|
||||
new Version Version { get; }
|
||||
Version Version { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Get the <see cref="IInstance"/>s the <see cref="IServer"/> contains that the current user can access and connect to
|
||||
@@ -20,10 +20,15 @@ namespace TGS.Interface.Wrappers
|
||||
IEnumerable<IInstance> Instances { get; }
|
||||
|
||||
/// <summary>
|
||||
/// The <see cref="ITGInstanceManager"/> component
|
||||
/// The <see cref="ITGInstanceManager"/> component. Will be <see langword="null"/> if the connected user is not an administrator of the <see cref="IServer"/>
|
||||
/// </summary>
|
||||
ITGInstanceManager InstanceManager { get; }
|
||||
|
||||
/// <summary>
|
||||
/// The <see cref="ITGSService"/> component. Will be <see langword="null"/> if the connected user is not an administrator of the <see cref="IServer"/>
|
||||
/// </summary>
|
||||
ITGSService Management { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets the specified <see cref="IInstance"/> without connectivity checks
|
||||
/// </summary>
|
||||
|
||||
@@ -14,6 +14,10 @@ namespace TGS.Interface.Wrappers
|
||||
/// The name of the <see cref="IInstance"/>
|
||||
/// </summary>
|
||||
InstanceMetadata metadata;
|
||||
/// <summary>
|
||||
/// Whether or not the current user is known to be an administrator of the <see cref="IInstance"/>
|
||||
/// </summary>
|
||||
bool isAdministrator;
|
||||
|
||||
/// <summary>
|
||||
/// Construct an <see cref="Instance"/>
|
||||
@@ -41,8 +45,28 @@ namespace TGS.Interface.Wrappers
|
||||
}
|
||||
}
|
||||
|
||||
public bool UserIsAdministrator { get
|
||||
{
|
||||
lock (this)
|
||||
{
|
||||
if (isAdministrator)
|
||||
return true;
|
||||
try
|
||||
{
|
||||
Administration.GetCurrentAuthorizedGroup();
|
||||
isAdministrator = true;
|
||||
return true;
|
||||
}
|
||||
catch
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public ITGAdministration Administration => serverInterface.GetComponent<ITGAdministration>(metadata.Name);
|
||||
public ITGAdministration Administration => UserIsAdministrator ? serverInterface.GetComponent<ITGAdministration>(metadata.Name) : null;
|
||||
|
||||
/// <inheritdoc />
|
||||
public ITGByond Byond => serverInterface.GetComponent<ITGByond>(metadata.Name);
|
||||
|
||||
@@ -35,10 +35,37 @@ namespace TGS.Interface.Wrappers
|
||||
/// <inheritdoc />
|
||||
public ITGInstanceManager InstanceManager => serverInterface.GetComponent<ITGInstanceManager>(null);
|
||||
|
||||
/// <inheritdoc />
|
||||
public ITGSService Management
|
||||
{
|
||||
get
|
||||
{
|
||||
var component = serverInterface.GetComponent<ITGSService>(null);
|
||||
lock (this)
|
||||
{
|
||||
if (!userIsAdministrator)
|
||||
try
|
||||
{
|
||||
var test = component.Version();
|
||||
userIsAdministrator = true;
|
||||
}
|
||||
catch
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
return component;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The backing <see cref="ServerInterface"/>
|
||||
/// </summary>
|
||||
readonly ServerInterface serverInterface;
|
||||
/// <summary>
|
||||
/// If the connected user is an administrator of the <see cref="IServer"/>
|
||||
/// </summary>
|
||||
bool userIsAdministrator;
|
||||
|
||||
/// <summary>
|
||||
/// Result of a call to <see cref="ITGLanding.ListInstances"/>
|
||||
@@ -59,41 +86,5 @@ namespace TGS.Interface.Wrappers
|
||||
{
|
||||
return new Instance(serverInterface, new InstanceMetadata { Name = name, Enabled = false });
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public void PrepareForUpdate()
|
||||
{
|
||||
serverInterface.GetComponent<ITGSService>(null).PrepareForUpdate();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public string PythonPath()
|
||||
{
|
||||
return serverInterface.GetComponent<ITGSService>(null).PythonPath();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public ushort RemoteAccessPort()
|
||||
{
|
||||
return serverInterface.GetComponent<ITGSService>(null).RemoteAccessPort();
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public bool SetPythonPath(string path)
|
||||
{
|
||||
return serverInterface.GetComponent<ITGSService>(null).SetPythonPath(path);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public string SetRemoteAccessPort(ushort port)
|
||||
{
|
||||
return serverInterface.GetComponent<ITGSService>(null).SetRemoteAccessPort(port);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
string ITGSService.Version()
|
||||
{
|
||||
return serverInterface.GetComponent<ITGSService>(null).Version();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user