]> git.ipfire.org Git - thirdparty/tor.git/commitdiff
Make check_private_dir check for group ownership as appropriate
authorNick Mathewson <nickm@torproject.org>
Sun, 15 May 2011 17:11:48 +0000 (13:11 -0400)
committerNick Mathewson <nickm@torproject.org>
Mon, 16 May 2011 00:20:30 +0000 (20:20 -0400)
src/common/util.c

index 0e739f212795403f4b06aca98e703cbf85811410..1bb116b2121c5bd423defec115dec15492d09d8c 100644 (file)
@@ -30,6 +30,7 @@
 #else
 #include <dirent.h>
 #include <pwd.h>
+#include <grp.h>
 #endif
 
 /* math.h needs this on Linux */
@@ -1736,6 +1737,21 @@ check_private_dir(const char *dirname, cpd_check_t check)
     tor_free(process_ownername);
     return -1;
   }
+  if ((check & CPD_GROUP_OK) && st.st_gid != getgid()) {
+    struct group *gr;
+    char *process_groupname = NULL;
+    gr = getgrgid(getgid());
+    process_groupname = gr ? tor_strdup(gr->gr_name) : tor_strdup("<unknown>");
+    gr = getgrgid(st.st_gid);
+
+    log_warn(LD_FS, "%s is not owned by this group (%s, %d) but by group "
+             "%s (%d).  Are you running Tor as the wrong user?",
+             dirname, process_groupname, (int)getgid(),
+             gr ?  gr->gr_name : "<unknown>", (int)st.st_gid);
+
+    tor_free(process_groupname);
+    return -1;
+  }
   if (check & CPD_GROUP_OK) {
     mask = 0027;
   } else {