summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authordrebs <drebs@riseup.net>2016-09-27 22:04:41 -0300
committerdrebs <drebs@riseup.net>2016-10-03 12:01:29 -0300
commit10330b390de4dfaf72853ecb4454bf4142415add (patch)
tree59c8079d983f7442897c39c14e51ac7272d79baa /src
parent9c4bf6adf42f0f9553ae11f24ffeb6f7cf39f374 (diff)
[bug] stop syncing after logout (#8479)
Diffstat (limited to 'src')
-rw-r--r--src/leap/bitmask/bonafide/service.py3
-rw-r--r--src/leap/bitmask/core/mail_services.py20
-rw-r--r--src/leap/bitmask/core/service.py5
-rw-r--r--src/leap/bitmask/mail/incoming/service.py21
4 files changed, 32 insertions, 17 deletions
diff --git a/src/leap/bitmask/bonafide/service.py b/src/leap/bitmask/bonafide/service.py
index 797e6065..1f0d6362 100644
--- a/src/leap/bitmask/bonafide/service.py
+++ b/src/leap/bitmask/bonafide/service.py
@@ -98,6 +98,9 @@ class BonafideService(HookableService):
self._active_user = None
return passthrough
+ data = dict(username=username)
+ self.trigger_hook('on_bonafide_logout', **data)
+
d = self._bonafide.do_logout(username)
d.addCallback(reset_active)
d.addCallback(lambda response: {'logout': 'ok'})
diff --git a/src/leap/bitmask/core/mail_services.py b/src/leap/bitmask/core/mail_services.py
index d2967f89..f971c1a2 100644
--- a/src/leap/bitmask/core/mail_services.py
+++ b/src/leap/bitmask/core/mail_services.py
@@ -435,8 +435,6 @@ class StandardMailService(service.MultiService, HookableService):
# TODO factor out Mail Service to inside mail package.
- subscribed_to_hooks = ('on_new_keymanager_instance',)
-
def __init__(self, basedir):
self._basedir = basedir
self._soledad_sessions = {}
@@ -502,12 +500,22 @@ class StandardMailService(service.MultiService, HookableService):
def hook_on_bonafide_auth(self, **kw):
# TODO: if it's expired we should renew it
userid = kw['username']
+
+ # turn on incoming mail service for the user that just logged in
+ multiservice = self.getServiceNamed('incoming_mail')
+ incoming = multiservice.getServiceNamed(userid)
+ log.msg('looking for incoming mail service for auth: %s' % userid)
+ if incoming:
+ incoming.startService()
+
+ # check if smtp cert exists
username, provider = userid.split('@')
cert_path = _get_smtp_client_cert_path(self._basedir, provider,
username)
if os.path.exists(cert_path):
return
+ # fetch smtp cert and store
bonafide = self.parent.getServiceNamed("bonafide")
_, cert_str = yield bonafide.do_get_smtp_cert(userid)
@@ -518,6 +526,14 @@ class StandardMailService(service.MultiService, HookableService):
outf.write(cert_str)
check_and_fix_urw_only(cert_path)
+ def hook_on_bonafide_logout(self, **kw):
+ username = kw['username']
+ multiservice = self.getServiceNamed('incoming_mail')
+ incoming = multiservice.getServiceNamed(username)
+ log.msg('looking for incoming mail service for logout: %s' % username)
+ if incoming:
+ incoming.stopService()
+
# commands
def do_status(self):
diff --git a/src/leap/bitmask/core/service.py b/src/leap/bitmask/core/service.py
index de99ea55..1a544acf 100644
--- a/src/leap/bitmask/core/service.py
+++ b/src/leap/bitmask/core/service.py
@@ -89,6 +89,7 @@ class BitmaskBackend(configurable.ConfigurableService):
bf.register_hook('on_passphrase_change', listener='soledad')
bf.register_hook('on_bonafide_auth', listener='keymanager')
bf.register_hook('on_bonafide_auth', listener='mail')
+ bf.register_hook('on_bonafide_logout', listener='mail')
def _start_child_service(self, name):
log.msg('starting backend child service: %s' % name)
@@ -156,13 +157,13 @@ class BitmaskBackend(configurable.ConfigurableService):
def _maybe_init_service(self, label, klass, *args, **kw):
try:
- self.getServiceNamed(label)
+ service = self.getServiceNamed(label)
except KeyError:
log.msg("initializing service: %s" % label)
service = klass(*args, **kw)
service.setName(label)
service.setServiceParent(self)
- return service
+ return service
def do_stats(self):
return self.core_commands.do_stats()
diff --git a/src/leap/bitmask/mail/incoming/service.py b/src/leap/bitmask/mail/incoming/service.py
index b4cdfcf3..86c3055c 100644
--- a/src/leap/bitmask/mail/incoming/service.py
+++ b/src/leap/bitmask/mail/incoming/service.py
@@ -31,7 +31,6 @@ from urlparse import urlparse
from twisted.application.service import Service
from twisted.application.service import IService
from twisted.logger import Logger
-from twisted.python.failure import Failure
from twisted.internet import defer, reactor
from twisted.internet.task import LoopingCall
from twisted.internet.task import deferLater
@@ -183,27 +182,23 @@ class IncomingMail(Service):
def startService(self):
"""
- Starts a loop to fetch mail.
-
- :returns: A Deferred whose callback will be invoked with
- the LoopingCall instance when loop.stop is called, or
- whose errback will be invoked when the function raises an
- exception or returned a deferred that has its errback
- invoked.
+ Start a loop to fetch mail.
"""
+ if self.running:
+ return
+
Service.startService(self)
if self._loop is None:
self._loop = LoopingCall(self.fetch)
- stop_deferred = self._loop.start(self._check_period)
- return stop_deferred
- else:
- logger.warning("Tried to start an already running fetching loop.")
- return defer.fail(Failure('Already running loop.'))
+ self._loop.start(self._check_period)
def stopService(self):
"""
Stops the loop that fetches mail.
"""
+ if not self.running:
+ return
+
if self._loop and self._loop.running is True:
self._loop.stop()
self._loop = None