Skip to content

Commit

Permalink
imp - sec - Signing in is now required before shut...
Browse files Browse the repository at this point in the history
...ting down

---

To improve security, we now require that users sign in before attempting to power off or reboot the kernel. This is to avoid unnecessary disruptions.

---

Type: imp
Breaking: False
Doc Required: False
Backport Required: False
Part: 1/1
  • Loading branch information
AptiviCEO committed Sep 7, 2024
1 parent 61a4e3c commit ab6edd1
Showing 1 changed file with 23 additions and 5 deletions.
28 changes: 23 additions & 5 deletions public/Nitrocid/Users/Login/Login.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
using Terminaux.Writer.ConsoleWriters;
using Nitrocid.Kernel.Power;
using Terminaux.Colors;
using Nitrocid.Security.Permissions;
using Terminaux.Inputs.Styles.Infobox;

namespace Nitrocid.Users.Login
{
Expand Down Expand Up @@ -84,25 +86,29 @@ public static void LoginPrompt()
// Now, show the Login screen
bool proceed = handler.LoginScreen();

// The login screen may provide an option to perform power options.
if (PowerManager.RebootRequested || PowerManager.KernelShutdown)
continue;

// The login screen may provide an option to refresh itself.
if (!proceed)
if (!proceed && !PowerManager.RebootRequested && !PowerManager.KernelShutdown)
continue;

// Prompt for username
user = handler.UserSelector();

// Handlers may return an empty username. This may indicate that the user has exited. In this case, go to the beginning.
if (string.IsNullOrEmpty(user))
{
// Cancel shutdown and reboot attempts
PowerManager.RebootRequested = false;
PowerManager.KernelShutdown = false;
continue;
}

// OK. Here's where things get tricky. Some handlers may misleadingly give us a completely invalid username, so verify it
// the second time for these handlers to behave.
if (!UserManagement.ValidateUsername(user))
{
// Cancel shutdown and reboot attempts
PowerManager.RebootRequested = false;
PowerManager.KernelShutdown = false;
TextWriters.Write(Translate.DoTranslation("Wrong username or username not found."), true, KernelColorType.Error);
continue;
}
Expand All @@ -112,7 +118,19 @@ public static void LoginPrompt()
bool valid = handler.PasswordHandler(user, ref pass);
valid = UserManagement.ValidatePassword(user, pass);
if (!valid)
{
// Cancel shutdown and reboot attempts
PowerManager.RebootRequested = false;
PowerManager.KernelShutdown = false;
TextWriters.Write(Translate.DoTranslation("Wrong password."), true, KernelColorType.Error);
}
else if (!PermissionsTools.IsPermissionGranted(user, PermissionTypes.ManagePower) && (PowerManager.RebootRequested || PowerManager.KernelShutdown))
{
// Cancel shutdown and reboot attempts
PowerManager.RebootRequested = false;
PowerManager.KernelShutdown = false;
InfoBoxColor.WriteInfoBoxColor(Translate.DoTranslation("You don't have permission to request a reboot or a shutdown."), KernelColorTools.GetColor(KernelColorType.Error));
}
else
break;
}
Expand Down

0 comments on commit ab6edd1

Please sign in to comment.