[or-cvs] [torflow/master 14/92] Check directories exist before loading/saving scan results
mikeperry at torproject.org
mikeperry at torproject.org
Sat Aug 21 05:13:58 UTC 2010
Author: John M. Schanck <john at anomos.info>
Date: Sun, 4 Jul 2010 17:14:04 -0400
Subject: Check directories exist before loading/saving scan results
Commit: 820fad718de605203946bf29b0396b30cd1d9b5d
---
NetworkScanners/ExitAuthority/libsoat.py | 13 +++++++++++
NetworkScanners/ExitAuthority/soat.py | 34 ++++++++++++++++++++++++++++++
2 files changed, 47 insertions(+), 0 deletions(-)
diff --git a/NetworkScanners/ExitAuthority/libsoat.py b/NetworkScanners/ExitAuthority/libsoat.py
index dc6ea50..31ec77f 100644
--- a/NetworkScanners/ExitAuthority/libsoat.py
+++ b/NetworkScanners/ExitAuthority/libsoat.py
@@ -686,6 +686,19 @@ class DataHandler:
return DataHandler.uniqueFilename(str((rdir+address+'.'+result.exit_node[1:]+".result").decode('ascii', 'ignore')))
+ def checkResultDir(self, dir):
+ if not dir.startswith(self.data_dir):
+ return False
+ if not os.path.exists(dir):
+ try:
+ os.makedirs(dir, 0700)
+ except OSError, e:
+ plog("WARN", "Unable to create results directory %s. %s" % (dir, e))
+ return False
+ elif not os.access(dir, os.R_OK|os.W_OK):
+ return False
+ return True
+
def saveResult(self, result):
''' generic method for saving test results '''
result.filename = self.__resultFilename(result)
diff --git a/NetworkScanners/ExitAuthority/soat.py b/NetworkScanners/ExitAuthority/soat.py
index 731b5f0..d0d1b0e 100755
--- a/NetworkScanners/ExitAuthority/soat.py
+++ b/NetworkScanners/ExitAuthority/soat.py
@@ -2788,6 +2788,40 @@ def main(argv):
tests = {}
+ # Check that necessary result directories exist
+ dirsok = True
+ tocheck = []
+ rsubdirs = ['confirmed/', 'falsepositive/', 'rescan/', 'successful/', 'inconclusive/', 'failed/']
+ if do_ssl:
+ ssl_data_dir = os.path.join(soat_dir, 'ssl')
+ tocheck += [ssl_certs_dir]
+ tocheck += [os.path.join(ssl_data_dir, r) for r in rsubdirs]
+ if do_html or do_http:
+ tocheck += [http_content_dir]
+ tocheck += [os.path.join(http_data_dir, r) for r in rsubdirs]
+ if do_dns_rebind:
+ rebind_data_dir = os.path.join(soat_dir, 'dnsrebind')
+ tocheck += [os.path.join(rebind_data_dir, r) for r in rsubdirs]
+ # TODO: Uncomment relevant sections when tests are reenabled
+ #if do_ssh:
+ # ssh_data_dir = os.path.join(soat_dir, 'ssh')
+ # tocheck += [os.path.join(ssh_data_dir, r) for r in rsubdirs]
+ #if do_smtp:
+ # smtp_data_dir = os.path.join(soat_dir, 'smtp')
+ # tocheck += [os.path.join(smtp_data_dir, r) for r in rsubdirs]
+ #if do_pop:
+ # pop_data_dir = os.path.join(soat_dir, 'pop')
+ # tocheck += [os.path.join(pop_data_dir, r) for r in rsubdirs]
+ #if do_imap:
+ # imap_data_dir = os.path.join(soat_dir, 'imap')
+ # tocheck += [os.path.join(imap_data_dir, r) for r in rsubdirs]
+ for d in tocheck:
+ dirsok &= datahandler.checkResultDir(d)
+ if not dirsok:
+ plog("ERROR", "Could not create result directories")
+ sys.exit(1)
+
+ # Initialize tests
if do_resume:
plog("NOTICE", "Resuming previous SoaT run #"+str(resume_run))
if do_ssl:
--
1.7.1
More information about the tor-commits
mailing list