1
0
mirror of https://github.com/falk-werner/webfuse synced 2026-03-02 03:40:24 +00:00

use stdin to provide authentication token to authenticator rather than command line option

This commit is contained in:
Falk Werner
2023-02-04 15:48:17 +01:00
parent 1cbdfac3cc
commit 6f1841e610
5 changed files with 45 additions and 44 deletions

View File

@@ -17,23 +17,35 @@ bool authenticator::authenticate(std::string const & token)
{
bool result = false;
int fds[2];
int const rc = pipe(fds);
if (0 != rc)
{
return false;
}
pid_t const pid = fork();
if (pid == 0)
{
// child
close(STDIN_FILENO);
dup2(fds[0], STDIN_FILENO);
// prepare file descriptors
closefrom(0);
open("/dev/null", O_RDONLY);
closefrom(1);
open("/dev/null", O_WRONLY);
dup2(STDOUT_FILENO, STDERR_FILENO);
execl(app_.c_str(), app_.c_str(), token.c_str(), nullptr);
execl(app_.c_str(), app_.c_str(), nullptr);
exit(EXIT_FAILURE);
}
else if (pid > 0)
{
write(fds[1], reinterpret_cast<void const*>(token.c_str()), token.size());
close(fds[1]);
// parent
int exit_status = EXIT_FAILURE;
@@ -44,7 +56,8 @@ bool authenticator::authenticate(std::string const & token)
exit_status = WEXITSTATUS(status);
}
result = (exit_status == EXIT_SUCCESS);
close(fds[0]);
result = (exit_status == EXIT_SUCCESS);
}
return result;