Gnration de logs exploitables pour radius.
darcs-hash:20061125010944-68412-d11eedd0b3f282bb04ba3770d98e3df4594abc4e.gz
This commit is contained in:
parent
4df72aab9f
commit
00eb2945b8
1 changed files with 32 additions and 23 deletions
|
@ -3,6 +3,7 @@
|
||||||
|
|
||||||
import os, md5, sys, binascii
|
import os, md5, sys, binascii
|
||||||
from commands import getoutput
|
from commands import getoutput
|
||||||
|
from syslog import *
|
||||||
|
|
||||||
sys.path.append('/usr/scripts/gestion')
|
sys.path.append('/usr/scripts/gestion')
|
||||||
from ldap_crans import crans_ldap, AssociationCrans
|
from ldap_crans import crans_ldap, AssociationCrans
|
||||||
|
@ -26,42 +27,50 @@ def chap_ok(password, challenge, clear_pass) :
|
||||||
|
|
||||||
return False
|
return False
|
||||||
|
|
||||||
if __name__ == '__main__' :
|
def do_auth():
|
||||||
# Test chap (comme cela on est sur que c'est bien un switch qui demande)
|
# Test chap (comme cela on est sur que c'est bien un switch qui demande)
|
||||||
mac=os.getenv('USER_NAME','').replace('"','')
|
mac = os.getenv('USER_NAME', '').replace('"', '')
|
||||||
|
|
||||||
if not chap_ok(os.getenv('CHAP_PASSWORD'), os.getenv('CHAP_CHALLENGE'), mac) :
|
if not chap_ok(os.getenv('CHAP_PASSWORD'), os.getenv('CHAP_CHALLENGE'), mac):
|
||||||
sys.stdout.write("Echec test CHAP")
|
return (-1, "Échec test CHAP")
|
||||||
sys.exit(-1)
|
|
||||||
|
|
||||||
# Mac dans la base LDAP
|
# Mac dans la base LDAP
|
||||||
m=crans_ldap(readonly=True).search('mac=%s'%mac)['machine']
|
m = crans_ldap(readonly=True).search('mac=%s' % mac)['machine']
|
||||||
if len(m)!=1 :
|
if len(m) != 1:
|
||||||
sys.stdout.write("Pb recherche mac (nb résultat !=1)")
|
return (-1, "Pb recherche mac (nb résultat !=1)")
|
||||||
sys.exit(-1)
|
|
||||||
|
|
||||||
# N'appartient pas au Crans et n'a pas de prise attribuée
|
# N'appartient pas au Crans et n'a pas de prise attribuée
|
||||||
# donc sur uplink ou switch non filtré
|
# donc sur uplink ou switch non filtré
|
||||||
# But : éviter le spoof d'une mac d'une machine clef
|
# But : éviter le spoof d'une mac d'une machine clef
|
||||||
proprio=m[0].proprietaire()
|
proprio = m[0].proprietaire()
|
||||||
if proprio.__class__ == AssociationCrans and m[0].prise() == u'N/A' :
|
if proprio.__class__ == AssociationCrans and m[0].prise() == u'N/A':
|
||||||
sys.stdout.write("Machine du crans")
|
return (-1, "Machine du crans")
|
||||||
sys.exit(-1)
|
|
||||||
|
|
||||||
# blockliste bloq
|
# blockliste bloq
|
||||||
if 'bloq' in m[0].blacklist_actif():
|
if 'bloq' in m[0].blacklist_actif():
|
||||||
sys.stdout.write("Bloquage total des services pour cette machine")
|
return (-1, "Bloquage total des services pour cette machine")
|
||||||
sys.exit(-1)
|
|
||||||
|
|
||||||
# Paiment ok ?
|
# Paiment ok ?
|
||||||
paid=max(proprio.paiement()+[0])
|
paid = max(proprio.paiement() + [0])
|
||||||
if dat[1]==9 :
|
if dat[1] == 9:
|
||||||
# En septembre les anciennes adhésion sont OK
|
# En septembre les anciennes adhésions sont OK
|
||||||
ann_scol -= 1
|
ann_scol -= 1
|
||||||
if ann_scol > paid :
|
if ann_scol > paid:
|
||||||
sys.stdout.write("Echec test LDAP")
|
return (-1, "Échec test LDAP")
|
||||||
sys.exit(-1)
|
|
||||||
|
|
||||||
# C'est bon
|
# C'est bon
|
||||||
sys.stdout.write("Acces OK")
|
return (0, "Accès OK")
|
||||||
sys.exit(0)
|
|
||||||
|
if __name__ == '__main__' :
|
||||||
|
# On vérifie si la mac est autorisée
|
||||||
|
(r, msg) = do_auth()
|
||||||
|
|
||||||
|
# On logue la prise sur laquelle a lieu la tentative
|
||||||
|
openlog("radius_auth.py")
|
||||||
|
switch = os.getenv("NAS_IDENTIFIER", "").replace('"', '')
|
||||||
|
prise = (len(switch) == 6 and (switch[3] + switch[5]) or (switch + "-"))
|
||||||
|
prise += "%02d" % int(os.getenv("NAS_PORT", 0))
|
||||||
|
syslog("%s -> %s [%s]" % (prise, mac, msg))
|
||||||
|
|
||||||
|
pring msg
|
||||||
|
sys.exit(r)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue