From 61c7e3f1ee52f9bea4eb66b5683e2e07786247de Mon Sep 17 00:00:00 2001 From: Cyberboss Date: Fri, 8 Dec 2017 12:05:51 -0500 Subject: [PATCH] More security improvements to the wrappers --- TGS.Interface/Wrappers/IInstance.cs | 7 +++- TGS.Interface/Wrappers/IServer.cs | 11 +++-- TGS.Interface/Wrappers/Instance.cs | 26 +++++++++++- TGS.Interface/Wrappers/Server.cs | 63 +++++++++++++---------------- 4 files changed, 66 insertions(+), 41 deletions(-) diff --git a/TGS.Interface/Wrappers/IInstance.cs b/TGS.Interface/Wrappers/IInstance.cs index a6895998d9..81db529014 100644 --- a/TGS.Interface/Wrappers/IInstance.cs +++ b/TGS.Interface/Wrappers/IInstance.cs @@ -13,7 +13,12 @@ namespace TGS.Interface.Wrappers InstanceMetadata Metadata { get; } /// - /// The component + /// Check if the connected user is an administrator of the + /// + bool UserIsAdministrator { get; } + + /// + /// The component. Will be if is /// ITGAdministration Administration { get; } diff --git a/TGS.Interface/Wrappers/IServer.cs b/TGS.Interface/Wrappers/IServer.cs index e06e7cb624..48ffc3d6cf 100644 --- a/TGS.Interface/Wrappers/IServer.cs +++ b/TGS.Interface/Wrappers/IServer.cs @@ -7,12 +7,12 @@ namespace TGS.Interface.Wrappers /// /// Wrapper representing a /// - public interface IServer : ITGSService + public interface IServer { /// /// The of the /// - new Version Version { get; } + Version Version { get; } /// /// Get the s the contains that the current user can access and connect to @@ -20,10 +20,15 @@ namespace TGS.Interface.Wrappers IEnumerable Instances { get; } /// - /// The component + /// The component. Will be if the connected user is not an administrator of the /// ITGInstanceManager InstanceManager { get; } + /// + /// The component. Will be if the connected user is not an administrator of the + /// + ITGSService Management { get; } + /// /// Gets the specified without connectivity checks /// diff --git a/TGS.Interface/Wrappers/Instance.cs b/TGS.Interface/Wrappers/Instance.cs index 72d9e364b4..f90d2202c8 100644 --- a/TGS.Interface/Wrappers/Instance.cs +++ b/TGS.Interface/Wrappers/Instance.cs @@ -14,6 +14,10 @@ namespace TGS.Interface.Wrappers /// The name of the /// InstanceMetadata metadata; + /// + /// Whether or not the current user is known to be an administrator of the + /// + bool isAdministrator; /// /// Construct an @@ -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; + } + } + } + } + /// - public ITGAdministration Administration => serverInterface.GetComponent(metadata.Name); + public ITGAdministration Administration => UserIsAdministrator ? serverInterface.GetComponent(metadata.Name) : null; /// public ITGByond Byond => serverInterface.GetComponent(metadata.Name); diff --git a/TGS.Interface/Wrappers/Server.cs b/TGS.Interface/Wrappers/Server.cs index 71b918ffe2..a826b623f4 100644 --- a/TGS.Interface/Wrappers/Server.cs +++ b/TGS.Interface/Wrappers/Server.cs @@ -35,10 +35,37 @@ namespace TGS.Interface.Wrappers /// public ITGInstanceManager InstanceManager => serverInterface.GetComponent(null); + /// + public ITGSService Management + { + get + { + var component = serverInterface.GetComponent(null); + lock (this) + { + if (!userIsAdministrator) + try + { + var test = component.Version(); + userIsAdministrator = true; + } + catch + { + return null; + } + } + return component; + } + } + /// /// The backing /// readonly ServerInterface serverInterface; + /// + /// If the connected user is an administrator of the + /// + bool userIsAdministrator; /// /// Result of a call to @@ -59,41 +86,5 @@ namespace TGS.Interface.Wrappers { return new Instance(serverInterface, new InstanceMetadata { Name = name, Enabled = false }); } - - /// - public void PrepareForUpdate() - { - serverInterface.GetComponent(null).PrepareForUpdate(); - } - - /// - public string PythonPath() - { - return serverInterface.GetComponent(null).PythonPath(); - } - - /// - public ushort RemoteAccessPort() - { - return serverInterface.GetComponent(null).RemoteAccessPort(); - } - - /// - public bool SetPythonPath(string path) - { - return serverInterface.GetComponent(null).SetPythonPath(path); - } - - /// - public string SetRemoteAccessPort(ushort port) - { - return serverInterface.GetComponent(null).SetRemoteAccessPort(port); - } - - /// - string ITGSService.Version() - { - return serverInterface.GetComponent(null).Version(); - } } }