Loading ccserver/conf.py +2 −27 Original line number Diff line number Diff line Loading @@ -56,8 +56,7 @@ class CCConf(object): CONF_TEMPLATE = {'password': None, 'role': None, 'tags': {}, 'rights': [], 'enabled': True} 'rights': []} RE_SALTPW = re.compile(r'{(?P<method>[A-Z]+)}(?P<password>.+)') Loading Loading @@ -208,7 +207,7 @@ class CCConf(object): passwd_conf = conf['password'] # Check if account password is disabled or if account is disabled: if passwd_conf is None or not conf.get('enabled'): if passwd_conf is None: return None is_valid = False Loading Loading @@ -341,30 +340,6 @@ class CCConf(object): rights.insert(index, rule) self._set_conf(login, conf) @_writer def set_enabled(self, login, enable=True): ''' Disable or enable the provided account. :param login: the login of the account to disable. ''' conf = self._get_conf(login) conf['enabled'] = enable self._set_conf(login, conf) @_writer def disable(self, login): ''' Disable an existing account without deleting it. :param login: the login of the account to disable. ''' conf = self._get_conf(login) conf['enabled'] = False self._set_conf(login, conf) @_writer def remove_right(self, login, index): ''' Loading ccserver/handlers.py +12 −2 Original line number Diff line number Diff line Loading @@ -187,7 +187,7 @@ class ClientHandler(OnlineCCHandler): if 'a' not in obj: raise BadObjectError('All objects must have the "a" tag.') for obj in objects: self._server.conf.set_enabled(obj['a'], enable=False) self._server.conf.add_tag(obj['a'], 'close', 'yes') @listed def declose(self, conn, query): Loading @@ -200,7 +200,7 @@ class ClientHandler(OnlineCCHandler): if 'a' not in obj: raise BadObjectError('All objects must have the "a" tag.') for obj in objects: self._server.conf.set_enabled(obj['a'], enable=True) self._server.conf.remove_tag(obj['a'], 'close') @listed def kill(self, conn, query): Loading Loading @@ -279,12 +279,22 @@ class WelcomeHandler(CCHandler): ''' Authenticate the client. ''' conf = self._server.conf conf.acquire() try: role = self._server.conf.authentify(login, password) except CCConf.UnknownAccount: conf.release() raise AuthenticationError('Unknown login') else: if 'close' in self._server.conf.show(login)['tags']: conf.release() raise AuthenticationError('Account is closed') if role is None: logging.info('New authentication from %s: ' 'failure' % login.encode('ascii', 'ignore')) raise AuthenticationError('Bad login/password') else: # If authentication is a success, try to register the client: Loading Loading
ccserver/conf.py +2 −27 Original line number Diff line number Diff line Loading @@ -56,8 +56,7 @@ class CCConf(object): CONF_TEMPLATE = {'password': None, 'role': None, 'tags': {}, 'rights': [], 'enabled': True} 'rights': []} RE_SALTPW = re.compile(r'{(?P<method>[A-Z]+)}(?P<password>.+)') Loading Loading @@ -208,7 +207,7 @@ class CCConf(object): passwd_conf = conf['password'] # Check if account password is disabled or if account is disabled: if passwd_conf is None or not conf.get('enabled'): if passwd_conf is None: return None is_valid = False Loading Loading @@ -341,30 +340,6 @@ class CCConf(object): rights.insert(index, rule) self._set_conf(login, conf) @_writer def set_enabled(self, login, enable=True): ''' Disable or enable the provided account. :param login: the login of the account to disable. ''' conf = self._get_conf(login) conf['enabled'] = enable self._set_conf(login, conf) @_writer def disable(self, login): ''' Disable an existing account without deleting it. :param login: the login of the account to disable. ''' conf = self._get_conf(login) conf['enabled'] = False self._set_conf(login, conf) @_writer def remove_right(self, login, index): ''' Loading
ccserver/handlers.py +12 −2 Original line number Diff line number Diff line Loading @@ -187,7 +187,7 @@ class ClientHandler(OnlineCCHandler): if 'a' not in obj: raise BadObjectError('All objects must have the "a" tag.') for obj in objects: self._server.conf.set_enabled(obj['a'], enable=False) self._server.conf.add_tag(obj['a'], 'close', 'yes') @listed def declose(self, conn, query): Loading @@ -200,7 +200,7 @@ class ClientHandler(OnlineCCHandler): if 'a' not in obj: raise BadObjectError('All objects must have the "a" tag.') for obj in objects: self._server.conf.set_enabled(obj['a'], enable=True) self._server.conf.remove_tag(obj['a'], 'close') @listed def kill(self, conn, query): Loading Loading @@ -279,12 +279,22 @@ class WelcomeHandler(CCHandler): ''' Authenticate the client. ''' conf = self._server.conf conf.acquire() try: role = self._server.conf.authentify(login, password) except CCConf.UnknownAccount: conf.release() raise AuthenticationError('Unknown login') else: if 'close' in self._server.conf.show(login)['tags']: conf.release() raise AuthenticationError('Account is closed') if role is None: logging.info('New authentication from %s: ' 'failure' % login.encode('ascii', 'ignore')) raise AuthenticationError('Bad login/password') else: # If authentication is a success, try to register the client: Loading