# If you want to use different operators
# you can do
# return (radiusd.RLM_MODULE_UPDATED,
- # radiusd.resolve(
- # 'Session-Timeout := %s' % str(sessionTimeout),
- # 'Some-other-option -= Value',
+ # (
+ # ('Session-Timeout', ':=', str(sessionTimeout)),
+ # ('Some-other-option', '-=', Value'),
+ # ),
+ # (
+ # ('Auth-Type', ':=', 'python'),
# ),
- # radiusd.resolve(
- # 'Auth-Type := python'
- # )
# )
- # Edit operators you need in OP_TRY in radiusd.py
def authenticate(p):
p = p
L_PROXY = 5
L_CONS = 128
-OP={ '{':2, '}':3, '(':4, ')':5, ',':6, ';':7, '+=':8, '-=':9, ':=':10,
- '=':11, '!=':12, '>=':13, '>':14, '<=':15, '<':16, '=~':17, '!~':18, '=*':19, '!*':20,
- '==':21 , '#':22 }
-
-OP_TRY = (':=', '+=', '-=', '=' )
-
-def resolve(*lines):
- tuples = []
- for line in lines:
- for op in OP_TRY:
- arr = line.rsplit(op)
- if len(arr)==2:
- tuples.append((str(arr[0].strip()),OP[op],str(arr[1].strip())))
- break
- return tuple(tuples)
-
# log function
def radlog(level, msg):
import sys
int pairsize;
char const *s1;
char const *s2;
- FR_TOKEN op;
+ FR_TOKEN op = T_OP_EQ;
if (!PyTuple_CheckExact(pTupleElement)) {
ERROR("rlm_python:%s: tuple element %d of %s is not a tuple", funcname, i, list_name);
if (pairsize == 2) {
pStr1 = PyTuple_GET_ITEM(pTupleElement, 0);
pStr2 = PyTuple_GET_ITEM(pTupleElement, 1);
- op = T_OP_EQ;
} else {
pStr1 = PyTuple_GET_ITEM(pTupleElement, 0);
pStr2 = PyTuple_GET_ITEM(pTupleElement, 2);
- pOp = PyTuple_GET_ITEM(pTupleElement, 1);
- op = PyInt_AsLong(pOp);
+ pOp = PyTuple_GET_ITEM(pTupleElement, 1);
+ if (PyInt_Check(pOp)) {
+ op = PyInt_AsLong(pOp);
+ if (!fr_int2str(fr_tokens, op, NULL)) {
+ ERROR("rlm_python:%s: Invalid operator '%i', falling back to '='", funcname, op);
+ op = T_OP_EQ;
+ }
+ } else if (PyString_CheckExact(pOp)) {
+ if (!(op = fr_str2int(fr_tokens, PyString_AsString(pOp), 0))) {
+ ERROR("rlm_python:%s: Invalid operator '%s', falling back to '='", funcname, PyString_AsString(pOp));
+ op = T_OP_EQ;
+ }
+ } else {
+ ERROR("rlm_python:%s: Invalid operator type, using default '='", funcname);
+ }
}
if ((!PyString_CheckExact(pStr1)) || (!PyString_CheckExact(pStr2))) {