offlineimap/offlineimap
Herton R. Krzesinski 6a25f1930c Fix stale gss api authentication security context
Inside __authn_gssapi function, the else clause is never executed
because the return statement in the try section, which means if there is
an error and a reconnect is tried, the authentication will now fail with
due the stale self.gss_vc value. For example, offlineimap will be
stuck after any socket error and unable to reconnect, even if I have a
valid kerberos ticket:

========================================================================
abort: command: FETCH => socket error: <type 'exceptions.IOError'> - Too many read 0

  command: FETCH => socket error: <type 'exceptions.IOError'> - Too many read 0
 GSSAPI authentication failed: AUTHENTICATE command error: BAD ['AUTHENTICATE aborted']. Data: BLMC2 AUTHENTICATE GSSAPI

Enter password for user 'XXX':
========================================================================

You can verify this try..finally behaviour with this slightly modified
example that I copied from python documentation:

>>> def divide(x, y):
...     try:
...         result = x / y
...         return 1
...     except ZeroDivisionError:
...         print("division by zero!")
...     else:
...         print("result is", result)
...     finally:
...         print("executing finally clause")
...
>>> divide(2, 1)
executing finally clause
1
>>>

The else section is never executed with a return inside try.

To fix the issue here, instead of relying on else clause, just clear
gss_vc always inside finally, and we don't need to handle any exception
to set self.gssapi, it can be left False by default and just set to True
after authentication is done.

I'm running with this fix and now offlineimap doesn't stop requiring manual
intervention, and succesfully re-authenticate after errors while fetching
data.

Signed-off-by: Herton R. Krzesinski <herton@gmail.com>
Signed-off-by: Nicolas Sebrecht <nicolas.s-dev@laposte.net>
2020-04-11 01:01:44 +02:00
..
folder Gmail: allow parenthesis in labels 2018-05-18 02:10:56 +02:00
repository Handle [ALREADYEXISTS] and Mailbox already exists! 2020-02-06 19:10:33 +01:00
ui Additional address for sysloghandler to handle mac 2019-10-12 19:58:44 +02:00
utils offlineimap/utilis/distro.py: identation fix 2018-08-17 18:49:04 +02:00
CustomConfig.py ConfigHelperMixin must be new-style class to not break inheritance 2016-07-30 04:26:25 +02:00
__init__.py v7.3.2 2019-12-17 20:01:18 +01:00
accounts.py export env. variables when running account hooks 2020-03-23 23:01:30 +01:00
bundled_imaplib2.py imaplib2 v2.101 2019-06-18 23:50:29 +02:00
emailutil.py Rename email.Parser to email.parser 2016-05-10 02:53:09 +02:00
error.py more consistent style 2015-01-07 21:31:43 +01:00
globals.py fix: when called with -a, mbnames must not erase entries of other accounts 2016-06-25 17:33:42 +02:00
imaplibutil.py exec() the tunnel command 2020-03-22 09:02:41 +01:00
imapserver.py Fix stale gss api authentication security context 2020-04-11 01:01:44 +02:00
imaputil.py utf8: Add utf-7/8 conversion functions 2017-10-02 21:09:43 +02:00
init.py Make CTRL-C message more clear 2018-05-01 16:21:57 +02:00
localeval.py minor code enhancements 2016-07-28 00:42:35 +02:00
mbnames.py mbnames: don't duplicate entries in autorefresh mode 2017-05-19 08:32:22 +02:00
threadutil.py fix the profile mode 2016-11-08 07:11:33 +01:00
virtual_imaplib2.py increase imaplib2 requirement from v2.55 to v2.57 2017-07-09 17:28:12 +02:00