Skip to content

Commit

Permalink
Linux: simpler and more robust approach to detect active sudo session (
Browse files Browse the repository at this point in the history
  • Loading branch information
idrassi committed Jan 25, 2025
1 parent e34411b commit 5ff256a
Showing 1 changed file with 1 addition and 3 deletions.
4 changes: 1 addition & 3 deletions src/Core/Unix/CoreService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -305,8 +305,6 @@ namespace VeraCrypt
bool authCheckDone = false;
if (!Core->GetUseDummySudoPassword ())
{
// sudo man page: "If the -l option was specified without a command, sudo, will exit
// with a value of 0 if the user is allowed to run sudo, and they authenticated successfully"
// We are using -n to avoid prompting the user for a password.
// We are redirecting stderr to stdout and discarding both to avoid any output.
// This approach also works on newer macOS versions (12.0 and later).
Expand All @@ -316,7 +314,7 @@ namespace VeraCrypt
if (sudoAbsolutePath.empty())
throw SystemException(SRC_POS, errorMsg);

std::string popenCommand = sudoAbsolutePath + " -n -l > /dev/null 2>&1"; // We redirect stderr to stdout (2>&1) to be able to catch the result of the command
std::string popenCommand = sudoAbsolutePath + " -n true > /dev/null 2>&1"; // We redirect stderr to stdout (2>&1) to be able to catch the result of the command
FILE* pipe = popen(popenCommand.c_str(), "r");
if (pipe)
{
Expand Down

0 comments on commit 5ff256a

Please sign in to comment.