1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
|
#! /usr/bin/env python3
import radiusd
def get_attribute(p, attribute):
return [x[1] for x in p if x[0] == attribute][0]
def instantiate(p):
radiusd.radlog(radiusd.L_INFO, '*** example.py instantiate ***')
return radiusd.RLM_MODULE_OK
def authorize(p):
radiusd.radlog(radiusd.L_INFO, '*** example.py authorize ***')
# whatever password was supplied
config = ( ('Cleartext-Password', get_attribute(p, 'User-Password')), )
if get_attribute(p, 'User-Name') == "ubuntu":
msg = "Hello ubuntu!"
status = radiusd.RLM_MODULE_OK
reply = ( ('Reply-Message', msg), )
return (radiusd.RLM_MODULE_OK, reply, config)
else:
msg = "You are not ubuntu!"
reply = ( ('Reply-Message', msg), )
status = radiusd.RLM_MODULE_REJECT
return (status, reply, config)
def detach(p):
radiusd.radlog(radiusd.L_INFO, "*** example.py detach ***")
return radiusd.RLM_MODULE_OK
|