Commit 77727c8e authored by Antoine Millet's avatar Antoine Millet
Browse files

Close/declose is now a tag.

parent a93e6df3
Loading
Loading
Loading
Loading
+2 −27
Original line number Diff line number Diff line
@@ -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>.+)')

@@ -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
@@ -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):
        '''
+12 −2
Original line number Diff line number Diff line
@@ -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):
@@ -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):
@@ -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: