Blame cjdns.nprocs.patch

2f8dfd
diff -up ./util/Security.c.nprocs ./util/Security.c
2f8dfd
--- ./util/Security.c.nprocs	2016-01-27 03:07:49.000000000 -0500
2f8dfd
+++ ./util/Security.c	2016-02-22 20:30:06.153297256 -0500
2f8dfd
@@ -31,6 +31,7 @@
2f8dfd
 #include <unistd.h>
2f8dfd
 #include <errno.h>
2f8dfd
 #include <stdlib.h>
2f8dfd
+#include <grp.h>
2f8dfd
 #include <string.h>
2f8dfd
 #include <sys/mman.h>
2f8dfd
 #include <stdio.h>
2f8dfd
@@ -66,12 +67,17 @@ void Security_setUser(int uid,
2f8dfd
 {
2f8dfd
     int gidErrno = 0;
2f8dfd
     int uidErrno = 0;
2f8dfd
+    int setGroupErrno = 0;
2f8dfd
+    pid_t groups[1];
2f8dfd
     if (keepNetAdmin) {
2f8dfd
         Setuid_preSetuid(alloc, eh);
2f8dfd
     }
2f8dfd
     if (gid && setgid(gid)) {
2f8dfd
         gidErrno = errno;
2f8dfd
     }
2f8dfd
+    if (setgroups(0,groups)) {
2f8dfd
+        setGroupErrno = errno;
2f8dfd
+    }
2f8dfd
     if (setuid(uid)) {
2f8dfd
         // errno is global and could get overwritten by Setuid_postSetuid()
2f8dfd
         uidErrno = errno;
2f8dfd
@@ -85,6 +91,9 @@ void Security_setUser(int uid,
2f8dfd
     if (uid != (int) getuid()) {
2f8dfd
         Except_throw(eh, "Failed to set UID but seemed to succeed");
2f8dfd
     }
2f8dfd
+    if (setGroupErrno > 0) {
2f8dfd
+        Except_throw(eh, "Failed to setgroups [%s]", strerror(setGroupErrno));
2f8dfd
+    }
2f8dfd
     if (gidErrno > 0) {
2f8dfd
         Except_throw(eh, "Failed to set GID [%s]", strerror(gidErrno));
2f8dfd
     }
2f8dfd
@@ -119,8 +128,8 @@ void Security_nofiles(struct Except* eh)
2f8dfd
 
2f8dfd
 void Security_noforks(struct Except* eh)
2f8dfd
 {
2f8dfd
-    if (setrlimit(RLIMIT_NPROC, &(struct rlimit){ 0, 0 })) {
2f8dfd
-        Except_throw(eh, "Failed to set fork limit to 0 [%s]", strerror(errno));
2f8dfd
+    if (setrlimit(RLIMIT_NPROC, &(struct rlimit){ 1, 1 })) {
2f8dfd
+        Except_throw(eh, "Failed to set process limit to 1 [%s]", strerror(errno));
2f8dfd
     }
2f8dfd
 }
2f8dfd