diff --git a/radicale/auth/__init__.py b/radicale/auth/__init__.py index d8f35e83..fc453a84 100644 --- a/radicale/auth/__init__.py +++ b/radicale/auth/__init__.py @@ -30,8 +30,8 @@ Take a look at the class ``BaseAuth`` if you want to implement your own. """ import hashlib -import time import threading +import time from typing import Sequence, Set, Tuple, Union, final from radicale import config, types, utils @@ -89,7 +89,7 @@ class BaseAuth: # cache_successful_logins self._cache_logins = configuration.get("auth", "cache_logins") self._type = configuration.get("auth", "type") - if (self._type in [ "dovecot", "ldap", "htpasswd" ]) or (self._cache_logins is False): + if (self._type in ["dovecot", "ldap", "htpasswd"]) or (self._cache_logins is False): logger.info("auth.cache_logins: %s", self._cache_logins) else: logger.info("auth.cache_logins: %s (but not required for type '%s' and disabled therefore)", self._cache_logins, self._type) diff --git a/radicale/auth/htpasswd.py b/radicale/auth/htpasswd.py index a5f46f93..e4c420cd 100644 --- a/radicale/auth/htpasswd.py +++ b/radicale/auth/htpasswd.py @@ -48,12 +48,12 @@ When bcrypt is installed: """ -import os -import time import functools import hmac +import os import threading -from typing import Any +import time +from typing import Any, Tuple from passlib.hash import apr_md5_crypt, sha256_crypt, sha512_crypt @@ -66,9 +66,9 @@ class Auth(auth.BaseAuth): _encoding: str _htpasswd: dict # login -> digest _htpasswd_mtime_ns: int - _htpasswd_size: bytes + _htpasswd_size: int _htpasswd_ok: bool - _htpasswd_not_ok_seconds: int + _htpasswd_not_ok_time: float _htpasswd_not_ok_reminder_seconds: int _htpasswd_bcrypt_use: int _has_bcrypt: bool @@ -154,7 +154,7 @@ class Auth(auth.BaseAuth): # assumed plaintext return self._plain(hash_value, password) - def _read_htpasswd(self, init: bool) -> (bool, int): + def _read_htpasswd(self, init: bool) -> Tuple[bool, int]: """Read htpasswd file init == True: stop on error @@ -168,6 +168,7 @@ class Auth(auth.BaseAuth): else: info = "Re-read" logger.info("%s content of htpasswd file start: %r", info, self._filename) + htpasswd: dict[str, str] htpasswd = dict() try: with open(self._filename, encoding=self._encoding) as f: @@ -179,7 +180,7 @@ class Auth(auth.BaseAuth): line = line.rstrip("\n") if line.lstrip() and not line.lstrip().startswith("#"): try: - login, digest = line.split( ":", maxsplit=1) + login, digest = line.split(":", maxsplit=1) skip = False if login == "" or digest == "": if init is True: @@ -216,7 +217,7 @@ class Auth(auth.BaseAuth): if init is True: raise RuntimeError("Failed to load htpasswd file %r: %s" % (self._filename, e)) from e else: - logger.warning("Failed to load htpasswd file on re-read: %r" % (self._filename, e)) + logger.warning("Failed to load htpasswd file on re-read: %r" % self._filename) htpasswd_ok = False else: self._htpasswd_size = os.stat(self._filename).st_size