auth.py: proprification légère
This commit is contained in:
parent
a0f0c80ead
commit
4205d73132
1 changed files with 23 additions and 19 deletions
|
@ -1,9 +1,14 @@
|
|||
# ⁻*- coding: utf-8 -*-
|
||||
#
|
||||
# Ce fichier contient la définition de plusieurs fonctions d'interface à freeradius
|
||||
# qui peuvent être appelées (suivant les configurations) à certains moment de
|
||||
# l'éxécution.
|
||||
#
|
||||
"""
|
||||
Backend python pour freeradius.
|
||||
|
||||
Ce fichier contient la définition de plusieurs fonctions d'interface à
|
||||
freeradius qui peuvent être appelées (suivant les configurations) à certains
|
||||
moment de l'authentification, en WiFi, filaire, ou par les NAS eux-mêmes.
|
||||
|
||||
Inspirés d'autres exemples trouvés ici :
|
||||
https://github.com/FreeRADIUS/freeradius-server/blob/master/src/modules/rlm_python/
|
||||
"""
|
||||
|
||||
import logging
|
||||
import netaddr
|
||||
|
@ -91,8 +96,6 @@ def radius_event(fun):
|
|||
et autres trucs du genre)
|
||||
* un tuple de couples (clé, valeur) pour les valeurs internes à mettre à
|
||||
jour (mot de passe par exemple)
|
||||
Voir des exemples plus complets ici:
|
||||
https://github.com/FreeRADIUS/freeradius-server/blob/master/src/modules/rlm_python/
|
||||
|
||||
On se contente avec ce décorateur (pour l'instant) de convertir la liste de
|
||||
tuples en entrée en un dictionnaire."""
|
||||
|
@ -105,8 +108,8 @@ def radius_event(fun):
|
|||
data[key] = value.replace('"', '')
|
||||
try:
|
||||
return fun(data)
|
||||
except Exception as e:
|
||||
logger.error(repr(e) + ' on data ' + repr(auth_data))
|
||||
except Exception as err:
|
||||
logger.error('Failed %r on data %r' % (err, auth_data))
|
||||
raise
|
||||
|
||||
return new_f
|
||||
|
@ -189,7 +192,7 @@ def get_prise_chbre(data):
|
|||
try:
|
||||
bat_name = nas[3].upper()
|
||||
bat_num = int(nas.split('-', 1)[1])
|
||||
except IndexError, ValueError:
|
||||
except (IndexError, ValueError):
|
||||
pass
|
||||
port = data.get('NAS-Port', None)
|
||||
if port:
|
||||
|
@ -215,12 +218,12 @@ def realm_of_machine(machine):
|
|||
|
||||
def get_fresh_rid(machine):
|
||||
"""Génère un rid tout frais pour la machine. Fonction kludge"""
|
||||
lockId = machine.conn.lockholder.newid()
|
||||
lock_id = machine.conn.lockholder.newid()
|
||||
realm = realm_of_machine(machine)
|
||||
try:
|
||||
return machine.conn._find_id('rid', realm, lockId)
|
||||
return machine.conn._find_id('rid', realm, lock_id)
|
||||
finally:
|
||||
machine.conn.lockholder.purge(lockId)
|
||||
machine.conn.lockholder.purge(lock_id)
|
||||
|
||||
@use_ldap_admin
|
||||
def register_machine(data, machine, conn):
|
||||
|
@ -236,7 +239,7 @@ def register_machine(data, machine, conn):
|
|||
mac = mac.decode('ascii', 'ignore').replace('"','')
|
||||
try:
|
||||
mac = lc_ldap.crans_utils.format_mac(mac).lower()
|
||||
except:
|
||||
except Exception:
|
||||
logger.warn('Cannot format MAC for registration (aborting)')
|
||||
return
|
||||
|
||||
|
@ -258,7 +261,7 @@ def register_machine(data, machine, conn):
|
|||
@radius_event
|
||||
@use_ldap_admin
|
||||
@use_ldap
|
||||
def instantiate(_, *conns):
|
||||
def instantiate(*_):
|
||||
"""Utile pour initialiser les connexions ldap une première fois (otherwise,
|
||||
do nothing)"""
|
||||
logger.info('Instantiation')
|
||||
|
@ -337,11 +340,11 @@ def authorize_fil(data):
|
|||
chap_ok = True
|
||||
else:
|
||||
logger.info("(fil) Chap wrong")
|
||||
except:
|
||||
logger.info("(fil) Chap challenge check failed")
|
||||
except Exception as err:
|
||||
logger.info("(fil) Chap challenge check failed with %r" % err)
|
||||
|
||||
if not chap_ok:
|
||||
if DEBUG:
|
||||
if TEST_SERVER:
|
||||
logger.debug('(fil) Continue auth (debug)')
|
||||
else:
|
||||
return radiusd.RLM_MODULE_REJECT
|
||||
|
@ -574,7 +577,8 @@ def decide_vlan(data, is_wifi, conn):
|
|||
return (port,) + decision
|
||||
|
||||
@radius_event
|
||||
def dummy_fun(p):
|
||||
def dummy_fun(_):
|
||||
"""Do nothing, successfully. (C'est pour avoir un truc à mettre)"""
|
||||
return radiusd.RLM_MODULE_OK
|
||||
|
||||
def detach(_=None):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue