mirror of
https://github.com/2dust/v2rayN.git
synced 2026-05-30 01:34:08 +00:00
fix: Allow TUN mode to auto-enable for NOPASSWD sudo users on Linux
Previously, AllowEnableTun() only checked if LinuxSudoPwd was non-empty, which is always null on startup. This caused the password dialog to always appear when enabling TUN mode, even for users with NOPASSWD sudo configured. Add a check using 'sudo -n true' to detect NOPASSWD configuration. This allows users with NOPASSWD sudo to auto-enable TUN mode without being prompted for a password on each startup, matching the behavior of Windows (which auto-enables when run as administrator). Fixes behavior discussed in #7116 and #8069.
This commit is contained in:
parent
177ad7db3d
commit
4ca8c90e5e
1 changed files with 21 additions and 1 deletions
|
|
@ -503,7 +503,27 @@ public class StatusBarViewModel : MyReactiveObject
|
||||||
}
|
}
|
||||||
else if (Utils.IsLinux())
|
else if (Utils.IsLinux())
|
||||||
{
|
{
|
||||||
return AppManager.Instance.LinuxSudoPwd.IsNotEmpty();
|
if (AppManager.Instance.LinuxSudoPwd.IsNotEmpty())
|
||||||
|
return true;
|
||||||
|
// Check if sudo is configured with NOPASSWD
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var psi = new ProcessStartInfo
|
||||||
|
{
|
||||||
|
FileName = "/usr/bin/sudo",
|
||||||
|
Arguments = "-n true",
|
||||||
|
RedirectStandardOutput = true,
|
||||||
|
RedirectStandardError = true,
|
||||||
|
UseShellExecute = false,
|
||||||
|
};
|
||||||
|
using var proc = Process.Start(psi);
|
||||||
|
proc?.WaitForExit();
|
||||||
|
return proc?.ExitCode == 0;
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else if (Utils.IsMacOS())
|
else if (Utils.IsMacOS())
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue