rlm_python question...

i_amok i_amok iamokcn at gmail.com
Sat Apr 15 10:27:39 CEST 2006


why radius  say :

authorize: function call failed
exceptions.TypeError: unsubscriptable object


below is a modify radius_test.py

=====================================

# Miguel A.L. Paraz <mparaz at mparaz.com>

import radiusd
import MySQLdb

def instantiate(p):
  print "*** instantiate ***"
  print p

def authorize(p):
  print "*** authorize ***"
  print
  radiusd.radlog(radiusd.L_INFO, '*** radlog call in authorize ***')
  print
  print p

  dbHandle = MySQLdb.connect(db="radius", host="localhost", user="radius",
passwd="radius")

  userName = None
  userPasswd = None

  for t in p:
    if t[0] == 'User-Name':
      userName = t[1]
    elif t[0] == 'Password':
      userPasswd = t[1]

  sql = 'select value from radcheck where username = ' +  userName + ' limit
1'

  dbCursor = dbHandle.cursor()
  dbCursor.execute(sql)
  result = dbCursor.fetchone()

  if not result:
    dbCursor.close()
    return radiusd.RLM_MODULE_NOTFOUND

  if result[0] != userPasswd[1:-1]:
    return radiusd.RLM_MODULE_REJECT

  dbCursor.close()

  return (radiusd.RLM_MODULE_OK,
         (('Reply-Message', 'ok'),),
          (('Auth-Type', 'python'),))


def preacct(p):
  print "*** preacct ***"
  print p
  return radiusd.RLM_MODULE_OK

def accounting(p):
  print "*** accounting ***"
  radiusd.radlog(radiusd.L_INFO, '*** radlog call in accounting (0) ***')
  print
  print p
  return radiusd.RLM_MODULE_OK


def detach():
  print "*** goodbye from radiusd_test.py ***"
  return radiusd.RLM_MODULE_OK

======================================

and my python.conf

======================================

python {
                mod_instantiate = radiusd_test
                func_instantiate = instantiate

                mod_authorize = radiusd_test
                func_authorize = authorize

                mod_accounting = radiusd_test
                func_accounting = accounting

                mod_preacct = radiusd_test
                func_preacct = preacct

                mod_detach = radiusd_test
                func_detach = detach

        }



======================================





i had test original  radiusd_test ,it's work well,

but i add the sql query,it's dont work...

and i also test the pure python script ,it's work well with "import MySQLdb"
and some sql query...

i don't know why...please help me....
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freeradius.org/pipermail/freeradius-users/attachments/20060415/de6c0d76/attachment.html>


More information about the Freeradius-Users mailing list