More of RETURN_ON_FAILURE
authorRobert Swiecki <robert@swiecki.net>
Tue, 1 Jan 2019 10:36:02 +0000 (11:36 +0100)
committerRobert Swiecki <robert@swiecki.net>
Tue, 1 Jan 2019 10:36:02 +0000 (11:36 +0100)
Makefile
contain.cc
user.cc

index 105fc96..e318820 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -109,7 +109,7 @@ cmdline.o: util.h
 config.o: caps.h nsjail.h cmdline.h config.h config.pb.h logs.h macros.h
 config.o: mnt.h user.h util.h
 contain.o: contain.h nsjail.h caps.h cgroup.h cpu.h logs.h macros.h mnt.h
-contain.o: net.h pid.h user.h uts.h
+contain.o: net.h pid.h user.h util.h uts.h
 cpu.o: cpu.h nsjail.h logs.h util.h
 logs.o: logs.h macros.h util.h nsjail.h
 mnt.o: mnt.h nsjail.h logs.h macros.h subproc.h util.h
index 18c43d4..176f216 100644 (file)
@@ -48,6 +48,7 @@
 #include "net.h"
 #include "pid.h"
 #include "user.h"
+#include "util.h"
 #include "uts.h"
 
 namespace contain {
@@ -294,41 +295,21 @@ bool setupFD(nsjconf_t* nsjconf, int fd_in, int fd_out, int fd_err) {
 }
 
 bool containProc(nsjconf_t* nsjconf) {
-       if (!containUserNs(nsjconf)) {
-               return false;
-       }
-       if (!containInitPidNs(nsjconf)) {
-               return false;
-       }
-       if (!containInitMountNs(nsjconf)) {
-               return false;
-       }
-       if (!containInitNetNs(nsjconf)) {
-               return false;
-       }
-       if (!containInitUtsNs(nsjconf)) {
-               return false;
-       }
-       if (!containInitCgroupNs()) {
-               return false;
-       }
-       if (!containDropPrivs(nsjconf)) {
-               return false;
-       }
+       RETURN_ON_FAILURE(containUserNs(nsjconf));
+       RETURN_ON_FAILURE(containInitPidNs(nsjconf));
+       RETURN_ON_FAILURE(containInitMountNs(nsjconf));
+       RETURN_ON_FAILURE(containInitNetNs(nsjconf));
+       RETURN_ON_FAILURE(containInitUtsNs(nsjconf));
+       RETURN_ON_FAILURE(containInitCgroupNs());
+       RETURN_ON_FAILURE(containDropPrivs(nsjconf));
+       ;
        /* */
        /* As non-root */
-       if (!containCPU(nsjconf)) {
-               return false;
-       }
-       if (!containSetLimits(nsjconf)) {
-               return false;
-       }
-       if (!containPrepareEnv(nsjconf)) {
-               return false;
-       }
-       if (!containMakeFdsCOE(nsjconf)) {
-               return false;
-       }
+       RETURN_ON_FAILURE(containCPU(nsjconf));
+       RETURN_ON_FAILURE(containSetLimits(nsjconf));
+       RETURN_ON_FAILURE(containPrepareEnv(nsjconf));
+       RETURN_ON_FAILURE(containMakeFdsCOE(nsjconf));
+
        return true;
 }
 
diff --git a/user.cc b/user.cc
index 1eccadc..4053884 100644 (file)
--- a/user.cc
+++ b/user.cc
@@ -205,18 +205,11 @@ static bool uidMapExternal(nsjconf_t* nsjconf, pid_t pid UNUSED) {
 }
 
 static bool uidGidMap(nsjconf_t* nsjconf, pid_t pid) {
-       if (!gidMapSelf(nsjconf, pid)) {
-               return false;
-       }
-       if (!gidMapExternal(nsjconf, pid)) {
-               return false;
-       }
-       if (!uidMapSelf(nsjconf, pid)) {
-               return false;
-       }
-       if (!uidMapExternal(nsjconf, pid)) {
-               return false;
-       }
+       RETURN_ON_FAILURE(gidMapSelf(nsjconf, pid));
+       RETURN_ON_FAILURE(gidMapExternal(nsjconf, pid));
+       RETURN_ON_FAILURE(uidMapSelf(nsjconf, pid));
+       RETURN_ON_FAILURE(uidMapExternal(nsjconf, pid));
+
        return true;
 }