]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
Add different operators handle to rlm_python
authorMetasov <metasov@gmail.com>
Fri, 14 Oct 2011 14:49:23 +0000 (17:49 +0300)
committerArran Cudbard-Bell <a.cudbardb@freeradius.org>
Mon, 15 Oct 2012 20:44:32 +0000 (21:44 +0100)
src/modules/rlm_python/prepaid.py
src/modules/rlm_python/radiusd.py
src/modules/rlm_python/rlm_python.c

index aae1c83d0ffd9bc3ff6d85998af36d43a96c591e..c08876ab4a77dbb1c29ff977745e860eb96c6318 100644 (file)
@@ -158,8 +158,18 @@ def authorize(authData):
   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
index 08a1aa02db9b30aced031dca603c76d991b6e4d7..87c9b64dafecee1cf672e5a527b6a8a3d2eedd67 100644 (file)
@@ -32,6 +32,21 @@ L_ERR = 4
 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):
@@ -39,7 +54,5 @@ def radlog(level, msg):
     sys.stdout.write(msg + '\n')
 
     level = level
-  
 
 
-  
index 7030323aca3e8f3e3957cfab6a828ddb00d02539..5d8f0b217fe289eaf7463b265426a7a74fa4c53b 100644 (file)
@@ -271,29 +271,42 @@ static void python_vptuple(VALUE_PAIR **vpp, PyObject *pValue,
                 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);