[tor-commits] [arm/release] fix: torrc validation case sensetive

atagar at torproject.org atagar at torproject.org
Sun Apr 29 04:00:58 UTC 2012

commit e7e4bb5a9a39857436620f71edba9092ff963247
Author: Damian Johnson <atagar at torproject.org>
Date:   Wed Dec 7 09:17:29 2011 -0800

    fix: torrc validation case sensetive
    The torrc validation is case sensetive using tor's camelcase convention, but
    tor's torrc parsing is case insensetive. This caused confusing torrc warnings
    where, for instance, "Exitpolicy" would be reported as both being unused and
    also missing an "ExitPolicy" option. Reported in...
    This fix is functional but less than ideal since it makes the case
    insensetivity non-obvious (we're essentially converting the torrc arguments
    into the camelcase options we expect). I'll look into doing something nicer
    while refactoring for stem.
    Issue was caught on a Tor Cloud instance by kooly
 src/util/torConfig.py |   19 ++++++++++++++++++-
 1 files changed, 18 insertions(+), 1 deletions(-)

diff --git a/src/util/torConfig.py b/src/util/torConfig.py
index e26f634..851ef77 100644
--- a/src/util/torConfig.py
+++ b/src/util/torConfig.py
@@ -531,6 +531,21 @@ def validate(contents = None):
     if len(lineComp) == 2: option, value = lineComp
     else: option, value = lineText, ""
+    # Tor is case insensetive when parsing its torrc. This poses a bit of an
+    # issue for us because we want all of our checks to be case insensetive
+    # too but also want messages to match the normal camel-case conventions.
+    #
+    # Using the customOptions to account for this. It contains the tor reported
+    # options (camel case) and is either a matching set or the following defaut
+    # value check will fail. Hence using that hash to correct the case.
+    #
+    # TODO: when refactoring for stem make this less confusing...
+    for customOpt in customOptions:
+      if customOpt.lower() == option.lower():
+        option = customOpt
+        break
     # if an aliased option then use its real name
     if option in CONFIG["torrc.alias"]:
       option = CONFIG["torrc.alias"][option]
@@ -787,7 +802,9 @@ class Torrc():
       skipValidation = not CONFIG["features.torrc.validate"]
       skipValidation |= not torTools.getConn().isVersion("")
-      if skipValidation: returnVal = {}
+      if skipValidation:
+        log.log(log.INFO, "Skipping torrc validation (requires tor")
+        returnVal = {}
         if self.corrections == None:
           self.corrections = validate(self.contents)

More information about the tor-commits mailing list