"clone_newnet:%s, clone_newuser:%s, clone_newns:%s, clone_newpid:%s, "
"clone_newipc:%s, clonew_newuts:%s, clone_newcgroup:%s, keep_caps:%s, "
"tmpfs_size:%zu, disable_no_new_privs:%s, max_cpus:%zu",
- nsjconf->hostname, nsjconf->chroot ? nsjconf->chroot : "[NULL]", nsjconf->argv[0],
- nsjconf->bindhost, nsjconf->port, nsjconf->max_conns_per_ip, nsjconf->tlimit,
- nsjconf->personality, logYesNo(nsjconf->daemonize), logYesNo(nsjconf->clone_newnet),
+ nsjconf->hostname.c_str(), nsjconf->chroot.c_str(), nsjconf->argv[0], nsjconf->bindhost,
+ nsjconf->port, nsjconf->max_conns_per_ip, nsjconf->tlimit, nsjconf->personality,
+ logYesNo(nsjconf->daemonize), logYesNo(nsjconf->clone_newnet),
logYesNo(nsjconf->clone_newuser), logYesNo(nsjconf->clone_newns),
logYesNo(nsjconf->clone_newpid), logYesNo(nsjconf->clone_newipc),
logYesNo(nsjconf->clone_newuts), logYesNo(nsjconf->clone_newcgroup),
nsjconf->argv = NULL;
nsjconf->hostname = "NSJAIL";
nsjconf->cwd = "/";
- nsjconf->chroot = NULL;
nsjconf->port = 0;
nsjconf->bindhost = "::";
nsjconf->log_fd = STDERR_FILENO;
- nsjconf->logfile = NULL;
nsjconf->loglevel = INFO;
nsjconf->daemonize = false;
nsjconf->tlimit = 0;
break;
case 'l':
nsjconf->logfile = optarg;
- if (log::initLogFile(nsjconf.get()) == false) {
+ if (!log::initLogFile(nsjconf.get())) {
return nullptr;
}
break;
return nullptr;
}
}
- if (nsjconf->chroot) {
- if (!mnt::addMountPtHead(nsjconf.get(), nsjconf->chroot, "/", /* fs_type= */ "",
+ if (!(nsjconf->chroot.empty())) {
+ if (!mnt::addMountPtHead(nsjconf.get(), nsjconf->chroot.c_str(), "/",
+ /* fs_type= */ "",
/* options= */ "",
nsjconf->is_root_rw ? (MS_BIND | MS_REC | MS_PRIVATE)
: (MS_BIND | MS_REC | MS_PRIVATE | MS_RDONLY),
LOG_E("Uknown running mode: %d", njc.mode());
return false;
}
- nsjconf->chroot = DUP_IF_SET(njc, chroot_dir);
+ if (njc.has_chroot_dir()) {
+ nsjconf->chroot = njc.chroot_dir();
+ }
nsjconf->is_root_rw = njc.is_root_rw();
- nsjconf->hostname = njc.hostname().c_str();
- nsjconf->cwd = njc.cwd().c_str();
+ nsjconf->hostname = njc.hostname();
+ nsjconf->cwd = njc.cwd();
nsjconf->port = njc.port();
nsjconf->bindhost = njc.bindhost().c_str();
nsjconf->max_conns_per_ip = njc.max_conns_per_ip();
if (njc.has_log_fd()) {
nsjconf->log_fd = njc.log_fd();
}
- nsjconf->logfile = DUP_IF_SET(njc, log_file);
+ if (njc.has_log_file()) {
+ nsjconf->logfile = njc.log_file();
+ }
if (njc.has_log_level()) {
switch (njc.log_level()) {
case nsjail::LogLevel::DEBUG:
log_fd = nsjconf->log_fd;
log_level = nsjconf->loglevel;
- if (nsjconf->logfile == NULL && nsjconf->daemonize) {
+ if (nsjconf->logfile.empty() && nsjconf->daemonize) {
nsjconf->logfile = _LOG_DEFAULT_FILE;
}
- if (nsjconf->logfile == NULL) {
+ if (nsjconf->logfile.empty()) {
log_fd = fcntl(log_fd, F_DUPFD_CLOEXEC, 0);
} else {
if (TEMP_FAILURE_RETRY(
- log_fd = open(nsjconf->logfile, O_CREAT | O_RDWR | O_APPEND, 0640)) == -1) {
+ log_fd = open(nsjconf->logfile.c_str(), O_CREAT | O_RDWR | O_APPEND, 0640)) == -1) {
log_fd = STDERR_FILENO;
- PLOG_E("Couldn't open logfile open('%s')", nsjconf->logfile);
+ PLOG_E("Couldn't open logfile open('%s')", nsjconf->logfile.c_str());
return false;
}
}
* use --chroot in this case
*/
if (nsjconf->clone_newns == false) {
- if (nsjconf->chroot == NULL) {
+ if (nsjconf->chroot.empty()) {
PLOG_E(
"--chroot was not specified, and it's required when not using "
"CLONE_NEWNS");
return false;
}
- if (chroot(nsjconf->chroot) == -1) {
- PLOG_E("chroot('%s')", nsjconf->chroot);
+ if (chroot(nsjconf->chroot.c_str()) == -1) {
+ PLOG_E("chroot('%s')", nsjconf->chroot.c_str());
return false;
}
if (chdir("/") == -1) {
PLOG_E("umount2('/', MNT_DETACH)");
return false;
}
- if (chdir(nsjconf->cwd) == -1) {
- PLOG_E("chdir('%s')", nsjconf->cwd);
+ if (chdir(nsjconf->cwd.c_str()) == -1) {
+ PLOG_E("chdir('%s')", nsjconf->cwd.c_str());
return false;
}
bool use_execveat;
int exec_fd;
const char** argv;
- const char* hostname;
- const char* cwd;
- const char* chroot;
+ std::string hostname;
+ std::string cwd;
+ std::string chroot;
int port;
const char* bindhost;
int log_fd;
- const char* logfile;
+ std::string logfile;
enum llevel_t loglevel;
bool daemonize;
time_t tlimit;
return true;
}
- LOG_D("Setting hostname to '%s'", nsjconf->hostname);
- if (sethostname(nsjconf->hostname, strlen(nsjconf->hostname)) == -1) {
- PLOG_E("sethostname('%s')", nsjconf->hostname);
+ LOG_D("Setting hostname to '%s'", nsjconf->hostname.c_str());
+ if (sethostname(nsjconf->hostname.c_str(), strlen(nsjconf->hostname.c_str())) == -1) {
+ PLOG_E("sethostname('%s')", nsjconf->hostname.c_str());
return false;
}
return true;