From c190b7f66cc1977d0e058bfa2d8fc1a850326320 Mon Sep 17 00:00:00 2001 From: kali Date: Wed, 5 Sep 2012 10:23:24 +0900 Subject: missing_pkexec error converted to "auto" error. idea is that we define user messages in the exceptions, and queue them during (conductor) checks. user facing dialogs get constucted from exception attrs. if critical, log as such and exit. --- src/leap/eip/eipconnection.py | 38 +++++++++++++---------- src/leap/eip/exceptions.py | 64 +++++++++++++++++++++------------------ src/leap/eip/openvpnconnection.py | 16 +++++++--- 3 files changed, 67 insertions(+), 51 deletions(-) (limited to 'src/leap/eip') diff --git a/src/leap/eip/eipconnection.py b/src/leap/eip/eipconnection.py index 3a6f4d49..e090f9a7 100644 --- a/src/leap/eip/eipconnection.py +++ b/src/leap/eip/eipconnection.py @@ -3,6 +3,7 @@ EIP Connection Class """ from __future__ import (absolute_import,) import logging +import Queue from leap.eip.checks import EIPConfigChecker from leap.eip import exceptions as eip_exceptions @@ -23,8 +24,8 @@ class EIPConnection(OpenVPNConnection): self.settingsfile = kwargs.get('settingsfile', None) self.logfile = kwargs.get('logfile', None) - # not used atm. but should. - self.error_queue = [] + # XXX USE THIS + self.error_queue = Queue.Queue() status_signals = kwargs.pop('status_signals', None) self.status = EIPConnectionStatus(callbacks=status_signals) @@ -36,7 +37,12 @@ class EIPConnection(OpenVPNConnection): """ run all eip checks previous to attempting a connection """ - self.config_checker.run_all(skip_download=skip_download) + logger.debug('running conductor checks') + try: + self.config_checker.run_all(skip_download=skip_download) + self.run_openvpn_checks() + except Exception as exc: + self.error_queue.put(exc) def connect(self): """ @@ -44,7 +50,6 @@ class EIPConnection(OpenVPNConnection): """ self.forget_errors() self._try_connection() - # XXX should capture errors? def disconnect(self): """ @@ -65,11 +70,11 @@ class EIPConnection(OpenVPNConnection): """ return self.status.current - def desired_connection_state(self): - """ - returns the desired_connection state - """ - return self.desired_con_state + #def desired_connection_state(self): + #""" + #returns the desired_connection state + #""" + #return self.desired_con_state def poll_connection_state(self): """ @@ -107,26 +112,27 @@ class EIPConnection(OpenVPNConnection): private method for disconnecting """ if self.subp is not None: + logger.debug('disconnecting...') self.subp.terminate() self.subp = None - # XXX signal state changes! :) - def _is_alive(self): - """ - don't know yet - """ - pass + #def _is_alive(self): + #""" + #don't know yet + #""" + #pass def _connect(self): """ entry point for connection cascade methods. """ - #conn_result = ConState.DISCONNECTED try: conn_result = self._try_connection() except eip_exceptions.UnrecoverableError as except_msg: logger.error("FATAL: %s" % unicode(except_msg)) conn_result = self.status.UNRECOVERABLE + + # XXX enqueue exceptions themselves instead? except Exception as except_msg: self.error_queue.append(except_msg) logger.error("Failed Connection: %s" % diff --git a/src/leap/eip/exceptions.py b/src/leap/eip/exceptions.py index 19a0e707..a30cd2a6 100644 --- a/src/leap/eip/exceptions.py +++ b/src/leap/eip/exceptions.py @@ -1,68 +1,72 @@ -class EIPNoCommandError(Exception): - pass - - -class ConnectionError(Exception): - """ - generic connection error - """ - pass - - class EIPClientError(Exception): """ base EIPClient exception """ - def __str__(self): - if len(self.args) >= 1: - return repr(self.args[0]) - else: - return ConnectionError + # Should inherit from LeapException + # and move basic attrs there + critical = False + + #def __str__(self): + #if len(self.args) >= 1: + #return repr(self.args[0]) + #else: + #return ConnectionError -class UnrecoverableError(EIPClientError): +class CriticalError(EIPClientError): """ we cannot do anything about it, sorry """ - # XXX we should catch this and raise - # to qtland, so we emit signal - # to translate whatever kind of error - # to user-friendly msg in dialog. - pass + critical = True -class MissingSocketError(Exception): +class EIPNoPolkitAuthAgentAvailable(CriticalError): + message = "No polkit authentication agent could be found" + usermessage = ("We could not find any authentication " + "agent in your system.
" + "Make sure you have " + "polkit-gnome-authentication-agent-1 " + "running and try again.") + +# Errors needing some work + + +class EIPNoPkexecAvailable(Exception): pass -class ConnectionRefusedError(Exception): +class EIPInitNoProviderError(Exception): pass -class EIPNoPkexecAvailable(Exception): +class EIPInitBadProviderError(Exception): pass -class EIPNoPolkitAuthAgentAvailable(Exception): +class EIPInitNoKeyFileError(Exception): pass -class EIPInitNoProviderError(Exception): +class EIPInitBadKeyFilePermError(Exception): pass -class EIPInitBadProviderError(Exception): +class EIPNoCommandError(Exception): pass +# Errors that probably we don't need anymore -class EIPInitNoKeyFileError(Exception): + +class MissingSocketError(Exception): pass -class EIPInitBadKeyFilePermError(Exception): +class ConnectionRefusedError(Exception): pass + + class EIPMissingDefaultProvider(Exception): pass diff --git a/src/leap/eip/openvpnconnection.py b/src/leap/eip/openvpnconnection.py index 48252e10..4a6a495a 100644 --- a/src/leap/eip/openvpnconnection.py +++ b/src/leap/eip/openvpnconnection.py @@ -22,7 +22,6 @@ class OpenVPNConnection(Connection): All related to invocation of the openvpn binary """ - # Connection Methods def __init__(self, config_file=None, watcher_cb=None, @@ -45,7 +44,6 @@ to be triggered for each one of them. """ logger.debug('init openvpn connection') self.debug = debug - #print('conductor:%s' % debug) self.config_file = config_file self.watcher_cb = watcher_cb @@ -58,15 +56,18 @@ to be triggered for each one of them. self.port = None self.proto = None + ################################## # XXX move all error messages # into a more encapsulated object. self.missing_pkexec = False self.missing_auth_agent = False + self.bad_keyfile_perms = False self.missing_vpn_keyfile = False self.missing_provider = False self.missing_definition = False self.bad_provider = False + ################################# #XXX workaround for signaling #the ui that we don't know how to @@ -78,9 +79,6 @@ to be triggered for each one of them. # XXX get autostart from config self.autostart = True - #self._get_or_create_config() - self._set_ovpn_command() - self._check_vpn_keys() # # management init methods @@ -96,6 +94,11 @@ to be triggered for each one of them. self.port = port self.password = password + def run_openvpn_checks(self): + logger.debug('running openvpn checks') + self._set_ovpn_command() + self._check_vpn_keys() + def _set_ovpn_command(self): # XXX check also for command-line --command flag try: @@ -103,10 +106,13 @@ to be triggered for each one of them. debug=self.debug) except eip_exceptions.EIPNoPolkitAuthAgentAvailable: command = args = None + # XXX deprecate self.missing_auth_agent = True + raise except eip_exceptions.EIPNoPkexecAvailable: command = args = None self.missing_pkexec = True + raise # XXX if not command, signal error. self.command = command -- cgit v1.2.3