mirror of
https://github.com/ppy/osu.git
synced 2025-01-27 14:52:55 +08:00
Rename AdminChecker to ElevatedPrivilegesChecker, refactor elevated check
This commit is contained in:
parent
260dd06f47
commit
c3bad1d4c5
@ -5,7 +5,7 @@ using System;
|
|||||||
using System.Security.Principal;
|
using System.Security.Principal;
|
||||||
using osu.Framework;
|
using osu.Framework;
|
||||||
using osu.Framework.Allocation;
|
using osu.Framework.Allocation;
|
||||||
using osu.Framework.Graphics.Containers;
|
using osu.Framework.Graphics;
|
||||||
using osu.Framework.Graphics.Sprites;
|
using osu.Framework.Graphics.Sprites;
|
||||||
using osu.Game.Graphics;
|
using osu.Game.Graphics;
|
||||||
using osu.Game.Overlays;
|
using osu.Game.Overlays;
|
||||||
@ -16,7 +16,7 @@ namespace osu.Desktop.Admin
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Checks if the game is running with elevated privileges (as admin in Windows, root in Unix) and displays a warning notification if so.
|
/// Checks if the game is running with elevated privileges (as admin in Windows, root in Unix) and displays a warning notification if so.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class AdminChecker : CompositeDrawable
|
public class ElevatedPrivilegesChecker : Component
|
||||||
{
|
{
|
||||||
[Resolved]
|
[Resolved]
|
||||||
protected NotificationOverlay Notifications { get; private set; }
|
protected NotificationOverlay Notifications { get; private set; }
|
||||||
@ -24,17 +24,31 @@ namespace osu.Desktop.Admin
|
|||||||
protected override void LoadComplete()
|
protected override void LoadComplete()
|
||||||
{
|
{
|
||||||
base.LoadComplete();
|
base.LoadComplete();
|
||||||
if (isAdmin())
|
|
||||||
Notifications.Post(new AdminNotification());
|
bool elevated = false;
|
||||||
|
|
||||||
|
if (OperatingSystem.IsWindows())
|
||||||
|
{
|
||||||
|
var windowsIdentity = WindowsIdentity.GetCurrent();
|
||||||
|
var windowsPrincipal = new WindowsPrincipal(windowsIdentity);
|
||||||
|
elevated = windowsPrincipal.IsInRole(WindowsBuiltInRole.Administrator);
|
||||||
|
}
|
||||||
|
else if (RuntimeInfo.IsUnix)
|
||||||
|
{
|
||||||
|
elevated = Mono.Unix.Native.Syscall.geteuid() == 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!elevated)
|
||||||
|
return;
|
||||||
|
|
||||||
|
Notifications.Post(new ElevatedPrivilegesNotification());
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool isAdmin() => OperatingSystem.IsWindows() ? new WindowsPrincipal(WindowsIdentity.GetCurrent()).IsInRole(WindowsBuiltInRole.Administrator) : Mono.Unix.Native.Syscall.geteuid() == 0;
|
private class ElevatedPrivilegesNotification : SimpleNotification
|
||||||
|
|
||||||
private class AdminNotification : SimpleNotification
|
|
||||||
{
|
{
|
||||||
public override bool IsImportant => true;
|
public override bool IsImportant => true;
|
||||||
|
|
||||||
public AdminNotification()
|
public ElevatedPrivilegesNotification()
|
||||||
{
|
{
|
||||||
Text = $"Running osu! as {(RuntimeInfo.IsUnix ? "root" : "administrator")} does not improve performance and poses a security risk. Please run the game normally.";
|
Text = $"Running osu! as {(RuntimeInfo.IsUnix ? "root" : "administrator")} does not improve performance and poses a security risk. Please run the game normally.";
|
||||||
}
|
}
|
@ -115,7 +115,7 @@ namespace osu.Desktop
|
|||||||
if (RuntimeInfo.OS == RuntimeInfo.Platform.Windows)
|
if (RuntimeInfo.OS == RuntimeInfo.Platform.Windows)
|
||||||
LoadComponentAsync(new GameplayWinKeyBlocker(), Add);
|
LoadComponentAsync(new GameplayWinKeyBlocker(), Add);
|
||||||
|
|
||||||
LoadComponentAsync(new AdminChecker(), Add);
|
LoadComponentAsync(new ElevatedPrivilegesChecker(), Add);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void ScreenChanged(IScreen lastScreen, IScreen newScreen)
|
protected override void ScreenChanged(IScreen lastScreen, IScreen newScreen)
|
||||||
|
Loading…
Reference in New Issue
Block a user