tor: Fix problems with running a relay

This is a fix for regression introduced by
ebe6a0ed026e27dc650b4c2fed8426357f959ddc. I have incorrectly assumed that
providing only IPv6 ORPort is sufficient to listen on IPv4 and IPv6. As a
result, Tor does not run when relay is enabled. Fix this by adding ORPorts for
both IPv6 and IPv4.

Tests performed:

- Tor shows as running after enabling relay functionality.

- Adding single or multiple ORPort values in the configuration file leads to
actions/tor get-status reporting that relay is enabled.

- Functional tests for Tor run properly.

Signed-off-by: Sunil Mohan Adapa <sunil@medhas.org>
Reviewed-by: James Valleroy <jvalleroy@mailbox.org>
This commit is contained in:
Sunil Mohan Adapa 2020-05-20 16:45:26 -07:00 committed by James Valleroy
parent a4dab3cc36
commit 8cb5716f76
No known key found for this signature in database
GPG Key ID: 77C0C75E7B650808
2 changed files with 8 additions and 6 deletions

View File

@ -65,7 +65,7 @@ def parse_arguments():
def subcommand_setup(arguments):
"""Setup Tor configuration after installing it."""
if arguments.old_version and arguments.old_version <= 3:
if arguments.old_version and arguments.old_version <= 4:
_upgrade_orport_value()
return
@ -148,7 +148,8 @@ def _upgrade_orport_value():
aug = augeas_load()
if _is_relay_enabled(aug):
aug.set(TOR_CONFIG + '/ORPort', '[::]:9001')
aug.set(TOR_CONFIG + '/ORPort[1]', '9001')
aug.set(TOR_CONFIG + '/ORPort[2]', '[::]:9001')
aug.save()
@ -241,7 +242,7 @@ def _get_upstream_bridges(aug):
def _is_relay_enabled(aug):
"""Return whether a relay is enabled."""
orport = aug.get(TOR_CONFIG + '/ORPort')
orport = aug.get(TOR_CONFIG + '/ORPort[1]')
return bool(orport) and orport != '0'
@ -390,7 +391,8 @@ def _enable_relay(relay=None, bridge=None, aug=None):
use_upstream_bridges = _are_upstream_bridges_enabled(aug)
if relay == 'enable' and not use_upstream_bridges:
aug.set(TOR_CONFIG + '/ORPort', '[::]:9001')
aug.set(TOR_CONFIG + '/ORPort[1]', '9001')
aug.set(TOR_CONFIG + '/ORPort[2]', '[::]:9001')
elif relay == 'disable':
aug.remove(TOR_CONFIG + '/ORPort')

View File

@ -14,13 +14,13 @@ from plinth.daemon import Daemon, diagnose_netcat, diagnose_port_listening
from plinth.modules.apache.components import diagnose_url
from plinth.modules.firewall.components import Firewall
from plinth.modules.names.components import DomainType
from plinth.signals import domain_added, domain_removed
from plinth.modules.users.components import UsersAndGroups
from plinth.signals import domain_added, domain_removed
from . import utils
from .manifest import backup, clients # noqa, pylint: disable=unused-import
version = 4
version = 5
depends = ['names']