[or-cvs] r22258: {arm} Improved messaging and failover behavior if controller passw (in arm/trunk: init util)

Damian Johnson atagar1 at gmail.com
Fri Apr 30 14:57:32 UTC 2010


Author: atagar
Date: 2010-04-30 14:57:31 +0000 (Fri, 30 Apr 2010)
New Revision: 22258

Modified:
   arm/trunk/init/starter.py
   arm/trunk/util/torTools.py
Log:
Improved messaging and failover behavior if controller password defined in config is incorrect.


Modified: arm/trunk/init/starter.py
===================================================================
--- arm/trunk/init/starter.py	2010-04-29 22:34:53 UTC (rev 22257)
+++ arm/trunk/init/starter.py	2010-04-30 14:57:31 UTC (rev 22258)
@@ -137,6 +137,7 @@
   
   # sets up TorCtl connection, prompting for the passphrase if necessary and
   # printing a notice if they arise
+  util.torTools.INCORRECT_PASSWORD_MSG = "Controller password found in '%s' was incorrect" % configPath
   authPassword = config.get(AUTH_CFG, None)
   conn = util.torTools.getConn(controlAddr, controlPort, authPassword)
   if conn == None: sys.exit(1)

Modified: arm/trunk/util/torTools.py
===================================================================
--- arm/trunk/util/torTools.py	2010-04-29 22:34:53 UTC (rev 22257)
+++ arm/trunk/util/torTools.py	2010-04-30 14:57:31 UTC (rev 22258)
@@ -8,6 +8,8 @@
 
 from TorCtl import TorCtl
 
+INCORRECT_PASSWORD_MSG = "Provided passphrase was incorrect"
+
 def makeCtlConn(controlAddr="127.0.0.1", controlPort=9051):
   """
   Opens a socket to the tor controller and queries its authentication type,
@@ -113,8 +115,8 @@
   """
   Convenience method for quickly getting a TorCtl connection. This is very
   handy for debugging or CLI setup, handling setup and prompting for a password
-  if necessary. If any issues arise this prints a description of the problem
-  and returns None.
+  if necessary (if either none is provided as input or it fails). If any issues
+  arise this prints a description of the problem and returns None.
   
   Arguments:
     controlAddr - ip address belonging to the controller
@@ -139,6 +141,12 @@
     initCtlConn(conn, authType, authValue)
     return conn
   except Exception, exc:
-    print exc
-    return None
+    if passphrase and str(exc) == "Unable to authenticate: password incorrect":
+      # provide a warining that the provided password didn't work, then try
+      # again prompting for the user to enter it
+      print INCORRECT_PASSWORD_MSG
+      return getConn(controlAddr, controlPort)
+    else:
+      print exc
+      return None
 



More information about the tor-commits mailing list