Added a run_as string in json to configure which user the app has to be run by.
This commit is contained in:
parent
f75e4d236c
commit
7426d1dfd7
1 changed files with 38 additions and 5 deletions
|
|
@ -8,6 +8,8 @@ extern "C" {
|
|||
#include <fcntl.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/wait.h>
|
||||
#include <pwd.h>
|
||||
#include <grp.h>
|
||||
#include <stdlib.h>
|
||||
}
|
||||
|
||||
|
|
@ -96,6 +98,10 @@ void ExecutionManager::run()
|
|||
std::string program_name = ptr->getProgramName();
|
||||
std::string program_log_name_temp = module_name + ".log";
|
||||
std::string program_log_name = "";
|
||||
std::string run_as = ptr->getRunAs();
|
||||
struct passwd *pw = nullptr;
|
||||
if(run_as.size() != 0)
|
||||
pw = getpwnam(run_as.c_str());
|
||||
for(auto &ch: program_log_name_temp) {
|
||||
if(ch != ' ') {
|
||||
program_log_name += ch;
|
||||
|
|
@ -127,6 +133,11 @@ void ExecutionManager::run()
|
|||
if(!dir.empty()) {
|
||||
int err = chdir(dir.c_str());
|
||||
}
|
||||
if(pw) {
|
||||
initgroups(pw->pw_name, pw->pw_gid);
|
||||
setgid(pw->pw_gid);
|
||||
setuid(pw->pw_uid);
|
||||
}
|
||||
for(auto &[key,value]: env) {
|
||||
setenv(key.data(), value.data(), 1);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue