parent
f12f461154
commit
8c290b8c02
@ -0,0 +1,13 @@
|
|||||||
|
#!/usr/bin/bash
|
||||||
|
|
||||||
|
AUTH_TOKEN="$1"
|
||||||
|
|
||||||
|
if [[ "$AUTH_TOKEN" == "user:bob;token=foo" ]]
|
||||||
|
then
|
||||||
|
echo "$(date): webfuse: auth granted: $AUTH_TOKEN" >> /tmp/webfuse_auth.log
|
||||||
|
else
|
||||||
|
echo "$(date): webfuse: auth denied: $AUTH_TOKEN" >> /tmp/webfuse_auth.log
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
@ -0,0 +1,55 @@
|
|||||||
|
#include "webfuse/util/authenticator.hpp"
|
||||||
|
|
||||||
|
#include <unistd.h>
|
||||||
|
#include <sys/wait.h>
|
||||||
|
#include <fcntl.h>
|
||||||
|
|
||||||
|
namespace webfuse
|
||||||
|
{
|
||||||
|
|
||||||
|
authenticator::authenticator(std::string const & app)
|
||||||
|
: app_(app)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
bool authenticator::authenticate(std::string const & token)
|
||||||
|
{
|
||||||
|
bool result = false;
|
||||||
|
|
||||||
|
pid_t const pid = fork();
|
||||||
|
|
||||||
|
if (pid == 0)
|
||||||
|
{
|
||||||
|
// child
|
||||||
|
|
||||||
|
// prepare file descriptors
|
||||||
|
closefrom(0);
|
||||||
|
open("/dev/null", O_RDONLY);
|
||||||
|
open("/dev/null", O_WRONLY);
|
||||||
|
dup2(STDOUT_FILENO, STDERR_FILENO);
|
||||||
|
|
||||||
|
execl(app_.c_str(), app_.c_str(), token.c_str(), nullptr);
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
else if (pid > 0)
|
||||||
|
{
|
||||||
|
// parent
|
||||||
|
int exit_status = EXIT_FAILURE;
|
||||||
|
|
||||||
|
int status = 0;
|
||||||
|
int const rc = waitpid(pid, &status, 0);
|
||||||
|
if (rc == pid)
|
||||||
|
{
|
||||||
|
exit_status = WEXITSTATUS(status);
|
||||||
|
}
|
||||||
|
|
||||||
|
result = (exit_status == EXIT_SUCCESS);
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,23 @@
|
|||||||
|
#ifndef WEBFUSE_AUTHENTICATOR_HPP
|
||||||
|
#define WEBFUSE_AUTHENTICATOR_HPP
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
namespace webfuse
|
||||||
|
{
|
||||||
|
|
||||||
|
class authenticator
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
explicit authenticator(std::string const & app);
|
||||||
|
~authenticator() = default;
|
||||||
|
|
||||||
|
bool authenticate(std::string const & token);
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::string app_;
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif
|
Loading…
Reference in new issue