
adherent -> Adherent club -> Club darcs-hash:20060325215156-68412-615c1bfb3b23e16cd10b82cc3dc467e716c258ea.gz
62 lines
1.9 KiB
Python
Executable file
62 lines
1.9 KiB
Python
Executable file
#! /usr/bin/env python
|
|
# -*- coding: iso-8859-15 -*-
|
|
|
|
import os, md5, sys, binascii
|
|
from commands import getoutput
|
|
|
|
sys.path.append('/usr/scripts/gestion')
|
|
from ldap_crans import crans_ldap, AssociationCrans
|
|
from config import ann_scol, dat
|
|
|
|
def chap_ok(password, challenge, clear_pass) :
|
|
""" Test l'authentification chap fournie
|
|
password et chalenge doivent être données
|
|
en hexa (avec ou sans le 0x devant)
|
|
|
|
retourne True si l'authentification est OK
|
|
retourne False sinon
|
|
"""
|
|
try :
|
|
challenge = binascii.a2b_hex(challenge.replace('0x',''))
|
|
password = binascii.a2b_hex(password.replace('0x',''))
|
|
if md5.new(password[0] + clear_pass + challenge).digest() == password[1:] :
|
|
return True
|
|
except :
|
|
pass
|
|
|
|
return False
|
|
|
|
if __name__ == '__main__' :
|
|
# Test chap (comme cela on est sur que c'est bien un switch qui demande)
|
|
mac=os.getenv('USER_NAME','').replace('"','')
|
|
|
|
if not chap_ok(os.getenv('CHAP_PASSWORD'), os.getenv('CHAP_CHALLENGE'), mac) :
|
|
sys.stdout.write("Echec test CHAP")
|
|
sys.exit(-1)
|
|
|
|
# Mac dans la base LDAP
|
|
m=crans_ldap(readonly=True).search('mac=%s'%mac)['machine']
|
|
if len(m)!=1 :
|
|
sys.stdout.write("Pb recherche mac (nb résultat !=1)")
|
|
sys.exit(-1)
|
|
|
|
# N'appartient pas au Crans et n'a pas de prise attribuée
|
|
# donc sur uplink ou switch non filtré
|
|
# But : éviter le spoof d'une mac d'une machine clef
|
|
proprio=m[0].proprietaire()
|
|
if proprio.__class__ == AssociationCrans and m[0].prise() == u'N/A' :
|
|
sys.stdout.write("Machine du crans")
|
|
sys.exit(-1)
|
|
|
|
# Paiment ok ?
|
|
paid=max(proprio.paiement()+[0])
|
|
if dat[1]==9 :
|
|
# En septembre les anciennes adhésion sont OK
|
|
ann_scol -= 1
|
|
if ann_scol > paid :
|
|
sys.stdout.write("Echec test LDAP")
|
|
sys.exit(-1)
|
|
|
|
# C'est bon
|
|
sys.stdout.write("Acces OK")
|
|
sys.exit(0)
|