Skip to content

Commit d1058e2

Browse files
committed
Allow the user to force user gsudo via a SecureSetting (fix #3692)
1 parent 1f3bfff commit d1058e2

7 files changed

Lines changed: 26 additions & 17 deletions

File tree

src/UniGetUI.Core.SecureSettings/SecureSettings.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ public static class SecureSettings
1212
public const string ALLOW_IMPORTING_CLI_ARGUMENTS = "AllowImportingCLIArguments";
1313
public const string ALLOW_PREPOST_OPERATIONS = "AllowPrePostInstallCommands";
1414
public const string ALLOW_IMPORT_PREPOST_OPERATIONS = "AllowImportingPrePostInstallCommands";
15+
public const string FORCE_USER_GSUDO = "ForceUserGSudo";
1516

1617

1718
private static readonly Dictionary<string, bool> _cache = new();

src/UniGetUI.PackageEngine.PackageManagerClasses/Packages/Classes/InstallOptionsFactory.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -212,11 +212,11 @@ private static InstallOptions EnsureSecureOptions(InstallOptions options)
212212
{
213213
// Otherwhise, clear them
214214
if (options.CustomParameters_Install.Count > 0)
215-
Logger.Warn($"Custom CLI parameters [{string.Join(' ', options.CustomParameters_Install)}] will be discarded");
215+
Logger.Warn($"Custom install parameters [{string.Join(' ', options.CustomParameters_Install)}] will be discarded");
216216
if (options.CustomParameters_Update.Count > 0)
217-
Logger.Warn($"Custom CLI parameters [{string.Join(' ', options.CustomParameters_Update)}] will be discarded");
217+
Logger.Warn($"Custom update parameters [{string.Join(' ', options.CustomParameters_Update)}] will be discarded");
218218
if (options.CustomParameters_Uninstall.Count > 0)
219-
Logger.Warn($"Custom CLI parameters [{string.Join(' ', options.CustomParameters_Uninstall)}] will be discarded");
219+
Logger.Warn($"Custom uninstall parameters [{string.Join(' ', options.CustomParameters_Uninstall)}] will be discarded");
220220

221221
options.CustomParameters_Install = [];
222222
options.CustomParameters_Update = [];

src/UniGetUI.PackageEngine.Serializable/InstallOptions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ private static List<string> ReadArrayFromJson(JsonNode data, string name)
8383
foreach (var element in data[name]?.AsArray2() ?? [])
8484
if (element is not null)
8585
result.Add(element.GetVal<string>());
86-
return result;
86+
return result.Where(x => x.Any()).ToList();
8787
}
8888

8989
public bool DiffersFromDefault()

src/UniGetUI/App.xaml.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
using UniGetUI.PackageEngine.Classes.Manager.Classes;
1616
using Microsoft.Windows.AppLifecycle;
1717
using Microsoft.Windows.AppNotifications;
18+
using UniGetUI.Core.SettingsEngine.SecureSettings;
1819
using UniGetUI.Interface.Telemetry;
1920
using UniGetUI.PackageEngine.Interfaces;
2021
using LaunchActivatedEventArgs = Microsoft.UI.Xaml.LaunchActivatedEventArgs;
@@ -98,6 +99,17 @@ private static async void LoadGSudo()
9899
Logger.Warn($"Using bundled GSudo at {CoreData.ElevatorPath} since UniGetUI Elevator is not available!");
99100
CoreData.ElevatorPath = (await CoreTools.WhichAsync("gsudo.exe")).Item2;
100101
#else
102+
if (SecureSettings.Get(SecureSettings.FORCE_USER_GSUDO))
103+
{
104+
var res = await CoreTools.WhichAsync("gsudo.exe");
105+
if (res.Item1)
106+
{
107+
CoreData.ElevatorPath = res.Item2;
108+
Logger.Warn($"Using user GSudo (forced by user) at {CoreData.ElevatorPath}");
109+
return;
110+
}
111+
}
112+
101113
CoreData.ElevatorPath = Path.Join(CoreData.UniGetUIExecutableDirectory, "Assets", "Utilities", "UniGetUI Elevator.exe");
102114
Logger.Debug($"Using built-in UniGetUI Elevator at {CoreData.ElevatorPath}");
103115
#endif

src/UniGetUI/Controls/SettingsWidgets/SecureCheckboxCard.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,8 @@ protected virtual async Task _checkbox_Toggled()
115115

116116
_loading.Visibility = Visibility.Visible;
117117
_checkbox.IsEnabled = false;
118-
StateChanged?.Invoke(this, EventArgs.Empty);
119118
await SecureSettings.TrySet(setting_name, _checkbox.IsOn ^ IS_INVERTED ^ ForceInversion);
119+
StateChanged?.Invoke(this, EventArgs.Empty);
120120
_textblock.Opacity = _checkbox.IsOn ? 1 : 0.7;
121121
_checkbox.IsOn = SecureSettings.Get(setting_name) ^ IS_INVERTED ^ ForceInversion;
122122
_loading.Visibility = Visibility.Collapsed;

src/UniGetUI/Pages/SettingsPages/GeneralPages/Administrator.xaml

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,16 +65,14 @@
6565
Text="Allow custom command-line arguments"
6666
WarningText="Custom command-line arguments can change the way in which programs are installed, upgraded or uninstalled, in a way UniGetUI cannot control. Using custom command-lines can break packages. Proceed with caution." />
6767

68-
69-
<!-- The lines below will soon see the light of the sun, but not yet. Please do not modify them -->
7068
<!--
7169
widgets:SecureCheckboxCard
7270
x:Name="AllowPrePostInstallCommands"
7371
BorderThickness="1,0,1,1"
7472
CornerRadius="0,0,8,8"
7573
SettingName="AllowPrePostInstallCommands"
7674
Text="Ignore custom pre-install and post-install commands when importing packages from a bundle"
77-
WarningText="Pre and post install commands will be run before and after a package gets installed, upgraded or uninstalled. Be aware thay they may break things unless used carefully" /
75+
WarningText="Pre and post install commands will be run before and after a package gets installed, upgraded or uninstalled. Be aware that they may break things unless used carefully" /
7876
-->
7977

8078
<widgets:TranslatedTextBlock
@@ -88,7 +86,7 @@
8886
IsEnabled="{x:Bind AllowCLIArguments._checkbox.IsOn, Mode=OneWay}"
8987
SettingName="AllowImportingCLIArguments"
9088
Text="Allow importing custom command-line arguments when importing packages from a bundle"
91-
WarningText="Malformed command-line arguments can break packages, or even gain remote execution. Therefore, importing custom command-line arguments is disabled by default" />
89+
WarningText="Malformed command-line arguments can break packages, or even allow a malicious actor to gain privileged execution. Therefore, importing custom command-line arguments is disabled by default" />
9290

9391
<!--
9492
widgets:SecureCheckboxCard

src/UniGetUI/Pages/SettingsPages/GeneralPages/Experimental.xaml

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -53,21 +53,19 @@
5353

5454
<UserControl Height="16" />
5555

56-
<widgets:CheckboxCard
56+
<!--widgets:CheckboxCard
5757
x:Name="DisableUniGetUIElevatorToggle"
5858
BorderThickness="1,1,1,0"
5959
CornerRadius="8"
6060
SettingName="DisableUniGetUIElevator"
6161
StateChanged="ShowRestartBanner"
62-
Text="Enable the new UniGetUI-Branded UAC Elevator" />
63-
<!--
64-
widgets:CheckboxCard
62+
Text="Enable the new UniGetUI-Branded UAC Elevator" /-->
63+
<widgets:SecureCheckboxCard
6564
x:Name="UseUserGSudoToggle"
66-
CornerRadius="0,0,8,8"
67-
SettingName="UseUserGSudo"
65+
CornerRadius="8"
66+
SettingName="ForceUserGSudo"
6867
StateChanged="ShowRestartBanner"
69-
Text="Use installed GSudo instead of the bundled one" /
70-
-->
68+
Text="Use installed GSudo instead of UniGetUI Elevator" />
7169

7270
<UserControl Height="16" />
7371

0 commit comments

Comments
 (0)