]> git.ipfire.org Git - thirdparty/tor.git/commitdiff
Warn when two hs use the same directory
authorSebastian Hahn <sebastian@torproject.org>
Sat, 28 May 2011 22:54:59 +0000 (00:54 +0200)
committerNick Mathewson <nickm@torproject.org>
Mon, 30 May 2011 19:47:06 +0000 (15:47 -0400)
This simple implementation has a few issues, but it should do for
0.2.2.x. We will want to revisit this later and make it smarter.

changes/bug3289 [new file with mode: 0644]
src/or/rendservice.c

diff --git a/changes/bug3289 b/changes/bug3289
new file mode 100644 (file)
index 0000000..c469796
--- /dev/null
@@ -0,0 +1,5 @@
+  o Minor bugfixes:
+    - Warn when the user configures two HiddenServiceDir lines that point
+      to the same directory. Bugfix on 0.0.6 (the version introducing
+      HiddenServiceDir); fixes bug 3289.
+
index edcf59d8703461baf5c8d3e528a31bd80d917d2c..a10e43fead71ac80bd047e438b92d5602be421ca 100644 (file)
@@ -181,6 +181,31 @@ rend_add_service(rend_service_t *service)
     log_warn(LD_CONFIG, "Hidden service with no ports configured; ignoring.");
     rend_service_free(service);
   } else {
+    int dupe = 0;
+    /* XXX This duplicate check has two problems:
+     *
+     * a) It's O(n^2), but the same comment from the bottom of
+     *    rend_config_services() should apply.
+     *
+     * b) We only compare directory paths as strings, so we can't
+     *    detect two distinct paths that specify the same directory
+     *    (which can arise from symlinks, case-insensitivity, bind
+     *    mounts, etc.).
+     *
+     * It also can't detect that two separate Tor instances are trying
+     * to use the same HiddenServiceDir; for that, we would need a
+     * lock file.  But this is enough to detect a simple mistake that
+     * at least one person has actually made.
+     */
+    SMARTLIST_FOREACH(rend_service_list, rend_service_t*, ptr,
+                      dupe = dupe ||
+                             !strcmp(ptr->directory, service->directory));
+    if (dupe) {
+      log_warn(LD_REND, "Another hidden service is already configured for "
+               "directory %s, ignoring.", service->directory);
+      rend_service_free(service);
+      return;
+    }
     smartlist_add(rend_service_list, service);
     log_debug(LD_REND,"Configuring service with directory \"%s\"",
               service->directory);