Quick fix for crash in cyruslib
Rand Druid
RandDruid at mail.ru
Thu Feb 13 05:59:02 CET 2014
Hello!
I manage to walkaround one problem in cyruslib and would to share solution.
Sometimes, when I try to execute commands like [kolab add-user-subscription
name.surname at example.com "Other Users/something.else"],
I receive this error:
Traceback (most recent call last):
File "/usr/sbin/kolab", line 39, in <module>
kolab = Cli()
File "/usr/lib/python2.7/dist-packages/pykolab/cli/__init__.py", line 64,
in __init__
commands.execute('_'.join(to_execute))
File "/usr/lib/python2.7/dist-packages/pykolab/cli/commands.py", line 139,
in execute
commands[cmd_name]['function'](conf.cli_args, kw)
File
"/usr/lib/python2.7/dist-packages/pykolab/cli/cmd_add_user_subscription.py",
line 68, in execute
imap.login_plain(admin_login, admin_password, user)
File "/usr/lib/python2.7/dist-packages/cyruslib.py", line 431, in
login_plain
res, msg = self.__docommand("login_plain", username, password, asUser)
File "/usr/lib/python2.7/dist-packages/cyruslib.py", line 391, in
__docommand
self.__doexception(function, error, *args)
File "/usr/lib/python2.7/dist-packages/cyruslib.py", line 360, in
__doexception
self.__doraise( function.upper(), msg )
File "/usr/lib/python2.7/dist-packages/cyruslib.py", line 369, in
__doraise
raise CYRUSError( idError[0], mode, msg )
cyruslib.CYRUSError: (16, 'LOGIN_PLAIN', 'Unexpected extra arguments to
Authenticate')
The strange thing is that I receive it only for some accounts, identical on
everything, except name.
After digging in python code, I found out, that in cyruslib.py, in function
"login_plain", arguments are Base64 encoded, before they sent to functions
in parent class in imaplib.py. Functions in imaplib.py make some
formatting, including escaping and quoting.
Finally, if our Base64 encoded parameter have "=" at the end, things got
screwed up. And since Base64 padded with "=", it happens quite often.
I come up with little hack to cyruslib.py. I insert spaces in front of user
name. I am sure, bright heads in Kolab will find better way, but this worked
for me:
(Be careful editing python files, do not mix tabs and spaces)
Old version (line 272):
def login_plain(self, admin, password, asUser):
if asUser:
encoded = b2a_base64("%s\0%s\0%s" % (asUser, admin,
password)).strip()
else:
encoded = b2a_base64("%s\0%s\0%s" % (admin, admin,
password)).strip()
res, data = self._simple_command('AUTHENTICATE', 'PLAIN', encoded)
if ok(res):
self.state = 'AUTH'
return res, data
New version:
def login_plain(self, admin, password, asUser):
if asUser:
encoded = b2a_base64("%s\0%s\0%s" % (asUser, admin,
password)).strip()
if encoded.endswith("="):
encoded = b2a_base64(" %s\0%s\0%s" % (asUser, admin,
password)).strip()
if encoded.endswith("="):
encoded = b2a_base64(" %s\0%s\0%s" % (asUser, admin,
password)).strip()
if encoded.endswith("="):
encoded = b2a_base64(" %s\0%s\0%s" % (asUser,
admin, password)).strip()
else:
encoded = b2a_base64("%s\0%s\0%s" % (admin, admin,
password)).strip()
if encoded.endswith("="):
encoded = b2a_base64(" %s\0%s\0%s" % (admin, admin,
password)).strip()
if encoded.endswith("="):
encoded = b2a_base64(" %s\0%s\0%s" % (admin, admin,
password)).strip()
if encoded.endswith("="):
encoded = b2a_base64(" %s\0%s\0%s" % (admin,
admin, password)).strip()
res, data = self._simple_command('AUTHENTICATE', 'PLAIN', encoded)
if ok(res):
self.state = 'AUTH'
return res, data
More information about the users
mailing list