diff --git a/src/BashModule.cpp b/src/BashModule.cpp index a23ba4b..808991c 100644 --- a/src/BashModule.cpp +++ b/src/BashModule.cpp @@ -51,7 +51,7 @@ int BashModule::executeScript(string serviceUsername, string script) return status; } else { //child process - if(execl("/bin/bash", "/bin/bash", "--noediting", "--noprofile", "--norc", script.c_str(), (char *)0)==-1) + if(execl("/bin/bash", "/bin/bash", "--noediting", "--noprofile", "--norc", "--", script.c_str(), (char *)0)==-1) { cerr << "Error in the execl call of " << script << endl; } @@ -105,7 +105,7 @@ int BashModule::executeScriptAs(string serviceUsername, string script) //executing as the user corresponding to the service setgid(p->pw_gid); setuid(p->pw_uid); - if(execl("/bin/bash", "/bin/bash", "--noediting", "--noprofile", "--norc", script.c_str(), serviceUsername, (char *)0)==-1) + if(execl("/bin/bash", "/bin/bash", "--noediting", "--noprofile", "--norc", "--",script.c_str(), serviceUsername, (char *)0)==-1) { cerr << "Error in the execl call of " << script << endl; } diff --git a/src/main.cpp b/src/main.cpp index 186a4d5..78a681a 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -7,6 +7,7 @@ #include #include #include +#include #include "Services.h" #include "Modules.h" #include "BashManager.h" @@ -33,7 +34,8 @@ int isServiceOnServer(string serviceUsername) return 0; } -int createUser(string serviceUsername){ +int createUser(string serviceUsername) +{ //this method creates a Unix user dedicated to the service //get the User ID from servers.csv int uidStart=2000; //so that the uids do not overlap with existing uids @@ -48,25 +50,65 @@ int createUser(string serviceUsername){ return 0; } //create user - string cmd2 ="useradd -u " + to_string(uid) + " " + serviceUsername; - cout << cmd2 << endl; - int res2 = BashManager::execute(cmd2); - if (res2 != 0){ + string cmd2 ="useradd -u " + to_string(uid) + " " + serviceUsername + "&& usermod -s /sbin/nologin "+ serviceUsername; //no direct login + string res2 = BashManager::executeAndReadResult(cmd2); + if (res2 != ""){ cerr << "Error when executing the bash command to create a user specific to the service." << endl; + cerr << res2 << endl; return -1; } return 0; } -int createEnv(string serviceUsername){ - //TO DO - cout << "create env called" << endl; +int createEnvService(string serviceUsername) +{ + //create directories + //filesystem::create_directories() + + + /* + run mkdir -p "$DATA_DIR" "$HTTP_DIR" + run chown $uid "$DATA_DIR" + run chmod 751 "$DATA_DIR" + run chown $uid:www-data -R "$HTTP_DIR" + if [ -d "$SECRET_DIR" ] ; then + run chown $uid "$SECRET_DIR" -R + run chmod 751 "$SECRET_DIR" -R + fi*/ return 0; +} + +int removeEnvService() +{ + /* + [ -d "$HTTP_DIR" ] && rm -r "$HTTP_DIR"*/ return 0; } -int deployAll(){ +int createEnv() +{ + string proxyDir="etc/nginx"; + string dns_certs_path="/data/dnscerts.jean-cloud.org/certs/live"; + string http_certs_path="/etc/letsencrypt/live"; + + ofstream outfile ("/etc/jeancloud.env"); + outfile << "proxy_dir=" << proxyDir << endl; + outfile << "nginx_conf_path=" << proxyDir << "/sites-enabled/" <