return (radiusd.RLM_MODULE_UPDATED,
(('Session-Timeout', str(sessionTimeout)),),
(('Auth-Type', 'python'),))
-
-
+ # 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',
+ # ),
+ # 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):
sys.stdout.write(msg + '\n')
level = level
-
-
PyObject *pTupleElement = PyTuple_GET_ITEM(pValue, i);
PyObject *pStr1;
PyObject *pStr2;
+ PyObject *pOp;
int pairsize;
const char *s1;
const char *s2;
+ long Op;
if (!PyTuple_CheckExact(pTupleElement)) {
radlog(L_ERR, "rlm_python:%s: tuple element %d is not a tuple", funcname, i);
continue;
}
/* Check if it's a pair */
- if ((pairsize = PyTuple_GET_SIZE(pTupleElement)) != 2) {
- radlog(L_ERR, "rlm_python:%s: tuple element %d is a tuple of size %d. Must be 2", funcname, i, pairsize);
+
+ pairsize = PyTuple_GET_SIZE(pTupleElement);
+ if ((pairsize < 2) || (pairsize > 3)) {
+ radlog(L_ERR, "rlm_python:%s: tuple element %d is a tuple of size %d. Must be 2 or 3.", funcname, i, pairsize);
continue;
}
+
+ 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);
+ }
+
if ((!PyString_CheckExact(pStr1)) || (!PyString_CheckExact(pStr2))) {
radlog(L_ERR, "rlm_python:%s: tuple element %d must be as (str, str)", funcname, i);
continue;
}
s1 = PyString_AsString(pStr1);
s2 = PyString_AsString(pStr2);
- /* xxx Might need to support other T_OP */
- vp = pairmake(s1, s2, T_OP_EQ);
+ vp = pairmake(s1, s2, Op);
if (vp != NULL) {
pairadd(vpp, vp);
radlog(L_DBG, "rlm_python:%s: '%s' = '%s'", funcname, s1, s2);