[Pkg-privacy-commits] [onionshare] 04/33: In Linux, create HS dir in /tmp/onionshare/* (#185), and also connect to Tor control port more robustly

Ximin Luo infinity0 at debian.org
Mon Oct 19 14:15:39 UTC 2015


This is an automated email from the git hooks/post-receive script.

infinity0 pushed a commit to branch debian
in repository onionshare.

commit 210448d6c9eea513bcefc009d07e4e0e4c3c8580
Author: Micah Lee <micah at micahflee.com>
Date:   Tue May 19 13:34:36 2015 -0700

    In Linux, create HS dir in /tmp/onionshare/* (#185), and also connect to Tor control port more robustly
---
 locale/en.json           |  4 +++-
 onionshare/onionshare.py | 23 +++++++++++++++++++----
 2 files changed, 22 insertions(+), 5 deletions(-)

diff --git a/locale/en.json b/locale/en.json
index 4a3faee..e918b42 100644
--- a/locale/en.json
+++ b/locale/en.json
@@ -40,5 +40,7 @@
     "gui_starting_server1": "Starting Tor hidden service...",
     "gui_starting_server2": "Crunching files...",
     "gui_starting_server3": "Waiting for Tor hidden service...",
-    "gui_please_wait": "Please wait..."
+    "gui_please_wait": "Please wait...",
+    "error_hs_dir_cannot_create": "Cannot create hidden service dir {0:s}",
+    "error_hs_dir_not_writable": "Hidden service dir {0:s} is not writable"
 }
diff --git a/onionshare/onionshare.py b/onionshare/onionshare.py
index 54f3b27..e08b1a6 100644
--- a/onionshare/onionshare.py
+++ b/onionshare/onionshare.py
@@ -21,7 +21,6 @@ import os, sys, subprocess, time, argparse, inspect, shutil, socket, threading,
 import socks
 
 from stem.control import Controller
-from stem import SocketError
 
 import strings, helpers, web
 
@@ -34,6 +33,10 @@ class TailsError(Exception):
     pass
 
 
+class HSDirError(Exception):
+    pass
+
+
 def hsdic2list(dic):
     """Convert what we get from get_conf_map to what we need for set_options"""
     return [
@@ -131,7 +134,17 @@ class OnionShare(object):
                     gid = grp.getgrnam("debian-tor").gr_gid
                     os.chown(self.hidserv_dir, uid, gid)
                 else:
-                    self.hidserv_dir = tempfile.mkdtemp()
+                    # in non-Tails linux, onionshare will create HS dir in /tmp/onionshare/*
+                    path = '/tmp/onionshare'
+                    try:
+                        if not os.path.exists(path):
+                            os.makedirs(path, 0700)
+                    except:
+                        raise HSDirError(strings._("error_hs_dir_cannot_create").format(path))
+                    if not os.access(path, os.W_OK):
+                        raise HSDirError(strings._("error_hs_dir_not_writable").format(path))
+
+                    self.hidserv_dir = tempfile.mkdtemp(dir=path)
                 self.cleanup_filenames.append(self.hidserv_dir)
 
                 # connect to the tor controlport
@@ -140,12 +153,12 @@ class OnionShare(object):
                 for tor_control_port in tor_control_ports:
                     try:
                         self.controller = Controller.from_port(port=tor_control_port)
+                        self.controller.authenticate()
                         break
-                    except SocketError:
+                    except:
                         pass
                 if not self.controller:
                     raise NoTor(strings._("cant_connect_ctrlport").format(tor_control_ports))
-                self.controller.authenticate()
 
                 # set up hidden service
                 if helpers.get_platform() == 'Windows':
@@ -301,6 +314,8 @@ def main(cwd=None):
         sys.exit(e.args[0])
     except TailsError as e:
         sys.exit(e.args[0])
+    except HSDirError as e:
+        sys.exit(e.args[0])
 
     # prepare files to share
     print strings._("preparing_files")

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-privacy/packages/onionshare.git



More information about the Pkg-privacy-commits mailing list