From 46b344d833b20411fa10d979b5e2e7760e87c52f Mon Sep 17 00:00:00 2001 From: ZephyrTFA Date: Sun, 18 Aug 2024 04:00:20 -0400 Subject: [PATCH] no root --- src/Tgstation.Server.Host/Program.cs | 30 ++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/src/Tgstation.Server.Host/Program.cs b/src/Tgstation.Server.Host/Program.cs index b23633b7df..9e1beb9624 100644 --- a/src/Tgstation.Server.Host/Program.cs +++ b/src/Tgstation.Server.Host/Program.cs @@ -2,11 +2,13 @@ using System.Collections.Generic; using System.Diagnostics; using System.Linq; +using System.Runtime.InteropServices; using System.Text; using System.Threading; using System.Threading.Tasks; using Tgstation.Server.Host.Common; +using Tgstation.Server.Host.Components.Interop.Bridge; using Tgstation.Server.Host.Core; using Tgstation.Server.Host.Properties; using Tgstation.Server.Host.System; @@ -67,6 +69,34 @@ namespace Tgstation.Server.Host args = listArgs.ToArray(); } + if(RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) + { + var proc = new Process + { + StartInfo = new ProcessStartInfo + { + FileName = "id", + Arguments = "-u", + UseShellExecute = false, + RedirectStandardOutput = true, + CreateNoWindow = true + } + }; + proc.Start(); + await proc.WaitForExitAsync(); + if(proc.ExitCode is not 0 || !int.TryParse(await proc.StandardOutput.ReadToEndAsync(), out var uid)) { + Console.Error.WriteLine("Failed to obtain user id."); + Environment.Exit(1); + return; + } + if(uid is 0) + { + Console.Error.WriteLine("TGS is being run as root. This is not recommended and will prevent launching in a future version!"); + // Environment.Exit(1); + // return; + } + } + var program = new Program(); return (int)await program.Main(args, updatePath); }