From bb06a2eff208c49f36cde0818ac98b6fbabedf31 Mon Sep 17 00:00:00 2001 From: Jordan Dominion Date: Wed, 15 Nov 2023 19:41:11 -0500 Subject: [PATCH] `Forbid()` before accessing instance here --- .../Controllers/DreamDaemonController.cs | 40 +++++++++---------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/src/Tgstation.Server.Host/Controllers/DreamDaemonController.cs b/src/Tgstation.Server.Host/Controllers/DreamDaemonController.cs index 097e0377d3..c438b2e7fa 100644 --- a/src/Tgstation.Server.Host/Controllers/DreamDaemonController.cs +++ b/src/Tgstation.Server.Host/Controllers/DreamDaemonController.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Linq; using System.Linq.Expressions; using System.Reflection; @@ -208,6 +208,25 @@ namespace Tgstation.Server.Host.Controllers return false; } + if (CheckModified(x => x.AllowWebClient, DreamDaemonRights.SetWebClient) + || CheckModified(x => x.AutoStart, DreamDaemonRights.SetAutoStart) + || CheckModified(x => x.Port, DreamDaemonRights.SetPort) + || CheckModified(x => x.SecurityLevel, DreamDaemonRights.SetSecurity) + || CheckModified(x => x.Visibility, DreamDaemonRights.SetVisibility) + || (model.SoftRestart.HasValue && !AuthenticationContext.InstancePermissionSet.DreamDaemonRights.Value.HasFlag(DreamDaemonRights.SoftRestart)) + || (model.SoftShutdown.HasValue && !AuthenticationContext.InstancePermissionSet.DreamDaemonRights.Value.HasFlag(DreamDaemonRights.SoftShutdown)) + || CheckModified(x => x.StartupTimeout, DreamDaemonRights.SetStartupTimeout) + || CheckModified(x => x.HealthCheckSeconds, DreamDaemonRights.SetHealthCheckInterval) + || CheckModified(x => x.DumpOnHealthCheckRestart, DreamDaemonRights.CreateDump) + || CheckModified(x => x.TopicRequestTimeout, DreamDaemonRights.SetTopicTimeout) + || CheckModified(x => x.AdditionalParameters, DreamDaemonRights.SetAdditionalParameters) + || CheckModified(x => x.StartProfiler, DreamDaemonRights.SetProfiler) + || CheckModified(x => x.LogOutput, DreamDaemonRights.SetLogOutput) + || CheckModified(x => x.MapThreads, DreamDaemonRights.SetMapThreads)) + return Forbid(); + + await DatabaseContext.Save(cancellationToken); + return await WithComponentInstance( async instance => { @@ -216,25 +235,6 @@ namespace Tgstation.Server.Host.Controllers var oldSoftRestart = rebootState == RebootState.Restart; var oldSoftShutdown = rebootState == RebootState.Shutdown; - if (CheckModified(x => x.AllowWebClient, DreamDaemonRights.SetWebClient) - || CheckModified(x => x.AutoStart, DreamDaemonRights.SetAutoStart) - || CheckModified(x => x.Port, DreamDaemonRights.SetPort) - || CheckModified(x => x.SecurityLevel, DreamDaemonRights.SetSecurity) - || CheckModified(x => x.Visibility, DreamDaemonRights.SetVisibility) - || (model.SoftRestart.HasValue && !AuthenticationContext.InstancePermissionSet.DreamDaemonRights.Value.HasFlag(DreamDaemonRights.SoftRestart)) - || (model.SoftShutdown.HasValue && !AuthenticationContext.InstancePermissionSet.DreamDaemonRights.Value.HasFlag(DreamDaemonRights.SoftShutdown)) - || CheckModified(x => x.StartupTimeout, DreamDaemonRights.SetStartupTimeout) - || CheckModified(x => x.HealthCheckSeconds, DreamDaemonRights.SetHealthCheckInterval) - || CheckModified(x => x.DumpOnHealthCheckRestart, DreamDaemonRights.CreateDump) - || CheckModified(x => x.TopicRequestTimeout, DreamDaemonRights.SetTopicTimeout) - || CheckModified(x => x.AdditionalParameters, DreamDaemonRights.SetAdditionalParameters) - || CheckModified(x => x.StartProfiler, DreamDaemonRights.SetProfiler) - || CheckModified(x => x.LogOutput, DreamDaemonRights.SetLogOutput) - || CheckModified(x => x.MapThreads, DreamDaemonRights.SetMapThreads)) - return Forbid(); - - await DatabaseContext.Save(cancellationToken); - // run this second because current may be modified by it await watchdog.ChangeSettings(current, cancellationToken);