From: Jelte Jansen Date: Wed, 16 Jan 2013 14:43:27 +0000 (+0100) Subject: [2595] Better error reporting on failed login in bindctl X-Git-Tag: bind10-1.0.0-rc-release~76^2~8^2~4^2~1^2~10 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=d4d5c0ee659e6ecfb3e3384f2462a58559464f80;p=thirdparty%2Fkea.git [2595] Better error reporting on failed login in bindctl If the connection is reset, it is likely there is an SSL problem, so report that. Also a tiny refactor for the common login code in login_to_cmdctl() --- diff --git a/src/bin/bindctl/bindcmd.py b/src/bin/bindctl/bindcmd.py index 7c2b2af7dd..2bf8f4730c 100644 --- a/src/bin/bindctl/bindcmd.py +++ b/src/bin/bindctl/bindcmd.py @@ -39,6 +39,7 @@ import csv import pwd import getpass import copy +import errno try: from collections import OrderedDict @@ -207,6 +208,18 @@ WARNING: Python readline module isn't available, so the command line editor return True + def __try_login(self, username, password): + param = {'username': username, 'password' : password} + try: + return self.send_POST('/login', param) + except socket.error as err: + print("Socket error while sending login information: ", err) + if err.errno == errno.ECONNRESET: + print("Please check the logs of b10-cmdctl, there may be a " + "problem accepting SSL connections, such as a " + "permission problem on the server certificate file.") + raise FailToLogin() + def login_to_cmdctl(self): '''Login to cmdctl with the username and password given by the user. After the login is sucessful, the username and @@ -217,14 +230,8 @@ WARNING: Python readline module isn't available, so the command line editor # Look at existing username/password combinations and try to log in users = self._get_saved_user_info(self.csv_file_dir, CSV_FILE_NAME) for row in users: - param = {'username': row[0], 'password' : row[1]} - try: - response = self.send_POST('/login', param) - data = response.read().decode() - except socket.error as err: - print("Socket error while sending login information:", err) - raise FailToLogin() - + response = self.__try_login(row[0], row[1]) + data = response.read().decode() if response.status == http.client.OK: # Is interactive? if sys.stdin.isatty(): @@ -244,14 +251,10 @@ WARNING: Python readline module isn't available, so the command line editor username = input("Username: ") passwd = getpass.getpass() - param = {'username': username, 'password' : passwd} - try: - response = self.send_POST('/login', param) - data = response.read().decode() - print(data) - except socket.error as err: - print("Socket error while sending login information:", err) - raise FailToLogin() + + response = self.__try_login(username, passwd) + data = response.read().decode() + print(data) if response.status == http.client.OK: self._save_user_info(username, passwd, self.csv_file_dir,