diff --git a/auth.py b/auth.py index 41fdbad..b91fbdb 100644 --- a/auth.py +++ b/auth.py @@ -159,9 +159,20 @@ def authorize(data): nas_type = data_from_api["nas"] user = data_from_api["user"] - if not nas_type or nas_type and nas_type["port_access_mode"] == "802.1X": - password = user.get("pwd_ntlm", "") - logger.info(username.encode("utf-8")) + if not nas_type or (nas_type and nas_type["port_access_mode"]) == "802.1X": + + # The user doesn't exist + if not user: + logger.info("User \"{0}\" does not exist, reject".format(username)) + return radiusd.RLM_MODULE_REJECT + + password = user.get("pwd_ntlm", None) + + if not password: + logger.info("User \"{0}\" doesn't have a NTLM password, reject".format(username)) + return radiusd.RLM_MODULE_REJECT + + logger.info("User \"{0}\" accepted in authorize".format(username)) return ( radiusd.RLM_MODULE_UPDATED, @@ -249,8 +260,8 @@ def post_auth(data): result, log = check_user_machine_and_register( nas_type, user, user_interface, nas, username, mac) - logger.info(log.encode("utf-8")) - logger.info(username.encode("utf-8")) + logger.info(log) + logger.info(username) if not result: return radiusd.RLM_MODULE_REJECT