From 810394cf16d8428c394e8a83fa1ccc7842f7192d Mon Sep 17 00:00:00 2001 From: Robert Swiecki Date: Mon, 12 Feb 2018 15:17:33 +0100 Subject: [PATCH] switc all == false cmps to ! --- caps.cc | 8 ++++---- cmdline.cc | 4 ++-- config.cc | 2 +- contain.cc | 30 +++++++++++++++--------------- net.cc | 6 +++--- nsjail.cc | 6 +++--- subproc.cc | 22 +++++++++++----------- user.cc | 6 +++--- util.cc | 2 +- uts.cc | 2 +- 10 files changed, 44 insertions(+), 44 deletions(-) diff --git a/caps.cc b/caps.cc index 96f1361..ffc15ed 100644 --- a/caps.cc +++ b/caps.cc @@ -179,14 +179,14 @@ static bool initNsKeepCaps(cap_user_data_t cap_data) { } LOG_D("Adding the following capabilities to the inheritable set:%s", dbgmsg); - if (setCaps(cap_data) == false) { + if (!setCaps(cap_data)) { return false; } /* Make sure the inheritable set is preserved across execve via the ambient set */ dbgmsg[0] = '\0'; for (size_t i = 0; i < ARRAYSIZE(capNames); i++) { - if (getPermitted(cap_data, capNames[i].val) == false) { + if (!getPermitted(cap_data, capNames[i].val)) { continue; } if (prctl(PR_CAP_AMBIENT, PR_CAP_AMBIENT_RAISE, (unsigned long)capNames[i].val, 0UL, @@ -228,7 +228,7 @@ bool initNs(nsjconf_t* nsjconf) { */ dbgmsg[0] = '\0'; for (const auto& cap : nsjconf->caps) { - if (getPermitted(cap_data, cap) == false) { + if (!getPermitted(cap_data, cap)) { LOG_W("Capability %s is not permitted in the namespace", capToStr(cap).c_str()); return false; @@ -238,7 +238,7 @@ bool initNs(nsjconf_t* nsjconf) { } LOG_D("Adding the following capabilities to the inheritable set:%s", dbgmsg); - if (setCaps(cap_data) == false) { + if (!setCaps(cap_data)) { return false; } diff --git a/cmdline.cc b/cmdline.cc index 2096c2f..5dcbf8c 100644 --- a/cmdline.cc +++ b/cmdline.cc @@ -282,7 +282,7 @@ uint64_t parseRLimit(int res, const char* optarg, unsigned long mul) { if (strcasecmp(optarg, "max") == 0 || strcasecmp(optarg, "hard") == 0) { return cur.rlim_max; } - if (util::isANumber(optarg) == false) { + if (!util::isANumber(optarg)) { LOG_F( "RLIMIT %d needs a numeric or 'max'/'hard'/'def'/'soft'/'inf' value ('%s' " "provided)", @@ -403,7 +403,7 @@ std::unique_ptr parseArgs(int argc, char* argv[]) { nsjconf->cwd = optarg; break; case 'C': - if (config::parseFile(nsjconf.get(), optarg) == false) { + if (!config::parseFile(nsjconf.get(), optarg)) { LOG_F("Couldn't parse configuration from '%s' file", optarg); } break; diff --git a/config.cc b/config.cc index 4b8bd1c..14ca363 100644 --- a/config.cc +++ b/config.cc @@ -208,7 +208,7 @@ static bool configParseInternal(nsjconf_t* nsjconf, const nsjail::NsJailConfig& std::string fstype = njc.mount(i).fstype(); std::string options = njc.mount(i).options(); - uintptr_t flags = (njc.mount(i).rw() == false) ? MS_RDONLY : 0; + uintptr_t flags = (!njc.mount(i).rw()) ? MS_RDONLY : 0; flags |= njc.mount(i).is_bind() ? (MS_BIND | MS_REC | MS_PRIVATE) : 0; bool is_mandatory = njc.mount(i).mandatory(); bool is_symlink = njc.mount(i).is_symlink(); diff --git a/contain.cc b/contain.cc index 089c7e6..525c045 100644 --- a/contain.cc +++ b/contain.cc @@ -74,14 +74,14 @@ static bool containDropPrivs(nsjconf_t* nsjconf) { #ifndef PR_SET_NO_NEW_PRIVS #define PR_SET_NO_NEW_PRIVS 38 #endif - if (nsjconf->disable_no_new_privs == false) { + if (!nsjconf->disable_no_new_privs) { if (prctl(PR_SET_NO_NEW_PRIVS, 1UL, 0UL, 0UL, 0UL) == -1) { /* Only new kernels support it */ PLOG_W("prctl(PR_SET_NO_NEW_PRIVS, 1)"); } } - if (caps::initNs(nsjconf) == false) { + if (!caps::initNs(nsjconf)) { return false; } @@ -101,7 +101,7 @@ static bool containPrepareEnv(nsjconf_t* nsjconf) { if (setpriority(PRIO_PROCESS, 0, 19) == -1 && errno != 0) { PLOG_W("setpriority(19)"); } - if (nsjconf->skip_setsid == false) { + if (!nsjconf->skip_setsid) { setsid(); } return true; @@ -261,7 +261,7 @@ static bool containMakeFdsCOE(nsjconf_t* nsjconf) { bool setupFD(nsjconf_t* nsjconf, int fd_in, int fd_out, int fd_err) { if (nsjconf->mode != MODE_LISTEN_TCP) { - if (nsjconf->is_silent == false) { + if (!nsjconf->is_silent) { return true; } if (TEMP_FAILURE_RETRY(fd_in = fd_out = fd_err = open("/dev/null", O_RDWR)) == -1) { @@ -286,39 +286,39 @@ bool setupFD(nsjconf_t* nsjconf, int fd_in, int fd_out, int fd_err) { } bool containProc(nsjconf_t* nsjconf) { - if (containUserNs(nsjconf) == false) { + if (!containUserNs(nsjconf)) { return false; } - if (containInitPidNs(nsjconf) == false) { + if (!containInitPidNs(nsjconf)) { return false; } - if (containInitMountNs(nsjconf) == false) { + if (!containInitMountNs(nsjconf)) { return false; } - if (containInitNetNs(nsjconf) == false) { + if (!containInitNetNs(nsjconf)) { return false; } - if (containInitUtsNs(nsjconf) == false) { + if (!containInitUtsNs(nsjconf)) { return false; } - if (containInitCgroupNs() == false) { + if (!containInitCgroupNs()) { return false; } - if (containDropPrivs(nsjconf) == false) { + if (!containDropPrivs(nsjconf)) { return false; } /* */ /* As non-root */ - if (containCPU(nsjconf) == false) { + if (!containCPU(nsjconf)) { return false; } - if (containSetLimits(nsjconf) == false) { + if (!containSetLimits(nsjconf)) { return false; } - if (containPrepareEnv(nsjconf) == false) { + if (!containPrepareEnv(nsjconf)) { return false; } - if (containMakeFdsCOE(nsjconf) == false) { + if (!containMakeFdsCOE(nsjconf)) { return false; } return true; diff --git a/net.cc b/net.cc index f40407e..6c9b091 100644 --- a/net.cc +++ b/net.cc @@ -54,7 +54,7 @@ namespace net { #include #include bool initNsFromParent(nsjconf_t* nsjconf, int pid) { - if (nsjconf->clone_newnet == false) { + if (!nsjconf->clone_newnet) { return true; } if (nsjconf->iface_vs.empty()) { @@ -122,7 +122,7 @@ bool initNsFromParent(nsjconf_t* nsjconf, int pid) { #else // defined(NSJAIL_NL3_WITH_MACVLAN) bool initNsFromParent(nsjconf_t* nsjconf, int pid) { - if (nsjconf->clone_newnet == false) { + if (!nsjconf->clone_newnet) { return true; } if (nsjconf->iface_vs.empty()) { @@ -369,7 +369,7 @@ static bool netConfigureVs(nsjconf_t* nsjconf) { return false; } - if (ifaceUp(IFACE_NAME) == false) { + if (!ifaceUp(IFACE_NAME)) { close(sock); return false; } diff --git a/nsjail.cc b/nsjail.cc index 270d0c3..6ba72f0 100644 --- a/nsjail.cc +++ b/nsjail.cc @@ -162,17 +162,17 @@ int main(int argc, char* argv[]) { if (!nsjconf) { LOG_F("Couldn't parse cmdline options"); } - if (nsjconf->clone_newuser == false && geteuid() != 0) { + if (!nsjconf->clone_newuser && geteuid() != 0) { LOG_W("--disable_clone_newuser might require root() privs"); } if (nsjconf->daemonize && (daemon(0, 0) == -1)) { PLOG_F("daemon"); } cmdline::logParams(nsjconf.get()); - if (nsjailSetSigHandlers() == false) { + if (!nsjailSetSigHandlers()) { LOG_F("nsjailSetSigHandlers() failed"); } - if (nsjailSetTimer(nsjconf.get()) == false) { + if (!nsjailSetTimer(nsjconf.get())) { LOG_F("nsjailSetTimer() failed"); } if (!sandbox::preparePolicy(nsjconf.get())) { diff --git a/subproc.cc b/subproc.cc index 4752465..dd453cc 100644 --- a/subproc.cc +++ b/subproc.cc @@ -131,7 +131,7 @@ static bool resetEnv(void) { static const char kSubprocDoneChar = 'D'; static int subprocNewProc(nsjconf_t* nsjconf, int fd_in, int fd_out, int fd_err, int pipefd) { - if (contain::setupFD(nsjconf, fd_in, fd_out, fd_err) == false) { + if (!contain::setupFD(nsjconf, fd_in, fd_out, fd_err)) { _exit(0xff); } if (!resetEnv()) { @@ -139,11 +139,11 @@ static int subprocNewProc(nsjconf_t* nsjconf, int fd_in, int fd_out, int fd_err, } if (pipefd == -1) { - if (user::initNsFromParent(nsjconf, getpid()) == false) { + if (!user::initNsFromParent(nsjconf, getpid())) { LOG_E("Couldn't initialize net user namespace"); _exit(0xff); } - if (cgroup::initNsFromParent(nsjconf, getpid()) == false) { + if (!cgroup::initNsFromParent(nsjconf, getpid())) { LOG_E("Couldn't initialize net user namespace"); _exit(0xff); } @@ -156,10 +156,10 @@ static int subprocNewProc(nsjconf_t* nsjconf, int fd_in, int fd_out, int fd_err, _exit(0xff); } } - if (contain::containProc(nsjconf) == false) { + if (!contain::containProc(nsjconf)) { _exit(0xff); } - if (nsjconf->keep_env == false) { + if (!nsjconf->keep_env) { clearenv(); } for (const auto& env : nsjconf->envs) { @@ -174,7 +174,7 @@ static int subprocNewProc(nsjconf_t* nsjconf, int fd_in, int fd_out, int fd_err, } /* Should be the last one in the sequence */ - if (sandbox::applyPolicy(nsjconf) == false) { + if (!sandbox::applyPolicy(nsjconf)) { exit(0xff); } @@ -365,15 +365,15 @@ void killAll(nsjconf_t* nsjconf) { } static bool initParent(nsjconf_t* nsjconf, pid_t pid, int pipefd) { - if (net::initNsFromParent(nsjconf, pid) == false) { + if (!net::initNsFromParent(nsjconf, pid)) { LOG_E("Couldn't create and put MACVTAP interface into NS of PID '%d'", pid); return false; } - if (cgroup::initNsFromParent(nsjconf, pid) == false) { + if (!cgroup::initNsFromParent(nsjconf, pid)) { LOG_E("Couldn't initialize cgroup user namespace"); exit(0xff); } - if (user::initNsFromParent(nsjconf, pid) == false) { + if (!user::initNsFromParent(nsjconf, pid)) { LOG_E("Couldn't initialize user namespaces for pid %d", pid); return false; } @@ -386,7 +386,7 @@ static bool initParent(nsjconf_t* nsjconf, pid_t pid, int pipefd) { } void runChild(nsjconf_t* nsjconf, int fd_in, int fd_out, int fd_err) { - if (net::limitConns(nsjconf, fd_in) == false) { + if (!net::limitConns(nsjconf, fd_in)) { return; } unsigned long flags = 0UL; @@ -441,7 +441,7 @@ void runChild(nsjconf_t* nsjconf, int fd_in, int fd_out, int fd_err) { } addProc(nsjconf, pid, fd_in); - if (initParent(nsjconf, pid, parent_fd) == false) { + if (!initParent(nsjconf, pid, parent_fd)) { close(parent_fd); return; } diff --git a/user.cc b/user.cc index d2e5064..448f842 100644 --- a/user.cc +++ b/user.cc @@ -221,13 +221,13 @@ static bool uidGidMap(nsjconf_t* nsjconf, pid_t pid) { } bool initNsFromParent(nsjconf_t* nsjconf, pid_t pid) { - if (setGroups(pid) == false) { + if (!setGroups(pid)) { return false; } - if (nsjconf->clone_newuser == false) { + if (!nsjconf->clone_newuser) { return true; } - if (uidGidMap(nsjconf, pid) == false) { + if (!uidGidMap(nsjconf, pid)) { return false; } return true; diff --git a/util.cc b/util.cc index e48ea59..44f2daa 100644 --- a/util.cc +++ b/util.cc @@ -97,7 +97,7 @@ bool writeBufToFile(const char* filename, const void* buf, size_t len, int open_ return false; } - if (writeToFd(fd, buf, len) == false) { + if (!writeToFd(fd, buf, len)) { PLOG_E("Couldn't write '%zu' bytes to file '%s' (fd='%d')", len, filename, fd); close(fd); unlink(filename); diff --git a/uts.cc b/uts.cc index db6450b..5827ddd 100644 --- a/uts.cc +++ b/uts.cc @@ -29,7 +29,7 @@ namespace uts { bool initNs(nsjconf_t* nsjconf) { - if (nsjconf->clone_newuts == false) { + if (!nsjconf->clone_newuts) { return true; }